Changeset 3438 for trunk/src/kash/exec.c


Ignore:
Timestamp:
Sep 9, 2020, 10:01:39 PM (5 years ago)
Author:
bird
Message:

kash: Hammering on threaded mode.

File:
1 edited

Legend:

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

    r3437 r3438  
    4545#include <stdio.h>
    4646#include <stdlib.h>
     47#include <stddef.h>
    4748
    4849/*
     
    112113extern char *const parsekwd[];
    113114
     115#ifndef SH_FORKED_MODE
     116void
     117subshellinitexec(shinstance *psh, shinstance *inherit)
     118{
     119    unsigned i;
     120    for (i = 0; i < K_ELEMENTS(inherit->cmdtable); i++) {
     121        struct tblentry const *csrc = inherit->cmdtable[i];
     122        if (!csrc) {
     123        } else {
     124            struct tblentry **ppdst = &psh->cmdtable[i];
     125            do
     126            {
     127                size_t const namesize = strlen(csrc->cmdname) + 1;
     128                size_t const entrysize = offsetof(struct tblentry, cmdname) + namesize;
     129                struct tblentry *dst = (struct tblentry *)ckmalloc(psh, entrysize);
     130                memcpy(dst->cmdname, csrc->cmdname, namesize);
     131                dst->rehash = csrc->rehash;
     132                dst->cmdtype = csrc->cmdtype;
     133
     134                dst->param.func = NULL;
     135                switch (csrc->cmdtype) {
     136                case CMDUNKNOWN:
     137                case CMDNORMAL:
     138                    dst->param.index = csrc->param.index;
     139                    break;
     140                case CMDFUNCTION:
     141                    dst->param.func = copyfunc(psh, csrc->param.func); /** @todo optimize function allocations */
     142                    break;
     143                case CMDBUILTIN:
     144                case CMDSPLBLTIN:
     145                    dst->param.bltin = csrc->param.bltin;
     146                    break;
     147                }
     148
     149                *ppdst = dst;
     150                ppdst = &dst->next;
     151
     152                csrc = csrc->next;
     153            } while (csrc);
     154            *ppdst = NULL;
     155        }
     156    }
     157
     158    psh->builtinloc = inherit->builtinloc;
     159}
     160#endif /* SH_FORKED_MODE */
     161
     162
    114163/*
    115164 * Exec a program.  Never returns.  If you change this routine, you may
     
    222271                initshellproc(psh);
    223272                setinputfile(psh, cmd, 0);
     273                if (psh->commandnamemalloc) {
     274                    sh_free(psh, psh->commandname);
     275                    psh->commandnamemalloc = 0;
     276                }
     277                if (psh->arg0malloc)
     278                    sh_free(psh, psh->arg0);
    224279                psh->commandname = psh->arg0 = savestr(psh, argv[0]);
     280                psh->arg0malloc = 1;
    225281#ifdef EXEC_HASH_BANG_SCRIPT
    226282                pgetc(psh); pungetc(psh);               /* fill up input buffer */
Note: See TracChangeset for help on using the changeset viewer.