Skip to content

Commit 935eef8

Browse files
hugovkaisk
authored andcommitted
pythongh-111863: Rename Py_NOGIL to Py_GIL_DISABLED (python#111864)
Rename Py_NOGIL to Py_GIL_DISABLED
1 parent 16fd370 commit 935eef8

39 files changed

+82
-81
lines changed

Include/cpython/pystate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct _ts {
151151

152152
/* Tagged pointer to top-most critical section, or zero if there is no
153153
* active critical section. Critical sections are only used in
154-
* `--disable-gil` builds (i.e., when Py_NOGIL is defined to 1). In the
154+
* `--disable-gil` builds (i.e., when Py_GIL_DISABLED is defined to 1). In the
155155
* default build, this field is always zero.
156156
*/
157157
uintptr_t critical_section;

Include/internal/pycore_critical_section.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern "C" {
8686
#define _Py_CRITICAL_SECTION_TWO_MUTEXES 0x2
8787
#define _Py_CRITICAL_SECTION_MASK 0x3
8888

89-
#ifdef Py_NOGIL
89+
#ifdef Py_GIL_DISABLED
9090
# define Py_BEGIN_CRITICAL_SECTION(op) \
9191
{ \
9292
_PyCriticalSection _cs; \
@@ -104,13 +104,13 @@ extern "C" {
104104
# define Py_END_CRITICAL_SECTION2() \
105105
_PyCriticalSection2_End(&_cs2); \
106106
}
107-
#else /* !Py_NOGIL */
107+
#else /* !Py_GIL_DISABLED */
108108
// The critical section APIs are no-ops with the GIL.
109109
# define Py_BEGIN_CRITICAL_SECTION(op)
110110
# define Py_END_CRITICAL_SECTION()
111111
# define Py_BEGIN_CRITICAL_SECTION2(a, b)
112112
# define Py_END_CRITICAL_SECTION2()
113-
#endif /* !Py_NOGIL */
113+
#endif /* !Py_GIL_DISABLED */
114114

115115
typedef struct {
116116
// Tagged pointer to an outer active critical section (or 0).

Include/internal/pycore_importdl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef FARPROC dl_funcptr;
3131
# define PYD_DEBUG_SUFFIX ""
3232
#endif
3333

34-
#ifdef Py_NOGIL
34+
#ifdef Py_GIL_DISABLED
3535
# define PYD_THREADING_TAG "t"
3636
#else
3737
# define PYD_THREADING_TAG ""

Include/internal/pycore_lock.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ extern "C" {
3333
// ...
3434
// PyMutex_Unlock(&m);
3535

36-
// NOTE: In Py_NOGIL builds, `struct _PyMutex` is defined in Include/object.h.
37-
// The Py_NOGIL builds need the definition in Include/object.h for the
36+
// NOTE: In Py_GIL_DISABLED builds, `struct _PyMutex` is defined in Include/object.h.
37+
// The Py_GIL_DISABLED builds need the definition in Include/object.h for the
3838
// `ob_mutex` field in PyObject. For the default (non-free-threaded) build,
3939
// we define the struct here to avoid exposing it in the public API.
40-
#ifndef Py_NOGIL
40+
#ifndef Py_GIL_DISABLED
4141
struct _PyMutex { uint8_t v; };
4242
#endif
4343

Include/internal/pycore_object.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
5454
Furthermore, we can't use designated initializers in Extensions since these
5555
are not supported pre-C++20. Thus, keeping an internal copy here is the most
5656
backwards compatible solution */
57-
#if defined(Py_NOGIL)
57+
#if defined(Py_GIL_DISABLED)
5858
#define _PyObject_HEAD_INIT(type) \
5959
{ \
6060
.ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \
@@ -103,7 +103,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
103103
#ifdef Py_REF_DEBUG
104104
_Py_AddRefTotal(_PyInterpreterState_GET(), n);
105105
#endif
106-
#if !defined(Py_NOGIL)
106+
#if !defined(Py_GIL_DISABLED)
107107
op->ob_refcnt += n;
108108
#else
109109
if (_Py_IsOwnedByCurrentThread(op)) {
@@ -128,7 +128,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
128128
static inline void _Py_SetImmortal(PyObject *op)
129129
{
130130
if (op) {
131-
#ifdef Py_NOGIL
131+
#ifdef Py_GIL_DISABLED
132132
op->ob_tid = _Py_UNOWNED_TID;
133133
op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL;
134134
op->ob_ref_shared = 0;
@@ -145,7 +145,7 @@ static inline void _Py_SetMortal(PyObject *op, Py_ssize_t refcnt)
145145
{
146146
if (op) {
147147
assert(_Py_IsImmortal(op));
148-
#ifdef Py_NOGIL
148+
#ifdef Py_GIL_DISABLED
149149
op->ob_tid = _Py_UNOWNED_TID;
150150
op->ob_ref_local = 0;
151151
op->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
@@ -169,7 +169,7 @@ static inline void _Py_ClearImmortal(PyObject *op)
169169
op = NULL; \
170170
} while (0)
171171

172-
#if !defined(Py_NOGIL)
172+
#if !defined(Py_GIL_DISABLED)
173173
static inline void
174174
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
175175
{
@@ -210,7 +210,7 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
210210
}
211211

212212
#else
213-
// TODO: implement Py_DECREF specializations for Py_NOGIL build
213+
// TODO: implement Py_DECREF specializations for Py_GIL_DISABLED build
214214
static inline void
215215
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
216216
{
@@ -238,7 +238,7 @@ _Py_REF_IS_QUEUED(Py_ssize_t ob_ref_shared)
238238
// Merge the local and shared reference count fields and add `extra` to the
239239
// refcount when merging.
240240
Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra);
241-
#endif // !defined(Py_NOGIL)
241+
#endif // !defined(Py_GIL_DISABLED)
242242

243243
#ifdef Py_REF_DEBUG
244244
# undef _Py_DEC_REFTOTAL

Include/object.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ check by comparing the reference count field to the immortality reference count.
106106
#define _Py_IMMORTAL_REFCNT (UINT_MAX >> 2)
107107
#endif
108108

109-
// Py_NOGIL builds indicate immortal objects using `ob_ref_local`, which is
109+
// Py_GIL_DISABLED builds indicate immortal objects using `ob_ref_local`, which is
110110
// always 32-bits.
111-
#ifdef Py_NOGIL
111+
#ifdef Py_GIL_DISABLED
112112
#define _Py_IMMORTAL_REFCNT_LOCAL UINT32_MAX
113113
#endif
114114

@@ -117,7 +117,7 @@ check by comparing the reference count field to the immortality reference count.
117117

118118
// Make all internal uses of PyObject_HEAD_INIT immortal while preserving the
119119
// C-API expectation that the refcnt will be set to 1.
120-
#if defined(Py_NOGIL)
120+
#if defined(Py_GIL_DISABLED)
121121
#define PyObject_HEAD_INIT(type) \
122122
{ \
123123
0, \
@@ -162,7 +162,7 @@ check by comparing the reference count field to the immortality reference count.
162162
* by hand. Similarly every pointer to a variable-size Python object can,
163163
* in addition, be cast to PyVarObject*.
164164
*/
165-
#ifndef Py_NOGIL
165+
#ifndef Py_GIL_DISABLED
166166
struct _object {
167167
#if (defined(__GNUC__) || defined(__clang__)) \
168168
&& !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
@@ -238,7 +238,7 @@ typedef struct {
238238
PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
239239
#define Py_Is(x, y) ((x) == (y))
240240

241-
#if defined(Py_NOGIL) && !defined(Py_LIMITED_API)
241+
#if defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
242242
static inline uintptr_t
243243
_Py_ThreadId(void)
244244
{
@@ -275,7 +275,7 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
275275
#endif
276276

277277
static inline Py_ssize_t Py_REFCNT(PyObject *ob) {
278-
#if !defined(Py_NOGIL)
278+
#if !defined(Py_GIL_DISABLED)
279279
return ob->ob_refcnt;
280280
#else
281281
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) {
316316

317317
static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
318318
{
319-
#if defined(Py_NOGIL)
319+
#if defined(Py_GIL_DISABLED)
320320
return op->ob_ref_local == _Py_IMMORTAL_REFCNT_LOCAL;
321321
#elif SIZEOF_VOID_P > 4
322322
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) {
350350
if (_Py_IsImmortal(ob)) {
351351
return;
352352
}
353-
#ifndef Py_NOGIL
353+
#ifndef Py_GIL_DISABLED
354354
ob->ob_refcnt = refcnt;
355355
#else
356356
if (_Py_IsOwnedByCurrentThread(ob)) {
@@ -367,7 +367,7 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
367367
ob->ob_ref_local = 0;
368368
ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
369369
}
370-
#endif // Py_NOGIL
370+
#endif // Py_GIL_DISABLED
371371
#endif // Py_LIMITED_API+0 < 0x030d0000
372372
}
373373
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
@@ -746,7 +746,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
746746
#else
747747
// Non-limited C API and limited C API for Python 3.9 and older access
748748
// directly PyObject.ob_refcnt.
749-
#if defined(Py_NOGIL)
749+
#if defined(Py_GIL_DISABLED)
750750
uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local);
751751
uint32_t new_local = local + 1;
752752
if (new_local == 0) {
@@ -784,7 +784,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
784784
#endif
785785

786786

787-
#if !defined(Py_LIMITED_API) && defined(Py_NOGIL)
787+
#if !defined(Py_LIMITED_API) && defined(Py_GIL_DISABLED)
788788
// Implements Py_DECREF on objects not owned by the current thread.
789789
PyAPI_FUNC(void) _Py_DecRefShared(PyObject *);
790790
PyAPI_FUNC(void) _Py_DecRefSharedDebug(PyObject *, const char *, int);
@@ -810,7 +810,7 @@ static inline void Py_DECREF(PyObject *op) {
810810
}
811811
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
812812

813-
#elif defined(Py_NOGIL) && defined(Py_REF_DEBUG)
813+
#elif defined(Py_GIL_DISABLED) && defined(Py_REF_DEBUG)
814814
static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
815815
{
816816
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)
835835
}
836836
#define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
837837

838-
#elif defined(Py_NOGIL)
838+
#elif defined(Py_GIL_DISABLED)
839839
static inline void Py_DECREF(PyObject *op)
840840
{
841841
uint32_t local = _Py_atomic_load_uint32_relaxed(&op->ob_ref_local);

Lib/sysconfig/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _init_non_posix(vars):
348348
vars['BINLIBDEST'] = get_path('platstdlib')
349349
vars['INCLUDEPY'] = get_path('include')
350350

351-
# Add EXT_SUFFIX, SOABI, and Py_NOGIL
351+
# Add EXT_SUFFIX, SOABI, and Py_GIL_DISABLED
352352
vars.update(_sysconfig.config_vars())
353353

354354
vars['LIBDIR'] = _safe_realpath(os.path.join(get_config_var('installed_base'), 'libs'))

Lib/test/libregrtest/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def get_build_info():
290290
build = []
291291

292292
# --disable-gil
293-
if sysconfig.get_config_var('Py_NOGIL'):
293+
if sysconfig.get_config_var('Py_GIL_DISABLED'):
294294
build.append("nogil")
295295

296296
if hasattr(sys, 'gettotalrefcount'):

Lib/test/pythoninfo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def collect_sysconfig(info_add):
517517
'PY_STDMODULE_CFLAGS',
518518
'Py_DEBUG',
519519
'Py_ENABLE_SHARED',
520-
'Py_NOGIL',
520+
'Py_GIL_DISABLED',
521521
'SHELL',
522522
'SOABI',
523523
'abs_builddir',

Lib/test/support/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def check_cflags_pgo():
796796
return any(option in cflags_nodist for option in pgo_options)
797797

798798

799-
if sysconfig.get_config_var('Py_NOGIL'):
799+
if sysconfig.get_config_var('Py_GIL_DISABLED'):
800800
_header = 'PHBBInP'
801801
else:
802802
_header = 'nP'

Lib/test/test_cppext/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# gh-110119: pip does not currently support 't' in the ABI flag use by
1717
# --disable-gil builds. Once it does, we can remove this skip.
18-
@unittest.skipIf(sysconfig.get_config_var('Py_NOGIL') == 1,
18+
@unittest.skipIf(sysconfig.get_config_var('Py_GIL_DISABLED') == 1,
1919
'test does not work with --disable-gil')
2020
@support.requires_subprocess()
2121
class TestCPPExt(unittest.TestCase):

Lib/test/test_importlib/test_windows.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_module_not_found(self):
112112
class WindowsExtensionSuffixTests:
113113
def test_tagged_suffix(self):
114114
suffixes = self.machinery.EXTENSION_SUFFIXES
115-
abi_flags = "t" if sysconfig.get_config_var("Py_NOGIL") else ""
115+
abi_flags = "t" if sysconfig.get_config_var("Py_GIL_DISABLED") else ""
116116
ver = sys.version_info
117117
platform = re.sub('[^a-zA-Z0-9]', '_', get_platform())
118118
expected_tag = f".cp{ver.major}{ver.minor}{abi_flags}-{platform}.pyd"

Lib/test/test_sys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def test_pystats(self):
12091209
@unittest.skipUnless(hasattr(sys, 'abiflags'), 'need sys.abiflags')
12101210
def test_disable_gil_abi(self):
12111211
abi_threaded = 't' in sys.abiflags
1212-
py_nogil = (sysconfig.get_config_var('Py_NOGIL') == 1)
1212+
py_nogil = (sysconfig.get_config_var('Py_GIL_DISABLED') == 1)
12131213
self.assertEqual(py_nogil, abi_threaded)
12141214

12151215

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rename ``Py_NOGIL`` to ``Py_GIL_DISABLED``. Patch by Hugo van Kemenade.

Modules/_ctypes/_ctypes_test.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _MSC_VER
2-
#include "pyconfig.h" // Py_NOGIL
2+
#include "pyconfig.h" // Py_GIL_DISABLED
33
#endif
44

5-
#ifndef Py_NOGIL
5+
#ifndef Py_GIL_DISABLED
66
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
77
#define Py_LIMITED_API 0x030c0000
88
#endif

Modules/_multiprocessing/posixshmem.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
posixshmem - A Python extension that provides shm_open() and shm_unlink()
33
*/
44

5-
#include "pyconfig.h" // Py_NOGIL
5+
#include "pyconfig.h" // Py_GIL_DISABLED
66

7-
#ifndef Py_NOGIL
7+
#ifndef Py_GIL_DISABLED
88
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
99
#define Py_LIMITED_API 0x030c0000
1010
#endif

Modules/_scproxy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
#ifndef _MSC_VER
7-
#include "pyconfig.h" // Py_NOGIL
7+
#include "pyconfig.h" // Py_GIL_DISABLED
88
#endif
99

10-
#ifndef Py_NOGIL
10+
#ifndef Py_GIL_DISABLED
1111
// Need limited C API version 3.12 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
1212
#define Py_LIMITED_API 0x030c0000
1313
#endif

Modules/_stat.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
*/
1313

1414
#ifndef _MSC_VER
15-
#include "pyconfig.h" // Py_NOGIL
15+
#include "pyconfig.h" // Py_GIL_DISABLED
1616
#endif
1717

18-
#ifndef Py_NOGIL
18+
#ifndef Py_GIL_DISABLED
1919
// Need limited C API version 3.13 for PyModule_Add() on Windows
2020
#define Py_LIMITED_API 0x030d0000
2121
#endif

Modules/_sysconfig.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ _sysconfig_config_vars_impl(PyObject *module)
5757
}
5858
#endif
5959

60-
#ifdef Py_NOGIL
60+
#ifdef Py_GIL_DISABLED
6161
PyObject *py_nogil = _PyLong_GetOne();
6262
#else
6363
PyObject *py_nogil = _PyLong_GetZero();
6464
#endif
65-
if (PyDict_SetItemString(config, "Py_NOGIL", py_nogil) < 0) {
65+
if (PyDict_SetItemString(config, "Py_GIL_DISABLED", py_nogil) < 0) {
6666
Py_DECREF(config);
6767
return NULL;
6868
}

Modules/_testcapi/heaptype_relative.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _MSC_VER
2-
#include "pyconfig.h" // Py_NOGIL
2+
#include "pyconfig.h" // Py_GIL_DISABLED
33
#endif
44

5-
#ifndef Py_NOGIL
5+
#ifndef Py_GIL_DISABLED
66
#define Py_LIMITED_API 0x030c0000 // 3.12
77
#endif
88

Modules/_testcapi/vectorcall_limited.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* Test Vectorcall in the limited API */
22

33
#ifndef _MSC_VER
4-
#include "pyconfig.h" // Py_NOGIL
4+
#include "pyconfig.h" // Py_GIL_DISABLED
55
#endif
66

7-
#ifndef Py_NOGIL
7+
#ifndef Py_GIL_DISABLED
88
#define Py_LIMITED_API 0x030c0000 // 3.12
99
#endif
1010

Modules/_testclinic_limited.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#undef Py_BUILD_CORE_BUILTIN
66

77
#ifndef _MSC_VER
8-
#include "pyconfig.h" // Py_NOGIL
8+
#include "pyconfig.h" // Py_GIL_DISABLED
99
#endif
1010

11-
#ifndef Py_NOGIL
11+
#ifndef Py_GIL_DISABLED
1212
// For now, only limited C API 3.13 is supported
1313
#define Py_LIMITED_API 0x030d0000
1414
#endif

0 commit comments

Comments
 (0)