1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

More misc. tweaks and cleanups

Notable changes:

.github/workflows/ci.yml:
- Run 'bin/package test' on the github runner so we test iffe too.

src/cmd/ksh93/sh/subshell.c:
- sh_assignok was usually called like 'np = sh_assignok(np,0)'. But
  the function never changes np, it just returns the np value
  passed to it, so the assignment is pointless and that function
  can be changed to a void.

src/cmd/ksh93/sh/fault.c: sh_fault():
- Remove check for sh.subshell after sh_isstate(SH_INTERACTIVE). As
  of 48ba6964, it is never set in subshells.
This commit is contained in:
Martijn Dekker 2022-07-14 07:54:53 +02:00
parent adc6a64b82
commit 064baa372e
24 changed files with 47 additions and 51 deletions

View file

@ -19,7 +19,7 @@ jobs:
export TZ=UTC export TZ=UTC
ulimit -n 1024 ulimit -n 1024
: default regression tests && : default regression tests &&
script -q -e -c "bin/shtests" && script -q -e -c "bin/package test" &&
: regression tests with OS-provided multibyte locales && : regression tests with OS-provided multibyte locales &&
LANG=nl_NL.UTF-8 script -q -e -c "bin/shtests --locale --nocompile" && LANG=nl_NL.UTF-8 script -q -e -c "bin/shtests --locale --nocompile" &&
LANG=ja_JP.SJIS script -q -e -c "bin/shtests --locale --nocompile" && LANG=ja_JP.SJIS script -q -e -c "bin/shtests --locale --nocompile" &&

View file

@ -6,7 +6,6 @@ note * Mamfiles are processed by mamake (src/cmd/INIT/mamake.c); we added
note * indentation to improve readability. The language is documented in note * indentation to improve readability. The language is documented in
note * src/cmd/INIT/README-mamake.md. note * src/cmd/INIT/README-mamake.md.
note * note *
note source level :MAKE: equivalent
make test make test
make install make install
make all make all

View file

@ -32,7 +32,7 @@ ksh 93u+m made a few minor changes to `mamake` that make it easier to maintain M
* Unrecognized commands and rule attributes throw an error instead of being silently ignored. * Unrecognized commands and rule attributes throw an error instead of being silently ignored.
* Fixed some crashing bugs and memory leaks. * Fixed some crashing bugs and memory leaks.
### Comments and unrecognized commands ### ## Commands ##
MAM commands have the following basic form: MAM commands have the following basic form:

View file

@ -6,7 +6,6 @@ note * Mamfiles are processed by mamake (src/cmd/INIT/mamake.c); we added
note * indentation to improve readability. The language is documented in note * indentation to improve readability. The language is documented in
note * src/cmd/INIT/README-mamake.md. note * src/cmd/INIT/README-mamake.md.
note * note *
note component level :MAKE: equivalent
make test make test
make install make install
make all make all

View file

@ -104,8 +104,8 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
if(sh.subshell) if(sh.subshell)
{ {
/* clone $OLDPWD and $PWD into the subshell's scope */ /* clone $OLDPWD and $PWD into the subshell's scope */
opwdnod = sh_assignok(opwdnod,1); sh_assignok(opwdnod,1);
pwdnod = sh_assignok(pwdnod,1); sh_assignok(pwdnod,1);
} }
if(argc==2) if(argc==2)
dir = sh_substitute(oldpwd,dir,argv[1]); dir = sh_substitute(oldpwd,dir,argv[1]);

View file

