mcst-linux-kernel/patches-2024.06.26/python-stdlib-extensions-2..../0009-bug121650.patch

69 lines
1.8 KiB
Diff

diff -Naur old/Python/thread_pthread.h new/Python/thread_pthread.h
--- old/Python/thread_pthread.h 2020-03-13 16:21:20.845034698 +0300
+++ new/Python/thread_pthread.h 2020-03-13 16:30:05.223942052 +0300
@@ -156,6 +156,29 @@
* Thread support.
*/
+/* bpo-33015: pythread_callback struct and pythread_wrapper() cast
+ "void func(void *)" to "void* func(void *)": always return NULL.
+
+ PyThread_start_new_thread() uses "void func(void *)" type, whereas
+ pthread_create() requires a void* return value. */
+
+typedef struct {
+ void (*func) (void *);
+ void *arg;
+} pythread_callback;
+
+static void *
+pythread_wrapper(void *arg)
+{
+ /* copy func and func_arg and free the temporary structure */
+ pythread_callback *callback = arg;
+ void (*func)(void *) = callback->func;
+ void *func_arg = callback->arg;
+ free(arg);
+
+ func(func_arg);
+ return NULL;
+}
long
PyThread_start_new_thread(void (*func)(void *), void *arg)
@@ -191,21 +214,30 @@
pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
#endif
+ pythread_callback *callback = malloc(sizeof(pythread_callback));
+
+ if (callback == NULL) {
+ return -1;
+ }
+
+ callback->func = func;
+ callback->arg = arg;
+
status = pthread_create(&th,
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
&attrs,
#else
(pthread_attr_t*)NULL,
#endif
- (void* (*)(void *))func,
- (void *)arg
- );
+ pythread_wrapper, callback);
#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_destroy(&attrs);
#endif
- if (status != 0)
+ if (status != 0) {
+ free(callback);
return -1;
+ }
pthread_detach(th);