Yes I think that you must always incref the results. Also consider using Py_XINCREF and Py_XDECREF which handle the case where you pass a null pointer.
A good idea is to test your code with the help of the
sys.getrefcount() function. For example
>>> class A:
... pass
...
>>> a = A()
>>> sys.getrefcount(a)
2
>>> L =[a, a, a]
>>> sys.getrefcount(a)
5
With this, you can check the refcounts before and after various calls to your C functions.
Last edited by Gribouillis; Nov 3rd, 2009 at 4:52 pm.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Offline 2,655 posts
since Jul 2008