diff -r 784fea019cab Include/pythread.h --- a/Include/pythread.h Wed Nov 09 18:57:00 2016 -0500 +++ b/Include/pythread.h Fri Nov 11 00:25:33 2016 +0900 @@ -25,8 +25,8 @@ PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void); PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock); PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int); -#define WAIT_LOCK 1 -#define NOWAIT_LOCK 0 +#define WAIT_LOCK 1 +#define NOWAIT_LOCK 0 /* PY_TIMEOUT_T is the integral type used to specify timeouts when waiting on a lock (see PyThread_acquire_lock_timed() below). @@ -72,11 +72,11 @@ PyAPI_FUNC(PyObject*) PyThread_GetInfo(void); /* Thread Local Storage (TLS) API */ -PyAPI_FUNC(int) PyThread_create_key(void); -PyAPI_FUNC(void) PyThread_delete_key(int); -PyAPI_FUNC(int) PyThread_set_key_value(int, void *); -PyAPI_FUNC(void *) PyThread_get_key_value(int); -PyAPI_FUNC(void) PyThread_delete_key_value(int key); +PyAPI_FUNC(intptr_t) PyThread_create_key(void); +PyAPI_FUNC(void) PyThread_delete_key(intptr_t); +PyAPI_FUNC(int) PyThread_set_key_value(intptr_t, void *); +PyAPI_FUNC(void *) PyThread_get_key_value(intptr_t); +PyAPI_FUNC(void) PyThread_delete_key_value(intptr_t key); /* Cleanup after a fork */ PyAPI_FUNC(void) PyThread_ReInitTLS(void); diff -r 784fea019cab Modules/_tracemalloc.c --- a/Modules/_tracemalloc.c Wed Nov 09 18:57:00 2016 -0500 +++ b/Modules/_tracemalloc.c Fri Nov 11 00:25:33 2016 +0900 @@ -165,7 +165,7 @@ # error "need native thread local storage (TLS)" #endif -static int tracemalloc_reentrant_key = -1; +static intptr_t tracemalloc_reentrant_key = -1; /* Any non-NULL pointer can be used */ #define REENTRANT Py_True diff -r 784fea019cab Python/pystate.c --- a/Python/pystate.c Wed Nov 09 18:57:00 2016 -0500 +++ b/Python/pystate.c Fri Nov 11 00:25:33 2016 +0900 @@ -47,7 +47,7 @@ GILState implementation */ static PyInterpreterState *autoInterpreterState = NULL; -static int autoTLSkey = -1; +static intptr_t autoTLSkey = -1; #else #define HEAD_INIT() /* Nothing */ #define HEAD_LOCK() /* Nothing */ diff -r 784fea019cab Python/thread.c --- a/Python/thread.c Wed Nov 09 18:57:00 2016 -0500 +++ b/Python/thread.c Fri Nov 11 00:25:33 2016 +0900 @@ -175,13 +175,13 @@ long id; /* The key and its associated value. */ - int key; + intptr_t key; void *value; }; static struct key *keyhead = NULL; static PyThread_type_lock keymutex = NULL; -static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ +static intptr_t nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */ /* Internal helper. * If the current thread has a mapping for key, the appropriate struct key* @@ -205,7 +205,7 @@ * segfaults. Now we lock the whole routine. */ static struct key * -find_key(int set_value, int key, void *value) +find_key(int set_value, intptr_t key, void *value) { struct key *p, *prev_p; long id = PyThread_get_thread_ident(); @@ -251,7 +251,7 @@ * this family, and callers must arrange to serialize calls to this * function. No violations are detected. */ -int +intptr_t PyThread_create_key(void) { /* All parts of this function are wrong if it's called by multiple @@ -264,7 +264,7 @@ /* Forget the associations for key across *all* threads. */ void -PyThread_delete_key(int key) +PyThread_delete_key(intptr_t key) { struct key *p, **q; @@ -283,7 +283,7 @@ } int -PyThread_set_key_value(int key, void *value) +PyThread_set_key_value(intptr_t key, void *value) { struct key *p; @@ -298,7 +298,7 @@ * if the current thread doesn't have an association for key. */ void * -PyThread_get_key_value(int key) +PyThread_get_key_value(intptr_t key) { struct key *p = find_key(0, key, NULL); @@ -310,7 +310,7 @@ /* Forget the current thread's association for key, if any. */ void -PyThread_delete_key_value(int key) +PyThread_delete_key_value(intptr_t key) { long id = PyThread_get_thread_ident(); struct key *p, **q; diff -r 784fea019cab Python/thread_foobar.h --- a/Python/thread_foobar.h Wed Nov 09 18:57:00 2016 -0500 +++ b/Python/thread_foobar.h Fri Nov 11 00:25:33 2016 +0900 @@ -71,7 +71,7 @@ dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) -> %d\n", - lock, microseconds, intr_flag, success)); + lock, microseconds, intr_flag, success)); return success; } @@ -85,21 +85,21 @@ #define Py_HAVE_NATIVE_TLS #ifdef Py_HAVE_NATIVE_TLS -int +intptr_t PyThread_create_key(void) { - int result; + intptr_t result; return result; } void -PyThread_delete_key(int key) +PyThread_delete_key(intptr_t key) { } int -PyThread_set_key_value(int key, void *value) +PyThread_set_key_value(intptr_t key, void *value) { int ok; @@ -110,7 +110,7 @@ } void * -PyThread_get_key_value(int key) +PyThread_get_key_value(intptr_t key) { void *result; @@ -118,7 +118,7 @@ } void -PyThread_delete_key_value(int key) +PyThread_delete_key_value(intptr_t key) { } diff -r 784fea019cab Python/thread_nt.h --- a/Python/thread_nt.h Wed Nov 09 18:57:00 2016 -0500 +++ b/Python/thread_nt.h Fri Nov 11 00:25:33 2016 +0900 @@ -352,34 +352,34 @@ #define Py_HAVE_NATIVE_TLS #ifdef Py_HAVE_NATIVE_TLS -int +intptr_t PyThread_create_key(void) { DWORD result= TlsAlloc(); if (result == TLS_OUT_OF_INDEXES) return -1; - return (int)result; + return (intptr_t)result; } void -PyThread_delete_key(int key) +PyThread_delete_key(intptr_t key) { - TlsFree(key); + TlsFree((DWORD)key); } int -PyThread_set_key_value(int key, void *value) +PyThread_set_key_value(intptr_t key, void *value) { BOOL ok; - ok = TlsSetValue(key, value); + ok = TlsSetValue((DWORD)key, value); if (!ok) return -1; return 0; } void * -PyThread_get_key_value(int key) +PyThread_get_key_value(intptr_t key) { /* because TLS is used in the Py_END_ALLOW_THREAD macro, * it is necessary to preserve the windows error state, because @@ -388,18 +388,18 @@ * do it here. */ DWORD error = GetLastError(); - void *result = TlsGetValue(key); + void *result = TlsGetValue((DWORD)key); SetLastError(error); return result; } void -PyThread_delete_key_value(int key) +PyThread_delete_key_value(intptr_t key) { /* NULL is used as "key missing", and it is also the default * given by TlsGetValue() if nothing has been set yet. */ - TlsSetValue(key, NULL); + TlsSetValue((DWORD)key, NULL); } /* reinitialization of TLS is not necessary after fork when using diff -r 784fea019cab Python/thread_pthread.h --- a/Python/thread_pthread.h Wed Nov 09 18:57:00 2016 -0500 +++ b/Python/thread_pthread.h Fri Nov 11 00:25:33 2016 +0900 @@ -603,46 +603,46 @@ #define Py_HAVE_NATIVE_TLS -int +intptr_t PyThread_create_key(void) { pthread_key_t key; int fail = pthread_key_create(&key, NULL); if (fail) return -1; - if (key > INT_MAX) { + if ((uintptr_t)key > INTPTR_MAX) { /* Issue #22206: handle integer overflow */ pthread_key_delete(key); errno = ENOMEM; return -1; } - return (int)key; -} - -void -PyThread_delete_key(int key) -{ - pthread_key_delete(key); + return (intptr_t)key; } void -PyThread_delete_key_value(int key) +PyThread_delete_key(intptr_t key) { - pthread_setspecific(key, NULL); + pthread_key_delete((pthread_key_t)key); +} + +void +PyThread_delete_key_value(intptr_t key) +{ + pthread_setspecific((pthread_key_t)key, NULL); } int -PyThread_set_key_value(int key, void *value) +PyThread_set_key_value(intptr_t key, void *value) { int fail; - fail = pthread_setspecific(key, value); + fail = pthread_setspecific((pthread_key_t)key, value); return fail ? -1 : 0; } void * -PyThread_get_key_value(int key) +PyThread_get_key_value(intptr_t key) { - return pthread_getspecific(key); + return pthread_getspecific((pthread_key_t)key); } void