@ -832,10 +832,8 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
*/ */
if((flag&NV_ARRAY) && !sh.envlist && !nv_isnull(np)) if((flag&NV_ARRAY) && !sh.envlist && !nv_isnull(np))
sh_subfork(); /* work around https://github.com/ksh93/ksh/issues/409 */ sh_subfork(); /* work around https://github.com/ksh93/ksh/issues/409 */
else if(!nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np))
np=sh_assignok(np,2);
else else
np=sh_assignok(np,0); sh_assignok(np, !nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np));
} }
if(iarray) if(iarray)
{ {
@ -939,7 +937,7 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
if(np==SH_LEVELNOD) if(np==SH_LEVELNOD)
return(r); return(r);
if(sh.subshell) if(sh.subshell)
sh_assignok(np,2); sh_assignok(np,1);
if(troot!=sh.var_tree) if(troot!=sh.var_tree)
nv_setattr(np,newflag&~NV_ASSIGN); nv_setattr(np,newflag&~NV_ASSIGN);
else else
@ -1390,10 +1388,7 @@ static int unall(int argc, char **argv, register Dt_t *troot)
* Create local scope for virtual subshell. Variables with discipline functions * Create local scope for virtual subshell. Variables with discipline functions
* (LC_*, LINENO, etc.) need to be cloned, as moving them will remove the discipline. * (LC_*, LINENO, etc.) need to be cloned, as moving them will remove the discipline.
*/ */
if(!nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np)) sh_assignok(np, !nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np));
np=sh_assignok(np,2);
else
np=sh_assignok(np,0);
} }
} }
/* /*

View file

@ -1,7 +1,7 @@
/*********************************************************************** /***********************************************************************
* * * *
* This software is part of the ast package * * This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property * * Copyright (c) 1982-2014 AT&T Intellectual Property *
* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the * * and is licensed under the *
* Eclipse Public License, Version 1.0 * * Eclipse Public License, Version 1.0 *

View file

@ -112,7 +112,7 @@ extern struct dolnod *sh_argnew(char*[],struct dolnod**);
extern void *sh_argopen(void); extern void *sh_argopen(void);
extern struct argnod *sh_argprocsub(struct argnod*); extern struct argnod *sh_argprocsub(struct argnod*);
extern void sh_argreset(struct dolnod*,struct dolnod*); extern void sh_argreset(struct dolnod*,struct dolnod*);
extern Namval_t *sh_assignok(Namval_t*,int); extern void sh_assignok(Namval_t*,int);
extern struct dolnod *sh_arguse(void); extern struct dolnod *sh_arguse(void);
extern char *sh_checkid(char*,char*); extern char *sh_checkid(char*,char*);
extern void sh_chktrap(void); extern void sh_chktrap(void);

View file

@ -277,7 +277,7 @@ struct Shell_s
Sfio_t *heredocs; /* current here-doc temp file */ Sfio_t *heredocs; /* current here-doc temp file */
Sfio_t *funlog; /* for logging function definitions */ Sfio_t *funlog; /* for logging function definitions */
int **fdptrs; /* pointer to file numbers */ int **fdptrs; /* pointer to file numbers */
char *lastarg; char *lastarg; /* $_ */
int path_err; /* last error on path search */ int path_err; /* last error on path search */
Dt_t *var_base; /* global level variables */ Dt_t *var_base; /* global level variables */
Dt_t *fun_base; /* global level functions */ Dt_t *fun_base; /* global level functions */

View file

