This commit folds in changes to both stringfields (some enhancements to the ...field_set() macro, to optimize setting strings to empty, resetting strings to shorter contents, etc.) and to chan_iax2.c, to use stringfields in the user, peer, and pvt structs. Has been running stably on iaxtel, but while iaxtel has a large registration volume, it doesn't seem to have a high call volume. So far, it seems to reduce heap usage by over half. YMMV\! Please report any IAX bugs that might involve stringfields\!

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39203 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Steve Murphy
2006-08-07 18:12:51 +00:00
parent 2f69bec40e
commit 3042d0e046
2 changed files with 232 additions and 157 deletions

View File

@@ -218,10 +218,36 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
\return nothing
*/
#define ast_string_field_index_set(x, index, data) do { \
if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, strlen(data) + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
strcpy((char *) (x)->__begin_field[index], data); \
} while (0)
char *__zz__ = (char*)(x)->__begin_field[index]; \
int __dlen__ = strlen(data); \
if( __dlen__ == 0 ) { (x)->__begin_field[index] = __ast_string_field_empty; \
} else { \
if( __zz__[0] != 0 && __dlen__ <= strlen(__zz__) ) { \
strcpy(__zz__, data); \
} else { \
if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__ + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
strcpy((char*)(x)->__begin_field[index], data); \
} \
} \
} while (0)
#ifdef FOR_TEST
#define ast_string_field_index_logset(x, index, data, logstr) do { \
char *__zz__ = (char*)(x)->__begin_field[index]; \
int __dlen__ = strlen(data); \
if( __dlen__ == 0 ) { (x)->__begin_field[index] = __ast_string_field_empty; \
} else { \
if( __zz__[0] != 0 && __dlen__ <= strlen(__zz__) ) { \
ast_verbose("%s: ======replacing '%s' with '%s'\n", logstr, __zz__, data); \
strcpy(__zz__, data); \
} else { \
ast_verbose("%s: ++++++allocating room for '%s' to replace '%s'\n", logstr, data, __zz__); \
if (((x)->__begin_field[index] = __ast_string_field_alloc_space(&(x)->__field_mgr, __dlen__ + 1, &(x)->__begin_field[0], ast_string_field_count(x)))) \
strcpy((char*)(x)->__begin_field[index], data); \
} \
} \
} while (0)
#endif
/*!
\brief Set a field to a simple string value
\param x Pointer to a structure containing fields
@@ -232,6 +258,10 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
#define ast_string_field_set(x, field, data) \
ast_string_field_index_set(x, ast_string_field_index(x, field), data)
#ifdef FOR_TEST
#define ast_string_field_logset(x, field, data, logstr) \
ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr)
#endif
/*!
\brief Set a field to a complex (built) value
\param x Pointer to a structure containing fields