diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-23 13:48:39 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-03-23 13:48:39 (GMT) |
commit | aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5 (patch) | |
tree | 39560da26771d1e10add697e558bb727639fdbb0 /Modules | |
parent | 1e2147b9d75a64df370a9393c2b5b9d170dc0afd (diff) | |
download | cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.zip cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.tar.gz cpython-aefa7ebf0ff0f73feee7ab24f4cdcb2014d83ee5.tar.bz2 |
bpo-6532: Make the thread id an unsigned integer. (#781)
* bpo-6532: Make the thread id an unsigned integer.
From C API side the type of results of PyThread_start_new_thread() and
PyThread_get_thread_ident(), the id parameter of
PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState
changed from "long" to "unsigned long".
* Restore a check in thread_get_ident().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/bufferedio.c | 2 | ||||
-rw-r--r-- | Modules/_multiprocessing/semaphore.c | 2 | ||||
-rw-r--r-- | Modules/_sqlite/connection.c | 2 | ||||
-rw-r--r-- | Modules/_sqlite/connection.h | 2 | ||||
-rw-r--r-- | Modules/_ssl.c | 3 | ||||
-rw-r--r-- | Modules/_threadmodule.c | 29 | ||||
-rw-r--r-- | Modules/clinic/signalmodule.c.h | 9 | ||||
-rw-r--r-- | Modules/faulthandler.c | 2 | ||||
-rw-r--r-- | Modules/signalmodule.c | 9 |
9 files changed, 30 insertions, 30 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 4f6dddb..b30d229 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -239,7 +239,7 @@ typedef struct { #ifdef WITH_THREAD PyThread_type_lock lock; - volatile long owner; + volatile unsigned long owner; #endif Py_ssize_t buffer_size; diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index cea962a..9614329 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -14,7 +14,7 @@ enum { RECURSIVE_MUTEX, SEMAPHORE }; typedef struct { PyObject_HEAD SEM_HANDLE handle; - long last_tid; + unsigned long last_tid; int count; int maxvalue; int kind; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 7743999..72156b9 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1125,7 +1125,7 @@ int pysqlite_check_thread(pysqlite_Connection* self) if (PyThread_get_thread_ident() != self->thread_ident) { PyErr_Format(pysqlite_ProgrammingError, "SQLite objects created in a thread can only be used in that same thread." - "The object was created in thread id %ld and this is thread id %ld", + "The object was created in thread id %lu and this is thread id %lu", self->thread_ident, PyThread_get_thread_ident()); return 0; } diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h index 2860a0c..5fb410a 100644 --- a/Modules/_sqlite/connection.h +++ b/Modules/_sqlite/connection.h @@ -61,7 +61,7 @@ typedef struct int initialized; /* thread identification of the thread the connection was created in */ - long thread_ident; + unsigned long thread_ident; pysqlite_Cache* statement_cache; diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 421e0b6..327fb37 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -5032,8 +5032,7 @@ static PyThread_type_lock *_ssl_locks = NULL; static void _ssl_threadid_callback(CRYPTO_THREADID *id) { - CRYPTO_THREADID_set_numeric(id, - (unsigned long)PyThread_get_thread_ident()); + CRYPTO_THREADID_set_numeric(id, PyThread_get_thread_ident()); } #else /* deprecated CRYPTO_set_id_callback() API. */ diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index bf25a19..da750c0 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -267,7 +267,7 @@ static PyTypeObject Locktype = { typedef struct { PyObject_HEAD PyThread_type_lock rlock_lock; - long rlock_owner; + unsigned long rlock_owner; unsigned long rlock_count; PyObject *in_weakreflist; } rlockobject; @@ -293,7 +293,7 @@ static PyObject * rlock_acquire(rlockobject *self, PyObject *args, PyObject *kwds) { _PyTime_t timeout; - long tid; + unsigned long tid; PyLockStatus r = PY_LOCK_ACQUIRED; if (lock_acquire_parse_args(args, kwds, &timeout) < 0) @@ -342,7 +342,7 @@ the lock is taken and its internal counter initialized to 1."); static PyObject * rlock_release(rlockobject *self) { - long tid = PyThread_get_thread_ident(); + unsigned long tid = PyThread_get_thread_ident(); if (self->rlock_count == 0 || self->rlock_owner != tid) { PyErr_SetString(PyExc_RuntimeError, @@ -371,11 +371,11 @@ to be available for other threads."); static PyObject * rlock_acquire_restore(rlockobject *self, PyObject *args) { - long owner; + unsigned long owner; unsigned long count; int r = 1; - if (!PyArg_ParseTuple(args, "(kl):_acquire_restore", &count, &owner)) + if (!PyArg_ParseTuple(args, "(kk):_acquire_restore", &count, &owner)) return NULL; if (!PyThread_acquire_lock(self->rlock_lock, 0)) { @@ -401,7 +401,7 @@ For internal use by `threading.Condition`."); static PyObject * rlock_release_save(rlockobject *self) { - long owner; + unsigned long owner; unsigned long count; if (self->rlock_count == 0) { @@ -415,7 +415,7 @@ rlock_release_save(rlockobject *self) self->rlock_count = 0; self->rlock_owner = 0; PyThread_release_lock(self->rlock_lock); - return Py_BuildValue("kl", count, owner); + return Py_BuildValue("kk", count, owner); } PyDoc_STRVAR(rlock_release_save_doc, @@ -427,7 +427,7 @@ For internal use by `threading.Condition`."); static PyObject * rlock_is_owned(rlockobject *self) { - long tid = PyThread_get_thread_ident(); + unsigned long tid = PyThread_get_thread_ident(); if (self->rlock_count > 0 && self->rlock_owner == tid) { Py_RETURN_TRUE; @@ -1031,7 +1031,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) { PyObject *func, *args, *keyw = NULL; struct bootstate *boot; - long ident; + unsigned long ident; if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3, &func, &args, &keyw)) @@ -1068,7 +1068,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) Py_XINCREF(keyw); PyEval_InitThreads(); /* Start the interpreter's thread-awareness */ ident = PyThread_start_new_thread(t_bootstrap, (void*) boot); - if (ident == -1) { + if (ident == PYTHREAD_INVALID_THREAD_ID) { PyErr_SetString(ThreadError, "can't start new thread"); Py_DECREF(func); Py_DECREF(args); @@ -1077,7 +1077,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) PyMem_DEL(boot); return NULL; } - return PyLong_FromLong(ident); + return PyLong_FromUnsignedLong(ident); } PyDoc_STRVAR(start_new_doc, @@ -1137,13 +1137,12 @@ information about locks."); static PyObject * thread_get_ident(PyObject *self) { - long ident; - ident = PyThread_get_thread_ident(); - if (ident == -1) { + unsigned long ident = PyThread_get_thread_ident(); + if (ident == PYTHREAD_INVALID_THREAD_ID) { PyErr_SetString(ThreadError, "no current thread ident"); return NULL; } - return PyLong_FromLong(ident); + return PyLong_FromUnsignedLong(ident); } PyDoc_STRVAR(get_ident_doc, diff --git a/Modules/clinic/signalmodule.c.h b/Modules/clinic/signalmodule.c.h index 9e16f32..2a4e935 100644 --- a/Modules/clinic/signalmodule.c.h +++ b/Modules/clinic/signalmodule.c.h @@ -395,16 +395,17 @@ PyDoc_STRVAR(signal_pthread_kill__doc__, {"pthread_kill", (PyCFunction)signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__}, static PyObject * -signal_pthread_kill_impl(PyObject *module, long thread_id, int signalnum); +signal_pthread_kill_impl(PyObject *module, unsigned long thread_id, + int signalnum); static PyObject * signal_pthread_kill(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - long thread_id; + unsigned long thread_id; int signalnum; - if (!_PyArg_ParseStack(args, nargs, "li:pthread_kill", + if (!_PyArg_ParseStack(args, nargs, "ki:pthread_kill", &thread_id, &signalnum)) { goto exit; } @@ -463,4 +464,4 @@ exit: #ifndef SIGNAL_PTHREAD_KILL_METHODDEF #define SIGNAL_PTHREAD_KILL_METHODDEF #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ -/*[clinic end generated code: output=fab3dba32c058588 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c1a3f374b2c77e5d input=a9049054013a1b77]*/ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 4fc8ebd..4a03eaf 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -678,7 +678,7 @@ faulthandler_dump_traceback_later(PyObject *self, /* Arm these locks to serve as events when released */ PyThread_acquire_lock(thread.running, 1); - if (PyThread_start_new_thread(faulthandler_thread, NULL) == -1) { + if (PyThread_start_new_thread(faulthandler_thread, NULL) == PYTHREAD_INVALID_THREAD_ID) { PyThread_release_lock(thread.running); Py_CLEAR(thread.file); PyMem_Free(header); diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index bc36d41..ed03683 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -88,7 +88,7 @@ module signal #ifdef WITH_THREAD #include <sys/types.h> /* For pid_t */ #include "pythread.h" -static long main_thread; +static unsigned long main_thread; static pid_t main_pid; #endif @@ -1088,7 +1088,7 @@ signal_sigtimedwait_impl(PyObject *module, PyObject *sigset, /*[clinic input] signal.pthread_kill - thread_id: long + thread_id: unsigned_long(bitwise=True) signalnum: int / @@ -1096,8 +1096,9 @@ Send a signal to a thread. [clinic start generated code]*/ static PyObject * -signal_pthread_kill_impl(PyObject *module, long thread_id, int signalnum) -/*[clinic end generated code: output=2a09ce41f1c4228a input=77ed6a3b6f2a8122]*/ +signal_pthread_kill_impl(PyObject *module, unsigned long thread_id, + int signalnum) +/*[clinic end generated code: output=7629919b791bc27f input=1d901f2c7bb544ff]*/ { int err; |