[capi-sig] Python 3.x PyObject_HEAD versus PyObject_VAR_HEAD
mal at egenix.com
Mon Feb 1 11:27:21 CET 2010
Philip Semanchuk wrote:
> Hi all,
> I'm trying to port my posix_ipc extension to Python 3, and I'm confused
> by the documentation for PyObject_HEAD and PyObject_VAR_HEAD.
> My understanding is that a PyObject-derived type should begin its
> PyTypeObject struct with PyObject_HEAD and a PyVarObject-derived type
> with PyObject_VAR_HEAD. the documentation says of PyVarObject, "This
> type does not often appear in the Python/C API."
> The doc also says that PyObject_VAR_HEAD, "is used when declaring new
> types which represent objects with a length that varies from instance to
> I assumed, then, that PyObject_VAR_HEAD would also appear infrequently,
> but that's not the case at all. In fact, I can't find PyObject_HEAD used
> at all in the Python 3.1.1 source code, whereas PyObject_VAR_HEAD is
> used hundreds of times, including for objects that don't have a length
> (like the float type, for instance).
I'm not sure how you searched for these, but I get somewhat
in the Include/ dir of Python 3 (SVN)
> Is the documentation wrong, or am I misreading it? Suggestions appreciated.
The docs are correct.
PyObject_HEAD does not include the field ob_size, PyObject_VAR_HEAD
Perhaps you are confusing this with PyVarObject_HEAD_INIT() ?!
Professional Python Services directly from the Source (#1, Feb 01 2010)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the capi-sig