From owner-svn-src-head@FreeBSD.ORG Tue Jun 23 20:45:12 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 607A7106566C; Tue, 23 Jun 2009 20:45:12 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4E86E8FC1D; Tue, 23 Jun 2009 20:45:12 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5NKjCuS089613; Tue, 23 Jun 2009 20:45:12 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5NKjCw6089608; Tue, 23 Jun 2009 20:45:12 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <200906232045.n5NKjCw6089608@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 23 Jun 2009 20:45:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194765 - head/bin/sh X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2009 20:45:13 -0000 Author: jilles Date: Tue Jun 23 20:45:12 2009 New Revision: 194765 URL: http://svn.freebsd.org/changeset/base/194765 Log: sh: Improve handling of setjmp/longjmp volatile: - remove ineffective and unnecessary (void) &var; [1] - remove some unnecessary volatile keywords - add a necessary volatile keyword - save the old handler before doing something that could use the saved value Submitted by: Christoph Mallon [1] Approved by: ed (mentor) Modified: head/bin/sh/eval.c head/bin/sh/histedit.c head/bin/sh/parser.c head/bin/sh/var.c Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Tue Jun 23 20:38:35 2009 (r194764) +++ head/bin/sh/eval.c Tue Jun 23 20:45:12 2009 (r194765) @@ -589,22 +589,14 @@ evalcommand(union node *cmd, int flags, struct cmdentry cmdentry; struct job *jp; struct jmploc jmploc; - struct jmploc *volatile savehandler; - char *volatile savecmdname; - volatile struct shparam saveparam; - struct localvar *volatile savelocalvars; + struct jmploc *savehandler; + char *savecmdname; + struct shparam saveparam; + struct localvar *savelocalvars; volatile int e; char *lastarg; int realstatus; int do_clearcmdentry; -#ifdef __GNUC__ - /* Avoid longjmp clobbering */ - (void) &argv; - (void) &argc; - (void) &lastarg; - (void) &flags; - (void) &do_clearcmdentry; -#endif /* First expand the arguments. */ TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags)); @@ -779,9 +771,10 @@ evalcommand(union node *cmd, int flags, savelocalvars = localvars; localvars = NULL; INTON; + savehandler = handler; if (setjmp(jmploc.loc)) { if (exception == EXSHELLPROC) - freeparam((struct shparam *)&saveparam); + freeparam(&saveparam); else { freeparam(&shellparam); shellparam = saveparam; @@ -791,7 +784,6 @@ evalcommand(union node *cmd, int flags, handler = savehandler; longjmp(handler->loc, 1); } - savehandler = handler; handler = &jmploc; for (sp = varlist.list ; sp ; sp = sp->next) mklocal(sp->text); @@ -830,12 +822,12 @@ evalcommand(union node *cmd, int flags, savecmdname = commandname; cmdenviron = varlist.list; e = -1; + savehandler = handler; if (setjmp(jmploc.loc)) { e = exception; exitstatus = (e == EXINT)? SIGINT+128 : 2; goto cmddone; } - savehandler = handler; handler = &jmploc; redirect(cmd->ncmd.redirect, mode); if (cmdentry.special) Modified: head/bin/sh/histedit.c ============================================================================== --- head/bin/sh/histedit.c Tue Jun 23 20:38:35 2009 (r194764) +++ head/bin/sh/histedit.c Tue Jun 23 20:45:12 2009 (r194765) @@ -173,25 +173,11 @@ histcmd(int argc, char **argv) char *pat = NULL, *repl; static int active = 0; struct jmploc jmploc; - struct jmploc *volatile savehandler; - char editfile[PATH_MAX]; + struct jmploc *savehandler; + char editfilestr[PATH_MAX]; + char *volatile editfile; FILE *efp; int oldhistnum; -#ifdef __GNUC__ - /* Avoid longjmp clobbering */ - (void) &editor; - (void) &lflg; - (void) &nflg; - (void) &rflg; - (void) &sflg; - (void) &firststr; - (void) &laststr; - (void) &pat; - (void) &repl; - (void) &efp; - (void) &argc; - (void) &argv; -#endif if (hist == NULL) error("history not active"); @@ -232,19 +218,19 @@ histcmd(int argc, char **argv) */ if (lflg == 0 || editor || sflg) { lflg = 0; /* ignore */ - editfile[0] = '\0'; + editfile = NULL; /* * Catch interrupts to reset active counter and * cleanup temp files. */ + savehandler = handler; if (setjmp(jmploc.loc)) { active = 0; - if (*editfile) + if (editfile) unlink(editfile); handler = savehandler; longjmp(handler->loc, 1); } - savehandler = handler; handler = &jmploc; if (++active > MAXHISTLOOPS) { active = 0; @@ -318,9 +304,10 @@ histcmd(int argc, char **argv) if (editor) { int fd; INTOFF; /* easier */ - sprintf(editfile, "%s/_shXXXXXX", _PATH_TMP); - if ((fd = mkstemp(editfile)) < 0) + sprintf(editfilestr, "%s/_shXXXXXX", _PATH_TMP); + if ((fd = mkstemp(editfilestr)) < 0) error("can't create temporary file %s", editfile); + editfile = editfilestr; if ((efp = fdopen(fd, "w")) == NULL) { close(fd); error("can't allocate stdio buffer for temp"); Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Tue Jun 23 20:38:35 2009 (r194764) +++ head/bin/sh/parser.c Tue Jun 23 20:45:12 2009 (r194765) @@ -898,19 +898,6 @@ readtoken1(int firstc, char const *synta int oldstyle; char const *prevsyntax; /* syntax before arithmetic */ int synentry; -#ifdef __GNUC__ - /* Avoid longjmp clobbering */ - (void) &out; - (void) "ef; - (void) &dblquote; - (void) &varnest; - (void) &arinest; - (void) &parenlevel; - (void) &oldstyle; - (void) &prevsyntax; - (void) &syntax; - (void) &synentry; -#endif startlinno = plinno; dblquote = 0; @@ -1320,13 +1307,9 @@ parsebackq: { union node *n; char *volatile str; struct jmploc jmploc; - struct jmploc *volatile savehandler; + struct jmploc *const savehandler = handler; int savelen; int saveprompt; -#ifdef __GNUC__ - /* Avoid longjmp clobbering */ - (void) &saveprompt; -#endif savepbq = parsebackquote; if (setjmp(jmploc.loc)) { @@ -1343,7 +1326,6 @@ parsebackq: { str = ckmalloc(savelen); memcpy(str, stackblock(), savelen); } - savehandler = handler; handler = &jmploc; INTON; if (oldstyle) { Modified: head/bin/sh/var.c ============================================================================== --- head/bin/sh/var.c Tue Jun 23 20:38:35 2009 (r194764) +++ head/bin/sh/var.c Tue Jun 23 20:45:12 2009 (r194765) @@ -193,12 +193,8 @@ int setvarsafe(char *name, char *val, int flags) { struct jmploc jmploc; - struct jmploc *volatile savehandler = handler; + struct jmploc *const savehandler = handler; int err = 0; -#ifdef __GNUC__ - /* Avoid longjmp clobbering */ - (void) &err; -#endif if (setjmp(jmploc.loc)) err = 1;