summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorOwen Taylor <owt1@cornell.edu>1997-11-21 17:28:17 -0500
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-11-25 15:49:22 +0000
commitd0066dc7de72349a42c2c47e1fc66da2ba66542a (patch)
tree5932be96c8460e30d3bf05633a3cd8d63a835473 /hv.c
parentdd4ea8b47491cf43b89a153ec2b48cb3ffade15b (diff)
downloadperl-d0066dc7de72349a42c2c47e1fc66da2ba66542a.tar.gz
Make hv_ functions cope better with 'm'-magic:
Subject: [5.004_54] Another neglected patch p4raw-id: //depot/perl@298
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/hv.c b/hv.c
index f3ab6ccbb9..dfa0498baa 100644
--- a/hv.c
+++ b/hv.c
@@ -216,6 +216,30 @@ hv_fetch_ent(HV *hv, SV *keysv, I32 lval, register U32 hash)
return 0;
}
+static void
+hv_magic_check (hv, needs_copy, needs_store)
+HV *hv;
+bool *needs_copy;
+bool *needs_store;
+{
+ MAGIC *mg = SvMAGIC(hv);
+ *needs_copy = FALSE;
+ *needs_store = TRUE;
+ while (mg) {
+ if (isUPPER(mg->mg_type)) {
+ *needs_copy = TRUE;
+ switch (mg->mg_type) {
+ case 'P':
+ case 'I':
+ case 'S':
+ *needs_store = FALSE;
+ default:
+ }
+ }
+ mg = mg->mg_moremagic;
+ }
+}
+
SV**
hv_store(HV *hv, char *key, U32 klen, SV *val, register U32 hash)
{
@@ -229,15 +253,14 @@ hv_store(HV *hv, char *key, U32 klen, SV *val, register U32 hash)
xhv = (XPVHV*)SvANY(hv);
if (SvMAGICAL(hv)) {
- mg_copy((SV*)hv, val, key, klen);
- if (!xhv->xhv_array
- && (SvMAGIC(hv)->mg_moremagic
- || (SvMAGIC(hv)->mg_type != 'E'
-#ifdef OVERLOAD
- && SvMAGIC(hv)->mg_type != 'A'
-#endif /* OVERLOAD */
- )))
- return 0;
+ bool needs_copy;
+ bool needs_store;
+ hv_magic_check (hv, &needs_copy, &needs_store);
+ if (needs_copy) {
+ mg_copy((SV*)hv, val, key, klen);
+ if (!xhv->xhv_array && !needs_store)
+ return 0;
+ }
}
if (!hash)
PERL_HASH(hash, key, klen);
@@ -295,20 +318,19 @@ hv_store_ent(HV *hv, SV *keysv, SV *val, register U32 hash)
xhv = (XPVHV*)SvANY(hv);
if (SvMAGICAL(hv)) {
dTHR;
- bool save_taint = tainted;
- if (tainting)
- tainted = SvTAINTED(keysv);
- keysv = sv_2mortal(newSVsv(keysv));
- mg_copy((SV*)hv, val, (char*)keysv, HEf_SVKEY);
- TAINT_IF(save_taint);
- if (!xhv->xhv_array
- && (SvMAGIC(hv)->mg_moremagic
- || (SvMAGIC(hv)->mg_type != 'E'
-#ifdef OVERLOAD
- && SvMAGIC(hv)->mg_type != 'A'
-#endif /* OVERLOAD */
- )))
- return Nullhe;
+ bool needs_copy;
+ bool needs_store;
+ hv_magic_check (hv, &needs_copy, &needs_store);
+ if (needs_copy) {
+ bool save_taint = tainted;
+ if (tainting)
+ tainted = SvTAINTED(keysv);
+ keysv = sv_2mortal(newSVsv(keysv));
+ mg_copy((SV*)hv, val, (char*)keysv, HEf_SVKEY);
+ TAINT_IF(save_taint);
+ if (!xhv->xhv_array && !needs_store)
+ return Nullhe;
+ }
}
key = SvPV(keysv, klen);