Skip to content

Python 3.12.2 headers contain non-C90-compliant code #116869

Closed

Description

@jayaddison

Bug report

Bug description:

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);

This is fairly similar to previous issue #92781.

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.
#include "/usr/include/python3.11/Python.h"
#include "/usr/include/python3.11/object.h"

int main() {}
#include "/usr/include/python3.12/Python.h"
#include "/usr/include/python3.12/object.h"

int main() {}

Compiled in either case using:

$ gcc bugreport.c -Werror=declaration-after-statement

or equivalently, using llvm v17:

$ clang-17 bugreport.c -Werror=declaration-after-statement

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Activity

  1. hugovk commented on Mar 15, 2024

    @hugovk
    Member

    The build requirements for 3.12 include:

    This is since 3.11:

    Changed in version 3.11: C11 compiler, IEEE 754 and NaN support are now required. On Windows, Visual Studio 2017 or later is required.

    https://docs.python.org/3/using/configure.html

  2. added a commit that references this issue on Mar 18, 2024
  3. vstinner commented on Mar 18, 2024

    @vstinner
    Member

    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.

  4. added 6 commits that reference this issue on Mar 18, 2024
  5. colesbury commented on Mar 18, 2024

    @colesbury
    Contributor

    While C11 is needed to build Python itself, the C API should be usable with ISO C90.

    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 inline keyword.

  6. vstinner commented on Mar 18, 2024

    @vstinner
    Member

    Where do we document that?

    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.

  7. colesbury commented on Mar 18, 2024

    @colesbury
    Contributor

    So we are not at all supporting ISO C90... we are just supporting -Werror=declaration-after-statement.

    But if the limited C API only exposes opaque functions, in fact, it's cheap to support -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 tomorrow, we have a better reason to break that unwritten rule, we can revisit it.

    If we are going to enforce an unwritten rule, we should at the very least document it.

  8. vstinner commented on Mar 18, 2024

    @vstinner
    Member

    I agree on writing down the rule. Also, I'm working on an unit test (starting with PR gh-116954) to avoid future regression.

  9. 43 remaining items

  10. added 4 commits that reference this issue on Mar 25, 2024
  11. added 9 commits that reference this issue on Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions