PERL PERL5 CHANGES 12 CHANGE 23259 INTEGRATE
Date: Sat, 4 Sep 2004 13:15:00 -0700

Subject: Change 23259: Integrate:
From: nick@no-spam (Nicholas Clark)

Change 23259 by nicholas@no-spam on 2004/09/04 19:40:24

Integrate:
[ 22969]
Abolish the "Tied variable freed while still in use" error - I have a way to cleanly avoid the coredump.

[ 23040]
t/op/tie.t test 23 is failing when run with utf8 everywhere.
Problem appears to be due to theft of temporaries
Affected files ...

... //depot/maint-5.8/perl/mg.c#43 integrate ... //depot/maint-5.8/perl/pod/perldiag.pod#60 integrate ... //depot/maint-5.8/perl/t/op/tie.t#13 integrate
Differences ...

==== //depot/maint-5.8/perl/mg.c#43 (text) ====
Index: perl/mg.c --- perl/mg.c#42~23017~ Wed Jun 30 13:28:29 2004
+++ perl/mg.c Sat Sep 4 12:40:24 2004
@@no-spam -124,6 +124,18 @@no-spam int new = 0;
MAGIC *newmg, *head, *cur, *mg;
I32 mgs_ix = SSNEW(sizeof(MGS));
+ int was_temp = SvTEMP(sv);
+ /* guard against sv having being freed midway by holding a private + reference. */
+
+ /* sv_2mortal has this side effect of turning on the TEMP flag, which can + cause the SV's buffer to get stolen (and maybe other stuff).
+ So restore it.
+ */
+ sv_2mortal(SvREFCNT_inc(sv));
+ if (!was_temp) {
+ SvTEMP_off(sv);
+ }
save_magic(mgs_ix, sv);
@@no-spam -138,10 +150,6 @@no-spam if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) {
CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg);
- /* guard against sv having been freed */
- if (SvTYPE(sv) == SVTYPEMASK) {
- Perl_croak(aTHX_ "Tied variable freed while still in use");
- }
/* guard against magic having been deleted - eg FETCH calling * untie */
if (!SvMAGIC(sv))
@@no-spam -173,6 +181,12 @@no-spam }
restore_magic(aTHX_ INT2PTR(void *, (IV)mgs_ix));
+
+ if (SvREFCNT(sv) == 1) {
+ /* We hold the last reference to this SV, which implies that the + SV was deleted as a side effect of the routines we called. */
+ SvOK_off(sv);
+ }
return 0;
}

==== //depot/maint-5.8/perl/pod/perldiag.pod#60 (text) ====
Index: perl/pod/perldiag.pod --- perl/pod/perldiag.pod#59~23033~ Sun Jul 4 13:12:51 2004
+++ perl/pod/perldiag.pod Sat Sep 4 12:40:24 2004
@@no-spam -3703,12 +3703,6 @@no-spam are deprecated and one should use the new ithreads instead,
see L<perl58delta> for more details.
-=item Tied variable freed while still in use -
-(F) An access method for a tied variable (e.g. FETCH) did something to -free the variable. Since continuing the current operation is likely -to result in a coredump, Perl is bailing out instead.
-
=item times not implemented (F) Your version of the C library apparently doesn't do times(). I
==== //depot/maint-5.8/perl/t/op/tie.t#13 (xtext) ====
Index: perl/t/op/tie.t --- perl/t/op/tie.t#12~23017~ Wed Jun 30 13:28:29 2004
+++ perl/t/op/tie.t Sat Sep 4 12:40:24 2004
@@no-spam -294,7 +294,6 @@no-spam tie $a, 'main';
print $a;
EXPECT -Tied variable freed while still in use at - line 6.
########
# [20020716.007] - nested FETCHES End of Patch.