bpo-39573: Porting to Python 3.10: Py_SET_SIZE() macro by vstinner · Pull Request #20610 · python/cpython (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, the C language is so surprising sometimes :-) I designed Py_SET_SIZE() as a static inline function to ensure that the result is void and to prevent strange usage. But I didn't know that return Py_SET_TYPE(my_obj, some_type), (...); was legit.

I updated macros to use , (void)0. According to https://stackoverflow.com/a/25021889 this syntax is endorsed by the C standard, since NDEBUG uses #define assert(ignore) ((void)0).