8000 Work around the deprecation of Py_OptimizeFlag in Py3.12 by reading t… · scoder/cython@dfcf447 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfcf447

Browse files
committed
Work around the deprecation of Py_OptimizeFlag in Py3.12 by reading the value from the interpreter's current PyConfig.
See python/cpython#99872
1 parent 6add7fe commit dfcf447

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Cython/Compiler/Builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def init_builtins():
422422

423423
builtin_scope.declare_var(
424424
'__debug__', PyrexTypes.c_const_type(PyrexTypes.c_bint_type),
425-
pos=None, cname='(!Py_OptimizeFlag)', is_cdef=True)
425+
pos=None, cname='(!__pyx_get_Py_OptimizeFlag())', is_cdef=True)
426426

427427
global list_type, tuple_type, dict_type, set_type, frozenset_type
428428
global bytes_type, str_type, unicode_type, basestring_type, slice_type

Cython/Compiler/Nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6946,7 +6946,7 @@ def analyse_expressions(self, env):
69466946

69476947
def generate_execution_code(self, code):
69486948
code.putln("#ifndef CYTHON_WITHOUT_ASSERTIONS")
6949-
code.putln("if (unlikely(!Py_OptimizeFlag)) {")
6949+
code.putln("if (unlikely(!__pyx_get_Py_OptimizeFlag())) {")
69506950
code.mark_pos(self.pos)
69516951
self.condition.generate_evaluation_code(code)
69526952
code.putln(

Cython/Utility/ModuleSetupCode.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,15 @@ class __Pyx_FakeReference {
604604
/////////////// PythonCompatibility ///////////////
605605

606606
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
607-
#define Py_OptimizeFlag 0
607+
#define __pyx_get_Py_OptimizeFlag() (0)
608+
#elif PY_VERSION_HEX < 0x03080000 || CYTHON_COMPILING_IN_PYPY || defined(Py_LIMITED_API)
609+
#define __pyx_get_Py_OptimizeFlag() (Py_OptimizeFlag)
610+
#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030900A6
611+
// Py3.8+ has PyConfig from PEP 587, but only Py3.9 added read access to it.
612+
// Py_OptimizeFlag is deprecated in Py3.12+
613+
#define __pyx_get_Py_OptimizeFlag() (_PyInterpreterState_GetConfig(__Pyx_PyThreadState_Current->interp)->optimization_level)
614+
#else
615+
#define __pyx_get_Py_OptimizeFlag() (Py_OptimizeFlag)
608616
#endif
609617

610618
#define __PYX_BUILD_PY_SSIZE_T "n"

0 commit comments

Comments
 (0)
0