From aaf6682903d1a5cdb7a4c683f83c81a7af417d72 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 20 Jan 2000 09:01:43 +0000 Subject: zsh-workers/9382 --- Src/Modules/parameter.c | 2 +- Src/exec.c | 3 --- Src/mem.c | 10 ++-------- Src/parse.c | 31 +++++++++++++++---------------- Src/text.c | 4 ++++ 5 files changed, 22 insertions(+), 28 deletions(-) (limited to 'Src') diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 47fffde69..219ad5098 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -361,7 +361,7 @@ setfunction(char *name, char *val, int dis) if (!strncmp(name, "TRAP", 4) && (sn = getsignum(name + 4)) != -1) { if (settrap(sn, shf->funcdef)) { - freestruct(shf->funcdef); + freeeprog(shf->funcdef); zfree(shf, sizeof(*shf)); zsfree(val); LASTALLOC_RETURN; diff --git a/Src/exec.c b/Src/exec.c index 1e2cb5e5a..ae13ba016 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -842,9 +842,6 @@ sublist_done: break; code = *state->pc++; } - if (wc_code(code) == WC_END) - state->pc--; - pline_level = old_pline_level; list_pipe = old_list_pipe; lineno = oldlineno; diff --git a/Src/mem.c b/Src/mem.c index 8dccfdbb8..4936a5e73 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -56,17 +56,11 @@ attempting to free this memory may result in a core dump. The pair of pointers ncalloc and alloc may point to either zalloc & zcalloc or zhalloc & hcalloc; permalloc() sets them to the - former, and heapalloc() sets them to the latter. This can be useful. - For example, the dupstruct() routine duplicates a syntax tree, - allocating the new memory for the tree using alloc(). If you want - to duplicate a structure for a one-time use (i.e. to execute the list - in a for loop), call heapalloc(), then dupstruct(). If you want - to duplicate a structure in order to preserve it (i.e. a function - definition), call permalloc(), then dupstruct(). + former, and heapalloc() sets them to the latter. If possible, the heaps are allocated using mmap() so that the (*real*) heap isn't filled up with empty zsh heaps. If mmap() - is not available and zsh's own allocator we use a simple trick + is not available and zsh's own allocator is used, we use a simple trick to avoid that: we allocate a large block of memory before allocating a heap pool, this memory is freed again immediately after the pool is allocated. If there are only small blocks on the free list this diff --git a/Src/parse.c b/Src/parse.c index ecb88536b..1e1f9b02f 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1934,6 +1934,8 @@ ecstr(char *s) } #define ec(N) ecomp((struct node *) (N)) +#define ecsave(N) \ + do { int u = ecused; ec(N); if (u == ecused) ecadd(WCB_END()); } while (0) #define _Cond(X) ((Cond) (X)) #define _Cmd(X) ((Cmd) (X)) @@ -2024,7 +2026,7 @@ ecomp(struct node *n) break; case SUBSH: ecadd(WCB_SUBSH()); - ec(nn->u.list); + ecsave(nn->u.list); break; case ZCTIME: ecadd(WCB_TIMED(nn->u.pline ? WC_TIMED_PIPE : WC_TIMED_EMPTY)); @@ -2034,7 +2036,7 @@ ecomp(struct node *n) case FUNCDEF: { LinkNode np; - int num, sbeg, oecu, onp; + int num, sbeg, onp; Eccstr ostrs; /* Defined functions and their strings are stored @@ -2057,10 +2059,7 @@ ecomp(struct node *n) onp = ecnpats; ecnpats = 0; - oecu = ecused; - ec(nn->u.list); - if (oecu == ecused) - ecadd(WCB_END()); + ecsave(nn->u.list); ecbuf[p + num + 2] = ecused - num - p; ecbuf[p + num + 3] = ecnpats; @@ -2088,7 +2087,7 @@ ecomp(struct node *n) break; case CURSH: ecadd(WCB_CURSH()); - ec(nn->u.list); + ecsave(nn->u.list); break; case CFOR: { @@ -2118,7 +2117,7 @@ ecomp(struct node *n) } else type = WC_FOR_PPARAM; } - ec(nn->u.forcmd->list); + ecsave(nn->u.forcmd->list); ecbuf[p] = WCB_FOR(type, ecused - 1 - p); } @@ -2145,7 +2144,7 @@ ecomp(struct node *n) } else type = WC_SELECT_PPARAM; - ec(nn->u.forcmd->list); + ecsave(nn->u.forcmd->list); ecbuf[p] = WCB_SELECT(type, ecused - 1 - p); } @@ -2160,14 +2159,14 @@ ecomp(struct node *n) for (i = nn->u.ifcmd->ifls, t = nn->u.ifcmd->thenls; *i; i++, t++) { p = ecadd(0); - ec(*i); - ec(*t); + ecsave(*i); + ecsave(*t); ecbuf[p] = WCB_IF(type, ecused - 1 - p); type = WC_IF_ELIF; } if (*t) { p = ecadd(0); - ec(*t); + ecsave(*t); ecbuf[p] = WCB_IF(WC_IF_ELSE, ecused - 1 - p); } ecbuf[c] = WCB_IF(WC_IF_HEAD, ecused - 1 - c); @@ -2185,7 +2184,7 @@ ecomp(struct node *n) c = ecadd(0); ecstr(*pp + 1); ecadd(ecnpats++); - ec(*l); + ecsave(*l); ecbuf[c] = WCB_CASE((**pp == ';' ? WC_CASE_OR : WC_CASE_AND), ecused - 1 - c); @@ -2203,13 +2202,13 @@ ecomp(struct node *n) case CREPEAT: p = ecadd(0); ecstr((char *) getdata(firstnode(nn->args))); - ec(nn->u.list); + ecsave(nn->u.list); ecbuf[p] = WCB_REPEAT(ecused - 1 - p); break; case CWHILE: p = ecadd(0); - ec(nn->u.whilecmd->cont); - ec(nn->u.whilecmd->loop); + ecsave(nn->u.whilecmd->cont); + ecsave(nn->u.whilecmd->loop); ecbuf[p] = WCB_WHILE((nn->u.whilecmd->cond ? WC_WHILE_UNTIL : WC_WHILE_WHILE), ecused - 1 - p); diff --git a/Src/text.c b/Src/text.c index e806d6ece..b75ea193a 100644 --- a/Src/text.c +++ b/Src/text.c @@ -685,7 +685,11 @@ gettext2(Estate state) taddstr("))"); stack = 1; break; + case WC_END: + stack = 1; + break; default: + DPUTS(1, "unknown word code in gettext2()"); return; } } -- cgit 1.4.1