cvs commit: ponie/perl scope.c

[email protected] (Nicholas Clark) 9 Apr 2004 16:06:35 -0000
Newsgroups perl.ponie.changes
Message-ID <[email protected]>
cvsuser     04/04/09 09:06:35

  Modified:    perl     scope.c
  Log:
  During global destruction it appears that sometimes items restored from the
  save stack can turn out to be already destroyed. Cope with this.
  
  [Not sure if I'm concealing a real perl bug, as whatever is coming off the
  save stack wasn't actually ever a PMC]
  
  Revision  Changes    Path
  1.2       +17 -5     ponie/perl/scope.c
  
  Index: scope.c
  ===================================================================
  RCS file: /cvs/public/ponie/perl/scope.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- scope.c	9 Sep 2003 11:58:55 -0000	1.1
  +++ scope.c	9 Apr 2004 16:06:35 -0000	1.2
  @@ -1,7 +1,7 @@
   /*    scope.c
    *
    *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
  - *    2000, 2001, 2002, 2003, by Larry Wall and others
  + *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
    *
    *    You may distribute under the terms of either the GNU General Public
    *    License or the Artistic License, as specified in the README file.
  @@ -199,9 +199,9 @@
   
       sv = *sptr = NEWSV(0,0);
       if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
  +	MAGIC *mg;
   	sv_upgrade(sv, SvTYPE(osv));
   	if (SvGMAGICAL(osv)) {
  -	    MAGIC* mg;
   	    bool oldtainted = PL_tainted;
   	    mg_get(osv);		/* note, can croak! */
   	    if (PL_tainting && PL_tainted &&
  @@ -214,7 +214,17 @@
   	    PL_tainted = oldtainted;
   	}
   	SvMAGIC(sv) = SvMAGIC(osv);
  -	SvFLAGS(sv) |= SvMAGICAL(osv) | SvREADONLY(osv);
  +	/* if it's a special scalar or if it has no 'set' magic,
  +	 * propagate the SvREADONLY flag. --rgs 20030922 */
  +	for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
  +	    if (SvMAGIC(sv)->mg_type == '\0'
  +		    || !SvMAGIC(sv)->mg_virtual->svt_set)
  +	    {
  +		SvFLAGS(sv) |= SvREADONLY(osv);
  +		break;
  +	    }
  +	}
  +	SvFLAGS(sv) |= SvMAGICAL(osv);
   	/* XXX SvMAGIC() is *shared* between osv and sv.  This can
   	 * lead to coredumps when both SVs are destroyed without one
   	 * of their SvMAGIC() slots being NULLed. */
  @@ -772,8 +782,8 @@
   		 * mg_get() in save_scalar_at() croaked */
   		SvMAGIC(value) = 0;
   	    }
  -	    SvREFCNT_dec(sv);
   	    *(SV**)ptr = value;
  +	    SvREFCNT_dec(sv);
   	    PL_localizing = 2;
   	    SvSETMAGIC(value);
   	    PL_localizing = 0;
  @@ -1035,8 +1045,10 @@
   	    break;
   	case SAVEt_COMPPAD:
   	    PL_comppad = (PAD*)SSPOPPTR;
  -	    if (PL_comppad)
  +	    if (PL_comppad && SvTYPE(PL_comppad) != SVTYPEMASK) {
  +		assert(SvTYPE(PL_comppad) == SVt_PVAV);
   		PL_curpad = AvARRAY(PL_comppad);
  +	    }
   	    else
   		PL_curpad = Null(SV**);
   	    break;