Message263990
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. |
|
Date |
User |
Action |
Args |
2016-04-22 09:29:19 | xiang.zhang | set | recipients:
+ xiang.zhang, loewis, rhettinger, vstinner, ned.deily, martin.panter, serhiy.storchaka |
2016-04-22 09:29:19 | xiang.zhang | set | messageid: <1461317359.76.0.126419309052.issue26824@psf.upfronthosting.co.za> |
2016-04-22 09:29:19 | xiang.zhang | link | issue26824 messages |
2016-04-22 09:29:19 | xiang.zhang | create | |
|