From: Sergey Bugaev Date: Sat, 7 Jun 2025 20:06:24 +0000 (+0300) Subject: gvariant: Use actual destroy_func when creating GHashTable X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=3124b36ac8fa57ea260bc6ba204d5669af9e5671;p=thirdparty%2Fvala.git gvariant: Use actual destroy_func when creating GHashTable Instead of hard-coding a few known types, use the actual destroy_func for the type. This will now do the right thing for (nullable) structs. --- diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala index af90ad4da..9254e6878 100644 --- a/codegen/valagvariantmodule.vala +++ b/codegen/valagvariantmodule.vala @@ -509,25 +509,9 @@ public class Vala.GVariantModule : GValueModule { hash_table_new.add_argument (new CCodeIdentifier ("g_direct_equal")); } - if (key_type.type_symbol.is_subtype_of (string_type.type_symbol)) { - hash_table_new.add_argument (new CCodeIdentifier ("g_free")); - } else if (key_type.type_symbol == gvariant_type) { - hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier ("g_variant_unref"), "GDestroyNotify")); - } else if (key_type.type_symbol.get_full_name () == "GLib.HashTable") { - hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier ("g_hash_table_unref"), "GDestroyNotify")); - } else { - hash_table_new.add_argument (new CCodeConstant ("NULL")); - } + hash_table_new.add_argument (new CCodeCastExpression (get_destroy_func_expression (key_type), "GDestroyNotify")); + hash_table_new.add_argument (new CCodeCastExpression (get_destroy_func_expression (value_type), "GDestroyNotify")); - if (value_type.type_symbol.is_subtype_of (string_type.type_symbol)) { - hash_table_new.add_argument (new CCodeIdentifier ("g_free")); - } else if (value_type.type_symbol == gvariant_type) { - hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier ("g_variant_unref"), "GDestroyNotify")); - } else if (value_type.type_symbol.get_full_name () == "GLib.HashTable") { - hash_table_new.add_argument (new CCodeCastExpression (new CCodeIdentifier ("g_hash_table_unref"), "GDestroyNotify")); - } else { - hash_table_new.add_argument (new CCodeConstant ("NULL")); - } ccode.add_assignment (new CCodeIdentifier (temp_name), hash_table_new); var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_init")); diff --git a/tests/basic-types/gvariants-unboxing-safe.c-expected b/tests/basic-types/gvariants-unboxing-safe.c-expected index 2c587db10..ffc466986 100644 --- a/tests/basic-types/gvariants-unboxing-safe.c-expected +++ b/tests/basic-types/gvariants-unboxing-safe.c-expected @@ -434,7 +434,7 @@ _variant_get10 (GVariant* value) GVariant* _tmp3_; GVariant* _tmp4_; GHashTable* _tmp5_; - _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_free); g_variant_iter_init (&_tmp2_, value); while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { g_hash_table_insert (_tmp1_, g_variant_dup_string (_tmp3_, NULL), g_variant_dup_string (_tmp4_, NULL)); @@ -459,7 +459,7 @@ _variant_get11 (GVariant* value) GVariant* _tmp3_; GVariant* _tmp4_; GHashTable* _tmp5_; - _tmp1_ = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + _tmp1_ = g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify) NULL, (GDestroyNotify) g_free); g_variant_iter_init (&_tmp2_, value); while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { g_hash_table_insert (_tmp1_, (gpointer) ((gintptr) g_variant_get_int32 (_tmp3_)), g_variant_dup_string (_tmp4_, NULL)); diff --git a/tests/dbus/bug782719_client.c-expected b/tests/dbus/bug782719_client.c-expected index d30165898..018119ead 100644 --- a/tests/dbus/bug782719_client.c-expected +++ b/tests/dbus/bug782719_client.c-expected @@ -199,14 +199,14 @@ test_proxy_test_nested_dict (Test* self, } g_variant_iter_init (&_reply_iter, _reply); _tmp0_ = g_variant_iter_next_value (&_reply_iter); - _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref); + _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_hash_table_unref); g_variant_iter_init (&_tmp2_, _tmp0_); while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { GHashTable* _tmp5_; GVariantIter _tmp6_; GVariant* _tmp7_; GVariant* _tmp8_; - _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_variant_unref); g_variant_iter_init (&_tmp6_, _tmp4_); while (g_variant_iter_loop (&_tmp6_, "{?*}", &_tmp7_, &_tmp8_)) { g_hash_table_insert (_tmp5_, g_variant_dup_string (_tmp7_, NULL), g_variant_get_variant (_tmp8_)); diff --git a/tests/dbus/dicts_client.c-expected b/tests/dbus/dicts_client.c-expected index fdb305a2d..9e12f1f56 100644 --- a/tests/dbus/dicts_client.c-expected +++ b/tests/dbus/dicts_client.c-expected @@ -229,7 +229,7 @@ test_proxy_test_dict (Test* self, } g_variant_iter_init (&_reply_iter, _reply); _tmp0_ = g_variant_iter_next_value (&_reply_iter); - _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_variant_unref); g_variant_iter_init (&_tmp2_, _tmp0_); while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { g_hash_table_insert (_tmp1_, g_variant_dup_string (_tmp3_, NULL), g_variant_get_variant (_tmp4_)); diff --git a/tests/dbus/dicts_server.c-expected b/tests/dbus/dicts_server.c-expected index 5a5b6c499..c9d11fb7b 100644 --- a/tests/dbus/dicts_server.c-expected +++ b/tests/dbus/dicts_server.c-expected @@ -605,7 +605,7 @@ test_interface_bar_proxy_foo (TestInterfaceBar* self, } g_variant_iter_init (&_reply_iter, _reply); _tmp4_ = g_variant_iter_next_value (&_reply_iter); - _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_variant_unref); g_variant_iter_init (&_tmp6_, _tmp4_); while (g_variant_iter_loop (&_tmp6_, "{?*}", &_tmp7_, &_tmp8_)) { g_hash_table_insert (_tmp5_, g_variant_dup_string (_tmp7_, NULL), g_variant_get_variant (_tmp8_)); diff --git a/tests/dbus/type-mismatch_client.c-expected b/tests/dbus/type-mismatch_client.c-expected index 734722ffa..c378fdb98 100644 --- a/tests/dbus/type-mismatch_client.c-expected +++ b/tests/dbus/type-mismatch_client.c-expected @@ -759,7 +759,7 @@ _dbus_test_out_mismatch (Test* self, _ready_data->a = g_variant_get_int32 (_tmp20_); g_variant_unref (_tmp20_); _tmp21_ = g_variant_iter_next_value (&_arguments_iter); - _tmp22_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp22_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp23_, _tmp21_); while (g_variant_iter_loop (&_tmp23_, "{?*}", &_tmp24_, &_tmp25_)) { g_hash_table_insert (_tmp22_, g_variant_dup_string (_tmp24_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp25_))); @@ -827,7 +827,7 @@ _dbus_test_in_mismatch (Test* self, _ready_data->a = g_variant_get_int32 (_tmp26_); g_variant_unref (_tmp26_); _tmp27_ = g_variant_iter_next_value (&_arguments_iter); - _tmp28_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp28_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp29_, _tmp27_); while (g_variant_iter_loop (&_tmp29_, "{?*}", &_tmp30_, &_tmp31_)) { g_hash_table_insert (_tmp28_, g_variant_dup_string (_tmp30_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp31_))); @@ -895,7 +895,7 @@ _dbus_test_out_mismatch_nothrow (Test* self, _ready_data->a = g_variant_get_int32 (_tmp32_); g_variant_unref (_tmp32_); _tmp33_ = g_variant_iter_next_value (&_arguments_iter); - _tmp34_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp34_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp35_, _tmp33_); while (g_variant_iter_loop (&_tmp35_, "{?*}", &_tmp36_, &_tmp37_)) { g_hash_table_insert (_tmp34_, g_variant_dup_string (_tmp36_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp37_))); diff --git a/tests/dbus/type-mismatch_server.c-expected b/tests/dbus/type-mismatch_server.c-expected index 196430166..161efe429 100644 --- a/tests/dbus/type-mismatch_server.c-expected +++ b/tests/dbus/type-mismatch_server.c-expected @@ -445,7 +445,7 @@ _dbus_test_out_mismatch (Test* self, a = g_variant_get_int32 (_tmp0_); g_variant_unref (_tmp0_); _tmp1_ = g_variant_iter_next_value (&_arguments_iter); - _tmp2_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp2_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp3_, _tmp1_); while (g_variant_iter_loop (&_tmp3_, "{?*}", &_tmp4_, &_tmp5_)) { g_hash_table_insert (_tmp2_, g_variant_dup_string (_tmp4_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp5_))); @@ -497,7 +497,7 @@ _dbus_test_in_mismatch (Test* self, a = g_variant_get_int64 (_tmp6_); g_variant_unref (_tmp6_); _tmp7_ = g_variant_iter_next_value (&_arguments_iter); - _tmp8_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp8_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp9_, _tmp7_); while (g_variant_iter_loop (&_tmp9_, "{?*}", &_tmp10_, &_tmp11_)) { g_hash_table_insert (_tmp8_, g_variant_dup_string (_tmp10_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp11_))); @@ -550,7 +550,7 @@ _dbus_test_out_mismatch_nothrow (Test* self, a = g_variant_get_int32 (_tmp12_); g_variant_unref (_tmp12_); _tmp13_ = g_variant_iter_next_value (&_arguments_iter); - _tmp14_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + _tmp14_ = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); g_variant_iter_init (&_tmp15_, _tmp13_); while (g_variant_iter_loop (&_tmp15_, "{?*}", &_tmp16_, &_tmp17_)) { g_hash_table_insert (_tmp14_, g_variant_dup_string (_tmp16_, NULL), (gpointer) ((gintptr) g_variant_get_int32 (_tmp17_)));