Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] MARK -Ds debugging #14589

Closed
p5pRT opened this issue Mar 16, 2015 · 10 comments
Closed

[PATCH] MARK -Ds debugging #14589

p5pRT opened this issue Mar 16, 2015 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 16, 2015

Migrated from rt.perl.org#124080 (status was 'resolved')

Searchable as RT124080$

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2015

From @rurban

This is a bug report for perl from rurban@​cpanel.net,
generated with the help of perlbug 1.40 running under perl 5.21.9.


Add DEBUGGING versions of the MARK macros
to display the arity of op and functions calls.
Also assert on markstack underflow.

This might also be helpful on davem's signature op work, e.g.
by using the stack directly and not copying @​_.



Flags​:
  category=core
  severity=medium
  Type=Patch
  PatchStatus=HasPatch


Site configuration information for perl 5.21.9​:

Configured by rurban at Sun Feb 22 17​:14​:55 CET 2015.

Summary of my perl5 (revision 5 version 21 subversion 9) configuration​:
 
  Platform​:
  osname=linux, osvers=3.16.0-4-amd64, archname=x86_64-linux-debug
  uname='linux reini 3.16.0-4-amd64 #1 smp debian 3.16.7-ckt2-1 (2014-12-08) x86_64 gnulinux '
  config_args='-de -Dusedevel -Uversiononly -Dinstallman1dir=none -Dinstallman3dir=none -Dinstallsiteman1dir=none -Dinstallsiteman3dir=none -DEBUGGING -Doptimize='-g3' -Uuseithreads -D'cc=gcc-5.0' -Accflags=''-msse4.2'' -Accflags=''-march=corei7'' -Dcf_email=''rurban@​cpanel.net'' -Dperladmin=''rurban@​cpanel.net'''
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc-5.0', ccflags ='-msse4.2 -march=corei7 -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-g3',
  cppflags='-msse4.2 -march=corei7 -fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion='', gccversion='5.0.0 20150103 (experimental)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='gcc-5.0', ldflags =' -fstack-protector-strong -L/usr/local/lib'
  libpth=/usr/local/lib /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.0.0/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64 /usr/local/lib64
  libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
  perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.19'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -g3 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches​:
  Devel​::PatchPerl 1.30


