Skip to content

[BUG] Compilation error with Python 3.13 on macOS #6385

Closed as not planned
Closed as not planned

Description

@dnicolodi

Describe the bug

Compiling for Python 3.13 on macOS results in a compilation error:

cc -Isiphash24.cpython-313-darwin.so.p -I. -I.. -Isubprojects/libcsiphash-1/src -I../subprojects/libcsiphash-1/src -Isubprojects/libcstdaux-1/src -I../subprojects/libcstdaux-1/src -I/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13 -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -Wall -Winvalid-pch -std=c99 -O3 -MD -MQ siphash24.cpython-313-darwin.so.p/meson-generated_siphash24.pyx.c.o -MF siphash24.cpython-313-darwin.so.p/meson-generated_siphash24.pyx.c.o.d -o siphash24.cpython-313-darwin.so.p/meson-generated_siphash24.pyx.c.o -c siphash24.cpython-313-darwin.so.p/siphash24.pyx.c
In file included from siphash24.cpython-313-darwin.so.p/siphash24.pyx.c:27782:
In file included from /Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_frame.h:13:
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_code.h:493:15: error: expected parameter declarator
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
              ^
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_backoff.h:113:33: note: expanded from macro 'COLD_EXIT_INITIAL_VALUE'
#define COLD_EXIT_INITIAL_VALUE 64
                                ^
In file included from siphash24.cpython-313-darwin.so.p/siphash24.pyx.c:27782:
In file included from /Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_frame.h:13:
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_code.h:493:15: error: expected ')'
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_backoff.h:113:33: note: expanded from macro 'COLD_EXIT_INITIAL_VALUE'
#define COLD_EXIT_INITIAL_VALUE 64
                                ^
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_code.h:493:14: note: to match this '('
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
             ^
/Library/Frameworks/Python.framework/Versions/3.13/include/python3.13/internal/pycore_code.h:493:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
^

The same code works fine when using other Python versions or Python 3.13 on Windows or Linux. If I decode the C compiler error message correctly, it seems that static_assert() is not defined. I think this is a "bug" caused by the CPython header missing a required include, but Cython is using an internal header, thus it should probably make sure that prerequisites are satisfied.

Code to reproduce the behaviour:

# example code

Expected behaviour

No response

OS

macOS

Python version

3.13b2

Cython version

git master

Additional context

No response

Activity

  1. dnicolodi commented on Sep 5, 2024

    @dnicolodi
    ContributorAuthor

    python3.13/internal/pycore_code.h uses static_assert() but does not include python3.13/pymacro.h which makes sure that static_assert() is defined in some setups. However, this is not the problem at hand. CPython 3.13 requires C11 support, which implies that static_assert() should be defined. Indeed, compiling with -std=c11 solves the issue. Does Cython require C11?

  2. scoder commented on Sep 6, 2024

    @scoder
    Contributor

    Does Cython require C11?

    No, it requires C99. I'll report the issue to CPython.

    EDIT: I see that you already reported python/cpython#123747

  3. scoder commented on Sep 6, 2024

    @scoder
    Contributor

    Do you include pycore_code.h yourself or is it the #include in Cython that strikes here? Cython generated modules should always have #include "Python.h" before all other C includes, which should avoid the issue at hand according to the comments in the CPython ticket.

  4. scoder commented on Sep 6, 2024

    @scoder
    Contributor

    Note that CPython 3.13 is really close to its final release. If we find anything to fix on their side, now is the time.

  5. dnicolodi commented on Sep 6, 2024

    @dnicolodi
    ContributorAuthor

    pycore_code.h is included (indirectly via pycore_frame.h) by Cython itself.

    The issue is that static_assert() is defined only when compiling with -std=c11 or later. The definition in pymacro.h is there only for cases where static_assert() should be defined but for some reason is not. It does not add a definition that works when compiling with a C standard older than C11. Thus including Python.h or not does not make a difference.

    Since at least Python 3.13, C11 is required to build CPython, therefore the CPython internal headers assume support for all C11 features (I think the public header is still C99 or even C89 compatible). Cython includes CPython internal headers, thus it should also require C11 or it should define compatibility shims to be used for older C standard versions. I think requiring C11 (at least when building for CPython 3.13) is the easiest way forward.

  6. vstinner commented on Sep 6, 2024

    @vstinner
    Contributor

    Can you provide a reproducer?

  7. scoder commented on Sep 6, 2024

    @scoder
    Contributor

    I reopened the CPython ticket and nominated it as release blocker.

  8. scoder commented on Sep 6, 2024

    @scoder
    Contributor

    python/cpython#123747 was resolved in CPython.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions