From 5faa324fe245b863e614cc0dbdd69d96f8faa81e Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 18 Aug 2025 23:19:04 +0300 Subject: [PATCH 01/12] gh-137884: Added threading.get_native_id on Illumos/Solaris --- Include/pythread.h | 3 ++- Python/thread_pthread.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Include/pythread.h b/Include/pythread.h index 82247daf8e0aa0..e9d8f846ac80a0 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -42,7 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void); #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \ || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__) || defined(__NetBSD__) \ - || defined(__DragonFly__) || defined(_AIX)) + || defined(__DragonFly__) || defined(_AIX)) \ + || defined(__sun__) #define PY_HAVE_THREAD_NATIVE_ID PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void); #endif diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 13992f95723866..d649bcfab307d1 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -30,6 +30,8 @@ # include /* _lwp_self() */ #elif defined(__DragonFly__) # include /* lwp_gettid() */ +#elif defined(__sun__) + # include #endif /* The POSIX spec requires that use of pthread_attr_setstacksize @@ -399,6 +401,8 @@ PyThread_get_thread_native_id(void) #elif defined(__DragonFly__) lwpid_t native_id; native_id = lwp_gettid(); +#elif defined(__sun__) + unsigned long native_id = (unsigned long)getpid() << 32 | thr_self(); #endif return (unsigned long) native_id; } From dc6bc14b9844ea6536384a73e83a3c7f2ae673d9 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 00:11:10 +0300 Subject: [PATCH 02/12] updated docs --- Doc/library/_thread.rst | 4 +++- Doc/library/threading.rst | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index ed29ac70035597..a632b826516b8f 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -120,13 +120,15 @@ This module defines the following constants and functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Illumos/Solaris. .. versionadded:: 3.8 .. versionchanged:: 3.13 Added support for GNU/kFreeBSD. + .. versionchanged:: 3.15 + Added support for Illumos/Solaris. .. function:: stack_size([size]) diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst index cabb41442f8419..4fffde74227689 100644 --- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -191,13 +191,16 @@ This module defines the following functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Illumos/Solaris. .. versionadded:: 3.8 .. versionchanged:: 3.13 Added support for GNU/kFreeBSD. + .. versionchanged:: 3.15 + Added support for Illumos/Solaris. + .. function:: enumerate() From 608bace8792725dc4abe64d82fa2116c3d7b9f47 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 00:13:36 +0300 Subject: [PATCH 03/12] Added the NEWS entry --- .../next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst diff --git a/Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst b/Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst new file mode 100644 index 00000000000000..c28f62ba3ce7b7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-19-00-12-57.gh-issue-137884.4faCA_.rst @@ -0,0 +1,2 @@ +Add :func:`threading.get_native_id` support for Illumos/Solaris. Patch by +Yüce Tekol. From 3c9fc4faabfd739e996c8f53fed3377340c50d51 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 00:26:32 +0300 Subject: [PATCH 04/12] Fixed doc --- Doc/library/_thread.rst | 4 ++-- Doc/library/threading.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index a632b826516b8f..e3697ca769f5ba 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -120,7 +120,7 @@ This module defines the following constants and functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Illumos/Solaris. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris. .. versionadded:: 3.8 @@ -128,7 +128,7 @@ This module defines the following constants and functions: Added support for GNU/kFreeBSD. .. versionchanged:: 3.15 - Added support for Illumos/Solaris. + Added support for Solaris. .. function:: stack_size([size]) diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst index 4fffde74227689..5df1def8b972bc 100644 --- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -191,7 +191,7 @@ This module defines the following functions: Its value may be used to uniquely identify this particular thread system-wide (until the thread terminates, after which the value may be recycled by the OS). - .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Illumos/Solaris. + .. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris. .. versionadded:: 3.8 @@ -199,7 +199,7 @@ This module defines the following functions: Added support for GNU/kFreeBSD. .. versionchanged:: 3.15 - Added support for Illumos/Solaris. + Added support for Solaris. .. function:: enumerate() From f8dd81cdb4b4419e4d1794c970e3ce881b070202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BCce=20Tekol?= Date: Tue, 19 Aug 2025 19:23:26 +0300 Subject: [PATCH 05/12] Update Doc/library/_thread.rst Co-authored-by: Furkan Onder --- Doc/library/_thread.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index e3697ca769f5ba..cb5e63be3fe3df 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -127,7 +127,7 @@ This module defines the following constants and functions: .. versionchanged:: 3.13 Added support for GNU/kFreeBSD. - .. versionchanged:: 3.15 + .. versionchanged:: next Added support for Solaris. .. function:: stack_size([size]) From 11c04379fdff6bf2c5b0d96ac2cae85acc0b1f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BCce=20Tekol?= Date: Tue, 19 Aug 2025 19:23:35 +0300 Subject: [PATCH 06/12] Update Doc/library/threading.rst Co-authored-by: Furkan Onder --- Doc/library/threading.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/threading.rst b/Doc/library/threading.rst index 5df1def8b972bc..9a0aeb7c1287ee 100644 --- a/Doc/library/threading.rst +++ b/Doc/library/threading.rst @@ -198,7 +198,7 @@ This module defines the following functions: .. versionchanged:: 3.13 Added support for GNU/kFreeBSD. - .. versionchanged:: 3.15 + .. versionchanged:: next Added support for Solaris. From 6e0f7aad8febd9c721b2fbc8556ff43ed121edff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BCce=20Tekol?= Date: Tue, 19 Aug 2025 19:23:41 +0300 Subject: [PATCH 07/12] Update Python/thread_pthread.h Co-authored-by: Serhiy Storchaka --- Python/thread_pthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index d649bcfab307d1..6636d8df8f164b 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -31,7 +31,7 @@ #elif defined(__DragonFly__) # include /* lwp_gettid() */ #elif defined(__sun__) - # include +# include #endif /* The POSIX spec requires that use of pthread_attr_setstacksize From 04407ca2e8e52f7ef933b85eb8ac5c8a6ad60f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=BCce=20Tekol?= Date: Tue, 19 Aug 2025 19:23:57 +0300 Subject: [PATCH 08/12] Update Doc/library/_thread.rst Co-authored-by: Serhiy Storchaka --- Doc/library/_thread.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/_thread.rst b/Doc/library/_thread.rst index cb5e63be3fe3df..1d00d05817eb6a 100644 --- a/Doc/library/_thread.rst +++ b/Doc/library/_thread.rst @@ -130,6 +130,7 @@ This module defines the following constants and functions: .. versionchanged:: next Added support for Solaris. + .. function:: stack_size([size]) Return the thread stack size used when creating new threads. The optional From 7eef71c95ec4520f718c025fb03af2948e6ad1b2 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 22:14:53 +0300 Subject: [PATCH 09/12] enable threading.get_native_id only when sizeof(long) >= 8 --- Python/thread_pthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 6636d8df8f164b..137910b3242950 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -401,7 +401,7 @@ PyThread_get_thread_native_id(void) #elif defined(__DragonFly__) lwpid_t native_id; native_id = lwp_gettid(); -#elif defined(__sun__) +#elif defined(__sun__) && SIZEOF_LONG == 8 unsigned long native_id = (unsigned long)getpid() << 32 | thr_self(); #endif return (unsigned long) native_id; From 8c1140916fbb1e07389d5ee7d06f15b24f7bbb9a Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 22:17:06 +0300 Subject: [PATCH 10/12] enable threading.get_native_id only when sizeof(long) >= 8 --- Python/thread_pthread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 137910b3242950..d3428b466c7acf 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -401,7 +401,7 @@ PyThread_get_thread_native_id(void) #elif defined(__DragonFly__) lwpid_t native_id; native_id = lwp_gettid(); -#elif defined(__sun__) && SIZEOF_LONG == 8 +#elif defined(__sun__) && SIZEOF_LONG >= 8 unsigned long native_id = (unsigned long)getpid() << 32 | thr_self(); #endif return (unsigned long) native_id; From e2f9c41905d629206bd3366fbaa25d86d6663abc Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Tue, 19 Aug 2025 22:27:12 +0300 Subject: [PATCH 11/12] long size check --- Include/pythread.h | 2 +- Python/thread_pthread.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/pythread.h b/Include/pythread.h index e9d8f846ac80a0..d9cd33895f9518 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -43,7 +43,7 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void); || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__) || defined(__NetBSD__) \ || defined(__DragonFly__) || defined(_AIX)) \ - || defined(__sun__) + || defined(__sun__) && SIZEOF_LONG >= 8 #define PY_HAVE_THREAD_NATIVE_ID PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void); #endif diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index d3428b466c7acf..8496f91db2eec2 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -30,7 +30,7 @@ # include /* _lwp_self() */ #elif defined(__DragonFly__) # include /* lwp_gettid() */ -#elif defined(__sun__) +#elif defined(__sun__) && SIZEOF_LONG >= 8 # include #endif From 2ef75ecf4a1d84a4060472c9e2404dd1fd017982 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Aug 2025 19:41:47 +0300 Subject: [PATCH 12/12] Update Include/pythread.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Include/pythread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/pythread.h b/Include/pythread.h index d9cd33895f9518..a8a28b8572acb6 100644 --- a/Include/pythread.h +++ b/Include/pythread.h @@ -42,8 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void); #if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \ || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__) || defined(__NetBSD__) \ - || defined(__DragonFly__) || defined(_AIX)) \ - || defined(__sun__) && SIZEOF_LONG >= 8 + || defined(__DragonFly__) || defined(_AIX) \ + || (defined(__sun__) && SIZEOF_LONG >= 8)) #define PY_HAVE_THREAD_NATIVE_ID PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void); #endif