Commit 1c4b0662 authored by David Zeuthen's avatar David Zeuthen
Browse files

ensure object is first in the list/hash iterator callback functions

This is useful for passing free / unref functions in.
parent ea980bee
...@@ -330,7 +330,7 @@ kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data) ...@@ -330,7 +330,7 @@ kit_hash_foreach (KitHash *hash, KitHashForeachFunc cb, void *user_data)
KitHashNode *node; KitHashNode *node;
for (node = hash->top_nodes[n]; node != NULL; node = node->next) { for (node = hash->top_nodes[n]; node != NULL; node = node->next) {
if (cb (hash, node->key, node->value, user_data)) if (cb (node->key, node->value, user_data, hash))
return TRUE; return TRUE;
} }
} }
...@@ -370,7 +370,7 @@ kit_hash_foreach_remove (KitHash *hash, KitHashForeachFunc cb, void *user_data) ...@@ -370,7 +370,7 @@ kit_hash_foreach_remove (KitHash *hash, KitHashForeachFunc cb, void *user_data)
for (node = hash->top_nodes[n]; node != NULL; node = node_next) { for (node = hash->top_nodes[n]; node != NULL; node = node_next) {
node_next = node->next; node_next = node->next;
if (cb (hash, node->key, node->value, user_data)) { if (cb (node->key, node->value, user_data, hash)) {
if (hash->key_destroy_func != NULL) if (hash->key_destroy_func != NULL)
hash->key_destroy_func (node->key); hash->key_destroy_func (node->key);
...@@ -472,7 +472,7 @@ kit_hash_str_copy (const void *p) ...@@ -472,7 +472,7 @@ kit_hash_str_copy (const void *p)
#ifdef KIT_BUILD_TESTS #ifdef KIT_BUILD_TESTS
static kit_bool_t static kit_bool_t
_it1 (KitHash *hash, void *key, void *value, void *user_data) _it1 (void *key, void *value, void *user_data, KitHash *hash)
{ {
int *count = (int *) user_data; int *count = (int *) user_data;
*count += 1; *count += 1;
...@@ -480,7 +480,7 @@ _it1 (KitHash *hash, void *key, void *value, void *user_data) ...@@ -480,7 +480,7 @@ _it1 (KitHash *hash, void *key, void *value, void *user_data)
} }
static kit_bool_t static kit_bool_t
_it2 (KitHash *hash, void *key, void *value, void *user_data) _it2 (void *key, void *value, void *user_data, KitHash *hash)
{ {
int *count = (int *) user_data; int *count = (int *) user_data;
*count += 1; *count += 1;
...@@ -488,7 +488,7 @@ _it2 (KitHash *hash, void *key, void *value, void *user_data) ...@@ -488,7 +488,7 @@ _it2 (KitHash *hash, void *key, void *value, void *user_data)
} }
static kit_bool_t static kit_bool_t
_it_sum (KitHash *hash, void *key, void *value, void *user_data) _it_sum (void *key, void *value, void *user_data, KitHash *hash)
{ {
int *count = (int *) user_data; int *count = (int *) user_data;
*count += (int) value; *count += (int) value;
...@@ -496,7 +496,7 @@ _it_sum (KitHash *hash, void *key, void *value, void *user_data) ...@@ -496,7 +496,7 @@ _it_sum (KitHash *hash, void *key, void *value, void *user_data)
} }
static kit_bool_t static kit_bool_t
_it_rem (KitHash *hash, void *key, void *value, void *user_data) _it_rem (void *key, void *value, void *user_data, KitHash *hash)
{ {
if (strlen ((char *) key) > 4) if (strlen ((char *) key) > 4)
return TRUE; return TRUE;
......
...@@ -96,19 +96,19 @@ typedef void *(*KitCopyFunc) (const void *p); ...@@ -96,19 +96,19 @@ typedef void *(*KitCopyFunc) (const void *p);
/** /**
* KitHashForeachFunc: * KitHashForeachFunc:
* @hash: the hash table
* @key: key * @key: key
* @value: value * @value: value
* @user_data: user data passed to kit_hash_foreach() * @user_data: user data passed to kit_hash_foreach()
* @hash: the hash table
* *
* Type signature for callback function used in kit_hash_foreach(). * Type signature for callback function used in kit_hash_foreach().
* *
* Returns: Return #TRUE to short-circuit, e.g. stop the iteration. * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
*/ */
typedef kit_bool_t (*KitHashForeachFunc) (KitHash *hash, typedef kit_bool_t (*KitHashForeachFunc) (void *key,
void *key,
void *value, void *value,
void *user_data); void *user_data,
KitHash *hash);
KitHash *kit_hash_new (KitHashFunc hash_func, KitHash *kit_hash_new (KitHashFunc hash_func,
......
...@@ -232,7 +232,7 @@ kit_list_foreach (KitList *list, KitListForeachFunc func, void *user_data) ...@@ -232,7 +232,7 @@ kit_list_foreach (KitList *list, KitListForeachFunc func, void *user_data)
kit_return_val_if_fail (func != NULL, FALSE); kit_return_val_if_fail (func != NULL, FALSE);
for (l = list; l != NULL; l = l->next) { for (l = list; l != NULL; l = l->next) {
if (func (list, l->data, user_data)) if (func (l->data, user_data, list))
return TRUE; return TRUE;
} }
...@@ -248,7 +248,7 @@ typedef struct { ...@@ -248,7 +248,7 @@ typedef struct {
} _Closure; } _Closure;
static kit_bool_t static kit_bool_t
_sum (KitList *list, void *data, void *user_data) _sum (void *data, void *user_data, KitList *list)
{ {
_Closure *c = (_Closure*) user_data; _Closure *c = (_Closure*) user_data;
...@@ -259,7 +259,7 @@ _sum (KitList *list, void *data, void *user_data) ...@@ -259,7 +259,7 @@ _sum (KitList *list, void *data, void *user_data)
} }
static kit_bool_t static kit_bool_t
_sum2 (KitList *list, void *data, void *user_data) _sum2 (void *data, void *user_data, KitList *list)
{ {
_Closure *c = (_Closure*) user_data; _Closure *c = (_Closure*) user_data;
......
...@@ -57,17 +57,17 @@ struct _KitList { ...@@ -57,17 +57,17 @@ struct _KitList {
/** /**
* KitListForeachFunc: * KitListForeachFunc:
* @list: the list
* @data: data of link entry * @data: data of link entry
* @user_data: user data passed to kit_list_foreach() * @user_data: user data passed to kit_list_foreach()
* @list: the list
* *
* Type signature for callback function used in kit_list_foreach(). * Type signature for callback function used in kit_list_foreach().
* *
* Returns: Return #TRUE to short-circuit, e.g. stop the iteration. * Returns: Return #TRUE to short-circuit, e.g. stop the iteration.
*/ */
typedef kit_bool_t (*KitListForeachFunc) (KitList *list, typedef kit_bool_t (*KitListForeachFunc) (void *data,
void *data, void *user_data,
void *user_data); KitList *list);
KitList *kit_list_append (KitList *list, void *data); KitList *kit_list_append (KitList *list, void *data);
KitList *kit_list_prepend (KitList *list, void *data); KitList *kit_list_prepend (KitList *list, void *data);
......
...@@ -774,7 +774,7 @@ out: ...@@ -774,7 +774,7 @@ out:
} }
static kit_bool_t static kit_bool_t
_free_elem_in_list (KitList *list, void *data, void *user_data) _free_elem_in_list (void *data, void *user_data, KitList *list)
{ {
kit_free (data); kit_free (data);
return FALSE; return FALSE;
...@@ -1161,7 +1161,7 @@ polkit_tracker_init (PolKitTracker *pk_tracker) ...@@ -1161,7 +1161,7 @@ polkit_tracker_init (PolKitTracker *pk_tracker)
/*--------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------*/
static void static void
_set_session_inactive_iter (KitHash *hash, void *key, PolKitCaller *caller, const char *session_objpath) _set_session_inactive_iter (void *key, PolKitCaller *caller, const char *session_objpath, KitHash *hash)
{ {
char *objpath; char *objpath;
PolKitSession *session; PolKitSession *session;
...@@ -1175,7 +1175,7 @@ _set_session_inactive_iter (KitHash *hash, void *key, PolKitCaller *caller, cons ...@@ -1175,7 +1175,7 @@ _set_session_inactive_iter (KitHash *hash, void *key, PolKitCaller *caller, cons
} }
static void static void
_set_session_active_iter (KitHash *hash, void *key, PolKitCaller *caller, const char *session_objpath) _set_session_active_iter (void *key, PolKitCaller *caller, const char *session_objpath, KitHash *hash)
{ {
char *objpath; char *objpath;
PolKitSession *session; PolKitSession *session;
...@@ -1191,7 +1191,7 @@ _set_session_active_iter (KitHash *hash, void *key, PolKitCaller *caller, const ...@@ -1191,7 +1191,7 @@ _set_session_active_iter (KitHash *hash, void *key, PolKitCaller *caller, const
static void static void
_update_session_is_active (PolKitTracker *pk_tracker, const char *session_objpath, kit_bool_t is_active) _update_session_is_active (PolKitTracker *pk_tracker, const char *session_objpath, kit_bool_t is_active)
{ {
kit_hash_foreach (pk_tracker->dbus_name_to_caller, kit_hash_foreach (pk_tracker->dbus_name_to_caller,
(KitHashForeachFunc) (is_active ? _set_session_active_iter : _set_session_inactive_iter), (KitHashForeachFunc) (is_active ? _set_session_active_iter : _set_session_inactive_iter),
(void *) session_objpath); (void *) session_objpath);
} }
...@@ -1199,7 +1199,7 @@ _update_session_is_active (PolKitTracker *pk_tracker, const char *session_objpat ...@@ -1199,7 +1199,7 @@ _update_session_is_active (PolKitTracker *pk_tracker, const char *session_objpat
/*--------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------*/
static kit_bool_t static kit_bool_t
_remove_caller_by_session_iter (KitHash *hash, void *key, PolKitCaller *caller, const char *session_objpath) _remove_caller_by_session_iter (void *key, PolKitCaller *caller, const char *session_objpath, KitHash *hash)
{ {
char *objpath; char *objpath;
PolKitSession *session; PolKitSession *session;
...@@ -1223,7 +1223,7 @@ _remove_caller_by_session (PolKitTracker *pk_tracker, const char *session_objpat ...@@ -1223,7 +1223,7 @@ _remove_caller_by_session (PolKitTracker *pk_tracker, const char *session_objpat
/*--------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------*/
static kit_bool_t static kit_bool_t
_remove_caller_by_dbus_name_iter (KitHash *hash, void *key, PolKitCaller *caller, const char *dbus_name) _remove_caller_by_dbus_name_iter (void *key, PolKitCaller *caller, const char *dbus_name, KitHash *hash)
{ {
char *name; char *name;
if (!polkit_caller_get_dbus_name (caller, &name)) if (!polkit_caller_get_dbus_name (caller, &name))
...@@ -1236,9 +1236,9 @@ _remove_caller_by_dbus_name_iter (KitHash *hash, void *key, PolKitCaller *caller ...@@ -1236,9 +1236,9 @@ _remove_caller_by_dbus_name_iter (KitHash *hash, void *key, PolKitCaller *caller
static void static void
_remove_caller_by_dbus_name (PolKitTracker *pk_tracker, const char *dbus_name) _remove_caller_by_dbus_name (PolKitTracker *pk_tracker, const char *dbus_name)
{ {
kit_hash_foreach_remove (pk_tracker->dbus_name_to_caller, kit_hash_foreach_remove (pk_tracker->dbus_name_to_caller,
(KitHashForeachFunc) _remove_caller_by_dbus_name_iter, (KitHashForeachFunc) _remove_caller_by_dbus_name_iter,
(void *) dbus_name); (void *) dbus_name);
} }
/*--------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------*/
......
...@@ -77,7 +77,7 @@ struct _PolKitAuthorizationDB; ...@@ -77,7 +77,7 @@ struct _PolKitAuthorizationDB;
/* PolKitAuthorizationDB structure is defined in polkit/polkit-private.h */ /* PolKitAuthorizationDB structure is defined in polkit/polkit-private.h */
static kit_bool_t static kit_bool_t
clear_auth (KitList *list, void *data, void *user_data) clear_auth (void *data, void *user_data, KitList *list)
{ {
PolKitAuthorization *auth = (PolKitAuthorization *) data; PolKitAuthorization *auth = (PolKitAuthorization *) data;
polkit_authorization_unref (auth); polkit_authorization_unref (auth);
......
...@@ -558,10 +558,10 @@ typedef struct { ...@@ -558,10 +558,10 @@ typedef struct {
} _AnnotationsClosure; } _AnnotationsClosure;
static polkit_bool_t static polkit_bool_t
_annotations_cb (KitHash *hash, _annotations_cb (void *key,
void *key,
void *value, void *value,
void *user_data) void *user_data,
KitHash *hash)
{ {
_AnnotationsClosure *closure = user_data; _AnnotationsClosure *closure = user_data;
return closure->cb (closure->pfe, (const char *) key, (const char *) value, closure->user_data); return closure->cb (closure->pfe, (const char *) key, (const char *) value, closure->user_data);
...@@ -593,8 +593,8 @@ polkit_policy_file_entry_annotations_foreach (PolKitPolicyFileEntry *policy_file ...@@ -593,8 +593,8 @@ polkit_policy_file_entry_annotations_foreach (PolKitPolicyFileEntry *policy_file
closure.user_data = user_data; closure.user_data = user_data;
return kit_hash_foreach (policy_file_entry->annotations, return kit_hash_foreach (policy_file_entry->annotations,
_annotations_cb, _annotations_cb,
&closure); &closure);
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment