From 9161899c943cde34a03983ccf07f92baaaae1832 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Mon, 1 Dec 2025 18:15:29 -0500 Subject: [PATCH 1/3] Only define HAVE_THREAD_LOCAL when Py_BUILD_CORE is set. --- Include/pyport.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 97c0e195d19808..61e2317976eed1 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -509,9 +509,15 @@ extern "C" { # define Py_CAN_START_THREADS 1 #endif -#ifdef WITH_THREAD -// HAVE_THREAD_LOCAL is just defined here for compatibility's sake + +/* gh-142163: Some libraries rely on HAVE_THREAD_LOCAL being undefined, so + * we can only define it only when Py_BUILD_CORE is set.*/ +#ifdef Py_BUILD_CORE +// This is no longer coupled to _Py_thread_local. # define HAVE_THREAD_LOCAL 1 +#endif + +#ifdef WITH_THREAD # ifdef thread_local # define _Py_thread_local thread_local # elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) From fe4fb52da27029b8e8a48b9ac3c42b809dd10f59 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Mon, 1 Dec 2025 18:17:19 -0500 Subject: [PATCH 2/3] Add blurb. --- .../next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst diff --git a/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst b/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst new file mode 100644 index 00000000000000..9b4d958a779d02 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst @@ -0,0 +1,2 @@ +Fix the ``HAVE_THREAD_LOCAL`` macro being defined without the +``Py_BUILD_CORE`` macro set. From 2321c5a9b61ec982b0380c95e78fea311211ba45 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Mon, 1 Dec 2025 18:19:01 -0500 Subject: [PATCH 3/3] Improve blurb. --- .../next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst b/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst index 9b4d958a779d02..5edcfd81992c13 100644 --- a/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst +++ b/Misc/NEWS.d/next/C_API/2025-12-01-18-17-16.gh-issue-142163.2HiX5A.rst @@ -1,2 +1,2 @@ Fix the ``HAVE_THREAD_LOCAL`` macro being defined without the -``Py_BUILD_CORE`` macro set. +``Py_BUILD_CORE`` macro set after including :file:`Python.h`.