This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xiang.zhang
Recipients loewis, martin.panter, ned.deily, rhettinger, serhiy.storchaka, vstinner, xiang.zhang
Date 2016-04-22.09:29:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461317359.76.0.126419309052.issue26824@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-04-22 09:29:19xiang.zhangsetrecipients: + xiang.zhang, loewis, rhettinger, vstinner, ned.deily, martin.panter, serhiy.storchaka
2016-04-22 09:29:19xiang.zhangsetmessageid: <1461317359.76.0.126419309052.issue26824@psf.upfronthosting.co.za>
2016-04-22 09:29:19xiang.zhanglinkissue26824 messages
2016-04-22 09:29:19xiang.zhangcreate