mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +00:00
Streamline some shell state flaggery
src/cmd/ksh93/sh/args.c: sh_argprocsub(): - Save and restore state more efficiently by just saving and restoring all the state bits in one go using the sh_{get,set}state() macros, which are defined in defs.h as: #define sh_getstate() (sh.st.states) #define sh_setstate(x) (sh.st.states = (x)) (and there is yet more evidence that it doesn't matter whether we use a 'shp->' pointer or 'sh.' direct access). src/cmd/ksh93/sh/main.c: exfile(): - Remove a no-op 'sh_offstate(SH_INTERACTIVE);'. It was in the 'else' clause of 'if(sh_isstate(SH_INTERACTIVE))' so if we get there, it is known that this flag is already off. - To properly disable job control, we also have to save and restore the job.jobcontrol variable. src/cmd/ksh93/sh/xec.c: sh_exec(): - Remove some no-op flaggery from this highly performance-sensitive point in the code. Given the immediately preceding: volatile int was_errexit = sh_isstate(SH_ERREXIT); volatile int was_monitor = sh_isstate(SH_MONITOR); the following: sh_offstate(SH_ERREXIT); if(was_errexit&flags) sh_onstate(SH_ERREXIT); can be reformulated as: if(!(flags & sh_state(SH_ERREXIT))) sh_offstate(SH_ERREXIT); (IOW, if it was already on, don't turn it off and then on again) ...and the following: if(was_monitor&flags) sh_onstate(SH_MONITOR); can be removed; it's a no-op because it wasn't preceded by an sh_offstate() and if 'was_monitor' is true, this option is known to be on. (I considered they may have forgotten an 'sh_offstate' there like in the SH_ERREXIT case, but adding that causes several regressions in a shtests run.) src/cmd/ksh93/include/defs.h: - Remove comment that is evidently long outdated; there is not (or no longer) a Shscoped_t type defined anywhere, nor are these struct fields replicated in any other type definition. - Add comment to clarify what the 'states' int in 'struct sh_scoped' is for.
This commit is contained in:
parent
48ba6964ad
commit
79d1945813
4 changed files with 15 additions and 33 deletions
|
@ -71,12 +71,6 @@
|
|||
extern char* sh_getenv(const char*);
|
||||
extern char* sh_setenviron(const char*);
|
||||
|
||||
/*
|
||||
* note that the first few fields have to be the same as for
|
||||
* Shscoped_t in <shell.h>
|
||||
*/
|
||||
|
||||
|
||||
struct sh_scoped
|
||||
{
|
||||
struct sh_scoped *prevst; /* pointer to previous state */
|
||||
|
@ -90,7 +84,7 @@ struct sh_scoped
|
|||
struct sh_scoped *self; /* pointer to copy of this scope*/
|
||||
Dt_t *var_local; /* local level variables for name() */
|
||||
struct slnod *staklist; /* link list of function stacks */
|
||||
int states;
|
||||
int states; /* shell state bits used by sh_isstate(), etc. */
|
||||
int breakcnt;
|
||||
int execbrk;
|
||||
int loopcnt;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "defs.h"
|
||||
#include "path.h"
|
||||
#include "jobs.h"
|
||||
#include "builtins.h"
|
||||
#include "terminal.h"
|
||||
#include "edit.h"
|
||||
|
@ -682,8 +683,10 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp)
|
|||
{
|
||||
/* argument of the form <(cmd) or >(cmd) */
|
||||
register struct argnod *ap;
|
||||
int monitor, interactive, fd, pv[3];
|
||||
int subshell = shp->subshell;
|
||||
int fd, pv[3];
|
||||
int savestates = sh_getstate();
|
||||
char savejobcontrol = job.jobcontrol;
|
||||
unsigned int savesubshell = shp->subshell;
|
||||
ap = (struct argnod*)stkseek(shp->stk,ARGVAL);
|
||||
ap->argflag |= ARG_MAKE;
|
||||
ap->argflag &= ~ARG_RAW;
|
||||
|
@ -708,32 +711,21 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp)
|
|||
sfputr(shp->stk,fmtbase((long)pv[fd],10,0),0);
|
||||
ap = (struct argnod*)stkfreeze(shp->stk,0);
|
||||
shp->inpipe = shp->outpipe = 0;
|
||||
|
||||
/* turn off job control */
|
||||
if(interactive = (sh_isstate(SH_INTERACTIVE)!=0))
|
||||
sh_offstate(SH_INTERACTIVE);
|
||||
if(monitor = (sh_isstate(SH_MONITOR)!=0))
|
||||
sh_offstate(SH_MONITOR);
|
||||
|
||||
sh_offstate(SH_INTERACTIVE);
|
||||
sh_offstate(SH_MONITOR);
|
||||
job.jobcontrol = 0;
|
||||
/* do the process substitution */
|
||||
shp->subshell = 0;
|
||||
if(fd)
|
||||
{
|
||||
shp->inpipe = pv;
|
||||
sh_exec((Shnode_t*)argp->argchn.ap,(int)sh_isstate(SH_ERREXIT));
|
||||
}
|
||||
else
|
||||
{
|
||||
shp->outpipe = pv;
|
||||
sh_exec((Shnode_t*)argp->argchn.ap,(int)sh_isstate(SH_ERREXIT));
|
||||
}
|
||||
|
||||
sh_exec((Shnode_t*)argp->argchn.ap,(int)sh_isstate(SH_ERREXIT));
|
||||
/* restore the previous state */
|
||||
shp->subshell = subshell;
|
||||
if(monitor)
|
||||
sh_onstate(SH_MONITOR);
|
||||
if(interactive)
|
||||
sh_onstate(SH_INTERACTIVE);
|
||||
shp->subshell = savesubshell;
|
||||
job.jobcontrol = savejobcontrol;
|
||||
sh_setstate(savestates);
|
||||
#if SHOPT_DEVFD
|
||||
close(pv[1-fd]);
|
||||
sh_iosave(shp,-pv[fd], shp->topfd, (char*)0);
|
||||
|
|
|
@ -402,7 +402,6 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno)
|
|||
buff.mode = SH_JMPEXIT;
|
||||
sh_onoption(SH_TRACKALL);
|
||||
}
|
||||
sh_offstate(SH_INTERACTIVE);
|
||||
if(sh_isoption(SH_MONITOR))
|
||||
sh_onstate(SH_MONITOR);
|
||||
sh_offstate(SH_HISTORY);
|
||||
|
|
|
@ -980,12 +980,9 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
job.curjobid = 0;
|
||||
flags &= ~sh_state(SH_INTERACTIVE);
|
||||
}
|
||||
sh_offstate(SH_ERREXIT);
|
||||
sh_offstate(SH_DEFPATH);
|
||||
if(was_errexit&flags)
|
||||
sh_onstate(SH_ERREXIT);
|
||||
if(was_monitor&flags)
|
||||
sh_onstate(SH_MONITOR);
|
||||
if(!(flags & sh_state(SH_ERREXIT)))
|
||||
sh_offstate(SH_ERREXIT);
|
||||
type = t->tre.tretyp;
|
||||
shp->exitval=0;
|
||||
shp->lastsig = 0;
|
||||
|
|
Loading…
Reference in a new issue