@ -1198,7 +1198,7 @@ Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode)
if(size==0 && !(mode&ARRAY_FILL)) if(size==0 && !(mode&ARRAY_FILL))
return(NIL(Namval_t*)); return(NIL(Namval_t*));
if(sh.subshell) if(sh.subshell)
np = sh_assignok(np,1); sh_assignok(np,1);
ap = array_grow(np, ap,size); ap = array_grow(np, ap,size);
} }
ap->header.nelem &= ~ARRAY_UNDEF; ap->header.nelem &= ~ARRAY_UNDEF;
@ -1232,7 +1232,7 @@ Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode)
else if(!(sp=(char*)ap->val[size].cp) || sp==Empty) else if(!(sp=(char*)ap->val[size].cp) || sp==Empty)
{ {
if(sh.subshell) if(sh.subshell)
np = sh_assignok(np,1); sh_assignok(np,1);
if(ap->header.nelem&ARRAY_TREE) if(ap->header.nelem&ARRAY_TREE)
{ {
char *cp; char *cp;

View file

@ -123,7 +123,7 @@ void sh_fault(register int sig)
if(flag&SH_SIGDONE) if(flag&SH_SIGDONE)
{ {
void *ptr=0; void *ptr=0;
if((flag&SH_SIGINTERACTIVE) && sh_isstate(SH_INTERACTIVE) && !sh_isstate(SH_FORKED) && ! sh.subshell) if((flag&SH_SIGINTERACTIVE) && sh_isstate(SH_INTERACTIVE) && !sh_isstate(SH_FORKED))
{ {
/* check for TERM signal between fork/exec */ /* check for TERM signal between fork/exec */
if(sig==SIGTERM && job.in_critical) if(sig==SIGTERM && job.in_critical)

View file

@ -2014,7 +2014,7 @@ retry2:
if(np) if(np)
{ {
if(sh.subshell) if(sh.subshell)
np = sh_assignok(np,1); sh_assignok(np,1);
nv_putval(np,argp,0); nv_putval(np,argp,0);
v = nv_getval(np); v = nv_getval(np);
nulflg = 0; nulflg = 0;

View file

@ -536,7 +536,7 @@ static void exfile(register Sfio_t *iop,register int fno)
{ {
buff.mode = SH_JMPERREXIT; buff.mode = SH_JMPERREXIT;
#ifdef DEBUG #ifdef DEBUG
errormsg(SH_DICT,ERROR_warn(0),"%d: mode changed to JMP_EXIT",sh.current_pid); errormsg(SH_DICT,ERROR_warn(0),"%d: mode changed to SH_JMPERREXIT",sh.current_pid);
#endif #endif
} }
} }

View file

@ -1592,7 +1592,7 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
/* Create a local scope when inside of a virtual subshell */ /* Create a local scope when inside of a virtual subshell */
sh.argaddr = 0; sh.argaddr = 0;
if(sh.subshell && !nv_local && !(flags&NV_RDONLY)) if(sh.subshell && !nv_local && !(flags&NV_RDONLY))
np = sh_assignok(np,1); sh_assignok(np,1);
/* Export the variable if 'set -o allexport' is enabled */ /* Export the variable if 'set -o allexport' is enabled */
if(sh_isoption(SH_ALLEXPORT)) if(sh_isoption(SH_ALLEXPORT))
{ {
@ -2492,7 +2492,7 @@ void _nv_unset(register Namval_t *np,int flags)
goto done; goto done;
} }
if(sh.subshell) if(sh.subshell)
np = sh_assignok(np,0); sh_assignok(np,0);
nv_offattr(np,NV_NODISC); nv_offattr(np,NV_NODISC);
if(np->nvfun && !nv_isref(np)) if(np->nvfun && !nv_isref(np))
{ {

View file

@ -1581,7 +1581,7 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io)
type = NV_ARRAY; type = NV_ARRAY;
if(tok==LABLSYM && (flag&SH_ASSIGN)) if(tok==LABLSYM && (flag&SH_ASSIGN))
lexp->token = tok = 0; lexp->token = tok = 0;
if((tok==IPROCSYM || tok==OPROCSYM)) if(tok==IPROCSYM || tok==OPROCSYM)
{ {
procsub: procsub:
argp = process_sub(lexp,tok); argp = process_sub(lexp,tok);
@ -1745,7 +1745,7 @@ static int skipnl(Lex_t *lexp,int flag)
} }
/* /*
* check for and process and i/o redirections * check for and process I/O redirections
* if flag>0 then an alias can be in the next word * if flag>0 then an alias can be in the next word
* if flag<0 only one redirection will be processed * if flag<0 only one redirection will be processed
*/ */

View file

@ -236,7 +236,7 @@ char *path_pwd(void)
if(cp) if(cp)
{ {
if(sh.subshell) if(sh.subshell)
pwdnod = sh_assignok(pwdnod,1); sh_assignok(pwdnod,1);
nv_putval(pwdnod,cp,NV_RDONLY); nv_putval(pwdnod,cp,NV_RDONLY);
} }
} }

View file

@ -261,7 +261,7 @@ void sh_save_rand_seed(struct rand *rp, int reseed)
* add == 0: Move the node pointer from the parent shell to the current virtual subshell. * add == 0: Move the node pointer from the parent shell to the current virtual subshell.
* add == 1: Create a copy of the node pointer in the current virtual subshell. * add == 1: Create a copy of the node pointer in the current virtual subshell.
*/ */
Namval_t *sh_assignok(register Namval_t *np,int add) void sh_assignok(Namval_t *np,int add)
{ {
register Namval_t *mp; register Namval_t *mp;
register struct Link *lp; register struct Link *lp;
@ -275,18 +275,18 @@ Namval_t *sh_assignok(register Namval_t *np,int add)
* Also, ${.sh.level} (SH_LEVELNOD) is handled specially and is not scoped in virtual subshells. * Also, ${.sh.level} (SH_LEVELNOD) is handled specially and is not scoped in virtual subshells.
*/ */
if(subshell_noscope || sh.subshare || np==SH_LEVELNOD) if(subshell_noscope || sh.subshare || np==SH_LEVELNOD)
return(np); return;
if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np))) if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
{ {
sh.last_root = ap->table; sh.last_root = ap->table;
sh_assignok(mp,add); sh_assignok(mp,add);
if(!add || array_assoc(ap)) if(!add || array_assoc(ap))
return(np); return;
} }
for(lp=sp->svar; lp;lp = lp->next) for(lp=sp->svar; lp;lp = lp->next)
{ {
if(lp->node==np) if(lp->node==np)
return(np); return;
} }
/* first two pointers use linkage from np */ /* first two pointers use linkage from np */
lp = (struct Link*)sh_malloc(sizeof(*np)+2*sizeof(void*)); lp = (struct Link*)sh_malloc(sizeof(*np)+2*sizeof(void*));
@ -323,7 +323,6 @@ Namval_t *sh_assignok(register Namval_t *np,int add)
nv_onattr(mp,NV_IDENT); nv_onattr(mp,NV_IDENT);
nv_clone(np,mp,(add?(nv_isnull(np)?0:NV_NOFREE)|NV_ARRAY:NV_MOVE)); nv_clone(np,mp,(add?(nv_isnull(np)?0:NV_NOFREE)|NV_ARRAY:NV_MOVE));
sh.subshell = save; sh.subshell = save;
return(np);
} }
/* /*

View file

@ -893,10 +893,10 @@ static int check_exec_optimization(int type, int execflg, int execflg2, struct i
*/ */
int sh_exec(register const Shnode_t *t, int flags) int sh_exec(register const Shnode_t *t, int flags)
{ {
Stk_t *stkp = sh.stk;
sh_sigcheck(); sh_sigcheck();
if(t && sh.st.breakcnt==0 && !sh_isoption(SH_NOEXEC)) if(t && sh.st.breakcnt==0 && !sh_isoption(SH_NOEXEC))
{ {
Stk_t *stkp = sh.stk;
register int type = t->tre.tretyp; register int type = t->tre.tretyp;
register char *com0 = 0; register char *com0 = 0;
int errorflg = (flags&sh_state(SH_ERREXIT))|OPTIMIZE; int errorflg = (flags&sh_state(SH_ERREXIT))|OPTIMIZE;
@ -3463,8 +3463,6 @@ static pid_t sh_ntfork(const Shnode_t *t,char *argv[],int *jobid)
signal(SIGTSTP,SIG_DFL); signal(SIGTSTP,SIG_DFL);
jobwasset++; jobwasset++;
} }
#endif /* _use_ntfork_tcpgrp */
#if _use_ntfork_tcpgrp
if(sh_isstate(SH_MONITOR) && job.jobcontrol) if(sh_isstate(SH_MONITOR) && job.jobcontrol)
{ {
if(job.curpgid==0) if(job.curpgid==0)

View file

@ -36,7 +36,7 @@ fi
# use the same pseudorandom seed as the main shell. # use the same pseudorandom seed as the main shell.
# https://github.com/ksh93/ksh/issues/285 # https://github.com/ksh93/ksh/issues/285
# These tests sometimes fail as duplicate numbers can occur randomly, so try up to $N times. # These tests sometimes fail as duplicate numbers can occur randomly, so try up to $N times.
integer N=3 i rand1 rand2 integer N=5 i rand1 rand2
RANDOM=123 RANDOM=123
function rand_print { function rand_print {
ulimit -t unlimited 2> /dev/null ulimit -t unlimited 2> /dev/null
@ -81,7 +81,7 @@ do ( echo $RANDOM & ) >|r1
do ((giveup)) && break do ((giveup)) && break
done done
if ((giveup)) if ((giveup))
then err_exit "Test 4: ( echo $RANDOM & ) does not write output" then err_exit 'Test 4: ( echo $RANDOM & ) does not write output'
fi fi
kill $! 2>/dev/null kill $! 2>/dev/null
trap - USR1 trap - USR1

View file

@ -6,7 +6,6 @@ note * Mamfiles are processed by mamake (src/cmd/INIT/mamake.c); we added
note * indentation to improve readability. The language is documented in note * indentation to improve readability. The language is documented in
note * src/cmd/INIT/README-mamake.md. note * src/cmd/INIT/README-mamake.md.
note * note *
note component level :MAKE: equivalent
make test make test
make install make install
make all make all

View file

@ -25,10 +25,10 @@ tst ptr_void note{ standard C void* ok }end compile{
cat{ cat{
#pragma clang diagnostic ignored "-Wdeprecated-register" #pragma clang diagnostic ignored "-Wdeprecated-register"
#pragma clang diagnostic ignored "-Wmacro-redefined"
#pragma clang diagnostic ignored "-Wparentheses" #pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wstring-plus-int" #pragma clang diagnostic ignored "-Wstring-plus-int"
#pragma clang diagnostic ignored "-Wunused-value" #pragma clang diagnostic ignored "-Wunused-value"
#pragma GCC diagnostic ignored "-Wunused-result"
/* AST backwards compatibility macros */ /* AST backwards compatibility macros */
#undef _NIL_ #undef _NIL_

View file

@ -242,19 +242,26 @@ ERROR_OPTIONS="system"
provides debugging message macros when provides debugging message macros when
.L DEBUG .L DEBUG
or or
.L _TRACE_ .L _BLD_DEBUG
are defined are defined
.RL ( _TRACE_ .RL ( _BLD_DEBUG
is defined by is defined by
.I makerules the
when .IR Mamfile s
.L CCFLAGS when the
contains .L \-G
.LR \-g ). a.k.a.
.L \-\-debug\-symbols
option is passed to
.BR mamake (1),
which the
.BR package (1)
command does automatically when given the argument
.LR debug=1 ).
All of the macros expand to nothing when both All of the macros expand to nothing when both
.L DEBUG .L DEBUG
and and
.L _TRACE_ .L _BLD_DEBUG
are not defined. are not defined.
Otherwise Otherwise
.L debug .L debug

View file

@ -2,7 +2,7 @@
* * * *
* This software is part of the ast package * * This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property * * Copyright (c) 1985-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m * * Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the * * and is licensed under the *
* Eclipse Public License, Version 1.0 * * Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property * * by AT&T Intellectual Property *
@ -76,7 +76,8 @@ pathpath_20100601(const char* p, const char* a, int mode, register char* path, s
{ {
if (*p != '/' && (mode & PATH_ABSOLUTE)) if (*p != '/' && (mode & PATH_ABSOLUTE))
{ {
getcwd(buf, sizeof(buf)); if(!getcwd(buf, sizeof(buf)))
return (char*)0;
s = buf + strlen(buf); s = buf + strlen(buf);
sfsprintf(s, sizeof(buf) - (s - buf), "/%s", p); sfsprintf(s, sizeof(buf) - (s - buf), "/%s", p);
if (path != buf) if (path != buf)

View file

@ -2,7 +2,7 @@
* * * *
* This software is part of the ast package * * This software is part of the ast package *
* Copyright (c) 1992-2011 AT&T Intellectual Property * * Copyright (c) 1992-2011 AT&T Intellectual Property *
* Copyright (c) 2020-2021 Contributors to ksh 93u+m * * Copyright (c) 2020-2022 Contributors to ksh 93u+m *
* and is licensed under the * * and is licensed under the *
* Eclipse Public License, Version 1.0 * * Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property * * by AT&T Intellectual Property *
@ -52,7 +52,6 @@
#define eol(c) ((c)&WC_NL) #define eol(c) ((c)&WC_NL)
#define mbc(c) ((c)&WC_MB) #define mbc(c) ((c)&WC_MB)
#define spc(c) ((c)&WC_SP) #define spc(c) ((c)&WC_SP)
#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n)
Wc_t* wc_init(int mode) Wc_t* wc_init(int mode)
{ {