From 064baa372e6783c25d1c137264d2f0d7ebf45387 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 14 Jul 2022 07:54:53 +0200 Subject: [PATCH] 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. --- .github/workflows/ci.yml | 2 +- src/Mamfile | 1 - src/cmd/INIT/README-mamake.md | 2 +- src/cmd/Mamfile | 1 - src/cmd/ksh93/bltins/cd_pwd.c | 4 ++-- src/cmd/ksh93/bltins/typeset.c | 11 +++-------- src/cmd/ksh93/edit/history.c | 2 +- src/cmd/ksh93/include/defs.h | 2 +- src/cmd/ksh93/include/shell.h | 2 +- src/cmd/ksh93/sh/array.c | 4 ++-- src/cmd/ksh93/sh/fault.c | 2 +- src/cmd/ksh93/sh/macro.c | 2 +- src/cmd/ksh93/sh/main.c | 2 +- src/cmd/ksh93/sh/name.c | 4 ++-- src/cmd/ksh93/sh/parse.c | 4 ++-- src/cmd/ksh93/sh/path.c | 2 +- src/cmd/ksh93/sh/subshell.c | 9 ++++----- src/cmd/ksh93/sh/xec.c | 4 +--- src/cmd/ksh93/tests/variables.sh | 4 ++-- src/lib/Mamfile | 1 - src/lib/libast/features/common | 2 +- src/lib/libast/man/error.3 | 23 +++++++++++++++-------- src/lib/libast/path/pathpath.c | 5 +++-- src/lib/libcmd/wclib.c | 3 +-- 24 files changed, 47 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aebe8e859..aa9531b0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: export TZ=UTC ulimit -n 1024 : default regression tests && - script -q -e -c "bin/shtests" && + script -q -e -c "bin/package test" && : regression tests with OS-provided multibyte locales && 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" && diff --git a/src/Mamfile b/src/Mamfile index fd4afedca..24e5bcaa3 100644 --- a/src/Mamfile +++ b/src/Mamfile @@ -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 * src/cmd/INIT/README-mamake.md. note * -note source level :MAKE: equivalent make test make install make all diff --git a/src/cmd/INIT/README-mamake.md b/src/cmd/INIT/README-mamake.md index b69488f6c..5f9751538 100644 --- a/src/cmd/INIT/README-mamake.md +++ b/src/cmd/INIT/README-mamake.md @@ -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. * Fixed some crashing bugs and memory leaks. -### Comments and unrecognized commands ### +## Commands ## MAM commands have the following basic form: diff --git a/src/cmd/Mamfile b/src/cmd/Mamfile index 1675273fc..17a6e7357 100644 --- a/src/cmd/Mamfile +++ b/src/cmd/Mamfile @@ -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 * src/cmd/INIT/README-mamake.md. note * -note component level :MAKE: equivalent make test make install make all diff --git a/src/cmd/ksh93/bltins/cd_pwd.c b/src/cmd/ksh93/bltins/cd_pwd.c index 8dc2fdad6..f0a1d2fc7 100644 --- a/src/cmd/ksh93/bltins/cd_pwd.c +++ b/src/cmd/ksh93/bltins/cd_pwd.c @@ -104,8 +104,8 @@ int b_cd(int argc, char *argv[],Shbltin_t *context) if(sh.subshell) { /* clone $OLDPWD and $PWD into the subshell's scope */ - opwdnod = sh_assignok(opwdnod,1); - pwdnod = sh_assignok(pwdnod,1); + sh_assignok(opwdnod,1); + sh_assignok(pwdnod,1); } if(argc==2) dir = sh_substitute(oldpwd,dir,argv[1]); diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index f144c3069..82d8894b4 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -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)) 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 - np=sh_assignok(np,0); + sh_assignok(np, !nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np)); } if(iarray) { @@ -939,7 +937,7 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp if(np==SH_LEVELNOD) return(r); if(sh.subshell) - sh_assignok(np,2); + sh_assignok(np,1); if(troot!=sh.var_tree) nv_setattr(np,newflag&~NV_ASSIGN); 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 * (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)) - np=sh_assignok(np,2); - else - np=sh_assignok(np,0); + sh_assignok(np, !nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np)); } } /* diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index b53fe4067..3462ce35e 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * 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 * * and is licensed under the * * Eclipse Public License, Version 1.0 * diff --git a/src/cmd/ksh93/include/defs.h b/src/cmd/ksh93/include/defs.h index 1d9c44844..5c3e97021 100644 --- a/src/cmd/ksh93/include/defs.h +++ b/src/cmd/ksh93/include/defs.h @@ -112,7 +112,7 @@ extern struct dolnod *sh_argnew(char*[],struct dolnod**); extern void *sh_argopen(void); extern struct argnod *sh_argprocsub(struct argnod*); 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 char *sh_checkid(char*,char*); extern void sh_chktrap(void); diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index 4ec58f353..f409b16d3 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -277,7 +277,7 @@ struct Shell_s Sfio_t *heredocs; /* current here-doc temp file */ Sfio_t *funlog; /* for logging function definitions */ int **fdptrs; /* pointer to file numbers */ - char *lastarg; + char *lastarg; /* $_ */ int path_err; /* last error on path search */ Dt_t *var_base; /* global level variables */ Dt_t *fun_base; /* global level functions */ diff --git a/src/cmd/ksh93/sh/array.c b/src/cmd/ksh93/sh/array.c index bf2e84387..4705ff7d8 100644 --- a/src/cmd/ksh93/sh/array.c +++ b/src/cmd/ksh93/sh/array.c @@ -1198,7 +1198,7 @@ Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode) if(size==0 && !(mode&ARRAY_FILL)) return(NIL(Namval_t*)); if(sh.subshell) - np = sh_assignok(np,1); + sh_assignok(np,1); ap = array_grow(np, ap,size); } 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) { if(sh.subshell) - np = sh_assignok(np,1); + sh_assignok(np,1); if(ap->header.nelem&ARRAY_TREE) { char *cp; diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 5c46187fe..ab2f56d54 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -123,7 +123,7 @@ void sh_fault(register int sig) if(flag&SH_SIGDONE) { 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 */ if(sig==SIGTERM && job.in_critical) diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index c1dc903d3..f164c8e24 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -2014,7 +2014,7 @@ retry2: if(np) { if(sh.subshell) - np = sh_assignok(np,1); + sh_assignok(np,1); nv_putval(np,argp,0); v = nv_getval(np); nulflg = 0; diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index c8b2d7439..f944a5fbe 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -536,7 +536,7 @@ static void exfile(register Sfio_t *iop,register int fno) { buff.mode = SH_JMPERREXIT; #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 } } diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index fe711bfe3..6d0651464 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -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 */ sh.argaddr = 0; 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 */ if(sh_isoption(SH_ALLEXPORT)) { @@ -2492,7 +2492,7 @@ void _nv_unset(register Namval_t *np,int flags) goto done; } if(sh.subshell) - np = sh_assignok(np,0); + sh_assignok(np,0); nv_offattr(np,NV_NODISC); if(np->nvfun && !nv_isref(np)) { diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index af73da062..da9daf7d5 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -1581,7 +1581,7 @@ static Shnode_t *simple(Lex_t *lexp,int flag, struct ionod *io) type = NV_ARRAY; if(tok==LABLSYM && (flag&SH_ASSIGN)) lexp->token = tok = 0; - if((tok==IPROCSYM || tok==OPROCSYM)) + if(tok==IPROCSYM || tok==OPROCSYM) { procsub: 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 only one redirection will be processed */ diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 6ec3822f4..121e880dd 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -236,7 +236,7 @@ char *path_pwd(void) if(cp) { if(sh.subshell) - pwdnod = sh_assignok(pwdnod,1); + sh_assignok(pwdnod,1); nv_putval(pwdnod,cp,NV_RDONLY); } } diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index 6517ab32b..ff38d12ab 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -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 == 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 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. */ if(subshell_noscope || sh.subshare || np==SH_LEVELNOD) - return(np); + return; if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np))) { sh.last_root = ap->table; sh_assignok(mp,add); if(!add || array_assoc(ap)) - return(np); + return; } for(lp=sp->svar; lp;lp = lp->next) { if(lp->node==np) - return(np); + return; } /* first two pointers use linkage from np */ 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_clone(np,mp,(add?(nv_isnull(np)?0:NV_NOFREE)|NV_ARRAY:NV_MOVE)); sh.subshell = save; - return(np); } /* diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index e67b9bcc1..412f26a2e 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -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) { - Stk_t *stkp = sh.stk; sh_sigcheck(); if(t && sh.st.breakcnt==0 && !sh_isoption(SH_NOEXEC)) { + Stk_t *stkp = sh.stk; register int type = t->tre.tretyp; register char *com0 = 0; 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); jobwasset++; } -#endif /* _use_ntfork_tcpgrp */ -#if _use_ntfork_tcpgrp if(sh_isstate(SH_MONITOR) && job.jobcontrol) { if(job.curpgid==0) diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index f208d296e..cfd6f5167 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -36,7 +36,7 @@ fi # use the same pseudorandom seed as the main shell. # https://github.com/ksh93/ksh/issues/285 # 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 function rand_print { ulimit -t unlimited 2> /dev/null @@ -81,7 +81,7 @@ do ( echo $RANDOM & ) >|r1 do ((giveup)) && break done 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 kill $! 2>/dev/null trap - USR1 diff --git a/src/lib/Mamfile b/src/lib/Mamfile index 1675273fc..17a6e7357 100644 --- a/src/lib/Mamfile +++ b/src/lib/Mamfile @@ -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 * src/cmd/INIT/README-mamake.md. note * -note component level :MAKE: equivalent make test make install make all diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index 693bfb9e8..cbe539476 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -25,10 +25,10 @@ tst ptr_void note{ standard C void* ok }end compile{ cat{ #pragma clang diagnostic ignored "-Wdeprecated-register" - #pragma clang diagnostic ignored "-Wmacro-redefined" #pragma clang diagnostic ignored "-Wparentheses" #pragma clang diagnostic ignored "-Wstring-plus-int" #pragma clang diagnostic ignored "-Wunused-value" + #pragma GCC diagnostic ignored "-Wunused-result" /* AST backwards compatibility macros */ #undef _NIL_ diff --git a/src/lib/libast/man/error.3 b/src/lib/libast/man/error.3 index 6a7f8cd87..a2a365df6 100644 --- a/src/lib/libast/man/error.3 +++ b/src/lib/libast/man/error.3 @@ -242,19 +242,26 @@ ERROR_OPTIONS="system" provides debugging message macros when .L DEBUG or -.L _TRACE_ +.L _BLD_DEBUG are defined -.RL ( _TRACE_ +.RL ( _BLD_DEBUG is defined by -.I makerules -when -.L CCFLAGS -contains -.LR \-g ). +the +.IR Mamfile s +when the +.L \-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 .L DEBUG and -.L _TRACE_ +.L _BLD_DEBUG are not defined. Otherwise .L debug diff --git a/src/lib/libast/path/pathpath.c b/src/lib/libast/path/pathpath.c index e5a185db6..b3fb083a4 100644 --- a/src/lib/libast/path/pathpath.c +++ b/src/lib/libast/path/pathpath.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * 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 * * Eclipse Public License, Version 1.0 * * 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)) { - getcwd(buf, sizeof(buf)); + if(!getcwd(buf, sizeof(buf))) + return (char*)0; s = buf + strlen(buf); sfsprintf(s, sizeof(buf) - (s - buf), "/%s", p); if (path != buf) diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index 293834118..91a357bee 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * 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 * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -52,7 +52,6 @@ #define eol(c) ((c)&WC_NL) #define mbc(c) ((c)&WC_MB) #define spc(c) ((c)&WC_SP) -#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n) Wc_t* wc_init(int mode) {