[asterisk-commits] kpfleming: trunk r49580 - /trunk/include/asterisk/strings.h

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Jan 4 16:38:10 MST 2007


Author: kpfleming
Date: Thu Jan  4 17:38:10 2007
New Revision: 49580

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49580
Log:
ensure that the proper file/function/line shows up for dynamic string threadstorage objects
remove pointless casts

Modified:
    trunk/include/asterisk/strings.h

Modified: trunk/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=49580&r1=49579&r2=49580
==============================================================================
--- trunk/include/asterisk/strings.h (original)
+++ trunk/include/asterisk/strings.h Thu Jan  4 17:38:10 2007
@@ -333,7 +333,7 @@
 {
 	struct ast_str *buf;
 
-	buf = (struct ast_str *)ast_calloc(1, sizeof(*buf) + init_len);
+	buf = ast_calloc(1, sizeof(*buf) + init_len);
 	if (buf == NULL)
 		return NULL;
 	
@@ -373,7 +373,7 @@
 		return 0;	/* success */
 	if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC)
 		return -1;	/* cannot extend */
-	*buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));
+	*buf = ast_realloc(*buf, new_len + sizeof(struct ast_str));
 	if (*buf == NULL) /* XXX watch out, we leak memory here */
 		return -1;
 	if ((*buf)->ts != DS_MALLOC) {
@@ -431,13 +431,14 @@
  * }
  * \endcode
  */
+#if !defined(DEBUG_THREADLOCALS)
 AST_INLINE_API(
 struct ast_str *ast_str_thread_get(struct ast_threadstorage *ts,
 	size_t init_len),
 {
 	struct ast_str *buf;
 
-	buf = (struct ast_str *)ast_threadstorage_get(ts, sizeof(*buf) + init_len);
+	buf = ast_threadstorage_get(ts, sizeof(*buf) + init_len);
 	if (buf == NULL)
 		return NULL;
 	
@@ -450,6 +451,29 @@
 	return buf;
 }
 )
+#else /* defined(DEBUG_THREADLOCALS) */
+AST_INLINE_API(
+struct ast_str *__ast_str_thread_get(struct ast_threadstorage *ts,
+	size_t init_len, const char *file, const char *function, unsigned int line),
+{
+	struct ast_str *buf;
+
+	buf = __ast_threadstorage_get(ts, sizeof(*buf) + init_len, file, function, line);
+	if (buf == NULL)
+		return NULL;
+	
+	if (!buf->len) {
+		buf->len = init_len;
+		buf->used = 0;
+		buf->ts = ts;
+	}
+
+	return buf;
+}
+)
+
+#define ast_str_thread_get(ts, init_len) __ast_str_thread_get(ts, init_len, __FILE__, __PRETTY_FUNCTION__, __LINE__)
+#endif /* defined(DEBUG_THREADLOCALS) */
 
 /*!
  * \brief Error codes from __ast_str_helper()



More information about the asterisk-commits mailing list