version independant object usage counting

Martin v. Löwis loewis at
Mon Sep 2 09:37:49 EDT 2002

"Rolf Kalbermatter" <rolf.kalbermatter at> writes:

> However although this loader works quite fine now, I found out that
> I gained little with it because the current Python architecture is
> not really designed to link dynamically to it.

Yes, this is the case - mainly because the API changes in slight ways,
and because therefore, extension modules explicitly link to

> The problem arises in fact with the refcounting of Python
> objects. The macros Py_INCREF and Py_DECREF access directly
> structure members in the object layout and this layout is different
> for debugging and non debugging versions and potentially different
> between Python versions as well.

That is only a minor problem: those macros are correct across all
released Python versions, back to 1.4 or earlier.

> Is there a specific reason that these two API functions are not
> available and one is forced to use the according macros to do proper
> refcounting, or did I miss those functions completely?

Nobody has proposed to introduce them, because there is no need to do
so, and because other ABI changes break the ABI more often - INCREF
and DECREF have never done so, and it is unlikely that they ever will.

> Any thought about this?

Feel free to submit a patch to SourceForge. However, you might want to
consider the following issues:

- various places assume presence of the ob_type field:
  * the Py*_Check functions (e.g. PyList_Check) directly access the
    ob_type field.
  * PyObject_INIT relies on initializing the object members.
- PyType_HasFeature relies on the position of the tp_flags field
- various accessor macros rely on the internal structure, e.g.
  * PyTuple_GET_ITEM
  * PyString_AS_STRING
  * ...


More information about the Python-list mailing list