Hello,
Please forgive my ignorance, but I am running into a problem that
reveals my ignorance of reference counting and Cython in general.
I am running code that creates a dictionary, fills it with lists of
tuples created from C integers, and returns the dictionary, like this:
def afunc():
cdef int i=1
cdef int j=2
cdef int k=3
cdef int m=4
cdef int n=5
d = {}
val1 = (i, j)
val2 = (k, m)
d[m] = [val1, val2]
return d
The code above does indeed return the dictionary I was expecting:
{5: [(1, 2), (3, 4)]}
however, in a more complex routine, I am doing a similar thing, but
returning many thousands of lists of tuples, and the routine grinds to
a halt. If I only return lists of integers, as in:
d[m] = [i, j]
The code runs at good speed and returns the expected result.
Looking at the generated C code, I wonder if I am running into a
reference counting problem, because the tuple I'm creating seems to be
decref'ed.
I've tried adding Py_INCREFs to the list, tuple, and python copies of
the integers, but this made no difference to the larger routine.
I realize I'm not understanding on-the-fly python object creation /
destruction in Cython, and was wondering where I should go to look to
understand it better. Is there anything obvious I have missed that
would explain my problem?
Thanks a lot,
Matthew
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev