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

@ -97,7 +97,7 @@ static const char usage[] =
#define elementsof(x) (sizeof(x)/sizeof(x[0])) #define elementsof(x) (sizeof(x)/sizeof(x[0]))
#define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x))) #define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
#define NiL ((char*)0) #define NiL 0
#endif #endif
@ -267,7 +267,15 @@ extern char** environ;
static void static void
usage() usage()
{ {
fprintf(stderr, "Usage: %s [-iknFKNV] [-f mamfile] [-r pattern] [-C directory] [-D level] [target ...] [name=value ...]\n", state.id); fprintf(stderr, "Usage: %s"
" [-iknFKNV]"
" [-f Mamfile]"
" [-r pattern]"
" [-C directory]"
" [-D level]"
" [target ...]"
" [name=value ...]"
"\n", state.id);
exit(2); exit(2);
} }
@ -1834,7 +1842,7 @@ update(register Rule_t* r)
} }
/* /*
* scan makefile prereqs * scan Mamfile prereqs
*/ */
static int static int
@ -2123,7 +2131,7 @@ recurse(char* pattern)
search(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1)); search(state.vars, "MAMAKEARGS", duplicate(use(state.opt) + 1));
/* /*
* scan the makefile and descend * scan the Mamfile and descend
*/ */
walk(state.rules, scan, NiL); walk(state.rules, scan, NiL);

View file

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

View file

@ -113,7 +113,6 @@ struct argnod
/* legal argument flags */ /* legal argument flags */
#define ARG_RAW 0x1 /* string needs no processing */ #define ARG_RAW 0x1 /* string needs no processing */
#define ARG_MAKE 0x2 /* bit set during argument expansion */ #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_MAC 0x4 /* string needs macro expansion */
#define ARG_EXP 0x8 /* string needs file expansion */ #define ARG_EXP 0x8 /* string needs file expansion */
#define ARG_ASSIGN 0x10 /* argument is an assignment */ #define ARG_ASSIGN 0x10 /* argument is an assignment */

View file

