From d6fd0bcea9912a6dc166c5120b1c0fd8c98a334e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 23 Oct 2018 12:58:28 +0200 Subject: [PATCH] bpo-33015: Fix func cast warn in PyThread_start_new_thread() Fix a warning on a cast between two different function pointer types in the pthread implementation of PyThread_start_new_thread(). Cast the function pointer temporarily to "void *" to mute the warning. The overall cast changes the return type of the function pointer: convert "void" return type (no return type) to "void*" return type. Python uses pthread_detach() and doesn't use pthread_join(), the thread return value is ignored. --- Python/thread_pthread.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 697140558fdc5e7..b5c9934e01a667a 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -164,6 +164,14 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) #if defined(THREAD_STACK_SIZE) size_t tss; #endif + /* bpo-33015: Use a temporary cast of the function pointer to "void*" + to avoid a compiler warning on the + "void (*func)(void *)" => "void *(*func) (void *)" cast + ("void" return type => "void*" return type). + + Python uses pthread_detach() and doesn't use pthread_join(), + the thread return value is ignored. */ + void *(*start_routine) (void *) = (void *)func; dprintf(("PyThread_start_new_thread called\n")); if (!initialized) @@ -194,9 +202,8 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) #else (pthread_attr_t*)NULL, #endif - (void* (*)(void *))func, - (void *)arg - ); + start_routine, + arg); #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) pthread_attr_destroy(&attrs);