summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-12-12 00:07:27 +0000
committerjilles <jilles@FreeBSD.org>2010-12-12 00:07:27 +0000
commit9daf74d4c87761a7e7ef2d664810944cc789fe26 (patch)
tree66bc541c1c427371757d1d2e2510eb44cbf5cb94 /bin
parentb173b18025943e9b8fb30f95e8c8ad3161b21b0d (diff)
downloadFreeBSD-src-9daf74d4c87761a7e7ef2d664810944cc789fe26.zip
FreeBSD-src-9daf74d4c87761a7e7ef2d664810944cc789fe26.tar.gz
sh: Remove the herefd hack.
The herefd hack wrote out partial here documents while expanding them. It seems unnecessary complication given that other expansions just allocate memory. It causes bugs because the stack is also used for intermediate results such as arithmetic expressions. Such places should disable herefd for the duration but not all of them do, and I prefer removing the need for disabling herefd to disabling it everywhere needed. Here documents larger than 1024 bytes will use a bit more CPU time and memory. Additionally this allows a later change to expand here documents in the current shell environment. (This is faster for small here documents but also changes behaviour.) Obtained from: dash
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/expand.c8
-rw-r--r--bin/sh/memalloc.c6
-rw-r--r--bin/sh/memalloc.h1
3 files changed, 0 insertions, 15 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index f9c7f1b..1693a0b 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -132,7 +132,6 @@ collate_range_cmp(int c1, int c2)
void
expandhere(union node *arg, int fd)
{
- herefd = fd;
expandarg(arg, (struct arglist *)NULL, 0);
xwrite(fd, stackblock(), expdest - stackblock());
}
@@ -469,7 +468,6 @@ expbackq(union node *cmd, int quoted, int flag)
char lastc;
int startloc = dest - stackblock();
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
- int saveherefd;
int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
int nnl;
@@ -477,15 +475,12 @@ expbackq(union node *cmd, int quoted, int flag)
saveifs = ifsfirst;
savelastp = ifslastp;
saveargbackq = argbackq;
- saveherefd = herefd;
- herefd = -1;
p = grabstackstr(dest);
evalbackcmd(cmd, &in);
ungrabstackstr(p, dest);
ifsfirst = saveifs;
ifslastp = savelastp;
argbackq = saveargbackq;
- herefd = saveherefd;
p = in.buf;
lastc = '\0';
@@ -544,16 +539,13 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
char *loc = NULL;
char *q;
int c = 0;
- int saveherefd = herefd;
struct nodelist *saveargbackq = argbackq;
int amount;
- herefd = -1;
argstr(p, (subtype == VSTRIMLEFT || subtype == VSTRIMLEFTMAX ||
subtype == VSTRIMRIGHT || subtype == VSTRIMRIGHTMAX ?
EXP_CASE : 0) | EXP_TILDE);
STACKSTRNUL(expdest);
- herefd = saveherefd;
argbackq = saveargbackq;
startp = stackblock() + startloc;
if (str == NULL)
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c
index d00b4d9..47b5b83 100644
--- a/bin/sh/memalloc.c
+++ b/bin/sh/memalloc.c
@@ -128,7 +128,6 @@ static struct stackmark *markp;
char *stacknxt;
int stacknleft;
int sstrnleft;
-int herefd = -1;
static void
@@ -309,11 +308,6 @@ growstackstr(void)
int len;
len = stackblocksize();
- if (herefd >= 0 && len >= 1024) {
- xwrite(herefd, stackblock(), len);
- sstrnleft = len;
- return stackblock();
- }
return growstrstackblock(len);
}
diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h
index 88848dd..da23a95 100644
--- a/bin/sh/memalloc.h
+++ b/bin/sh/memalloc.h
@@ -46,7 +46,6 @@ struct stackmark {
extern char *stacknxt;
extern int stacknleft;
extern int sstrnleft;
-extern int herefd;
pointer ckmalloc(size_t);
pointer ckrealloc(pointer, int);
OpenPOWER on IntegriCloud