[svn-commits] russell: branch russell/ast_verbose_threadstorage r39270 - in /team/russell/a...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Aug 7 21:46:51 MST 2006


Author: russell
Date: Mon Aug  7 23:46:51 2006
New Revision: 39270

URL: http://svn.digium.com/view/asterisk?rev=39270&view=rev
Log:
move the main dynamic string function into utils.c

Modified:
    team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h
    team/russell/ast_verbose_threadstorage/utils.c

Modified: team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h?rev=39270&r1=39269&r2=39270&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h Mon Aug  7 23:46:51 2006
@@ -140,7 +140,7 @@
  *       be free()'d after it is no longer needed.
  */
 AST_INLINE_API(
-struct ast_dynamic_str * __attribute__ ((malloc)) ast_dynamic_str_create(size_t init_len),
+struct ast_dynamic_str *__attribute__ ((malloc)) ast_dynamic_str_create(size_t init_len),
 {
 	struct ast_dynamic_str *buf;
 
@@ -206,12 +206,12 @@
 enum {
 	/*! An error has occured and the contents of the dynamic string
 	 *  are undefined */
-	AST_DYNSTR_SET_FAILED = -1,
+	AST_DYNSTR_BUILD_FAILED = -1,
 	/*! The buffer size for the dynamic string had to be increased, and
 	 *  __ast_dynamic_str_thread_set_va() needs to be called again after
 	 *  a va_end() and va_start().
 	 */
-	AST_DYNSTR_SET_RETRY = -2
+	AST_DYNSTR_BUILD_RETRY = -2
 };
 
 /*!
@@ -259,7 +259,7 @@
 	({                                                                       \
 		int __res;                                                       \
 		while ((__res = __ast_dynamic_str_thread_set_va(buf, max_len,    \
-			ts, 0, fmt, ap)) == AST_DYNSTR_SET_RETRY) {              \
+			ts, 0, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) {              \
 			va_end(ap);                                              \
 			va_start(ap, fmt);                                       \
 		}                                                                \
@@ -277,7 +277,7 @@
 	({                                                                       \
 		int __res;                                                       \
 		while ((__res = __ast_dynamic_str_thread_set_va(buf, max_len,    \
-			ts, 1, fmt, ap)) == AST_DYNSTR_SET_RETRY) {              \
+			ts, 1, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) {              \
 			va_end(ap);                                              \
 			va_start(ap, fmt);                                       \
 		}                                                                \
@@ -292,42 +292,8 @@
  * If append is non-zero, this will append to the current string instead of
  * writing over it.
  */
-AST_INLINE_API(
-int __ast_dynamic_str_thread_set_va(struct ast_dynamic_str **buf, size_t max_len,
-	struct ast_threadstorage *ts, int append, const char *fmt, va_list ap),
-{
-	int res;
-	int offset = append ? strlen((*buf)->str) : 0;
-
-	res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap);
-
-	/* Check to see if there was not enough space in the string buffer to prepare
-	 * the string.  Also, if a maximum length is present, make sure the current
-	 * length is less than the maximum before increasing the size. */
-	if ((res + offset + 1) > (*buf)->len && (max_len ? ((*buf)->len < max_len) : 1)) {
-		/* Set the new size of the string buffer to be the size needed
-		 * to hold the resulting string (res) plus one byte for the
-		 * terminating '\0'.  If this size is greater than the max, set
-		 * the new length to be the maximum allowed. */
-		if (max_len)
-			(*buf)->len = ((res + offset + 1) < max_len) ? (res + offset + 1) : max_len;
-		else
-			(*buf)->len = res + offset + 1;
-
-		if (!(*buf = ast_realloc(*buf, (*buf)->len + sizeof(*(*buf)))))
-			return AST_DYNSTR_SET_FAILED;
-
-		if (ts)
-			pthread_setspecific(ts->key, *buf);
-
-		/* va_end() and va_start() must be done before calling
-		 * vsnprintf() again. */
-		return AST_DYNSTR_SET_RETRY;
-	}
-
-	return res;
-}
-)
+int ast_dynamic_str_thread_build_va(struct ast_dynamic_str **buf, size_t max_len,
+	struct ast_threadstorage *ts, int append, const char *fmt, va_list ap);
 
 /*!
  * \brief Set a thread locally stored dynamic string using variable arguments

Modified: team/russell/ast_verbose_threadstorage/utils.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/utils.c?rev=39270&r1=39269&r2=39270&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/utils.c (original)
+++ team/russell/ast_verbose_threadstorage/utils.c Mon Aug  7 23:46:51 2006
@@ -1195,3 +1195,37 @@
 		return -1;
 }
 
+int ast_dynamic_str_thread_build_va(struct ast_dynamic_str **buf, size_t max_len,
+	struct ast_threadstorage *ts, int append, const char *fmt, va_list ap)
+{
+	int res;
+	int offset = append ? strlen((*buf)->str) : 0;
+
+	res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap);
+
+	/* Check to see if there was not enough space in the string buffer to prepare
+	 * the string.  Also, if a maximum length is present, make sure the current
+	 * length is less than the maximum before increasing the size. */
+	if ((res + offset + 1) > (*buf)->len && (max_len ? ((*buf)->len < max_len) : 1)) {
+		/* Set the new size of the string buffer to be the size needed
+		 * to hold the resulting string (res) plus one byte for the
+		 * terminating '\0'.  If this size is greater than the max, set
+		 * the new length to be the maximum allowed. */
+		if (max_len)
+			(*buf)->len = ((res + offset + 1) < max_len) ? (res + offset + 1) : max_len;
+		else
+			(*buf)->len = res + offset + 1;
+
+		if (!(*buf = ast_realloc(*buf, (*buf)->len + sizeof(*(*buf)))))
+			return AST_DYNSTR_BUILD_FAILED;
+
+		if (ts)
+			pthread_setspecific(ts->key, *buf);
+
+		/* va_end() and va_start() must be done before calling
+		 * vsnprintf() again. */
+		return AST_DYNSTR_BUILD_RETRY;
+	}
+
+	return res;
+}



More information about the svn-commits mailing list