aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 21:10:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-25 21:10:20 +0200
commit579ad107a69690efc17401c487b06e89d9e8a91d (patch)
tree967ef2eeb3cb03d95aff3644f2842ac99b9c9b1f /shell
parentcaee80cd3da65670a576e610044fdc5e7c957d6d (diff)
downloadbusybox-w32-579ad107a69690efc17401c487b06e89d9e8a91d.tar.gz
busybox-w32-579ad107a69690efc17401c487b06e89d9e8a91d.tar.bz2
busybox-w32-579ad107a69690efc17401c487b06e89d9e8a91d.zip
ash: [EXPAND] Removed herefd hack
Upstream commit: Date: Sun, 11 Nov 2007 15:00:06 +0800 [EXPAND] Removed herefd hack The herefd hack goes back more than a decade. it limits the amount of memory we have to allocate when expanding here-documents by writing the result out from time to time. However, it's no longer safe because the stack is used to place intermediate results too and there we certainly don't want to write them out should we be short on memory. In any case, with today's computers we can afford to keep the entire result in memory and write them out at the end. function old new delta redirect 1268 1264 -4 ash_main 1485 1478 -7 subevalvar 1157 1132 -25 growstackstr 54 24 -30 argstr 1192 1154 -38 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-104) Total: -104 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c61
1 files changed, 22 insertions, 39 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 3f1405d81..527abc7b1 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1399,7 +1399,6 @@ struct globals_memstack {
1399 char *g_stacknxt; // = stackbase.space; 1399 char *g_stacknxt; // = stackbase.space;
1400 char *sstrend; // = stackbase.space + MINSIZE; 1400 char *sstrend; // = stackbase.space + MINSIZE;
1401 size_t g_stacknleft; // = MINSIZE; 1401 size_t g_stacknleft; // = MINSIZE;
1402 int herefd; // = -1;
1403 struct stack_block stackbase; 1402 struct stack_block stackbase;
1404}; 1403};
1405extern struct globals_memstack *const ash_ptr_to_globals_memstack; 1404extern struct globals_memstack *const ash_ptr_to_globals_memstack;
@@ -1408,7 +1407,6 @@ extern struct globals_memstack *const ash_ptr_to_globals_memstack;
1408#define g_stacknxt (G_memstack.g_stacknxt ) 1407#define g_stacknxt (G_memstack.g_stacknxt )
1409#define sstrend (G_memstack.sstrend ) 1408#define sstrend (G_memstack.sstrend )
1410#define g_stacknleft (G_memstack.g_stacknleft) 1409#define g_stacknleft (G_memstack.g_stacknleft)
1411#define herefd (G_memstack.herefd )
1412#define stackbase (G_memstack.stackbase ) 1410#define stackbase (G_memstack.stackbase )
1413#define INIT_G_memstack() do { \ 1411#define INIT_G_memstack() do { \
1414 (*(struct globals_memstack**)&ash_ptr_to_globals_memstack) = xzalloc(sizeof(G_memstack)); \ 1412 (*(struct globals_memstack**)&ash_ptr_to_globals_memstack) = xzalloc(sizeof(G_memstack)); \
@@ -1417,7 +1415,6 @@ extern struct globals_memstack *const ash_ptr_to_globals_memstack;
1417 g_stacknxt = stackbase.space; \ 1415 g_stacknxt = stackbase.space; \
1418 g_stacknleft = MINSIZE; \ 1416 g_stacknleft = MINSIZE; \
1419 sstrend = stackbase.space + MINSIZE; \ 1417 sstrend = stackbase.space + MINSIZE; \
1420 herefd = -1; \
1421} while (0) 1418} while (0)
1422 1419
1423 1420
@@ -1605,10 +1602,6 @@ static void *
1605growstackstr(void) 1602growstackstr(void)
1606{ 1603{
1607 size_t len = stackblocksize(); 1604 size_t len = stackblocksize();
1608 if (herefd >= 0 && len >= 1024) {
1609 full_write(herefd, stackblock(), len);
1610 return stackblock();
1611 }
1612 growstackblock(); 1605 growstackblock();
1613 return (char *)stackblock() + len; 1606 return (char *)stackblock() + len;
1614} 1607}
@@ -5893,33 +5886,28 @@ static int evaltree(union node *, int);
5893static void FAST_FUNC 5886static void FAST_FUNC
5894evalbackcmd(union node *n, struct backcmd *result) 5887evalbackcmd(union node *n, struct backcmd *result)
5895{ 5888{
5896 int saveherefd; 5889 int pip[2];
5890 struct job *jp;
5897 5891
5898 result->fd = -1; 5892 result->fd = -1;
5899 result->buf = NULL; 5893 result->buf = NULL;
5900 result->nleft = 0; 5894 result->nleft = 0;
5901 result->jp = NULL; 5895 result->jp = NULL;
5902 if (n == NULL) 5896 if (n == NULL) {
5903 goto out; 5897 goto out;
5898 }
5904 5899
5905 saveherefd = herefd; 5900 if (pipe(pip) < 0)
5906 herefd = -1; 5901 ash_msg_and_raise_error("pipe call failed");
5907 5902 jp = makejob(/*n,*/ 1);
5908 { 5903 if (forkshell(jp, n, FORK_NOJOB) == 0) {
5909 int pip[2]; 5904 FORCE_INT_ON;
5910 struct job *jp; 5905 close(pip[0]);
5911 5906 if (pip[1] != 1) {
5912 if (pipe(pip) < 0) 5907 /*close(1);*/
5913 ash_msg_and_raise_error("pipe call failed"); 5908 copyfd(pip[1], 1 | COPYFD_EXACT);
5914 jp = makejob(/*n,*/ 1); 5909 close(pip[1]);
5915 if (forkshell(jp, n, FORK_NOJOB) == 0) { 5910 }
5916 FORCE_INT_ON;
5917 close(pip[0]);
5918 if (pip[1] != 1) {
5919 /*close(1);*/
5920 copyfd(pip[1], 1 | COPYFD_EXACT);
5921 close(pip[1]);
5922 }
5923/* TODO: eflag clearing makes the following not abort: 5911/* TODO: eflag clearing makes the following not abort:
5924 * ash -c 'set -e; z=$(false;echo foo); echo $z' 5912 * ash -c 'set -e; z=$(false;echo foo); echo $z'
5925 * which is what bash does (unless it is in POSIX mode). 5913 * which is what bash does (unless it is in POSIX mode).
@@ -5928,15 +5916,14 @@ evalbackcmd(union node *n, struct backcmd *result)
5928 * [EVAL] Don't clear eflag in evalbackcmd 5916 * [EVAL] Don't clear eflag in evalbackcmd
5929 * For now, preserve bash-like behavior, it seems to be somewhat more useful: 5917 * For now, preserve bash-like behavior, it seems to be somewhat more useful:
5930 */ 5918 */
5931 eflag = 0; 5919 eflag = 0;
5932 evaltree(n, EV_EXIT); /* actually evaltreenr... */ 5920 evaltree(n, EV_EXIT); /* actually evaltreenr... */
5933 /* NOTREACHED */ 5921 /* NOTREACHED */
5934 }
5935 close(pip[1]);
5936 result->fd = pip[0];
5937 result->jp = jp;
5938 } 5922 }
5939 herefd = saveherefd; 5923 close(pip[1]);
5924 result->fd = pip[0];
5925 result->jp = jp;
5926
5940 out: 5927 out:
5941 TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", 5928 TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
5942 result->fd, result->buf, result->nleft, result->jp)); 5929 result->fd, result->buf, result->nleft, result->jp));
@@ -6343,7 +6330,6 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
6343 char *str; 6330 char *str;
6344 IF_ASH_BASH_COMPAT(char *repl = NULL;) 6331 IF_ASH_BASH_COMPAT(char *repl = NULL;)
6345 IF_ASH_BASH_COMPAT(int pos, len, orig_len;) 6332 IF_ASH_BASH_COMPAT(int pos, len, orig_len;)
6346 int saveherefd = herefd;
6347 int amount, resetloc; 6333 int amount, resetloc;
6348 IF_ASH_BASH_COMPAT(int workloc;) 6334 IF_ASH_BASH_COMPAT(int workloc;)
6349 int zero; 6335 int zero;
@@ -6352,12 +6338,10 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
6352 //bb_error_msg("subevalvar(p:'%s',varname:'%s',strloc:%d,subtype:%d,startloc:%d,varflags:%x,quotes:%d)", 6338 //bb_error_msg("subevalvar(p:'%s',varname:'%s',strloc:%d,subtype:%d,startloc:%d,varflags:%x,quotes:%d)",
6353 // p, varname, strloc, subtype, startloc, varflags, quotes); 6339 // p, varname, strloc, subtype, startloc, varflags, quotes);
6354 6340
6355 herefd = -1;
6356 argstr(p, EXP_TILDE | (subtype != VSASSIGN && subtype != VSQUESTION ? 6341 argstr(p, EXP_TILDE | (subtype != VSASSIGN && subtype != VSQUESTION ?
6357 (flag & (EXP_QUOTED | EXP_QPAT) ? EXP_QPAT : EXP_CASE) : 0), 6342 (flag & (EXP_QUOTED | EXP_QPAT) ? EXP_QPAT : EXP_CASE) : 0),
6358 var_str_list); 6343 var_str_list);
6359 STPUTC('\0', expdest); 6344 STPUTC('\0', expdest);
6360 herefd = saveherefd;
6361 argbackq = saveargbackq; 6345 argbackq = saveargbackq;
6362 startp = (char *)stackblock() + startloc; 6346 startp = (char *)stackblock() + startloc;
6363 6347
@@ -7391,7 +7375,6 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
7391static void 7375static void
7392expandhere(union node *arg, int fd) 7376expandhere(union node *arg, int fd)
7393{ 7377{
7394 herefd = fd;
7395 expandarg(arg, (struct arglist *)NULL, EXP_QUOTED); 7378 expandarg(arg, (struct arglist *)NULL, EXP_QUOTED);
7396 full_write(fd, stackblock(), expdest - (char *)stackblock()); 7379 full_write(fd, stackblock(), expdest - (char *)stackblock());
7397} 7380}