[Python-3000] PyObject_HEAD_INIT
Roger Binns
rogerb at rogerbinns.com
Fri Nov 21 19:58:15 CET 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
M.-A. Lemburg wrote:
> You might get warnings (esp. from GCC), but I have yet to see a compiler
> that doesn't map the above to the same memory.
They don't map the same as Adam showed. Your fields end up off by one
which is why the compiler is giving warnings.
> After all, Python 2 has been using this layout for years without any
> compiler warnings or segfaults because of this.
Instead of speculating, please write some Python 3 code to initialize a
PyTypeObject using the Python 2 way and look at what the compiler is
showing.
> Right. Things are now more standard compliant and you get fewer
> warnings.
The underlying structures also changed.
> BTW: With the "few thousand extensions" I was referring to the current
> use of the PyObject_HEAD_INIT() macro which you wanted to remove, not
> to a few thousand extensions using it correctly. Note that it's rather
> uncommon to create singletons like the type objects in C.
That means you are agreeing with what I said in the first place! You
*cannot* use PyObject_HEAD_INIT to initialize a PyTypeObject in Python
3. The fields end up misaligned. You *have to* change to using
PyVarObject_HEAD_INIT. As you point out Py{Var,}Object_HEAD_INIT is for
singleton static objects and other than type objects is very uncommon in
C. I couldn't find any.
The reason I am suggesting removing PyObject_HEAD_INIT from Python 3 is
because there are no demonstrated uses of it. Python 2 code being
ported will be using it, but will be using it incorrectly to initialize
PyTypeObjects. The compiler will issue warnings, but not errors. The
code will then run and probably crash in various interesting ways.
Every single extension author porting to Python 3 is going to encounter
this. If PyObject_HEAD_INIT is removed then their code won't compile
and they will have to work out what is going on.
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkknBMMACgkQmOOfHg372QR8xgCghQs2f1+O0p7anwRPRlGyM+fV
7lAAmgIj2FYcqvQ9XTAdQ1C+38/CD0g1
=VFDH
-----END PGP SIGNATURE-----
More information about the Python-3000
mailing list