__doc__ refcounts

Robin Becker robin at jessikat.fsnet.co.uk
Sat Sep 9 20:50:47 EDT 2000


I'm puzzled over refcounts

I have a C extension which sets up a doc string as
        /*add in the docstring*/
        v = Py_BuildValue("s", moduleDoc);
        PyDict_SetItemString(d, "__doc__", v);

there are no other references to v or d (the module dict)

when imported getrefcount(ext.__doc__) is 4

a similar python module seems to have a __doc__ refcount of 2

so assuming one extra reference for the call to getrefcount the python
module has only 1 reference to __doc__ the C one has 3. I could
understand that perhaps I might need to decrement v's refcount, but that
would bring my rc to 2 not 1; where is the extra reference? 
-- 
Robin Becker



More information about the Python-list mailing list