From abb70e9c9f79dd26e71368f9aab77ad72d0706bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 10 Jan 2009 12:14:31 +0000 Subject: [PATCH] Issue 4906: Preserve windows error state across PyThread_get_key_value --- Python/thread_nt.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Python/thread_nt.h b/Python/thread_nt.h index 5ec15f6a931..e0457a2486d 100644 --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -315,7 +315,16 @@ PyThread_set_key_value(int key, void *value) void * PyThread_get_key_value(int key) { - return TlsGetValue(key); + /* because TLS is used in the Py_END_ALLOW_THREAD macro, + * it is necessary to preserve the windows error state, because + * it is assumed to be preserved across the call to the macro. + * Ideally, the macro should be fixed, but it is simpler to + * do it here. + */ + DWORD error = GetLastError(); + void *result = TlsGetValue(key); + SetLastError(error); + return result; } void