@​INC for perl 5.21.9​:
  /usr/local/lib/perl5/site_perl/5.21.9/x86_64-linux-debug
  /usr/local/lib/perl5/site_perl/5.21.9
  /usr/local/lib/perl5/5.21.9/x86_64-linux-debug
  /usr/local/lib/perl5/5.21.9
  /usr/local/lib/perl5/site_perl/5.21.8
  /usr/local/lib/perl5/site_perl/5.21.7
  /usr/local/lib/perl5/site_perl/5.21.4
  /usr/local/lib/perl5/site_perl/5.21.3
  /usr/local/lib/perl5/site_perl/5.21.2
  /usr/local/lib/perl5/site_perl/5.21.1
  /usr/local/lib/perl5/site_perl/5.21.0
  /usr/local/lib/perl5/site_perl/5.20.1
  /usr/local/lib/perl5/site_perl/5.20.0
  /usr/local/lib/perl5/site_perl/5.19.11
  /usr/local/lib/perl5/site_perl/5.19.10
  /usr/local/lib/perl5/site_perl/5.19.9
  /usr/local/lib/perl5/site_perl/5.19.8
  /usr/local/lib/perl5/site_perl/5.19.7
  /usr/local/lib/perl5/site_perl/5.19.6
  /usr/local/lib/perl5/site_perl/5.19.5
  /usr/local/lib/perl5/site_perl/5.19.4
  /usr/local/lib/perl5/site_perl/5.19.3
  /usr/local/lib/perl5/site_perl/5.19.2
  /usr/local/lib/perl5/site_perl/5.19.1
  /usr/local/lib/perl5/site_perl/5.19.0
  /usr/local/lib/perl5/site_perl/5.18.4
  /usr/local/lib/perl5/site_perl/5.18.2
  /usr/local/lib/perl5/site_perl/5.18.1
  /usr/local/lib/perl5/site_perl/5.18.0
  /usr/local/lib/perl5/site_perl/5.17.11
  /usr/local/lib/perl5/site_perl/5.17.10
  /usr/local/lib/perl5/site_perl/5.17.8
  /usr/local/lib/perl5/site_perl/5.17.7
  /usr/local/lib/perl5/site_perl/5.17.6
  /usr/local/lib/perl5/site_perl/5.17.5
  /usr/local/lib/perl5/site_perl/5.17.4
  /usr/local/lib/perl5/site_perl/5.17.3
  /usr/local/lib/perl5/site_perl/5.17.2
  /usr/local/lib/perl5/site_perl/5.17.1
  /usr/local/lib/perl5/site_perl/5.17.0
  /usr/local/lib/perl5/site_perl/5.17
  /usr/local/lib/perl5/site_perl/5.16.3
  /usr/local/lib/perl5/site_perl/5.16.2
  /usr/local/lib/perl5/site_perl/5.16.1
  /usr/local/lib/perl5/site_perl/5.16.0
  /usr/local/lib/perl5/site_perl/5.15.9
  /usr/local/lib/perl5/site_perl/5.15.8
  /usr/local/lib/perl5/site_perl/5.15.7
  /usr/local/lib/perl5/site_perl/5.15.6
  /usr/local/lib/perl5/site_perl/5.15.5
  /usr/local/lib/perl5/site_perl/5.15.4
  /usr/local/lib/perl5/site_perl/5.15.3
  /usr/local/lib/perl5/site_perl/5.15.2
  /usr/local/lib/perl5/site_perl/5.14.4
  /usr/local/lib/perl5/site_perl/5.14.3
  /usr/local/lib/perl5/site_perl/5.14.2
  /usr/local/lib/perl5/site_perl/5.14.1
  /usr/local/lib/perl5/site_perl/5.12.5
  /usr/local/lib/perl5/site_perl/5.12.4
  /usr/local/lib/perl5/site_perl/5.10.1
  /usr/local/lib/perl5/site_perl/5.8.9
  /usr/local/lib/perl5/site_perl/5.8.8
  /usr/local/lib/perl5/site_perl/5.8.7
  /usr/local/lib/perl5/site_perl/5.8.6
  /usr/local/lib/perl5/site_perl/5.8.5
  /usr/local/lib/perl5/site_perl/5.8.4
  /usr/local/lib/perl5/site_perl/5.8.3
  /usr/local/lib/perl5/site_perl/5.8.2
  /usr/local/lib/perl5/site_perl/5.8.1
  /usr/local/lib/perl5/site_perl/5.6.2
  /usr/local/lib/perl5/site_perl
  .


Environment for perl 5.21.9​:
  HOME=/home/rurban
  LANG=en_US.utf8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/rurban/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/local/games​:/usr/games
  PERL_BADLANG (unset)
  PERL_DL_DEBUG=
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 16, 2015

From @rurban

0001-MARK-Ds-debugging.patch
From 21330370d887e5ce7ed0dc0c1c12eb325d25c25e Mon Sep 17 00:00:00 2001
From: Reini Urban <rurban@cpanel.net>
Date: Mon, 16 Mar 2015 10:27:37 +0100
Subject: [PATCH 1/2] MARK -Ds debugging

display the MARK arity and pointers with MARK macros.
assert on markptr underflow.
---
 perl.c   |  4 ++--
 pp.h     | 51 +++++++++++++++++++++++++++++++++++++++++----------
 pp_ctl.c | 12 ++++++------
 pp_hot.c |  4 ++--
 scope.c  |  2 ++
 5 files changed, 53 insertions(+), 20 deletions(-)

