diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-11-19 01:02:45 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-11-19 01:02:45 +0000 |
commit | afb571ba8fbc46cbe6c6d22421e32a13e66a6cbf (patch) | |
tree | 60217ccc3d23a25a5ad3269a0866e94d93a78a52 /include | |
parent | 07a22680ee54082a5a109d0c8b2fda5ea17ca9d8 (diff) |
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: https://origsvn.digium.com/svn/asterisk/trunk@157639 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/logger.h | 4 | ||||
-rw-r--r-- | include/asterisk/strings.h | 106 |
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 142fc7c62..7c25ecd5e 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -425,15 +425,17 @@ void ast_str_trim_blanks(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));) @@ -448,15 +450,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));) @@ -557,12 +561,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 @@ -570,12 +570,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. @@ -612,62 +637,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 |