Uh oh!
There was an error while loading. Please reload this page.
[DRAFT] gh-105059: C99 avoids PyObject.ob_refcnt union - #105767
Conversation
Only define PyObject.ob_refcnt as an anonymous union on C11 and newer, or when GCC is used. If GCC is used on C99 and older, add __extension__ on the union. On C99 and older without GCC, Py_INCREF() and Py_DECREF() are implemented as function calls.
When the Python C API is used with GCC and clang, I'm pretty sure that I don't know if MSC has pragma to turn off the compiler warning on "Compiler Warning (level 4) C4201": "nonstandard extension used: nameless struct/union". |
vstinner
commented
Jun 14, 2023
For now, my PR implements Py_INCREF() and Py_DECREF() as opaque function calls on C99 and newer. Maybe later, this code path can still be optimized to inline the code. But a solution without anonymous union should be found for that. |
vstinner
commented
Jun 14, 2023
To test this PR, I added the following code to #ifdef_PYOBJECT_REFCNT_ANON_UNIONprintf("PyObject.ob_refcnt is an union\n");
#elseprintf("PyObject.ob_refcnt type is Py_ssize_t\n");
#endifAnd I modified |
vstinner
commented
Jul 25, 2023
This change can have a significant negative impact on performance, so I abandon it and instead try to get rid of the compiler warning: PR #107232. |
Only define PyObject.ob_refcnt as an anonymous union on C11 and newer, or when GCC is used. If GCC is used on C99 and older, add extension on the union. On C99 and older without GCC, Py_INCREF() and Py_DECREF() are implemented as function calls.