[json-glib/wip/ordered-iter] Assert that foreach_member() won't mutate the object
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib/wip/ordered-iter] Assert that foreach_member() won't mutate the object
- Date: Mon, 24 Aug 2020 14:19:11 +0000 (UTC)
commit 9d31efb712ab43035163d46e34d020f0febb7e02
Author: Emmanuele Bassi <ebassi gnome org>
Date: Mon Aug 24 12:42:58 2020 +0100
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(+)
---
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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]