diff --git perl.c perl.c
index eebe150..9c02c3e 100644
--- perl.c
+++ perl.c
@@ -2736,9 +2736,9 @@ Perl_call_sv(pTHX_ SV *sv, VOL I32 flags)
     }
     else {
 	myop.op_other = (OP*)&myop;
-	PL_markstack_ptr--;
+	POPMARK;
 	create_eval_scope(flags|G_FAKINGEVAL);
-	PL_markstack_ptr++;
+	INCMARK;
 
 	JMPENV_PUSH(ret);
 
diff --git pp.h pp.h
index 2636dbf..3732d59 100644
--- pp.h
+++ pp.h
@@ -55,16 +55,47 @@ Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
 #define MARK mark
 #define TARG targ
 
-#define PUSHMARK(p)	\
-	STMT_START {					\
-	    I32 * mark_stack_entry;			\
-	    if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max))	\
-	    mark_stack_entry = markstack_grow();					\
-	    *mark_stack_entry  = (I32)((p) - PL_stack_base);				\
+#ifdef DEBUGGING
+#define PUSHMARK(p)                                                   \
+    STMT_START {					              \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+	    mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK push %p %d\n",    \
+                PL_markstack_ptr, *mark_stack_entry));                \
 	} STMT_END
-
-#define TOPMARK		(*PL_markstack_ptr)
-#define POPMARK		(*PL_markstack_ptr--)
+#define TOPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top  %p %d\n",    \
+                PL_markstack_ptr, *PL_markstack_ptr));                \
+        *PL_markstack_ptr;                                            \
+    })
+#define POPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK pop  %p %d\n",    \
+                (PL_markstack_ptr-1), *(PL_markstack_ptr-1)));        \
+        assert((PL_markstack_ptr > PL_markstack) || "MARK underflow");\
+        *PL_markstack_ptr--;                                          \
+    })
+#define INCMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK inc  %p %d\n",    \
+                (PL_markstack_ptr+1), *(PL_markstack_ptr+1)));        \
+        *PL_markstack_ptr++;                                          \
+    })
+#else
+#define PUSHMARK(p)                                                   \
+    STMT_START {					              \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+	    mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+    } STMT_END
+#define TOPMARK                (*PL_markstack_ptr)
+#define POPMARK                (*PL_markstack_ptr--)
+#define INCMARK                (*PL_markstack_ptr++)
+#endif
 
 #define dSP		SV **sp = PL_stack_sp
 #define djSP		dSP
@@ -465,7 +496,7 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 		while (jump_o->op_type == OP_NULL)		\
 		    jump_o = jump_o->op_next;			\
 		assert(jump_o->op_type == OP_ENTERSUB);		\
-		PL_markstack_ptr--;				\
+		POPMARK;                                        \
 		return jump_o->op_next;				\
 	    }							\
 	    return NORMAL;					\
diff --git pp_ctl.c pp_ctl.c
index f7cb216..409e0e3 100644
--- pp_ctl.c
+++ pp_ctl.c
@@ -921,13 +921,13 @@ PP(pp_grepstart)
     dSP;
     SV *src;
 
-    if (PL_stack_base + *PL_markstack_ptr == SP) {
+    if (PL_stack_base + TOPMARK == SP) {
 	(void)POPMARK;
 	if (GIMME_V == G_SCALAR)
 	    mXPUSHi(0);
 	RETURNOP(PL_op->op_next->op_next);
     }
-    PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
+    PL_stack_sp = PL_stack_base + TOPMARK + 1;
     Perl_pp_pushmark(aTHX);				/* push dst */
     Perl_pp_pushmark(aTHX);				/* push src */
     ENTER_with_name("grep");					/* enter outer scope */
@@ -940,9 +940,9 @@ PP(pp_grepstart)
     ENTER_with_name("grep_item");					/* enter inner scope */
     SAVEVPTR(PL_curpm);
 
-    src = PL_stack_base[*PL_markstack_ptr];
+    src = PL_stack_base[TOPMARK];
     if (SvPADTMP(src)) {
-	src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+	src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
 	PL_tmps_floor++;
     }
     SvTEMP_off(src);
@@ -961,7 +961,7 @@ PP(pp_mapwhile)
 {
     dSP;
     const I32 gimme = GIMME_V;
-    I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
+    I32 items = (SP - PL_stack_base) - TOPMARK; /* how many new items */
     I32 count;
     I32 shift;
     SV** src;
@@ -1062,7 +1062,7 @@ PP(pp_mapwhile)
     LEAVE_with_name("grep_item");					/* exit inner scope */
 
     /* All done yet? */
-    if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
+    if (PL_markstack_ptr[-1] > TOPMARK) {
 
 	(void)POPMARK;				/* pop top */
 	LEAVE_with_name("grep");					/* exit outer scope */
diff --git pp_hot.c pp_hot.c
index a820c87..5b86c5b 100644
--- pp_hot.c
+++ pp_hot.c
@@ -2923,9 +2923,9 @@ PP(pp_grepwhile)
 	ENTER_with_name("grep_item");					/* enter inner scope */
 	SAVEVPTR(PL_curpm);
 
-	src = PL_stack_base[*PL_markstack_ptr];
+	src = PL_stack_base[TOPMARK];
 	if (SvPADTMP(src)) {
-	    src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+	    src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
 	    PL_tmps_floor++;
 	}
 	SvTEMP_off(src);
diff --git scope.c scope.c
index 89b4e6e..6527fd1 100644
--- scope.c
+++ scope.c
@@ -113,6 +113,8 @@ Perl_markstack_grow(pTHX)
     Renew(PL_markstack, newmax, I32);
     PL_markstack_max = PL_markstack + newmax;
     PL_markstack_ptr = PL_markstack + oldmax;
+    DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK grow %p %d by %d\n",
+            PL_markstack_ptr, *PL_markstack_ptr, oldmax));
     return PL_markstack_ptr;
 }
 
