summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/scope.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-05-24 18:36:42 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-05-24 18:36:42 +0000
commit8bab8b19946f98d4be49345ca9c42e56674b65fb (patch)
treebd62d7b5d463fab205d08914b30ba647eb3c8bc8 /gnu/usr.bin/perl/scope.c
parent483d4e680bd2a6db14835b1b4d65be33488d532b (diff)
merge in perl 5.6.1 with our local changes
Diffstat (limited to 'gnu/usr.bin/perl/scope.c')
-rw-r--r--gnu/usr.bin/perl/scope.c126
1 files changed, 68 insertions, 58 deletions
diff --git a/gnu/usr.bin/perl/scope.c b/gnu/usr.bin/perl/scope.c
index 3b9f0d108aa..bb4143b079c 100644
--- a/gnu/usr.bin/perl/scope.c
+++ b/gnu/usr.bin/perl/scope.c
@@ -1,6 +1,6 @@
/* scope.c
*
- * Copyright (c) 1991-2000, Larry Wall
+ * Copyright (c) 1991-2001, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
@@ -33,7 +33,6 @@ void *
Perl_vdefault_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt,
protect_body_t body, va_list *args)
{
- dTHR;
int ex;
void *ret;
@@ -51,7 +50,6 @@ Perl_vdefault_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt,
SV**
Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
{
- dTHR;
#if defined(DEBUGGING) && !defined(USE_THREADS)
static int growing = 0;
if (growing++)
@@ -97,7 +95,6 @@ Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
I32
Perl_cxinc(pTHX)
{
- dTHR;
cxstack_max = GROW(cxstack_max);
Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */
return cxstack_ix + 1;
@@ -106,7 +103,6 @@ Perl_cxinc(pTHX)
void
Perl_push_return(pTHX_ OP *retop)
{
- dTHR;
if (PL_retstack_ix == PL_retstack_max) {
PL_retstack_max = GROW(PL_retstack_max);
Renew(PL_retstack, PL_retstack_max, OP*);
@@ -117,7 +113,6 @@ Perl_push_return(pTHX_ OP *retop)
OP *
Perl_pop_return(pTHX)
{
- dTHR;
if (PL_retstack_ix > 0)
return PL_retstack[--PL_retstack_ix];
else
@@ -127,7 +122,6 @@ Perl_pop_return(pTHX)
void
Perl_push_scope(pTHX)
{
- dTHR;
if (PL_scopestack_ix == PL_scopestack_max) {
PL_scopestack_max = GROW(PL_scopestack_max);
Renew(PL_scopestack, PL_scopestack_max, I32);
@@ -139,7 +133,6 @@ Perl_push_scope(pTHX)
void
Perl_pop_scope(pTHX)
{
- dTHR;
I32 oldsave = PL_scopestack[--PL_scopestack_ix];
LEAVE_SCOPE(oldsave);
}
@@ -147,7 +140,6 @@ Perl_pop_scope(pTHX)
void
Perl_markstack_grow(pTHX)
{
- dTHR;
I32 oldmax = PL_markstack_max - PL_markstack;
I32 newmax = GROW(oldmax);
@@ -159,7 +151,6 @@ Perl_markstack_grow(pTHX)
void
Perl_savestack_grow(pTHX)
{
- dTHR;
PL_savestack_max = GROW(PL_savestack_max) + 4;
Renew(PL_savestack, PL_savestack_max, ANY);
}
@@ -169,7 +160,6 @@ Perl_savestack_grow(pTHX)
void
Perl_tmps_grow(pTHX_ I32 n)
{
- dTHR;
#ifndef STRESS_REALLOC
if (n < 128)
n = (PL_tmps_max < 512) ? 128 : 512;
@@ -182,7 +172,6 @@ Perl_tmps_grow(pTHX_ I32 n)
void
Perl_free_tmps(pTHX)
{
- dTHR;
/* XXX should tmps_floor live in cxstack? */
I32 myfloor = PL_tmps_floor;
while (PL_tmps_ix > myfloor) { /* clean up after last statement */
@@ -198,7 +187,6 @@ Perl_free_tmps(pTHX)
STATIC SV *
S_save_scalar_at(pTHX_ SV **sptr)
{
- dTHR;
register SV *sv;
SV *osv = *sptr;
@@ -208,7 +196,7 @@ S_save_scalar_at(pTHX_ SV **sptr)
if (SvGMAGICAL(osv)) {
MAGIC* mg;
bool oldtainted = PL_tainted;
- mg_get(osv);
+ mg_get(osv); /* note, can croak! */
if (PL_tainting && PL_tainted && (mg = mg_find(osv, 't'))) {
SAVESPTR(mg->mg_obj);
mg->mg_obj = osv;
@@ -219,6 +207,9 @@ S_save_scalar_at(pTHX_ SV **sptr)
}
SvMAGIC(sv) = SvMAGIC(osv);
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. */
PL_localizing = 1;
SvSETMAGIC(sv);
PL_localizing = 0;
@@ -229,7 +220,6 @@ S_save_scalar_at(pTHX_ SV **sptr)
SV *
Perl_save_scalar(pTHX_ GV *gv)
{
- dTHR;
SV **sptr = &GvSV(gv);
SSCHECK(3);
SSPUSHPTR(SvREFCNT_inc(gv));
@@ -241,7 +231,6 @@ Perl_save_scalar(pTHX_ GV *gv)
SV*
Perl_save_svref(pTHX_ SV **sptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(sptr);
SSPUSHPTR(SvREFCNT_inc(*sptr));
@@ -249,22 +238,32 @@ Perl_save_svref(pTHX_ SV **sptr)
return save_scalar_at(sptr);
}
-/* Like save_svref(), but doesn't deal with magic. Can be used to
+/* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to
* restore a global SV to its prior contents, freeing new value. */
void
Perl_save_generic_svref(pTHX_ SV **sptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(sptr);
SSPUSHPTR(SvREFCNT_inc(*sptr));
SSPUSHINT(SAVEt_GENERIC_SVREF);
}
+/* Like save_pptr(), but also Safefree()s the new value if it is different
+ * from the old one. Can be used to restore a global char* to its prior
+ * contents, freeing new value. */
+void
+Perl_save_generic_pvref(pTHX_ char **str)
+{
+ SSCHECK(3);
+ SSPUSHPTR(str);
+ SSPUSHPTR(*str);
+ SSPUSHINT(SAVEt_GENERIC_PVREF);
+}
+
void
Perl_save_gp(pTHX_ GV *gv, I32 empty)
{
- dTHR;
SSCHECK(6);
SSPUSHIV((IV)SvLEN(gv));
SvLEN(gv) = 0; /* forget that anything was allocated here */
@@ -289,6 +288,7 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty)
GvGP(gv) = gp_ref(gp);
GvSV(gv) = NEWSV(72,0);
GvLINE(gv) = CopLINE(PL_curcop);
+ GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : "";
GvEGV(gv) = gv;
}
else {
@@ -300,7 +300,6 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty)
AV *
Perl_save_ary(pTHX_ GV *gv)
{
- dTHR;
AV *oav = GvAVn(gv);
AV *av;
@@ -328,7 +327,6 @@ Perl_save_ary(pTHX_ GV *gv)
HV *
Perl_save_hash(pTHX_ GV *gv)
{
- dTHR;
HV *ohv, *hv;
SSCHECK(3);
@@ -353,7 +351,6 @@ Perl_save_hash(pTHX_ GV *gv)
void
Perl_save_item(pTHX_ register SV *item)
{
- dTHR;
register SV *sv = NEWSV(0,0);
sv_setsv(sv,item);
@@ -366,7 +363,6 @@ Perl_save_item(pTHX_ register SV *item)
void
Perl_save_int(pTHX_ int *intp)
{
- dTHR;
SSCHECK(3);
SSPUSHINT(*intp);
SSPUSHPTR(intp);
@@ -376,7 +372,6 @@ Perl_save_int(pTHX_ int *intp)
void
Perl_save_long(pTHX_ long int *longp)
{
- dTHR;
SSCHECK(3);
SSPUSHLONG(*longp);
SSPUSHPTR(longp);
@@ -386,7 +381,6 @@ Perl_save_long(pTHX_ long int *longp)
void
Perl_save_I32(pTHX_ I32 *intp)
{
- dTHR;
SSCHECK(3);
SSPUSHINT(*intp);
SSPUSHPTR(intp);
@@ -396,7 +390,6 @@ Perl_save_I32(pTHX_ I32 *intp)
void
Perl_save_I16(pTHX_ I16 *intp)
{
- dTHR;
SSCHECK(3);
SSPUSHINT(*intp);
SSPUSHPTR(intp);
@@ -406,7 +399,6 @@ Perl_save_I16(pTHX_ I16 *intp)
void
Perl_save_I8(pTHX_ I8 *bytep)
{
- dTHR;
SSCHECK(3);
SSPUSHINT(*bytep);
SSPUSHPTR(bytep);
@@ -416,7 +408,6 @@ Perl_save_I8(pTHX_ I8 *bytep)
void
Perl_save_iv(pTHX_ IV *ivp)
{
- dTHR;
SSCHECK(3);
SSPUSHIV(*ivp);
SSPUSHPTR(ivp);
@@ -429,7 +420,6 @@ Perl_save_iv(pTHX_ IV *ivp)
void
Perl_save_pptr(pTHX_ char **pptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(*pptr);
SSPUSHPTR(pptr);
@@ -439,7 +429,6 @@ Perl_save_pptr(pTHX_ char **pptr)
void
Perl_save_vptr(pTHX_ void *ptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(*(char**)ptr);
SSPUSHPTR(ptr);
@@ -449,18 +438,26 @@ Perl_save_vptr(pTHX_ void *ptr)
void
Perl_save_sptr(pTHX_ SV **sptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(*sptr);
SSPUSHPTR(sptr);
SSPUSHINT(SAVEt_SPTR);
}
+void
+Perl_save_padsv(pTHX_ PADOFFSET off)
+{
+ SSCHECK(4);
+ SSPUSHPTR(PL_curpad[off]);
+ SSPUSHPTR(PL_curpad);
+ SSPUSHLONG((long)off);
+ SSPUSHINT(SAVEt_PADSV);
+}
+
SV **
Perl_save_threadsv(pTHX_ PADOFFSET i)
{
#ifdef USE_THREADS
- dTHR;
SV **svp = &THREADSV(i); /* XXX Change to save by offset */
DEBUG_S(PerlIO_printf(Perl_debug_log, "save_threadsv %"UVuf": %p %p:%s\n",
(UV)i, svp, *svp, SvPEEK(*svp)));
@@ -475,7 +472,6 @@ Perl_save_threadsv(pTHX_ PADOFFSET i)
void
Perl_save_nogv(pTHX_ GV *gv)
{
- dTHR;
SSCHECK(2);
SSPUSHPTR(gv);
SSPUSHINT(SAVEt_NSTAB);
@@ -484,7 +480,6 @@ Perl_save_nogv(pTHX_ GV *gv)
void
Perl_save_hptr(pTHX_ HV **hptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(*hptr);
SSPUSHPTR(hptr);
@@ -494,7 +489,6 @@ Perl_save_hptr(pTHX_ HV **hptr)
void
Perl_save_aptr(pTHX_ AV **aptr)
{
- dTHR;
SSCHECK(3);
SSPUSHPTR(*aptr);
SSPUSHPTR(aptr);
@@ -504,16 +498,22 @@ Perl_save_aptr(pTHX_ AV **aptr)
void
Perl_save_freesv(pTHX_ SV *sv)
{
- dTHR;
SSCHECK(2);
SSPUSHPTR(sv);
SSPUSHINT(SAVEt_FREESV);
}
void
+Perl_save_mortalizesv(pTHX_ SV *sv)
+{
+ SSCHECK(2);
+ SSPUSHPTR(sv);
+ SSPUSHINT(SAVEt_MORTALIZESV);
+}
+
+void
Perl_save_freeop(pTHX_ OP *o)
{
- dTHR;
SSCHECK(2);
SSPUSHPTR(o);
SSPUSHINT(SAVEt_FREEOP);
@@ -522,7 +522,6 @@ Perl_save_freeop(pTHX_ OP *o)
void
Perl_save_freepv(pTHX_ char *pv)
{
- dTHR;
SSCHECK(2);
SSPUSHPTR(pv);
SSPUSHINT(SAVEt_FREEPV);
@@ -531,7 +530,6 @@ Perl_save_freepv(pTHX_ char *pv)
void
Perl_save_clearsv(pTHX_ SV **svp)
{
- dTHR;
SSCHECK(2);
SSPUSHLONG((long)(svp-PL_curpad));
SSPUSHINT(SAVEt_CLEARSV);
@@ -540,7 +538,6 @@ Perl_save_clearsv(pTHX_ SV **svp)
void
Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
{
- dTHR;
SSCHECK(4);
SSPUSHINT(klen);
SSPUSHPTR(key);
@@ -551,7 +548,6 @@ Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
void
Perl_save_list(pTHX_ register SV **sarg, I32 maxsarg)
{
- dTHR;
register SV *sv;
register I32 i;
@@ -568,7 +564,6 @@ Perl_save_list(pTHX_ register SV **sarg, I32 maxsarg)
void
Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
{
- dTHR;
SSCHECK(3);
SSPUSHDPTR(f);
SSPUSHPTR(p);
@@ -578,7 +573,6 @@ Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p)
void
Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
{
- dTHR;
SSCHECK(3);
SSPUSHDXPTR(f);
SSPUSHPTR(p);
@@ -588,7 +582,6 @@ Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p)
void
Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
{
- dTHR;
SSCHECK(4);
SSPUSHPTR(SvREFCNT_inc(av));
SSPUSHINT(idx);
@@ -600,7 +593,6 @@ Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
void
Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr)
{
- dTHR;
SSCHECK(4);
SSPUSHPTR(SvREFCNT_inc(hv));
SSPUSHPTR(SvREFCNT_inc(key));
@@ -612,7 +604,6 @@ Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr)
void
Perl_save_op(pTHX)
{
- dTHR;
SSCHECK(2);
SSPUSHPTR(PL_op);
SSPUSHINT(SAVEt_OP);
@@ -621,7 +612,6 @@ Perl_save_op(pTHX)
I32
Perl_save_alloc(pTHX_ 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));
@@ -639,13 +629,13 @@ Perl_save_alloc(pTHX_ I32 size, I32 pad)
void
Perl_leave_scope(pTHX_ I32 base)
{
- dTHR;
register SV *sv;
register SV *value;
register GV *gv;
register AV *av;
register HV *hv;
register void* ptr;
+ register char* str;
I32 i;
if (base < -1)
@@ -666,14 +656,20 @@ Perl_leave_scope(pTHX_ I32 base)
ptr = &GvSV(gv);
SvREFCNT_dec(gv);
goto restore_sv;
+ case SAVEt_GENERIC_PVREF: /* generic pv */
+ str = (char*)SSPOPPTR;
+ ptr = SSPOPPTR;
+ if (*(char**)ptr != str) {
+ Safefree(*(char**)ptr);
+ *(char**)ptr = str;
+ }
+ break;
case SAVEt_GENERIC_SVREF: /* generic sv */
value = (SV*)SSPOPPTR;
ptr = SSPOPPTR;
- if (ptr) {
- sv = *(SV**)ptr;
- *(SV**)ptr = value;
- SvREFCNT_dec(sv);
- }
+ sv = *(SV**)ptr;
+ *(SV**)ptr = value;
+ SvREFCNT_dec(sv);
SvREFCNT_dec(value);
break;
case SAVEt_SVREF: /* scalar reference */
@@ -693,12 +689,19 @@ Perl_leave_scope(pTHX_ I32 base)
SvMAGICAL_off(sv);
SvMAGIC(sv) = 0;
}
+ /* XXX This branch is pretty bogus. This code irretrievably
+ * clears(!) the magic on the SV (either to avoid further
+ * croaking that might ensue when the SvSETMAGIC() below is
+ * called, or to avoid two different SVs pointing at the same
+ * SvMAGIC()). This needs a total rethink. --GSAR */
else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) &&
SvTYPE(value) != SVt_PVGV)
{
SvFLAGS(value) |= (SvFLAGS(value) &
(SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
SvMAGICAL_off(value);
+ /* XXX this is a leak when we get here because the
+ * mg_get() in save_scalar_at() croaked */
SvMAGIC(value) = 0;
}
SvREFCNT_dec(sv);
@@ -808,6 +811,10 @@ Perl_leave_scope(pTHX_ I32 base)
ptr = SSPOPPTR;
SvREFCNT_dec((SV*)ptr);
break;
+ case SAVEt_MORTALIZESV:
+ ptr = SSPOPPTR;
+ sv_2mortal((SV*)ptr);
+ break;
case SAVEt_FREEOP:
ptr = SSPOPPTR;
if (PL_comppad)
@@ -927,10 +934,6 @@ Perl_leave_scope(pTHX_ I32 base)
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;
case SAVEt_COMPPAD:
@@ -940,6 +943,14 @@ Perl_leave_scope(pTHX_ I32 base)
else
PL_curpad = Null(SV**);
break;
+ case SAVEt_PADSV:
+ {
+ PADOFFSET off = (PADOFFSET)SSPOPLONG;
+ ptr = SSPOPPTR;
+ if (ptr)
+ ((SV**)ptr)[off] = (SV*)SSPOPPTR;
+ }
+ break;
default:
Perl_croak(aTHX_ "panic: leave_scope inconsistency");
}
@@ -950,7 +961,6 @@ void
Perl_cx_dump(pTHX_ PERL_CONTEXT *cx)
{
#ifdef DEBUGGING
- dTHR;
PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
if (CxTYPE(cx) != CXt_SUBST) {
PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);