Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More cleanup
* Rename "fn" to "callback"
* Add { ... } to if
* Remove useless cast
  • Loading branch information
vstinner committed Nov 30, 2018
commit 6d0bade9431ccf1e15bfa0750f99342b51947b02
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Add a wrapper for the thread function argument in
`PyThread_start_new_thread` to avoid an incompatible cast warning with gcc
8.
Fix an undefined behaviour in the pthread implementation of
:c:func:`PyThread_start_new_thread`: add a function wrapper to always return
``NULL`.
13 changes: 7 additions & 6 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,29 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
#endif

pythread_callback *fn = PyMem_RawMalloc(sizeof(pythread_callback));
pythread_callback *callback = PyMem_RawMalloc(sizeof(pythread_callback));

if (fn == NULL)
if (callback == NULL) {
return PYTHREAD_INVALID_THREAD_ID;
Comment thread
vstinner marked this conversation as resolved.
Outdated
}

fn->func = func;
fn->arg = arg;
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
pythread_wrapper, fn);
pythread_wrapper, callback);

#if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
pthread_attr_destroy(&attrs);
#endif

if (status != 0) {
PyMem_RawFree((void *)fn);
PyMem_RawFree(callback);
return PYTHREAD_INVALID_THREAD_ID;
}

Expand Down