]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 4906: Preserve windows error state across PyThread_get_key_value
authorKristján Valur Jónsson <kristjan@ccpgames.com>
Sat, 10 Jan 2009 12:14:31 +0000 (12:14 +0000)
committerKristján Valur Jónsson <kristjan@ccpgames.com>
Sat, 10 Jan 2009 12:14:31 +0000 (12:14 +0000)
Python/thread_nt.h

index 5ec15f6a931957348060ca0e6ef1183ecc4c3e6f..e0457a2486d4ff1121fe66f5a1ac723d829c340b 100644 (file)
@@ -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