Remove duplicate code from the ast_str API. We now use __AST_STR_* to

access 'struct ast_str' members, but this must only be used inside the API implementation.

(closes issue #14098)
Reported by: eliel
Patches:
      ast_str.patch uploaded by eliel (license 64)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@165502 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.2
Eliel C. Sardanons 17 years ago
parent 9e3ecac5ab
commit 344a37f2a7

@ -30,6 +30,18 @@
#include "asterisk/utils.h" #include "asterisk/utils.h"
#include "asterisk/threadstorage.h" #include "asterisk/threadstorage.h"
#if defined(DEBUG_OPAQUE)
#define __AST_STR_USED used2
#define __AST_STR_LEN len2
#define __AST_STR_STR str2
#define __AST_STR_TS ts2
#else
#define __AST_STR_USED used
#define __AST_STR_LEN len
#define __AST_STR_STR str
#define __AST_STR_TS ts
#endif
/* You may see casts in this header that may seem useless but they ensure this file is C++ clean */ /* You may see casts in this header that may seem useless but they ensure this file is C++ clean */
#define AS_OR(a,b) (a && ast_str_strlen(a)) ? ast_str_buffer(a) : (b) #define AS_OR(a,b) (a && ast_str_strlen(a)) ? ast_str_buffer(a) : (b)
@ -340,23 +352,13 @@ int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default
* struct ast_threadstorage pointer. * struct ast_threadstorage pointer.
*/ */
struct ast_str { struct ast_str {
#ifdef DEBUG_OPAQUE size_t __AST_STR_LEN; /*!< The current maximum length of the string */
size_t len2; size_t __AST_STR_USED; /*!< Amount of space used */
size_t used2; struct ast_threadstorage *__AST_STR_TS; /*!< What kind of storage is this ? */
struct ast_threadstorage *ts2;
#else
size_t len; /*!< The current maximum length of the string */
size_t used; /*!< Amount of space used */
struct ast_threadstorage *ts; /*!< What kind of storage is this ? */
#endif
#define DS_MALLOC ((struct ast_threadstorage *)1) #define DS_MALLOC ((struct ast_threadstorage *)1)
#define DS_ALLOCA ((struct ast_threadstorage *)2) #define DS_ALLOCA ((struct ast_threadstorage *)2)
#define DS_STATIC ((struct ast_threadstorage *)3) /* not supported yet */ #define DS_STATIC ((struct ast_threadstorage *)3) /* not supported yet */
#ifdef DEBUG_OPAQUE char __AST_STR_STR[0]; /*!< The string buffer */
char str2[0];
#else
char str[0]; /*!< The string buffer */
#endif
}; };
/*! /*!
@ -379,15 +381,9 @@ struct ast_str * attribute_malloc ast_str_create(size_t init_len),
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
#ifdef DEBUG_OPAQUE buf->__AST_STR_LEN = init_len;
buf->len2 = init_len; buf->__AST_STR_USED = 0;
buf->used2 = 0; buf->__AST_STR_TS = DS_MALLOC;
buf->ts2 = DS_MALLOC;
#else
buf->len = init_len;
buf->used = 0;
buf->ts = DS_MALLOC;
#endif
return buf; return buf;
} }
@ -400,15 +396,9 @@ AST_INLINE_API(
void ast_str_reset(struct ast_str *buf), void ast_str_reset(struct ast_str *buf),
{ {
if (buf) { if (buf) {
#ifdef DEBUG_OPAQUE buf->__AST_STR_USED = 0;
buf->used2 = 0; if (buf->__AST_STR_LEN)
if (buf->len2) buf->__AST_STR_STR[0] = '\0';
buf->str2[0] = '\0';
#else
buf->used = 0;
if (buf->len)
buf->str[0] = '\0';
#endif
} }
} }
) )
@ -422,15 +412,9 @@ void ast_str_trim_blanks(struct ast_str *buf),
if (!buf) { if (!buf) {
return; return;
} }
#ifdef DEBUG_OPAQUE while (buf->__AST_STR_USED && buf->__AST_STR_STR[buf->__AST_STR_USED - 1] < 33) {
while (buf->used2 && buf->str2[buf->used2 - 1] < 33) { buf->__AST_STR_STR[--(buf->__AST_STR_USED)] = '\0';
buf->str2[--(buf->used2)] = '\0';
} }
#else
while (buf->used && buf->str[buf->used - 1] < 33) {
buf->str[--(buf->used)] = '\0';
}
#endif
} }
) )
@ -440,11 +424,7 @@ void ast_str_trim_blanks(struct ast_str *buf),
AST_INLINE_API( AST_INLINE_API(
size_t ast_str_strlen(struct ast_str *buf), size_t ast_str_strlen(struct ast_str *buf),
{ {
#ifdef DEBUG_OPAQUE return buf->__AST_STR_USED;
return buf->used2;
#else
return buf->used;
#endif
} }
) )
@ -454,11 +434,7 @@ size_t ast_str_strlen(struct ast_str *buf),
AST_INLINE_API( AST_INLINE_API(
size_t ast_str_size(struct ast_str *buf), size_t ast_str_size(struct ast_str *buf),
{ {
#ifdef DEBUG_OPAQUE return buf->__AST_STR_LEN;
return buf->len2;
#else
return buf->len;
#endif
} }
) )
@ -468,34 +444,20 @@ size_t ast_str_size(struct ast_str *buf),
AST_INLINE_API( AST_INLINE_API(
attribute_pure char *ast_str_buffer(struct ast_str *buf), attribute_pure char *ast_str_buffer(struct ast_str *buf),
{ {
#ifdef DEBUG_OPAQUE return buf->__AST_STR_STR;
return buf->str2;
#else
return buf->str;
#endif
} }
) )
AST_INLINE_API( AST_INLINE_API(
char *ast_str_truncate(struct ast_str *buf, ssize_t len), char *ast_str_truncate(struct ast_str *buf, ssize_t len),
{ {
#ifdef DEBUG_OPAQUE
if (len < 0) { if (len < 0) {
buf->used2 += ((ssize_t) abs(len)) > (ssize_t) buf->used2 ? -buf->used2 : len; buf->__AST_STR_USED += ((ssize_t) abs(len)) > (ssize_t) buf->__AST_STR_USED ? -buf->__AST_STR_USED : len;
} else { } else {
buf->used2 = len; buf->__AST_STR_USED = len;
} }
buf->str2[buf->used2] = '\0'; buf->__AST_STR_STR[buf->__AST_STR_USED] = '\0';
return buf->str2; return buf->__AST_STR_STR;
#else
if (len < 0) {
buf->used += ((ssize_t) abs(len)) > (ssize_t) buf->used ? -buf->used : len;
} else {
buf->used = len;
}
buf->str[buf->used] = '\0';
return buf->str;
#endif
} }
) )
@ -522,39 +484,21 @@ int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file,
{ {
struct ast_str *old_buf = *buf; struct ast_str *old_buf = *buf;
#ifdef DEBUG_OPAQUE if (new_len <= (*buf)->__AST_STR_LEN)
if (new_len <= (*buf)->len2)
return 0; /* success */
if ((*buf)->ts2 == DS_ALLOCA || (*buf)->ts2 == 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) {
*buf = old_buf;
return -1;
}
if ((*buf)->ts2 != DS_MALLOC) {
pthread_setspecific((*buf)->ts2->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
}
(*buf)->len2 = new_len;
#else
if (new_len <= (*buf)->len)
return 0; /* success */ return 0; /* success */
if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) if ((*buf)->__AST_STR_TS == DS_ALLOCA || (*buf)->__AST_STR_TS == DS_STATIC)
return -1; /* cannot extend */ return -1; /* cannot extend */
*buf = (struct ast_str *)__ast_realloc(*buf, new_len + sizeof(struct ast_str), file, lineno, function); *buf = (struct ast_str *)__ast_realloc(*buf, new_len + sizeof(struct ast_str), file, lineno, function);
if (*buf == NULL) { if (*buf == NULL) {
*buf = old_buf; *buf = old_buf;
return -1; return -1;
} }
if ((*buf)->ts != DS_MALLOC) { if ((*buf)->__AST_STR_TS != DS_MALLOC) {
pthread_setspecific((*buf)->ts->key, *buf); pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));) _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
} }
(*buf)->len = new_len; (*buf)->__AST_STR_LEN = new_len;
#endif
return 0; return 0;
} }
) )
@ -565,67 +509,36 @@ int ast_str_make_space(struct ast_str **buf, size_t new_len),
{ {
struct ast_str *old_buf = *buf; struct ast_str *old_buf = *buf;
#ifdef DEBUG_OPAQUE if (new_len <= (*buf)->__AST_STR_LEN)
if (new_len <= (*buf)->len2)
return 0; /* success */
if ((*buf)->ts2 == DS_ALLOCA || (*buf)->ts2 == DS_STATIC)
return -1; /* cannot extend */
*buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));
if (*buf == NULL) {
*buf = old_buf;
return -1;
}
if ((*buf)->ts2 != DS_MALLOC) {
pthread_setspecific((*buf)->ts2->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
}
(*buf)->len2 = new_len;
#else
if (new_len <= (*buf)->len)
return 0; /* success */ return 0; /* success */
if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) if ((*buf)->__AST_STR_TS == DS_ALLOCA || (*buf)->__AST_STR_TS == DS_STATIC)
return -1; /* cannot extend */ return -1; /* cannot extend */
*buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str)); *buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));
if (*buf == NULL) { if (*buf == NULL) {
*buf = old_buf; *buf = old_buf;
return -1; return -1;
} }
if ((*buf)->ts != DS_MALLOC) { if ((*buf)->__AST_STR_TS != DS_MALLOC) {
pthread_setspecific((*buf)->ts->key, *buf); pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));) _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
} }
(*buf)->len = new_len; (*buf)->__AST_STR_LEN = new_len;
#endif
return 0; return 0;
} }
) )
#endif #endif
#ifdef DEBUG_OPAQUE
#define ast_str_alloca(init_len) \ #define ast_str_alloca(init_len) \
({ \ ({ \
struct ast_str *__ast_str_buf; \ struct ast_str *__ast_str_buf; \
__ast_str_buf = alloca(sizeof(*__ast_str_buf) + init_len); \ __ast_str_buf = alloca(sizeof(*__ast_str_buf) + init_len); \
__ast_str_buf->len2 = init_len; \ __ast_str_buf->__AST_STR_LEN = init_len; \
__ast_str_buf->used2 = 0; \ __ast_str_buf->__AST_STR_USED = 0; \
__ast_str_buf->ts2 = DS_ALLOCA; \ __ast_str_buf->__AST_STR_TS = DS_ALLOCA; \
__ast_str_buf->str2[0] = '\0'; \ __ast_str_buf->__AST_STR_STR[0] = '\0'; \
(__ast_str_buf); \ (__ast_str_buf); \
}) })
#else
#define ast_str_alloca(init_len) \
({ \
struct ast_str *__ast_str_buf; \
__ast_str_buf = alloca(sizeof(*__ast_str_buf) + init_len); \
__ast_str_buf->len = init_len; \
__ast_str_buf->used = 0; \
__ast_str_buf->ts = DS_ALLOCA; \
__ast_str_buf->str[0] = '\0'; \
(__ast_str_buf); \
})
#endif
/*! /*!
* \brief Retrieve a thread locally stored dynamic string * \brief Retrieve a thread locally stored dynamic string
@ -669,19 +582,11 @@ struct ast_str *ast_str_thread_get(struct ast_threadstorage *ts,
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
#ifdef DEBUG_OPAQUE if (!buf->__AST_STR_LEN) {
if (!buf->len2) { buf->__AST_STR_LEN = init_len;
buf->len2 = init_len; buf->__AST_STR_USED = 0;
buf->used2 = 0; buf->__AST_STR_TS = ts;
buf->ts2 = ts;
}
#else
if (!buf->len) {
buf->len = init_len;
buf->used = 0;
buf->ts = ts;
} }
#endif
return buf; return buf;
} }
@ -697,19 +602,11 @@ struct ast_str *__ast_str_thread_get(struct ast_threadstorage *ts,
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
#ifdef DEBUG_OPAQUE if (!buf->__AST_STR_LEN) {
if (!buf->len2) { buf->__AST_STR_LEN = init_len;
buf->len2 = init_len; buf->__AST_STR_USED = 0;
buf->used2 = 0; buf->__AST_STR_TS = ts;
buf->ts2 = ts;
}
#else
if (!buf->len) {
buf->len = init_len;
buf->used = 0;
buf->ts = ts;
} }
#endif
return buf; return buf;
} }
@ -862,27 +759,15 @@ AST_INLINE_API(SQLRETURN ast_str_SQLGetData(struct ast_str **buf, size_t maxlen,
{ {
SQLRETURN res; SQLRETURN res;
if (maxlen == 0) { if (maxlen == 0) {
#ifdef DEBUG_OPAQUE if (SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->__AST_STR_STR, 0, StrLen_or_Ind) == SQL_SUCCESS_WITH_INFO) {
if (SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->str2, 0, StrLen_or_Ind) == SQL_SUCCESS_WITH_INFO) {
ast_str_make_space(buf, *StrLen_or_Ind + 1); ast_str_make_space(buf, *StrLen_or_Ind + 1);
} }
maxlen = (*buf)->len2; maxlen = (*buf)->__AST_STR_LEN;
} else if (maxlen > 0) { } else if (maxlen > 0) {
ast_str_make_space(buf, maxlen); ast_str_make_space(buf, maxlen);
} }
res = SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->str2, maxlen, StrLen_or_Ind); res = SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->__AST_STR_STR, maxlen, StrLen_or_Ind);
(*buf)->used2 = *StrLen_or_Ind; (*buf)->__AST_STR_USED = *StrLen_or_Ind;
#else
if (SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->str, 0, StrLen_or_Ind) == SQL_SUCCESS_WITH_INFO) {
ast_str_make_space(buf, *StrLen_or_Ind + 1);
}
maxlen = (*buf)->len;
} else if (maxlen > 0) {
ast_str_make_space(buf, maxlen);
}
res = SQLGetData(StatementHandle, ColumnNumber, TargetType, (*buf)->str, maxlen, StrLen_or_Ind);
(*buf)->used = *StrLen_or_Ind;
#endif
return res; return res;
} }
) )
@ -977,4 +862,5 @@ static force_inline int ast_str_case_hash(const char *str)
return abs(hash); return abs(hash);
} }
#endif /* _ASTERISK_STRINGS_H */ #endif /* _ASTERISK_STRINGS_H */

