From 03ace3354a9a0c048a39954ff800f0d30d4bc7f5 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 24 Nov 2024 23:12:54 +0000 Subject: [PATCH] next rounnd of minor cleanups Notable changes: src/cmd/ksh93/sh/xec.c, src/cmd/ksh93/bltins/misc.c: - Tweak scoping/usage of pointers to sh.bltindata ('bp'/'context'). - In xec.c, eliminate one test for non-NULL 'bp' as it is known to point to sh.bltindata. src/cmd/ksh93/sh/macro.c: tilde_expand2(): - Simplify pointer to tilde string. (re: 936a1939) src/cmd/ksh93/sh.1: - Clarify that 'VAR=foo somefunction' will not export VAR to the environment if foo is a POSIX-syntax function. --- src/cmd/ksh93/RELEASE | 2 +- src/cmd/ksh93/bltins/misc.c | 3 +-- src/cmd/ksh93/bltins/sleep.c | 2 +- src/cmd/ksh93/features/externs | 2 +- src/cmd/ksh93/sh.1 | 6 ++++-- src/cmd/ksh93/sh/macro.c | 6 +++--- src/cmd/ksh93/sh/xec.c | 12 ++++-------- src/lib/libast/man/stk.3 | 8 ++++---- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/cmd/ksh93/RELEASE b/src/cmd/ksh93/RELEASE index 210ed3c7641b..bab8c127dc78 100644 --- a/src/cmd/ksh93/RELEASE +++ b/src/cmd/ksh93/RELEASE @@ -786,7 +786,7 @@ ____ are treated as a shell pattern and cause matching lines from the history file to be displayed as a numbered list as you type. You can scroll up and down this list or you can use nTAB - to make this the current line (n defaults to 1 of omitted) or + to make this the current line (n defaults to 1 if omitted) or n to execute. 10-05-20 A bug which caused an exception when multiple levels of composite functions in arithmetic expressions has been fixed. diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index 9dd404380c8e..96282f42c97b 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -239,7 +239,6 @@ int b_dot_cmd(int n,char *argv[],Shbltin_t *context) volatile struct dolnod *argsave=0; struct checkpt buff; Sfio_t *iop=0; - NOT_USED(context); while (n = optget(argv,sh_optdot)) switch (n) { case ':': @@ -265,7 +264,7 @@ int b_dot_cmd(int n,char *argv[],Shbltin_t *context) { /* check for KornShell style function first */ np = nv_search(script,sh.fun_tree,0); - if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX) && !(sh_isoption(SH_POSIX) && sh.bltindata.bnode==SYSDOT)) + if(np && is_afunction(np) && !nv_isattr(np,NV_FPOSIX) && !(sh_isoption(SH_POSIX) && context->bnode==SYSDOT)) { if(!np->nvalue.ip) { diff --git a/src/cmd/ksh93/bltins/sleep.c b/src/cmd/ksh93/bltins/sleep.c index da86e3fc3b5d..6017119e6dae 100644 --- a/src/cmd/ksh93/bltins/sleep.c +++ b/src/cmd/ksh93/bltins/sleep.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * diff --git a/src/cmd/ksh93/features/externs b/src/cmd/ksh93/features/externs index 717393646e2d..55cf991995a5 100644 --- a/src/cmd/ksh93/features/externs +++ b/src/cmd/ksh93/features/externs @@ -188,7 +188,7 @@ tst note{ determining size of PID variables }end output{ exit 1 }end -# execve(3) breakage on Android/Termux (as of API 36) +# execve(3) breakage on Android/Termux (as of API 35) tst execve_ignores_argv0 note{ does execve(3) ignore the specified argv[0] }end output{ #include #include diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 99e36c1c2891..04dc738e9cc4 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -3999,8 +3999,10 @@ or commands. .PP The environment for any -.I simple-command\^ -or function +.IR simple-command\^ , +except calls of functions declared with the +.IB name (\^) +syntax, may be augmented by prefixing it with one or more variable assignments. A variable assignment argument is a word of the form .IR identifier=value . diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index 4164a9f52deb..d065416eab96 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -2708,7 +2708,7 @@ static int charlen(const char *string,int len) static void tilde_expand2(int offset) { char *cp = NULL; /* character pointer for tilde expansion result */ - char *stakp = stkptr(sh.stk,0); /* current stack object (&stakp[offset] is tilde string) */ + char *tp = stkptr(sh.stk,offset); /* pointer to tilde string */ int curoff = stktell(sh.stk); /* current offset of current stack object */ sfputc(sh.stk,0); /* terminate current stack object to avoid data corruption */ /* @@ -2717,7 +2717,7 @@ static void tilde_expand2(int offset) if(!sh.tilde_block && SH_TILDENOD->nvfun && SH_TILDENOD->nvfun->disc) { sh.tilde_block = 1; - nv_putval(SH_TILDENOD, &stakp[offset], 0); + nv_putval(SH_TILDENOD, tp, 0); cp = nv_getval(SH_TILDENOD); sh.tilde_block = 0; if(cp[0]=='\0' || cp[0]=='~') @@ -2728,7 +2728,7 @@ static void tilde_expand2(int offset) * Write the result to the stack, if any. */ if(!cp) - cp = sh_tilde(&stakp[offset]); + cp = sh_tilde(tp); if(cp) { stkseek(sh.stk,offset); diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 680fb47e303b..3756273c81cf 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1102,7 +1102,6 @@ int sh_exec(const Shnode_t *t, int flags) sh.last_table = 0; if(io || argn) { - Shbltin_t *bp=0; static char *argv[2]; int tflags = 1; if(np && nv_isattr(np,BLT_DCL)) @@ -1196,13 +1195,13 @@ int sh_exec(const Shnode_t *t, int flags) volatile void *save_data; int save_prompt; struct checkpt *buffp; + Shbltin_t *bp = &sh.bltindata; /* Fallback optimization for ':'/'true' and 'false' */ if(!io && !argp && (funptr(np)==b_true || funptr(np)==b_false && ++sh.exitval)) goto setexit; scope = 0, share = 0; was_mktype = sh.mktype!=NULL; was_nofork = execflg && sh_isstate(SH_NOFORK); - bp = &sh.bltindata; save_ptr = bp->ptr; save_data = bp->data; if(execflg) @@ -1301,12 +1300,9 @@ int sh_exec(const Shnode_t *t, int flags) fifo_cleanup(); #endif } - if(bp) - { - bp->bnode = 0; - if( bp->ptr!= nv_context(np)) - np->nvfun = (Namfun_t*)bp->ptr; - } + bp->bnode = 0; + if(bp->ptr != nv_context(np)) + np->nvfun = bp->ptr; if(execflg && !was_nofork) sh_offstate(SH_NOFORK); if(!(nv_isattr(np,BLT_ENV))) diff --git a/src/lib/libast/man/stk.3 b/src/lib/libast/man/stk.3 index 2a88017de324..9c9e21abd3ce 100644 --- a/src/lib/libast/man/stk.3 +++ b/src/lib/libast/man/stk.3 @@ -106,14 +106,14 @@ is deprecated and provided for backward compatibility. and returns a pointer to the previous \f3stkstd\fP stack. If the \fIoverflow\fP argument is not null and the stack was not opened with the \f3STK_NULL\fP option, then \fIoverflow\fP sets the overflow action -(see \f3overflow\fP() above). +(see \f3stkoverflow\fP() above). When \fIstack\fP is a null pointer, the \f3stkstd\fP stack is not changed but the \fIoverflow\fP function for the \f3stkstd\fP stack can be changed and a pointer to the \f3stkstd\fP stack is returned. -(Current usage is simply -passing the pointer to the desired stack to the \f3stk\fP functions, -and using \f3stkoverflow\fP() to set the stack overflow function). +(To replace deprecated \f3stkinstall\fP() usage, simply +pass the pointer to the desired stack to the \f3stk\fP functions, +and use \f3stkoverflow\fP() to set the stack overflow function). .PP The \f3stkclose\fP() function decrements the reference count and frees the memory associated with