From 3978fc21c75f527f1220c15c9e2427c6a0b7a08d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 24 Aug 2020 12:42:58 +0100 Subject: Assert that foreach_member() won't mutate the object We document that it's not safe, but we kind of rely on GHashTable to do that for us. Instead, let's use the newly added age field to protect against accidental mutations during iteration, just like we do for the iterator API. --- json-glib/json-object.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'json-glib/json-object.c') diff --git a/json-glib/json-object.c b/json-glib/json-object.c index a17fd6d..8555eb9 100644 --- a/json-glib/json-object.c +++ b/json-glib/json-object.c @@ -968,16 +968,21 @@ json_object_foreach_member (JsonObject *object, gpointer data) { GList *l; + int age; g_return_if_fail (object != NULL); g_return_if_fail (func != NULL); + age = object->age; + for (l = object->members_ordered.head; l != NULL; l = l->next) { const gchar *member_name = l->data; JsonNode *member_node = g_hash_table_lookup (object->members, member_name); func (object, member_name, member_node, data); + + g_assert (object->age == age); } } -- cgit v1.2.1