zsh-workers
 help / color / mirror / code / Atom feed
* Bug/misfeature with autoloaded TRAPxxx functions
@ 2004-04-13  5:15 Bart Schaefer
  2004-04-20 12:09 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-04-13  5:15 UTC (permalink / raw)
  To: zsh-workers

zagzig% echo $ZSH_VERSION
4.2.0-dev-1
zagzig% print $-
569XZfims
zagzig% autoload TRAPALRM
zagzig% functions
TRAPALRM () {
        # undefined
        builtin autoload -X
}
zagzig% unfunction TRAPALRM
unfunction: no such hash table element: TRAPALRM
zagzig% functions
TRAPALRM () {
        # undefined
        builtin autoload -X
}
zagzig% trap
zagzig% 


It's impossible to delete TRAPALRM without first defining it.  Also, no
attempt to autoload the function is made when the ALRM signal arrives:

zagzig% kill -ALRM $$
zsh: timeout

(The shell has now exited.)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug/misfeature with autoloaded TRAPxxx functions
  2004-04-13  5:15 Bug/misfeature with autoloaded TRAPxxx functions Bart Schaefer
@ 2004-04-20 12:09 ` Peter Stephenson
  2004-04-21 16:06   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2004-04-20 12:09 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> ... autoloaded TRAP functions don't work...

I don't think this ever got added... It might be as simple as the
following, which seems to work.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.114
diff -u -r1.114 builtin.c
--- Src/builtin.c	6 Apr 2004 09:25:18 -0000	1.114
+++ Src/builtin.c	20 Apr 2004 12:05:12 -0000
@@ -2499,14 +2499,32 @@
 		/* no flags, so just print */
 		shfunctab->printnode((HashNode) shf, pflags);
 	} else if (on & PM_UNDEFINED) {
+	    int signum, ok = 1;
+
 	    /* Add a new undefined (autoloaded) function to the *
 	     * hash table with the corresponding flags set.     */
 	    shf = (Shfunc) zshcalloc(sizeof *shf);
 	    shf->flags = on;
 	    shf->funcdef = mkautofn(shf);
-	    shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
-	    if (OPT_ISSET(ops,'X') && eval_autoload(shf, shf->nam, ops, func))
-		returnval = 1;
+
+	    if (!strncmp(*argv, "TRAP", 4) &&
+		(signum = getsignum(*argv + 4)) != -1) {
+		if (settrap(signum, shf->funcdef)) {
+		    freeeprog(shf->funcdef);
+		    zfree(shf, sizeof(*shf));
+		    returnval = 1;
+		    ok = 0;
+		}
+		else
+		    sigtrapped[signum] |= ZSIG_FUNC;
+	    }
+
+	    if (ok) {
+		shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
+		if (OPT_ISSET(ops,'X') &&
+		    eval_autoload(shf, shf->nam, ops, func))
+		    returnval = 1;
+	    }
 	} else
 	    returnval = 1;
     }

-- 
Peter Stephenson <pws@csr.com>                  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
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug/misfeature with autoloaded TRAPxxx functions
  2004-04-20 12:09 ` Peter Stephenson
@ 2004-04-21 16:06   ` Bart Schaefer
  2004-04-21 17:49     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-04-21 16:06 UTC (permalink / raw)
  To: zsh-workers

On Apr 20,  1:09pm, Peter Stephenson wrote:
} Subject: Re: Bug/misfeature with autoloaded TRAPxxx functions
}
} Bart Schaefer wrote:
} > ... autoloaded TRAP functions don't work...
} 
} I don't think this ever got added... It might be as simple as the
} following, which seems to work.

I worry that there's a race condition between setting sigtrapped[signum]
and actually adding the function node.  And what happens if the fucntion
fails to load?  Does sigtrapped[signum] get cleared somewhere else?

Otherwise it looks like the right idea.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug/misfeature with autoloaded TRAPxxx functions
  2004-04-21 16:06   ` Bart Schaefer
@ 2004-04-21 17:49     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2004-04-21 17:49 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> I worry that there's a race condition between setting sigtrapped[signum]
> and actually adding the function node.

Well, I would guess there are various possible races, many of which were
already in the TRAP function handling.

I suppose this fixes the one you are worried about.

> And what happens if the fucntion
> fails to load?  Does sigtrapped[signum] get cleared somewhere else?

No, but it's consistent with other failed functions.

% autoload spooble
% spooble
zsh: spooble: function definition file not found
% spooble
zsh: spooble: function definition file not found
% autoload TRAPZERR
% false
zsh: TRAPZERR: function definition file not found
% false
zsh: TRAPZERR: function definition file not found

With the current behaviour of retrying, clearing the trap doesn't look
like the right thing to do.

However, there seems to be a bug somewhere anyway.

% autoload TRAPZERR
% echo <TAB>
...
% false
zsh: segmentation fault (core dumped)  ./zsh

Happens whether or not the autoload was successful, interestingly.
Doesn't happen if you successfully autoload the trap before completion
(or define TRAPZERR inline).  Symptom is an empty state->prog->shf in
execautofn.

Also, $functions don't show TRAP functions.

Index: builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.117
diff -u -r1.117 builtin.c
--- builtin.c	20 Apr 2004 12:57:35 -0000	1.117
+++ builtin.c	21 Apr 2004 17:23:27 -0000
@@ -2515,12 +2515,13 @@
 	    shf = (Shfunc) zshcalloc(sizeof *shf);
 	    shf->flags = on;
 	    shf->funcdef = mkautofn(shf);
+	    shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
 
 	    if (!strncmp(*argv, "TRAP", 4) &&
 		(signum = getsignum(*argv + 4)) != -1) {
 		if (settrap(signum, shf->funcdef)) {
-		    freeeprog(shf->funcdef);
-		    zfree(shf, sizeof(*shf));
+		    shfunctab->removenode(shfunctab, *argv);
+		    shfunctab->freenode((HashNode)shf);
 		    returnval = 1;
 		    ok = 0;
 		}
@@ -2528,12 +2529,9 @@
 		    sigtrapped[signum] |= ZSIG_FUNC;
 	    }
 
-	    if (ok) {
-		shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
-		if (OPT_ISSET(ops,'X') &&
-		    eval_autoload(shf, shf->nam, ops, func))
-		    returnval = 1;
-	    }
+	    if (ok && OPT_ISSET(ops,'X') &&
+		eval_autoload(shf, shf->nam, ops, func))
+		returnval = 1;
 	} else
 	    returnval = 1;
     }
-- 
Peter Stephenson <pws@csr.com>                  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
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-04-21 17:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-13  5:15 Bug/misfeature with autoloaded TRAPxxx functions Bart Schaefer
2004-04-20 12:09 ` Peter Stephenson
2004-04-21 16:06   ` Bart Schaefer
2004-04-21 17:49     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).