mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
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().
This commit is contained in:
parent
1e2147b9d7
commit
aefa7ebf0f
27 changed files with 116 additions and 88 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]*/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue