From 0a0bb7c7269ef911ca3981a2b5365150a9ad4cfe Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Fri, 19 Dec 1997 06:31:36 -0500 Subject: [PATCH] Fix hv_delete for 'm'-magic. Based on following patch, modified to cope with ENV_IS_CASELESS: Subject: [perl5.004_56] [PATCH] hv_delete and 'm' magic p4raw-id: //depot/perl@398 --- hv.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/hv.c b/hv.c index add7a39..d973ea8 100644 --- a/hv.c +++ b/hv.c @@ -257,7 +257,6 @@ hv_magic_check (HV *hv, bool *needs_copy, bool *needs_store) *needs_copy = TRUE; switch (mg->mg_type) { case 'P': - case 'I': case 'S': *needs_store = FALSE; } @@ -429,15 +428,21 @@ hv_delete(HV *hv, char *key, U32 klen, I32 flags) if (!hv) return Nullsv; if (SvRMAGICAL(hv)) { - sv = *hv_fetch(hv, key, klen, TRUE); - mg_clear(sv); - if (mg_find(sv, 's')) { - return Nullsv; /* %SIG elements cannot be deleted */ - } - else if (mg_find(sv, 'p')) { - sv_unmagic(sv, 'p'); /* No longer an element */ - return sv; - } + bool needs_copy; + bool needs_store; + hv_magic_check (hv, &needs_copy, &needs_store); + + if (needs_copy) { + sv = *hv_fetch(hv, key, klen, TRUE); + mg_clear(sv); + if (!needs_store) { + if (mg_find(sv, 'p')) { + sv_unmagic(sv, 'p'); /* No longer an element */ + return sv; + } + return Nullsv; /* element cannot be deleted */ + } + } #ifdef ENV_IS_CASELESS else if (mg_find((SV*)hv,'E')) { sv = sv_2mortal(newSVpv(key,klen)); @@ -492,12 +497,21 @@ hv_delete_ent(HV *hv, SV *keysv, I32 flags, U32 hash) if (!hv) return Nullsv; if (SvRMAGICAL(hv)) { - entry = hv_fetch_ent(hv, keysv, TRUE, hash); - sv = HeVAL(entry); - mg_clear(sv); - if (mg_find(sv, 'p')) { - sv_unmagic(sv, 'p'); /* No longer an element */ - return sv; + bool needs_copy; + bool needs_store; + hv_magic_check (hv, &needs_copy, &needs_store); + + if (needs_copy) { + entry = hv_fetch_ent(hv, keysv, TRUE, hash); + sv = HeVAL(entry); + mg_clear(sv); + if (!needs_store) { + if (mg_find(sv, 'p')) { + sv_unmagic(sv, 'p'); /* No longer an element */ + return sv; + } + return Nullsv; /* element cannot be deleted */ + } } #ifdef ENV_IS_CASELESS else if (mg_find((SV*)hv,'E')) { -- 2.7.4