From 1054071bd60937ae8a9fbc16c1407211c6198a55 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Wed, 23 Feb 2000 15:18:43 +0000 Subject: zsh-workers/9839 --- Src/Modules/example.c | 4 +- Src/Modules/mapfile.c | 47 ++-- Src/Modules/parameter.c | 660 ++++++++++++++++++++++-------------------------- Src/Modules/zftp.c | 22 +- Src/Modules/zprof.c | 34 ++- Src/Modules/zpty.c | 4 +- Src/Modules/zutil.c | 84 +++--- 7 files changed, 389 insertions(+), 466 deletions(-) (limited to 'Src/Modules') diff --git a/Src/Modules/example.c b/Src/Modules/example.c index 0b15fa064..40620fa96 100644 --- a/Src/Modules/example.c +++ b/Src/Modules/example.c @@ -70,9 +70,7 @@ bin_example(char *nam, char **args, char *ops, int func) zsfree(strparam); strparam = ztrdup(*oargs ? *oargs : ""); freearray(arrparam); - PERMALLOC { - arrparam = arrdup(oargs); - } LASTALLOC; + arrparam = zarrdup(oargs); return 0; } diff --git a/Src/Modules/mapfile.c b/Src/Modules/mapfile.c index 5bbc17eca..52c57a75c 100644 --- a/Src/Modules/mapfile.c +++ b/Src/Modules/mapfile.c @@ -248,7 +248,7 @@ get_contents(char *fname) val = NULL; if ((fd = open(fname, O_RDONLY | O_NOCTTY)) >= 0) { LinkList ll; - MUSTUSEHEAP("mapfile:get_contents"); + if ((ll = readoutput(fd, 1))) val = peekfirst(ll); } @@ -264,30 +264,27 @@ getpmmapfile(HashTable ht, char *name) char *contents; Param pm = NULL; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = setpmmapfile; - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmmapfile; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - pm->flags |= (mapfile_pm->flags & PM_READONLY); - - /* Set u.str to contents of file given by name */ - if ((contents = get_contents(pm->nam))) - pm->u.str = contents; - else { - pm->u.str = ""; - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = setpmmapfile; + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmmapfile; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + pm->flags |= (mapfile_pm->flags & PM_READONLY); + + /* Set u.str to contents of file given by name */ + if ((contents = get_contents(pm->nam))) + pm->u.str = contents; + else { + pm->u.str = ""; + pm->flags |= PM_UNSET; + } return (HashNode) pm; } diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 84a70e4c6..d9ae607bc 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -136,27 +136,24 @@ getpmparameter(HashTable ht, char *name) { Param rpm, pm = NULL; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((rpm = (Param) realparamtab->getnode(realparamtab, name)) && - !(rpm->flags & PM_UNSET)) - pm->u.str = paramtypestr(rpm); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((rpm = (Param) realparamtab->getnode(realparamtab, name)) && + !(rpm->flags & PM_UNSET)) + pm->u.str = paramtypestr(rpm); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -257,34 +254,30 @@ getpmcommand(HashTable ht, char *name) cmdnamtab->filltable(cmdnamtab); cmd = (Cmdnam) cmdnamtab->getnode(cmdnamtab, name); } - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = setpmcommand; - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmcommand; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if (cmd) { - if (cmd->flags & HASHED) - pm->u.str = cmd->u.cmd; - else { - pm->u.str = zhalloc(strlen(*(cmd->u.name)) + - strlen(name) + 2); - strcpy(pm->u.str, *(cmd->u.name)); - strcat(pm->u.str, "/"); - strcat(pm->u.str, name); - } - } else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = setpmcommand; + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmcommand; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if (cmd) { + if (cmd->flags & HASHED) + pm->u.str = cmd->u.cmd; + else { + pm->u.str = zhalloc(strlen(*(cmd->u.name)) + strlen(name) + 2); + strcpy(pm->u.str, *(cmd->u.name)); + strcat(pm->u.str, "/"); + strcat(pm->u.str, name); } - } LASTALLOC; - + } else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -344,32 +337,28 @@ setfunction(char *name, char *val, int dis) val = metafy(val, strlen(val), META_REALLOC); - HEAPALLOC { - prog = parse_string(val, 1); - } LASTALLOC; + prog = parse_string(val, 1); if (!prog || prog == &dummy_eprog) { zwarn("invalid function definition", value, 0); zsfree(val); return; } - PERMALLOC { - shf = (Shfunc) zalloc(sizeof(*shf)); - shf->funcdef = dupeprog(prog); - shf->flags = dis; - - if (!strncmp(name, "TRAP", 4) && - (sn = getsignum(name + 4)) != -1) { - if (settrap(sn, shf->funcdef)) { - freeeprog(shf->funcdef); - zfree(shf, sizeof(*shf)); - zsfree(val); - LASTALLOC_RETURN; - } - sigtrapped[sn] |= ZSIG_FUNC; + shf = (Shfunc) zalloc(sizeof(*shf)); + shf->funcdef = zdupeprog(prog); + shf->flags = dis; + + if (!strncmp(name, "TRAP", 4) && + (sn = getsignum(name + 4)) != -1) { + if (settrap(sn, shf->funcdef)) { + freeeprog(shf->funcdef); + zfree(shf, sizeof(*shf)); + zsfree(val); + return; } - shfunctab->addnode(shfunctab, ztrdup(name), shf); - } LASTALLOC; + sigtrapped[sn] |= ZSIG_FUNC; + } + shfunctab->addnode(shfunctab, ztrdup(name), shf); zsfree(val); } @@ -442,41 +431,38 @@ getfunction(HashTable ht, char *name, int dis) Shfunc shf; Param pm = NULL; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = (dis ? setpmdisfunction : setpmfunction); - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmfunction; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if ((shf = (Shfunc) shfunctab->getnode2(shfunctab, name)) && - (dis ? (shf->flags & DISABLED) : !(shf->flags & DISABLED))) { - if (shf->flags & PM_UNDEFINED) { - pm->u.str = dyncat("builtin autoload -X", - ((shf->flags & PM_UNALIASED) ? - ((shf->flags & PM_TAGGED) ? "Ut" : "U") : - ((shf->flags & PM_TAGGED) ? "t" : ""))); - } else { - char *t = getpermtext(shf->funcdef, NULL), *h; + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = (dis ? setpmdisfunction : setpmfunction); + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmfunction; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if ((shf = (Shfunc) shfunctab->getnode2(shfunctab, name)) && + (dis ? (shf->flags & DISABLED) : !(shf->flags & DISABLED))) { + if (shf->flags & PM_UNDEFINED) { + pm->u.str = dyncat("builtin autoload -X", + ((shf->flags & PM_UNALIASED) ? + ((shf->flags & PM_TAGGED) ? "Ut" : "U") : + ((shf->flags & PM_TAGGED) ? "t" : ""))); + } else { + char *t = getpermtext(shf->funcdef, NULL), *h; - h = dupstring(t); - zsfree(t); - unmetafy(h, NULL); + h = dupstring(t); + zsfree(t); + unmetafy(h, NULL); - pm->u.str = h; - } - } else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; + pm->u.str = h; } - } LASTALLOC; - + } else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -583,30 +569,27 @@ getbuiltin(HashTable ht, char *name, int dis) Param pm = NULL; Builtin bn; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((bn = (Builtin) builtintab->getnode2(builtintab, name)) && - (dis ? (bn->flags & DISABLED) : !(bn->flags & DISABLED))) { - char *t = ((bn->handlerfunc || (bn->flags & BINF_PREFIX)) ? - "defined" : "undefined"); - - pm->u.str = dupstring(t); - } else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((bn = (Builtin) builtintab->getnode2(builtintab, name)) && + (dis ? (bn->flags & DISABLED) : !(bn->flags & DISABLED))) { + char *t = ((bn->handlerfunc || (bn->flags & BINF_PREFIX)) ? + "defined" : "undefined"); + + pm->u.str = dupstring(t); + } else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -775,27 +758,24 @@ getpmoption(HashTable ht, char *name) Param pm = NULL; int n; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = setpmoption; - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmoption; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if ((n = optlookup(name))) - pm->u.str = dupstring(opts[n] ? "on" : "off"); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = setpmoption; + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmoption; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if ((n = optlookup(name))) + pm->u.str = dupstring(opts[n] ? "on" : "off"); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -871,57 +851,54 @@ getpmmodule(HashTable ht, char *name) char *type = NULL; LinkNode node; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if (!type) { - Module m; - - for (node = firstnode(modules); node; incnode(node)) { - m = (Module) getdata(node); - if (m->u.handle && !(m->flags & MOD_UNLOAD) && - !strcmp(name, m->nam)) { - type = "loaded"; - break; - } - } - } - modpmname = name; - modpmfound = 0; - if (!type) { - scanhashtable(builtintab, 0, 0, 0, modpmbuiltinscan, 0); - if (!modpmfound) { - Conddef p; - - for (p = condtab; p; p = p->next) - if (p->module && !strcmp(name, p->module)) { - modpmfound = 1; - break; - } - if (!modpmfound) - scanhashtable(realparamtab, 0, 0, 0, modpmparamscan, 0); + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if (!type) { + Module m; + + for (node = firstnode(modules); node; incnode(node)) { + m = (Module) getdata(node); + if (m->u.handle && !(m->flags & MOD_UNLOAD) && + !strcmp(name, m->nam)) { + type = "loaded"; + break; } - if (modpmfound) - type = "autoloaded"; } - if (type) - pm->u.str = dupstring(type); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; + } + modpmname = name; + modpmfound = 0; + if (!type) { + scanhashtable(builtintab, 0, 0, 0, modpmbuiltinscan, 0); + if (!modpmfound) { + Conddef p; + + for (p = condtab; p; p = p->next) + if (p->module && !strcmp(name, p->module)) { + modpmfound = 1; + break; + } + if (!modpmfound) + scanhashtable(realparamtab, 0, 0, 0, modpmparamscan, 0); } - } LASTALLOC; - + if (modpmfound) + type = "autoloaded"; + } + if (type) + pm->u.str = dupstring(type); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -991,12 +968,10 @@ static void dirssetfn(Param pm, char **x) { if (!incleanup) { - PERMALLOC { - freelinklist(dirstack, freestr); - dirstack = newlinklist(); - while (x && *x) - addlinknode(dirstack, ztrdup(*x++)); - } LASTALLOC; + freelinklist(dirstack, freestr); + dirstack = znewlinklist(); + while (x && *x) + zaddlinknode(dirstack, ztrdup(*x++)); } if (x) freearray(x); @@ -1026,26 +1001,23 @@ getpmhistory(HashTable ht, char *name) Param pm = NULL; Histent he; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((he = quietgethist(atoi(name)))) - pm->u.str = dupstring(he->text); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((he = quietgethist(atoi(name)))) + pm->u.str = dupstring(he->text); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1145,29 +1117,26 @@ getpmjobtext(HashTable ht, char *name) Param pm = NULL; int job; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if ((job = atoi(name)) >= 1 && job < MAXJOB && - jobtab[job].stat && jobtab[job].procs && - !(jobtab[job].stat & STAT_NOPRINT)) - pm->u.str = pmjobtext(job); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if ((job = atoi(name)) >= 1 && job < MAXJOB && + jobtab[job].stat && jobtab[job].procs && + !(jobtab[job].stat & STAT_NOPRINT)) + pm->u.str = pmjobtext(job); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1251,29 +1220,26 @@ getpmjobstate(HashTable ht, char *name) Param pm = NULL; int job; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if ((job = atoi(name)) >= 1 && job < MAXJOB && - jobtab[job].stat && jobtab[job].procs && - !(jobtab[job].stat & STAT_NOPRINT)) - pm->u.str = pmjobstate(job); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if ((job = atoi(name)) >= 1 && job < MAXJOB && + jobtab[job].stat && jobtab[job].procs && + !(jobtab[job].stat & STAT_NOPRINT)) + pm->u.str = pmjobstate(job); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1329,29 +1295,26 @@ getpmjobdir(HashTable ht, char *name) Param pm = NULL; int job; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - - if ((job = atoi(name)) >= 1 && job < MAXJOB && - jobtab[job].stat && jobtab[job].procs && - !(jobtab[job].stat & STAT_NOPRINT)) - pm->u.str = pmjobdir(job); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + + if ((job = atoi(name)) >= 1 && job < MAXJOB && + jobtab[job].stat && jobtab[job].procs && + !(jobtab[job].stat & STAT_NOPRINT)) + pm->u.str = pmjobdir(job); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1462,27 +1425,24 @@ getpmnameddir(HashTable ht, char *name) Param pm = NULL; Nameddir nd; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = setpmnameddir; - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmnameddir; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((nd = (Nameddir) nameddirtab->getnode(nameddirtab, name)) && - !(nd->flags & ND_USERNAME)) - pm->u.str = dupstring(nd->dir); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = setpmnameddir; + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmnameddir; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((nd = (Nameddir) nameddirtab->getnode(nameddirtab, name)) && + !(nd->flags & ND_USERNAME)) + pm->u.str = dupstring(nd->dir); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1529,27 +1489,24 @@ getpmuserdir(HashTable ht, char *name) nameddirtab->filltable(nameddirtab); - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR | PM_READONLY; - pm->sets.cfn = NULL; - pm->gets.cfn = strgetfn; - pm->unsetfn = NULL; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((nd = (Nameddir) nameddirtab->getnode(nameddirtab, name)) && - (nd->flags & ND_USERNAME)) - pm->u.str = dupstring(nd->dir); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR | PM_READONLY; + pm->sets.cfn = NULL; + pm->gets.cfn = strgetfn; + pm->unsetfn = NULL; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((nd = (Nameddir) nameddirtab->getnode(nameddirtab, name)) && + (nd->flags & ND_USERNAME)) + pm->u.str = dupstring(nd->dir); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } @@ -1715,30 +1672,27 @@ getalias(HashTable ht, char *name, int global, int dis) Param pm = NULL; Alias al; - HEAPALLOC { - pm = (Param) zhalloc(sizeof(struct param)); - pm->nam = dupstring(name); - pm->flags = PM_SCALAR; - pm->sets.cfn = (global ? (dis ? setpmdisgalias : setpmgalias) : - (dis ? setpmdisralias : setpmralias)); - pm->gets.cfn = strgetfn; - pm->unsetfn = unsetpmalias; - pm->ct = 0; - pm->env = NULL; - pm->ename = NULL; - pm->old = NULL; - pm->level = 0; - if ((al = (Alias) aliastab->getnode2(aliastab, name)) && - ((global && (al->flags & ALIAS_GLOBAL)) || - (!global && !(al->flags & ALIAS_GLOBAL))) && - (dis ? (al->flags & DISABLED) : !(al->flags & DISABLED))) - pm->u.str = dupstring(al->text); - else { - pm->u.str = dupstring(""); - pm->flags |= PM_UNSET; - } - } LASTALLOC; - + pm = (Param) zhalloc(sizeof(struct param)); + pm->nam = dupstring(name); + pm->flags = PM_SCALAR; + pm->sets.cfn = (global ? (dis ? setpmdisgalias : setpmgalias) : + (dis ? setpmdisralias : setpmralias)); + pm->gets.cfn = strgetfn; + pm->unsetfn = unsetpmalias; + pm->ct = 0; + pm->env = NULL; + pm->ename = NULL; + pm->old = NULL; + pm->level = 0; + if ((al = (Alias) aliastab->getnode2(aliastab, name)) && + ((global && (al->flags & ALIAS_GLOBAL)) || + (!global && !(al->flags & ALIAS_GLOBAL))) && + (dis ? (al->flags & DISABLED) : !(al->flags & DISABLED))) + pm->u.str = dupstring(al->text); + else { + pm->u.str = dupstring(""); + pm->flags |= PM_UNSET; + } return (HashNode) pm; } diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index 0df035c74..64565c9e1 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -2887,17 +2887,15 @@ newsession(char *nm) } if (!nptr) { - PERMALLOC { - zfsess = (Zftp_session) zcalloc(sizeof(struct zftp_session)); - zfsess->name = ztrdup(nm); - zfsess->cfd = zfsess->dfd = -1; - zfsess->params = (char **) zcalloc(sizeof(zfparams)); - addlinknode(zfsessions, zfsess); + zfsess = (Zftp_session) zcalloc(sizeof(struct zftp_session)); + zfsess->name = ztrdup(nm); + zfsess->cfd = zfsess->dfd = -1; + zfsess->params = (char **) zcalloc(sizeof(zfparams)); + zaddlinknode(zfsessions, zfsess); - zfsesscnt++; - zfstatusp = (int *)zrealloc(zfstatusp, sizeof(int)*zfsesscnt); - zfstatusp[zfsessno] = 0; - } LASTALLOC; + zfsesscnt++; + zfstatusp = (int *)zrealloc(zfstatusp, sizeof(int)*zfsesscnt); + zfstatusp[zfsessno] = 0; } zfsetparam("ZFTP_SESSION", ztrdup(zfsess->name), ZFPM_READONLY); @@ -3221,9 +3219,7 @@ boot_(Module m) /* default preferences if user deletes variable */ zfprefs = ZFPF_SNDP|ZFPF_PASV; - PERMALLOC { - zfsessions = newlinklist(); - } LASTALLOC; + zfsessions = znewlinklist(); newsession("default"); } diff --git a/Src/Modules/zprof.c b/Src/Modules/zprof.c index 59fea3154..5c602ec18 100644 --- a/Src/Modules/zprof.c +++ b/Src/Modules/zprof.c @@ -224,28 +224,24 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name) double prev, now; if (!(f = findpfunc(name))) { - PERMALLOC { - f = (Pfunc) zalloc(sizeof(*f)); - f->name = ztrdup(name); - f->calls = 0; - f->time = f->self = 0.0; - f->next = calls; - calls = f; - ncalls++; - } LASTALLOC; + f = (Pfunc) zalloc(sizeof(*f)); + f->name = ztrdup(name); + f->calls = 0; + f->time = f->self = 0.0; + f->next = calls; + calls = f; + ncalls++; } if (stack) { if (!(a = findparc(stack->p, f))) { - PERMALLOC { - a = (Parc) zalloc(sizeof(*a)); - a->from = stack->p; - a->to = f; - a->calls = 0; - a->time = a->self = 0.0; - a->next = arcs; - arcs = a; - narcs++; - } LASTALLOC; + a = (Parc) zalloc(sizeof(*a)); + a->from = stack->p; + a->to = f; + a->calls = 0; + a->time = a->self = 0.0; + a->next = arcs; + arcs = a; + narcs++; } } sf.prev = stack; diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 088979514..250b769a3 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -307,9 +307,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int block) p = (Ptycmd) zalloc(sizeof(*p)); p->name = ztrdup(pname); - PERMALLOC { - p->args = arrdup(args); - } LASTALLOC; + p->args = zarrdup(args); p->fd = master; p->pid = pid; p->echo = echo; diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 8c552433f..f2a3ed34c 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -115,9 +115,7 @@ setstypat(Style s, char *pat, Patprog prog, char **vals) if (p->vals) freearray(p->vals); - PERMALLOC { - p->vals = arrdup(vals); - } LASTALLOC; + p->vals = zarrdup(vals); return; } @@ -127,9 +125,7 @@ setstypat(Style s, char *pat, Patprog prog, char **vals) p = (Stypat) zalloc(sizeof(*p)); p->pat = ztrdup(pat); p->prog = prog; - PERMALLOC { - p->vals = arrdup(vals); - } LASTALLOC; + p->vals = zarrdup(vals); p->next = NULL; /* Calculate the weight. */ @@ -353,9 +349,7 @@ bin_zstyle(char *nam, char **args, char *ops, int func) int val; if ((s = lookupstyle(args[1], args[2])) && s->vals[0]) { - PERMALLOC { - ret = sepjoin(s->vals, (args[4] ? args[4] : " ")); - } LASTALLOC; + ret = sepjoin(s->vals, (args[4] ? args[4] : " "), 0); val = 0; } else { ret = ztrdup(""); @@ -397,16 +391,12 @@ bin_zstyle(char *nam, char **args, char *ops, int func) int val; if ((s = lookupstyle(args[1], args[2]))) { - PERMALLOC { - ret = arrdup(s->vals); - } LASTALLOC; + ret = zarrdup(s->vals); val = 0; } else { char *dummy = NULL; - PERMALLOC { - ret = arrdup(&dummy); - } LASTALLOC; + ret = zarrdup(&dummy); val = 1; } if (args[0][1] == 'a') @@ -697,14 +687,12 @@ savematch(MatchData *m) { char **a; - PERMALLOC { - a = getaparam("match"); - m->match = a ? arrdup(a) : NULL; - a = getaparam("mbegin"); - m->mbegin = a ? arrdup(a) : NULL; - a = getaparam("mend"); - m->mend = a ? arrdup(a) : NULL; - } LASTALLOC; + a = getaparam("match"); + m->match = a ? zarrdup(a) : NULL; + a = getaparam("mbegin"); + m->mbegin = a ? zarrdup(a) : NULL; + a = getaparam("mend"); + m->mend = a ? zarrdup(a) : NULL; } static void @@ -770,7 +758,7 @@ connectstates(LinkList out, LinkList in) for (innode = firstnode(in); innode; innode = nextnode(innode)) { RParseBranch *inbranch = getdata(innode); - RParseBranch *br = ncalloc(sizeof(*br)); + RParseBranch *br = hcalloc(sizeof(*br)); br->state = inbranch->state; br->actions = newlinklist(); @@ -804,7 +792,7 @@ rparseelt(RParseResult *result, jmp_buf *perr) (3 <= l && s[l - 2] == '/' && (s[l - 1] == '+' || s[l - 1] == '-')))) return 1; - st = ncalloc(sizeof(*st)); + st = hcalloc(sizeof(*st)); st->branches = newlinklist(); st->cutoff = s[l - 1]; if (s[l - 1] == '/') { @@ -830,7 +818,7 @@ rparseelt(RParseResult *result, jmp_buf *perr) int l = patternlen + 12; /* (#b)((#B)...)...* */ if(lookahead) l += lookaheadlen + 4; /* (#B)... */ - cp = st->pattern = ncalloc(l); + cp = st->pattern = hcalloc(l); strcpy(cp, "(#b)((#B)"); cp += 9; strcpy(cp, pattern); @@ -849,7 +837,7 @@ rparseelt(RParseResult *result, jmp_buf *perr) if ((s = *rparseargs) && *s == '-') { rparseargs++; l = strlen(s); - st->guard = ncalloc(l); + st->guard = hcalloc(l); memcpy(st->guard, s + 1, l - 1); st->guard[l - 1] = '\0'; } else @@ -857,19 +845,19 @@ rparseelt(RParseResult *result, jmp_buf *perr) if ((s = *rparseargs) && *s == ':') { rparseargs++; l = strlen(s); - st->action = ncalloc(l); + st->action = hcalloc(l); memcpy(st->action, s + 1, l - 1); st->action[l - 1] = '\0'; } else st->action = NULL; result->nullacts = NULL; result->in = newlinklist(); - br = ncalloc(sizeof(*br)); + br = hcalloc(sizeof(*br)); br->state = st; br->actions = newlinklist(); addlinknode(result->in, br); result->out = newlinklist(); - br = ncalloc(sizeof(*br)); + br = hcalloc(sizeof(*br)); br->state = st; br->actions = newlinklist(); addlinknode(result->out, br); @@ -948,7 +936,7 @@ rparseseq(RParseResult *result, jmp_buf *perr) while (1) { if ((s = *rparseargs) && s[0] == '{' && s[(l = strlen(s)) - 1] == '}') { - char *action = ncalloc(l - 1); + char *action = hcalloc(l - 1); LinkNode ln; rparseargs++; @@ -1136,22 +1124,21 @@ bin_zregexparse(char *nam, char **args, char *ops, int func) opts[EXTENDEDGLOB] = 1; rparseargs = args + 3; - HEAPALLOC { - pushheap(); - rparsestates = newlinklist(); - if (setjmp(rparseerr) || rparsealt(&result, &rparseerr) || *rparseargs) { - if (*rparseargs) - zwarnnam(nam, "invalid regex : %s", *rparseargs, 0); - else - zwarnnam(nam, "not enough regex arguments", NULL, 0); - ret = 3; - } else - ret = 0; - if (!ret) - ret = rmatch(&result, subj, var1, var2, ops['c']); - popheap(); - } LASTALLOC; + pushheap(); + rparsestates = newlinklist(); + if (setjmp(rparseerr) || rparsealt(&result, &rparseerr) || *rparseargs) { + if (*rparseargs) + zwarnnam(nam, "invalid regex : %s", *rparseargs, 0); + else + zwarnnam(nam, "not enough regex arguments", NULL, 0); + ret = 3; + } else + ret = 0; + + if (!ret) + ret = rmatch(&result, subj, var1, var2, ops['c']); + popheap(); opts[EXTENDEDGLOB] = oldextendedglob; return ret; @@ -1511,10 +1498,7 @@ bin_zparseopts(char *nam, char **args, char *ops, int func) sethparam(assoc, aval); } if (del) { - PERMALLOC { - pp = arrdup(pp); - } LASTALLOC; - + pp = zarrdup(pp); freearray(pparams); pparams = pp; } -- cgit 1.4.1