1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

nv_associative(): finally use proper check for enum (re: b98e32fc)

As of the previous commit, I finally know how to properly check for
a variable of a type created by 'enum'. We need to check for both
the NV_UINT16 attribute and the ENUM_disc discipline.

Also:
- regression test tweaks
- add missing tests for previous commit (f600a5ea)
This commit is contained in:
Martijn Dekker 2021-11-24 01:11:55 +01:00
parent a66cd72f7d
commit e3d91ffa90
3 changed files with 25 additions and 10 deletions

View file

@ -1777,11 +1777,11 @@ void *nv_associative(register Namval_t *np,const char *sp,int mode)
if(sh.subshell) if(sh.subshell)
np = sh_assignok(np,1); np = sh_assignok(np,1);
/* /*
* type == NV_UINT16 (16-bit unsigned integer, see include/nval.h) indicates an * For enum types (NV_UINT16 with discipline ENUM_disc), nelem should not
* associative array of a type created by the enum command. nelem should not be * not increased or 'unset' will fail to completely unset such an array.
* increased in that case or 'unset' will fail to completely unset such an array.
*/ */
if(type != NV_UINT16 && (!ap->header.scope || !nv_search(sp,dtvnext(ap->header.table),0))) if((!ap->header.scope || !nv_search(sp,dtvnext(ap->header.table),0))
&& !(type==NV_UINT16 && nv_hasdisc(np, &ENUM_disc)))
ap->header.nelem++; ap->header.nelem++;
if(nv_isnull(mp)) if(nv_isnull(mp))
{ {

View file

@ -238,7 +238,9 @@ function foo {
} }
foo foo
EOF EOF
$SHELL "$multiarray_unset" > /dev/null || err_exit 'Multidimensional arrays with an unset method crash ksh' { $SHELL "$multiarray_unset" > /dev/null; } 2>/dev/null
let "(e=$?)==0" || err_exit 'Multidimensional arrays with an unset method crash ksh' \
"(got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
# ====== # ======
# Multidimensional indexed array arithmetic assignment operation tests # Multidimensional indexed array arithmetic assignment operation tests

View file

@ -22,7 +22,7 @@
. "${SHTESTS_COMMON:-${0%/*}/_common}" . "${SHTESTS_COMMON:-${0%/*}/_common}"
enum Color_t=(red green blue orange yellow) enum Color_t=(red green blue orange yellow)
enum -i Sex_t=(Male Female) enum -i Bool_t=(False True)
for ((i=0; i < 1000; i++)) for ((i=0; i < 1000; i++))
do do
Color_t x Color_t x
@ -47,10 +47,10 @@ z[green]=xyz
z[orange]=bam z[orange]=bam
[[ ${!z[@]} == 'green orange' ]] || err_exit '${!z[@]} == "green orange"' [[ ${!z[@]} == 'green orange' ]] || err_exit '${!z[@]} == "green orange"'
unset x unset x
Sex_t x Bool_t x
[[ $x == Male ]] || err_exit 'Sex_t not defaulting to Male' [[ $x == False ]] || err_exit 'Bool_t not defaulting to False'
x=female x=true
[[ $x == Female ]] || err_exit 'Sex_t not case sensitive' [[ $x == True ]] || err_exit 'Bool_t not case sensitive'
unset x y z unset x y z
done done
( (
@ -133,5 +133,18 @@ got=$("$SHELL" -c 'source ./cmd.sh' 2>&1)
[[ $got == "$exp" ]] || err_exit "sourced script failed" \ [[ $got == "$exp" ]] || err_exit "sourced script failed" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))" "(expected $(printf %q "$exp"); got $(printf %q "$got"))"
# ======
# https://github.com/ksh93/ksh/issues/335
unset a
Color_t a
let "a=5" 2>/dev/null && err_exit "arithmetic can assign out of range (positive)"
let "a=-1" 2>/dev/null && err_exit "arithmetic can assign out of range (negative)"
a=yellow; let "a++" 2>/dev/null && err_exit "arithmetic can assign out of range (increment)"
a=red; let "a--" 2>/dev/null && err_exit "arithmetic can assign out of range (decrement)"
a=orange; let "a+=2" 2>/dev/null && err_exit "arithmetic can assign out of range (add)"
a=green; let "a-=2" 2>/dev/null && err_exit "arithmetic can assign out of range (subtract)"
a=blue; let "a*=3" 2>/dev/null && err_exit "arithmetic can assign out of range (multiply)"
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))