[Python-3000] PyObject_HEAD_INIT

Roger Binns rogerb at rogerbinns.com
Fri Nov 21 20:47:58 CET 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

M.-A. Lemburg wrote:
> Starting with Python 3, you have to use PyVarObject_HEAD_INIT()
> on PyVarObjects and PyObject_HEAD_INIT() on PyObjects. I don't
> see the problem. It's just another change to remember when porting
> to Python 3.

The problem is that unless you are clairvoyant you have no way of
knowing about this change.  Even in rc3 the documentation shows the old
(wrong) way:

  http://docs.python.org/dev/3.0/extending/newtypes.html

PyObject_HEAD_INIT is documented:

  http://docs.python.org/dev/3.0/search.html?q=PyObject_HEAD_INIT

PyVarObject_HEAD_INIT is not:

  http://docs.python.org/dev/3.0/search.html?q=PyVarObject_HEAD_INIT

So anyone porting from Python 2 to Python 3 is just going to compile
their code.  There will be some warnings but if they consult the docs
the code will still look correct.  They will just assume it is a Python
quirk.  Then the code will run and crash and they will have to examine
the Python 3 source to work out what the underlying issue is and how to
fix it.

If PyObject_HEAD_INIT were removed/renamed then the code wouldn't even
compile and so they would realize they have to fix it.

>  * PyNumberMethods have changed due to removal of the division,
...
>  * PySequenceMethods have changed, but maintained binary compatibility
>    (why ?) by replacing the removed slice functions with dummy pointers
...
>  * PyBufferProcs is a completely new design

PyTypeObjects are used in every extension.  The above changes affect
fewer extensions and the compiler error/warnings will be more
meaningful.  I would have expected minor changes like these.

>  * A lot type flags were removed.

That is fine.  The Python 2 code would fail to compile so you would at
least know what to look for and about.

Roger

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEUEARECAAYFAkknEGsACgkQmOOfHg372QR6RwCeOJ6Sj2hYWPVwpHnwc9yOvG2H
2YkAmOb6VXWaqHQL+Xd7ihq9gEWLHiA=
=EwXY
-----END PGP SIGNATURE-----



More information about the Python-3000 mailing list