Discussion:
[ast-developers] print -v c array formatting chaos when array was modified by { unset, typeset -m, typeset -c ... } ...
Roland Mainz
2013-08-04 02:13:57 UTC
Permalink
Hi!

----

The following testcase...
-- snip --
typeset -T x_t=(
integer i
)

typeset -T b_t=(
compound -a ar

function move
{
integer fx=$1
integer fy=$2
integer fz=$3
integer tx=$4
integer ty=$5
integer tz=$6

typeset -m '_.ar[tx][ty][tz].value=_.ar[fx][fy][fz].value'
#unset '_.ar[fx][fy][fz]'
}
)

function main
{
compound c
b_t c.b

x_t c.b.ar[100][200][300].value=( i=9 )

for ((i=0 ; i < 10 ; i++ )) ; do
c.b.move 100 200 300 400 500 600
c.b.move 400 500 600 1000 1100 1200
c.b.move 1000 1100 1200 100 200 300
done

out1="$(print -v c)"
read -C d <<<"$out1"
diff -u <(print -v c) <(print -v d)
}

main
-- snip --

... should AFAIK print nothing... but on ast-ksh.2013-07-27 it shows
the following whitespace differences (the output from /dev/fd/4 is IMO
the expected one):

-- snip --
--- /dev/fd/3 2013-08-04 04:06:37.462048062 +0200
+++ /dev/fd/4 2013-08-04 04:06:37.463047829 +0200
@@ -10,13 +10,13 @@
)
)
)
-typeset -a [400]=(
+ typeset -a [400]=(
typeset -a [500]=(
[600]=(
)
)
)
-typeset -a [1000]=(
+ typeset -a [1000]=(
typeset -a [1100]=(
[1200]=(
)
-- snip --

The issue seems to be that if "typeset -m", "typeset -c" or "unset"
change the array then some array elements are not intended correctly.
Using $ print -v ... | read -C ... # to copy the compound variable
fixes the problem (the trouble for me is that testing whether the
string values of two compound variables are identical is impossible
due to this bug... ;-( ).

----

Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
Loading...