[pypy-issue] [issue1122] [cpyext] PyVarObject builtins and definition of Py_SIZE()

Amaury Forgeot d Arc tracker at bugs.pypy.org
Wed Apr 11 10:19:21 CEST 2012

Amaury Forgeot d Arc <amauryfa at gmail.com> added the comment:

> Py_SIZE() doesn't do any error checking in CPython, but I think the above
> would be reasonable way to work around the fact that it (by design) works
> for more objects in CPython than it can in PyPy. I don't think it matters
> if it works for more objects in PyPy than in CPython. All that really
> counts is that it works for exactly the objects it supports in CPython.

Yes. in PyPy even type-specialized functions use the abstract interface,
for example PyString_Format also works with numbers...

> it's really the
> users fault if Py_SIZE() is used on something other than a PyVarObject.

> Tuple and bytes objects can be fixed by making them PyVarObjects, but not
> bytearray and listobject. They have their own Py*_GET_SIZE() macros,
> however. We could require portable code to use those instead of Py_SIZE().
> Not a big deal, IMHO.

This seems to contradict what you said earlier: Py_SIZE() should work
for all types it supports in CPython.
Py_SIZE() should use ob_size when there is one, and fall back to
PyObject_Size() in other cases.

Support for longs can come later -- this type has more issues, like direct access
to underlying storage.

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list