From ab801874f852312787c049272c20b14e06ed8195 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 2 Dec 2007 08:35:37 +0000 Subject: attack the biggest stack users: -mkfs_minix_main [busybox_unstripped]: 4288 -mkfs_minix_main [busybox_unstripped]: 4276 -grave [busybox_unstripped]: 4260 (bzip2 users too - not listed) price we pay in code size increase: mainSort 2458 2515 +57 grave 1005 1058 +53 sendMTFValues 2177 2195 +18 BZ2_blockSort 122 125 +3 mkfs_minix_main 3070 3022 -48 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 131/-48) Total: 83 bytes --- shell/msh.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'shell/msh.c') diff --git a/shell/msh.c b/shell/msh.c index 32953f4ed..9f95fe28a 100644 --- a/shell/msh.c +++ b/shell/msh.c @@ -735,6 +735,9 @@ struct globals { char filechar_cmdbuf[BUFSIZ]; char line[LINELIM]; char child_cmd[LINELIM]; + + char grave__var_name[LINELIM]; + char grave__alt_value[LINELIM]; }; #define G (*ptr_to_globals) @@ -746,6 +749,9 @@ struct globals { #define filechar_cmdbuf (G.filechar_cmdbuf) #define line (G.line ) #define child_cmd (G.child_cmd ) +#define INIT_G() do { \ + PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ +} while (0) #ifdef MSHDEBUG @@ -4042,8 +4048,12 @@ static int grave(int quoted) ignore_once = 1; if (*src == '$' && !ignore && !ignore_once) { struct var *vp; + /* moved to G to reduce stack usage char var_name[LINELIM]; char alt_value[LINELIM]; + */ +#define var_name (G.grave__var_name) +#define alt_value (G.grave__alt_value) int var_index = 0; int alt_index = 0; char operator = 0; @@ -4131,6 +4141,8 @@ static int grave(int quoted) count++; } } +#undef var_name +#undef alt_value } else { *dest++ = *src++; count++; @@ -5173,7 +5185,8 @@ int msh_main(int argc, char **argv) char *name, **ap; int (*iof) (struct ioarg *); - PTR_TO_GLOBALS = xzalloc(sizeof(G)); + INIT_G(); + sharedbuf.id = AFID_NOBUF; mainbuf.id = AFID_NOBUF; e.linep = line; -- cgit v1.2.3