if (growing++)
abort();
#endif
- stack_sp = sp;
- av_extend(curstack, (p - stack_base) + (n) + 128);
+ PL_stack_sp = sp;
+#ifndef STRESS_REALLOC
+ av_extend(PL_curstack, (p - PL_stack_base) + (n) + 128);
+#else
+ av_extend(PL_curstack, (p - PL_stack_base) + (n) + 1);
+#endif
#if defined(DEBUGGING) && !defined(USE_THREADS)
growing--;
#endif
- return stack_sp;
+ return PL_stack_sp;
+}
+
+#ifndef STRESS_REALLOC
+#define GROW(old) ((old) * 3 / 2)
+#else
+#define GROW(old) ((old) + 1)
+#endif
+
+PERL_SI *
+new_stackinfo(I32 stitems, I32 cxitems)
+{
+ PERL_SI *si;
+ PERL_CONTEXT *cxt;
+ New(56, si, 1, PERL_SI);
+ si->si_stack = newAV();
+ AvREAL_off(si->si_stack);
+ av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0);
+ AvALLOC(si->si_stack)[0] = &PL_sv_undef;
+ AvFILLp(si->si_stack) = 0;
+ si->si_prev = 0;
+ si->si_next = 0;
+ si->si_cxmax = cxitems - 1;
+ si->si_cxix = -1;
+ si->si_type = PERLSI_UNDEF;
+ New(56, si->si_cxstack, cxitems, PERL_CONTEXT);
+ return si;
}
I32
cxinc(void)
{
dTHR;
- cxstack_max = cxstack_max * 3 / 2;
+ cxstack_max = GROW(cxstack_max);
Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
return cxstack_ix + 1;
}
push_return(OP *retop)
{
dTHR;
- if (retstack_ix == retstack_max) {
- retstack_max = retstack_max * 3 / 2;
- Renew(retstack, retstack_max, OP*);
+ if (PL_retstack_ix == PL_retstack_max) {
+ PL_retstack_max = GROW(PL_retstack_max);
+ Renew(PL_retstack, PL_retstack_max, OP*);
}
- retstack[retstack_ix++] = retop;
+ PL_retstack[PL_retstack_ix++] = retop;
}
OP *
pop_return(void)
{
dTHR;
- if (retstack_ix > 0)
- return retstack[--retstack_ix];
+ if (PL_retstack_ix > 0)
+ return PL_retstack[--PL_retstack_ix];
else
return Nullop;
}
push_scope(void)
{
dTHR;
- if (scopestack_ix == scopestack_max) {
- scopestack_max = scopestack_max * 3 / 2;
- Renew(scopestack, scopestack_max, I32);
+ if (PL_scopestack_ix == PL_scopestack_max) {
+ PL_scopestack_max = GROW(PL_scopestack_max);
+ Renew(PL_scopestack, PL_scopestack_max, I32);
}
- scopestack[scopestack_ix++] = savestack_ix;
+ PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix;
}
pop_scope(void)
{
dTHR;
- I32 oldsave = scopestack[--scopestack_ix];
+ I32 oldsave = PL_scopestack[--PL_scopestack_ix];
LEAVE_SCOPE(oldsave);
}
markstack_grow(void)
{
dTHR;
- I32 oldmax = markstack_max - markstack;
- I32 newmax = oldmax * 3 / 2;
+ I32 oldmax = PL_markstack_max - PL_markstack;
+ I32 newmax = GROW(oldmax);
- Renew(markstack, newmax, I32);
- markstack_ptr = markstack + oldmax;
- markstack_max = markstack + newmax;
+ Renew(PL_markstack, newmax, I32);
+ PL_markstack_ptr = PL_markstack + oldmax;
+ PL_markstack_max = PL_markstack + newmax;
}
void
savestack_grow(void)
{
dTHR;
- savestack_max = savestack_max * 3 / 2;
- Renew(savestack, savestack_max, ANY);
+ PL_savestack_max = GROW(PL_savestack_max) + 4;
+ Renew(PL_savestack, PL_savestack_max, ANY);
}
+#undef GROW
+
void
free_tmps(void)
{
dTHR;
/* XXX should tmps_floor live in cxstack? */
- I32 myfloor = tmps_floor;
- while (tmps_ix > myfloor) { /* clean up after last statement */
- SV* sv = tmps_stack[tmps_ix];
- tmps_stack[tmps_ix--] = Nullsv;
+ I32 myfloor = PL_tmps_floor;
+ while (PL_tmps_ix > myfloor) { /* clean up after last statement */
+ SV* sv = PL_tmps_stack[PL_tmps_ix];
+ PL_tmps_stack[PL_tmps_ix--] = Nullsv;
if (sv) {
-#ifdef DEBUGGING
SvTEMP_off(sv);
-#endif
SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */
}
}
}
-static SV *
+STATIC SV *
save_scalar_at(SV **sptr)
{
dTHR;
sv_upgrade(sv, SvTYPE(osv));
if (SvGMAGICAL(osv)) {
MAGIC* mg;
- bool oldtainted = tainted;
+ bool oldtainted = PL_tainted;
mg_get(osv);
- if (tainting && tainted && (mg = mg_find(osv, 't'))) {
+ if (PL_tainting && PL_tainted && (mg = mg_find(osv, 't'))) {
SAVESPTR(mg->mg_obj);
mg->mg_obj = osv;
}
SvFLAGS(osv) |= (SvFLAGS(osv) &
(SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
- tainted = oldtainted;
+ PL_tainted = oldtainted;
}
SvMAGIC(sv) = SvMAGIC(osv);
SvFLAGS(sv) |= SvMAGICAL(osv);
- localizing = 1;
+ PL_localizing = 1;
SvSETMAGIC(sv);
- localizing = 0;
+ PL_localizing = 0;
}
return sv;
}
save_scalar(GV *gv)
{
dTHR;
+ SV **sptr = &GvSV(gv);
SSCHECK(3);
- SSPUSHPTR(gv);
- SSPUSHPTR(GvSV(gv));
+ SSPUSHPTR(SvREFCNT_inc(gv));
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
SSPUSHINT(SAVEt_SV);
- return save_scalar_at(&GvSV(gv));
+ return save_scalar_at(sptr);
}
SV*
dTHR;
SSCHECK(3);
SSPUSHPTR(sptr);
- SSPUSHPTR(*sptr);
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
SSPUSHINT(SAVEt_SVREF);
return save_scalar_at(sptr);
}
+/* Like save_svref(), but doesn't deal with magic. Can be used to
+ * restore a global SV to its prior contents, freeing new value. */
+void
+save_generic_svref(SV **sptr)
+{
+ dTHR;
+ SSCHECK(3);
+ SSPUSHPTR(sptr);
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
+ SSPUSHINT(SAVEt_GENERIC_SVREF);
+}
+
void
save_gp(GV *gv, I32 empty)
{
if (empty) {
register GP *gp;
+
+ if (GvCVu(gv))
+ PL_sub_generation++; /* taking a method out of circulation */
Newz(602, gp, 1, GP);
GvGP(gv) = gp_ref(gp);
GvSV(gv) = NEWSV(72,0);
- GvLINE(gv) = curcop->cop_line;
+ GvLINE(gv) = PL_curcop->cop_line;
GvEGV(gv) = gv;
}
else {
SvFLAGS(av) |= SvMAGICAL(oav);
SvMAGICAL_off(oav);
SvMAGIC(oav) = 0;
- localizing = 1;
+ PL_localizing = 1;
SvSETMAGIC((SV*)av);
- localizing = 0;
+ PL_localizing = 0;
}
return av;
}
SvFLAGS(hv) |= SvMAGICAL(ohv);
SvMAGICAL_off(ohv);
SvMAGIC(ohv) = 0;
- localizing = 1;
+ PL_localizing = 1;
SvSETMAGIC((SV*)hv);
- localizing = 0;
+ PL_localizing = 0;
}
return hv;
}
#ifdef USE_THREADS
dTHR;
SV **svp = &THREADSV(i); /* XXX Change to save by offset */
- DEBUG_L(PerlIO_printf(PerlIO_stderr(), "save_threadsv %u: %p %p:%s\n",
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(), "save_threadsv %u: %p %p:%s\n",
i, svp, *svp, SvPEEK(*svp)));
save_svref(svp);
return svp;
{
dTHR;
SSCHECK(2);
- SSPUSHLONG((long)(svp-curpad));
+ SSPUSHLONG((long)(svp-PL_curpad));
SSPUSHINT(SAVEt_CLEARSV);
}
SSCHECK(4);
SSPUSHINT(klen);
SSPUSHPTR(key);
- SSPUSHPTR(hv);
+ SSPUSHPTR(SvREFCNT_inc(hv));
SSPUSHINT(SAVEt_DELETE);
}
}
void
+#ifdef PERL_OBJECT
+save_destructor(DESTRUCTORFUNC f, void* p)
+#else
save_destructor(void (*f) (void *), void *p)
+#endif
{
dTHR;
SSCHECK(3);
}
void
+save_aelem(AV *av, I32 idx, SV **sptr)
+{
+ dTHR;
+ SSCHECK(4);
+ SSPUSHPTR(SvREFCNT_inc(av));
+ SSPUSHINT(idx);
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
+ SSPUSHINT(SAVEt_AELEM);
+ save_scalar_at(sptr);
+}
+
+void
+save_helem(HV *hv, SV *key, SV **sptr)
+{
+ dTHR;
+ SSCHECK(4);
+ SSPUSHPTR(SvREFCNT_inc(hv));
+ SSPUSHPTR(SvREFCNT_inc(key));
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
+ SSPUSHINT(SAVEt_HELEM);
+ save_scalar_at(sptr);
+}
+
+void
save_op(void)
{
dTHR;
SSCHECK(2);
- SSPUSHPTR(op);
+ SSPUSHPTR(PL_op);
SSPUSHINT(SAVEt_OP);
}
+I32
+save_alloc(I32 size, I32 pad)
+{
+ dTHR;
+ register I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix]
+ - (char*)PL_savestack);
+ register I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
+
+ /* SSCHECK may not be good enough */
+ while (PL_savestack_ix + elems + 2 > PL_savestack_max)
+ savestack_grow();
+
+ PL_savestack_ix += elems;
+ SSPUSHINT(elems);
+ SSPUSHINT(SAVEt_ALLOC);
+ return start;
+}
+
void
leave_scope(I32 base)
{
register AV *av;
register HV *hv;
register void* ptr;
+ I32 i;
if (base < -1)
croak("panic: corrupt saved stack index");
- while (savestack_ix > base) {
+ while (PL_savestack_ix > base) {
switch (SSPOPINT) {
case SAVEt_ITEM: /* normal string */
value = (SV*)SSPOPPTR;
sv = (SV*)SSPOPPTR;
sv_replace(sv,value);
- localizing = 2;
+ PL_localizing = 2;
SvSETMAGIC(sv);
- localizing = 0;
+ PL_localizing = 0;
break;
case SAVEt_SV: /* scalar reference */
value = (SV*)SSPOPPTR;
gv = (GV*)SSPOPPTR;
ptr = &GvSV(gv);
+ SvREFCNT_dec(gv);
goto restore_sv;
+ case SAVEt_GENERIC_SVREF: /* generic sv */
+ value = (SV*)SSPOPPTR;
+ ptr = SSPOPPTR;
+ if (ptr) {
+ sv = *(SV**)ptr;
+ *(SV**)ptr = value;
+ SvREFCNT_dec(sv);
+ }
+ SvREFCNT_dec(value);
+ break;
case SAVEt_SVREF: /* scalar reference */
value = (SV*)SSPOPPTR;
ptr = SSPOPPTR;
restore_sv:
sv = *(SV**)ptr;
- DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+ DEBUG_S(PerlIO_printf(PerlIO_stderr(),
"restore svref: %p %p:%s -> %p:%s\n",
ptr, sv, SvPEEK(sv), value, SvPEEK(value)));
if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) &&
}
SvREFCNT_dec(sv);
*(SV**)ptr = value;
- localizing = 2;
+ PL_localizing = 2;
SvSETMAGIC(value);
- localizing = 0;
+ PL_localizing = 0;
+ SvREFCNT_dec(value);
break;
case SAVEt_AV: /* array reference */
av = (AV*)SSPOPPTR;
}
GvAV(gv) = av;
if (SvMAGICAL(av)) {
- localizing = 2;
+ PL_localizing = 2;
SvSETMAGIC((SV*)av);
- localizing = 0;
+ PL_localizing = 0;
}
break;
case SAVEt_HV: /* hash reference */
}
GvHV(gv) = hv;
if (SvMAGICAL(hv)) {
- localizing = 2;
+ PL_localizing = 2;
SvSETMAGIC((SV*)hv);
- localizing = 0;
+ PL_localizing = 0;
}
break;
case SAVEt_INT: /* int reference */
case SAVEt_GP: /* scalar reference */
ptr = SSPOPPTR;
gv = (GV*)SSPOPPTR;
- if (SvPOK(gv) && SvLEN(gv) > 0) {
+ if (SvPVX(gv) && SvLEN(gv) > 0) {
Safefree(SvPVX(gv));
}
SvPVX(gv) = (char *)SSPOPPTR;
SvLEN(gv) = (STRLEN)SSPOPIV;
gp_free(gv);
GvGP(gv) = (GP*)ptr;
+ if (GvCVu(gv))
+ PL_sub_generation++; /* putting a method back into circulation */
SvREFCNT_dec(gv);
break;
case SAVEt_FREESV:
break;
case SAVEt_FREEOP:
ptr = SSPOPPTR;
- if (comppad)
- curpad = AvARRAY(comppad);
+ if (PL_comppad)
+ PL_curpad = AvARRAY(PL_comppad);
op_free((OP*)ptr);
break;
case SAVEt_FREEPV:
Safefree((char*)ptr);
break;
case SAVEt_CLEARSV:
- ptr = (void*)&curpad[SSPOPLONG];
+ ptr = (void*)&PL_curpad[SSPOPLONG];
sv = *(SV**)ptr;
/* Can clear pad variable in place? */
if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
hv = (HV*)ptr;
ptr = SSPOPPTR;
(void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD);
+ SvREFCNT_dec(hv);
Safefree(ptr);
break;
case SAVEt_DESTRUCTOR:
ptr = SSPOPPTR;
- (*SSPOPDPTR)(ptr);
+ (CALLDESTRUCTOR)(ptr);
break;
case SAVEt_REGCONTEXT:
- {
- I32 delta = SSPOPINT;
- savestack_ix -= delta; /* regexp must have croaked */
- }
+ case SAVEt_ALLOC:
+ i = SSPOPINT;
+ PL_savestack_ix -= i; /* regexp must have croaked */
break;
case SAVEt_STACK_POS: /* Position on Perl stack */
- {
- I32 delta = SSPOPINT;
- stack_sp = stack_base + delta;
+ i = SSPOPINT;
+ PL_stack_sp = PL_stack_base + i;
+ break;
+ case SAVEt_AELEM: /* array element */
+ value = (SV*)SSPOPPTR;
+ i = SSPOPINT;
+ av = (AV*)SSPOPPTR;
+ ptr = av_fetch(av,i,1);
+ if (ptr) {
+ sv = *(SV**)ptr;
+ if (sv && sv != &PL_sv_undef) {
+ if (SvTIED_mg((SV*)av, 'P'))
+ (void)SvREFCNT_inc(sv);
+ SvREFCNT_dec(av);
+ goto restore_sv;
+ }
+ }
+ SvREFCNT_dec(av);
+ SvREFCNT_dec(value);
+ break;
+ case SAVEt_HELEM: /* hash element */
+ value = (SV*)SSPOPPTR;
+ sv = (SV*)SSPOPPTR;
+ hv = (HV*)SSPOPPTR;
+ ptr = hv_fetch_ent(hv, sv, 1, 0);
+ if (ptr) {
+ SV *oval = HeVAL((HE*)ptr);
+ if (oval && oval != &PL_sv_undef) {
+ ptr = &HeVAL((HE*)ptr);
+ if (SvTIED_mg((SV*)hv, 'P'))
+ (void)SvREFCNT_inc(*(SV**)ptr);
+ SvREFCNT_dec(hv);
+ SvREFCNT_dec(sv);
+ goto restore_sv;
+ }
}
+ SvREFCNT_dec(hv);
+ SvREFCNT_dec(sv);
+ SvREFCNT_dec(value);
break;
case SAVEt_OP:
- op = (OP*)SSPOPPTR;
+ PL_op = (OP*)SSPOPPTR;
+ break;
+ case SAVEt_HINTS:
+ if (GvHV(PL_hintgv)) {
+ SvREFCNT_dec((SV*)GvHV(PL_hintgv));
+ GvHV(PL_hintgv) = NULL;
+ }
+ *(I32*)&PL_hints = (I32)SSPOPINT;
break;
default:
croak("panic: leave_scope inconsistency");
}
}
-#ifdef DEBUGGING
-
void
cx_dump(PERL_CONTEXT *cx)
{
+#ifdef DEBUGGING
dTHR;
- PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), block_type[cx->cx_type]);
- if (cx->cx_type != CXt_SUBST) {
+ PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), block_type[CxTYPE(cx)]);
+ if (CxTYPE(cx) != CXt_SUBST) {
PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
}
- switch (cx->cx_type) {
+ switch (CxTYPE(cx)) {
case CXt_NULL:
case CXt_BLOCK:
break;
(long)cx->sb_rxres);
break;
}
+#endif /* DEBUGGING */
}
-#endif