grow PL_tmps_stack more efficiently; make it more amenable to
Gurusamy Sarathy [Sat, 3 Apr 1999 23:14:34 +0000 (23:14 +0000)]
STRESS_REALLOC testing

p4raw-id: //depot/perl@3215

embed.h
embed.pl
global.sym
objXSUB.h
pp.h
proto.h
scope.c
sv.c

diff --git a/embed.h b/embed.h
index e95c95c..fed0530 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define swash_init             Perl_swash_init
 #define taint_env              Perl_taint_env
 #define taint_proper           Perl_taint_proper
+#define tmps_grow              Perl_tmps_grow
 #define to_uni_lower           Perl_to_uni_lower
 #define to_uni_lower_lc                Perl_to_uni_lower_lc
 #define to_uni_title           Perl_to_uni_title
 #define sv_len_utf8            CPerlObj::Perl_sv_len_utf8
 #define sv_magic               CPerlObj::Perl_sv_magic
 #define sv_mortalcopy          CPerlObj::Perl_sv_mortalcopy
-#define sv_mortalgrow          CPerlObj::Perl_sv_mortalgrow
 #define sv_ncmp                        CPerlObj::Perl_sv_ncmp
 #define sv_newmortal           CPerlObj::Perl_sv_newmortal
 #define sv_newref              CPerlObj::Perl_sv_newref
 #define swash_init             CPerlObj::Perl_swash_init
 #define taint_env              CPerlObj::Perl_taint_env
 #define taint_proper           CPerlObj::Perl_taint_proper
+#define tmps_grow              CPerlObj::Perl_tmps_grow
 #define to_uni_lower           CPerlObj::Perl_to_uni_lower
 #define to_uni_lower_lc                CPerlObj::Perl_to_uni_lower_lc
 #define to_uni_title           CPerlObj::Perl_to_uni_title
