X-Git-Url: https://git.gag.com/?p=debian%2Famanda;a=blobdiff_plain;f=perl%2Famglue%2Fghashtable.c;h=50d493ff606b2b670e1652b463cc35b2fdd9441c;hp=6ef2e94a45f058bf565266cd657efea527ec6779;hb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e diff --git a/perl/amglue/ghashtable.c b/perl/amglue/ghashtable.c index 6ef2e94..50d493f 100644 --- a/perl/amglue/ghashtable.c +++ b/perl/amglue/ghashtable.c @@ -21,6 +21,11 @@ #include "amglue.h" #include "conffile.h" +/* PERL_MAGIC_tied is not defined in perl 5.6 */ +#if !defined PERL_MAGIC_tied +#define PERL_MAGIC_tied 'P' +#endif + static void foreach_fn(gpointer key_p, gpointer value_p, gpointer user_data_p) { @@ -75,6 +80,7 @@ foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p) HV *hv = user_data_p; AV *list = newAV(); HV *property_hv = newHV(); + SV *val; hv_store(property_hv, "append", strlen("append"), newSViv(property->append), 0); hv_store(property_hv, "priority", strlen("priority"), newSViv(property->priority), 0); @@ -83,14 +89,26 @@ foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p) } hv_store(property_hv, "values", strlen("values"), newRV_noinc((SV*)list), 0); - hv_store(hv, key, strlen(key), newRV_noinc((SV*)property_hv), 0); + val = newRV_noinc((SV*)property_hv); + hv_store(hv, key, strlen(key), val, 0); + mg_set(val); + SvREFCNT_dec(val); } SV * g_hash_table_to_hashref_property(GHashTable *hash) { - HV *hv = (HV *)sv_2mortal((SV *)newHV()); + HV *hv; + HV *stash; + SV *tie; + + hv = newHV(); + tie = newRV_noinc((SV*)newHV()); + stash = gv_stashpv("Amanda::Config::FoldingHash", GV_ADD); + sv_bless(tie, stash); + hv_magic(hv, (GV*)tie, PERL_MAGIC_tied); + hv = (HV *)sv_2mortal((SV *)hv); g_hash_table_foreach(hash, foreach_fn_property, hv); return newRV((SV *)hv);