diff --git a/NEWS b/NEWS index ee998203f..8bb88dd38 100644 --- a/NEWS +++ b/NEWS @@ -14,10 +14,13 @@ Any uppercase BUG_* names are modernish shell bug IDs. an incompletely defined 'foo_t' built-in comamnd that will crash the shell when used. Instead, it is now silently ignored for backwards compatibility. -- A bug in which the output of a two dimensional sparse indexed array would - cause the second subscript to be treated as an associative array when read - back in has been fixed. Elements that are sparse indexed arrays are now - prefixed with "typeset -a". +- Compound arrays belonging to a type created with 'typeset -T' now have + their -C attribute preserved in the output of 'typeset -p'. + +- A bug has been fixed in which the 'typeset -p' output of a two-dimensional + sparse indexed array would cause the second subscript to be treated as an + associative array when read back in by the shell. Elements that are sparse + indexed arrays are now prefixed with "typeset -a". 2022-02-05: diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index e6cbf1d15..0a5c0693d 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -139,6 +139,8 @@ static const Namdisc_t type_disc = 0, }; +static char *AltEmpty = ""; + size_t nv_datasize(Namval_t *np, size_t *offset) { size_t s=0, a=0; @@ -333,6 +335,8 @@ static int fixnode(Namtype_t *dp, Namtype_t *pp, int i, struct Namref *nrp,int f nv_offattr(nq,NV_NOFREE); } } + else if(nq->nvalue.cp==AltEmpty) + nq->nvalue.cp = Empty; else if(nq->nvalue.cp==Empty) nv_offattr(nq,NV_NOFREE); @@ -1159,7 +1163,12 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes) free((void*)np->nvalue.cp); } if(!nq->nvalue.cp && nq->nvfun== &pp->childfun.fun) - nq->nvalue.cp = Empty; + { + if(nv_isattr(np,NV_ARRAY|NV_NOFREE)==(NV_ARRAY|NV_NOFREE)) + nq->nvalue.cp = AltEmpty; + else + nq->nvalue.cp = Empty; + } np->nvalue.cp = 0; offset += (dsize?dsize:4); } diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index ced406e81..b5e9331f6 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -592,7 +592,7 @@ $SHELL << \EOF compound p=( hello=world ) c.b.binsert p 1 $i done - exp='typeset -C c=(board_t b=(typeset -a board_y=( [1]=(typeset -a board_x=( [0]=(field=(hello=world;))[1]=(field=(hello=world)));));))' + exp='typeset -C c=(board_t b=(typeset -C -a board_y=( [1]=(typeset -a board_x=( [0]=(field=(hello=world;))[1]=(field=(hello=world)));));))' [[ $(typeset -p c) == "$exp" ]] || exit 1 } main @@ -634,6 +634,13 @@ Bar_t bar bar.foo+=(bam) [[ ${bar.foo[0]} == bam ]] || err_exit 'appending to empty array variable in type does not create element 0' +# ====== +# Compound arrays listed with 'typeset -p' should have their -C attribute +# preserved in the output. +typeset -T Z_t=(compound -a x) +Z_t z +[[ $(typeset -p z.x) == *'-C -a'* ]] || err_exit 'typeset -p for compound array element does not display all attributes' + # ====== # 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"