From e554a07c56bbdf25f716ce2813b6db3e016d2098 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Sat, 20 Nov 2021 00:41:49 -0800 Subject: [PATCH] `typeset -T` shouldn't list types created with `enum` (#340) Listing types with 'typeset -T' will list not only types created with typeset, but also types created with enum. However, the types created by enum are not displayed correctly in the resulting output: $ enum Foo_t=(foo bar) $ typeset -T typeset -T Foo_t typeset -T Foo_t=fo) The fix for this bug was backported from ksh93v- 2013-10-08. src/cmd/ksh93/sh/nvtype.c: - sh_outtype(): Skip over enums when listing types with 'typeset -T'. --- NEWS | 5 +++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/nvtype.c | 5 ++++- src/cmd/ksh93/tests/types.sh | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 73c1533c4..8bc6b973b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2021-11-20: + +- Listing types with 'typeset -T' no longer displays incomplete versions of + types created by the enum built-in. + 2021-11-18: - The printf built-in command now supports a -v option as on bash and zsh. diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 6f0e909a5..f20e43b2f 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -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-18" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2021-11-20" /* 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. */ diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index 3ec80584d..4b47e0029 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -1580,13 +1580,16 @@ int sh_outtype(Shell_t *shp,Sfio_t *out) if(indent==0) for(tp = (Namval_t*)dtfirst(dp); tp; tp = (Namval_t*)dtnext(dp,tp)) { + /* skip over enums */ + if(tp->nvfun && !nv_isvtree(tp)) + continue; if(!nv_search(tp->nvname,shp->bltin_tree,0)) continue; sfprintf(out,"typeset -T %s\n",tp->nvname); } for(tp = (Namval_t*)dtfirst(dp); tp; tp = (Namval_t*)dtnext(dp,tp)) { - if(nv_isnull(tp)) + if(nv_isnull(tp) || !nv_isvtree(tp)) continue; if(indent && (memcmp(tp->nvname,shp->prefix,n-1) || tp->nvname[n-1]!='.' || strchr(tp->nvname+n,'.'))) continue; diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index 6a45d7cd0..1b1c1a1d3 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -633,5 +633,11 @@ bar.foo+=(bam) # Type names that have 'a' as the first letter should be functional "$SHELL" -c 'typeset -T al=(typeset bar); al foo=(bar=testset)' || err_exit "type names that start with 'a' don't work" +# ====== +# 'typeset -T' shouldn't list types created by enum +got=$($SHELL -c 'enum Foo_t=(foo bar); typeset -T') +[[ -z $got ]] || err_exit "Types created by enum are listed with 'typeset -T'" \ + "(got $(printf %q "$got"))" + # ====== exit $((Errors<125?Errors:125))