From e745f3264b577dc706ab83cb8c50e3e7f5e9da8d Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Mon, 18 Sep 2023 16:26:39 -0400 Subject: [PATCH 1/8] gh-109740: Use 't' in `--disable-gil` SOABI Shared libraries for CPython 3.13 are now marked with a 't' for threading. For example, `binascii.cpython-313t-darwin.so`. --- Lib/test/test_sys.py | 7 ++ ...-09-26-16-00-50.gh-issue-109740.wboWdQ.rst | 2 + Python/dynload_win.c | 10 ++- configure | 64 ++++++++++--------- configure.ac | 32 +++++----- 5 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index c616a27364b494..16050171ad139d 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1210,6 +1210,13 @@ def test_pystats(self): sys._stats_clear() sys._stats_dump() + @test.support.cpython_only + @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) + self.assertEqual(py_nogil, abi_threaded) + @test.support.cpython_only class UnraisableHookTest(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst new file mode 100644 index 00000000000000..3e872b3f92f225 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst @@ -0,0 +1,2 @@ +The experimental `--disable-gil` flag now includes "t" (for "threaded") in +extension ABI tags. diff --git a/Python/dynload_win.c b/Python/dynload_win.c index f69995b8f9e3a1..0228adc30bd786 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -15,10 +15,16 @@ #define PYD_DEBUG_SUFFIX "" #endif +#ifdef Py_NOGIL +#define PYD_THREADING_TAG "t" +#else +#define PYD_THREADING_TAG "" +#endif + #ifdef PYD_PLATFORM_TAG -#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) "-" PYD_PLATFORM_TAG ".pyd" +#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG "-" PYD_PLATFORM_TAG ".pyd" #else -#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) ".pyd" +#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG ".pyd" #endif #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" diff --git a/configure b/configure index abae542b528a23..53dd6f96523ec0 100755 --- a/configure +++ b/configure @@ -1065,6 +1065,7 @@ with_suffix enable_shared with_static_libpython enable_profiling +enable_gil with_pydebug with_trace_refs enable_pystats @@ -1105,7 +1106,6 @@ with_openssl_rpath with_ssl_default_suites with_builtin_hashlib_hashes enable_test_modules -enable_gil ' ac_precious_vars='build_alias host_alias @@ -1792,6 +1792,8 @@ Optional Features: no) --enable-profiling enable C-level code profiling with gprof (default is no) + --disable-gil enable experimental support for running without the + GIL (default is no) --enable-pystats enable internal statistics gathering (default is no) --enable-optimizations enable expensive, stable optimizations (PGO, etc.) (default is no) @@ -1806,8 +1808,6 @@ Optional Features: use big digits (30 or 15 bits) for Python longs (default is 30)] --disable-test-modules don't build nor install test modules - --disable-gil enable experimental support for running without the - GIL (default is no) Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -7845,6 +7845,35 @@ fi ABIFLAGS="" +# Check for --disable-gil +# --disable-gil +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --disable-gil" >&5 +printf %s "checking for --disable-gil... " >&6; } +# Check whether --enable-gil was given. +if test ${enable_gil+y} +then : + enableval=$enable_gil; if test "x$enable_gil" = xyes +then : + disable_gil=no +else $as_nop + disable_gil=yes +fi +else $as_nop + disable_gil=no + +fi + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $disable_gil" >&5 +printf "%s\n" "$disable_gil" >&6; } + +if test "$disable_gil" = "yes" +then + +printf "%s\n" "#define Py_NOGIL 1" >>confdefs.h + + ABIFLAGS="${ABIFLAGS}t" +fi + # Check for --with-pydebug { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-pydebug" >&5 printf %s "checking for --with-pydebug... " >&6; } @@ -23546,6 +23575,7 @@ printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h # # * The Python implementation (always 'cpython-' for us) # * The major and minor version numbers +# * --disable-gil (adds a 't') # * --with-pydebug (adds a 'd') # # Thus for example, Python 3.2 built with wide unicode, pydebug, and pymalloc, @@ -27724,34 +27754,6 @@ fi printf "%s\n" "$TEST_MODULES" >&6; } -# Check for --disable-gil -# --disable-gil -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --disable-gil" >&5 -printf %s "checking for --disable-gil... " >&6; } -# Check whether --enable-gil was given. -if test ${enable_gil+y} -then : - enableval=$enable_gil; if test "x$enable_gil" = xyes -then : - disable_gil=no -else $as_nop - disable_gil=yes -fi -else $as_nop - disable_gil=no - -fi - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $disable_gil" >&5 -printf "%s\n" "$disable_gil" >&6; } - -if test "$disable_gil" = "yes" -then - -printf "%s\n" "#define Py_NOGIL 1" >>confdefs.h - -fi - # gh-109054: Check if -latomic is needed to get atomic functions. # On Linux aarch64, GCC may require programs and libraries to be linked # explicitly to libatomic. Call _Py_atomic_or_uint64() which may require diff --git a/configure.ac b/configure.ac index 205a98a992279c..d7787746d5ffb4 100644 --- a/configure.ac +++ b/configure.ac @@ -1489,6 +1489,22 @@ fi AC_SUBST([ABIFLAGS]) ABIFLAGS="" +# Check for --disable-gil +# --disable-gil +AC_MSG_CHECKING([for --disable-gil]) +AC_ARG_ENABLE([gil], + [AS_HELP_STRING([--disable-gil], [enable experimental support for running without the GIL (default is no)])], + [AS_VAR_IF([enable_gil], [yes], [disable_gil=no], [disable_gil=yes])], [disable_gil=no] +) +AC_MSG_RESULT([$disable_gil]) + +if test "$disable_gil" = "yes" +then + AC_DEFINE([Py_NOGIL], [1], + [Define if you want to disable the GIL]) + ABIFLAGS="${ABIFLAGS}t" +fi + # Check for --with-pydebug AC_MSG_CHECKING([for --with-pydebug]) AC_ARG_WITH([pydebug], @@ -5669,6 +5685,7 @@ AC_C_BIGENDIAN # # * The Python implementation (always 'cpython-' for us) # * The major and minor version numbers +# * --disable-gil (adds a 't') # * --with-pydebug (adds a 'd') # # Thus for example, Python 3.2 built with wide unicode, pydebug, and pymalloc, @@ -6947,21 +6964,6 @@ AC_ARG_ENABLE([test-modules], AC_MSG_RESULT([$TEST_MODULES]) AC_SUBST([TEST_MODULES]) -# Check for --disable-gil -# --disable-gil -AC_MSG_CHECKING([for --disable-gil]) -AC_ARG_ENABLE([gil], - [AS_HELP_STRING([--disable-gil], [enable experimental support for running without the GIL (default is no)])], - [AS_VAR_IF([enable_gil], [yes], [disable_gil=no], [disable_gil=yes])], [disable_gil=no] -) -AC_MSG_RESULT([$disable_gil]) - -if test "$disable_gil" = "yes" -then - AC_DEFINE([Py_NOGIL], [1], - [Define if you want to disable the GIL]) -fi - # gh-109054: Check if -latomic is needed to get atomic functions. # On Linux aarch64, GCC may require programs and libraries to be linked # explicitly to libatomic. Call _Py_atomic_or_uint64() which may require From 306081ba123778e6deed23a52c83fedd1cd88346 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 26 Sep 2023 16:22:11 -0400 Subject: [PATCH 2/8] Use double backticks in blurb --- .../next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst index 3e872b3f92f225..44b52ffa3c4656 100644 --- a/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst +++ b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst @@ -1,2 +1,2 @@ -The experimental `--disable-gil` flag now includes "t" (for "threaded") in +The experimental ``--disable-gil`` flag now includes "t" (for "threaded") in extension ABI tags. From 44f0e17ec4dcc90f995b48b71842338cb051b5e4 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 26 Sep 2023 16:40:19 -0400 Subject: [PATCH 3/8] Update Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst Co-authored-by: Erlend E. Aasland --- .../next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst index 44b52ffa3c4656..f59f462aecd1fc 100644 --- a/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst +++ b/Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst @@ -1,2 +1,2 @@ -The experimental ``--disable-gil`` flag now includes "t" (for "threaded") in +The experimental ``--disable-gil`` configure flag now includes "t" (for "threaded") in extension ABI tags. From 0dbbbce3ea37b65b54832214b056483654a4e681 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Tue, 26 Sep 2023 18:51:03 -0400 Subject: [PATCH 4/8] Add comment about ABIFLAGS --- configure | 1 + configure.ac | 1 + 2 files changed, 2 insertions(+) diff --git a/configure b/configure index 53dd6f96523ec0..c192422a4ab726 100755 --- a/configure +++ b/configure @@ -7871,6 +7871,7 @@ then printf "%s\n" "#define Py_NOGIL 1" >>confdefs.h + # "t" (for "threaded") ABIFLAGS="${ABIFLAGS}t" fi diff --git a/configure.ac b/configure.ac index d7787746d5ffb4..400c575e291524 100644 --- a/configure.ac +++ b/configure.ac @@ -1502,6 +1502,7 @@ if test "$disable_gil" = "yes" then AC_DEFINE([Py_NOGIL], [1], [Define if you want to disable the GIL]) + # "t" (for "threaded") ABIFLAGS="${ABIFLAGS}t" fi From 964e3790d1d993fc896426ccc6f6677db5a0ceed Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Sep 2023 10:04:28 +0200 Subject: [PATCH 5/8] Update configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 400c575e291524..3e6cbc69c21009 100644 --- a/configure.ac +++ b/configure.ac @@ -1502,7 +1502,7 @@ if test "$disable_gil" = "yes" then AC_DEFINE([Py_NOGIL], [1], [Define if you want to disable the GIL]) - # "t" (for "threaded") + # Add "t" for "threaded" ABIFLAGS="${ABIFLAGS}t" fi From 39dec482ee5200c9550e62d8d93a22be76fabe7d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Sep 2023 10:04:36 +0200 Subject: [PATCH 6/8] Update Python/dynload_win.c --- Python/dynload_win.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 0228adc30bd786..fcb3cb744047ce 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -16,9 +16,9 @@ #endif #ifdef Py_NOGIL -#define PYD_THREADING_TAG "t" +# define PYD_THREADING_TAG "t" #else -#define PYD_THREADING_TAG "" +# define PYD_THREADING_TAG "" #endif #ifdef PYD_PLATFORM_TAG From 597e489586f80f410b609c55d41e6b3b3c495e81 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Sep 2023 10:05:56 +0200 Subject: [PATCH 7/8] sys.abiflags is not available on Windows --- Doc/library/sys.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index ef818a7da016de..f9f556306f5827 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -22,6 +22,8 @@ always available. .. versionadded:: 3.2 + .. availability:: Unix. + .. function:: addaudithook(hook) From c985f63799d84a80822dcb16fc9f581e650abc0f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Sep 2023 10:38:09 +0200 Subject: [PATCH 8/8] Run make regen-configure --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index c192422a4ab726..098def9aab08bf 100755 --- a/configure +++ b/configure @@ -7871,7 +7871,7 @@ then printf "%s\n" "#define Py_NOGIL 1" >>confdefs.h - # "t" (for "threaded") + # Add "t" for "threaded" ABIFLAGS="${ABIFLAGS}t" fi