From bee3bbaaf8ce8898d103b45b28c699acfab42410 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 29 Jan 2012 01:41:15 +0000 Subject: [PATCH] =?UTF-8?q?reduce=20stack=20usage=20a=20bit=20(several=20c?= =?UTF-8?q?andidates=20for=20more,=20including=20$CC=20itself=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 4 ++-- edit.c | 4 ++-- funcs.c | 4 ++-- main.c | 38 ++++++++++++++++++++++++++++---------- sh.h | 4 ++-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/check.t b/check.t index 82fbe1e..89bd42f 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.513 2012/01/14 19:20:17 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.514 2012/01/29 01:41:09 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -29,7 +29,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R40 2012/01/04 + @(#)MIRBSD KSH R40 2012/01/28 description: Check version of shell. stdin: diff --git a/edit.c b/edit.c index 56b6c06..fbb3df8 100644 --- a/edit.c +++ b/edit.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.226 2011/12/29 23:36:10 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.227 2012/01/29 01:41:12 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -1802,7 +1802,7 @@ static int x_search_hist(int c) { int offset = -1; /* offset of match in xbuf, else -1 */ - char pat[256 + 1]; /* pattern buffer */ + char pat[80 + 1]; /* pattern buffer */ char *p = pat; unsigned char f; diff --git a/funcs.c b/funcs.c index 45d8530..7705240 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.206 2011/12/29 22:54:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.207 2012/01/29 01:41:13 tg Exp $"); #if HAVE_KILLPG /* @@ -1759,11 +1759,11 @@ c_wait(const char **wp) return (rv); } +static char REPLY[] = "REPLY"; int c_read(const char **wp) { #define is_ifsws(c) (ctype((c), C_IFS) && ctype((c), C_IFSWS)) - static char REPLY[] = "REPLY"; int c, fd = 0, rv = 0, lastparm = 0; bool savehist = false, intoarray = false, aschars = false; bool rawmode = false, expanding = false; diff --git a/main.c b/main.c index 21fa2b5..8da11dc 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,8 @@ /* $OpenBSD: table.c,v 1.13 2009/01/17 22:06:44 millert Exp $ */ /*- - * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 + * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, + * 2011, 2012 * Thorsten Glaser * * Provided that these terms and disclaimer and all copyright notices @@ -33,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.201 2011/11/08 22:07:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.202 2012/01/29 01:41:14 tg Exp $"); extern char **environ; @@ -45,6 +46,7 @@ extern char **environ; #define MKSH_DEFAULT_TMPDIR "/tmp" #endif +static int main_init(int, const char *[], Source **, struct block **); void chvt_reinit(void); static void reclaim(void); static void remove_temps(struct temp *); @@ -155,8 +157,8 @@ static const char *empty_argv[] = { "mksh", NULL }; -int -main(int argc, const char *argv[]) +static int +main_init(int argc, const char *argv[], Source **sp, struct block **lp) { int argi, i; Source *s = NULL; @@ -594,15 +596,31 @@ main(int argc, const char *argv[]) alarm_init(); - if (Flag(FAS_BUILTIN)) - return (shcomexec(l->argv)); - - /* doesn't return */ - shell(s, true); - /* NOTREACHED */ + *sp = s; + *lp = l; return (0); } +/* this indirection barrier reduces stack usage during normal operation */ + +int +main(int argc, const char *argv[]) +{ + int rv; + Source *s; + struct block *l; + + if ((rv = main_init(argc, argv, &s, &l)) == 0) { + if (Flag(FAS_BUILTIN)) { + rv = shcomexec(l->argv); + } else { + shell(s, true); + /* NOTREACHED */ + } + } + return (rv); +} + int include(const char *name, int argc, const char **argv, int intr_ok) { diff --git a/sh.h b/sh.h index 1e30754..f5285ec 100644 --- a/sh.h +++ b/sh.h @@ -152,9 +152,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.519 2012/01/04 19:09:36 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.520 2012/01/29 01:41:15 tg Exp $"); #endif -#define MKSH_VERSION "R40 2012/01/04" +#define MKSH_VERSION "R40 2012/01/28" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES