why PyObject_VAR_HEAD?
Benjamin Peterson
benjamin at python.org
Mon Jun 29 22:30:18 EDT 2009
kio <lehchao <at> gmail.com> writes:
>
> Hi,
>
> I'm studying the CPython source code. I don’t quite understand why
> they’re using PyObject_VAR_HEAD to define struct like PyListObject. To
> define such kind of struct, could I use _PyObject_HEAD_EXTRA as a
> header and add "items" pointer and "allocated" count explicity? Is
> there any difference?
No, PyObject_VAR_HEAD adds a ob_size field, which is used to indicate the size
of the list. PyList uses this just as a convenience; it does not actually use
varsize mallocing. You could use PyObject_HEAD if you added an additional size
field.
More information about the Python-list
mailing list