Ignore:
Timestamp:
Sep 14, 2020, 11:46:32 PM (5 years ago)
Author:
bird
Message:

kash: Use reference counting of parser output in threaded-mode.

File:
1 edited

Legend:

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

    r3451 r3458  
    4444#include "error.h"
    4545#include "memalloc.h"
     46#include "nodes.h"
    4647#include "redir.h"
    4748#include "shell.h"
     
    274275    unsigned left, i;
    275276
     277    INTOFF;
     278
    276279    sh_int_unlink(psh);
    277     shfile_uninit(&psh->fdtab);
     280    shfile_uninit(&psh->fdtab, psh->tracefd);
    278281    sh_free_string_vector(psh, &psh->shenviron);
    279282
     
    328331    struct arglist      exparg;         /**< holds expanded arg list */
    329332    char               *expdir;         /**< Used by expandmeta. */
    330 
    331     /* exec.h */
    332     const char         *pathopt;        /**< set by padvance */
    333 
    334     /* exec.c */
    335     struct tblentry    *cmdtable[CMDTABLESIZE];
    336     int                 builtinloc/* = -1*/;    /**< index in path of %builtin, or -1 */
    337 
     333#endif
     334
     335    /* exec.h/exec.c */
     336    psh->pathopt = NULL;
     337    for (i = 0; i < CMDTABLESIZE; i++)
     338    {
     339        struct tblentry *cur = psh->cmdtable[i];
     340        if (cur)
     341        {
     342            do
     343            {
     344                struct tblentry *next = cur->next;
     345                if (cur->cmdtype == CMDFUNCTION)
     346                {
     347                    freefunc(psh, cur->param.func);
     348                    cur->param.func = NULL;
     349                }
     350                sh_free(psh, cur);
     351                cur = next;
     352            } while (cur);
     353            psh->cmdtable[i] = NULL;
     354        }
     355    }
     356
     357#if 0
    338358    /* input.h */
    339359    int                 plinno/* = 1 */;/**< input line number */
     
    382402    int                 sstrnleft;
    383403    int                 herefd/* = -1 */;
    384 
    385     /* memalloc.c */
    386     struct stack_block  stackbase;
    387     struct stack_block *stackp/* = &stackbase*/;
    388     struct stackmark   *markp;
    389404
    390405    /* myhistedit.h */
     
    491506#endif
    492507
    493 /** @todo finish this...   */
     508    /*
     509     * memalloc.c: Make sure we've gotten rid of all the stack memory.
     510     */
     511    if (psh->stackp != &psh->stackbase && psh->stackp)
     512    {
     513        struct stack_block *stackp = psh->stackp;
     514        do
     515        {
     516            psh->stackp = stackp->prev;
     517            sh_free(psh, stackp);
     518        } while ((stackp = psh->stackp) != &psh->stackbase && stackp);
     519    }
     520#ifdef KASH_SEPARATE_PARSER_ALLOCATOR //bp msvcr100!_wassert
     521    if (psh->pstack)
     522    {
     523        if (psh->pstacksize > 0)
     524            pstackpop(psh, 0);
     525        sh_free(psh, psh->pstack);
     526        psh->pstack = NULL;
     527    }
     528#endif
     529    psh->markp = NULL;
     530
     531
     532    /*
     533     * Finally get rid of tracefd and then free the shell:
     534     */
     535    shfile_uninit(&psh->fdtab, -1);
     536
    494537    memset(psh, 0, sizeof(*psh));
    495538    sh_free(NULL, psh);
     
    673716{
    674717    /*
     718     * Make sure we can use TRACE/TRACE2 for logging here.
     719     */
     720#ifdef DEBUG
     721    /* show.c */
     722    psh->tracefd = inherit->tracefd;
     723    /* options.c */
     724    debug(psh) = debug(inherit);
     725#endif
     726
     727    /*
    675728     * Do the rest of the inheriting.
    676729     */
     
    743796    /* redir.c */
    744797    subshellinitredir(psh, inherit);
    745 
    746     /* show.c */
    747     psh->tracefd = inherit->tracefd;
    748798
    749799    /* trap.h / trap.c */ /** @todo we don't carry pendingsigs to the subshell, right? */
     
    16631713    {
    16641714        TRACE2((psh, "sh__exit: %u shells around, must wait...\n", g_num_shells));
    1665         shfile_uninit(&psh->fdtab);
     1715        shfile_uninit(&psh->fdtab, psh->tracefd);
    16661716        sh_int_unlink(psh);
    16671717        /** @todo    */
Note: See TracChangeset for help on using the changeset viewer.