[asterisk-commits] dr adaptive odbc.c, cel odbc.c, cel pgsql.c: REFACTOR Macro ... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 19 09:15:03 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: dr_adaptive_odbc.c, cel_odbc.c, cel_pgsql.c: REFACTOR Macro LENGTHEN_BUF
......................................................................


dr_adaptive_odbc.c, cel_odbc.c, cel_pgsql.c: REFACTOR Macro LENGTHEN_BUF

Remove repeated code on macro of assigned buffer to SQL vars

Change-Id: Icb19ad013124498e172ea1d0b29ccd0ed17deef0
---
M cdr/cdr_adaptive_odbc.c
M cel/cel_odbc.c
M cel/cel_pgsql.c
3 files changed, 21 insertions(+), 44 deletions(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index 8bd9d0d..0da8c01 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -358,11 +358,11 @@
 	return stmt;
 }
 
-#define LENGTHEN_BUF1(size)														\
+#define LENGTHEN_BUF(size, var_sql)														\
 			do {																\
 				/* Lengthen buffer, if necessary */								\
-				if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) {		\
-					if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 1) / 512 + 1) * 512) != 0) { \
+				if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) {		\
+					if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 1) / 512 + 1) * 512) != 0) { \
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
 						ast_free(sql);											\
 						ast_free(sql2);											\
@@ -372,18 +372,10 @@
 				}																\
 			} while (0)
 
-#define LENGTHEN_BUF2(size)														\
-			do {																\
-				if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) {		\
-					if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \
-						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
-						ast_free(sql);											\
-						ast_free(sql2);											\
-						AST_RWLIST_UNLOCK(&odbc_tables);						\
-						return -1;												\
-					}															\
-				}																\
-			} while (0)
+#define LENGTHEN_BUF1(size)	\
+	LENGTHEN_BUF(size, sql);
+#define LENGTHEN_BUF2(size)	\
+	LENGTHEN_BUF(size, sql2);
 
 static int odbc_log(struct ast_cdr *cdr)
 {
diff --git a/cel/cel_odbc.c b/cel/cel_odbc.c
index 2d8408b..3c0be04 100644
--- a/cel/cel_odbc.c
+++ b/cel/cel_odbc.c
@@ -341,11 +341,11 @@
 	return stmt;
 }
 
-#define LENGTHEN_BUF1(size)														\
+#define LENGTHEN_BUF(size, var_sql)														\
 			do {																\
 				/* Lengthen buffer, if necessary */								\
-				if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) {		\
-					if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 1) / 512 + 1) * 512) != 0) { \
+				if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) {		\
+					if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 1) / 512 + 1) * 512) != 0) { \
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CEL '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
 						ast_free(sql);											\
 						ast_free(sql2);											\
@@ -355,18 +355,11 @@
 				}																\
 			} while (0)
 
-#define LENGTHEN_BUF2(size)														\
-			do {																\
-				if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) {		\
-					if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \
-						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CEL '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
-						ast_free(sql);											\
-						ast_free(sql2);											\
-						AST_RWLIST_UNLOCK(&odbc_tables);						\
-						return;													\
-					}															\
-				}																\
-			} while (0)
+#define LENGTHEN_BUF1(size) \
+	LENGTHEN_BUF(size, sql);
+
+#define LENGTHEN_BUF2(size) \
+	LENGTHEN_BUF(size, sql2);
 
 static void odbc_log(struct ast_event *event)
 {
diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c
index f495947..e4e280e 100644
--- a/cel/cel_pgsql.c
+++ b/cel/cel_pgsql.c
@@ -100,11 +100,11 @@
 
 static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
 
-#define LENGTHEN_BUF1(size) \
+#define LENGTHEN_BUF(size, var_sql) \
 	do { \
 		/* Lengthen buffer, if necessary */ \
-		if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) { \
-			if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 3) / 512 + 1) * 512) != 0) { \
+		if (ast_str_strlen(var_sql) + size + 1 > ast_str_size(var_sql)) { \
+			if (ast_str_make_space(&var_sql, ((ast_str_size(var_sql) + size + 3) / 512 + 1) * 512) != 0) { \
 				ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CEL '%s:%s' failed.\n", pghostname, table); \
 				ast_free(sql); \
 				ast_free(sql2); \
@@ -114,18 +114,10 @@
 		} \
 	} while (0)
 
+#define LENGTHEN_BUF1(size) \
+	LENGTHEN_BUF(size, sql);
 #define LENGTHEN_BUF2(size) \
-	do { \
-		if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) { \
-			if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \
-				ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CEL '%s:%s' failed.\n", pghostname, table); \
-				ast_free(sql); \
-				ast_free(sql2); \
-				AST_RWLIST_UNLOCK(&psql_columns); \
-				return; \
-			} \
-		} \
-	} while (0)
+	LENGTHEN_BUF(size, sql2);
 
 static void pgsql_reconnect(void)
 {

-- 
To view, visit https://gerrit.asterisk.org/1261
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icb19ad013124498e172ea1d0b29ccd0ed17deef0
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list