index d089160..248792c 100755 (executable)
--- a/embed.pl
+++ b/embed.pl
@@ -225,7 +225,6 @@ my @staticfuncs = qw(
     del_xnv
     del_xpv
     del_xrv
-    sv_mortalgrow
     sv_unglob
     avhv_index_sv
     do_report_used
index 881ee76..e7d1e36 100644 (file)
@@ -578,6 +578,7 @@ swash_fetch
 swash_init
 taint_env
 taint_proper
+tmps_grow
 to_uni_lower
 to_uni_lower_lc
 to_uni_title
index 2c24b59..59856fd 100644 (file)
--- a/objXSUB.h
+++ b/objXSUB.h
 #define sv_magic               pPerl->Perl_sv_magic
 #undef  sv_mortalcopy
 #define sv_mortalcopy          pPerl->Perl_sv_mortalcopy
-#undef  sv_mortalgrow
-#define sv_mortalgrow          pPerl->Perl_sv_mortalgrow
 #undef  sv_ncmp
 #define sv_ncmp                        pPerl->Perl_sv_ncmp
 #undef  sv_newmortal
 #define taint_env              pPerl->Perl_taint_env
 #undef  taint_proper
 #define taint_proper           pPerl->Perl_taint_proper
+#undef  tmps_grow
+#define tmps_grow              pPerl->Perl_tmps_grow
 #undef  to_uni_lower
 #define to_uni_lower           pPerl->Perl_to_uni_lower
 #undef  to_uni_lower_lc
diff --git a/pp.h b/pp.h
index 7aeee70..2b8f233 100644 (file)
--- a/pp.h
+++ b/pp.h
 
 #define SWITCHSTACK(f,t) \
     STMT_START {                                                       \
-       AvFILLp(f) = sp - PL_stack_base;                                        \
+       AvFILLp(f) = sp - PL_stack_base;                                \
        PL_stack_base = AvARRAY(t);                                     \
-       PL_stack_max = PL_stack_base + AvMAX(t);                                \
+       PL_stack_max = PL_stack_base + AvMAX(t);                        \
        sp = PL_stack_sp = PL_stack_base + AvFILLp(t);                  \
-       PL_curstack = t;                                                        \
+       PL_curstack = t;                                                \
     } STMT_END
 
 #define EXTEND_MORTAL(n) \
-       STMT_START { \
-           if (PL_tmps_ix + (n) >= PL_tmps_max) \
-               Renew(PL_tmps_stack, PL_tmps_max = PL_tmps_ix + (n) + 1, SV*); \
-       } STMT_END
+    STMT_START {                                                       \
+       if (PL_tmps_ix + (n) >= PL_tmps_max)                            \
+           tmps_grow(n);                                               \
+    } STMT_END
 
 #define AMGf_noright   1
 #define AMGf_noleft    2
diff --git a/proto.h b/proto.h
index 0b1c962..cc98104 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -715,7 +715,6 @@ void del_xiv _((XPVIV* p));
 void del_xnv _((XPVNV* p));
 void del_xpv _((XPV* p));
 void del_xrv _((XRV* p));
-void sv_mortalgrow _((void));
 void sv_unglob _((SV* sv));
 I32 avhv_index_sv _((SV* sv));
 
@@ -967,3 +966,5 @@ VIRTUAL void reginitcolors _((void));
 VIRTUAL char* sv_2pv_nolen _((SV* sv));
 VIRTUAL char* sv_pv _((SV *sv));
 VIRTUAL void sv_force_normal _((SV *sv));
+VIRTUAL void tmps_grow _((I32 n));
+
diff --git a/scope.c b/scope.c
index 4d62ae8..b8d4558 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -135,6 +135,19 @@ savestack_grow(void)
 #undef GROW
 
 void
+tmps_grow(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
 free_tmps(void)
 {
     dTHR;
diff --git a/sv.c b/sv.c
index 95f69ea..be65acb 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -57,7 +57,6 @@ static void del_xiv _((XPVIV* p));
 static void del_xnv _((XPVNV* p));
 static void del_xpv _((XPV* p));
 static void del_xrv _((XRV* p));
-static void sv_mortalgrow _((void));
 static void sv_unglob _((SV* sv));
 
 #ifndef PURIFY
@@ -3551,14 +3550,6 @@ sv_dec(register SV *sv)
  * hopefully we won't free it until it has been assigned to a
  * permanent location. */
 
-STATIC void
-sv_mortalgrow(void)
-{
-    dTHR;
-    PL_tmps_max += (PL_tmps_max < 512) ? 128 : 512;
-    Renew(PL_tmps_stack, PL_tmps_max, SV*);
-}
-
 SV *
 sv_mortalcopy(SV *oldstr)
 {
@@ -3570,9 +3561,8 @@ sv_mortalcopy(SV *oldstr)
     SvREFCNT(sv) = 1;
     SvFLAGS(sv) = 0;
     sv_setsv(sv,oldstr);
-    if (++PL_tmps_ix >= PL_tmps_max)
-       sv_mortalgrow();
-    PL_tmps_stack[PL_tmps_ix] = sv;
+    EXTEND_MORTAL(1);
+    PL_tmps_stack[++PL_tmps_ix] = sv;
     SvTEMP_on(sv);
     return sv;
 }
@@ -3587,9 +3577,8 @@ sv_newmortal(void)
     SvANY(sv) = 0;
     SvREFCNT(sv) = 1;
     SvFLAGS(sv) = SVs_TEMP;
-    if (++PL_tmps_ix >= PL_tmps_max)
-       sv_mortalgrow();
-    PL_tmps_stack[PL_tmps_ix] = sv;
+    EXTEND_MORTAL(1);
+    PL_tmps_stack[++PL_tmps_ix] = sv;
     return sv;
 }
 
@@ -3603,9 +3592,8 @@ sv_2mortal(register SV *sv)
        return sv;
     if (SvREADONLY(sv) && SvIMMORTAL(sv))
        return sv;
-    if (++PL_tmps_ix >= PL_tmps_max)
-       sv_mortalgrow();
-    PL_tmps_stack[PL_tmps_ix] = sv;
+    EXTEND_MORTAL(1);
+    PL_tmps_stack[++PL_tmps_ix] = sv;
     SvTEMP_on(sv);
     return sv;
 }