-- 
2.1.4

@p5pRT
Copy link
Author

p5pRT commented Apr 13, 2015

From @tonycoz

On Mon Mar 16 03​:39​:29 2015, rurban@​cpanel.net wrote​:

This is a bug report for perl from rurban@​cpanel.net,
generated with the help of perlbug 1.40 running under perl 5.21.9.

-----------------------------------------------------------------
Add DEBUGGING versions of the MARK macros
to display the arity of op and functions calls.
Also assert on markstack underflow.

This might also be helpful on davem's signature op work, e.g.
by using the stack directly and not copying @​_.

This​:

+#define TOPMARK \
+ ({ \
+ DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top %p %d\n", \
+ PL_markstack_ptr, *PL_markstack_ptr)); \
+ *PL_markstack_ptr; \
+ })

is a gcc-ism and won't work on other compilers (except maybe clang.)

Similarly for POPMARK and INCMARK.

Tony

@p5pRT
Copy link
Author

p5pRT commented Apr 13, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 13, 2015

From @rurban

On 04/13/2015 02​:02 AM, Tony Cook via RT wrote​:

On Mon Mar 16 03​:39​:29 2015, rurban@​cpanel.net wrote​:

This is a bug report for perl from rurban@​cpanel.net,
generated with the help of perlbug 1.40 running under perl 5.21.9.

-----------------------------------------------------------------
Add DEBUGGING versions of the MARK macros
to display the arity of op and functions calls.
Also assert on markstack underflow.

This might also be helpful on davem's signature op work, e.g.
by using the stack directly and not copying @​_.

This​:

+#define TOPMARK \
+ ({ \
+ DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top %p %d\n", \
+ PL_markstack_ptr, *PL_markstack_ptr)); \
+ *PL_markstack_ptr; \
+ })

is a gcc-ism and won't work on other compilers (except maybe clang.)

Similarly for POPMARK and INCMARK.

Right. Forgot checking for #ifdef PERL_USE_GCC_BRACE_GROUPS

Attached patch should be better.

@p5pRT
Copy link
Author

p5pRT commented Apr 13, 2015

From @rurban

0001-MARK-Ds-debugging.patch
From 990f60df9927a63a8dcf10452764214b9326fe3a Mon Sep 17 00:00:00 2001
From: Reini Urban <rurban@cpanel.net>
Date: Mon, 16 Mar 2015 10:27:37 +0100
Subject: [PATCH] MARK -Ds debugging

display the MARK arity and pointers with MARK macros.
assert on markptr underflow.
---
 perl.c   |  4 ++--
 pp.h     | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
 pp_ctl.c | 12 ++++++------
 pp_hot.c |  4 ++--
 scope.c  |  2 ++
 5 files changed, 54 insertions(+), 21 deletions(-)

diff --git perl.c perl.c
index eebe150..9c02c3e 100644
--- perl.c
+++ perl.c
@@ -2736,9 +2736,9 @@ Perl_call_sv(pTHX_ SV *sv, VOL I32 flags)
     }
     else {
 	myop.op_other = (OP*)&myop;
-	PL_markstack_ptr--;
+	POPMARK;
 	create_eval_scope(flags|G_FAKINGEVAL);
-	PL_markstack_ptr++;
+	INCMARK;
 
 	JMPENV_PUSH(ret);
 
diff --git pp.h pp.h
index 2636dbf..5e2fe0c 100644
--- pp.h
+++ pp.h
@@ -55,16 +55,47 @@ Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
 #define MARK mark
 #define TARG targ
 
-#define PUSHMARK(p)	\
-	STMT_START {					\
-	    I32 * mark_stack_entry;			\
-	    if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max))	\
-	    mark_stack_entry = markstack_grow();					\
-	    *mark_stack_entry  = (I32)((p) - PL_stack_base);				\
-	} STMT_END
-
-#define TOPMARK		(*PL_markstack_ptr)
-#define POPMARK		(*PL_markstack_ptr--)
+#if defined(DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
+#define PUSHMARK(p)                                                   \
+    STMT_START {                                                      \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+	    mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK push %p %d\n",    \
+                PL_markstack_ptr, *mark_stack_entry));                \
+    } STMT_END
+#define TOPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top  %p %d\n",    \
+                PL_markstack_ptr, *PL_markstack_ptr));                \
+        *PL_markstack_ptr;                                            \
+    })
+#define POPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK pop  %p %d\n",    \
+                (PL_markstack_ptr-1), *(PL_markstack_ptr-1)));        \
+        assert((PL_markstack_ptr > PL_markstack) || "MARK underflow");\
+        *PL_markstack_ptr--;                                          \
+    })
+#define INCMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK inc  %p %d\n",    \
+                (PL_markstack_ptr+1), *(PL_markstack_ptr+1)));        \
+        *PL_markstack_ptr++;                                          \
+    })
+#else
+#define PUSHMARK(p)                                                   \
+    STMT_START {					              \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+	    mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+    } STMT_END
+#define TOPMARK                (*PL_markstack_ptr)
+#define POPMARK                (*PL_markstack_ptr--)
+#define INCMARK                (*PL_markstack_ptr++)
+#endif
 
 #define dSP		SV **sp = PL_stack_sp
 #define djSP		dSP
