@@ -44,7 +44,7 @@ get_thread_state(PyObject *module)
44
44
45
45
typedef struct {
46
46
PyObject_HEAD
47
- unsigned long ident ; // TODO ULL instead
47
+ unsigned long long ident ;
48
48
Py_uintptr_t handle ;
49
49
char joinable ;
50
50
} ThreadHandleObject ;
@@ -80,14 +80,14 @@ ThreadHandle_dealloc(ThreadHandleObject *self)
80
80
static PyObject *
81
81
ThreadHandle_repr (ThreadHandleObject * self )
82
82
{
83
- return PyUnicode_FromFormat ("<%s object: ident=%ul >" ,
83
+ return PyUnicode_FromFormat ("<%s object: ident=%llu >" ,
84
84
Py_TYPE (self )-> tp_name , self -> ident );
85
85
}
86
86
87
87
static PyObject *
88
88
ThreadHandle_get_ident (ThreadHandleObject * self , void * ignored )
89
89
{
90
- return PyLong_FromUnsignedLong (self -> ident );
90
+ return PyLong_FromUnsignedLongLong (self -> ident );
91
91
}
92
92
93
93
static PyObject *
@@ -115,7 +115,7 @@ ThreadHandle_join(ThreadHandleObject *self, void* ignored)
115
115
PyErr_SetString (PyExc_ValueError , "the thread is not joinable" );
116
116
return NULL ;
117
117
}
118
- if (self -> ident == PyThread_get_thread_ident ()) {
118
+ if (self -> ident == PyThread_get_thread_ident_ex ()) {
119
119
// PyThread_join_thread() would deadlock or error out.
120
120
PyErr_SetString (ThreadError , "Cannot join current thread" );
121
121
return NULL ;
@@ -397,7 +397,7 @@ static PyType_Spec lock_type_spec = {
397
397
typedef struct {
398
398
PyObject_HEAD
399
399
PyThread_type_lock rlock_lock ;
400
- unsigned long rlock_owner ;
400
+ unsigned long long rlock_owner ;
401
401
unsigned long rlock_count ;
402
402
PyObject * in_weakreflist ;
403
403
} rlockobject ;
@@ -434,13 +434,13 @@ static PyObject *
434
434
rlock_acquire (rlockobject * self , PyObject * args , PyObject * kwds )
435
435
{
436
436
_PyTime_t timeout ;
437
- unsigned long tid ;
437
+ unsigned long long tid ;
438
438
PyLockStatus r = PY_LOCK_ACQUIRED ;
439
439
440
440
if (lock_acquire_parse_args (args , kwds , & timeout ) < 0 )
441
441
return NULL ;
442
442
443
- tid = PyThread_get_thread_ident ();
443
+ tid = PyThread_get_thread_ident_ex ();
444
444
if (self -> rlock_count > 0 && tid == self -> rlock_owner ) {
445
445
unsigned long count = self -> rlock_count + 1 ;
446
446
if (count <= self -> rlock_count ) {
@@ -483,7 +483,7 @@ the lock is taken and its internal counter initialized to 1.");
483
483
static PyObject *
484
484
rlock_release (rlockobject * self , PyObject * Py_UNUSED (ignored ))
485
485
{
486
- unsigned long tid = PyThread_get_thread_ident ();
486
+ unsigned long long tid = PyThread_get_thread_ident_ex ();
487
487
488
488
if (self -> rlock_count == 0 || self -> rlock_owner != tid ) {
489
489
PyErr_SetString (PyExc_RuntimeError ,
@@ -567,7 +567,7 @@ For internal use by `threading.Condition`.");
567
567
static PyObject *
568
568
rlock_recursion_count (rlockobject * self , PyObject * Py_UNUSED (ignored ))
569
569
{
570
- unsigned long tid = PyThread_get_thread_ident ();
570
+ unsigned long long tid = PyThread_get_thread_ident_ex ();
571
571
return PyLong_FromUnsignedLong (
572
572
self -> rlock_owner == tid ? self -> rlock_count : 0UL );
573
573
}
@@ -580,7 +580,7 @@ For internal use by reentrancy checks.");
580
580
static PyObject *
581
581
rlock_is_owned (rlockobject * self , PyObject * Py_UNUSED (ignored ))
582
582
{
583
- unsigned long tid = PyThread_get_thread_ident ();
583
+ unsigned long long tid = PyThread_get_thread_ident_ex ();
584
584
585
585
if (self -> rlock_count > 0 && self -> rlock_owner == tid ) {
586
586
Py_RETURN_TRUE ;
@@ -1235,7 +1235,7 @@ static int
1235
1235
do_start_new_thread (thread_module_state * state ,
1236
1236
PyObject * func , PyObject * args , PyObject * kwargs ,
1237
1237
int joinable ,
1238
- unsigned long * ident , Py_uintptr_t * handle )
1238
+ unsigned long long * ident , Py_uintptr_t * handle )
1239
1239
{
1240
1240
PyInterpreterState * interp = _PyInterpreterState_GET ();
1241
1241
if (!_PyInterpreterState_HasFeature (interp , Py_RTFLAGS_THREADS )) {
@@ -1269,13 +1269,15 @@ do_start_new_thread(thread_module_state* state,
1269
1269
boot -> args = Py_NewRef (args );
1270
1270
boot -> kwargs = Py_XNewRef (kwargs );
1271
1271
1272
+ int err ;
1272
1273
if (joinable ) {
1273
- * ident = PyThread_start_joinable_thread (thread_run , (void * ) boot , handle );
1274
+ err = PyThread_start_joinable_thread (thread_run , (void * ) boot , ident , handle );
1274
1275
} else {
1275
1276
* handle = 0 ;
1276
1277
* ident = PyThread_start_new_thread (thread_run , (void * ) boot );
1278
+ err = (* ident == PYTHREAD_INVALID_THREAD_ID );
1277
1279
}
1278
- if (* ident == PYTHREAD_INVALID_THREAD_ID ) {
1280
+ if (err ) {
1279
1281
PyErr_SetString (ThreadError , "can't start new thread" );
1280
1282
PyThreadState_Clear (boot -> tstate );
1281
1283
thread_bootstate_free (boot , 1 );
@@ -1314,13 +1316,13 @@ thread_PyThread_start_new_thread(PyObject *module, PyObject *fargs)
1314
1316
return NULL ;
1315
1317
}
1316
1318
1317
- unsigned long ident = 0 ;
1319
+ unsigned long long ident = 0 ;
1318
1320
Py_uintptr_t handle ;
1319
1321
if (do_start_new_thread (state , func , args , kwargs , /*joinable=*/ 0 ,
1320
1322
& ident , & handle )) {
1321
1323
return NULL ;
1322
1324
}
1323
- return PyLong_FromUnsignedLong (ident );
1325
+ return PyLong_FromUnsignedLongLong (ident );
1324
1326
}
1325
1327
1326
1328
PyDoc_STRVAR (start_new_doc ,
@@ -1440,12 +1442,12 @@ information about locks.");
1440
1442
static PyObject *
1441
1443
thread_get_ident (PyObject * self , PyObject * Py_UNUSED (ignored ))
1442
1444
{
1443
- unsigned long ident = PyThread_get_thread_ident ();
1445
+ unsigned long long ident = PyThread_get_thread_ident_ex ();
1444
1446
if (ident == PYTHREAD_INVALID_THREAD_ID ) {
1445
1447
PyErr_SetString (ThreadError , "no current thread ident" );
1446
1448
return NULL ;
1447
1449
}
1448
- return PyLong_FromUnsignedLong (ident );
1450
+ return PyLong_FromUnsignedLongLong (ident );
1449
1451
}
1450
1452
1451
1453
PyDoc_STRVAR (get_ident_doc ,
@@ -1632,8 +1634,8 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
1632
1634
Py_DECREF (name );
1633
1635
}
1634
1636
else {
1635
- unsigned long ident = PyThread_get_thread_ident ();
1636
- PyObject * str = PyUnicode_FromFormat ("%lu " , ident );
1637
+ unsigned long long ident = PyThread_get_thread_ident_ex ();
1638
+ PyObject * str = PyUnicode_FromFormat ("%llu " , ident );
1637
1639
if (str != NULL ) {
1638
1640
if (PyFile_WriteObject (str , file , Py_PRINT_RAW ) < 0 ) {
1639
1641
Py_DECREF (str );
0 commit comments