@ -195,7 +195,6 @@ struct sh_scoped
int lineno; int lineno;
Dt_t *save_tree; /* var_tree for calling function */ Dt_t *save_tree; /* var_tree for calling function */
struct sh_scoped *self; /* pointer to copy of this scope */ 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 */ struct slnod *staklist; /* link list of function stacks */
int states; /* shell state bits used by sh_isstate(), etc. */ int states; /* shell state bits used by sh_isstate(), etc. */
int breakcnt; /* number of levels to 'break'/'continue' (negative if 'continue') */ 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); 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) static void timed_out(void *handle)
{ {
NOT_USED(handle); NOT_USED(handle);
@ -2954,6 +2942,17 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid)
return(0); 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) pid_t sh_fork(int flags, int *jobid)
{ {
register pid_t parent; 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); sh_pushcontext(buffp,SH_JMPFUN);
errorpush(&buffp->err,0); errorpush(&buffp->err,0);
error_info.id = argv[0]; error_info.id = argv[0];
sh.st.var_local = sh.var_tree;
if(!fun) if(!fun)
{ {
if(fp->node->nvalue.rp) if(fp->node->nvalue.rp)

View file

@ -983,5 +983,11 @@ float x
exit 0 exit 0
EOF 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)) exit $((Errors<125?Errors:125))

View file

@ -385,7 +385,8 @@ done
unset v unset v
typeset -H v=/dev/null 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 unset x
(typeset +C x) 2> /dev/null && err_exit 'typeset +C should be an error' (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 # Variables set in functions inside of a virtual subshell should not affect the
# outside environment. This regression test must be run from the disk. # outside environment. This regression test must be run as a separate script.
testvars=$tmp/testvars.sh got=$("$SHELL" -c '
cat >| "$testvars" << 'EOF'
c=0 c=0
function set_ac { a=1; c=1; } function set_ac { a=1; c=1; }
function set_abc { ( set_ac ; b=1 ) } function set_abc { ( set_ac ; b=1 ) }
set_abc set_abc
echo "a=$a b=$b c=$c" 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 ' got=$("$SHELL" -c '

View file

@ -1424,5 +1424,12 @@ do
done done
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)) exit $((Errors<125?Errors:125))

View file

@ -2832,6 +2832,7 @@ make install
done FEATURE/omitted generated done FEATURE/omitted generated
prev include/tm.h implicit prev include/tm.h implicit
prev include/error.h implicit prev include/error.h implicit
prev ast_stdio.h implicit
prev include/ast.h implicit prev include/ast.h implicit
prev FEATURE/float implicit prev FEATURE/float implicit
done comp/omitted.c done comp/omitted.c

View file

@ -7,6 +7,7 @@
#define utimes ______utimes #define utimes ______utimes
#include <ast.h> #include <ast.h>
#include <ast_stdio.h>
#include <error.h> #include <error.h>
#include <tm.h> #include <tm.h>
@ -24,6 +25,7 @@
#if __CYGWIN__ #if __CYGWIN__
#include <ast_windows.h> #include <ast_windows.h>
#include <sys/cygwin.h>
#if _win32_botch_execve || _lib_spawn_mode #if _win32_botch_execve || _lib_spawn_mode
#define CONVERT 1 #define CONVERT 1
#endif #endif

View file

@ -47,12 +47,9 @@
/* /*
* 2007-03-19 move error_info from _error_info_ to (*_error_infop_) * 2007-03-19 move error_info from _error_info_ to (*_error_infop_)
* to allow future Error_info_t growth * to allow future Error_info_t growth
* by 2009 _error_info_ can be static
*/ */
extern Error_info_t _error_info_; static Error_info_t _error_info_ =
Error_info_t _error_info_ =
{ {
2, exit, write, 2, exit, write,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
@ -64,8 +61,7 @@ Error_info_t _error_info_ =
translate, translate,
0 /* catalog */ 0 /* catalog */
}; };
Error_info_t* _error_infop_ = &_error_info_;
extern Error_info_t* _error_infop_ = &_error_info_;
/* /*
* these should probably be in error_info * these should probably be in error_info
@ -356,10 +352,8 @@ errorv(const char* id, int level, va_list ap)
int line; int line;
char* file; char* file;
#if !_PACKAGE_astsa
unsigned long d; unsigned long d;
struct tms us; struct tms us;
#endif
if (!error_info.init) if (!error_info.init)
{ {
@ -466,14 +460,12 @@ errorv(const char* id, int level, va_list ap)
sfprintf(stkstd, "%s %d: ", ERROR_translate(NiL, NiL, ast.id, "line"), error_info.line); sfprintf(stkstd, "%s %d: ", ERROR_translate(NiL, NiL, ast.id, "line"), error_info.line);
} }
} }
#if !_PACKAGE_astsa
if (error_info.time) if (error_info.time)
{ {
if ((d = times(&us)) < error_info.time || error_info.time == 1) if ((d = times(&us)) < error_info.time || error_info.time == 1)
error_info.time = d; error_info.time = d;
sfprintf(stkstd, " %05lu.%05lu.%05lu ", d - error_info.time, (unsigned long)us.tms_utime, (unsigned long)us.tms_stime); sfprintf(stkstd, " %05lu.%05lu.%05lu ", d - error_info.time, (unsigned long)us.tms_utime, (unsigned long)us.tms_stime);
} }
#endif
switch (level) switch (level)
{ {
case 0: case 0:

View file

@ -176,8 +176,6 @@ static unsigned char map[UCHAR_MAX];
static Optstate_t state; static Optstate_t state;
#if 0 /* #if !_PACKAGE_astsa // this somehow corrupts "Or:" usage messages, e.g. in 'typeset -\?' */
#define ID ast.id #define ID ast.id
#define C(s) ERROR_catalog(s) #define C(s) ERROR_catalog(s)
@ -200,18 +198,6 @@ translate(const char* cmd, const char* cat, const char* msg)
return errorx(NiL, cmd, cat, msg); return errorx(NiL, cmd, cat, msg);
} }
#else
static char ID[] = "ast";
#define C(s) s
#define D(s) (state.msgdict && dtmatch(state.msgdict, (s)))
#define T(i,c,m) m
#define X(c) 0
#define Z(x) C(x),sizeof(x)-1
#endif
static const List_t help_head[] = static const List_t help_head[] =
{ {
'-', 0, '-', 0,
@ -337,17 +323,9 @@ static Msg_t C_LC_MESSAGES_libast[] =
/* /*
* 2007-03-19 move opt_info from _opt_info_ to (*_opt_data_) * 2007-03-19 move opt_info from _opt_info_ to (*_opt_data_)
* to allow future Opt_t growth * to allow future Opt_t growth
* by 2009 _opt_info_ can be static
*/ */
extern Opt_t _opt_info_; static Opt_t _opt_info_ = { 0,0,0,0,0,0,0,{0},{0},0,0,0,{0},{0},&state };
Opt_t _opt_info_ = { 0,0,0,0,0,0,0,{0},{0},0,0,0,{0},{0},&state };
extern Opt_t _opt_info_;
extern Opt_t* _opt_infop_;
Opt_t* _opt_infop_ = &_opt_info_; Opt_t* _opt_infop_ = &_opt_info_;
Optstate_t* Optstate_t*
@ -925,10 +903,8 @@ init(register char* s, Optpass_t* p)
if (!state.localized) if (!state.localized)
{ {
state.localized = 1; state.localized = 1;
#if !_PACKAGE_astsa
if (!ast.locale.serial) if (!ast.locale.serial)
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
#endif
state.xp = sfstropen(); state.xp = sfstropen();
if (!map[OPT_FLAGS[0]]) if (!map[OPT_FLAGS[0]])
for (n = 0, t = OPT_FLAGS; *t; t++) for (n = 0, t = OPT_FLAGS; *t; t++)
@ -1650,9 +1626,10 @@ args(register Sfio_t* sp, register char* p, register int n, int flags, int style
sfputr(sp, b, -1); sfputr(sp, b, -1);
if (X(catalog)) if (X(catalog))
{ {
char *cp;
sfwrite(ip, p, i); sfwrite(ip, p, i);
if (b = sfstruse(ip)) if (cp = sfstruse(ip))
sfputr(sp, T(id, catalog, b), -1); sfputr(sp, T(id, catalog, cp), -1);
else else
sfwrite(sp, p, i); sfwrite(sp, p, i);
} }
@ -4283,19 +4260,6 @@ optget(register char** argv, const char* oopts)
Optcache_t* pcache; Optcache_t* pcache;
Optpass_t* pass; Optpass_t* pass;
#if !_PACKAGE_astsa && !_YOU_FIGURED_OUT_HOW_TO_GET_ALL_DLLS_TO_DO_THIS_
/*
* these are not initialized by all dlls!
*/
extern Error_info_t _error_info_;
extern Opt_t _opt_info_;
if (!_error_infop_)
_error_infop_ = &_error_info_;
if (!_opt_infop_)
_opt_infop_ = &_opt_info_;
#endif
if (!oopts) if (!oopts)
return 0; return 0;
state.pindex = opt_info.index; state.pindex = opt_info.index;

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 *
@ -34,9 +34,7 @@
#include <ctype.h> #include <ctype.h>
#include <ccode.h> #include <ccode.h>
#if !_PACKAGE_astsa
#include <regex.h> #include <regex.h>
#endif
int int
chrexp(register const char* s, char** p, int* m, register int flags) chrexp(register const char* s, char** p, int* m, register int flags)

View file

@ -56,14 +56,6 @@ int sys_nerr = 0;
extern char* strerror(int); extern char* strerror(int);
#endif #endif
#if _PACKAGE_astsa
#define fmtbuf(n) ((n),tmp)
static char tmp[32];
#endif
char* char*
_ast_strerror(int err) _ast_strerror(int err)
{ {
@ -82,7 +74,6 @@ _ast_strerror(int err)
#endif #endif
if (msg) if (msg)
{ {
#if !_PACKAGE_astsa
if (ERROR_translating()) if (ERROR_translating())
{ {
#if _lib_strerror #if _lib_strerror
@ -125,7 +116,6 @@ _ast_strerror(int err)
#endif #endif
return ERROR_translate(NiL, NiL, "errlist", msg); return ERROR_translate(NiL, NiL, "errlist", msg);
} }
#endif
return msg; return msg;
} }
msg = fmtbuf(z = 32); msg = fmtbuf(z = 32);