1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
From bd35d8ee1cce3e06db6f44fe9772ea3c154bb0ce Mon Sep 17 00:00:00 2001
From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 29 Mar 2006 07:47:18 +1100
Subject: [PATCH] [PARSER] Use alloca to get rid of setjmp
Now that the only thing protected by setjmp/longjmp is the saved string,
we can allocate it on the stack to get rid of the jump.
---
ChangeLog | 1 +
src/parser.c | 38 +++-----------------------------------
2 files changed, 4 insertions(+), 35 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5dd6d40..6295fe9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
2006-03-29 Herbert Xu <herbert@gondor.apana.org.au>
* Removed useless parsebackquote flag.
+ * Use alloca to get rid of setjmp in parse.c.
2006-01-12 Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/parser.c b/src/parser.c
index 375fd54..4362f6a 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -32,6 +32,7 @@
* SUCH DAMAGE.
*/
+#include <alloca.h>
#include <stdlib.h>
#include "shell.h"
@@ -846,19 +847,6 @@ readtoken1(int firstc, char const *synta
int dqvarnest; /* levels of variables expansion within double quotes */
int oldstyle;
char const *prevsyntax; /* syntax before arithmetic */
-#if __GNUC__
- /* Avoid longjmp clobbering */
- (void) &out;
- (void) "ef;
- (void) &dblquote;
- (void) &varnest;
- (void) &arinest;
- (void) &parenlevel;
- (void) &dqvarnest;
- (void) &oldstyle;
- (void) &prevsyntax;
- (void) &syntax;
-#endif
startlinno = plinno;
dblquote = 0;
@@ -1263,31 +1251,16 @@ badsub: synerror("Bad substitution");
parsebackq: {
struct nodelist **nlpp;
union node *n;
- char *volatile str;
- struct jmploc jmploc;
- struct jmploc *volatile savehandler;
+ char *str;
size_t savelen;
int saveprompt;
-#ifdef __GNUC__
- (void) &saveprompt;
-#endif
- if (setjmp(jmploc.loc)) {
- if (str)
- ckfree(str);
- handler = savehandler;
- longjmp(handler->loc, 1);
- }
- INTOFF;
str = NULL;
savelen = out - (char *)stackblock();
if (savelen > 0) {
- str = ckmalloc(savelen);
+ str = alloca(savelen);
memcpy(str, stackblock(), savelen);
}
- savehandler = handler;
- handler = &jmploc;
- INTON;
if (oldstyle) {
/* We must read until the closing backquote, giving special
treatment to some slashes, and then push the string and
@@ -1386,12 +1359,7 @@ done:
if (str) {
memcpy(out, str, savelen);
STADJUST(savelen, out);
- INTOFF;
- ckfree(str);
- str = NULL;
- INTON;
}
- handler = savehandler;
if (arinest || dblquote)
USTPUTC(CTLBACKQ | CTLQUOTE, out);
else
--
1.4.3.1
|