diff -r 5f8c68281d18 Doc/c-api/init.rst --- a/Doc/c-api/init.rst Wed Feb 06 10:37:19 2013 +0200 +++ b/Doc/c-api/init.rst Wed Feb 06 16:36:18 2013 +0200 @@ -745,7 +745,7 @@ the caller should assume no current thread state is available. -.. c:function:: int PyThreadState_SetAsyncExc(long id, PyObject *exc) +.. c:function:: int PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) Asynchronously raise an exception in a thread. The *id* argument is the thread id of the target thread; *exc* is the exception object to be raised. This diff -r 5f8c68281d18 Include/pystate.h --- a/Include/pystate.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Include/pystate.h Wed Feb 06 16:36:18 2013 +0200 @@ -112,7 +112,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; @@ -147,7 +147,7 @@ PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void); 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 -r 5f8c68281d18 Include/pythread.h --- a/Include/pythread.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Include/pythread.h Wed Feb 06 16:36:18 2013 +0200 @@ -18,9 +18,9 @@ } PyLockStatus; 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); diff -r 5f8c68281d18 Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/_io/bufferedio.c Wed Feb 06 16:36:18 2013 +0200 @@ -240,7 +240,7 @@ #ifdef WITH_THREAD PyThread_type_lock lock; - volatile long owner; + volatile unsigned long owner; #endif Py_ssize_t buffer_size; diff -r 5f8c68281d18 Modules/_multiprocessing/semaphore.c --- a/Modules/_multiprocessing/semaphore.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/_multiprocessing/semaphore.c Wed Feb 06 16:36:18 2013 +0200 @@ -14,7 +14,7 @@ typedef struct { PyObject_HEAD SEM_HANDLE handle; - long last_tid; + unsigned long last_tid; int count; int maxvalue; int kind; diff -r 5f8c68281d18 Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/_sqlite/connection.c Wed Feb 06 16:36:18 2013 +0200 @@ -1079,7 +1079,7 @@ 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; } diff -r 5f8c68281d18 Modules/_threadmodule.c --- a/Modules/_threadmodule.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/_threadmodule.c Wed Feb 06 16:36:18 2013 +0200 @@ -68,7 +68,7 @@ Py_BEGIN_ALLOW_THREADS r = PyThread_acquire_lock_timed(lock, microseconds, 1); Py_END_ALLOW_THREADS - } + } if (r == PY_LOCK_INTR) { /* Run signal handlers if we were interrupted. Propagate @@ -247,7 +247,7 @@ typedef struct { PyObject_HEAD PyThread_type_lock rlock_lock; - long rlock_owner; + unsigned long rlock_owner; unsigned long rlock_count; PyObject *in_weakreflist; } rlockobject; @@ -273,7 +273,7 @@ int blocking = 1; double timeout = -1; PY_TIMEOUT_T microseconds; - long tid; + unsigned long tid; PyLockStatus r = PY_LOCK_ACQUIRED; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|id:acquire", kwlist, @@ -347,7 +347,7 @@ 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, @@ -376,11 +376,11 @@ static PyObject * rlock_acquire_restore(rlockobject *self, PyObject *arg) { - long owner; + unsigned long owner; unsigned long count; int r = 1; - if (!PyArg_ParseTuple(arg, "kl:_acquire_restore", &count, &owner)) + if (!PyArg_ParseTuple(arg, "kk:_acquire_restore", &count, &owner)) return NULL; if (!PyThread_acquire_lock(self->rlock_lock, 0)) { @@ -406,7 +406,7 @@ static PyObject * rlock_release_save(rlockobject *self) { - long owner; + unsigned long owner; unsigned long count; if (self->rlock_count == 0) { @@ -420,7 +420,7 @@ 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, @@ -432,7 +432,7 @@ 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; @@ -1028,7 +1028,7 @@ { 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)) @@ -1065,7 +1065,7 @@ 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 == (unsigned long)-1) { PyErr_SetString(ThreadError, "can't start new thread"); Py_DECREF(func); Py_DECREF(args); @@ -1074,7 +1074,7 @@ PyMem_DEL(boot); return NULL; } - return PyLong_FromLong(ident); + return PyLong_FromUnsignedLong(ident); } PyDoc_STRVAR(start_new_doc, @@ -1134,13 +1134,13 @@ static PyObject * thread_get_ident(PyObject *self) { - long ident; + unsigned long ident; ident = PyThread_get_thread_ident(); if (ident == -1) { PyErr_SetString(ThreadError, "no current thread ident"); return NULL; } - return PyLong_FromLong(ident); + return PyLong_FromUnsignedLong(ident); } PyDoc_STRVAR(get_ident_doc, diff -r 5f8c68281d18 Modules/faulthandler.c --- a/Modules/faulthandler.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/faulthandler.c Wed Feb 06 16:36:18 2013 +0200 @@ -567,7 +567,7 @@ /* 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) == (unsigned long)-1) { PyThread_release_lock(thread.running); Py_CLEAR(thread.file); free(header); diff -r 5f8c68281d18 Modules/signalmodule.c --- a/Modules/signalmodule.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Modules/signalmodule.c Wed Feb 06 16:36:18 2013 +0200 @@ -79,7 +79,7 @@ #ifdef WITH_THREAD #include /* For pid_t */ #include "pythread.h" -static long main_thread; +static unsigned long main_thread; static pid_t main_pid; #endif @@ -818,11 +818,11 @@ static PyObject * signal_pthread_kill(PyObject *self, PyObject *args) { - long tid; + unsigned long tid; int signum; int err; - if (!PyArg_ParseTuple(args, "li:pthread_kill", &tid, &signum)) + if (!PyArg_ParseTuple(args, "ki:pthread_kill", &tid, &signum)) return NULL; err = pthread_kill((pthread_t)tid, signum); diff -r 5f8c68281d18 Python/ceval.c --- a/Python/ceval.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/ceval.c Wed Feb 06 16:36:18 2013 +0200 @@ -280,7 +280,7 @@ #include "pythread.h" static PyThread_type_lock pending_lock = 0; /* for pending calls */ -static long main_thread = 0; +static unsigned long main_thread = 0; /* This single variable consolidates all requests to break out of the fast path in the eval loop. */ static _Py_atomic_int eval_breaker = {0}; diff -r 5f8c68281d18 Python/import.c --- a/Python/import.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/import.c Wed Feb 06 16:36:18 2013 +0200 @@ -145,13 +145,13 @@ #include "pythread.h" static PyThread_type_lock import_lock = 0; -static long import_lock_thread = -1; +static unsigned long import_lock_thread = (unsigned long)-1; static int import_lock_level = 0; void _PyImport_AcquireLock(void) { - long me = PyThread_get_thread_ident(); + unsigned long me = PyThread_get_thread_ident(); if (me == -1) return; /* Too bad */ if (import_lock == NULL) { @@ -163,7 +163,8 @@ import_lock_level++; return; } - if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0)) + if (import_lock_thread != (unsigned long)-1 || + !PyThread_acquire_lock(import_lock, 0)) { PyThreadState *tstate = PyEval_SaveThread(); PyThread_acquire_lock(import_lock, 1); @@ -177,7 +178,7 @@ int _PyImport_ReleaseLock(void) { - long me = PyThread_get_thread_ident(); + unsigned long me = PyThread_get_thread_ident(); if (me == -1 || import_lock == NULL) return 0; /* Too bad */ if (import_lock_thread != me) @@ -185,7 +186,7 @@ import_lock_level--; assert(import_lock_level >= 0); if (import_lock_level == 0) { - import_lock_thread = -1; + import_lock_thread = (unsigned long)-1; PyThread_release_lock(import_lock); } return 1; @@ -203,7 +204,7 @@ import_lock = PyThread_allocate_lock(); if (import_lock_level > 1) { /* Forked as a side effect of import */ - long me = PyThread_get_thread_ident(); + unsigned long me = PyThread_get_thread_ident(); /* The following could fail if the lock is already held, but forking as a side-effect of an import is a) rare, b) nuts, and c) difficult to do thanks to the lock only being held when doing individual module @@ -212,7 +213,7 @@ import_lock_thread = me; import_lock_level--; } else { - import_lock_thread = -1; + import_lock_thread = (unsigned long)-1; import_lock_level = 0; } } @@ -223,7 +224,7 @@ imp_lock_held(PyObject *self, PyObject *noargs) { #ifdef WITH_THREAD - return PyBool_FromLong(import_lock_thread != -1); + return PyBool_FromLong(import_lock_thread != (unsigned long)-1); #else return PyBool_FromLong(0); #endif diff -r 5f8c68281d18 Python/pystate.c --- a/Python/pystate.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/pystate.c Wed Feb 06 16:36:18 2013 +0200 @@ -485,7 +485,7 @@ existing async exception. This raises no exceptions. */ int -PyThreadState_SetAsyncExc(long id, PyObject *exc) { +PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) { PyThreadState *tstate = PyThreadState_GET(); PyInterpreterState *interp = tstate->interp; PyThreadState *p; @@ -574,7 +574,7 @@ struct _frame *frame = t->frame; if (frame == NULL) continue; - id = PyLong_FromLong(t->thread_id); + id = PyLong_FromUnsignedLong(t->thread_id); if (id == NULL) goto Fail; stat = PyDict_SetItem(result, id, (PyObject *)frame); diff -r 5f8c68281d18 Python/thread.c --- a/Python/thread.c Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/thread.c Wed Feb 06 16:36:18 2013 +0200 @@ -172,7 +172,7 @@ struct key *next; /* The thread id, according to PyThread_get_thread_ident(). */ - long id; + unsigned long id; /* The key and its associated value. */ int key; @@ -208,7 +208,7 @@ find_key(int key, void *value) { struct key *p, *prev_p; - long id = PyThread_get_thread_ident(); + unsigned long id = PyThread_get_thread_ident(); if (!keymutex) return NULL; @@ -316,7 +316,7 @@ void PyThread_delete_key_value(int key) { - long id = PyThread_get_thread_ident(); + unsigned long id = PyThread_get_thread_ident(); struct key *p, **q; PyThread_acquire_lock(keymutex, 1); @@ -342,7 +342,7 @@ void PyThread_ReInitTLS(void) { - long id = PyThread_get_thread_ident(); + unsigned long id = PyThread_get_thread_ident(); struct key *p, **q; if (!keymutex) diff -r 5f8c68281d18 Python/thread_foobar.h --- a/Python/thread_foobar.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/thread_foobar.h Wed Feb 06 16:36:18 2013 +0200 @@ -10,7 +10,7 @@ /* * Thread support. */ -long +unsigned long PyThread_start_new_thread(void (*func)(void *), void *arg) { int success = 0; /* init not needed when SOLARIS_THREADS and */ @@ -19,10 +19,10 @@ dprintf(("PyThread_start_new_thread called\n")); if (!initialized) PyThread_init_thread(); - return success < 0 ? -1 : 0; + return success < 0 ? (unsigned long)-1 : 0; } -long +unsigned long PyThread_get_thread_ident(void) { if (!initialized) diff -r 5f8c68281d18 Python/thread_nt.h --- a/Python/thread_nt.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/thread_nt.h Wed Feb 06 16:36:18 2013 +0200 @@ -107,7 +107,7 @@ result = PyCOND_SIGNAL(&mutex->cv); result &= PyMUTEX_UNLOCK(&mutex->cs); return result; -} +} #else /* if ! _PY_USE_CV_LOCKS */ @@ -140,7 +140,7 @@ } #endif /* _PY_USE_CV_LOCKS */ -long PyThread_get_thread_ident(void); +unsigned long PyThread_get_thread_ident(void); /* * Initialization of the C package, should not be needed. @@ -176,21 +176,21 @@ return 0; } -long +unsigned long PyThread_start_new_thread(void (*func)(void *), void *arg) { HANDLE hThread; unsigned threadID; callobj *obj; - dprintf(("%ld: PyThread_start_new_thread called\n", + dprintf(("%lu: PyThread_start_new_thread called\n", PyThread_get_thread_ident())); if (!initialized) PyThread_init_thread(); obj = (callobj*)HeapAlloc(GetProcessHeap(), 0, sizeof(*obj)); if (!obj) - return -1; + return (unsigned long)-1; obj->func = func; obj->arg = arg; #if defined(MS_WINCE) @@ -209,32 +209,32 @@ /* Save error in variable, to prevent PyThread_get_thread_ident from clobbering it. */ unsigned e = GetLastError(); - dprintf(("%ld: PyThread_start_new_thread failed, win32 error code %u\n", + dprintf(("%lu: PyThread_start_new_thread failed, win32 error code %u\n", PyThread_get_thread_ident(), e)); #else /* I've seen errno == EAGAIN here, which means "there are * too many threads". */ int e = errno; - dprintf(("%ld: PyThread_start_new_thread failed, errno %d\n", + dprintf(("%lu: PyThread_start_new_thread failed, errno %d\n", PyThread_get_thread_ident(), e)); #endif threadID = (unsigned)-1; HeapFree(GetProcessHeap(), 0, obj); } else { - dprintf(("%ld: PyThread_start_new_thread succeeded: %p\n", + dprintf(("%lu: PyThread_start_new_thread succeeded: %p\n", PyThread_get_thread_ident(), (void*)hThread)); CloseHandle(hThread); } - return (long) threadID; + return threadID; } /* * Return the thread Id instead of an handle. The Id is said to uniquely identify the * thread in the system */ -long +unsigned long PyThread_get_thread_ident(void) { if (!initialized) @@ -246,7 +246,7 @@ void PyThread_exit_thread(void) { - dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); + dprintf(("%lu: PyThread_exit_thread called\n", PyThread_get_thread_ident())); if (!initialized) exit(0); #if defined(MS_WINCE) @@ -272,7 +272,7 @@ aLock = AllocNonRecursiveMutex() ; - dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); + dprintf(("%lu: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); return (PyThread_type_lock) aLock; } @@ -280,7 +280,7 @@ void PyThread_free_lock(PyThread_type_lock aLock) { - dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); + dprintf(("%lu: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); FreeNonRecursiveMutex(aLock) ; } @@ -311,7 +311,7 @@ else milliseconds = INFINITE; - dprintf(("%ld: PyThread_acquire_lock_timed(%p, %lld) called\n", + dprintf(("%lu: PyThread_acquire_lock_timed(%p, %lld) called\n", PyThread_get_thread_ident(), aLock, microseconds)); if (aLock && EnterNonRecursiveMutex((PNRMUTEX)aLock, @@ -322,7 +322,7 @@ success = PY_LOCK_FAILURE; } - dprintf(("%ld: PyThread_acquire_lock(%p, %lld) -> %d\n", + dprintf(("%lu: PyThread_acquire_lock(%p, %lld) -> %d\n", PyThread_get_thread_ident(), aLock, microseconds, success)); return success; @@ -336,10 +336,10 @@ void PyThread_release_lock(PyThread_type_lock aLock) { - dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); + dprintf(("%lu: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); if (!(aLock && LeaveNonRecursiveMutex((PNRMUTEX) aLock))) - dprintf(("%ld: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError())); + dprintf(("%lu: Could not PyThread_release_lock(%p) error: %ld\n", PyThread_get_thread_ident(), aLock, GetLastError())); } /* minimum/maximum thread stack sizes supported */ diff -r 5f8c68281d18 Python/thread_pth.h --- a/Python/thread_pth.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/thread_pth.h Wed Feb 06 16:36:18 2013 +0200 @@ -49,7 +49,7 @@ */ -long PyThread_start_new_thread(void (*func)(void *), void *arg) +unsigned long PyThread_start_new_thread(void (*func)(void *), void *arg) { pth_t th; dprintf(("PyThread_start_new_thread called\n")); @@ -61,16 +61,16 @@ (void *)arg ); - return th; + return (unsigned long) th; } -long PyThread_get_thread_ident(void) +unsigned long PyThread_get_thread_ident(void) { volatile pth_t threadid; if (!initialized) PyThread_init_thread(); threadid = pth_self(); - return (long) threadid; + return (unsigned long) threadid; } void PyThread_exit_thread(void) diff -r 5f8c68281d18 Python/thread_pthread.h --- a/Python/thread_pthread.h Wed Feb 06 10:37:19 2013 +0200 +++ b/Python/thread_pthread.h Wed Feb 06 16:36:18 2013 +0200 @@ -181,7 +181,7 @@ */ -long +unsigned long PyThread_start_new_thread(void (*func)(void *), void *arg) { pthread_t th; @@ -199,7 +199,7 @@ #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) if (pthread_attr_init(&attrs) != 0) - return -1; + return (unsigned long)-1; #endif #if defined(THREAD_STACK_SIZE) tss = (_pythread_stacksize != 0) ? _pythread_stacksize @@ -207,7 +207,7 @@ if (tss != 0) { if (pthread_attr_setstacksize(&attrs, tss) != 0) { pthread_attr_destroy(&attrs); - return -1; + return (unsigned long)-1; } } #endif @@ -229,31 +229,31 @@ pthread_attr_destroy(&attrs); #endif if (status != 0) - return -1; + return (unsigned long)-1; pthread_detach(th); #if SIZEOF_PTHREAD_T <= SIZEOF_LONG - return (long) th; + return (unsigned long) th; #else - return (long) *(long *) &th; + return (unsigned long) *(unsigned long *) &th; #endif } /* XXX This implementation is considered (to quote Tim Peters) "inherently hosed" because: - It does not guarantee the promise that a non-zero integer is returned. - - The cast to long is inherently unsafe. + - The cast to unsigned long is inherently unsafe. - It is not clear that the 'volatile' (for AIX?) are any longer necessary. */ -long +unsigned long PyThread_get_thread_ident(void) { volatile pthread_t threadid; if (!initialized) PyThread_init_thread(); threadid = pthread_self(); - return (long) threadid; + return (unsigned long) threadid; } void