]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 6 Sep 2024 01:09:35 +0000 (03:09 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Sep 2024 01:09:35 +0000 (10:09 +0900)
gh-123275: Support `-Xgil=1` and `PYTHON_GIL=1` on non-free-threaded builds (gh-123276)
(cherry picked from commit 84ad264ce602fb263a46a4536377bdc830eea81e)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/using/cmdline.rst
Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst [new file with mode: 0644]
Python/initconfig.c

index df2c29be9b6014489fa6382bd8dcf7658fc91f19..8f54a0fdebe1d31f81a15e0d230df3dd45585e40 100644 (file)
@@ -616,7 +616,7 @@ Miscellaneous options
      .. versionadded:: 3.13
 
    * :samp:`-X gil={0,1}` forces the GIL to be disabled or enabled,
-     respectively. Only available in builds configured with
+     respectively. Setting to ``0`` is only available in builds configured with
      :option:`--disable-gil`. See also :envvar:`PYTHON_GIL` and
      :ref:`whatsnew313-free-threaded-cpython`.
 
@@ -1215,13 +1215,12 @@ conflict.
 .. envvar:: PYTHON_GIL
 
    If this variable is set to ``1``, the global interpreter lock (GIL) will be
-   forced on. Setting it to ``0`` forces the GIL off.
+   forced on. Setting it to ``0`` forces the GIL off (needs Python configured with
+   the :option:`--disable-gil` build option).
 
    See also the :option:`-X gil <-X>` command-line option, which takes
    precedence over this variable, and :ref:`whatsnew313-free-threaded-cpython`.
 
-   Needs Python configured with the :option:`--disable-gil` build option.
-
    .. versionadded:: 3.13
 
 Debug-mode variables
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-08-23-18-31-10.gh-issue-123275.DprIrj.rst
new file mode 100644 (file)
index 0000000..ab344a8
--- /dev/null
@@ -0,0 +1 @@
+Support :option:`-X gil=1 <-X>` and :envvar:`PYTHON_GIL=1 <PYTHON_GIL>` on non-free-threaded builds.
index a28c08c5318ddce3ff7cbcc77198d511e2f37f07..84717b4e3c934b937b6064fd288902785b4dc44e 100644 (file)
@@ -1542,20 +1542,24 @@ config_wstr_to_int(const wchar_t *wstr, int *result)
 static PyStatus
 config_read_gil(PyConfig *config, size_t len, wchar_t first_char)
 {
-#ifdef Py_GIL_DISABLED
     if (len == 1 && first_char == L'0') {
+#ifdef Py_GIL_DISABLED
         config->enable_gil = _PyConfig_GIL_DISABLE;
+#else
+        return _PyStatus_ERR("Disabling the GIL is not supported by this build");
+#endif
     }
     else if (len == 1 && first_char == L'1') {
+#ifdef Py_GIL_DISABLED
         config->enable_gil = _PyConfig_GIL_ENABLE;
+#else
+        return _PyStatus_OK();
+#endif
     }
     else {
         return _PyStatus_ERR("PYTHON_GIL / -X gil must be \"0\" or \"1\"");
     }
     return _PyStatus_OK();
-#else
-    return _PyStatus_ERR("PYTHON_GIL / -X gil are not supported by this build");
-#endif
 }
 
 static PyStatus