Hi!
----
The following testcase (which is a variation of the object stack
demo... with the twist of pushing an objstack_t as stack entry of
another objstack_t...) ...
-- snip --
function _assert
{
integer line=$1
shift
print -u2 -f "ASSERT line=${line}: %q\n" "$@"
# exit 1
}
alias _assert='_assert $LINENO'
# stack of objects
typeset -T objstack_t=(
compound -a st
integer st_n=0
# push an object
# argument is the name of a variable which will
# be moved into the stack space
function pushobj
{
nameref obj=$1
typeset -m "_.st[$((_.st_n++))].obj=obj"
}
# print absolute variable name of object in head
function printhead
{
printf '%s%s\n' "${!_}" ".st[${_.st_n}].obj"
}
# pop an object and return it to the location
# specified by the variable name passed in
function popobj
{
nameref obj=$1
typeset -m "obj=_.st[$((--_.st_n))].obj"
# "obj" should be removed from _.st[_.st_n] by
# now... complain if there are any "leftovers"
s="$(typeset -p _.st[_.st_n].obj)"
[[ "$s" == '' ]] || \
_assert "_.st[_.st_n].obj == \"$s\""
# remove empty array node which was created
# when "pushobj" moved the obj into the array
[[ "$(typeset -p _.st[_.st_n])" != '' ]] || \
_assert "_.st[_.st_n] is gone"
# unset _.st[_.st_n]
}
)
function main
{
compound c
objstack_t c.ost
# push some objects
compound foo=( integer val=5 )
c.ost.pushobj foo
# create, fill and push another stack object
compound sc
objstack_t sc.s
compound c1=( integer a=1 )
compound c2=( integer a=2 )
sc.s.pushobj c1
sc.s.pushobj c2
c.ost.pushobj sc
print -v c
return 0
}
set -o nounset
main
-- snip --
... crashes ast-ksh.2013-05-03+latest patches when
VMALLOC_OPTIONS=abort is set like this:
-- snip --
$ VMALLOC_OPTIONS=abort ~/bin/ksh stk.sh
Memory fault(coredump)
$ dbx - core
Corefile specified executable: "/home/test001/bin/ksh"
For information about new features see `help changes'
[snip]
program terminated by signal SEGV (no mapping at the fault address)
Current function is nv_name
3712 if(!(table=shp->last_table) || *np->nvname=='.' ||
table==shp->namespace || np==table)
(dbx) where
=>[1] nv_name(np = 0xfffffd7fff0ac950), line 3712 in "name.c"
[2] nv_name(np = 0xfffffd7fff0c0f30), line 3724 in "name.c"
[3] name_chtype(np = 0xfffffd7fff0acbf8, fp = 0xfffffd7fff0acb88),
line 222 in "nvtype.c"
[4] nv_name(np = 0xfffffd7fff0acbf8), line 3709 in "name.c"
[5] nv_dirnext(dir = 0xfffffd7fff0c0d70), line 326 in "nvtree.c"
[6] walk_tree(np = 0xfffffd7fff0bf9e0, xp = 0xfffffd7fff0bffc0,
flags = 201326592), line 1118 in "nvtree.c"
[7] clone_tree(np = 0xfffffd7fff0bf9e0, mp = 0xfffffd7fff0bffc0,
flags = 201326592, fp = 0xfffffd7fff0ac850), line 94 in "nvtree.c"
[8] clone_all_disc(np = 0xfffffd7fff0bf9e0, mp = 0xfffffd7fff0bffc0,
flags = 201326592), line 894 in "nvdisc.c"
[9] nv_clone(np = 0xfffffd7fff0bf9e0, mp = 0xfffffd7fff0bffc0, flags
= 201326592), line 945 in "nvdisc.c"
[10] nv_rename(np = 0xfffffd7fff0bffc0, flags = 134218240), line
3347 in "name.c"
[11] setall(argv = 0xfffffd7fff0e5e78, flag = 134218240, troot =
0xfffffd7fff0c07b0, tp = 0xfffffd7fffdfe830), line 720 in "typeset.c"
[12] b_typeset(argc = 3, argv = 0xfffffd7fff0e5e70, context =
0x6b8900), line 455 in "typeset.c"
[13] sh_exec(shp = 0x6b8438, t = 0xfffffd7fff0a81b0, flags = 6),
line 1357 in "xec.c"
[14] sh_exec(shp = 0x6b8438, t = 0xfffffd7fff0a81b0, flags = 6),
line 2222 in "xec.c"
[15] sh_funscope_20120720(shp = 0x6b8438, argn = 2, argv =
0xfffffd7fff0abb00, fun = (nil), arg = 0xfffffd7fffdfef18, execflg =
4), line 4067 in "xec.c"
[16] sh_funct(shp = 0x6b8438, np = 0xfffffd7fff0a9b20, argn = 2,
argv = 0xfffffd7fff0abb00, envlist = (nil), execflg = 4), line 3376 in
"xec.c"
[17] sh_exec(shp = 0x6b8438, t = 0xfffffd7fff0aba10, flags = 4),
line 1555 in "xec.c"
[18] sh_exec(shp = 0x6b8438, t = 0xfffffd7fff0abdb0, flags = 6),
line 2218 in "xec.c"
[19] sh_funscope_20120720(shp = 0x6b8438, argn = 1, argv =
0xfffffd7fff0e5be0, fun = (nil), arg = 0xfffffd7fffdff5b8, execflg =
4), line 4067 in "xec.c"
[20] sh_funct(shp = 0x6b8438, np = 0xfffffd7fff0ac1b0, argn = 1,
argv = 0xfffffd7fff0e5be0, envlist = (nil), execflg = 4), line 3376 in
"xec.c"
[21] sh_exec(shp = 0x6b8438, t = 0xfffffd7fff0e5b80, flags = 4),
line 1555 in "xec.c"
[22] exfile(shp = 0x6b8438, iop = 0xfffffd7fff0a6fb0, fno = 11),
line 588 in "main.c"
[23] sh_main(ac = 2, av = 0xfffffd7fffdffad8, userinit = (nil)),
line 360 in "main.c"
[24] main(argc = 2, argv = 0xfffffd7fffdffad8), line 45 in "pmain.c"
(dbx) print shp
shp = (nil)
-- 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