This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Doc & feature patch for Thread::Queue
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index 1dfb25a..7a0a578 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -25,18 +25,48 @@ stack_grow(SV **sp, SV **p, int n)
       abort();
 #endif
     stack_sp = sp;
+#ifndef STRESS_REALLOC
     av_extend(curstack, (p - stack_base) + (n) + 128);
+#else
+    av_extend(curstack, (p - stack_base) + (n) + 1);
+#endif
 #if defined(DEBUGGING) && !defined(USE_THREADS)
     growing--;
 #endif
     return 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] = &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 = SI_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;
 }
@@ -46,7 +76,7 @@ push_return(OP *retop)
 {
     dTHR;
     if (retstack_ix == retstack_max) {
-       retstack_max = retstack_max * 3 / 2;
+       retstack_max = GROW(retstack_max);
        Renew(retstack, retstack_max, OP*);
     }
     retstack[retstack_ix++] = retop;
@@ -67,7 +97,7 @@ push_scope(void)
 {
     dTHR;
     if (scopestack_ix == scopestack_max) {
-       scopestack_max = scopestack_max * 3 / 2;
+       scopestack_max = GROW(scopestack_max);
        Renew(scopestack, scopestack_max, I32);
     }
     scopestack[scopestack_ix++] = savestack_ix;
@@ -87,7 +117,7 @@ markstack_grow(void)
 {
     dTHR;
     I32 oldmax = markstack_max - markstack;
-    I32 newmax = oldmax * 3 / 2;
+    I32 newmax = GROW(oldmax);
 
     Renew(markstack, newmax, I32);
     markstack_ptr = markstack + oldmax;
@@ -98,10 +128,12 @@ void
 savestack_grow(void)
 {
     dTHR;
-    savestack_max = savestack_max * 3 / 2;
+    savestack_max = GROW(savestack_max) + 4; 
     Renew(savestack, savestack_max, ANY);
 }
 
+#undef GROW
+
 void
 free_tmps(void)
 {
@@ -120,7 +152,7 @@ free_tmps(void)
     }
 }
 
-static SV *
+STATIC SV *
 save_scalar_at(SV **sptr)
 {
     dTHR;
@@ -451,7 +483,11 @@ 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
 {
     dTHR;
     SSCHECK(3);
@@ -715,7 +751,7 @@ leave_scope(I32 base)
            break;
        case SAVEt_DESTRUCTOR:
            ptr = SSPOPPTR;
-           (*SSPOPDPTR)(ptr);
+           (CALLDESTRUCTOR)(ptr);
            break;
        case SAVEt_REGCONTEXT:
            i = SSPOPINT;
@@ -771,11 +807,10 @@ leave_scope(I32 base)
     }
 }
 
-#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) {
@@ -864,5 +899,5 @@ cx_dump(PERL_CONTEXT *cx)
                (long)cx->sb_rxres);
        break;
     }
+#endif /* DEBUGGING */
 }
-#endif