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 vstinner
Recipients vstinner
Date 2021-10-14.21:17:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634246251.33.0.982878943146.issue45476@roundup.psfhosted.org>
In-reply-to
Content
The Python C API provides "AS" functions to convert an object to another type, like PyFloat_AS_DOUBLE(). These macros can be abused to be used as l-value: "PyFloat_AS_DOUBLE(obj) = new_value;". It prevents to change the PyFloat implementation and makes life harder for Python implementations other than CPython.

I propose to convert these macros to static inline functions to disallow using them as l-value.

I made a similar change for Py_REFCNT(), Py_TYPE() and Py_SIZE(). For these functions, I added "SET" variants: Py_SET_REFCNT(), Py_SET_TYPE(), Py_SET_SIZE(). Here, I don't think that the l-value case is legit, and so I don't see the need to add a way to *set* a value.

For example, I don't think that PyFloat_SET_DOUBLE(obj, value) would make sense. A Python float object is supposed to be immutable.
History
Date User Action Args
2021-10-14 21:17:31vstinnersetrecipients: + vstinner
2021-10-14 21:17:31vstinnersetmessageid: <1634246251.33.0.982878943146.issue45476@roundup.psfhosted.org>
2021-10-14 21:17:31vstinnerlinkissue45476 messages
2021-10-14 21:17:31vstinnercreate