From 3042d0e0463459fbb211fdfbd3c295eea76133be Mon Sep 17 00:00:00 2001 From: Steve Murphy Date: Mon, 7 Aug 2006 18:12:51 +0000 Subject: 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 --- include/asterisk/stringfields.h | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'include/asterisk/stringfields.h') diff --git a/include/asterisk/stringfields.h b/include/asterisk/stringfields.h index 5a9a58f82..9b5fbc6df 100644 --- a/include/asterisk/stringfields.h +++ b/include/asterisk/stringfields.h @@ -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 -- cgit v1.2.3