Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-111863: Rename Py_NOGIL to Py_GIL_DISABLED #111864

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_importdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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, \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_cppext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename ``Py_NOGIL`` to ``Py_GIL_DISABLED``. Patch by Hugo van Kemenade.
4 changes: 2 additions & 2 deletions Modules/_ctypes/_ctypes_test.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Modules/_multiprocessing/posixshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Modules/_scproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Modules/_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sysconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapi/heaptype_relative.c
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions Modules/_testcapi/vectorcall_limited.c
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions Modules/_testclinic_limited.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading