From 773614e03aef29c744d0300bd62fc8254e3c06b6 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 27 Sep 2023 11:24:12 -0400 Subject: [PATCH] gh-109740: Use 't' in `--disable-gil` SOABI (#109922) Shared libraries for CPython 3.13 are now marked with a 't' for threading. For example, `binascii.cpython-313t-darwin.so`. --- Doc/library/sys.rst | 2 + Lib/test/test_sys.py | 7 ++ ...-09-26-16-00-50.gh-issue-109740.wboWdQ.rst | 2 + Python/dynload_win.c | 12 +++- configure | 65 ++++++++++--------- configure.ac | 33 +++++----- 6 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2023-09-26-16-00-50.gh-issue-109740.wboWdQ.rst diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index ef818a7da01..f9f556306f5 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) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index c616a27364b..16050171ad1 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1210,6 +1210,13 @@ class SysModuleTest(unittest.TestCase): 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 00000000000..f59f462aecd --- /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`` configure flag now includes "t" (for "threaded") in +extension ABI tags. diff --git a/Python/dynload_win.c b/Python/dynload_win.c index f69995b8f9e..fcb3cb74404 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -15,10 +15,16 @@ #define PYD_DEBUG_SUFFIX "" #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" +#ifdef Py_NOGIL +# define PYD_THREADING_TAG "t" #else -#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) ".pyd" +# 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_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_THREADING_TAG ".pyd" #endif #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" diff --git a/configure b/configure index abae542b528..098def9aab0 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,36 @@ 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 + + # Add "t" for "threaded" + 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 +23576,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 +27755,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 205a98a9922..3e6cbc69c21 100644 --- a/configure.ac +++ b/configure.ac @@ -1489,6 +1489,23 @@ 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]) + # Add "t" for "threaded" + ABIFLAGS="${ABIFLAGS}t" +fi + # Check for --with-pydebug AC_MSG_CHECKING([for --with-pydebug]) AC_ARG_WITH([pydebug], @@ -5669,6 +5686,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 +6965,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