@ -52,67 +52,39 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len,
int append, const char *fmt, va_list ap) int append, const char *fmt, va_list ap)
{ {
int res, need; int res, need;
#ifdef DEBUG_OPAQUE int offset = (append && (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_USED : 0;
int offset = (append && (*buf)->len2) ? (*buf)->used2 : 0;
#else
int offset = (append && (*buf)->len) ? (*buf)->used : 0;
#endif
va_list aq; va_list aq;
do { do {
if (max_len < 0) { if (max_len < 0) {
#ifdef DEBUG_OPAQUE max_len = (*buf)->__AST_STR_LEN; /* don't exceed the allocated space */
max_len = (*buf)->len2; /* don't exceed the allocated space */
#else
max_len = (*buf)->len; /* don't exceed the allocated space */
#endif
} }
/* /*
* Ask vsnprintf how much space we need. Remember that vsnprintf * Ask vsnprintf how much space we need. Remember that vsnprintf
* does not count the final '\0' so we must add 1. * does not count the final '\0' so we must add 1.
*/ */
va_copy(aq, ap); va_copy(aq, ap);
#ifdef DEBUG_OPAQUE res = vsnprintf((*buf)->__AST_STR_STR + offset, (*buf)->__AST_STR_LEN - offset, fmt, aq);
res = vsnprintf((*buf)->str2 + offset, (*buf)->len2 - offset, fmt, aq);
#else
res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, aq);
#endif
need = res + offset + 1; need = res + offset + 1;
/* /*
* If there is not enough space and we are below the max length, * If there is not enough space and we are below the max length,
* reallocate the buffer and return a message telling to retry. * reallocate the buffer and return a message telling to retry.
*/ */
#ifdef DEBUG_OPAQUE if (need > (*buf)->__AST_STR_LEN && (max_len == 0 || (*buf)->__AST_STR_LEN < max_len) ) {
if (need > (*buf)->len2 && (max_len == 0 || (*buf)->len2 < max_len) ) {
#else
if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
#endif
if (max_len && max_len < need) { /* truncate as needed */ if (max_len && max_len < need) { /* truncate as needed */
need = max_len; need = max_len;
} else if (max_len == 0) { /* if unbounded, give more room for next time */ } else if (max_len == 0) { /* if unbounded, give more room for next time */
need += 16 + need / 4; need += 16 + need / 4;
} }
if (0) { /* debugging */ if (0) { /* debugging */
#ifdef DEBUG_OPAQUE ast_verbose("extend from %d to %d\n", (int)(*buf)->__AST_STR_LEN, need);
ast_verbose("extend from %d to %d\n", (int)(*buf)->len2, need);
#else
ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need);
#endif
} }
if (ast_str_make_space(buf, need)) { if (ast_str_make_space(buf, need)) {
#ifdef DEBUG_OPAQUE ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->__AST_STR_LEN, need);
ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len2, need);
#else
ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need);
#endif
return AST_DYNSTR_BUILD_FAILED; return AST_DYNSTR_BUILD_FAILED;
} }
#ifdef DEBUG_OPAQUE (*buf)->__AST_STR_STR[offset] = '\0'; /* Truncate the partial write. */
(*buf)->str2[offset] = '\0'; /* Truncate the partial write. */
#else
(*buf)->str[offset] = '\0'; /* Truncate the partial write. */
#endif
/* Restart va_copy before calling vsnprintf() again. */ /* Restart va_copy before calling vsnprintf() again. */
va_end(aq); va_end(aq);
@ -121,11 +93,7 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len,
break; break;
} while (1); } while (1);
/* update space used, keep in mind the truncation */ /* update space used, keep in mind the truncation */
#ifdef DEBUG_OPAQUE (*buf)->__AST_STR_USED = (res + offset > (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_LEN : res + offset;
(*buf)->used2 = (res + offset > (*buf)->len2) ? (*buf)->len2 : res + offset;
#else
(*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
#endif
return res; return res;
} }
@ -133,73 +101,41 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len,
void ast_str_substitute_variables(struct ast_str **buf, size_t maxlen, struct ast_channel *chan, const char *template) void ast_str_substitute_variables(struct ast_str **buf, size_t maxlen, struct ast_channel *chan, const char *template)
{ {
int first = 1; int first = 1;
#ifdef DEBUG_OPAQUE
do { do {
ast_str_make_space(buf, maxlen ? maxlen : ast_str_make_space(buf, maxlen ? maxlen :
(first ? strlen(template) * 2 : (*buf)->len2 * 2)); (first ? strlen(template) * 2 : (*buf)->__AST_STR_LEN * 2));
pbx_substitute_variables_helper_full(chan, NULL, template, (*buf)->str2, (*buf)->len2 - 1, &((*buf)->used2)); pbx_substitute_variables_helper_full(chan, NULL, template, (*buf)->__AST_STR_STR, (*buf)->__AST_STR_LEN - 1, &((*buf)->__AST_STR_USED));
first = 0; first = 0;
} while (maxlen == 0 && (*buf)->len2 - 5 < (*buf)->used2); } while (maxlen == 0 && (*buf)->__AST_STR_LEN - 5 < (*buf)->__AST_STR_USED);
#else
do {
ast_str_make_space(buf, maxlen ? maxlen :
(first ? strlen(template) * 2 : (*buf)->len * 2));
pbx_substitute_variables_helper_full(chan, NULL, template, (*buf)->str, (*buf)->len - 1, &((*buf)->used));
first = 0;
} while (maxlen == 0 && (*buf)->len - 5 < (*buf)->used);
#endif
} }
char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas) char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas)
{ {
int dynamic = 0; int dynamic = 0;
#ifdef DEBUG_OPAQUE char *ptr = append ? &((*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED]) : (*buf)->__AST_STR_STR;
char *ptr = append ? &((*buf)->str2[(*buf)->used2]) : (*buf)->str2;
#else
char *ptr = append ? &((*buf)->str[(*buf)->used]) : (*buf)->str;
#endif
if (!maxlen) { if (!maxlen) {
dynamic = 1; dynamic = 1;
#ifdef DEBUG_OPAQUE maxlen = (*buf)->__AST_STR_LEN;
maxlen = (*buf)->len2;
#else
maxlen = (*buf)->len;
#endif
} }
while (*src && maxsrc && maxlen && (!escapecommas || (maxlen - 1))) { while (*src && maxsrc && maxlen && (!escapecommas || (maxlen - 1))) {
if (escapecommas && (*src == '\\' || *src == ',')) { if (escapecommas && (*src == '\\' || *src == ',')) {
*ptr++ = '\\'; *ptr++ = '\\';
maxlen--; maxlen--;
#ifdef DEBUG_OPAQUE (*buf)->__AST_STR_USED++;
(*buf)->used2++;
#else
(*buf)->used++;
#endif
} }
*ptr++ = *src++; *ptr++ = *src++;
maxsrc--; maxsrc--;
maxlen--; maxlen--;
#ifdef DEBUG_OPAQUE (*buf)->__AST_STR_USED++;
(*buf)->used2++;
#else
(*buf)->used++;
#endif
if (dynamic && (!maxlen || (escapecommas && !(maxlen - 1)))) { if (dynamic && (!maxlen || (escapecommas && !(maxlen - 1)))) {
#ifdef DEBUG_OPAQUE size_t old = (*buf)->__AST_STR_LEN;
size_t old = (*buf)->len2; if (ast_str_make_space(buf, (*buf)->__AST_STR_LEN * 2)) {
if (ast_str_make_space(buf, (*buf)->len2 * 2)) {
/* If the buffer can't be extended, end it. */
break;
}
#else
size_t old = (*buf)->len;
if (ast_str_make_space(buf, (*buf)->len * 2)) {
/* If the buffer can't be extended, end it. */ /* If the buffer can't be extended, end it. */
break; break;
} }
#endif
/* What we extended the buffer by */ /* What we extended the buffer by */
maxlen = old; maxlen = old;
} }
@ -208,12 +144,7 @@ char *__ast_str_helper2(struct ast_str **buf, size_t maxlen, const char *src, si
ptr--; ptr--;
} }
*ptr = '\0'; *ptr = '\0';
#ifdef DEBUG_OPAQUE (*buf)->__AST_STR_USED--;
(*buf)->used2--; return (*buf)->__AST_STR_STR;
return (*buf)->str2;
#else
(*buf)->used--;
return (*buf)->str;
#endif
} }

Loading…
Cancel
Save