@@ -44,7 +44,7 @@ get_thread_state(PyObject *module)
4444
4545typedef struct {
4646 PyObject_HEAD
47- unsigned long ident ; // TODO ULL instead
47+ unsigned long long ident ;
4848 Py_uintptr_t handle ;
4949 char joinable ;
5050} ThreadHandleObject ;
@@ -80,14 +80,14 @@ ThreadHandle_dealloc(ThreadHandleObject *self)
8080static PyObject *
8181ThreadHandle_repr (ThreadHandleObject * self )
8282{
83- return PyUnicode_FromFormat ("<%s object: ident=%ul >" ,
83+ return PyUnicode_FromFormat ("<%s object: ident=%llu >" ,
8484 Py_TYPE (self )-> tp_name , self -> ident );
8585}
8686
8787static PyObject *
8888ThreadHandle_get_ident (ThreadHandleObject * self , void * ignored )
8989{
90- return PyLong_FromUnsignedLong (self -> ident );
90+ return PyLong_FromUnsignedLongLong (self -> ident );
9191}
9292
9393static PyObject *
@@ -115,7 +115,7 @@ ThreadHandle_join(ThreadHandleObject *self, void* ignored)
115115 PyErr_SetString (PyExc_ValueError , "the thread is not joinable" );
116116 return NULL ;
117117 }
118- if (self -> ident == PyThread_get_thread_ident ()) {
118+ if (self -> ident == PyThread_get_thread_ident_ex ()) {
119119 // PyThread_join_thread() would deadlock or error out.
120120 PyErr_SetString (ThreadError , "Cannot join current thread" );
121121 return NULL ;
@@ -397,7 +397,7 @@ static PyType_Spec lock_type_spec = {
397397typedef struct {
398398 PyObject_HEAD
399399 PyThread_type_lock rlock_lock ;
400- unsigned long rlock_owner ;
400+ unsigned long long rlock_owner ;
401401 unsigned long rlock_count ;
402402 PyObject * in_weakreflist ;
403403} rlockobject ;
@@ -434,13 +434,13 @@ static PyObject *
434434rlock_acquire (rlockobject * self , PyObject * args , PyObject * kwds )
435435{
436436 _PyTime_t timeout ;
437- unsigned long tid ;
437+ unsigned long long tid ;
438438 PyLockStatus r = PY_LOCK_ACQUIRED ;
439439
440440 if (lock_acquire_parse_args (args , kwds , & timeout ) < 0 )
441441 return NULL ;
442442
443- tid = PyThread_get_thread_ident ();
443+ tid = PyThread_get_thread_ident_ex ();
444444 if (self -> rlock_count > 0 && tid == self -> rlock_owner ) {
445445 unsigned long count = self -> rlock_count + 1 ;
446446 if (count <= self -> rlock_count ) {
@@ -483,7 +483,7 @@ the lock is taken and its internal counter initialized to 1.");
483483static PyObject *
484484rlock_release (rlockobject * self , PyObject * Py_UNUSED (ignored ))
485485{
486- unsigned long tid = PyThread_get_thread_ident ();
486+ unsigned long long tid = PyThread_get_thread_ident_ex ();
487487
488488 if (self -> rlock_count == 0 || self -> rlock_owner != tid ) {
489489 PyErr_SetString (PyExc_RuntimeError ,
@@ -567,7 +567,7 @@ For internal use by `threading.Condition`.");
567567static PyObject *
568568rlock_recursion_count (rlockobject * self , PyObject * Py_UNUSED (ignored ))
569569{
570- unsigned long tid = PyThread_get_thread_ident ();
570+ unsigned long long tid = PyThread_get_thread_ident_ex ();
571571 return PyLong_FromUnsignedLong (
572572 self -> rlock_owner == tid ? self -> rlock_count : 0UL );
573573}
@@ -580,7 +580,7 @@ For internal use by reentrancy checks.");
580580static PyObject *
581581rlock_is_owned (rlockobject * self , PyObject * Py_UNUSED (ignored ))
582582{
583- unsigned long tid = PyThread_get_thread_ident ();
583+ unsigned long long tid = PyThread_get_thread_ident_ex ();
584584
585585 if (self -> rlock_count > 0 && self -> rlock_owner == tid ) {
586586 Py_RETURN_TRUE ;
@@ -1235,7 +1235,7 @@ static int
12351235do_start_new_thread (thread_module_state * state ,
12361236 PyObject * func , PyObject * args , PyObject * kwargs ,
12371237 int joinable ,
1238- unsigned long * ident , Py_uintptr_t * handle )
1238+ unsigned long long * ident , Py_uintptr_t * handle )
12391239{
12401240 PyInterpreterState * interp = _PyInterpreterState_GET ();
12411241 if (!_PyInterpreterState_HasFeature (interp , Py_RTFLAGS_THREADS )) {
@@ -1269,13 +1269,15 @@ do_start_new_thread(thread_module_state* state,
12691269 boot -> args = Py_NewRef (args );
12701270 boot -> kwargs = Py_XNewRef (kwargs );
12711271
1272+ int err ;
12721273 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 );
12741275 } else {
12751276 * handle = 0 ;
12761277 * ident = PyThread_start_new_thread (thread_run , (void * ) boot );
1278+ err = (* ident == PYTHREAD_INVALID_THREAD_ID );
12771279 }
1278- if (* ident == PYTHREAD_INVALID_THREAD_ID ) {
1280+ if (err ) {
12791281 PyErr_SetString (ThreadError , "can't start new thread" );
12801282 PyThreadState_Clear (boot -> tstate );
12811283 thread_bootstate_free (boot , 1 );
@@ -1314,13 +1316,13 @@ thread_PyThread_start_new_thread(PyObject *module, PyObject *fargs)
13141316 return NULL ;
13151317 }
13161318
1317- unsigned long ident = 0 ;
1319+ unsigned long long ident = 0 ;
13181320 Py_uintptr_t handle ;
13191321 if (do_start_new_thread (state , func , args , kwargs , /*joinable=*/ 0 ,
13201322 & ident , & handle )) {
13211323 return NULL ;
13221324 }
1323- return PyLong_FromUnsignedLong (ident );
1325+ return PyLong_FromUnsignedLongLong (ident );
13241326}
13251327
13261328PyDoc_STRVAR (start_new_doc ,
@@ -1440,12 +1442,12 @@ information about locks.");
14401442static PyObject *
14411443thread_get_ident (PyObject * self , PyObject * Py_UNUSED (ignored ))
14421444{
1443- unsigned long ident = PyThread_get_thread_ident ();
1445+ unsigned long long ident = PyThread_get_thread_ident_ex ();
14441446 if (ident == PYTHREAD_INVALID_THREAD_ID ) {
14451447 PyErr_SetString (ThreadError , "no current thread ident" );
14461448 return NULL ;
14471449 }
1448- return PyLong_FromUnsignedLong (ident );
1450+ return PyLong_FromUnsignedLongLong (ident );
14491451}
14501452
14511453PyDoc_STRVAR (get_ident_doc ,
@@ -1632,8 +1634,8 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
16321634 Py_DECREF (name );
16331635 }
16341636 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 );
16371639 if (str != NULL ) {
16381640 if (PyFile_WriteObject (str , file , Py_PRINT_RAW ) < 0 ) {
16391641 Py_DECREF (str );
0 commit comments