From 63755a6bb1e812c6a3b40b158dded0aed326bf77 Mon Sep 17 00:00:00 2001 From: Jesus Cea Date: Fri, 5 Oct 2012 01:04:27 +0200 Subject: #16135: Removal of OS/2 support (I) --- Python/thread.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index e55d34244e..25ab16e647 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -91,10 +91,6 @@ static size_t _pythread_stacksize = 0; #include "thread_nt.h" #endif -#ifdef OS2_THREADS -#define PYTHREAD_NAME "os2" -#include "thread_os2.h" -#endif /* #ifdef FOOBAR_THREADS -- cgit v1.2.1 From 0e6215070ac12c5aecdce573f75624eaa7ed056e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 7 Jul 2013 16:25:15 +0200 Subject: Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization * Replace malloc() with PyMem_RawMalloc() * Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held. * _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead of PyMem_Malloc() --- Python/thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index 25ab16e647..54ce875eb2 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -231,7 +231,7 @@ find_key(int key, void *value) assert(p == NULL); goto Done; } - p = (struct key *)malloc(sizeof(struct key)); + p = (struct key *)PyMem_RawMalloc(sizeof(struct key)); if (p != NULL) { p->id = id; p->key = key; @@ -270,7 +270,7 @@ PyThread_delete_key(int key) while ((p = *q) != NULL) { if (p->key == key) { *q = p->next; - free((void *)p); + PyMem_RawFree((void *)p); /* NB This does *not* free p->value! */ } else @@ -324,7 +324,7 @@ PyThread_delete_key_value(int key) while ((p = *q) != NULL) { if (p->key == key && p->id == id) { *q = p->next; - free((void *)p); + PyMem_RawFree((void *)p); /* NB This does *not* free p->value! */ break; } @@ -357,7 +357,7 @@ PyThread_ReInitTLS(void) while ((p = *q) != NULL) { if (p->id != id) { *q = p->next; - free((void *)p); + PyMem_RawFree((void *)p); /* NB This does *not* free p->value! */ } else -- cgit v1.2.1 From 92d3e3cf6bfe7320aea27780a6525e6075624935 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 22 Jul 2013 22:24:54 +0200 Subject: Issue #18520: Add a new PyStructSequence_InitType2() function, same than PyStructSequence_InitType() except that it has a return value (0 on success, -1 on error). * PyStructSequence_InitType2() now raises MemoryError on memory allocation failure * Fix also some calls to PyDict_SetItemString(): handle error --- Python/thread.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index 54ce875eb2..8540942e28 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -399,8 +399,10 @@ PyThread_GetInfo(void) int len; #endif - if (ThreadInfoType.tp_name == 0) - PyStructSequence_InitType(&ThreadInfoType, &threadinfo_desc); + if (ThreadInfoType.tp_name == 0) { + if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0) + return NULL; + } threadinfo = PyStructSequence_New(&ThreadInfoType); if (threadinfo == NULL) -- 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.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index 8540942e28..5396ca30e3 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -205,7 +205,7 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ * segfaults. Now we lock the whole routine. */ static struct key * -find_key(int key, void *value) +find_key(int key, int update, void *value) { struct key *p, *prev_p; long id = PyThread_get_thread_ident(); @@ -215,8 +215,11 @@ find_key(int key, void *value) PyThread_acquire_lock(keymutex, 1); prev_p = NULL; for (p = keyhead; p != NULL; p = p->next) { - if (p->id == id && p->key == key) + if (p->id == id && p->key == key) { + if (update) + p->value = value; goto Done; + } /* Sanity check. These states should never happen but if * they do we must abort. Otherwise we'll end up spinning in * in a tight loop with the lock held. A similar check is done @@ -227,7 +230,7 @@ find_key(int key, void *value) if (p->next == keyhead) Py_FatalError("tls find_key: circular list(!)"); } - if (value == NULL) { + if (!update && value == NULL) { assert(p == NULL); goto Done; } @@ -279,19 +282,12 @@ PyThread_delete_key(int key) PyThread_release_lock(keymutex); } -/* Confusing: If the current thread has an association for key, - * value is ignored, and 0 is returned. Else an attempt is made to create - * an association of key to value for the current thread. 0 is returned - * if that succeeds, but -1 is returned if there's not enough memory - * to create the association. value must not be NULL. - */ int PyThread_set_key_value(int key, void *value) { struct key *p; - assert(value != NULL); - p = find_key(key, value); + p = find_key(key, 1, value); if (p == NULL) return -1; else @@ -304,7 +300,7 @@ PyThread_set_key_value(int key, void *value) void * PyThread_get_key_value(int key) { - struct key *p = find_key(key, NULL); + struct key *p = find_key(key, 0, NULL); if (p == NULL) return NULL; -- 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.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index 5396ca30e3..8540942e28 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -205,7 +205,7 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ * segfaults. Now we lock the whole routine. */ static struct key * -find_key(int key, int update, void *value) +find_key(int key, void *value) { struct key *p, *prev_p; long id = PyThread_get_thread_ident(); @@ -215,11 +215,8 @@ find_key(int key, int update, void *value) PyThread_acquire_lock(keymutex, 1); prev_p = NULL; for (p = keyhead; p != NULL; p = p->next) { - if (p->id == id && p->key == key) { - if (update) - p->value = value; + if (p->id == id && p->key == key) goto Done; - } /* Sanity check. These states should never happen but if * they do we must abort. Otherwise we'll end up spinning in * in a tight loop with the lock held. A similar check is done @@ -230,7 +227,7 @@ find_key(int key, int update, void *value) if (p->next == keyhead) Py_FatalError("tls find_key: circular list(!)"); } - if (!update && value == NULL) { + if (value == NULL) { assert(p == NULL); goto Done; } @@ -282,12 +279,19 @@ PyThread_delete_key(int key) PyThread_release_lock(keymutex); } +/* Confusing: If the current thread has an association for key, + * value is ignored, and 0 is returned. Else an attempt is made to create + * an association of key to value for the current thread. 0 is returned + * if that succeeds, but -1 is returned if there's not enough memory + * to create the association. value must not be NULL. + */ int PyThread_set_key_value(int key, void *value) { struct key *p; - p = find_key(key, 1, value); + assert(value != NULL); + p = find_key(key, value); if (p == NULL) return -1; else @@ -300,7 +304,7 @@ PyThread_set_key_value(int key, void *value) void * PyThread_get_key_value(int key) { - struct key *p = find_key(key, 0, NULL); + struct key *p = find_key(key, NULL); if (p == NULL) return NULL; -- 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.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'Python/thread.c') diff --git a/Python/thread.c b/Python/thread.c index 8540942e28..d1cb0e6f9d 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -205,7 +205,7 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ * segfaults. Now we lock the whole routine. */ static struct key * -find_key(int key, void *value) +find_key(int set_value, int key, void *value) { struct key *p, *prev_p; long id = PyThread_get_thread_ident(); @@ -215,8 +215,11 @@ find_key(int key, void *value) PyThread_acquire_lock(keymutex, 1); prev_p = NULL; for (p = keyhead; p != NULL; p = p->next) { - if (p->id == id && p->key == key) + if (p->id == id && p->key == key) { + if (set_value) + p->value = value; goto Done; + } /* Sanity check. These states should never happen but if * they do we must abort. Otherwise we'll end up spinning in * in a tight loop with the lock held. A similar check is done @@ -227,7 +230,7 @@ find_key(int key, void *value) if (p->next == keyhead) Py_FatalError("tls find_key: circular list(!)"); } - if (value == NULL) { + if (!set_value && value == NULL) { assert(p == NULL); goto Done; } @@ -279,19 +282,12 @@ PyThread_delete_key(int key) PyThread_release_lock(keymutex); } -/* Confusing: If the current thread has an association for key, - * value is ignored, and 0 is returned. Else an attempt is made to create - * an association of key to value for the current thread. 0 is returned - * if that succeeds, but -1 is returned if there's not enough memory - * to create the association. value must not be NULL. - */ int PyThread_set_key_value(int key, void *value) { struct key *p; - assert(value != NULL); - p = find_key(key, value); + p = find_key(1, key, value); if (p == NULL) return -1; else @@ -304,7 +300,7 @@ PyThread_set_key_value(int key, void *value) void * PyThread_get_key_value(int key) { - struct key *p = find_key(key, NULL); + struct key *p = find_key(0, key, NULL); if (p == NULL) return NULL; -- cgit v1.2.1