diff options
author | Ron Yorston <rmy@frippery.org> | 2015-07-01 16:46:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-07-13 04:02:45 +0200 |
commit | 072fc60f29ee3a4ff38f095a9ef149b2e820c8c0 (patch) | |
tree | 8180cc80c19bca52fe07e8dad8fd69cf84fe545f | |
parent | f54a487bb4d36a4318c5ec539f8265fdff2cac90 (diff) | |
download | busybox-w32-072fc60f29ee3a4ff38f095a9ef149b2e820c8c0.tar.gz busybox-w32-072fc60f29ee3a4ff38f095a9ef149b2e820c8c0.tar.bz2 busybox-w32-072fc60f29ee3a4ff38f095a9ef149b2e820c8c0.zip |
ash: 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.
Based on commit bd35d8e from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.
function old new delta
readtoken1 3182 3116 -66
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-66) Total: -66 bytes
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 36 |
1 files changed, 2 insertions, 34 deletions
diff --git a/shell/ash.c b/shell/ash.c index 6627cec9b..f4779ee2b 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11132,19 +11132,6 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11132 | 11132 | ||
11133 | IF_ASH_BASH_COMPAT(smallint bash_dollar_squote = 0;) | 11133 | IF_ASH_BASH_COMPAT(smallint bash_dollar_squote = 0;) |
11134 | 11134 | ||
11135 | #if __GNUC__ | ||
11136 | /* Avoid longjmp clobbering */ | ||
11137 | (void) &out; | ||
11138 | (void) "ef; | ||
11139 | (void) &dblquote; | ||
11140 | (void) &varnest; | ||
11141 | (void) &arinest; | ||
11142 | (void) &parenlevel; | ||
11143 | (void) &dqvarnest; | ||
11144 | (void) &oldstyle; | ||
11145 | (void) &prevsyntax; | ||
11146 | (void) &syntax; | ||
11147 | #endif | ||
11148 | startlinno = g_parsefile->linno; | 11135 | startlinno = g_parsefile->linno; |
11149 | bqlist = NULL; | 11136 | bqlist = NULL; |
11150 | quotef = 0; | 11137 | quotef = 0; |
@@ -11609,30 +11596,16 @@ parsesub: { | |||
11609 | parsebackq: { | 11596 | parsebackq: { |
11610 | struct nodelist **nlpp; | 11597 | struct nodelist **nlpp; |
11611 | union node *n; | 11598 | union node *n; |
11612 | char *volatile str; | 11599 | char *str; |
11613 | struct jmploc jmploc; | ||
11614 | struct jmploc *volatile savehandler; | ||
11615 | size_t savelen; | 11600 | size_t savelen; |
11616 | smallint saveprompt = 0; | 11601 | smallint saveprompt = 0; |
11617 | 11602 | ||
11618 | #ifdef __GNUC__ | ||
11619 | (void) &saveprompt; | ||
11620 | #endif | ||
11621 | if (setjmp(jmploc.loc)) { | ||
11622 | free(str); | ||
11623 | exception_handler = savehandler; | ||
11624 | longjmp(exception_handler->loc, 1); | ||
11625 | } | ||
11626 | INT_OFF; | ||
11627 | str = NULL; | 11603 | str = NULL; |
11628 | savelen = out - (char *)stackblock(); | 11604 | savelen = out - (char *)stackblock(); |
11629 | if (savelen > 0) { | 11605 | if (savelen > 0) { |
11630 | str = ckmalloc(savelen); | 11606 | str = alloca(savelen); |
11631 | memcpy(str, stackblock(), savelen); | 11607 | memcpy(str, stackblock(), savelen); |
11632 | } | 11608 | } |
11633 | savehandler = exception_handler; | ||
11634 | exception_handler = &jmploc; | ||
11635 | INT_ON; | ||
11636 | if (oldstyle) { | 11609 | if (oldstyle) { |
11637 | /* We must read until the closing backquote, giving special | 11610 | /* We must read until the closing backquote, giving special |
11638 | * treatment to some slashes, and then push the string and | 11611 | * treatment to some slashes, and then push the string and |
@@ -11731,12 +11704,7 @@ parsebackq: { | |||
11731 | if (str) { | 11704 | if (str) { |
11732 | memcpy(out, str, savelen); | 11705 | memcpy(out, str, savelen); |
11733 | STADJUST(savelen, out); | 11706 | STADJUST(savelen, out); |
11734 | INT_OFF; | ||
11735 | free(str); | ||
11736 | str = NULL; | ||
11737 | INT_ON; | ||
11738 | } | 11707 | } |
11739 | exception_handler = savehandler; | ||
11740 | USTPUTC(CTLBACKQ, out); | 11708 | USTPUTC(CTLBACKQ, out); |
11741 | if (oldstyle) | 11709 | if (oldstyle) |
11742 | goto parsebackq_oldreturn; | 11710 | goto parsebackq_oldreturn; |