On Saturday 04 March 2006 11:04, Andrey Borzenkov wrote: > [moved to workers] > > On Thursday 02 March 2006 20:52, Francisco Borges wrote: > > % typeset -U dirstack > > > > and the shell crashed. > > The problem is rather non-trivial. dirsgetfn returns array built on-the-fly > in heap, while typeset -U calls uniqarray() that tries to zfree array > elements. There are at least two problems here: > > - typeset -U is not prepared to deal with "pseudo" parameters at all. It > assumes a->getfn() returns pointer to real parameter value. So it would > have not worked for dirstack anyway > > - I was about to change typeset -U to pm->gsu.a->setfn(pm, > pm->gsu.a->getfn(pm)) (basically doing foo=($foo)) and adding uniqarray > call to dirssetfn() when I realized that it would not help at all in this > case as dirssetfn() tries to free passed value too; so it would have > crashed just the same. > > Apparently to solve it in general we need one of > > - per-parameter type ->uniq function (is it an overkill?) Possibly > generalized to per-parameter ->setflags function. > > - some way to know if passed pointer was allocated from heap or not. I > guess it should be possible; something like isheap(p)? > Assuming the issue with freeing heap memory is resolved, the patch adds support for -U to dirstack. It also adds framework for adding uniqueness support to any parameter by changing typeset to simply do equiv. of 'foo=($foo)'. It also uncovered one case of using free() instead of zfree(); assuming previous patch is accepted it is necessary to audit code and replace all plain free() with zfree(). -andrey