On Mon, Mar 28, 2011 at 4:15 PM, David Korn <[email protected]> wrote:
> cc: [email protected]
> Subject: Re: [ast-developers] ksh: problem with arrays
> --------
>> 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
>>
>>
>> ksh 2008-10-09 ... 2010-09-24 prints:
>> 1
>> typeset -a xx=([7]=)
>> hello
>> typeset -a xx=([6]=hello [7]=)
>> world
>> typeset -a xx=([5]=world [6]=hello [7]= [8]=foo)
>> 0
>>
>>
>> ksh <=2008-10-01 prints:
>> 0
>> typeset -a xx=([0]=)
>> hello
>> typeset -a xx=([6]=hello)
>> world
>> typeset -a xx=([5]=world [6]=hello [8]=foo)
>> 0
>>
>>
>> bash output for comparison:
>> 0
>> declare -a xx='()'
>> hello
>> declare -a xx='([6]="hello")'
>> world
>> declare -a xx='([5]="world" [6]="hello" [8]="foo")'
>> bash: line 0: typeset: xx: not found
>> 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.
>
> 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.
>
> ========================cut here==========================
> --- old/bltins/typeset.c        Thu Dec 30 19:15:57 2010
> +++ new/bltins/typeset.c        Thu Mar  3 11:02:49 2011
> @@ -568,7 +568,7 @@
>                                
> path_alias(np,path_absolute(shp,nv_name(np),NIL(Pathcomp_t*)));
>                                continue;
>                        }
> -                       np = 
> nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|NV_FARRAY);
> +                       np = 
> nv_open(name,troot,nvflags|((nvflags&NV_ASSIGN)?0:NV_ARRAY)|(iarray?NV_FARRAY:0));
>                        if(nv_isnull(np) && !nv_isarray(np) && 
> nv_isattr(np,NV_NOFREE))
>                                nv_offattr(np,NV_NOFREE);
>                        if(tp->pflag)
> ========================cut here==========================

Uhm... the patch does not work:
On Solaris with the XXX test module I get these failures:
-- snip --
test sun_solaris_compound_misc(C.UTF-8) begins at 2011-04-13+20:33:26
        sun_solaris_compound_misc.sh[238]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/0:
Expected stdout=='MARK', got ''
        sun_solaris_compound_misc.sh[239]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/0:
Expected empty stderr, got
'/home/test001/work/ast_ksh_20110208/build_testtypeset/arch/linux.i386/bin/ksh[1]:
bf[1]: typeset: node.elements: no parent'
        sun_solaris_compound_misc.sh[240]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/0:
Unexpected exit code 1
        sun_solaris_compound_misc.sh[238]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/1:
Expected stdout=='MARK', got ''
        sun_solaris_compound_misc.sh[239]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/1:
Expected empty stderr, got
'/home/test001/work/ast_ksh_20110208/build_testtypeset/arch/linux.i386/bin/ksh[1]:
typeset: node.elements: no parent'
        sun_solaris_compound_misc.sh[240]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/1:
Unexpected exit code 1
        sun_solaris_compound_misc.sh[238]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/2:
Expected stdout=='MARK', got ''
        sun_solaris_compound_misc.sh[239]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/2:
Expected empty stderr, got
'/home/test001/work/ast_ksh_20110208/build_testtypeset/arch/linux.i386/bin/ksh[1]:
wrap[1]: bf[1]: typeset: node.elements: no parent'
        sun_solaris_compound_misc.sh[240]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/2:
Unexpected exit code 1
        sun_solaris_compound_misc.sh[238]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/3:
Expected stdout=='MARK', got ''
        sun_solaris_compound_misc.sh[239]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/3:
Expected empty stderr, got
'/home/test001/work/ast_ksh_20110208/build_testtypeset/arch/linux.i386/bin/ksh[1]:
wrap[1]: typeset: node.elements: no parent'
        sun_solaris_compound_misc.sh[240]:
test_implicit_node_creation_through_nameref_in_local_associative_array_in_function/3:
Unexpected exit code 1
test sun_solaris_compound_misc(C.UTF-8) failed at 2011-04-13+20:33:27
with exit code 12 [ 48 tests 12 errors ]
-- snip --

The basic problem is that $ ./arch/linux.i386/bin/ksh -c 'set -o
errexit ; function bf { nameref treename=$1 ; nodepath="treename" ;
nameref x="$nodepath" ; compound -A x.nodes ; nameref
node=treename.nodes[4] ; node=() ; typeset +p node.elements ; } ;
compound c ; bf c ; print "MARK"' # now fails with a...
-- snip --
typeset: node.elements: no parent
-- snip --

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

Attachment: sun_solaris_compound_misc.sh.bz2
Description: BZip2 compressed data

_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to