Hi!

----

The following testcase (derived from the "typeset -m" demo in
http://lists.research.att.com/pipermail/ast-users/2013q2/003879.html)
crashes ast-ksh.2013-04-22 on SuSE 12.3/AMD64/64bit...
-- snip --
typeset -T printfish_t=(
        typeset fname

        function unset
        {
                printf '# fish %q died.\n' "${_.fname}"
        }
)

function createfish_t
{
        nameref ret=$1
        typeset fishname="$2"

        printfish_t f
        f.fname="$fishname"

        # return the object via nameref _only_ if it
        # is a true fish
        if [[ "${f.fname}" == ~(Ei)(coelacanth|trout) ]] ; then
                typeset -m 'ret=f'
        fi

        return 0
}

function main
{
        compound c
        compound -a c.cx
        compound c.cx[4][9].ca

        print '# creating objects...'
        createfish_t c.cx[4][9].ca.shark 'coelacanth'
        createfish_t c.cx[4][9].ca.horse 'horse'
        createfish_t c.cx[4][9].ca.trout 'trout'
        print '# ... objects created.'

        print -v c
}

# program start.
set -o nounset

print '# calling main...'
main
print '# main done.'
-- snip --
... the stack trace looks like this:
-- snip --
Program received signal SIGSEGV, Segmentation fault.
nv_hasdisc (np=0x7ffff7e235b0, dp=0x7fdfc0 <array_disc>) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvdisc.c:779
779                     if(fp->disc== dp)
(gdb) where
#0  nv_hasdisc (np=0x7ffff7e235b0, dp=0x7fdfc0 <array_disc>) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvdisc.c:779
#1  0x000000000042a7f2 in nv_arrayptr (np=0x30ec8348e5894855) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/array.c:941
#2  0x00000000004207e0 in next_type (np=0x7ffff7e23788,
root=0x7ffff7e23330, fp=0x7ffff7e236b0)
    at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvtype.c:645
#3  0x0000000000469ca6 in nextnode (dp=0x7ffff7fbee90) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvtree.c:275
#4  0x0000000000469dfe in nv_dirnext (dir=0x7ffff7fbee90) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvtree.c:307
#5  0x000000000046cac1 in walk_tree (np=0x7ffff7fcfcf0, xp=0x0,
flags=0) at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvtree.c:1078
#6  0x000000000046cebf in nv_getvtree (np=0x7ffff7fcfcf0,
fp=0x7ffff7fcfd50) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvtree.c:1180
#7  0x000000000041a6c8 in nv_getv (np=0x7ffff7fcfcf0,
nfp=0x30ec8348e5894855) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/nvdisc.c:59
#8  0x000000000046653f in nv_getval (np=0x7ffff7fcfcf0) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/name.c:2778
#9  0x00000000004a5dbb in fmtbase64 (shp=0x815600 <sh>, iop=0x8143a0
<_Sfstdout>, string=0x7ffff7e21371 "c", alt=0)
    at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/bltins/print.c:612
#10 0x00000000004a513b in b_print (argc=3, argv=0x7ffff7e213b8,
context=0x815b50 <sh+1360>)
    at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/bltins/print.c:338
#11 0x0000000000487e15 in sh_exec (shp=0x815600 <sh>,
t=0x7ffff7e21300, flags=6) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c:1357
#12 0x000000000048ae97 in sh_exec (shp=0x815600 <sh>,
t=0x7ffff7e21300, flags=6) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c:2222
#13 0x0000000000490d06 in sh_funscope_20120720 (shp=0x815600 <sh>,
argn=1, argv=0x7ffff7fb4670, fun=0x0, arg=0x7fffffffd850, execflg=4)
    at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c:4067
#14 0x000000000048ee7b in sh_funct (shp=0x815600 <sh>,
np=0x7ffff7e20c30, argn=1, argv=0x7ffff7fb4670, envlist=0x0,
execflg=4)
    at 
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c:3376
#15 0x000000000048892f in sh_exec (shp=0x815600 <sh>,
t=0x7ffff7fb4610, flags=4) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/xec.c:1555
#16 0x0000000000419f3d in exfile (shp=0x815600 <sh>,
iop=0x7ffff7e1f070, fno=11) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/main.c:588
#17 0x0000000000419108 in sh_main (ac=2, av=0x7fffffffe1c8,
userinit=0x0) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/main.c:360
#18 0x00000000004181a1 in main (argc=2, argv=0x7fffffffe1c8) at
/home/test001/work/ast_ksh_20130422/build_i386_64bit_debug/src/cmd/ksh93/sh/pmain.c:45
-- snip --

----

Bye,
Roland


P.S.: Below is the original demo from
http://lists.research.att.com/pipermail/ast-users/2013q2/003879.html
...

---------- Forwarded message ----------
From: Roland Mainz <[email protected]>
Date: Sat, Apr 27, 2013 at 11:29 AM
Subject: Passing (variable) objects between functions...
To: AST / Korn Shell Users List <[email protected]>


Hi!

----

[Per offlist request for a "typeset -m" demo and to answer the
question how to abort object creation _after_ it has been created...]

The following demo shows how to pass variables/objects via
namerefs+typeset -m (move variables) between shell functions... in
this demo the function "createfish_t" creates a function-local (=in
the functions local scope) variable of type "printfish_t" and then
validates whether the object represents a "real" fish... if "yes" it
returns the object via nameref (which stores it as a member of the
compound variable "c" of the calling "main" function) ... otherwise
the object remains in the scope of function "createfish_t" and is
destroyed when the function exists.
-- snip --
typeset -T printfish_t=(
        typeset fname

        function unset
        {
                printf '# fish %q died.\n' "${_.fname}"
        }
)

function createfish_t
{
        nameref ret=$1
        typeset fishname="$2"

        printfish_t f
        f.fname="$fishname"

        # return the object via nameref _only_ if it
        # is a true fish
        if [[ "${f.fname}" == ~(Ei)(coelacanth|trout) ]] ; then
                typeset -m 'ret=f'
        fi

        return 0
}

function main
{
        compound c

        print '# creating objects...'
        createfish_t c.shark 'coelacanth'
        createfish_t c.horse 'horse'
        createfish_t c.trout 'trout'
        print '# ... objects created.'

        print -v c
}

# program start.
set -o nounset

print '# calling main...'
main
print '# main done.'
-- snip --

Output should look like this (ast-ksh.2013-04-22 prints this CORRECT :-) ):
-- snip --
# calling main...
# creating objects...
# fish horse died.
# ... objects created.
(
        printfish_t shark=(
                fname=coelacanth
        )
        printfish_t trout=(
                fname=trout
        )
)
# fish coelacanth died.
# fish trout died.
# main done.
-- snip --

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to