@@ -465,7 +496,7 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 		while (jump_o->op_type == OP_NULL)		\
 		    jump_o = jump_o->op_next;			\
 		assert(jump_o->op_type == OP_ENTERSUB);		\
-		PL_markstack_ptr--;				\
+		POPMARK;                                        \
 		return jump_o->op_next;				\
 	    }							\
 	    return NORMAL;					\
diff --git pp_ctl.c pp_ctl.c
index f7cb216..409e0e3 100644
--- pp_ctl.c
+++ pp_ctl.c
@@ -921,13 +921,13 @@ PP(pp_grepstart)
     dSP;
     SV *src;
 
-    if (PL_stack_base + *PL_markstack_ptr == SP) {
+    if (PL_stack_base + TOPMARK == SP) {
 	(void)POPMARK;
 	if (GIMME_V == G_SCALAR)
 	    mXPUSHi(0);
 	RETURNOP(PL_op->op_next->op_next);
     }
-    PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
+    PL_stack_sp = PL_stack_base + TOPMARK + 1;
     Perl_pp_pushmark(aTHX);				/* push dst */
     Perl_pp_pushmark(aTHX);				/* push src */
     ENTER_with_name("grep");					/* enter outer scope */
@@ -940,9 +940,9 @@ PP(pp_grepstart)
     ENTER_with_name("grep_item");					/* enter inner scope */
     SAVEVPTR(PL_curpm);
 
-    src = PL_stack_base[*PL_markstack_ptr];
+    src = PL_stack_base[TOPMARK];
     if (SvPADTMP(src)) {
-	src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+	src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
 	PL_tmps_floor++;
     }
     SvTEMP_off(src);
@@ -961,7 +961,7 @@ PP(pp_mapwhile)
 {
     dSP;
     const I32 gimme = GIMME_V;
-    I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
+    I32 items = (SP - PL_stack_base) - TOPMARK; /* how many new items */
     I32 count;
     I32 shift;
     SV** src;
@@ -1062,7 +1062,7 @@ PP(pp_mapwhile)
     LEAVE_with_name("grep_item");					/* exit inner scope */
 
     /* All done yet? */
-    if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
+    if (PL_markstack_ptr[-1] > TOPMARK) {
 
 	(void)POPMARK;				/* pop top */
 	LEAVE_with_name("grep");					/* exit outer scope */
diff --git pp_hot.c pp_hot.c
index a820c87..5b86c5b 100644
--- pp_hot.c
+++ pp_hot.c
@@ -2923,9 +2923,9 @@ PP(pp_grepwhile)
 	ENTER_with_name("grep_item");					/* enter inner scope */
 	SAVEVPTR(PL_curpm);
 
-	src = PL_stack_base[*PL_markstack_ptr];
+	src = PL_stack_base[TOPMARK];
 	if (SvPADTMP(src)) {
-	    src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+	    src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
 	    PL_tmps_floor++;
 	}
 	SvTEMP_off(src);
diff --git scope.c scope.c
index 89b4e6e..6527fd1 100644
--- scope.c
+++ scope.c
@@ -113,6 +113,8 @@ Perl_markstack_grow(pTHX)
     Renew(PL_markstack, newmax, I32);
     PL_markstack_max = PL_markstack + newmax;
     PL_markstack_ptr = PL_markstack + oldmax;
+    DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK grow %p %d by %d\n",
+            PL_markstack_ptr, *PL_markstack_ptr, oldmax));
     return PL_markstack_ptr;
 }
 
