Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh malloc bug



Dave Yost wrote:
> A real example follows.

Finaly got around to looking, thanks for the script.

Rather embarassingly, it turns out EXIT traps on scripts are completely
broken.  You just need to do:

zsh -fc 'TRAPEXIT() { print Ooh-er.; }'

It's now documented that special traps such as EXIT don't run inside
other traps, so the following simple fix ought to be fine.

Are there any remaining trap problems after this?

I added a variable to give the name of the zsh executable inside tests,
so we can test this kind of thing.  As you'll see it's a bit imperfect.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.67
diff -u -r1.67 exec.c
--- Src/exec.c	7 Jul 2004 15:00:57 -0000	1.67
+++ Src/exec.c	26 Jul 2004 13:02:33 -0000
@@ -3495,7 +3495,8 @@
 	memcpy(oldpipestats, pipestats, bytes);
     }
 
-    starttrapscope();
+    if (!intrap)
+	starttrapscope();
 
     tab = pparams;
     if (!(flags & PM_UNDEFINED))
@@ -3595,7 +3596,8 @@
 	opts[LOCALOPTIONS] = saveopts[LOCALOPTIONS];
     }
 
-    endtrapscope();
+    if (!intrap)
+	endtrapscope();
 
     if (trapreturn < -1)
 	trapreturn++;
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.28
diff -u -r1.28 signals.c
--- Src/signals.c	2 May 2004 19:55:58 -0000	1.28
+++ Src/signals.c	26 Jul 2004 13:02:34 -0000
@@ -939,6 +939,10 @@
  * with non-standard sigtrapped & sigfuncs values
  */
 
+/* Are we already executing a trap? */
+/**/
+int intrap;
+
 /**/
 void
 dotrapargs(int sig, int *sigtr, void *sigfn)
@@ -949,9 +953,6 @@
     int obreaks = breaks;
     int isfunc;
 
-    /* Are we already executing a trap? */
-    static int intrap;
-
     /* if signal is being ignored or the trap function		      *
      * is NULL, then return					      *
      *								      *
Index: Test/C03traps.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v
retrieving revision 1.3
diff -u -r1.3 C03traps.ztst
--- Test/C03traps.ztst	10 Mar 2004 10:50:03 -0000	1.3
+++ Test/C03traps.ztst	26 Jul 2004 13:02:34 -0000
@@ -57,6 +57,13 @@
 >Function 1 going
 >Function 2 going
 
+# $ZTST_exe is relative to the parent directory.
+# We ought to fix this in ztst.zsh...
+  cd ..
+  $ZTST_exe -fc 'TRAPEXIT() { print Exited.; }'
+0:EXIT traps on a script
+>Exited.
+
   fn1() {
     trap
     trap 'print INT1' INT
Index: Test/Makefile.in
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- Test/Makefile.in	12 Aug 2001 19:43:13 -0000	1.7
+++ Test/Makefile.in	26 Jul 2004 13:02:34 -0000
@@ -46,7 +46,8 @@
 	  $(MAKE) MODDIR=`pwd`/$(subdir)/Modules install.modules > /dev/null; \
 	fi
 	-for f in $(sdir)/$(TESTNUM)*.ztst; do \
-	  $(dir_top)/Src/zsh +Z -f $(sdir)/ztst.zsh $$f; \
+	  ZTST_exe=$(dir_top)/Src/zsh \
+	    $(dir_top)/Src/zsh +Z -f $(sdir)/ztst.zsh $$f; \
 	done
 	rm -rf Modules .zcompdump
 
Index: Test/ztst.zsh
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/ztst.zsh,v
retrieving revision 1.18
diff -u -r1.18 ztst.zsh
--- Test/ztst.zsh	5 Aug 2002 13:10:03 -0000	1.18
+++ Test/ztst.zsh	26 Jul 2004 13:02:35 -0000
@@ -31,6 +31,8 @@
 # Set the module load path to correspond to this build of zsh.
 # This Modules directory should have been created by "make check".
 [[ -d Modules/zsh ]] && module_path=( $PWD/Modules )
+# Allow this to be passed down.
+export MODULE_PATH
 
 # We need to be able to save and restore the options used in the test.
 # We use the $options variable of the parameter module for this.


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author