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

Re: [ID 20000409.003] Disappearing constant values [PATCH]

Thread Previous | Thread Next
From:
Eric Blood
Date:
April 10, 2000 20:28
Subject:
Re: [ID 20000409.003] Disappearing constant values [PATCH]
Message ID:
000401bfa365$f036a280$0101000a@tlizard.xmission.com
On Monday, April 10, 2000 12:48 AM, "Gurusamy Sarathy" 
<gsar@ActiveState.com> wrote:
> On Sun, 09 Apr 2000 22:21:27 MDT, eric@xmission.com wrote:
> >[excellent analysis snipped]
> >
> >These are the possibilities I see:
> >
> >  1. Have the tokenizer always create a new SV for constant subs.
> >  2. Have peek copy the constant instead of using it directly when
> >     it moves it to the pad.
> >  3. Have pad_free never remove the flags when both SVs_PADTMP and
> >     SVs_READONLY are set.
> >  4. Have pad_free only remove the flags when the reference count
> >     for the SV is 1.
> >
> >I lean towards 4 or 2.  I think that 4 would be safe but it might
> >not always free up a pad slot when it should.  2 should also be
> >safe but would cause additional memory usage.
> 
> I'd say peek() should make a copy when moving it to the pad if the
> SV is already a PADTMP.
> 

Sounds good.  Here's the patch.

--- op.c~ Fri Mar 24 22:24:40 2000
+++ op.c Mon Apr 10 21:17:16 2000
@@ -6417,10 +6417,17 @@
       * for reference counts, sv_upgrade() etc. */
      if (cSVOP->op_sv) {
   PADOFFSET ix = pad_alloc(OP_CONST, SVs_PADTMP);
-  SvREFCNT_dec(PL_curpad[ix]);
-  SvPADTMP_on(cSVOPo->op_sv);
-  PL_curpad[ix] = cSVOPo->op_sv;
-  cSVOPo->op_sv = Nullsv;
+  if (SvPADTMP(cSVOPo->op_sv)) {
+    /* If op_sv is already a PADTMP then it is being used by */
+    /* another pad so make a copy.                           */
+    sv_setsv(PL_curpad[ix],cSVOPo->op_sv);
+    SvREADONLY_on(PL_curpad[ix]);
+  } else {
+    SvREFCNT_dec(PL_curpad[ix]);
+    SvPADTMP_on(cSVOPo->op_sv);
+    PL_curpad[ix] = cSVOPo->op_sv;
+    cSVOPo->op_sv = Nullsv;
+  }
   o->op_targ = ix;
      }
 #endif



Thread Previous | Thread Next


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