summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@wiw.org>2003-04-16 02:32:11 +0000
committerAbhijit Menon-Sen <ams@wiw.org>2003-04-16 02:32:11 +0000
commit72edffd8c9be795e5b3d054712ab905abfc441f0 (patch)
tree17dd31033964ff5549ad341692dd30b3474f618c
parent7e2c3868e4a7eef3080ba50609c91634f388dd28 (diff)
downloadperl-72edffd8c9be795e5b3d054712ab905abfc441f0.tar.gz
[#17040] Storable now handles self-tied scalars with NULL mg_obj.
p4raw-id: //depot/perl@19227
-rw-r--r--ext/Storable/Storable.xs21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/Storable/Storable.xs b/ext/Storable/Storable.xs
index f59316aef4..86f8b65752 100644
--- a/ext/Storable/Storable.xs
+++ b/ext/Storable/Storable.xs
@@ -2475,6 +2475,7 @@ static int store_code(stcxt_t *cxt, CV *cv)
static int store_tied(stcxt_t *cxt, SV *sv)
{
MAGIC *mg;
+ SV *obj = NULL;
int ret = 0;
int svt = SvTYPE(sv);
char mtype = 'P';
@@ -2520,7 +2521,9 @@ static int store_tied(stcxt_t *cxt, SV *sv)
* accesses on the retrieved object will indeed call the magic methods...
*/
- if ((ret = store(cxt, mg->mg_obj))) /* Extra () for -Wall, grr... */
+ /* [#17040] mg_obj is NULL for scalar self-ties. AMS 20030416 */
+ obj = mg->mg_obj ? mg->mg_obj : newSV(0);
+ if ((ret = store(cxt, obj)))
return ret;
TRACEME(("ok (tied)"));
@@ -4263,19 +4266,27 @@ static SV *retrieve_tied_hash(stcxt_t *cxt, char *cname)
static SV *retrieve_tied_scalar(stcxt_t *cxt, char *cname)
{
SV *tv;
- SV *sv;
+ SV *sv, *obj = NULL;
TRACEME(("retrieve_tied_scalar (#%d)", cxt->tagnum));
tv = NEWSV(10002, 0);
SEEN(tv, cname); /* Will return if rv is null */
sv = retrieve(cxt, 0); /* Retrieve <object> */
- if (!sv)
+ if (!sv) {
return (SV *) 0; /* Failed */
+ }
+ else if (SvTYPE(sv) != SVt_NULL) {
+ obj = sv;
+ }
sv_upgrade(tv, SVt_PVMG);
- sv_magic(tv, sv, 'q', Nullch, 0);
- SvREFCNT_dec(sv); /* Undo refcnt inc from sv_magic() */
+ sv_magic(tv, obj, 'q', Nullch, 0);
+
+ if (obj) {
+ /* Undo refcnt inc from sv_magic() */
+ SvREFCNT_dec(obj);
+ }
TRACEME(("ok (retrieve_tied_scalar at 0x%"UVxf")", PTR2UV(tv)));