Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: LinkList implementation



On Sunday 28 of February 2010 01:33:24 Michael Hwang wrote:
> In the process of writing a new builtin, I discovered an oddity of
> zsh's implementation of LinkList, which is a doubly linked list.
> 
> LinkList alist = newlinklist();
> LinkNode node;
> for (node = lastnode(alist); node; decnode(alist)) {
>      ((SomeStructPointer) getdata(node))->someField;
> }
> 
BTW decnode applies to node, not list - it should be decnode(node)

> Since no nodes have been added to the LinkList, one would expect the
> body of the loop to not run at all.

Well, you have to accept that and use another termination condition, 
like e.g. in zle_hist.c:isearch_newpos():

        for (node = lastnode(matchlist);
             node != (LinkNode)matchlist; decnode(node)) {

For the sake of purity this actually should be
             node != &matchlist->node

The games linklist.c plays are really daunting ... but to change it now 
you have to carefully go through all of code to adjust snippets like 
above.

Attachment: signature.asc
Description: This is a digitally signed message part.



Messages sorted by: Reverse Date, Date, Thread, Author