On Monday, March 28, 2011 10:15:01 you wrote:
> cc: [email protected]
> Subject: Re: [ast-developers] ksh: problem with arrays
> --------
>
> > Hi,
> >
> > one our user reported change in ksh's behavior. I've checked it and
> > prepared thi
> > s simplified test case. Could you look at it? Thanks, Michal
> >
> > Simplified test case:
> >
> > typeset xx[7];
> > echo ${#xx[@]};
> > typeset -p xx;
> > xx[6]=hello; echo ${xx[6]};
> > typeset -p xx;
> > xx[5]=world; echo ${xx[5]};
> > typeset -p xx;
> > xx[8]=foo; typeset -p xx;
> > unset xx; typeset -p xx;
> > echo ${#xx[@]}
> >
> > ksh >=2010-10-10 prints:
> > 7 #why is that 7? bash,mksh, ksh<=2008-10-01 prints 0, ksh 2008-10-09 ...
> > 2010-0
> > 9-24 prints 1
> > typeset -a xx[7];xx=()
> > <nothing> #should print hello
> > typeset -a xx[7];xx=('' '' '' '' '' '' '') #definition unexpectedly changed
> > and
> > 'hello' is missing
> > <nothing> #should print world
> > typeset -a xx[7];xx=('' '' '' '' '' '' '')
> > xx[5]: subscript out of range #why out of range? why xx[5] , this was
> > xx[8]=foo
> > assignment
> > <nothing>
> > 0
> >
>
> This bug was already reported and is fixed for the first bug fix release of
> ksh93u which will be distributed this quarter.
>
> The problem is that the declaration
>
> typeset xx[7];
>
> is incorrectly treating xx as a fixed size array of size 7 and currently
> fixed sized arrays only for for fixed sized objects. The declaration for
> fixed size arrays should be
> typeset -a xx[7];
> and the declaration
> typeset xx[7];
> is not even necessary, but should not have been treated as a fixed array.
I'll have to answer some questions, so I'd like to confirm a few things.
1) It is expected that typeset xx[7]; creates array with one empty element [7]
so
${#xx[@]} is really expected to be 1 despite all other shells I've tested don't
create that
element, so they report zero. Old ksh reported 0 too, this changed between
2008-10-01 and 2008-10-10, but I did not find anything about this in RELEASE
file.
This was original complain I've got so I'd like to be sure this is expected
before I tell
it to our users :)
2) I was looking for fixed arrays at ksh man page (just searched for 'fixed'
keyword),
but did not find anything. So I've looked at RELEASE file and I've found fixed
arrays
mentioned only once (10-09-28):
> ... It allows fixed sized indexed arrays be to defined
> using "typeset array[dim1][dim2]...[dimn]". ...
so should it be typeset -a xx[7] or typeset xx[7] ?
3) Is there any document/web page/something about fixed arrays I could forward
to users
who ask me about this?
And last thing. Cosmetic issue when ksh reports problem "subscript out of
range". I
don't care about this, it just looks odd so if there isn't any more serious bug
hidden:
$ typeset -a -i xx[7]
$ xx[8]=1
ksh: xx: subscript out of range
$ xx[6]=1
$ xx[8]=1
ksh: xx[6]: subscript out of range
in first error there is "xx" in second error there is "xx[6]", always the last
used (valid)
index is reported in error message
>
> Therefore the workaround is to delete this declaration
> or use the declaration
> typeset -a xx
> instead. This is also the cause of the core dump you reported with
> typeset -p.
>
> Here is a patch that should fix this problem.
Thanks, now it works the same way as prev. version and typeset -p crash is gone
too
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers