Author: kmoore Date: Fri Aug 2 09:08:34 2013 New Revision: 396105 URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396105 Log: Move ast_str_container_alloc and friends
This moves ast_str_container_alloc, ast_str_container_add, ast_str_container_remove, and related private functions into strings.c/h since they really don't belong in astobj2.c/h. As a result of this move, utils also had to be updated. Review: https://reviewboard.asterisk.org/r/2719/ (closes issue ASTERISK-22041) Modified: trunk/include/asterisk/astobj2.h trunk/include/asterisk/strings.h trunk/main/astobj2.c trunk/main/strings.c trunk/utils/Makefile trunk/utils/refcounter.c Modified: trunk/include/asterisk/astobj2.h URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/astobj2.h?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/include/asterisk/astobj2.h (original) +++ trunk/include/asterisk/astobj2.h Fri Aug 2 09:08:34 2013 @@ -1938,54 +1938,4 @@ #endif void ao2_iterator_cleanup(struct ao2_iterator *iter); - -/* XXX TODO BUGBUG and all the other things... - * These functions should eventually be moved elsewhere, but the utils folder - * won't compile with them in strings.h - */ - -/*! - * \since 12 - * \brief Allocates a hash container for bare strings - * - * \param buckets The number of buckets to use for the hash container - * - * \retval AO2 container for strings - * \retval NULL if allocation failed - */ -#define ast_str_container_alloc(buckets) ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, buckets) - -/*! - * \since 12 - * \brief Allocates a hash container for bare strings - * - * \param opts Options to be provided to the container - * \param buckets The number of buckets to use for the hash container - * - * \retval AO2 container for strings - * \retval NULL if allocation failed - */ -struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets); - -/*! - * \since 12 - * \brief Adds a string to a string container allocated by ast_str_container_alloc - * - * \param str_container The container to which to add a string - * \param add The string to add to the container - * - * \retval zero on success - * \retval non-zero if the operation failed - */ -int ast_str_container_add(struct ao2_container *str_container, const char *add); - -/*! - * \since 12 - * \brief Removes a string from a string container allocated by ast_str_container_alloc - * - * \param str_container The container from which to remove a string - * \param remove The string to remove from the container - */ -void ast_str_container_remove(struct ao2_container *str_container, const char *remove); - #endif /* _ASTERISK_ASTOBJ2_H */ Modified: trunk/include/asterisk/strings.h URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/strings.h?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/include/asterisk/strings.h (original) +++ trunk/include/asterisk/strings.h Fri Aug 2 09:08:34 2013 @@ -29,6 +29,7 @@ #include "asterisk/utils.h" #include "asterisk/threadstorage.h" +#include "asterisk/astobj2.h" #if defined(DEBUG_OPAQUE) #define __AST_STR_USED used2 @@ -1109,4 +1110,48 @@ return str_orig; } +/*! + * \since 12 + * \brief Allocates a hash container for bare strings + * + * \param buckets The number of buckets to use for the hash container + * + * \retval AO2 container for strings + * \retval NULL if allocation failed + */ +#define ast_str_container_alloc(buckets) ast_str_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, buckets) + +/*! + * \since 12 + * \brief Allocates a hash container for bare strings + * + * \param opts Options to be provided to the container + * \param buckets The number of buckets to use for the hash container + * + * \retval AO2 container for strings + * \retval NULL if allocation failed + */ +struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets); + +/*! + * \since 12 + * \brief Adds a string to a string container allocated by ast_str_container_alloc + * + * \param str_container The container to which to add a string + * \param add The string to add to the container + * + * \retval zero on success + * \retval non-zero if the operation failed + */ +int ast_str_container_add(struct ao2_container *str_container, const char *add); + +/*! + * \since 12 + * \brief Removes a string from a string container allocated by ast_str_container_alloc + * + * \param str_container The container from which to remove a string + * \param remove The string to remove from the container + */ +void ast_str_container_remove(struct ao2_container *str_container, const char *remove); + #endif /* _ASTERISK_STRINGS_H */ Modified: trunk/main/astobj2.c URL: http://svnview.digium.com/svn/asterisk/trunk/main/astobj2.c?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/main/astobj2.c (original) +++ trunk/main/astobj2.c Fri Aug 2 09:08:34 2013 @@ -5797,40 +5797,3 @@ return 0; } -/* XXX TODO BUGBUG and all the other things... - * These functions should eventually be moved elsewhere, but the utils folder - * won't compile with them in strings.h - */ -static int str_hash(const void *obj, const int flags) -{ - return ast_str_hash(obj); -} - -static int str_cmp(void *lhs, void *rhs, int flags) -{ - return strcmp(lhs, rhs) ? 0 : CMP_MATCH; -} - -struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets) -{ - return ao2_container_alloc_options(opts, buckets, str_hash, str_cmp); -} - -int ast_str_container_add(struct ao2_container *str_container, const char *add) -{ - RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup); - - if (!ao2_add) { - return -1; - } - - /* safe strcpy */ - strcpy(ao2_add, add); - ao2_link(str_container, ao2_add); - return 0; -} - -void ast_str_container_remove(struct ao2_container *str_container, const char *remove) -{ - ao2_find(str_container, remove, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK); -} Modified: trunk/main/strings.c URL: http://svnview.digium.com/svn/asterisk/trunk/main/strings.c?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/main/strings.c (original) +++ trunk/main/strings.c Fri Aug 2 09:08:34 2013 @@ -160,4 +160,36 @@ return (*buf)->__AST_STR_STR; } +static int str_hash(const void *obj, const int flags) +{ + return ast_str_hash(obj); +} +static int str_cmp(void *lhs, void *rhs, int flags) +{ + return strcmp(lhs, rhs) ? 0 : CMP_MATCH; +} + +struct ao2_container *ast_str_container_alloc_options(enum ao2_container_opts opts, int buckets) +{ + return ao2_container_alloc_options(opts, buckets, str_hash, str_cmp); +} + +int ast_str_container_add(struct ao2_container *str_container, const char *add) +{ + RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup); + + if (!ao2_add) { + return -1; + } + + /* safe strcpy */ + strcpy(ao2_add, add); + ao2_link(str_container, ao2_add); + return 0; +} + +void ast_str_container_remove(struct ao2_container *str_container, const char *remove) +{ + ao2_find(str_container, remove, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK); +} Modified: trunk/utils/Makefile URL: http://svnview.digium.com/svn/asterisk/trunk/utils/Makefile?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/utils/Makefile (original) +++ trunk/utils/Makefile Fri Aug 2 09:08:34 2013 @@ -180,7 +180,7 @@ $(CMD_PREFIX) cp "$<" "$@" -refcounter: refcounter.o md5.o hashtab.o lock.o utils.o strings.o sha1.o strcompat.o threadstorage.o clicompat.o poll.o version.o +refcounter: refcounter.o md5.o hashtab.o lock.o utils.o strings.o sha1.o strcompat.o threadstorage.o clicompat.o poll.o version.o astobj2.o refcounter.o: _ASTCFLAGS+=-O0 extconf.o: extconf.c Modified: trunk/utils/refcounter.c URL: http://svnview.digium.com/svn/asterisk/trunk/utils/refcounter.c?view=diff&rev=396105&r1=396104&r2=396105 ============================================================================== --- trunk/utils/refcounter.c (original) +++ trunk/utils/refcounter.c Fri Aug 2 09:08:34 2013 @@ -310,4 +310,13 @@ { return NULL; } + +void ast_log_backtrace(void) +{ +} + +int ast_register_atexit(void (*func)(void)) +{ + return 0; +} #endif -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- svn-commits mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/svn-commits
