summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c214
1 files changed, 145 insertions, 69 deletions
diff --git a/scope.c b/scope.c
index 1008ab1437..44c3d923a9 100644
--- a/scope.c
+++ b/scope.c
@@ -1,6 +1,6 @@
/* scope.c
*
- * Copyright (c) 1991-1997, Larry Wall
+ * Copyright (c) 1991-1999, 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.
@@ -13,10 +13,42 @@
*/
#include "EXTERN.h"
+#define PERL_IN_SCOPE_C
#include "perl.h"
+void *
+Perl_default_protect(pTHX_ int *excpt, protect_body_t body, ...)
+{
+ void *ret;
+ va_list args;
+ va_start(args, body);
+ ret = vdefault_protect(excpt, body, &args);
+ va_end(args);
+ return ret;
+}
+
+void *
+Perl_vdefault_protect(pTHX_ int *excpt, protect_body_t body, va_list *args)
+{
+ dTHR;
+ dJMPENV;
+ int ex;
+ void *ret;
+
+ DEBUG_l(Perl_deb(aTHX_ "Setting up local jumplevel %p, was %p\n",
+ &cur_env, PL_top_env));
+ JMPENV_PUSH(ex);
+ if (ex)
+ ret = NULL;
+ else
+ ret = CALL_FPTR(body)(aTHX_ *args);
+ *excpt = ex;
+ JMPENV_POP;
+ return ret;
+}
+
SV**
-stack_grow(SV **sp, SV **p, int n)
+Perl_stack_grow(pTHX_ SV **sp, SV **p, int n)
{
dTHR;
#if defined(DEBUGGING) && !defined(USE_THREADS)
@@ -43,7 +75,7 @@ stack_grow(SV **sp, SV **p, int n)
#endif
PERL_SI *
-new_stackinfo(I32 stitems, I32 cxitems)
+Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems)
{
PERL_SI *si;
PERL_CONTEXT *cxt;
@@ -63,7 +95,7 @@ new_stackinfo(I32 stitems, I32 cxitems)
}
I32
-cxinc(void)
+Perl_cxinc(pTHX)
{
dTHR;
cxstack_max = GROW(cxstack_max);
@@ -72,7 +104,7 @@ cxinc(void)
}
void
-push_return(OP *retop)
+Perl_push_return(pTHX_ OP *retop)
{
dTHR;
if (PL_retstack_ix == PL_retstack_max) {
@@ -83,7 +115,7 @@ push_return(OP *retop)
}
OP *
-pop_return(void)
+Perl_pop_return(pTHX)
{
dTHR;
if (PL_retstack_ix > 0)
@@ -93,7 +125,7 @@ pop_return(void)
}
void
-push_scope(void)
+Perl_push_scope(pTHX)
{
dTHR;
if (PL_scopestack_ix == PL_scopestack_max) {
@@ -105,7 +137,7 @@ push_scope(void)
}
void
-pop_scope(void)
+Perl_pop_scope(pTHX)
{
dTHR;
I32 oldsave = PL_scopestack[--PL_scopestack_ix];
@@ -113,7 +145,7 @@ pop_scope(void)
}
void
-markstack_grow(void)
+Perl_markstack_grow(pTHX)
{
dTHR;
I32 oldmax = PL_markstack_max - PL_markstack;
@@ -125,7 +157,7 @@ markstack_grow(void)
}
void
-savestack_grow(void)
+Perl_savestack_grow(pTHX)
{
dTHR;
PL_savestack_max = GROW(PL_savestack_max) + 4;
@@ -135,7 +167,20 @@ savestack_grow(void)
#undef GROW
void
-free_tmps(void)
+Perl_tmps_grow(pTHX_ I32 n)
+{
+ dTHR;
+#ifndef STRESS_REALLOC
+ if (n < 128)
+ n = (PL_tmps_max < 512) ? 128 : 512;
+#endif
+ PL_tmps_max = PL_tmps_ix + n + 1;
+ Renew(PL_tmps_stack, PL_tmps_max, SV*);
+}
+
+
+void
+Perl_free_tmps(pTHX)
{
dTHR;
/* XXX should tmps_floor live in cxstack? */
@@ -144,16 +189,14 @@ free_tmps(void)
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 *
-save_scalar_at(SV **sptr)
+S_save_scalar_at(pTHX_ SV **sptr)
{
dTHR;
register SV *sv;
@@ -184,7 +227,7 @@ save_scalar_at(SV **sptr)
}
SV *
-save_scalar(GV *gv)
+Perl_save_scalar(pTHX_ GV *gv)
{
dTHR;
SV **sptr = &GvSV(gv);
@@ -196,7 +239,7 @@ save_scalar(GV *gv)
}
SV*
-save_svref(SV **sptr)
+Perl_save_svref(pTHX_ SV **sptr)
{
dTHR;
SSCHECK(3);
@@ -206,8 +249,20 @@ save_svref(SV **sptr)
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
+Perl_save_generic_svref(pTHX_ SV **sptr)
+{
+ dTHR;
+ SSCHECK(3);
+ SSPUSHPTR(sptr);
+ SSPUSHPTR(SvREFCNT_inc(*sptr));
+ SSPUSHINT(SAVEt_GENERIC_SVREF);
+}
+
void
-save_gp(GV *gv, I32 empty)
+Perl_save_gp(pTHX_ GV *gv, I32 empty)
{
dTHR;
SSCHECK(6);
@@ -238,7 +293,7 @@ save_gp(GV *gv, I32 empty)
}
AV *
-save_ary(GV *gv)
+Perl_save_ary(pTHX_ GV *gv)
{
dTHR;
AV *oav = GvAVn(gv);
@@ -266,7 +321,7 @@ save_ary(GV *gv)
}
HV *
-save_hash(GV *gv)
+Perl_save_hash(pTHX_ GV *gv)
{
dTHR;
HV *ohv, *hv;
@@ -291,7 +346,7 @@ save_hash(GV *gv)
}
void
-save_item(register SV *item)
+Perl_save_item(pTHX_ register SV *item)
{
dTHR;
register SV *sv = NEWSV(0,0);
@@ -304,7 +359,7 @@ save_item(register SV *item)
}
void
-save_int(int *intp)
+Perl_save_int(pTHX_ int *intp)
{
dTHR;
SSCHECK(3);
@@ -314,7 +369,7 @@ save_int(int *intp)
}
void
-save_long(long int *longp)
+Perl_save_long(pTHX_ long int *longp)
{
dTHR;
SSCHECK(3);
@@ -324,7 +379,7 @@ save_long(long int *longp)
}
void
-save_I32(I32 *intp)
+Perl_save_I32(pTHX_ I32 *intp)
{
dTHR;
SSCHECK(3);
@@ -334,7 +389,7 @@ save_I32(I32 *intp)
}
void
-save_I16(I16 *intp)
+Perl_save_I16(pTHX_ I16 *intp)
{
dTHR;
SSCHECK(3);
@@ -344,7 +399,7 @@ save_I16(I16 *intp)
}
void
-save_iv(IV *ivp)
+Perl_save_iv(pTHX_ IV *ivp)
{
dTHR;
SSCHECK(3);
@@ -357,7 +412,7 @@ save_iv(IV *ivp)
* force word-alignment and we'll miss the pointer.
*/
void
-save_pptr(char **pptr)
+Perl_save_pptr(pTHX_ char **pptr)
{
dTHR;
SSCHECK(3);
@@ -367,7 +422,7 @@ save_pptr(char **pptr)
}
void
-save_sptr(SV **sptr)
+Perl_save_sptr(pTHX_ SV **sptr)
{
dTHR;
SSCHECK(3);
@@ -377,23 +432,23 @@ save_sptr(SV **sptr)
}
SV **
-save_threadsv(PADOFFSET i)
+Perl_save_threadsv(pTHX_ PADOFFSET i)
{
#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;
#else
- croak("panic: save_threadsv called in non-threaded perl");
+ Perl_croak(aTHX_ "panic: save_threadsv called in non-threaded perl");
return 0;
#endif /* USE_THREADS */
}
void
-save_nogv(GV *gv)
+Perl_save_nogv(pTHX_ GV *gv)
{
dTHR;
SSCHECK(2);
@@ -402,7 +457,7 @@ save_nogv(GV *gv)
}
void
-save_hptr(HV **hptr)
+Perl_save_hptr(pTHX_ HV **hptr)
{
dTHR;
SSCHECK(3);
@@ -412,7 +467,7 @@ save_hptr(HV **hptr)
}
void
-save_aptr(AV **aptr)
+Perl_save_aptr(pTHX_ AV **aptr)
{
dTHR;
SSCHECK(3);
@@ -422,7 +477,7 @@ save_aptr(AV **aptr)
}
void
-save_freesv(SV *sv)
+Perl_save_freesv(pTHX_ SV *sv)
{
dTHR;
SSCHECK(2);
@@ -431,7 +486,7 @@ save_freesv(SV *sv)
}
void
-save_freeop(OP *o)
+Perl_save_freeop(pTHX_ OP *o)
{
dTHR;
SSCHECK(2);
@@ -440,7 +495,7 @@ save_freeop(OP *o)
}
void
-save_freepv(char *pv)
+Perl_save_freepv(pTHX_ char *pv)
{
dTHR;
SSCHECK(2);
@@ -449,7 +504,7 @@ save_freepv(char *pv)
}
void
-save_clearsv(SV **svp)
+Perl_save_clearsv(pTHX_ SV **svp)
{
dTHR;
SSCHECK(2);
@@ -458,7 +513,7 @@ save_clearsv(SV **svp)
}
void
-save_delete(HV *hv, char *key, I32 klen)
+Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen)
{
dTHR;
SSCHECK(4);
@@ -469,7 +524,7 @@ save_delete(HV *hv, char *key, I32 klen)
}
void
-save_list(register SV **sarg, I32 maxsarg)
+Perl_save_list(pTHX_ register SV **sarg, I32 maxsarg)
{
dTHR;
register SV *sv;
@@ -486,11 +541,7 @@ save_list(register SV **sarg, I32 maxsarg)
}
void
-#ifdef PERL_OBJECT
-save_destructor(DESTRUCTORFUNC f, void* p)
-#else
-save_destructor(void (*f) (void *), void *p)
-#endif
+Perl_save_destructor(pTHX_ DESTRUCTORFUNC_t f, void* p)
{
dTHR;
SSCHECK(3);
@@ -500,7 +551,7 @@ save_destructor(void (*f) (void *), void *p)
}
void
-save_aelem(AV *av, I32 idx, SV **sptr)
+Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr)
{
dTHR;
SSCHECK(4);
@@ -512,7 +563,7 @@ save_aelem(AV *av, I32 idx, SV **sptr)
}
void
-save_helem(HV *hv, SV *key, SV **sptr)
+Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr)
{
dTHR;
SSCHECK(4);
@@ -524,7 +575,7 @@ save_helem(HV *hv, SV *key, SV **sptr)
}
void
-save_op(void)
+Perl_save_op(pTHX)
{
dTHR;
SSCHECK(2);
@@ -532,8 +583,26 @@ save_op(void)
SSPUSHINT(SAVEt_OP);
}
+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));
+
+ /* 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)
+Perl_leave_scope(pTHX_ I32 base)
{
dTHR;
register SV *sv;
@@ -545,7 +614,7 @@ leave_scope(I32 base)
I32 i;
if (base < -1)
- croak("panic: corrupt saved stack index");
+ Perl_croak(aTHX_ "panic: corrupt saved stack index");
while (PL_savestack_ix > base) {
switch (SSPOPINT) {
case SAVEt_ITEM: /* normal string */
@@ -562,12 +631,22 @@ leave_scope(I32 base)
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) &&
@@ -704,12 +783,8 @@ leave_scope(I32 base)
sv = *(SV**)ptr;
/* Can clear pad variable in place? */
if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
- if (SvTHINKFIRST(sv)) {
- if (SvREADONLY(sv))
- croak("panic: leave_scope clearsv");
- if (SvROK(sv))
- sv_unref(sv);
- }
+ if (SvTHINKFIRST(sv))
+ sv_force_normal(sv);
if (SvMAGICAL(sv))
mg_free(sv);
@@ -723,7 +798,7 @@ leave_scope(I32 base)
hv_clear((HV*)sv);
break;
case SVt_PVCV:
- croak("panic: leave_scope pad code");
+ Perl_croak(aTHX_ "panic: leave_scope pad code");
case SVt_RV:
case SVt_IV:
case SVt_NV:
@@ -756,9 +831,10 @@ leave_scope(I32 base)
break;
case SAVEt_DESTRUCTOR:
ptr = SSPOPPTR;
- (CALLDESTRUCTOR)(ptr);
+ CALLDESTRUCTOR(aTHXo_ ptr);
break;
case SAVEt_REGCONTEXT:
+ case SAVEt_ALLOC:
i = SSPOPINT;
PL_savestack_ix -= i; /* regexp must have croaked */
break;
@@ -774,7 +850,7 @@ leave_scope(I32 base)
if (ptr) {
sv = *(SV**)ptr;
if (sv && sv != &PL_sv_undef) {
- if (SvRMAGICAL(av) && mg_find((SV*)av, 'P'))
+ if (SvTIED_mg((SV*)av, 'P'))
(void)SvREFCNT_inc(sv);
SvREFCNT_dec(av);
goto restore_sv;
@@ -792,7 +868,7 @@ leave_scope(I32 base)
SV *oval = HeVAL((HE*)ptr);
if (oval && oval != &PL_sv_undef) {
ptr = &HeVAL((HE*)ptr);
- if (SvRMAGICAL(hv) && mg_find((SV*)hv, 'P'))
+ if (SvTIED_mg((SV*)hv, 'P'))
(void)SvREFCNT_inc(*(SV**)ptr);
SvREFCNT_dec(hv);
SvREFCNT_dec(sv);
@@ -814,18 +890,18 @@ leave_scope(I32 base)
*(I32*)&PL_hints = (I32)SSPOPINT;
break;
default:
- croak("panic: leave_scope inconsistency");
+ Perl_croak(aTHX_ "panic: leave_scope inconsistency");
}
}
}
void
-cx_dump(PERL_CONTEXT *cx)
+Perl_cx_dump(pTHX_ 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), PL_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);
@@ -834,7 +910,7 @@ cx_dump(PERL_CONTEXT *cx)
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;
@@ -854,8 +930,8 @@ cx_dump(PERL_CONTEXT *cx)
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
(long)cx->blk_eval.old_in_eval);
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
- op_name[cx->blk_eval.old_op_type],
- op_desc[cx->blk_eval.old_op_type]);
+ PL_op_name[cx->blk_eval.old_op_type],
+ PL_op_desc[cx->blk_eval.old_op_type]);
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
cx->blk_eval.old_name);
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
@@ -891,8 +967,8 @@ cx_dump(PERL_CONTEXT *cx)
(long)cx->sb_iters);
PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
(long)cx->sb_maxiters);
- PerlIO_printf(Perl_debug_log, "SB_SAFEBASE = %ld\n",
- (long)cx->sb_safebase);
+ PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
+ (long)cx->sb_rflags);
PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
(long)cx->sb_once);
PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",