@@ -79,7 +79,12 @@ static PF_SET_THREAD_DESCRIPTION pSetThreadDescription = NULL;
7979#endif
8080
8181#if defined(HAVE_PTHREAD_SETNAME_NP ) || defined(HAVE_PTHREAD_SET_NAME_NP )
82- int _set_thread_name (const char * name );
82+ static int _set_thread_name (const char * name );
83+ #endif
84+
85+ // Fallback: Provides a no-op implementation if neither pthread naming API is available. This avoids linker errors and provides a portable stub.
86+ #if !defined(HAVE_PTHREAD_SETNAME_NP ) && !defined(HAVE_PTHREAD_SET_NAME_NP )
87+ static int _set_thread_name (const char * name ) { return 0 ; }
8388#endif
8489
8590
@@ -2582,7 +2587,7 @@ Set the name of the current thread.
25822587
25832588#ifndef MS_WINDOWS
25842589// Helper to set the thread name using platform-specific APIs (POSIX only)
2585- int
2590+ static int
25862591_set_thread_name (const char * name )
25872592{
25882593 int rc ;
@@ -2695,38 +2700,6 @@ _thread_set_name_impl(PyObject *module, PyObject *name_obj)
26952700}
26962701#endif // HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP || MS_WINDOWS
26972702
2698- /* Fallback no-op implementation for builds that didn't compile the
2699- * platform-specific _set_thread_name. This prevents undefined-reference
2700- * linker errors on CI images that don't compile the native helper.
2701- */
2702- #if !defined(HAVE_PTHREAD_SETNAME_NP ) && !defined(HAVE_PTHREAD_SET_NAME_NP ) && !defined(MS_WINDOWS )
2703- static int
2704- _set_thread_name (const char * name )
2705- {
2706- /* name is unused for the no-op fallback */
2707- (void )name ;
2708- return 0 ; /* indicate success (no-op) */
2709- }
2710- #endif
2711-
2712- /* Weak global fallback when the platform-specific helper isn't compiled.
2713- * On toolchains that support weak symbols (GCC/Clang), mark it weak so a
2714- * real strong implementation will override it. */
2715- #if !defined(HAVE_PTHREAD_SETNAME_NP ) && !defined(HAVE_PTHREAD_SET_NAME_NP ) && !defined(MS_WINDOWS )
2716-
2717- #if defined(__GNUC__ ) || defined(__clang__ )
2718- int __attribute__((weak ))
2719- _set_thread_name (const char * name )
2720- #else
2721- int
2722- _set_thread_name (const char * name )
2723- #endif
2724- {
2725- (void )name ;
2726- return 0 ;
2727- }
2728- #endif
2729-
27302703
27312704static PyMethodDef thread_methods [] = {
27322705 {"start_new_thread" , thread_PyThread_start_new_thread ,
0 commit comments