From 935eef8dc6346a260709c4ffd72f3d00d0066f2b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 20 Nov 2023 15:52:00 +0200 Subject: [PATCH] gh-111863: Rename `Py_NOGIL` to `Py_GIL_DISABLED` (#111864) Rename Py_NOGIL to Py_GIL_DISABLED --- Include/cpython/pystate.h | 2 +- Include/internal/pycore_critical_section.h | 6 ++--- Include/internal/pycore_importdl.h | 2 +- Include/internal/pycore_lock.h | 6 ++--- Include/internal/pycore_object.h | 14 +++++----- Include/object.h | 26 +++++++++---------- Lib/sysconfig/__init__.py | 2 +- Lib/test/libregrtest/utils.py | 2 +- Lib/test/pythoninfo.py | 2 +- Lib/test/support/__init__.py | 2 +- Lib/test/test_cppext/__init__.py | 2 +- Lib/test/test_importlib/test_windows.py | 2 +- Lib/test/test_sys.py | 2 +- ...-11-08-20-28-03.gh-issue-111863.RPeFAX.rst | 1 + Modules/_ctypes/_ctypes_test.c | 4 +-- Modules/_multiprocessing/posixshmem.c | 4 +-- Modules/_scproxy.c | 4 +-- Modules/_stat.c | 4 +-- Modules/_sysconfig.c | 4 +-- Modules/_testcapi/heaptype_relative.c | 4 +-- Modules/_testcapi/vectorcall_limited.c | 4 +-- Modules/_testclinic_limited.c | 4 +-- Modules/_testimportmultiple.c | 4 +-- .../test_critical_sections.c | 4 +-- Modules/_uuidmodule.c | 4 +-- Modules/errnomodule.c | 4 +-- Modules/hashlib.h | 2 +- Modules/resource.c | 4 +-- Modules/xxlimited.c | 4 +-- Modules/xxlimited_35.c | 4 +-- Objects/object.c | 6 ++--- PC/winsound.c | 2 +- PCbuild/pyproject.props | 2 +- Python/ceval.c | 4 +-- Python/lock.c | 2 +- Python/pystate.c | 4 +-- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 6 ++--- 39 files changed, 82 insertions(+), 81 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2023-11-08-20-28-03.gh-issue-111863.RPeFAX.rst diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 34e23830f27e776..56172d231c44f4e 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -151,7 +151,7 @@ struct _ts { /* Tagged pointer to top-most critical section, or zero if there is no * active critical section. Critical sections are only used in - * `--disable-gil` builds (i.e., when Py_NOGIL is defined to 1). In the + * `--disable-gil` builds (i.e., when Py_GIL_DISABLED is defined to 1). In the * default build, this field is always zero. */ uintptr_t critical_section; diff --git a/Include/internal/pycore_critical_section.h b/Include/internal/pycore_critical_section.h index 73c2e243f20bcc0..bf2bbfffc38bd0f 100644 --- a/Include/internal/pycore_critical_section.h +++ b/Include/internal/pycore_critical_section.h @@ -86,7 +86,7 @@ extern "C" { #define _Py_CRITICAL_SECTION_TWO_MUTEXES 0x2 #define _Py_CRITICAL_SECTION_MASK 0x3 -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED # define Py_BEGIN_CRITICAL_SECTION(op) \ { \ _PyCriticalSection _cs; \ @@ -104,13 +104,13 @@ extern "C" { # define Py_END_CRITICAL_SECTION2() \ _PyCriticalSection2_End(&_cs2); \ } -#else /* !Py_NOGIL */ +#else /* !Py_GIL_DISABLED */ // The critical section APIs are no-ops with the GIL. # define Py_BEGIN_CRITICAL_SECTION(op) # define Py_END_CRITICAL_SECTION() # define Py_BEGIN_CRITICAL_SECTION2(a, b) # define Py_END_CRITICAL_SECTION2() -#endif /* !Py_NOGIL */ +#endif /* !Py_GIL_DISABLED */ typedef struct { // Tagged pointer to an outer active critical section (or 0). diff --git a/Include/internal/pycore_importdl.h b/Include/internal/pycore_importdl.h index dee64241c763f3b..c8583582b358ac1 100644 --- a/Include/internal/pycore_importdl.h +++ b/Include/internal/pycore_importdl.h @@ -31,7 +31,7 @@ typedef FARPROC dl_funcptr; # define PYD_DEBUG_SUFFIX "" #endif -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED # define PYD_THREADING_TAG "t" #else # define PYD_THREADING_TAG "" diff --git a/Include/internal/pycore_lock.h b/Include/internal/pycore_lock.h index 25c3cf5377b7780..f135cbbc3754fba 100644 --- a/Include/internal/pycore_lock.h +++ b/Include/internal/pycore_lock.h @@ -33,11 +33,11 @@ extern "C" { // ... // PyMutex_Unlock(&m); -// NOTE: In Py_NOGIL builds, `struct _PyMutex` is defined in Include/object.h. -// The Py_NOGIL builds need the definition in Include/object.h for the +// NOTE: In Py_GIL_DISABLED builds, `struct _PyMutex` is defined in Include/object.h. +// The Py_GIL_DISABLED builds need the definition in Include/object.h for the // `ob_mutex` field in PyObject. For the default (non-free-threaded) build, // we define the struct here to avoid exposing it in the public API. -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED struct _PyMutex { uint8_t v; }; #endif diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 206d8a5d4cc5e13..f413b8451e5ab49 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -54,7 +54,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *); Furthermore, we can't use designated initializers in Extensions since these are not supported pre-C++20. Thus, keeping an internal copy here is the most backwards compatible solution */ -#if defined(Py_NOGIL) +#if defined(Py_GIL_DISABLED) #define _PyObject_HEAD_INIT(type) \ { \ .ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \ @@ -103,7 +103,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n) #ifdef Py_REF_DEBUG _Py_AddRefTotal(_PyInterpreterState_GET(), n); #endif -#if !defined(Py_NOGIL) +#if !defined(Py_GIL_DISABLED) op->ob_refcnt += n; #else if (_Py_IsOwnedByCurrentThread(op)) { @@ -128,7 +128,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n) static inline void _Py_SetImmortal(PyObject *op) { if (op) { -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED op->ob_tid = _Py_UNOWNED_TID; op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL; op->ob_ref_shared = 0; @@ -145,7 +145,7 @@ static inline void _Py_SetMortal(PyObject *op, Py_ssize_t refcnt) { if (op) { assert(_Py_IsImmortal(op)); -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED op->ob_tid = _Py_UNOWNED_TID; op->ob_ref_local = 0; op->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED); @@ -169,7 +169,7 @@ static inline void _Py_ClearImmortal(PyObject *op) op = NULL; \ } while (0) -#if !defined(Py_NOGIL) +#if !defined(Py_GIL_DISABLED) static inline void _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct) { @@ -210,7 +210,7 @@ _Py_DECREF_NO_DEALLOC(PyObject *op) } #else -// TODO: implement Py_DECREF specializations for Py_NOGIL build +// TODO: implement Py_DECREF specializations for Py_GIL_DISABLED build static inline void _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct) { @@ -238,7 +238,7 @@ _Py_REF_IS_QUEUED(Py_ssize_t ob_ref_shared) // Merge the local and shared reference count fields and add `extra` to the // refcount when merging. Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra); -#endif // !defined(Py_NOGIL) +#endif // !defined(Py_GIL_DISABLED) #ifdef Py_REF_DEBUG # undef _Py_DEC_REFTOTAL diff --git a/Include/object.h b/Include/object.h index 061b5093fb1a350..6b70a4948444767 100644 --- a/Include/object.h +++ b/Include/object.h @@ -106,9 +106,9 @@ check by comparing the reference count field to the immortality reference count. #define _Py_IMMORTAL_REFCNT (UINT_MAX >> 2) #endif -// Py_NOGIL builds indicate immortal objects using `ob_ref_local`, which is +// Py_GIL_DISABLED builds indicate immortal objects using `ob_ref_local`, which is // always 32-bits. -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED #define _Py_IMMORTAL_REFCNT_LOCAL UINT32_MAX #endif @@ -117,7 +117,7 @@ check by comparing the reference count field to the immortality reference count. // Make all internal uses of PyObject_HEAD_INIT immortal while preserving the // C-API expectation that the refcnt will be set to 1. -#if defined(Py_NOGIL) +#if defined(Py_GIL_DISABLED) #define PyObject_HEAD_INIT(type) \ { \ 0, \ @@ -162,7 +162,7 @@ check by comparing the reference count field to the immortality reference count. * by hand. Similarly every pointer to a variable-size Python object can, * in addition, be cast to PyVarObject*. */ -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED struct _object { #if (defined(__GNUC__) || defined(__clang__)) \ && !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) @@ -238,7 +238,7 @@ typedef struct { PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y); #define Py_Is(x, y) ((x) == (y)) -#if defined(Py_NOGIL) && !defined(Py_LIMITED_API) +#if defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) static inline uintptr_t _Py_ThreadId(void) { @@ -275,7 +275,7 @@ _Py_IsOwnedByCurrentThread(PyObject *ob) #endif static inline Py_ssize_t Py_REFCNT(PyObject *ob) { -#if !defined(Py_NOGIL) +#if !defined(Py_GIL_DISABLED) return ob->ob_refcnt; #else uint32_t local = _Py_atomic_load_uint32_relaxed(&ob->ob_ref_local); @@ -316,7 +316,7 @@ static inline Py_ssize_t Py_SIZE(PyObject *ob) { static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op) { -#if defined(Py_NOGIL) +#if defined(Py_GIL_DISABLED) return op->ob_ref_local == _Py_IMMORTAL_REFCNT_LOCAL; #elif SIZEOF_VOID_P > 4 return _Py_CAST(PY_INT32_T, op->ob_refcnt) < 0; @@ -350,7 +350,7 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { if (_Py_IsImmortal(ob)) { return; } -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED ob->ob_refcnt = refcnt; #else if (_Py_IsOwnedByCurrentThread(ob)) { @@ -367,7 +367,7 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { ob->ob_ref_local = 0; ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED); } -#endif // Py_NOGIL +#endif // Py_GIL_DISABLED #endif // Py_LIMITED_API+0 < 0x030d0000 } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 @@ -746,7 +746,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) #else // Non-limited C API and limited C API for Python 3.9 and older access // directly PyObject.ob_refcnt. -#if defined(Py_NOGIL) +#if defined(Py_GIL_DISABLED) uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local); uint32_t new_local = local + 1; if (new_local == 0) { @@ -784,7 +784,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) #endif -#if !defined(Py_LIMITED_API) && defined(Py_NOGIL) +#if !defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED) // Implements Py_DECREF on objects not owned by the current thread. PyAPI_FUNC(void) _Py_DecRefShared(PyObject *); PyAPI_FUNC(void) _Py_DecRefSharedDebug(PyObject *, const char *, int); @@ -810,7 +810,7 @@ static inline void Py_DECREF(PyObject *op) { } #define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op)) -#elif defined(Py_NOGIL) && defined(Py_REF_DEBUG) +#elif defined(Py_GIL_DISABLED) && defined(Py_REF_DEBUG) static inline void Py_DECREF(const char *filename, int lineno, PyObject *op) { uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local); @@ -835,7 +835,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op) } #define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op)) -#elif defined(Py_NOGIL) +#elif defined(Py_GIL_DISABLED) static inline void Py_DECREF(PyObject *op) { uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local); diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 68d30c0f9e618f1..2a7fa45be079de7 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -348,7 +348,7 @@ def _init_non_posix(vars): vars['BINLIBDEST'] = get_path('platstdlib') vars['INCLUDEPY'] = get_path('include') - # Add EXT_SUFFIX, SOABI, and Py_NOGIL + # Add EXT_SUFFIX, SOABI, and Py_GIL_DISABLED vars.update(_sysconfig.config_vars()) vars['LIBDIR'] = _safe_realpath(os.path.join(get_config_var('installed_base'), 'libs')) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index bd4dce3400f0a93..e4a28af381ee2da 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -290,7 +290,7 @@ def get_build_info(): build = [] # --disable-gil - if sysconfig.get_config_var('Py_NOGIL'): + if sysconfig.get_config_var('Py_GIL_DISABLED'): build.append("nogil") if hasattr(sys, 'gettotalrefcount'): diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py index 3a91a7dbc650216..49e41ca6cdaf98c 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -517,7 +517,7 @@ def collect_sysconfig(info_add): 'PY_STDMODULE_CFLAGS', 'Py_DEBUG', 'Py_ENABLE_SHARED', - 'Py_NOGIL', + 'Py_GIL_DISABLED', 'SHELL', 'SOABI', 'abs_builddir', diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index bb9f998db4622b5..eec5498e633eb68 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -796,7 +796,7 @@ def check_cflags_pgo(): return any(option in cflags_nodist for option in pgo_options) -if sysconfig.get_config_var('Py_NOGIL'): +if sysconfig.get_config_var('Py_GIL_DISABLED'): _header = 'PHBBInP' else: _header = 'nP' diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py index 4d9ee3cb2228aee..299a16ada2e32ef 100644 --- a/Lib/test/test_cppext/__init__.py +++ b/Lib/test/test_cppext/__init__.py @@ -15,7 +15,7 @@ # gh-110119: pip does not currently support 't' in the ABI flag use by # --disable-gil builds. Once it does, we can remove this skip. -@unittest.skipIf(sysconfig.get_config_var('Py_NOGIL') == 1, +@unittest.skipIf(sysconfig.get_config_var('Py_GIL_DISABLED') == 1, 'test does not work with --disable-gil') @support.requires_subprocess() class TestCPPExt(unittest.TestCase): diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py index a60a4c4cebcf1ab..d25133240b1afdb 100644 --- a/Lib/test/test_importlib/test_windows.py +++ b/Lib/test/test_importlib/test_windows.py @@ -112,7 +112,7 @@ def test_module_not_found(self): class WindowsExtensionSuffixTests: def test_tagged_suffix(self): suffixes = self.machinery.EXTENSION_SUFFIXES - abi_flags = "t" if sysconfig.get_config_var("Py_NOGIL") else "" + abi_flags = "t" if sysconfig.get_config_var("Py_GIL_DISABLED") else "" ver = sys.version_info platform = re.sub('[^a-zA-Z0-9]', '_', get_platform()) expected_tag = f".cp{ver.major}{ver.minor}{abi_flags}-{platform}.pyd" diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index b111962abdcdc32..ae73f5a7de7421d 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1209,7 +1209,7 @@ def test_pystats(self): @unittest.skipUnless(hasattr(sys, 'abiflags'), 'need sys.abiflags') def test_disable_gil_abi(self): abi_threaded = 't' in sys.abiflags - py_nogil = (sysconfig.get_config_var('Py_NOGIL') == 1) + py_nogil = (sysconfig.get_config_var('Py_GIL_DISABLED') == 1) self.assertEqual(py_nogil, abi_threaded) diff --git a/Misc/NEWS.d/next/C_API/2023-11-08-20-28-03.gh-issue-111863.RPeFAX.rst b/Misc/NEWS.d/next/C_API/2023-11-08-20-28-03.gh-issue-111863.RPeFAX.rst new file mode 100644 index 000000000000000..9e9145ceecf567d --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2023-11-08-20-28-03.gh-issue-111863.RPeFAX.rst @@ -0,0 +1 @@ +Rename ``Py_NOGIL`` to ``Py_GIL_DISABLED``. Patch by Hugo van Kemenade. diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c index 5869d8f952d1843..d33e6fc7586d286 100644 --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -1,8 +1,8 @@ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/_multiprocessing/posixshmem.c b/Modules/_multiprocessing/posixshmem.c index cd08a9fedc05784..425ce10075c1565 100644 --- a/Modules/_multiprocessing/posixshmem.c +++ b/Modules/_multiprocessing/posixshmem.c @@ -2,9 +2,9 @@ posixshmem - A Python extension that provides shm_open() and shm_unlink() */ -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/_scproxy.c b/Modules/_scproxy.c index 9f7a65c91e2d337..7920d2c2b8739dd 100644 --- a/Modules/_scproxy.c +++ b/Modules/_scproxy.c @@ -4,10 +4,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/_stat.c b/Modules/_stat.c index 9e278d6dcd1589d..1ef1e97f4b7dcae 100644 --- a/Modules/_stat.c +++ b/Modules/_stat.c @@ -12,10 +12,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.13 for PyModule_Add() on Windows #define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_sysconfig.c b/Modules/_sysconfig.c index 6f1cc16b58467d6..2918913c18ed1e9 100644 --- a/Modules/_sysconfig.c +++ b/Modules/_sysconfig.c @@ -57,12 +57,12 @@ _sysconfig_config_vars_impl(PyObject *module) } #endif -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED PyObject *py_nogil = _PyLong_GetOne(); #else PyObject *py_nogil = _PyLong_GetZero(); #endif - if (PyDict_SetItemString(config, "Py_NOGIL", py_nogil) < 0) { + if (PyDict_SetItemString(config, "Py_GIL_DISABLED", py_nogil) < 0) { Py_DECREF(config); return NULL; } diff --git a/Modules/_testcapi/heaptype_relative.c b/Modules/_testcapi/heaptype_relative.c index b58d26cddc723ac..52286f05f7154ce 100644 --- a/Modules/_testcapi/heaptype_relative.c +++ b/Modules/_testcapi/heaptype_relative.c @@ -1,8 +1,8 @@ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED #define Py_LIMITED_API 0x030c0000 // 3.12 #endif diff --git a/Modules/_testcapi/vectorcall_limited.c b/Modules/_testcapi/vectorcall_limited.c index 857cb30b3da1cac..0a650f1b351d2dd 100644 --- a/Modules/_testcapi/vectorcall_limited.c +++ b/Modules/_testcapi/vectorcall_limited.c @@ -1,10 +1,10 @@ /* Test Vectorcall in the limited API */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED #define Py_LIMITED_API 0x030c0000 // 3.12 #endif diff --git a/Modules/_testclinic_limited.c b/Modules/_testclinic_limited.c index c5d07e1370dac84..61bc84134458dab 100644 --- a/Modules/_testclinic_limited.c +++ b/Modules/_testclinic_limited.c @@ -5,10 +5,10 @@ #undef Py_BUILD_CORE_BUILTIN #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // For now, only limited C API 3.13 is supported #define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c index 99d48b6617f49ca..245e81b2dce7f8f 100644 --- a/Modules/_testimportmultiple.c +++ b/Modules/_testimportmultiple.c @@ -5,10 +5,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED #define Py_LIMITED_API 0x03020000 #endif diff --git a/Modules/_testinternalcapi/test_critical_sections.c b/Modules/_testinternalcapi/test_critical_sections.c index 9392096a16d1bf4..1f7e311558b27cb 100644 --- a/Modules/_testinternalcapi/test_critical_sections.c +++ b/Modules/_testinternalcapi/test_critical_sections.c @@ -6,7 +6,7 @@ #include "pycore_critical_section.h" -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED #define assert_nogil assert #define assert_gil(x) #else @@ -25,7 +25,7 @@ test_critical_sections(PyObject *self, PyObject *Py_UNUSED(args)) assert(d2 != NULL); // Beginning a critical section should lock the associated object and - // push the critical section onto the thread's stack (in Py_NOGIL builds). + // push the critical section onto the thread's stack (in Py_GIL_DISABLED builds). Py_BEGIN_CRITICAL_SECTION(d1); assert_nogil(PyMutex_IsLocked(&d1->ob_mutex)); assert_nogil(_PyCriticalSection_IsActive(PyThreadState_GET()->critical_section)); diff --git a/Modules/_uuidmodule.c b/Modules/_uuidmodule.c index 1d716051df4ade6..d8b211c632eef16 100644 --- a/Modules/_uuidmodule.c +++ b/Modules/_uuidmodule.c @@ -4,10 +4,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index 1e2c55a1a26b4b9..8287edbfb47f6c8 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -1,10 +1,10 @@ /* Errno module */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/hashlib.h b/Modules/hashlib.h index 25b2aaadfb28688..7105e68af7b806f 100644 --- a/Modules/hashlib.h +++ b/Modules/hashlib.h @@ -58,7 +58,7 @@ PyMutex_Unlock(&(obj)->mutex); \ } -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED #define HASHLIB_INIT_MUTEX(obj) \ do { \ (obj)->mutex = (PyMutex){0}; \ diff --git a/Modules/resource.c b/Modules/resource.c index 87c44607df1c4cd..a4b8f648c329e32 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -1,8 +1,8 @@ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.13 for PySys_Audit() #define Py_LIMITED_API 0x030d0000 #endif diff --git a/Modules/xxlimited.c b/Modules/xxlimited.c index 21d7e9ba67ad78c..19f61216255cfa1 100644 --- a/Modules/xxlimited.c +++ b/Modules/xxlimited.c @@ -63,10 +63,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/Modules/xxlimited_35.c b/Modules/xxlimited_35.c index 04673ea68cfee5f..867820a6cb93fae 100644 --- a/Modules/xxlimited_35.c +++ b/Modules/xxlimited_35.c @@ -6,10 +6,10 @@ */ #ifndef _MSC_VER -#include "pyconfig.h" // Py_NOGIL +#include "pyconfig.h" // Py_GIL_DISABLED #endif -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED #define Py_LIMITED_API 0x03050000 #endif diff --git a/Objects/object.c b/Objects/object.c index 1f5b2b4f79e5fa9..d145674cb3ba34d 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -296,7 +296,7 @@ _Py_DecRef(PyObject *o) Py_DECREF(o); } -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED # ifdef Py_REF_DEBUG static inline int is_shared_refcnt_dead(Py_ssize_t shared) @@ -414,7 +414,7 @@ _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra) _Py_atomic_store_uintptr_relaxed(&op->ob_tid, 0); return refcnt; } -#endif /* Py_NOGIL */ +#endif /* Py_GIL_DISABLED */ /**************************************/ @@ -2359,7 +2359,7 @@ new_reference(PyObject *op) _PyTraceMalloc_NewReference(op); } // Skip the immortal object check in Py_SET_REFCNT; always set refcnt to 1 -#if !defined(Py_NOGIL) +#if !defined(Py_GIL_DISABLED) op->ob_refcnt = 1; #else op->ob_tid = _Py_ThreadId(); diff --git a/PC/winsound.c b/PC/winsound.c index d1ff991c934bae0..b0e416cfec46996 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -35,7 +35,7 @@ winsound.PlaySound(None, 0) */ -#ifndef Py_NOGIL +#ifndef Py_GIL_DISABLED // Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED #define Py_LIMITED_API 0x030c0000 #endif diff --git a/PCbuild/pyproject.props b/PCbuild/pyproject.props index bb3555bd123089b..0acc7045c39a269 100644 --- a/PCbuild/pyproject.props +++ b/PCbuild/pyproject.props @@ -40,7 +40,7 @@ $(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)Include\internal\mimalloc;$(PySourcePath)PC;$(IntDir);%(AdditionalIncludeDirectories) WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions) - Py_NOGIL=1;%(PreprocessorDefinitions) + Py_GIL_DISABLED=1;%(PreprocessorDefinitions) _Py_USING_PGO=1;%(PreprocessorDefinitions) MaxSpeed diff --git a/Python/ceval.c b/Python/ceval.c index ae515780440ecbe..ba234dc57744729 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -46,13 +46,13 @@ # error "ceval.c must be build with Py_BUILD_CORE define for best performance" #endif -#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_NOGIL) +#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_GIL_DISABLED) // GH-89279: The MSVC compiler does not inline these static inline functions // in PGO build in _PyEval_EvalFrameDefault(), because this function is over // the limit of PGO, and that limit cannot be configured. // Define them as macros to make sure that they are always inlined by the // preprocessor. -// TODO: implement Py_DECREF macro for Py_NOGIL +// TODO: implement Py_DECREF macro for Py_GIL_DISABLED #undef Py_DECREF #define Py_DECREF(arg) \ diff --git a/Python/lock.c b/Python/lock.c index bc43b1ab192feaa..e9279f0b92a5e79 100644 --- a/Python/lock.c +++ b/Python/lock.c @@ -21,7 +21,7 @@ static const _PyTime_t TIME_TO_BE_FAIR_NS = 1000*1000; // Spin for a bit before parking the thread. This is only enabled for // `--disable-gil` builds because it is unlikely to be helpful if the GIL is // enabled. -#if Py_NOGIL +#if Py_GIL_DISABLED static const int MAX_SPIN_COUNT = 40; #else static const int MAX_SPIN_COUNT = 0; diff --git a/Python/pystate.c b/Python/pystate.c index 89e9bddc6de060d..6196b15da0117a2 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1857,7 +1857,7 @@ tstate_deactivate(PyThreadState *tstate) static int tstate_try_attach(PyThreadState *tstate) { -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED int expected = _Py_THREAD_DETACHED; if (_Py_atomic_compare_exchange_int( &tstate->state, @@ -1877,7 +1877,7 @@ static void tstate_set_detached(PyThreadState *tstate) { assert(tstate->state == _Py_THREAD_ATTACHED); -#ifdef Py_NOGIL +#ifdef Py_GIL_DISABLED _Py_atomic_store_int(&tstate->state, _Py_THREAD_DETACHED); #else tstate->state = _Py_THREAD_DETACHED; diff --git a/configure b/configure index 5e86e8255c03d0d..319009537f461c4 100755 --- a/configure +++ b/configure @@ -7883,7 +7883,7 @@ printf "%s\n" "$disable_gil" >&6; } if test "$disable_gil" = "yes" then -printf "%s\n" "#define Py_NOGIL 1" >>confdefs.h +printf "%s\n" "#define Py_GIL_DISABLED 1" >>confdefs.h # Add "t" for "threaded" ABIFLAGS="${ABIFLAGS}t" diff --git a/configure.ac b/configure.ac index f46e19ba4be3f89..b78472e04846b78 100644 --- a/configure.ac +++ b/configure.ac @@ -1505,7 +1505,7 @@ AC_MSG_RESULT([$disable_gil]) if test "$disable_gil" = "yes" then - AC_DEFINE([Py_NOGIL], [1], + AC_DEFINE([Py_GIL_DISABLED], [1], [Define if you want to disable the GIL]) # Add "t" for "threaded" ABIFLAGS="${ABIFLAGS}t" diff --git a/pyconfig.h.in b/pyconfig.h.in index 2bbc1bdd52dc0e0..bf708926e22c435 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1611,13 +1611,13 @@ /* Defined if Python is built as a shared library. */ #undef Py_ENABLE_SHARED +/* Define if you want to disable the GIL */ +#undef Py_GIL_DISABLED + /* Define hash algorithm for str, bytes and memoryview. SipHash24: 1, FNV: 2, SipHash13: 3, externally defined: 0 */ #undef Py_HASH_ALGORITHM -/* Define if you want to disable the GIL */ -#undef Py_NOGIL - /* Define if you want to enable internal statistics gathering. */ #undef Py_STATS