This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Extend STRESS_REALLOC to move the stack with every EXTEND
authorFather Chrysostomos <sprout@cpan.org>
Thu, 21 Nov 2013 04:39:56 +0000 (20:39 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 05:20:37 +0000 (21:20 -0800)
This allows us easily to catch cases where the stack could move to a
new memory address while code still holds pointers to the old loca-
tion.  Indeed, this causes test failures.

av.c
pp.h

diff --git a/av.c b/av.c
index bae7e61..d5dda54 100644 (file)
--- a/av.c
+++ b/av.c
@@ -143,7 +143,16 @@ Perl_av_extend_guts(pTHX_ AV *av, SSize_t key, SSize_t *maxp, SV ***allocp,
 #endif
                    MEM_WRAP_CHECK_1(newmax+1, SV*, oom_array_extend);
                }
+#ifdef STRESS_REALLOC
+               {
+                   SV ** const old_alloc = *allocp;
+                   Newx(*allocp, newmax+1, SV*);
+                   Copy(old_alloc, *allocp, *maxp + 1, SV*);
+                   Safefree(old_alloc);
+               }
+#else
                Renew(*allocp,newmax+1, SV*);
+#endif
 #ifdef Perl_safesysmalloc_size
              resized:
 #endif
diff --git a/pp.h b/pp.h
index 42e63fa..820c81b 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -270,15 +270,25 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 =cut
 */
 
-#define EXTEND(p,n)    (void)(UNLIKELY(PL_stack_max - p < (SSize_t)(n)) &&     \
+#ifdef STRESS_REALLOC
+# define EXTEND(p,n)   (void)(sp = stack_grow(sp,p, (SSize_t)(n)))
+/* Same thing, but update mark register too. */
+# define MEXTEND(p,n)  STMT_START {                                    \
+                           const int markoff = mark - PL_stack_base;   \
+                           sp = stack_grow(sp,p,(SSize_t) (n));        \
+                           mark = PL_stack_base + markoff;             \
+                       } STMT_END
+#else
+# define EXTEND(p,n)   (void)(UNLIKELY(PL_stack_max - p < (SSize_t)(n)) &&     \
                            (sp = stack_grow(sp,p, (SSize_t) (n))))
 
 /* Same thing, but update mark register too. */
-#define MEXTEND(p,n)   STMT_START {if (UNLIKELY(PL_stack_max - p < (int)(n))) {\
+# define MEXTEND(p,n)  STMT_START {if (UNLIKELY(PL_stack_max - p < (int)(n))) {\
                            const int markoff = mark - PL_stack_base;           \
                            sp = stack_grow(sp,p,(SSize_t) (n));                \
                            mark = PL_stack_base + markoff;                     \
                        } } STMT_END
+#endif
 
 #define PUSHs(s)       (*++sp = (s))
 #define PUSHTARG       STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END