1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Next round of minor tweaks and cleanups

Notable changes:
- Tie up some loose ends re: 3de4da5a and 7ba2c685.
- comp/omitted.c: Header include fix for Cygwin.
- misc/optget.c:
  - args(): When printing options for the uage line, use a local
    pointer for the 'if' block instead of reusing the 'b' pointer.
    That variable is used to output blanks later.
  - The above fix allows re-enabling the AST translation-aware
    macros and deleting the astsa fallback without causing usage
    message corruption in multibyte locales. Maybe someday we'll
    make ksh actually translatable.
  - Remove code to reinitialise _error_infop_ and _opt_info_
    'because these are not initialised by all DLLs'. In 2022,
    hopefully the buggy dynamic linkers are fixed. If not, we're
    not going to find out by keeping the workaround. I suspect that
    those bugs may have been triggered by the Microsoft/Cygwin
    import/export obfuscation removed in 3de4da5a.
- ksh93:
  - Remove unused sh.st.var_local variable. This was a leftover of
    a 93v- attempt to implement the bash 'local' command. It used
    static scoping, so it's not actually compatible.
  - Add a few regression tests for miscellaneous breakage that I
    caused in experiments (the breakage never made it to git; the
    tests are just to keep it that way).
This commit is contained in:
Martijn Dekker 2022-07-21 22:58:53 +02:00
parent 3de4da5afb
commit ce3cc66d58
15 changed files with 55 additions and 89 deletions

View file

@ -287,7 +287,7 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
}
*prevscope = sh.st;
sh.st.lineno = np?((struct functnod*)nv_funtree(np))->functline:1;
sh.st.var_local = sh.st.save_tree = sh.var_tree;
sh.st.save_tree = sh.var_tree;
if(filename)
{
sh.st.filename = filename;

View file

@ -113,7 +113,6 @@ struct argnod
/* legal argument flags */
#define ARG_RAW 0x1 /* string needs no processing */
#define ARG_MAKE 0x2 /* bit set during argument expansion */
#define ARG_COMSUB 0x2 /* command sub */
#define ARG_MAC 0x4 /* string needs macro expansion */
#define ARG_EXP 0x8 /* string needs file expansion */
#define ARG_ASSIGN 0x10 /* argument is an assignment */

View file

@ -195,7 +195,6 @@ struct sh_scoped
int lineno;
Dt_t *save_tree; /* var_tree for calling function */
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; /* shell state bits used by sh_isstate(), etc. */
int breakcnt; /* number of levels to 'break'/'continue' (negative if 'continue') */

View file

@ -2804,18 +2804,6 @@ int sh_trace(register char *argv[], register int nl)
return(0);
}
/*
* This routine creates a subshell by calling fork() or vfork()
* If ((flags&COMMSK)==TCOM), then vfork() is permitted
* If fork fails, the shell sleeps for exponentially longer periods
* and tries again until a limit is reached.
* SH_FORKLIM is the max period between forks - power of 2 usually.
* Currently shell tries after 2,4,8,16, and 32 seconds and then quits
* Failures cause the routine to error exit.
* Parent links to here-documents are removed by the child
* Traps are reset by the child
* The process-id of the child is returned to the parent, 0 to the child.
*/
static void timed_out(void *handle)
{
NOT_USED(handle);
@ -2954,6 +2942,17 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
return(0);
}
/*
* This routine creates a subshell by calling fork(2).
* If fork fails, the shell sleeps for exponentially longer periods
* and tries again until a limit is reached.
* SH_FORKLIM is the max period between forks - power of 2 usually.
* Currently, the shell tries after 2, 4, 8, 16 and 32 seconds, and then quits.
* Failures cause the routine to error exit.
* Parent links to here-documents are removed by the child.
* Traps are reset by the child.
* The process-id of the child is returned to the parent, 0 to the child.
*/
pid_t sh_fork(int flags, int *jobid)
{
register pid_t parent;
@ -3109,7 +3108,6 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg)
sh_pushcontext(buffp,SH_JMPFUN);
errorpush(&buffp->err,0);
error_info.id = argv[0];
sh.st.var_local = sh.var_tree;
if(!fun)
{
if(fp->node->nvalue.rp)

View file

@ -983,5 +983,11 @@ float x
exit 0
EOF
# ======
got=$(set +x; eval ': $((1 << 2))' 2>&1) \
|| err_exit "bitwise left shift operator fails to parse (got $(printf %q "$got"))"
got=$(set +x; eval 'got=$( ((y=1<<4)); echo $y )' 2>&1; echo $got) \
|| err_exit "bitwise left shift operator fails to parse in comsub (got $(printf %q "$got"))"
# ======
exit $((Errors<125?Errors:125))

View file

@ -385,7 +385,8 @@ done
unset v
typeset -H v=/dev/null
[[ $v == *nul* ]] || err_exit 'typeset -H for /dev/null not working'
# on cygwin, this is \\.\GLOBALROOT\Device\Null
[[ $v == *[Nn]ul* ]] || err_exit "typeset -H for /dev/null not working (got $(printf %q "$v"))"
unset x
(typeset +C x) 2> /dev/null && err_exit 'typeset +C should be an error'

View file

@ -790,16 +790,17 @@ hash -r
# ======
# Variables set in functions inside of a virtual subshell should not affect the
# outside environment. This regression test must be run from the disk.
testvars=$tmp/testvars.sh
cat >| "$testvars" << 'EOF'
# outside environment. This regression test must be run as a separate script.
got=$("$SHELL" -c '
c=0
function set_ac { a=1; c=1; }
function set_abc { ( set_ac ; b=1 ) }
set_abc
echo "a=$a b=$b c=$c"
EOF
v=$($SHELL $testvars) && [[ "$v" == "a= b= c=0" ]] || err_exit 'variables set in subshells are not confined to the subshell'
')
exp='a= b= c=0'
[[ $got == "$exp" ]] || err_exit 'variables set in subshells are not confined to the subshell' \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# ======
got=$("$SHELL" -c '

View file

@ -1424,5 +1424,12 @@ do
done
done
# ======
var1.get() { .sh.value=one; : $var2; }
var2.get() { .sh.value=two; }
got=$var1
unset var1 var2
[[ $got == one ]] || err_exit ".sh.value not restored after second .get discipline call (got $(printf %q "$got"))"
# ======
exit $((Errors<125?Errors:125))