summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c4
-rw-r--r--Python/ceval.c1
-rw-r--r--Python/thread_nt.h63
3 files changed, 9 insertions, 59 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 6f62b6c..82eaeff 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -248,6 +248,8 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
goto error;
asdl_seq_SET(stmts, 0, Pass(n->n_lineno, n->n_col_offset,
arena));
+ if (!asdl_seq_GET(stmts, 0))
+ goto error;
return Interactive(stmts, arena);
}
else {
@@ -278,6 +280,8 @@ PyAST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
return Interactive(stmts, arena);
}
default:
+ PyErr_Format(PyExc_SystemError,
+ "invalid node %d for PyAST_FromNode", TYPE(n));
goto error;
}
error:
diff --git a/Python/ceval.c b/Python/ceval.c
index 3bb2178..df3fa79 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -487,7 +487,6 @@ volatile int _Py_Ticker = 100;
PyObject *
PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
{
- /* XXX raise SystemError if globals is NULL */
return PyEval_EvalCodeEx(co,
globals, locals,
(PyObject **)NULL, 0,
diff --git a/Python/thread_nt.h b/Python/thread_nt.h
index 27fca72..9445529 100644
--- a/Python/thread_nt.h
+++ b/Python/thread_nt.h
@@ -15,72 +15,16 @@ typedef struct NRMUTEX {
HANDLE hevent ;
} NRMUTEX, *PNRMUTEX ;
-typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ;
-
-/* Sorry mate, but we haven't got InterlockedCompareExchange in Win95! */
-static PVOID WINAPI
-interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand)
-{
- static LONG spinlock = 0 ;
- PVOID result ;
- DWORD dwSleep = 0;
-
- /* Acqire spinlock (yielding control to other threads if cant aquire for the moment) */
- while(InterlockedExchange(&spinlock, 1))
- {
- // Using Sleep(0) can cause a priority inversion.
- // Sleep(0) only yields the processor if there's
- // another thread of the same priority that's
- // ready to run. If a high-priority thread is
- // trying to acquire the lock, which is held by
- // a low-priority thread, then the low-priority
- // thread may never get scheduled and hence never
- // free the lock. NT attempts to avoid priority
- // inversions by temporarily boosting the priority
- // of low-priority runnable threads, but the problem
- // can still occur if there's a medium-priority
- // thread that's always runnable. If Sleep(1) is used,
- // then the thread unconditionally yields the CPU. We
- // only do this for the second and subsequent even
- // iterations, since a millisecond is a long time to wait
- // if the thread can be scheduled in again sooner
- // (~100,000 instructions).
- // Avoid priority inversion: 0, 1, 0, 1,...
- Sleep(dwSleep);
- dwSleep = !dwSleep;
- }
- result = *dest ;
- if (result == comperand)
- *dest = exc ;
- /* Release spinlock */
- spinlock = 0 ;
- return result ;
-} ;
-
-static interlocked_cmp_xchg_t *ixchg;
BOOL
InitializeNonRecursiveMutex(PNRMUTEX mutex)
{
- if (!ixchg)
- {
- /* Sorely, Win95 has no InterlockedCompareExchange API (Win98 has), so we have to use emulation */
- HANDLE kernel = GetModuleHandle("kernel32.dll") ;
- if (!kernel || (ixchg = (interlocked_cmp_xchg_t *)GetProcAddress(kernel, "InterlockedCompareExchange")) == NULL)
- ixchg = interlocked_cmp_xchg ;
- }
-
mutex->owned = -1 ; /* No threads have entered NonRecursiveMutex */
mutex->thread_id = 0 ;
mutex->hevent = CreateEvent(NULL, FALSE, FALSE, NULL) ;
return mutex->hevent != NULL ; /* TRUE if the mutex is created */
}
-#ifdef InterlockedCompareExchange
-#undef InterlockedCompareExchange
-#endif
-#define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand)))
-
VOID
DeleteNonRecursiveMutex(PNRMUTEX mutex)
{
@@ -98,7 +42,7 @@ EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait)
/* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */
if (!wait)
{
- if (InterlockedCompareExchange((PVOID *)&mutex->owned, (PVOID)0, (PVOID)-1) != (PVOID)-1)
+ if (InterlockedCompareExchange(&mutex->owned, 0, -1) != -1)
return WAIT_TIMEOUT ;
ret = WAIT_OBJECT_0 ;
}
@@ -196,7 +140,10 @@ PyThread_start_new_thread(void (*func)(void *), void *arg)
if (obj.done == NULL)
return -1;
- rv = _beginthread(bootstrap, _pythread_stacksize, &obj);
+ rv = _beginthread(bootstrap,
+ Py_SAFE_DOWNCAST(_pythread_stacksize,
+ Py_ssize_t, int),
+ &obj);
if (rv == (Py_uintptr_t)-1) {
/* I've seen errno == EAGAIN here, which means "there are
* too many threads".