develooper Front page | perl.perl5.porters | Postings from April 2003

Re: [perl #17040] Storable can'T store self-tied objects

Thread Previous
From:
Abhijit Menon-Sen
Date:
April 15, 2003 20:46
Subject:
Re: [perl #17040] Storable can'T store self-tied objects
Message ID:
20030416091631.A21676@lustre.dyn.wiw.org
At 2002-09-05 20:38:26 -0000, perlbug@perl.org wrote:
>
> Storable segfaults because mg_obj is 0 for self-tied objects:

Change 19227 by ams@lustre on 2003/04/16 02:32:11

	[#17040] Storable now handles self-tied scalars with NULL mg_obj.

Affected files ...

... //depot/perl/ext/Storable/Storable.xs#70 edit

Differences ...

==== //depot/perl/ext/Storable/Storable.xs#70 (text) ====
Index: perl/ext/Storable/Storable.xs
--- perl/ext/Storable/Storable.xs#69~18904~	Tue Mar 11 11:03:10 2003
+++ perl/ext/Storable/Storable.xs	Wed Apr 16 08:02:11 2003
@@ -2475,6 +2475,7 @@
 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 @@
 	 * 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_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)));

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About