Module Name:    src
Committed By:   kre
Date:           Wed Jan  5 15:25:44 UTC 2022

Modified Files:
        src/bin/sh: eval.c

Log Message:
Use a volative local shadow of a field in an (on-stack) non-volatile struct
that is to be referenced after a return from setjmp() via longjmp().

This doesn't ever seem to have caused a problem, but I think using
volative vars is required here.

For reasons I never bothered to discover, even though this change
certainly requires a store into stack memory which wasn't required
before, earlier measurements showed the shell getting (slightly) smaller
with this change in place.

NFCI


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 src/bin/sh/eval.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.187 src/bin/sh/eval.c:1.188
--- src/bin/sh/eval.c:1.187	Sun Dec  5 04:35:38 2021
+++ src/bin/sh/eval.c	Wed Jan  5 15:25:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.187 2021/12/05 04:35:38 msaitoh Exp $	*/
+/*	$NetBSD: eval.c,v 1.188 2022/01/05 15:25:44 kre Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.187 2021/12/05 04:35:38 msaitoh Exp $");
+__RCSID("$NetBSD: eval.c,v 1.188 2022/01/05 15:25:44 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1218,6 +1218,7 @@ evalcommand(union node *cmd, int flgs, s
 	/* Execute the command. */
 	switch (cmdentry.cmdtype) {
 		volatile int saved;
+		struct funcdef * volatile savefunc;
 
 	case CMDFUNCTION:
 		VXTRACE(DBG_EVAL, ("Shell function%s:  ",vforked?" VF":""),
@@ -1233,7 +1234,7 @@ evalcommand(union node *cmd, int flgs, s
 		INTOFF;
 		savelocalvars = localvars;
 		localvars = NULL;
-		reffunc(cmdentry.u.func);
+		reffunc(savefunc = cmdentry.u.func);
 		INTON;
 		if (setjmp(jmploc.loc)) {
 			if (exception == EXSHELLPROC) {
@@ -1245,7 +1246,7 @@ evalcommand(union node *cmd, int flgs, s
 			}
 			if (saved)
 				popredir();
-			unreffunc(cmdentry.u.func);
+			unreffunc(savefunc);
 			poplocalvars();
 			localvars = savelocalvars;
 			funclinebase = savefuncline;

Reply via email to