Commit b62d340366 for asterisk.org
commit b62d34036658ad43930ff5b5bd80e69fc0e0f474
Author: Sean Bright <sean@seanbright.com>
Date: Fri Oct 2 14:23:45 2026 +0000
hashtab.c: Object lookups can be const
The objects passed to the various hashtable removal functions are not
modified, so they can - and should - be `const`.
diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h
index c40a76f377..6478773505 100644
--- a/include/asterisk/hashtab.h
+++ b/include/asterisk/hashtab.h
@@ -363,11 +363,11 @@ void ast_hashtab_end_traversal(struct ast_hashtab_iter *it);
void *ast_hashtab_next(struct ast_hashtab_iter *it);
/*! \brief Looks up the object, removes the corresponding bucket */
-void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj);
+void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, const void *obj);
/*! \brief Hash the object and then compare ptrs in bucket list instead of
calling the compare routine, will remove the bucket */
-void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj);
+void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, const void *obj);
/* ------------------ */
/* for lock-enabled traversals with ability to remove an object during the traversal*/
@@ -379,11 +379,11 @@ struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *
_ast_hashtab_start_write_traversal(tab, __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*! \brief Looks up the object, removes the corresponding bucket */
-void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj);
+void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, const void *obj);
/*! \brief Hash the object and then compare ptrs in bucket list instead of
calling the compare routine, will remove the bucket */
-void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, void *obj);
+void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, const void *obj);
/* ------------------ */
/* ------------------ */
diff --git a/main/hashtab.c b/main/hashtab.c
index 1f9c7bfe83..cc36d304ba 100644
--- a/main/hashtab.c
+++ b/main/hashtab.c
@@ -743,7 +743,7 @@ static void *ast_hashtab_remove_object_internal(struct ast_hashtab *tab, struct
return (void *) obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */
}
-void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
+void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, const void *obj)
{
/* looks up the object; removes the corresponding bucket */
const void *obj2;
@@ -762,7 +762,7 @@ void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
return (void *)obj2;
}
-void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj)
+void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, const void *obj)
{
/* looks up the object; removes the corresponding bucket */
unsigned int h;
@@ -786,7 +786,7 @@ void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void
return 0;
}
-void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
+void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, const void *obj)
{
/* looks up the object by hash and then comparing pts in bucket list instead of
calling the compare routine; removes the bucket -- a slightly cheaper operation */
@@ -799,7 +799,7 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
if (tab->do_locking)
ast_rwlock_wrlock(&tab->lock);
- obj2 = ast_hashtab_remove_this_object_nolock(tab,obj);
+ obj2 = ast_hashtab_remove_this_object_nolock(tab, obj);
if (tab->do_locking)
ast_rwlock_unlock(&tab->lock);
@@ -807,7 +807,7 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
return (void *)obj2;
}
-void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, void *obj)
+void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, const void *obj)
{
/* looks up the object by hash and then comparing pts in bucket list instead of
calling the compare routine; removes the bucket -- a slightly cheaper operation */