From 19f67cb1f4ab66b87b1bdfc881bb875faed8c1a3 Mon Sep 17 00:00:00 2001 From: da-woods Date: Thu, 23 May 2024 17:44:49 +0100 Subject: [PATCH] Rename to "CYTHON_COMPILING_IN_CPYTHON_FREETHREADING" (#6213) Because we're finding in other contexts that "nogil" seems ambiguous with the "with nogil" feature, consistency is good, and it's an early enough stage that we can change this. --- Cython/Compiler/Code.py | 4 ++-- Cython/Compiler/Nodes.py | 4 ++-- Cython/Runtime/refnanny.pyx | 2 +- Cython/Utility/ModuleSetupCode.c | 28 ++++++++++++++-------------- tests/compile/buildenv.pyx | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index fc04100108b..9a247777226 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -2721,12 +2721,12 @@ def put_release_ensured_gil(self, variable=None): def put_acquire_freethreading_lock(self): self.globalstate.use_utility_code( UtilityCode.load_cached("AccessPyMutexForFreeThreading", "ModuleSetupCode.c")) - self.putln("#if CYTHON_COMPILING_IN_CPYTHON_NOGIL") + self.putln("#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING") self.putln(f"PyMutex_Lock(&{Naming.parallel_freethreading_mutex});") self.putln("#endif") def put_release_freethreading_lock(self): - self.putln("#if CYTHON_COMPILING_IN_CPYTHON_NOGIL") + self.putln("#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING") self.putln(f"PyMutex_Unlock(&{Naming.parallel_freethreading_mutex});") self.putln("#endif") diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 25b8e982ce4..6c5af4ca7dd 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -9464,7 +9464,7 @@ def privatize_temps(self, code, exclude_temps=()): UtilityCode.load_cached( "SharedInFreeThreading", "ModuleSetupCode.c")) - c.put(f" __Pyx_shared_in_cpython_nogil({Naming.parallel_freethreading_mutex})") + c.put(f" __Pyx_shared_in_cpython_freethreading({Naming.parallel_freethreading_mutex})") c.put(" private(%s, %s, %s)" % self.pos_info) c.put(" shared(%s)" % ', '.join(shared_vars)) @@ -9776,7 +9776,7 @@ def end_parallel_control_flow_block( if self.error_label_used: c.putln("const char *%s = NULL; int %s = 0, %s = 0;" % self.parallel_pos_info) c.putln("PyObject *%s = NULL, *%s = NULL, *%s = NULL;" % self.parallel_exc) - c.putln("#if CYTHON_COMPILING_IN_CPYTHON_NOGIL") + c.putln("#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING") c.putln(f"PyMutex {Naming.parallel_freethreading_mutex} = {{0}};") c.putln("#endif") diff --git a/Cython/Runtime/refnanny.pyx b/Cython/Runtime/refnanny.pyx index 1a46be0f556..a80ec988052 100644 --- a/Cython/Runtime/refnanny.pyx +++ b/Cython/Runtime/refnanny.pyx @@ -8,7 +8,7 @@ cimport cython cdef extern from *: """ - #if CYTHON_COMPILING_IN_CPYTHON_NOGIL + #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING static CYTHON_INLINE int __Pyx_refnanny_init_lock(PyThread_type_lock* lock) { *lock = PyThread_allocate_lock(); if (!*lock) { diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c index cf537277ca8..d0344b2aed9 100644 --- a/Cython/Utility/ModuleSetupCode.c +++ b/Cython/Utility/ModuleSetupCode.c @@ -66,7 +66,7 @@ #define CYTHON_COMPILING_IN_LIMITED_API 0 #define CYTHON_COMPILING_IN_GRAAL 1 - #define CYTHON_COMPILING_IN_CPYTHON_NOGIL 0 + #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 @@ -126,7 +126,7 @@ #define CYTHON_COMPILING_IN_LIMITED_API 0 #define CYTHON_COMPILING_IN_GRAAL 0 - #define CYTHON_COMPILING_IN_CPYTHON_NOGIL 0 + #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0 #undef CYTHON_USE_TYPE_SLOTS #define CYTHON_USE_TYPE_SLOTS 0 @@ -198,7 +198,7 @@ #define CYTHON_COMPILING_IN_LIMITED_API 1 #define CYTHON_COMPILING_IN_GRAAL 0 - #define CYTHON_COMPILING_IN_CPYTHON_NOGIL 0 + #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0 // CYTHON_CLINE_IN_TRACEBACK is currently disabled for the Limited API #undef CYTHON_CLINE_IN_TRACEBACK @@ -266,9 +266,9 @@ #define CYTHON_COMPILING_IN_GRAAL 0 #ifdef Py_GIL_DISABLED - #define CYTHON_COMPILING_IN_CPYTHON_NOGIL 1 + #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 1 #else - #define CYTHON_COMPILING_IN_CPYTHON_NOGIL 0 + #define CYTHON_COMPILING_IN_CPYTHON_FREETHREADING 0 #endif #ifndef CYTHON_USE_TYPE_SLOTS @@ -286,7 +286,7 @@ #ifndef CYTHON_USE_PYLONG_INTERNALS #define CYTHON_USE_PYLONG_INTERNALS 1 #endif - #if CYTHON_COMPILING_IN_CPYTHON_NOGIL + #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING #undef CYTHON_USE_PYLIST_INTERNALS // Use thread-safe CPython C API calls to manipulate list contents #define CYTHON_USE_PYLIST_INTERNALS 0 @@ -296,7 +296,7 @@ #ifndef CYTHON_USE_UNICODE_INTERNALS #define CYTHON_USE_UNICODE_INTERNALS 1 #endif - #if CYTHON_COMPILING_IN_CPYTHON_NOGIL || PY_VERSION_HEX >= 0x030B00A2 + #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING || PY_VERSION_HEX >= 0x030B00A2 // Python 3.11a2 hid _PyLong_FormatAdvancedWriter and _PyFloat_FormatAdvancedWriter // therefore disable unicode writer until a better alternative appears #undef CYTHON_USE_UNICODE_WRITER @@ -322,7 +322,7 @@ #ifndef CYTHON_FAST_THREAD_STATE #define CYTHON_FAST_THREAD_STATE 1 #endif - #if CYTHON_COMPILING_IN_CPYTHON_NOGIL + #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING #undef CYTHON_FAST_GIL #define CYTHON_FAST_GIL 0 #elif !defined(CYTHON_FAST_GIL) @@ -352,7 +352,7 @@ #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 1 #endif - #if CYTHON_COMPILING_IN_CPYTHON_NOGIL + #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING #undef CYTHON_USE_DICT_VERSIONS #define CYTHON_USE_DICT_VERSIONS 0 #elif !defined(CYTHON_USE_DICT_VERSIONS) @@ -366,7 +366,7 @@ #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 #endif #ifndef CYTHON_USE_FREELISTS - #define CYTHON_USE_FREELISTS (!CYTHON_COMPILING_IN_CPYTHON_NOGIL) + #define CYTHON_USE_FREELISTS (!CYTHON_COMPILING_IN_CPYTHON_FREETHREADING) #endif #endif @@ -2233,7 +2233,7 @@ static PyObject* __Pyx_PyCode_New( /////////////////////////// AccessPyMutexForFreeThreading.proto //////////// -#if CYTHON_COMPILING_IN_CPYTHON_NOGIL +#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING // TODO - this is likely to get exposed properly at some point #ifndef Py_BUILD_CORE #define Py_BUILD_CORE 1 @@ -2243,8 +2243,8 @@ static PyObject* __Pyx_PyCode_New( ////////////////////////// SharedInFreeThreading.proto ////////////////// -#if CYTHON_COMPILING_IN_CPYTHON_NOGIL -#define __Pyx_shared_in_cpython_nogil(x) shared(x) +#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING +#define __Pyx_shared_in_cpython_freethreading(x) shared(x) #else -#define __Pyx_shared_in_cpython_nogil(x) +#define __Pyx_shared_in_cpython_freethreading(x) #endif \ No newline at end of file diff --git a/tests/compile/buildenv.pyx b/tests/compile/buildenv.pyx index f1752888a64..11468646824 100644 --- a/tests/compile/buildenv.pyx +++ b/tests/compile/buildenv.pyx @@ -37,7 +37,7 @@ cdef extern from *: cdef int CYTHON_COMPILING_IN_LIMITED_API cdef int CYTHON_COMPILING_IN_PYPY cdef int CYTHON_COMPILING_IN_GRAAL - cdef int CYTHON_COMPILING_IN_CPYTHON_NOGIL + cdef int CYTHON_COMPILING_IN_CPYTHON_FREETHREADING cdef int CYTHON_USE_PYLONG_INTERNALS cdef int CYTHON_USE_PYLIST_INTERNALS cdef int CYTHON_USE_UNICODE_INTERNALS @@ -83,7 +83,7 @@ CYTHON_COMPILING_IN_LIMITED_API {CYTHON_COMPILING_IN_LIMITED_API} CYTHON_COMPILING_IN_PYPY {CYTHON_COMPILING_IN_PYPY} CYTHON_COMPILING_IN_GRAAL {CYTHON_COMPILING_IN_GRAAL} -CYTHON_COMPILING_IN_CPYTHON_NOGIL {CYTHON_COMPILING_IN_CPYTHON_NOGIL} +CYTHON_COMPILING_IN_CPYTHON_FREETHREADING {CYTHON_COMPILING_IN_CPYTHON_FREETHREADING} CYTHON_USE_PYLONG_INTERNALS {CYTHON_USE_PYLONG_INTERNALS} CYTHON_USE_PYLIST_INTERNALS {CYTHON_USE_PYLIST_INTERNALS}