__doc__ refcounts

Robin Becker robin at jessikat.fsnet.co.uk
Sun Sep 10 02:50:47 CEST 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