diff options
author | Owen Taylor <owt1@cornell.edu> | 1997-12-19 06:31:36 -0500 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1998-01-08 12:23:41 +0000 |
commit | 0a0bb7c7269ef911ca3981a2b5365150a9ad4cfe (patch) | |
tree | d705de331a8d0605d46aa872fb82c0a09f2e94ba /hv.c | |
parent | 8cd305a30c9816c0c0e4535a1f79fd802d791fb4 (diff) | |
download | perl-0a0bb7c7269ef911ca3981a2b5365150a9ad4cfe.tar.gz |
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
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 46 |
1 files changed, 30 insertions, 16 deletions
@@ -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')) { |