Ignore:
Timestamp:
Sep 14, 2020, 2:03:45 PM (5 years ago)
Author:
bird
Message:

kash: parser.c,memalloc.c/.h,expand.c: Prepared the parser for using a separate allocator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/parser.c

    r3449 r3456  
    4141#endif
    4242
     43#define SH_MEMALLOC_NO_STACK
    4344#include <stdlib.h>
     45#include <assert.h>
    4446
    4547#include "shell.h"
     
    129131parsecmd(shinstance *psh, int interact)
    130132{
     133        union node *ret;
    131134        int t;
     135        TRACE2((psh, "parsecmd(%d)\n", interact));
    132136
    133137        psh->tokpushback = 0;
     
    144148                return NULL;
    145149        psh->tokpushback++;
    146         return list(psh, 1);
     150        ret = list(psh, 1);
     151#if 0 /*def DEBUG*/
     152        TRACE2((psh, "parsecmd(%d) returns:\n", interact));
     153        showtree(psh, ret);
     154#endif
     155        return ret;
    147156}
    148157
     
    167176                                n2->type = NBACKGND;
    168177                        } else {
    169                                 n3 = (union node *)stalloc(psh, sizeof (struct nredir));
     178                                n3 = pstallocnode(psh, sizeof (struct nredir));
    170179                                n3->type = NBACKGND;
    171180                                n3->nredir.n = n2;
     
    178187                }
    179188                else {
    180                         n3 = (union node *)stalloc(psh, sizeof (struct nbinary));
     189                        n3 = pstallocnode(psh, sizeof (struct nbinary));
    181190                        n3->type = NSEMI;
    182191                        n3->nbinary.ch1 = n1;
     
    235244                }
    236245                n2 = pipeline(psh);
    237                 n3 = (union node *)stalloc(psh, sizeof (struct nbinary));
     246                n3 = pstallocnode(psh, sizeof (struct nbinary));
    238247                n3->type = t;
    239248                n3->nbinary.ch1 = n1;
     
    259268        n1 = command(psh);
    260269        if (readtoken(psh) == TPIPE) {
    261                 pipenode = (union node *)stalloc(psh, sizeof (struct npipe));
     270                pipenode = pstallocnode(psh, sizeof (struct npipe));
    262271                pipenode->type = NPIPE;
    263272                pipenode->npipe.backgnd = 0;
    264                 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
     273                lp = pstalloclist(psh);
    265274                pipenode->npipe.cmdlist = lp;
    266275                lp->n = n1;
    267276                do {
    268277                        prev = lp;
    269                         lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
     278                        lp = pstalloclist(psh);
    270279                        lp->n = command(psh);
    271280                        prev->next = lp;
     
    276285        psh->tokpushback++;
    277286        if (negate) {
    278                 n2 = (union node *)stalloc(psh, sizeof (struct nnot));
     287                n2 = pstallocnode(psh, sizeof (struct nnot));
    279288                n2->type = NNOT;
    280289                n2->nnot.com = n1;
     
    316325        switch (readtoken(psh)) {
    317326        case TIF:
    318                 n1 = (union node *)stalloc(psh, sizeof (struct nif));
     327                n1 = pstallocnode(psh, sizeof (struct nif));
    319328                n1->type = NIF;
    320329                n1->nif.test = list(psh, 0);
     
    324333                n2 = n1;
    325334                while (readtoken(psh) == TELIF) {
    326                         n2->nif.elsepart = (union node *)stalloc(psh, sizeof (struct nif));
     335                        n2->nif.elsepart = pstallocnode(psh, sizeof (struct nif));
    327336                        n2 = n2->nif.elsepart;
    328337                        n2->type = NIF;
     
    345354        case TUNTIL: {
    346355                int got;
    347                 n1 = (union node *)stalloc(psh, sizeof (struct nbinary));
     356                n1 = pstallocnode(psh, sizeof (struct nbinary));
    348357                n1->type = (psh->lasttoken == TWHILE)? NWHILE : NUNTIL;
    349358                n1->nbinary.ch1 = list(psh, 0);
     
    361370                if (readtoken(psh) != TWORD || psh->quoteflag || ! goodname(psh->wordtext))
    362371                        synerror(psh, "Bad for loop variable");
    363                 n1 = (union node *)stalloc(psh, sizeof (struct nfor));
     372                n1 = pstallocnode(psh, sizeof (struct nfor));
    364373                n1->type = NFOR;
    365374                n1->nfor.var = psh->wordtext;
     
    367376                        app = &ap;
    368377                        while (readtoken(psh) == TWORD) {
    369                                 n2 = (union node *)stalloc(psh, sizeof (struct narg));
     378                                n2 = pstallocnode(psh, sizeof (struct narg));
    370379                                n2->type = NARG;
    371380                                n2->narg.text = psh->wordtext;
     
    381390                        static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
    382391                                                                   '@', '=', '\0'};
    383                         n2 = (union node *)stalloc(psh, sizeof (struct narg));
     392                        n2 = pstallocnode(psh, sizeof (struct narg));
    384393                        n2->type = NARG;
    385394                        n2->narg.text = argvars;
     
    407416                break;
    408417        case TCASE:
    409                 n1 = (union node *)stalloc(psh, sizeof (struct ncase));
     418                n1 = pstallocnode(psh, sizeof (struct ncase));
    410419                n1->type = NCASE;
    411420                if (readtoken(psh) != TWORD)
    412421                        synexpect(psh, TWORD);
    413                 n1->ncase.expr = n2 = (union node *)stalloc(psh, sizeof (struct narg));
     422                n1->ncase.expr = n2 = pstallocnode(psh, sizeof (struct narg));
    414423                n2->type = NARG;
    415424                n2->narg.text = psh->wordtext;
     
    423432                psh->checkkwd = 2, readtoken(psh);
    424433                do {
    425                         *cpp = cp = (union node *)stalloc(psh, sizeof (struct nclist));
     434                        *cpp = cp = pstallocnode(psh, sizeof (struct nclist));
    426435                        cp->type = NCLIST;
    427436                        app = &cp->nclist.pattern;
    428437                        for (;;) {
    429                                 *app = ap = (union node *)stalloc(psh, sizeof (struct narg));
     438                                *app = ap = pstallocnode(psh, sizeof (struct narg));
    430439                                ap->type = NARG;
    431440                                ap->narg.text = psh->wordtext;
     
    461470                break;
    462471        case TLP:
    463                 n1 = (union node *)stalloc(psh, sizeof (struct nredir));
     472                n1 = pstallocnode(psh, sizeof (struct nredir));
    464473                n1->type = NSUBSHELL;
    465474                n1->nredir.n = list(psh, 0);
     
    507516        if (redir) {
    508517                if (n1->type != NSUBSHELL) {
    509                         n2 = (union node *)stalloc(psh, sizeof (struct nredir));
     518                        n2 = pstallocnode(psh, sizeof (struct nredir));
    510519                        n2->type = NREDIR;
    511520                        n2->nredir.n = n1;
     
    517526checkneg:
    518527        if (negate) {
    519                 n2 = (union node *)stalloc(psh, sizeof (struct nnot));
     528                n2 = pstallocnode(psh, sizeof (struct nnot));
    520529                n2->type = NNOT;
    521530                n2->nnot.com = n1;
     
    557566        for (;;) {
    558567                if (readtoken(psh) == TWORD) {
    559                         n = (union node *)stalloc(psh, sizeof (struct narg));
     568                        n = pstallocnode(psh, sizeof (struct narg));
    560569                        n->type = NARG;
    561570                        n->narg.text = psh->wordtext;
     
    586595        *app = NULL;
    587596        *rpp = NULL;
    588         n = (union node *)stalloc(psh, sizeof (struct ncmd));
     597        n = pstallocnode(psh, sizeof (struct ncmd));
    589598        n->type = NCMD;
    590599        n->ncmd.backgnd = 0;
     
    594603checkneg:
    595604        if (negate) {
    596                 n2 = (union node *)stalloc(psh, sizeof (struct nnot));
     605                n2 = pstallocnode(psh, sizeof (struct nnot));
    597606                n2->type = NNOT;
    598607                n2->nnot.com = n;
     
    608617        union node *n;
    609618
    610         n = (union node *)stalloc(psh, sizeof (struct narg));
     619        n = pstallocnode(psh, sizeof (struct narg));
    611620        n->type = NARG;
    612621        n->narg.next = NULL;
     
    693702                readtoken1(psh, pgetc(psh), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
    694703                                here->eofmark, here->striptabs);
    695                 n = (union node *)stalloc(psh, sizeof (struct narg));
     704                n = pstallocnode(psh, sizeof (struct narg));
    696705                n->narg.type = NARG;
    697706                n->narg.next = NULL;
     
    911920        int c = firstc;
    912921        char *out;
    913         int len;
    914922        char line[EOFMARKLEN + 1];
    915923        struct nodelist *bqlist;
     
    950958#endif
    951959
    952         STARTSTACKSTR(psh, out);
     960        PSTARTSTACKSTR(psh, out);
    953961        loop: { /* for each line, until end of word */
    954962#if ATTY
     
    964972                CHECKEND();     /* set c to PEOF if at end of here document */
    965973                for (;;) {      /* until end of line or end of word */
    966                         CHECKSTRSPACE(psh, 4, out);     /* permit 4 calls to USTPUTC */
     974                        PSTCHECKSTRSPACE(psh, 4+1, out);        /* permit 4 calls to PSTUPUTC, pluss terminator */
    967975                        switch(syntax[c]) {
    968976                        case CNL:       /* '\n' */
    969977                                if (syntax == BASESYNTAX)
    970978                                        goto endword;   /* exit outer loop */
    971                                 USTPUTC(psh, c, out);
     979                                PSTUPUTC(psh, c, out);
    972980                                psh->plinno++;
    973981                                if (psh->doprompt)
     
    978986                                goto loop;              /* continue outer loop */
    979987                        case CWORD:
    980                                 USTPUTC(psh, c, out);
     988                                PSTUPUTC(psh, c, out);
    981989                                break;
    982990                        case CCTL:
    983991                                if (eofmark == NULL || ISDBLQUOTE())
    984                                         USTPUTC(psh, CTLESC, out);
    985                                 USTPUTC(psh, c, out);
     992                                        PSTUPUTC(psh, CTLESC, out);
     993                                PSTUPUTC(psh, c, out);
    986994                                break;
    987995                        case CBACK:     /* backslash */
    988996                                c = pgetc(psh);
    989997                                if (c == PEOF) {
    990                                         USTPUTC(psh, '\\', out);
     998                                        PSTUPUTC(psh, '\\', out);
    991999                                        pungetc(psh);
    9921000                                        break;
     
    10031011                                    c != '`' && c != '$' &&
    10041012                                    (c != '"' || eofmark != NULL))
    1005                                         USTPUTC(psh, '\\', out);
     1013                                        PSTUPUTC(psh, '\\', out);
    10061014                                if (SQSYNTAX[c] == CCTL)
    1007                                         USTPUTC(psh, CTLESC, out);
     1015                                        PSTUPUTC(psh, CTLESC, out);
    10081016                                else if (eofmark == NULL) {
    1009                                         USTPUTC(psh, CTLQUOTEMARK, out);
    1010                                         USTPUTC(psh, c, out);
     1017                                        PSTUPUTC(psh, CTLQUOTEMARK, out);
     1018                                        PSTUPUTC(psh, c, out);
    10111019                                        if (varnest != 0)
    1012                                                 USTPUTC(psh, CTLQUOTEEND, out);
     1020                                                PSTUPUTC(psh, CTLQUOTEEND, out);
    10131021                                        break;
    10141022                                }
    1015                                 USTPUTC(psh, c, out);
     1023                                PSTUPUTC(psh, c, out);
    10161024                                break;
    10171025                        case CSQUOTE:
    10181026                                if (syntax != SQSYNTAX) {
    10191027                                        if (eofmark == NULL)
    1020                                                 USTPUTC(psh, CTLQUOTEMARK, out);
     1028                                                PSTUPUTC(psh, CTLQUOTEMARK, out);
    10211029                                        quotef = 1;
    10221030                                        syntax = SQSYNTAX;
     
    10261034                                    varnest == 0) {
    10271035                                        /* Ignore inside quoted here document */
    1028                                         USTPUTC(psh, c, out);
     1036                                        PSTUPUTC(psh, c, out);
    10291037                                        break;
    10301038                                }
     
    10351043                                        syntax = BASESYNTAX;
    10361044                                        if (varnest != 0)
    1037                                                 USTPUTC(psh, CTLQUOTEEND, out);
     1045                                                PSTUPUTC(psh, CTLQUOTEEND, out);
    10381046                                }
    10391047                                break;
     
    10421050                                    varnest == 0) {
    10431051                                        /* Ignore inside here document */
    1044                                         USTPUTC(psh, c, out);
     1052                                        PSTUPUTC(psh, c, out);
    10451053                                        break;
    10461054                                }
     
    10531061                                                syntax = DQSYNTAX;
    10541062                                                SETDBLQUOTE();
    1055                                                 USTPUTC(psh, CTLQUOTEMARK, out);
     1063                                                PSTUPUTC(psh, CTLQUOTEMARK, out);
    10561064                                        }
    10571065                                        break;
     
    10611069                                if (ISDBLQUOTE()) {
    10621070                                        if (varnest != 0)
    1063                                                 USTPUTC(psh, CTLQUOTEEND, out);
     1071                                                PSTUPUTC(psh, CTLQUOTEEND, out);
    10641072                                        syntax = BASESYNTAX;
    10651073                                        CLRDBLQUOTE();
     
    10671075                                        syntax = DQSYNTAX;
    10681076                                        SETDBLQUOTE();
    1069                                         USTPUTC(psh, CTLQUOTEMARK, out);
     1077                                        PSTUPUTC(psh, CTLQUOTEMARK, out);
    10701078                                }
    10711079                                break;
     
    10761084                                if (varnest > 0 && !ISDBLQUOTE()) {
    10771085                                        varnest--;
    1078                                         USTPUTC(psh, CTLENDVAR, out);
     1086                                        PSTUPUTC(psh, CTLENDVAR, out);
    10791087                                } else {
    1080                                         USTPUTC(psh, c, out);
     1088                                        PSTUPUTC(psh, c, out);
    10811089                                }
    10821090                                break;
    10831091                        case CLP:       /* '(' in arithmetic */
    10841092                                parenlevel++;
    1085                                 USTPUTC(psh, c, out);
     1093                                PSTUPUTC(psh, c, out);
    10861094                                break;
    10871095                        case CRP:       /* ')' in arithmetic */
    10881096                                if (parenlevel > 0) {
    1089                                         USTPUTC(psh, c, out);
     1097                                        PSTUPUTC(psh, c, out);
    10901098                                        --parenlevel;
    10911099                                } else {
    10921100                                        if (pgetc(psh) == ')') {
    10931101                                                if (--arinest == 0) {
    1094                                                         USTPUTC(psh, CTLENDARI, out);
     1102                                                        PSTUPUTC(psh, CTLENDARI, out);
    10951103                                                        syntax = prevsyntax;
    10961104                                                        if (syntax == DQSYNTAX)
     
    10991107                                                                CLRDBLQUOTE();
    11001108                                                } else
    1101                                                         USTPUTC(psh, ')', out);
     1109                                                        PSTUPUTC(psh, ')', out);
    11021110                                        } else {
    11031111                                                /*
     
    11061114                                                 */
    11071115                                                pungetc(psh);
    1108                                                 USTPUTC(psh, ')', out);
     1116                                                PSTUPUTC(psh, ')', out);
    11091117                                        }
    11101118                                }
     
    11181126                                if (varnest == 0)
    11191127                                        goto endword;   /* exit outer loop */
    1120                                 USTPUTC(psh, c, out);
     1128                                PSTUPUTC(psh, c, out);
    11211129                        }
    11221130                        c = pgetc_macro(psh);
     
    11331141                synerror(psh, "Missing '}'");
    11341142        }
    1135         USTPUTC(psh, '\0', out);
    1136         len = (int)(out - stackblock(psh));
    1137         out = stackblock(psh);
     1143        PSTUPUTC(psh, '\0', out);
    11381144        if (eofmark == NULL) {
     1145                size_t len = (size_t)(out - PSTBLOCK(psh));
     1146                char *start = PSTBLOCK(psh);
    11391147                if ((c == '>' || c == '<')
    11401148                 && quotef == 0
    11411149                 && len <= 2
    1142                  && (*out == '\0' || is_digit(*out))) {
     1150                 && (*start == '\0' || is_digit(*start))) {
     1151                        out = start;
    11431152                        PARSEREDIR();
    11441153                        return psh->lasttoken = TREDIR;
     
    11491158        psh->quoteflag = quotef;
    11501159        psh->backquotelist = bqlist;
    1151         grabstackblock(psh, len);
    1152         psh->wordtext = out;
     1160        psh->wordtext = pstgrabstr(psh, out);
    11531161        if (dblquotep != NULL)
    11541162            ckfree(psh, dblquotep);
     
    12031211        (void)dummy;
    12041212
    1205         np = (union node *)stalloc(psh, sizeof (struct ndup));
     1213        np = pstallocnode(psh, sizeof (struct ndup));
    12061214        if (c == '>') {
    12071215                np->nfile.fd = 1;
     
    12221230                case '<':
    12231231                        np->type = NHERE;
    1224                         psh->heredoc = (struct heredoc *)stalloc(psh, sizeof (struct heredoc));
     1232                        psh->heredoc = (struct heredoc *)pstalloc(psh, sizeof (struct heredoc));
    12251233                        psh->heredoc->here = np;
    12261234                        if ((c = pgetc(psh)) == '-') {
     
    12671275        c = pgetc(psh);
    12681276        if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) {
    1269                 USTPUTC(psh, '$', out);
     1277                PSTUPUTC(psh, '$', out);
    12701278                pungetc(psh);
    12711279        } else if (c == '(') {  /* $(command) or $((arith)) */
     
    12771285                }
    12781286        } else {
    1279                 USTPUTC(psh, CTLVAR, out);
    1280                 typeloc = (int)(out - stackblock(psh));
    1281                 USTPUTC(psh, VSNORMAL, out);
     1287                PSTUPUTC(psh, CTLVAR, out);
     1288                typeloc = (int)(out - PSTBLOCK(psh));
     1289                PSTUPUTC(psh, VSNORMAL, out);
    12821290                subtype = VSNORMAL;
    12831291                if (c == OPENBRACE) {
     
    12941302                if (is_name(c)) {
    12951303                        do {
    1296                                 STPUTC(psh, c, out);
     1304                                PSTPUTC(psh, c, out);
    12971305                                c = pgetc(psh);
    12981306                        } while (is_in_name(c));
    12991307                } else if (is_digit(c)) {
    13001308                        do {
    1301                                 USTPUTC(psh, c, out);
     1309                                PSTUPUTC(psh, c, out);
    13021310                                c = pgetc(psh);
    13031311                        } while (is_digit(c));
    13041312                }
    13051313                else if (is_special(c)) {
    1306                         USTPUTC(psh, c, out);
     1314                        PSTUPUTC(psh, c, out);
    13071315                        c = pgetc(psh);
    13081316                }
    1309                 else
    1310 badsub:                 synerror(psh, "Bad substitution");
    1311 
    1312                 STPUTC(psh, '=', out);
     1317                else {
     1318badsub:
     1319                    synerror(psh, "Bad substitution");
     1320                }
     1321
     1322                PSTPUTC(psh, '=', out);
    13131323                flags = 0;
    13141324                if (subtype == 0) {
     
    13431353                if (ISDBLQUOTE() || arinest)
    13441354                        flags |= VSQUOTE;
    1345                 *(stackblock(psh) + typeloc) = subtype | flags;
     1355                *(PSTBLOCK(psh) + typeloc) = subtype | flags;
    13461356                if (subtype != VSNORMAL) {
    13471357                        varnest++;
     
    13871397        INTOFF;
    13881398        str = NULL;
    1389         savelen = (int)(out - stackblock(psh));
     1399        savelen = (int)(out - PSTBLOCK(psh));
    13901400        if (savelen > 0) {
    13911401                str = ckmalloc(psh, savelen);
    1392                 memcpy(str, stackblock(psh), savelen);
     1402                memcpy(str, PSTBLOCK(psh), savelen);
    13931403        }
    13941404        savehandler = psh->handler;
     
    14051415
    14061416
    1407                 STARTSTACKSTR(psh, pout);
     1417                PSTARTSTACKSTR(psh, pout);
    14081418                for (;;) {
    14091419                        if (psh->needprompt) {
     
    14251435                                         * If eating a newline, avoid putting
    14261436                                         * the newline into the new character
    1427                                          * stream (via the STPUTC after the
     1437                                         * stream (via the PSTPUTC after the
    14281438                                         * switch).
    14291439                                         */
     
    14311441                                }
    14321442                                if (pc != '\\' && pc != '`' && pc != '$' && (!ISDBLQUOTE() || pc != '"'))
    1433                                         STPUTC(psh, '\\', pout);
     1443                                        PSTPUTC(psh, '\\', pout);
    14341444                                break;
    14351445
     
    14471457                                break;
    14481458                        }
    1449                         STPUTC(psh, pc, pout);
     1459                        PSTPUTC(psh, pc, pout);
    14501460                }
    14511461done:
    1452                 STPUTC(psh, '\0', pout);
    1453                 psavelen = (int)(pout - stackblock(psh));
    1454                 if (psavelen > 0) {
    1455                         pstr = grabstackstr(psh, pout);
    1456                         setinputstring(psh, pstr, 1);
     1462                PSTPUTC(psh, '\0', pout);
     1463                psavelen = (int)(pout - PSTBLOCK(psh));
     1464                if (psavelen > 0) { /** @todo nonsensical test? */
     1465                        pstr = pstgrabstr(psh, pout);
     1466                        setinputstring(psh, pstr, 1 /*push*/);
    14571467                }
    14581468        }
     
    14601470        while (*nlpp)
    14611471                nlpp = &(*nlpp)->next;
    1462         *nlpp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist));
     1472        *nlpp = pstalloclist(psh);
    14631473        (*nlpp)->next = NULL;
    14641474        psh->parsebackquote = oldstyle;
     
    14871497                psh->tokpushback = 0;
    14881498        }
    1489         while (stackblocksize(psh) <= savelen)
    1490                 growstackblock(psh);
    1491         STARTSTACKSTR(psh, out);
     1499        PSTARTSTACKSTR(psh, out);
    14921500        if (str) {
    1493                 memcpy(out, str, savelen);
    1494                 STADJUST(psh, savelen, out);
     1501                PSTPUTSTRN(psh, str, savelen, out);
    14951502                INTOFF;
    14961503                ckfree(psh, str);
     
    15011508        psh->handler = savehandler;
    15021509        if (arinest || ISDBLQUOTE())
    1503                 USTPUTC(psh, CTLBACKQ | CTLQUOTE, out);
     1510                PSTUPUTC(psh, CTLBACKQ | CTLQUOTE, out);
    15041511        else
    1505                 USTPUTC(psh, CTLBACKQ, out);
     1512                PSTUPUTC(psh, CTLBACKQ, out);
    15061513        if (oldstyle)
    15071514                goto parsebackq_oldreturn;
     
    15181525                prevsyntax = syntax;
    15191526                syntax = ARISYNTAX;
    1520                 USTPUTC(psh, CTLARI, out);
     1527                PSTUPUTC(psh, CTLARI, out);
    15211528                if (ISDBLQUOTE())
    1522                         USTPUTC(psh, '"',out);
     1529                        PSTUPUTC(psh, '"',out);
    15231530                else
    1524                         USTPUTC(psh, ' ',out);
     1531                        PSTUPUTC(psh, ' ',out);
    15251532        } else {
    15261533                /*
     
    15281535                 * parenthesis, which should be equivalent
    15291536                 */
    1530                 USTPUTC(psh, '(', out);
     1537                PSTUPUTC(psh, '(', out);
    15311538        }
    15321539        goto parsearith_return;
     
    17881795                struct nodelist **ppnext = &ret;
    17891796                while (src) {
    1790                         struct nodelist *dst = stalloc(psh, sizeof(*dst));
     1797                        struct nodelist *dst = pstalloclist(psh);
    17911798                        dst->next = NULL;
    17921799                        *ppnext = dst;
     
    18181825                        case NWHILE:
    18191826                        case NUNTIL:
    1820                                 ret = (union node *)stalloc(psh, sizeof(src->nbinary));
     1827                                ret = pstallocnode(psh, sizeof(src->nbinary));
    18211828                                ret->nbinary.type = type;
    18221829                                ret->nbinary.ch1  = copyparsetree(psh, src->nbinary.ch1);
     
    18251832
    18261833                        case NCMD:
    1827                                 ret = (union node *)stalloc(psh, sizeof(src->ncmd));
     1834                                ret = pstallocnode(psh, sizeof(src->ncmd));
    18281835                                ret->ncmd.type     = NCMD;
    18291836                                ret->ncmd.backgnd  = src->ncmd.backgnd;
     
    18331840
    18341841                        case NPIPE:
    1835                                 ret = (union node *)stalloc(psh, sizeof(src->npipe));
     1842                                ret = pstallocnode(psh, sizeof(src->npipe));
    18361843                                ret->npipe.type     = NPIPE;
    18371844                                ret->npipe.backgnd  = src->ncmd.backgnd;
     
    18421849                        case NBACKGND:
    18431850                        case NSUBSHELL:
    1844                                 ret = (union node *)stalloc(psh, sizeof(src->nredir));
     1851                                ret = pstallocnode(psh, sizeof(src->nredir));
    18451852                                ret->nredir.type     = type;
    18461853                                ret->nredir.n        = copyparsetree(psh, src->nredir.n);
     
    18491856
    18501857                        case NIF:
    1851                                 ret = (union node *)stalloc(psh, sizeof(src->nif));
     1858                                ret = pstallocnode(psh, sizeof(src->nif));
    18521859                                ret->nif.type        = NIF;
    18531860                                ret->nif.test        = copyparsetree(psh, src->nif.test);
     
    18571864
    18581865                        case NFOR:
    1859                                 ret = (union node *)stalloc(psh, sizeof(src->nfor));
     1866                                ret = pstallocnode(psh, sizeof(src->nfor));
    18601867                                ret->nfor.type       = NFOR;
    18611868                                ret->nfor.args       = copyparsetree(psh, src->nfor.args);
    18621869                                ret->nfor.body       = copyparsetree(psh, src->nfor.body);
    1863                                 ret->nfor.var        = stsavestr(psh, src->nfor.var);
     1870                                ret->nfor.var        = pstsavestr(psh, src->nfor.var);
    18641871                                break;
    18651872
    18661873                        case NCASE:
    1867                                 ret = (union node *)stalloc(psh, sizeof(src->ncase));
     1874                                ret = pstallocnode(psh, sizeof(src->ncase));
    18681875                                ret->ncase.type      = NCASE;
    18691876                                ret->ncase.expr      = copyparsetree(psh, src->ncase.expr);
     
    18721879
    18731880                        case NCLIST:
    1874                                 ret = (union node *)stalloc(psh, sizeof(src->nclist));
     1881                                ret = pstallocnode(psh, sizeof(src->nclist));
    18751882                                ret->nclist.type     = NCLIST;
    18761883                                ret->nclist.next     = copyparsetree(psh, src->nclist.next);
     
    18811888                        case NDEFUN:
    18821889                        case NARG:
    1883                                 ret = (union node *)stalloc(psh, sizeof(src->narg));
     1890                                ret = pstallocnode(psh, sizeof(src->narg));
    18841891                                ret->narg.type       = type;
    18851892                                ret->narg.next       = copyparsetree(psh, src->narg.next);
    1886                                 ret->narg.text       = stsavestr(psh, src->narg.text);
     1893                                ret->narg.text       = pstsavestr(psh, src->narg.text);
    18871894                                ret->narg.backquote  = copynodelist(psh, src->narg.backquote);
    18881895                                break;
     
    18931900                        case NFROMTO:
    18941901                        case NAPPEND:
    1895                                 ret = (union node *)stalloc(psh, sizeof(src->nfile));
     1902                                ret = pstallocnode(psh, sizeof(src->nfile));
    18961903                                ret->nfile.type      = type;
    18971904                                ret->nfile.fd        = src->nfile.fd;
     
    19021909                        case NTOFD:
    19031910                        case NFROMFD:
    1904                                 ret = (union node *)stalloc(psh, sizeof(src->ndup));
     1911                                ret = pstallocnode(psh, sizeof(src->ndup));
    19051912                                ret->ndup.type       = type;
    19061913                                ret->ndup.fd         = src->ndup.fd;
     
    19121919                        case NHERE:
    19131920                        case NXHERE:
    1914                                 ret = (union node *)stalloc(psh, sizeof(src->nhere));
     1921                                ret = pstallocnode(psh, sizeof(src->nhere));
    19151922                                ret->nhere.type      = type;
    19161923                                ret->nhere.fd        = src->nhere.fd;
     
    19201927
    19211928                        case NNOT:
    1922                                 ret = (union node *)stalloc(psh, sizeof(src->nnot));
     1929                                ret = pstallocnode(psh, sizeof(src->nnot));
    19231930                                ret->nnot.type      = NNOT;
    19241931                                ret->nnot.com       = copyparsetree(psh, src->nnot.com);
Note: See TracChangeset for help on using the changeset viewer.