[asterisk-commits] cdr pgsql.cl: REFACTOR Macro LENGTHEN BUF (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 3 06:20:18 CST 2016


Joshua Colp has submitted this change and it was merged.

Change subject: cdr_pgsql.cl: REFACTOR Macro LENGTHEN_BUF
......................................................................


cdr_pgsql.cl: REFACTOR Macro LENGTHEN_BUF

Remove repeated code on macro of assigned buffer to SQL vars.

Add table and connection name to log error message when is not possible
allocate memory.

Change-Id: I1fbf37d286a032d38fdda72a9f736356956c9ffe
---
M cdr/cdr_pgsql.c
1 file changed, 17 insertions(+), 26 deletions(-)

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



diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index 8dc49e1..aec2116 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -101,34 +101,25 @@
 
 static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
 
-#define LENGTHEN_BUF1(size)                                               \
-			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) {	\
-						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR failed.\n"); \
-						ast_free(sql);                                    \
-						ast_free(sql2);                                   \
-						AST_RWLIST_UNLOCK(&psql_columns);                 \
-						ast_mutex_unlock(&pgsql_lock);                    \
-						return -1;                                        \
-					}                                                     \
-				}                                                         \
+#define LENGTHEN_BUF(size, var_sql) \
+			do { \
+				/* Lengthen buffer, if necessary */ \
+				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 CDR '%s:%s' failed.\n", pghostname, table); \
+						ast_free(sql); \
+						ast_free(sql2); \
+						AST_RWLIST_UNLOCK(&psql_columns); \
+						ast_mutex_unlock(&pgsql_lock); \
+						return -1; \
+					} \
+				} \
 			} 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 failed.\n");	\
-						ast_free(sql);                    \
-						ast_free(sql2);                   \
-						AST_RWLIST_UNLOCK(&psql_columns); \
-						ast_mutex_unlock(&pgsql_lock);    \
-						return -1;                        \
-					}                                     \
-				}                                         \
-			} while (0)
+#define LENGTHEN_BUF1(size) \
+	LENGTHEN_BUF(size, sql);
+#define LENGTHEN_BUF2(size) \
+	LENGTHEN_BUF(size, sql2);
 
 /*! \brief Handle the CLI command cdr show pgsql status */
 static char *handle_cdr_pgsql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1fbf37d286a032d38fdda72a9f736356956c9ffe
Gerrit-PatchSet: 1
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>



More information about the asterisk-commits mailing list