<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7779">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Use macros to generate ao2_container callbacks where possible.<br><br>This uses AO2_STRING_FIELD_HASH_FN and AO2_STRING_FIELD_CMP_FN where<br>possible in the Asterisk core.<br><br>This removes CMP_STOP from the result of CMP_FN callbacks for the<br>following structure types:<br>* ast_bucket_metadata<br>* ast_bucket_scheme<br>* generic_monitor_instance_list (ccss.c)<br>* ast_bucket_file (media_cache.c)<br>* named_acl<br><br>Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1<br>---<br>M main/bucket.c<br>M main/ccss.c<br>M main/cel.c<br>M main/codec.c<br>M main/endpoints.c<br>M main/format.c<br>M main/media_cache.c<br>M main/named_acl.c<br>M main/named_locks.c<br>M main/sorcery.c<br>10 files changed, 54 insertions(+), 668 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/bucket.c b/main/bucket.c<br>index e002848..07cd016 100644<br>--- a/main/bucket.c<br>+++ b/main/bucket.c<br>@@ -617,33 +617,10 @@<br> }<br> <br> /*! \brief Hashing function for file metadata */<br>-static int bucket_file_metadata_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_bucket_metadata *object;<br>- const char *key;<br>-<br>- switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {<br>- case OBJ_KEY:<br>- key = obj;<br>- return ast_str_hash(key);<br>- case OBJ_POINTER:<br>- object = obj;<br>- return ast_str_hash(object->name);<br>- default:<br>- /* Hash can only work on something with a full key */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_bucket_metadata, name)<br> <br> /*! \brief Comparison function for file metadata */<br>-static int bucket_file_metadata_cmp(void *obj, void *arg, int flags)<br>-{<br>- struct ast_bucket_metadata *metadata1 = obj, *metadata2 = arg;<br>- const char *name = arg;<br>-<br>- return !strcmp(metadata1->name, flags & OBJ_KEY ? name : metadata2->name) ? CMP_MATCH | CMP_STOP : 0;<br>-}<br>+AO2_STRING_FIELD_CMP_FN(ast_bucket_metadata, name)<br> <br> /*! \brief Destructor for bucket files */<br> static void bucket_file_destroy(void *obj)<br>@@ -673,7 +650,7 @@<br> }<br> <br> file->metadata = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, METADATA_BUCKETS,<br>- bucket_file_metadata_hash, bucket_file_metadata_cmp);<br>+ ast_bucket_metadata_hash_fn, ast_bucket_metadata_cmp_fn);<br> if (!file->metadata) {<br> return NULL;<br> }<br>@@ -941,33 +918,10 @@<br> }<br> <br> /*! \brief Hashing function for scheme container */<br>-static int bucket_scheme_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_bucket_scheme *object;<br>- const char *key;<br>-<br>- switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {<br>- case OBJ_KEY:<br>- key = obj;<br>- return ast_str_hash(key);<br>- case OBJ_POINTER:<br>- object = obj;<br>- return ast_str_hash(object->name);<br>- default:<br>- /* Hash can only work on something with a full key */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_bucket_scheme, name)<br> <br> /*! \brief Comparison function for scheme container */<br>-static int bucket_scheme_cmp(void *obj, void *arg, int flags)<br>-{<br>- struct ast_bucket_scheme *scheme1 = obj, *scheme2 = arg;<br>- const char *name = arg;<br>-<br>- return !strcmp(scheme1->name, flags & OBJ_KEY ? name : scheme2->name) ? CMP_MATCH | CMP_STOP : 0;<br>-}<br>+AO2_STRING_FIELD_CMP_FN(ast_bucket_scheme, name)<br> <br> /*! \brief Cleanup function for graceful shutdowns */<br> static void bucket_cleanup(void)<br>@@ -1000,8 +954,8 @@<br> {<br> ast_register_cleanup(&bucket_cleanup);<br> <br>- schemes = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, SCHEME_BUCKETS, bucket_scheme_hash,<br>- bucket_scheme_cmp);<br>+ schemes = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, SCHEME_BUCKETS,<br>+ ast_bucket_scheme_hash_fn, ast_bucket_scheme_cmp_fn);<br> if (!schemes) {<br> ast_log(LOG_ERROR, "Failed to create container for Bucket schemes\n");<br> return -1;<br>diff --git a/main/ccss.c b/main/ccss.c<br>index 892a8a5..ed0bba7 100644<br>--- a/main/ccss.c<br>+++ b/main/ccss.c<br>@@ -1380,19 +1380,8 @@<br> int core_id;<br> };<br> <br>-static int generic_monitor_hash_fn(const void *obj, const int flags)<br>-{<br>- const struct generic_monitor_instance_list *generic_list = obj;<br>- return ast_str_hash(generic_list->device_name);<br>-}<br>-<br>-static int generic_monitor_cmp_fn(void *obj, void *arg, int flags)<br>-{<br>- const struct generic_monitor_instance_list *generic_list1 = obj;<br>- const struct generic_monitor_instance_list *generic_list2 = arg;<br>-<br>- return !strcmp(generic_list1->device_name, generic_list2->device_name) ? CMP_MATCH | CMP_STOP : 0;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(generic_monitor_instance_list, device_name)<br>+AO2_STRING_FIELD_CMP_FN(generic_monitor_instance_list, device_name)<br> <br> static struct generic_monitor_instance_list *find_generic_monitor_instance_list(const char * const device_name)<br> {<br>@@ -4665,8 +4654,8 @@<br> return -1;<br> }<br> if (!(generic_monitors = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS,<br>- generic_monitor_hash_fn, generic_monitor_cmp_fn,<br>- "Create generic monitor container"))) {<br>+ generic_monitor_instance_list_hash_fn, generic_monitor_instance_list_cmp_fn,<br>+ "Create generic monitor container"))) {<br> return -1;<br> }<br> if (!(cc_core_taskprocessor = ast_taskprocessor_get("CCSS_core", TPS_REF_DEFAULT))) {<br>diff --git a/main/cel.c b/main/cel.c<br>index 24a35be..e4fae6d 100644<br>--- a/main/cel.c<br>+++ b/main/cel.c<br>@@ -329,129 +329,16 @@<br> };<br> <br> /*! \brief Hashing function for cel_backend */<br>-static int cel_backend_hash(const void *obj, int flags)<br>-{<br>- const struct cel_backend *backend;<br>- const char *name;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- backend = obj;<br>- name = backend->name;<br>- break;<br>- case OBJ_SEARCH_KEY:<br>- name = obj;<br>- break;<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-<br>- return ast_str_hash(name);<br>-}<br>+AO2_STRING_FIELD_HASH_FN(cel_backend, name)<br> <br> /*! \brief Comparator function for cel_backend */<br>-static int cel_backend_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct cel_backend *object_left = obj;<br>- const struct cel_backend *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->name;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->name, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- /*<br>- * We could also use a partial key struct containing a length<br>- * so strlen() does not get called for every comparison instead.<br>- */<br>- cmp = strncmp(object_left->name, right_key, strlen(right_key));<br>- break;<br>- default:<br>- /*<br>- * What arg points to is specific to this traversal callback<br>- * and has no special meaning to astobj2.<br>- */<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- /*<br>- * At this point the traversal callback is identical to a sorted<br>- * container.<br>- */<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_CMP_FN(cel_backend, name)<br> <br> /*! \brief Hashing function for dialstatus container */<br>-static int dialstatus_hash(const void *obj, int flags)<br>-{<br>- const struct cel_dialstatus *dialstatus;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- dialstatus = obj;<br>- key = dialstatus->uniqueid;<br>- break;<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>+AO2_STRING_FIELD_HASH_FN(cel_dialstatus, uniqueid)<br> <br> /*! \brief Comparator function for dialstatus container */<br>-static int dialstatus_cmp(void *obj, void *arg, int flags)<br>-{<br>- struct cel_dialstatus *object_left = obj;<br>- struct cel_dialstatus *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->uniqueid;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->uniqueid, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- /*<br>- * We could also use a partial key struct containing a length<br>- * so strlen() does not get called for every comparison instead.<br>- */<br>- cmp = strncmp(object_left->uniqueid, right_key, strlen(right_key));<br>- break;<br>- default:<br>- /*<br>- * What arg points to is specific to this traversal callback<br>- * and has no special meaning to astobj2.<br>- */<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- /*<br>- * At this point the traversal callback is identical to a sorted<br>- * container.<br>- */<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_CMP_FN(cel_dialstatus, uniqueid)<br> <br> unsigned int ast_cel_check_enabled(void)<br> {<br>@@ -1665,71 +1552,14 @@<br> return ret;<br> }<br> <br>-static int lid_hash(const void *obj, const int flags)<br>-{<br>- const struct cel_linkedid *lid;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- lid = obj;<br>- key = lid->id;<br>- break;<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>-<br>-static int lid_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct cel_linkedid *object_left = obj;<br>- const struct cel_linkedid *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->id;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->id, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- /*<br>- * We could also use a partial key struct containing a length<br>- * so strlen() does not get called for every comparison instead.<br>- */<br>- cmp = strncmp(object_left->id, right_key, strlen(right_key));<br>- break;<br>- default:<br>- /*<br>- * What arg points to is specific to this traversal callback<br>- * and has no special meaning to astobj2.<br>- */<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- /*<br>- * At this point the traversal callback is identical to a sorted<br>- * container.<br>- */<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(cel_linkedid, id)<br>+AO2_STRING_FIELD_CMP_FN(cel_linkedid, id)<br> <br> int ast_cel_engine_init(void)<br> {<br> struct ao2_container *container;<br> <br>- container = ao2_container_alloc(NUM_APP_BUCKETS, lid_hash, lid_cmp);<br>+ container = ao2_container_alloc(NUM_APP_BUCKETS, cel_linkedid_hash_fn, cel_linkedid_cmp_fn);<br> ao2_global_obj_replace_unref(cel_linkedids, container);<br> ao2_cleanup(container);<br> if (!container) {<br>@@ -1738,7 +1568,7 @@<br> }<br> <br> container = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS,<br>- dialstatus_hash, dialstatus_cmp);<br>+ cel_dialstatus_hash_fn, cel_dialstatus_cmp_fn);<br> ao2_global_obj_replace_unref(cel_dialstatus_store, container);<br> ao2_cleanup(container);<br> if (!container) {<br>@@ -1756,7 +1586,7 @@<br> return -1;<br> }<br> <br>- container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash, cel_backend_cmp);<br>+ container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash_fn, cel_backend_cmp_fn);<br> ao2_global_obj_replace_unref(cel_backends, container);<br> ao2_cleanup(container);<br> if (!container) {<br>diff --git a/main/codec.c b/main/codec.c<br>index 5b262f6..d6de072 100644<br>--- a/main/codec.c<br>+++ b/main/codec.c<br>@@ -73,24 +73,7 @@<br> int __ast_codec_register_with_format(struct ast_codec *codec, const char *format_name,<br> struct ast_module *mod);<br> <br>-static int codec_hash(const void *obj, int flags)<br>-{<br>- const struct ast_codec *codec;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- return ast_str_hash(key);<br>- case OBJ_SEARCH_OBJECT:<br>- codec = obj;<br>- return ast_str_hash(codec->name);<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_codec, name)<br> <br> static int codec_cmp(void *obj, void *arg, int flags)<br> {<br>@@ -265,7 +248,8 @@<br> <br> int ast_codec_init(void)<br> {<br>- codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS, codec_hash, codec_cmp);<br>+ codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS,<br>+ ast_codec_hash_fn, codec_cmp);<br> if (!codecs) {<br> return -1;<br> }<br>diff --git a/main/endpoints.c b/main/endpoints.c<br>index d314052..f1608f3 100644<br>--- a/main/endpoints.c<br>+++ b/main/endpoints.c<br>@@ -76,53 +76,8 @@<br> struct stasis_forward *tech_forward;<br> };<br> <br>-static int endpoint_hash(const void *obj, int flags)<br>-{<br>- const struct ast_endpoint *endpoint;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- return ast_str_hash(key);<br>- case OBJ_SEARCH_OBJECT:<br>- endpoint = obj;<br>- return ast_str_hash(endpoint->id);<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>-<br>-static int endpoint_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct ast_endpoint *left = obj;<br>- const struct ast_endpoint *right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = right->id;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(left->id, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(left->id, right_key, strlen(right_key));<br>- break;<br>- default:<br>- ast_assert(0);<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>-<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_endpoint, id)<br>+AO2_STRING_FIELD_CMP_FN(ast_endpoint, id)<br> <br> struct ast_endpoint *ast_endpoint_find_by_id(const char *id)<br> {<br>@@ -522,14 +477,14 @@<br> {<br> ast_register_cleanup(endpoint_cleanup);<br> <br>- endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, endpoint_hash,<br>- endpoint_cmp);<br>+ endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, ast_endpoint_hash_fn,<br>+ ast_endpoint_cmp_fn);<br> if (!endpoints) {<br> return -1;<br> }<br> <br>- tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, endpoint_hash,<br>- endpoint_cmp);<br>+ tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn,<br>+ ast_endpoint_cmp_fn);<br> if (!tech_endpoints) {<br> return -1;<br> }<br>diff --git a/main/format.c b/main/format.c<br>index 09e736c..5ba9ffe 100644<br>--- a/main/format.c<br>+++ b/main/format.c<br>@@ -64,53 +64,8 @@<br> /*! \brief Container for registered format interfaces */<br> static struct ao2_container *interfaces;<br> <br>-static int format_interface_hash(const void *obj, int flags)<br>-{<br>- const struct format_interface *format_interface;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- return ast_str_hash(key);<br>- case OBJ_SEARCH_OBJECT:<br>- format_interface = obj;<br>- return ast_str_hash(format_interface->codec);<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>-<br>-static int format_interface_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct format_interface *left = obj;<br>- const struct format_interface *right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- cmp = strcmp(left->codec, right->codec);<br>- break;<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(left->codec, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(left->codec, right_key, strlen(right_key));<br>- break;<br>- default:<br>- ast_assert(0);<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>-<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(format_interface, codec)<br>+AO2_STRING_FIELD_CMP_FN(format_interface, codec)<br> <br> /*! \brief Function called when the process is shutting down */<br> static void format_shutdown(void)<br>@@ -121,8 +76,8 @@<br> <br> int ast_format_init(void)<br> {<br>- interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, FORMAT_INTERFACE_BUCKETS, format_interface_hash,<br>- format_interface_cmp);<br>+ interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, FORMAT_INTERFACE_BUCKETS,<br>+ format_interface_hash_fn, format_interface_cmp_fn);<br> if (!interfaces) {<br> return -1;<br> }<br>diff --git a/main/media_cache.c b/main/media_cache.c<br>index c58acdd..90057dc 100644<br>--- a/main/media_cache.c<br>+++ b/main/media_cache.c<br>@@ -49,62 +49,6 @@<br> /*! Our one and only container holding media items */<br> static struct ao2_container *media_cache;<br> <br>-/*!<br>- * \internal<br>- * \brief Hashing function for file metadata<br>- */<br>-static int media_cache_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_bucket_file *object;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- object = obj;<br>- key = ast_sorcery_object_get_id(object);<br>- break;<br>- default:<br>- /* Hash can only work on something with a full key */<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>-<br>-/*!<br>- * \internal<br>- * \brief Comparison function for file metadata<br>- */<br>-static int media_cache_cmp(void *obj, void *arg, int flags)<br>-{<br>- struct ast_bucket_file *left = obj;<br>- struct ast_bucket_file *right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = ast_sorcery_object_get_id(right);<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(ast_sorcery_object_get_id(left), right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(ast_sorcery_object_get_id(left), right_key, strlen(right_key));<br>- break;<br>- default:<br>- ast_assert(0);<br>- cmp = 0;<br>- break;<br>- }<br>-<br>- return cmp ? 0 : CMP_MATCH | CMP_STOP;<br>-}<br>-<br>-<br> int ast_media_cache_exists(const char *uri)<br> {<br> struct ast_bucket_file *bucket_file;<br>@@ -712,7 +656,7 @@<br> ast_register_atexit(media_cache_shutdown);<br> <br> media_cache = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, AO2_BUCKETS,<br>- media_cache_hash, media_cache_cmp);<br>+ ast_sorcery_object_id_hash, ast_sorcery_object_id_compare);<br> if (!media_cache) {<br> return -1;<br> }<br>diff --git a/main/named_acl.c b/main/named_acl.c<br>index 0e0385b..3a4c454 100644<br>--- a/main/named_acl.c<br>+++ b/main/named_acl.c<br>@@ -105,19 +105,8 @@<br> char name[ACL_NAME_LENGTH]; /* Same max length as a configuration category */<br> };<br> <br>-static int named_acl_hash_fn(const void *obj, const int flags)<br>-{<br>- const struct named_acl *entry = obj;<br>- return ast_str_hash(entry->name);<br>-}<br>-<br>-static int named_acl_cmp_fn(void *obj, void *arg, const int flags)<br>-{<br>- struct named_acl *entry1 = obj;<br>- struct named_acl *entry2 = arg;<br>-<br>- return (!strcmp(entry1->name, entry2->name)) ? (CMP_MATCH | CMP_STOP) : 0;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(named_acl, name)<br>+AO2_STRING_FIELD_CMP_FN(named_acl, name)<br> <br> /*! \brief destructor for named_acl_config */<br> static void named_acl_config_destructor(void *obj)<br>diff --git a/main/named_locks.c b/main/named_locks.c<br>index b38539c..2fb8f44 100644<br>--- a/main/named_locks.c<br>+++ b/main/named_locks.c<br>@@ -41,46 +41,8 @@<br> struct ast_named_lock {<br> };<br> <br>-static int named_locks_hash(const void *obj, const int flags)<br>-{<br>- const struct named_lock_proxy *lock = obj;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- return ast_str_hash(obj);<br>- case OBJ_SEARCH_OBJECT:<br>- return ast_str_hash(lock->key);<br>- default:<br>- /* Hash can only work on something with a full key. */<br>- ast_assert(0);<br>- return 0;<br>- }<br>-}<br>-<br>-static int named_locks_cmp(void *obj_left, void *obj_right, int flags)<br>-{<br>- const struct named_lock_proxy *object_left = obj_left;<br>- const struct named_lock_proxy *object_right = obj_right;<br>- const char *right_key = obj_right;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->key;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->key, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(object_left->key, right_key, strlen(right_key));<br>- break;<br>- default:<br>- cmp = 0;<br>- break;<br>- }<br>-<br>- return cmp ? 0 : CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(named_lock_proxy, key)<br>+AO2_STRING_FIELD_CMP_FN(named_lock_proxy, key)<br> <br> static void named_locks_shutdown(void)<br> {<br>@@ -90,7 +52,7 @@<br> int ast_named_locks_init(void)<br> {<br> named_locks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,<br>- NAMED_LOCKS_BUCKETS, named_locks_hash, NULL, named_locks_cmp);<br>+ NAMED_LOCKS_BUCKETS, named_lock_proxy_hash_fn, NULL, named_lock_proxy_cmp_fn);<br> if (!named_locks) {<br> return -1;<br> }<br>diff --git a/main/sorcery.c b/main/sorcery.c<br>index 51b55c5..a55d5c7 100644<br>--- a/main/sorcery.c<br>+++ b/main/sorcery.c<br>@@ -343,102 +343,12 @@<br> return NULL;<br> }<br> <br>-/*! \brief Hashing function for sorcery wizards */<br>-static int sorcery_wizard_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_sorcery_internal_wizard *object;<br>- const char *key;<br>+/*! \brief Hashing and comparison functions for sorcery wizards */<br>+AO2_STRING_FIELD_HASH_FN(ast_sorcery_internal_wizard, callbacks.name)<br>+AO2_STRING_FIELD_CMP_FN(ast_sorcery_internal_wizard, callbacks.name)<br> <br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- object = obj;<br>- key = object->callbacks.name;<br>- break;<br>- default:<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>-<br>-/*! \brief Comparator function for sorcery wizards */<br>-static int sorcery_wizard_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct ast_sorcery_internal_wizard *object_left = obj;<br>- const struct ast_sorcery_internal_wizard *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->callbacks.name;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->callbacks.name, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(object_left->callbacks.name, right_key, strlen(right_key));<br>- break;<br>- default:<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- return CMP_MATCH;<br>-}<br>-<br>-/*! \brief Hashing function for sorcery wizards */<br>-static int object_type_field_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_sorcery_object_field *object_field;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- object_field = obj;<br>- key = object_field->name;<br>- break;<br>- default:<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>-<br>-static int object_type_field_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct ast_sorcery_object_field *field_left = obj;<br>- const struct ast_sorcery_object_field *field_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = field_right->name;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(field_left->name, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(field_left->name, right_key, strlen(right_key));<br>- break;<br>- default:<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_sorcery_object_field, name)<br>+AO2_STRING_FIELD_CMP_FN(ast_sorcery_object_field, name)<br> <br> /*! \brief Cleanup function for graceful shutdowns */<br> static void sorcery_cleanup(void)<br>@@ -454,53 +364,10 @@<br> }<br> <br> /*! \brief Compare function for sorcery instances */<br>-static int sorcery_instance_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct sorcery_proxy *object_left = obj;<br>- const struct sorcery_proxy *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->module_name;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->module_name, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(object_left->module_name, right_key, strlen(right_key));<br>- break;<br>- default:<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_CMP_FN(sorcery_proxy, module_name)<br> <br> /*! \brief Hashing function for sorcery instances */<br>-static int sorcery_instance_hash(const void *obj, const int flags)<br>-{<br>- const struct sorcery_proxy *object;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- object = obj;<br>- key = object->module_name;<br>- break;<br>- default:<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>+AO2_STRING_FIELD_HASH_FN(sorcery_proxy, module_name)<br> <br> int ast_sorcery_init(void)<br> {<br>@@ -519,7 +386,7 @@<br> }<br> <br> wizards = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, WIZARD_BUCKETS,<br>- sorcery_wizard_hash, NULL, sorcery_wizard_cmp);<br>+ ast_sorcery_internal_wizard_hash_fn, NULL, ast_sorcery_internal_wizard_cmp_fn);<br> if (!wizards) {<br> sorcery_cleanup();<br> return -1;<br>@@ -532,7 +399,7 @@<br> }<br> <br> instances = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, INSTANCE_BUCKETS,<br>- sorcery_instance_hash, NULL, sorcery_instance_cmp);<br>+ sorcery_proxy_hash_fn, NULL, sorcery_proxy_cmp_fn);<br> if (!instances) {<br> sorcery_cleanup();<br> return -1;<br>@@ -711,53 +578,8 @@<br> }<br> <br> /*! \brief Hashing function for sorcery types */<br>-static int sorcery_type_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_sorcery_object_type *object;<br>- const char *key;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_KEY:<br>- key = obj;<br>- break;<br>- case OBJ_SEARCH_OBJECT:<br>- object = obj;<br>- key = object->name;<br>- break;<br>- default:<br>- ast_assert(0);<br>- return 0;<br>- }<br>- return ast_str_hash(key);<br>-}<br>-<br>-/*! \brief Comparator function for sorcery types */<br>-static int sorcery_type_cmp(void *obj, void *arg, int flags)<br>-{<br>- const struct ast_sorcery_object_type *object_left = obj;<br>- const struct ast_sorcery_object_type *object_right = arg;<br>- const char *right_key = arg;<br>- int cmp;<br>-<br>- switch (flags & OBJ_SEARCH_MASK) {<br>- case OBJ_SEARCH_OBJECT:<br>- right_key = object_right->name;<br>- /* Fall through */<br>- case OBJ_SEARCH_KEY:<br>- cmp = strcmp(object_left->name, right_key);<br>- break;<br>- case OBJ_SEARCH_PARTIAL_KEY:<br>- cmp = strncmp(object_left->name, right_key, strlen(right_key));<br>- break;<br>- default:<br>- cmp = 0;<br>- break;<br>- }<br>- if (cmp) {<br>- return 0;<br>- }<br>- return CMP_MATCH;<br>-}<br>+AO2_STRING_FIELD_HASH_FN(ast_sorcery_object_type, name)<br>+AO2_STRING_FIELD_CMP_FN(ast_sorcery_object_type, name)<br> <br> static void sorcery_proxy_cb(void *weakproxy, void *data)<br> {<br>@@ -802,7 +624,9 @@<br> goto failure_cleanup;<br> }<br> <br>- if (!(sorcery->types = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, TYPE_BUCKETS, sorcery_type_hash, sorcery_type_cmp))) {<br>+ sorcery->types = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, TYPE_BUCKETS,<br>+ ast_sorcery_object_type_hash_fn, ast_sorcery_object_type_cmp_fn);<br>+ if (!sorcery->types) {<br> goto failure_cleanup;<br> }<br> <br>@@ -878,7 +702,7 @@<br> }<br> <br> object_type->fields = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,<br>- OBJECT_FIELD_BUCKETS, object_type_field_hash, NULL, object_type_field_cmp);<br>+ OBJECT_FIELD_BUCKETS, ast_sorcery_object_field_hash_fn, NULL, ast_sorcery_object_field_cmp_fn);<br> if (!object_type->fields) {<br> ao2_ref(object_type, -1);<br> return NULL;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7779">change 7779</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7779"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ide4c1449a894bce70dea1fef664dade9b57578f1 </div>
<div style="display:none"> Gerrit-Change-Number: 7779 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>