aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-19 01:08:46 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-19 01:08:46 +0000
commit51e9bc3e570340dbe63a0bdac28f99d8e529417c (patch)
tree094d4de7a664446e7ff86f7a636c041f87ad8462 /include
parentbd20ac4cd49de93892e9fe37fb958b9128d3457c (diff)
Merged revisions 157639 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r157639 | tilghman | 2008-11-18 19:02:45 -0600 (Tue, 18 Nov 2008) | 7 lines Starting with a change to ensure that ast_verbose() preserves ABI compatibility in 1.6.1 (as compared to 1.6.0 and versions of 1.4), this change also deprecates the use of Asterisk with FreeBSD 4, given the central use of va_copy in core functions. va_copy() is C99, anyway, and we already require C99 for other purposes, so this isn't really a big change anyway. This change also simplifies some of the core ast_str_* functions. ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@157641 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/logger.h4
-rw-r--r--include/asterisk/strings.h106
2 files changed, 50 insertions, 60 deletions
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index 7d03d8894..91be73181 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -80,6 +80,10 @@ void __ast_verbose(const char *file, int line, const char *func, const char *fmt
#define ast_verbose(...) __ast_verbose(__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
+void __ast_verbose_ap(const char *file, int line, const char *func, const char *fmt, va_list ap);
+
+#define ast_verbose_ap(fmt, ap) __ast_verbose_ap(__FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ap)
+
void ast_child_verbose(int level, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index a95ddcc3c..182f52356 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -410,15 +410,17 @@ void ast_str_reset(struct ast_str *buf),
AST_INLINE_API(
int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function),
{
- _DB1(struct ast_str *old_buf = *buf;)
+ struct ast_str *old_buf = *buf;
if (new_len <= (*buf)->len)
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), file, lineno, function);
- if (*buf == NULL) /* XXX watch out, we leak memory here */
+ if (*buf == NULL) {
+ *buf = old_buf;
return -1;
+ }
if ((*buf)->ts != DS_MALLOC) {
pthread_setspecific((*buf)->ts->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
@@ -433,15 +435,17 @@ int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file,
AST_INLINE_API(
int ast_str_make_space(struct ast_str **buf, size_t new_len),
{
- _DB1(struct ast_str *old_buf = *buf;)
+ struct ast_str *old_buf = *buf;
if (new_len <= (*buf)->len)
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));
- if (*buf == NULL) /* XXX watch out, we leak memory here */
+ if (*buf == NULL) {
+ *buf = old_buf;
return -1;
+ }
if ((*buf)->ts != DS_MALLOC) {
pthread_setspecific((*buf)->ts->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
@@ -542,12 +546,8 @@ struct ast_str *__ast_str_thread_get(struct ast_threadstorage *ts,
/*!
* \brief Error codes from __ast_str_helper()
* The undelying processing to manipulate dynamic string is done
- * by __ast_str_helper(), which can return a success, a
- * permanent failure (e.g. no memory), or a temporary one (when
- * the string needs to be reallocated, and we must run va_start()
- * again; XXX this convoluted interface is only here because
- * FreeBSD 4 lacks va_copy, but this will be fixed and the
- * interface simplified).
+ * by __ast_str_helper(), which can return a success or a
+ * permanent failure (e.g. no memory).
*/
enum {
/*! An error has occurred and the contents of the dynamic string
@@ -555,12 +555,37 @@ enum {
AST_DYNSTR_BUILD_FAILED = -1,
/*! The buffer size for the dynamic string had to be increased, and
* __ast_str_helper() needs to be called again after
- * a va_end() and va_start().
+ * a va_end() and va_start(). This return value is legacy and will
+ * no longer be used.
*/
AST_DYNSTR_BUILD_RETRY = -2
};
/*!
+ * \brief Core functionality of ast_str_(set|append)_va
+ *
+ * The arguments to this function are the same as those described for
+ * ast_str_set_va except for an addition argument, append.
+ * If append is non-zero, this will append to the current string instead of
+ * writing over it.
+ *
+ * AST_DYNSTR_BUILD_RETRY is a legacy define. It should probably never
+ * again be used.
+ *
+ * A return of AST_DYNSTR_BUILD_FAILED indicates a memory allocation error.
+ *
+ * A return value greater than or equal to zero indicates the number of
+ * characters that have been written, not including the terminating '\0'.
+ * In the append case, this only includes the number of characters appended.
+ *
+ * \note This function should never need to be called directly. It should
+ * through calling one of the other functions or macros defined in this
+ * file.
+ */
+int __ast_str_helper(struct ast_str **buf, size_t max_len,
+ int append, const char *fmt, va_list ap);
+
+/*!
* \brief Set a dynamic string from a va_list
*
* \param buf This is the address of a pointer to a struct ast_str.
@@ -597,62 +622,23 @@ enum {
* ...
* }
* \endcode
- *
- * \note: the following two functions must be implemented as macros
- * because we must do va_end()/va_start() on the original arguments.
*/
-#define ast_str_set_va(buf, max_len, fmt, ap) \
- ({ \
- int __res; \
- while ((__res = __ast_str_helper(buf, max_len, \
- 0, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) { \
- va_end(ap); \
- va_start(ap, fmt); \
- } \
- (__res); \
- })
+AST_INLINE_API(int ast_str_set_va(struct ast_str **buf, size_t max_len, const char *fmt, va_list ap),
+{
+ return __ast_str_helper(buf, max_len, 0, fmt, ap);
+}
+)
/*!
* \brief Append to a dynamic string using a va_list
*
* Same as ast_str_set_va(), but append to the current content.
*/
-#define ast_str_append_va(buf, max_len, fmt, ap) \
- ({ \
- int __res; \
- while ((__res = __ast_str_helper(buf, max_len, \
- 1, fmt, ap)) == AST_DYNSTR_BUILD_RETRY) { \
- va_end(ap); \
- va_start(ap, fmt); \
- } \
- (__res); \
- })
-
-/*!
- * \brief Core functionality of ast_str_(set|append)_va
- *
- * The arguments to this function are the same as those described for
- * ast_str_set_va except for an addition argument, append.
- * If append is non-zero, this will append to the current string instead of
- * writing over it.
- *
- * In the case that this function is called and the buffer was not large enough
- * to hold the result, the partial write will be truncated, and the result
- * AST_DYNSTR_BUILD_RETRY will be returned to indicate that the buffer size
- * was increased, and the function should be called a second time.
- *
- * A return of AST_DYNSTR_BUILD_FAILED indicates a memory allocation error.
- *
- * A return value greater than or equal to zero indicates the number of
- * characters that have been written, not including the terminating '\0'.
- * In the append case, this only includes the number of characters appended.
- *
- * \note This function should never need to be called directly. It should
- * through calling one of the other functions or macros defined in this
- * file.
- */
-int __ast_str_helper(struct ast_str **buf, size_t max_len,
- int append, const char *fmt, va_list ap);
+AST_INLINE_API(int ast_str_append_va(struct ast_str **buf, size_t max_len, const char *fmt, va_list ap),
+{
+ return __ast_str_helper(buf, max_len, 1, fmt, ap);
+}
+)
/*!
* \brief Set a dynamic string using variable arguments