cvs commit: ponie/perl mg.c
[email protected] (Nicholas Clark) 19 Jun 2004 14:06:13 -0000
| Newsgroups | perl.ponie.changes |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 04/06/19 07:06:12
Modified: perl mg.c
Log:
All checking of SvTYPEMASK is evil.
Avoid using it to check if a tied variable has already been freed by keeping
our own private reference.
(stops t/op/tie.t failing on OS X, and spewing valgrind errors on x86 Linux)
Revision Changes Path
1.5 +9 -1 ponie/perl/mg.c
Index: mg.c
===================================================================
RCS file: /cvs/public/ponie/perl/mg.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- mg.c 7 Apr 2004 10:37:27 -0000 1.4
+++ mg.c 19 Jun 2004 14:06:12 -0000 1.5
@@ -129,6 +129,8 @@
int new = 0;
MAGIC *newmg, *head, *cur, *mg;
I32 mgs_ix = SSNEW(sizeof(MGS));
+ /* Make sure this sv doesn't get freed underneath us. */
+ SvREFCNT_inc(sv);
{
save_magic(mgs_ix, sv);
@@ -145,9 +147,10 @@
CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg);
/* guard against sv having been freed */
- if (SvTYPE(sv) == SVTYPEMASK) {
+ if (SvREFCNT(sv) == 1) {
Perl_croak(aTHX_ "Tied variable freed while still in use");
}
+ assert (SvREFCNT(sv) > 1);
/* guard against magic having been deleted - eg FETCH calling
* untie */
if (!SvMAGIC(sv))
@@ -180,6 +183,11 @@
restore_magic(aTHX_ INT2PTR(void *, (IV)mgs_ix));
}
+ /* I guess that this will leak if something in the middle goes croak. */
+ /* It's not possible to make this sv mortal without failing several tests -
+ looks like it's important that it can get DESTROYed before the next
+ FREETMPS */
+ SvREFCNT_dec(sv);
return 0;
}