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().
diff --git a/Include/pystate.h b/Include/pystate.h
index afc3c0c..62254fa 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -108,7 +108,7 @@
     int gilstate_counter;
 
     PyObject *async_exc; /* Asynchronous exception to raise */
-    long thread_id; /* Thread id where this tstate was created */
+    unsigned long thread_id; /* Thread id where this tstate was created */
 
     int trash_delete_nesting;
     PyObject *trash_delete_later;
@@ -200,7 +200,7 @@
 
 PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
 PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
-PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
+PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
 
 
 /* Variable and macro for in-line access to current thread state */
diff --git a/Include/pythread.h b/Include/pythread.h
index 88c4873..dbacb8b 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -17,10 +17,14 @@
     PY_LOCK_INTR
 } PyLockStatus;
 
+#ifndef Py_LIMITED_API
+#define PYTHREAD_INVALID_THREAD_ID ((unsigned long)-1)
+#endif
+
 PyAPI_FUNC(void) PyThread_init_thread(void);
-PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
+PyAPI_FUNC(unsigned long) PyThread_start_new_thread(void (*)(void *), void *);
 PyAPI_FUNC(void) PyThread_exit_thread(void);
-PyAPI_FUNC(long) PyThread_get_thread_ident(void);
+PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
 
 PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
 PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);