<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7781">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>* 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/named_acl.c<br>M main/named_locks.c<br>M main/sorcery.c<br>9 files changed, 52 insertions(+), 605 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 7618761..084d253 100644<br>--- a/main/bucket.c<br>+++ b/main/bucket.c<br>@@ -560,33 +560,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>@@ -616,7 +593,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>@@ -851,33 +828,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>@@ -910,8 +864,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 ca0c17c..f11fe1d 100644<br>--- a/main/ccss.c<br>+++ b/main/ccss.c<br>@@ -1386,19 +1386,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>@@ -4671,8 +4660,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 24d7faa..31cd045 100644<br>--- a/main/cel.c<br>+++ b/main/cel.c<br>@@ -331,129 +331,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>@@ -1667,71 +1554,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>@@ -1740,7 +1570,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>@@ -1758,7 +1588,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 d0e6368..05cee4a 100644<br>--- a/main/codec.c<br>+++ b/main/codec.c<br>@@ -75,24 +75,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>@@ -267,7 +250,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 80e7f87..88506a4 100644<br>--- a/main/endpoints.c<br>+++ b/main/endpoints.c<br>@@ -78,53 +78,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>@@ -524,14 +479,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 758a7fc..b81a1f1 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/named_acl.c b/main/named_acl.c<br>index 458d4d3..9ea8990 100644<br>--- a/main/named_acl.c<br>+++ b/main/named_acl.c<br>@@ -107,19 +107,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 5960483..6b41f2a 100644<br>--- a/main/named_locks.c<br>+++ b/main/named_locks.c<br>@@ -39,46 +39,8 @@<br> char key[0];<br> };<br> <br>-static int named_locks_hash(const void *obj, const int flags)<br>-{<br>- const struct ast_named_lock *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 ast_named_lock *object_left = obj_left;<br>- const struct ast_named_lock *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(ast_named_lock, key)<br>+AO2_STRING_FIELD_CMP_FN(ast_named_lock, key)<br> <br> static void named_locks_shutdown(void)<br> {<br>@@ -88,7 +50,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, ast_named_lock_hash_fn, NULL, ast_named_lock_cmp_fn);<br> if (!named_locks) {<br> return -1;<br> }<br>diff --git a/main/sorcery.c b/main/sorcery.c<br>index cb0aff5..c20854f 100644<br>--- a/main/sorcery.c<br>+++ b/main/sorcery.c<br>@@ -336,101 +336,14 @@<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>-<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>+AO2_STRING_FIELD_HASH_FN(ast_sorcery_internal_wizard, callbacks.name)<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>+AO2_STRING_FIELD_CMP_FN(ast_sorcery_internal_wizard, callbacks.name)<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>@@ -446,53 +359,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 ast_sorcery *object_left = obj;<br>- const struct ast_sorcery *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(ast_sorcery, 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 ast_sorcery *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(ast_sorcery, module_name)<br> <br> int ast_sorcery_init(void)<br> {<br>@@ -511,7 +381,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>@@ -524,7 +394,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>+ ast_sorcery_hash_fn, NULL, ast_sorcery_cmp_fn);<br> if (!instances) {<br> sorcery_cleanup();<br> return -1;<br>@@ -724,53 +594,10 @@<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>+AO2_STRING_FIELD_HASH_FN(ast_sorcery_object_type, name)<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_CMP_FN(ast_sorcery_object_type, name)<br> <br> struct ast_sorcery *__ast_sorcery_open(const char *module_name)<br> {<br>@@ -787,7 +614,9 @@<br> goto done;<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> ao2_ref(sorcery, -1);<br> sorcery = NULL;<br> goto done;<br>@@ -863,7 +692,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/7781">change 7781</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/7781"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </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: 7781 </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>