Skip to content

Commit 59a7a46

Browse files
authored
gh-162214: Test Py_GIL_DISABLED macro using #ifdef (#162223)
Replace "#if Py_GIL_DISABLED" with "#ifdef Py_GIL_DISABLED" to fix compiler warnings when building Python with -Wundef. Example of fixed warning: Objects/unicodeobject.c:14740:5: warning: 'Py_GIL_DISABLED' is not defined, evaluates to '0' [-Wundef] 14740 | #if Py_GIL_DISABLED | ^~~~~~~~~~~~~~~ Simplify also Py_GIL_DISABLED == 0 test in PC/pyconfig.h.
1 parent ddd88c7 commit 59a7a46

8 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎Modules/_testinternalcapi/test_cases.c.h‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/unicodeobject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14737,7 +14737,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
1473714737
/* Statically allocated strings must be already interned. */
1473814738
assert(!_PyUnicode_STATE(s).statically_allocated);
1473914739

14740-
#if Py_GIL_DISABLED
14740+
#ifdef Py_GIL_DISABLED
1474114741
/* In the free-threaded build, all interned strings are immortal */
1474214742
immortalize = 1;
1474314743
#endif

‎PC/pyconfig.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ WIN32 is still required for the locale module.
9898
#endif
9999

100100
/* Define to 1 when compiling for experimental free-threaded builds */
101-
#ifdef Py_GIL_DISABLED
101+
#if defined(Py_GIL_DISABLED) && Py_GIL_DISABLED == 0
102102
/* We undefine if it was set to zero because all later checks are #ifdef.
103103
* Note that non-Windows builds do not do this, and so every effort should
104104
* be made to avoid defining the variable at all when not desired. However,
105105
* sysconfig.get_config_var always returns a 1 or a 0, and so it seems likely
106106
* that a build backend will define it with the value.
107107
*/
108-
#if Py_GIL_DISABLED == 0
109108
#undef Py_GIL_DISABLED
110109
#endif
111-
#endif
112110

113111
/* Compiler specific defines */
114112

‎Python/bytecodes.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ dummy_func(
22782278
assert(index < DK_SIZE(keys));
22792279
PyObject *res_o = FT_ATOMIC_LOAD_PTR_CONSUME(entries[index].me_value);
22802280
DEOPT_IF(res_o == NULL);
2281-
#if Py_GIL_DISABLED
2281+
#ifdef Py_GIL_DISABLED
22822282
int increfed = _Py_TryIncrefCompareStackRef(&entries[index].me_value, res_o, &res);
22832283
DEOPT_IF(!increfed);
22842284
#else
@@ -2297,7 +2297,7 @@ dummy_func(
22972297
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
22982298
PyObject *res_o = FT_ATOMIC_LOAD_PTR_CONSUME(entries[index].me_value);
22992299
DEOPT_IF(res_o == NULL);
2300-
#if Py_GIL_DISABLED
2300+
#ifdef Py_GIL_DISABLED
23012301
int increfed = _Py_TryIncrefCompareStackRef(&entries[index].me_value, res_o, &res);
23022302
DEOPT_IF(!increfed);
23032303
#else

‎Python/executor_cases.c.h‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/generated_cases.c.h‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/lock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const PyTime_t TIME_TO_BE_FAIR_NS = 1000*1000;
2525
// Spin for a bit before parking the thread. This is only enabled for
2626
// `--disable-gil` builds because it is unlikely to be helpful if the GIL is
2727
// enabled.
28-
#if Py_GIL_DISABLED
28+
#ifdef Py_GIL_DISABLED
2929
static const int MAX_SPIN_COUNT = 40;
3030
#else
3131
static const int MAX_SPIN_COUNT = 0;

‎Python/modsupport.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ int PyABIInfo_Check(PyABIInfo *info, const char *module_name)
767767

768768
/* Free-threading/GIL */
769769
uint16_t gilflags = info->flags & (PyABIInfo_GIL | PyABIInfo_FREETHREADED);
770-
#if Py_GIL_DISABLED
770+
#ifdef Py_GIL_DISABLED
771771
if (gilflags == PyABIInfo_GIL) {
772772
return _abiinfo_raise(module_name,
773773
"incompatible with free-threaded CPython");

0 commit comments

Comments
 (0)