You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When compiling a program that links against the Python libraries (and uses their headerfiles) with the -Werror=declaration-after-statement compiler flag enabled, the following error occurs:
/usr/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
233 | PyVarObject *var_ob = _PyVarObject_CAST(ob);
Although the C90 style may be archaic and perhaps not worth supporting at some point, maintaining support could be helpful for some downstream platforms (I encountered this in Debian bug #1057442).
Minimal test cases to show that the problem did not occur with Python 3.11.8 and that it does occur on Python 3.12.2 and to help verify any fixes.
I don't think that it's documented. It's just convenient since a few projects still use -Werror=declaration-after-statement. IMO these projects added this option when Visual Studio didn't support C99, it does now, but these projects were never updated.
In 2024, I don't see the point to support ISO C90. But the way, Python doesn't: it uses C99 "// comment" which fails with a build error with -std=c90.
But if the limited C API only exposes opaque functions, in fact, it's cheap to support -Werror=declaration-after-statement.
If tomorrow, we have a better reason to break that unwritten rule, we can revisit it.
Activity
hugovk commentedon Mar 15, 2024
The build requirements for 3.12 include:
This is since 3.11:
https://docs.python.org/3/using/configure.html
pythongh-116869: Make C API compatible with ISO C90
vstinner commentedon Mar 18, 2024
I wrote PR gh-116950 to fix the issue.
While C11 is needed to build Python itself, the C API should be usable with ISO C90.
pythongh-116869: Add test_cext test: build a C extension
pythongh-116869: Add test_cext test: build a C extension
pythongh-116869: Add test_cext test: build a C extension
pythongh-116869: Add test_cext test: build a C extension
pythongh-116869: Add test_cext test: build a C extension
pythongh-116869: Add test_cext test: build a C extension
colesbury commentedon Mar 18, 2024
Where do we document that? PEP 7 says "The public C API should be compatible with C++.", not ISO C90. ISO C90 doesn't even support the
inlinekeyword.vstinner commentedon Mar 18, 2024
I don't think that it's documented. It's just convenient since a few projects still use
-Werror=declaration-after-statement. IMO these projects added this option when Visual Studio didn't support C99, it does now, but these projects were never updated.In 2024, I don't see the point to support ISO C90. But the way, Python doesn't: it uses C99 "// comment" which fails with a build error with
-std=c90.But if the limited C API only exposes opaque functions, in fact, it's cheap to support
-Werror=declaration-after-statement.If tomorrow, we have a better reason to break that unwritten rule, we can revisit it.
colesbury commentedon Mar 18, 2024
So we are not at all supporting ISO C90... we are just supporting
-Werror=declaration-after-statement.Are these packages using the limited API? The linked issue #92781 does not look like it uses the limited API.
If we are going to enforce an unwritten rule, we should at the very least document it.
vstinner commentedon Mar 18, 2024
I agree on writing down the rule. Also, I'm working on an unit test (starting with PR gh-116954) to avoid future regression.
43 remaining items
pythongh-116869: Test the limited C API in test_cext (python#116995)
pythongh-116869: Fix test_cext on RHEL7 (python#117010)
pythongh-116869: Fix test_cext for Free Threading (python#117043)
pythongh-116869: Enable -Werror in test_cext for Free Threading (pyth…
Squashed commit of the following:
Squashed commit of the following:
pythongh-116869: Fix redefinition of the _PyOptimizerObject type (pyt…
pythongh-116869: Add test_cext test: build a C extension (python#116954)
pythongh-116869: Make C API compatible with ISO C90 (python#116950)
pythongh-116869: Enable test_cext and test_cppext on Free Threading b…
pythongh-116869: Build test_cext with -Werror=declaration-after-state…
pythongh-116869: Test the limited C API in test_cext (python#116995)
pythongh-116869: Fix test_cext on RHEL7 (python#117010)
pythongh-116869: Fix test_cext for Free Threading (python#117043)
pythongh-116869: Enable -Werror in test_cext for Free Threading (pyth…