Xiang Zhang added the comment: The current code is OK. But if the macro are used with arguments not of PyObject* in the future, the bugs described in PEP3123 can possibly be introduced.
The new PyObject_HEAD alone can not fix the problem. It just makes the exception happen: Standard C has one specific exception to its aliasing rules precisely designed to support the case of Python: a value of a struct type may also be accessed through a pointer to the first field. E.g. if a struct starts with an int , the struct * may also be cast to an int * , allowing to write int values into the first field. You still have to make sure accessing ob_type is via a PyObject* pointer. So the PEP also says: However, all accesses to ob_refcnt and ob_type MUST cast the object pointer to PyObject* (unless the pointer is already known to have that type), and SHOULD use the respective accessor macros. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26824> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com