mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix enum type definition pre-parsing for shcomp and dot/source
Parser limitations prevent shcomp or source from handling enum
types correctly:
$ cat /tmp/colors.sh
enum Color_t=(red green blue orange yellow)
Color_t -A Colors=([foo]=red)
$ shcomp /tmp/colors.sh > /dev/null
/tmp/colors.sh: syntax error at line 2: `(' unexpected
$ source /tmp/colors.sh
/bin/ksh: source: syntax error: `(' unexpected
Yet, for types created using 'typeset -T', this works. This is done
via a check_typedef() function that preliminarily adds the special
declaration builtin at parse time, with details to be filled in
later at execution time.
This hack will produce ugly undefined behaviour if the definition
command creating that type built-in is then not actually run at
execution time before the type built-in is accessed.
But the hack is necessary because we're dealing with a fundamental
design flaw in the ksh language. Dynamically addable built-ins that
change the syntactic parsing of the shell language on the fly are
an absurdity that violates the separation between parsing and
execution, which muddies the waters and creates the need for some
kind of ugly hack to keep things like shcomp more or less working.
This commit extends that hack to support enum.
src/cmd/ksh93/sh/parse.c:
- check_typedef():
- Add 'intypeset' parameter that should be set to 1 for typeset
and friends, 2 for enum.
- When processing enum arguments, use AST getopt(3) to skip over
enum's options to find the name of the type to be defined.
(getopt failed if we were running a -c script; deal with this
by zeroing opt_info.index first.)
- item(): Update check_typedef() call, passing lexp->intypeset.
- simple(): Set lexp->intypeset to 2 when processing enum.
The rest of the changes are all to support the above and should be
fairly obvious, except:
src/cmd/ksh93/bltins/enum.c:
- enuminfo(): Return on null pointer, avoiding a crash upon
executing 'Type_t --man' if Type_t has not been fully defined due
to the definition being pre-added at parse time but not executed.
It's all still wrong, but a crash is worse.
Resolves: https://github.com/ksh93/ksh/issues/256
This commit is contained in:
parent
996def3141
commit
8ced1daadf
9 changed files with 67 additions and 17 deletions
|
|
@ -60,6 +60,7 @@
|
|||
#define SYSDOT (shgd->bltin_cmds+20) /* . */
|
||||
#define SYSSOURCE (shgd->bltin_cmds+21) /* source */
|
||||
#define SYSRETURN (shgd->bltin_cmds+22) /* return */
|
||||
#define SYSENUM (shgd->bltin_cmds+23) /* enum */
|
||||
|
||||
/* entry point for shell special builtins */
|
||||
|
||||
|
|
@ -168,6 +169,7 @@ extern const char sh_optdot[];
|
|||
#ifndef ECHOPRINT
|
||||
extern const char sh_optecho[];
|
||||
#endif /* !ECHOPRINT */
|
||||
extern const char sh_optenum[];
|
||||
extern const char sh_opteval[];
|
||||
extern const char sh_optexec[];
|
||||
extern const char sh_optredirect[];
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ typedef struct _shlex_
|
|||
char aliasok; /* on when alias is legal */
|
||||
char assignok; /* on when name=value is legal */
|
||||
char inexec; /* on when processing exec */
|
||||
char intypeset; /* on when processing typeset */
|
||||
char intypeset; /* 1 when processing typeset, 2 when processing enum */
|
||||
char comp_assign; /* in compound assignment */
|
||||
char comsub; /* parsing command substitution */
|
||||
char noreserv; /* reserved works not legal */
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
|
||||
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
|
||||
#define SH_RELEASE_DATE "2021-11-20" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_DATE "2021-11-21" /* must be in this format for $((.sh.version)) */
|
||||
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
|
||||
|
||||
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue