> The best way would be to let Cython do it for you, instead of calling the
> function yourself. ;)

I definitely agree, but here I couldn't find any other way to do it.

> What function do you mean?
>
> For example, Cython uses PyDict_Next() when looping over a dictionary, so
> there is no need to call that function yourself. Other use cases may get
> optimised into a direct C-API call in a similar fashion.

That's exactly the function I'm using.  My use case is iterating
through a tree-like structure, where each node holds a dict of values
and/or branches.  When I encounter a branch, I iterate recursively
over that branch before continuing iteration locally.  The best way of
implementing this, at least that I found, is to use a stack of node
dictionaries references + position variables and invoke PyDict_Next()
while pushing/popping as needed.

I now implemented it using the intermediate variable method given
above.  It works great.  I assume you still have to have the "ctypedef
void PyObject" in the extern block; correct?

BTW, this solution:

> You can do <PyObject*>a, so do &(<PyObject*>a) to get a PyObject**

gives me the error message

/home/hoytak/workspace/paramtree/paramtree/paramtree.pyx:648:31:
Taking address of non-lvalue

Is that a bug?

Thanks for everyones help!

--Hoyt
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to