[docs] [issue29165] Use forward compatible macro in example code for creating new type
INADA Naoki
report at bugs.python.org
Tue Feb 21 04:59:25 EST 2017
INADA Naoki added the comment:
> but the code with PyObject_HEAD_INIT() doesn't look incompatible with Python 3.
It's incompatible actually.
https://github.com/python/cpython/blob/2.7/Include/object.h
/* PyObject_HEAD defines the initial segment of every PyObject. */
#define PyObject_HEAD_INIT(type) \
_PyObject_EXTRA_INIT \
1, type,
https://github.com/python/cpython/blob/3.5/Include/object.h
#define PyObject_HEAD_INIT(type) \
{ _PyObject_EXTRA_INIT \
1, type },
I noticed PyVarObject_HEAD_INIT is compatible, and simplified an extension I maintain.
https://github.com/PyMySQL/mysqlclient-python/commit/2feb5ed6850a3905edf0333e0cd11ea6218f0f4f
This small doc change helps people who writing Python 2's extension module now, and port it to Python 3 later.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29165>
_______________________________________
More information about the docs
mailing list