-- 
2.1.4

@p5pRT
Copy link
Author

p5pRT commented Oct 15, 2015

From @tonycoz

On Mon Apr 13 08​:05​:15 2015, rurban@​cpanel.net wrote​:

Right. Forgot checking for #ifdef PERL_USE_GCC_BRACE_GROUPS

Attached patch should be better.

Thanks, I was just looking at it to apply it, but noticed​:

+ assert((PL_markstack_ptr > PL_markstack) || "MARK underflow");\

which is an assertion that can't fail.

Should that be​:

  assert(("MARK underflow", PL_markstack_ptr > PL_markstack));\

since I'm assuming the string is there to make an assertion failure more understandable.

It's kind of a pity the DEBUG_x macros use if(), otherwise each of the MARK macros you're updating could just be comma-expressions.

Tony

@p5pRT
Copy link
Author

p5pRT commented Oct 15, 2015

From @rurban

On Oct 15, 2015, at 3​:13 AM, Tony Cook via RT <perlbug-followup@​perl.org> wrote​:

On Mon Apr 13 08​:05​:15 2015, rurban@​cpanel.net wrote​:

Right. Forgot checking for #ifdef PERL_USE_GCC_BRACE_GROUPS

Attached patch should be better.

Thanks, I was just looking at it to apply it, but noticed​:

+ assert((PL_markstack_ptr > PL_markstack) || "MARK underflow");\

which is an assertion that can't fail.

Uh, yes. Excellent catch. It should of course be​:

  assert((PL_markstack_ptr > PL_markstack) || !"MARK underflow");\

Should that be​:

assert(("MARK underflow", PL_markstack_ptr > PL_markstack));\

since I'm assuming the string is there to make an assertion failure more understandable.

It's kind of a pity the DEBUG_x macros use if(), otherwise each of the MARK macros you're updating could just be comma-expressions.

I’m not a friend of comma expressions if pure conditionals can do the same.

Reini Urban
rurban@​cpanel.net

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

From @tonycoz

On Thu Oct 15 00​:57​:36 2015, reini@​cpanel.net wrote​:

On Oct 15, 2015, at 3​:13 AM, Tony Cook via RT <perlbug-
Thanks, I was just looking at it to apply it, but noticed​:

+ assert((PL_markstack_ptr > PL_markstack) || "MARK
underflow");\

which is an assertion that can't fail.

Uh, yes. Excellent catch. It should of course be​:

assert((PL_markstack_ptr > PL_markstack) || !"MARK underflow");\

Applied with that changed as 6cae08a.

Tony

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant