Repository navigation
[BUG] Compilation error with Python 3.13 on macOS #6385
Copy link
Copy link
Closed as not planned
Labels
Description
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 codeExpected behaviour
No response
OS
macOS
Python version
3.13b2
Cython version
git master
Additional context
No response
Activity
dnicolodi commentedon Sep 5, 2024
python3.13/internal/pycore_code.husesstatic_assert()but does not includepython3.13/pymacro.hwhich makes sure thatstatic_assert()is defined in some setups. However, this is not the problem at hand. CPython 3.13 requires C11 support, which implies thatstatic_assert()should be defined. Indeed, compiling with-std=c11solves the issue. Does Cython require C11?scoder commentedon Sep 6, 2024
No, it requires C99. I'll report the issue to CPython.
EDIT: I see that you already reported python/cpython#123747
scoder commentedon Sep 6, 2024
Do you include
pycore_code.hyourself or is it the#includein 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.scoder commentedon Sep 6, 2024
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.
dnicolodi commentedon Sep 6, 2024
pycore_code.his included (indirectly viapycore_frame.h) by Cython itself.The issue is that
static_assert()is defined only when compiling with-std=c11or later. The definition inpymacro.his there only for cases wherestatic_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 includingPython.hor 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.
vstinner commentedon Sep 6, 2024
Can you provide a reproducer?
scoder commentedon Sep 6, 2024
I reopened the CPython ticket and nominated it as release blocker.
scoder commentedon Sep 6, 2024
python/cpython#123747 was resolved in CPython.