Skip to Content.
Sympa Menu

freetds - [freetds] Patch proposal

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddy77 AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Patch proposal
  • Date: Thu, 16 Jun 2011 09:32:52 +0200

Hi,
I would like to include this patch (and follows). It define some
macro to merge allocation and casting.


diff --git a/include/tds.h b/include/tds.h
index 0c77107..b1d9b9e 100644
--- a/include/tds.h
+++ b/include/tds.h
@@ -304,6 +304,10 @@ typedef enum tds_encryption_level {
#else
#define TDS_OFFSET(str, field) (((char*)&((str*)0)->field)-((char*)0))
#endif
+#define tds_alloc(struct) ((struct*) malloc(sizeof(struct)))
+#define tds_allocn(struct,n) ((struct*) malloc(sizeof(struct)*(n)))
+#define tds_zalloc(struct) ((struct*) calloc(1,sizeof(struct)))
+#define tds_zallocn(struct,n) ((struct*) calloc((n),sizeof(struct)))

#if defined(__GNUC__) && __GNUC__ >= 3
# define TDS_LIKELY(x) __builtin_expect(!!(x), 1)


see this patch as an example


diff --git a/src/ctlib/ct.c b/src/ctlib/ct.c
index e7217a9..9e2f03e 100644
--- a/src/ctlib/ct.c
+++ b/src/ctlib/ct.c
@@ -279,7 +279,7 @@ ct_con_alloc(CS_CONTEXT * ctx, CS_CONNECTION ** con)
login = tds_alloc_login();
if (!login)
return CS_FAIL;
- *con = (CS_CONNECTION *) calloc(1, sizeof(CS_CONNECTION));
+ *con = tds_zalloc(CS_CONNECTION);
if (!*con) {
tds_free_login(login);
return CS_FAIL;


as you can see line is shorter. Do you think tds_allocz is better than
tds_zalloc?

Frediano




Archive powered by MHonArc 2.6.24.

Top of Page