Skip to content

Commit

Permalink
next rounnd of minor cleanups
Browse files Browse the repository at this point in the history
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: 936a193)

src/cmd/ksh93/sh.1:
- Clarify that 'VAR=foo somefunction' will not export VAR to the
  environment if foo is a POSIX-syntax function.
  • Loading branch information
McDutchie committed Nov 24, 2024
1 parent 6e30fe1 commit 03ace33
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ESC>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
<ESC>n<cr> to execute.
10-05-20 A bug which caused an exception when multiple levels of composite
functions in arithmetic expressions has been fixed.
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/ksh93/bltins/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ':':
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/bltins/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/features/externs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
#include <unistd.h>
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/sh/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/*
Expand All @@ -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]=='~')
Expand All @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down
8 changes: 4 additions & 4 deletions src/lib/libast/man/stk.3
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03ace33

Please sign in to comment.