From 7850c7be123de47df42d181353b3ace62b8b71e2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 7 Jul 2013 17:17:59 +0200 Subject: Issue #18203: Replace malloc() with PyMem_RawMalloc() to allocate thread locks --- Python/thread_pthread.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Python/thread_pthread.h') diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index e90ae7e5b9..20f8535896 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -282,14 +282,14 @@ PyThread_allocate_lock(void) if (!initialized) PyThread_init_thread(); - lock = (sem_t *)malloc(sizeof(sem_t)); + lock = (sem_t *)PyMem_RawMalloc(sizeof(sem_t)); if (lock) { status = sem_init(lock,0,1); CHECK_STATUS("sem_init"); if (error) { - free((void *)lock); + PyMem_RawFree((void *)lock); lock = NULL; } } @@ -313,7 +313,7 @@ PyThread_free_lock(PyThread_type_lock lock) status = sem_destroy(thelock); CHECK_STATUS("sem_destroy"); - free((void *)thelock); + PyMem_RawFree((void *)thelock); } /* @@ -410,7 +410,7 @@ PyThread_allocate_lock(void) if (!initialized) PyThread_init_thread(); - lock = (pthread_lock *) malloc(sizeof(pthread_lock)); + lock = (pthread_lock *) PyMem_RawMalloc(sizeof(pthread_lock)); if (lock) { memset((void *)lock, '\0', sizeof(pthread_lock)); lock->locked = 0; @@ -430,7 +430,7 @@ PyThread_allocate_lock(void) CHECK_STATUS("pthread_cond_init"); if (error) { - free((void *)lock); + PyMem_RawFree((void *)lock); lock = 0; } } @@ -457,7 +457,7 @@ PyThread_free_lock(PyThread_type_lock lock) status = pthread_mutex_destroy( &thelock->mut ); CHECK_STATUS("pthread_mutex_destroy"); - free((void *)thelock); + PyMem_RawFree((void *)thelock); } PyLockStatus -- cgit v1.2.1 From d550baed54513c65c83fb4e8706ddb3984f58f10 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 13 Dec 2013 03:22:00 +0100 Subject: Close #19787: PyThread_set_key_value() now always set the value. In Python 3.3, the function did nothing if the key already exists (if the current value is a non-NULL pointer). _testcapi.run_in_subinterp() now correctly sets the new Python thread state of the current thread when a subinterpreter is created. --- Python/thread_pthread.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'Python/thread_pthread.h') diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 20f8535896..d9f7c76f2a 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -627,9 +627,6 @@ int PyThread_set_key_value(int key, void *value) { int fail; - void *oldValue = pthread_getspecific(key); - if (oldValue != NULL) - return 0; fail = pthread_setspecific(key, value); return fail ? -1 : 0; } -- cgit v1.2.1 From 85178aa8d643e098eeb3d1314194316369b49846 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 13 Dec 2013 04:14:41 +0100 Subject: Backout changeset 46393019b650 test_capi is failing and the fix is not trivial, I prefer to revert --- Python/thread_pthread.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Python/thread_pthread.h') diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index d9f7c76f2a..20f8535896 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -627,6 +627,9 @@ int PyThread_set_key_value(int key, void *value) { int fail; + void *oldValue = pthread_getspecific(key); + if (oldValue != NULL) + return 0; fail = pthread_setspecific(key, value); return fail ? -1 : 0; } -- cgit v1.2.1 From 63ac1fa663bbf793deb6f65ccea16f1bd8a5944c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 13 Dec 2013 11:08:56 +0100 Subject: Issue #19787: PyThread_set_key_value() now always set the value In Python 3.3, PyThread_set_key_value() did nothing if the key already exists (if the current value is a non-NULL pointer). When _PyGILState_NoteThreadState() is called twice on the same thread with a different Python thread state, it still keeps the old Python thread state to keep the old behaviour. Replacing the Python thread state with the new state introduces new bugs: see issues #10915 and #15751. --- Python/thread_pthread.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'Python/thread_pthread.h') diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 20f8535896..d9f7c76f2a 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -627,9 +627,6 @@ int PyThread_set_key_value(int key, void *value) { int fail; - void *oldValue = pthread_getspecific(key); - if (oldValue != NULL) - return 0; fail = pthread_setspecific(key, value); return fail ? -1 : 0; } -- cgit v1.2.1