Skip to content

Commit 40b4765

Browse files
author
kristjan.jonsson
committed
Issue 4906: Preserve windows error state across PyThread_get_key_value
git-svn-id: http://svn.python.org/projects/python/trunk@68476 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 7640bf5 commit 40b4765

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Python/thread_nt.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,16 @@ PyThread_set_key_value(int key, void *value)
315315
void *
316316
PyThread_get_key_value(int key)
317317
{
318-
return TlsGetValue(key);
318+
/* because TLS is used in the Py_END_ALLOW_THREAD macro,
319+
* it is necessary to preserve the windows error state, because
320+
* it is assumed to be preserved across the call to the macro.
321+
* Ideally, the macro should be fixed, but it is simpler to
322+
* do it here.
323+
*/
324+
DWORD error = GetLastError();
325+
void *result = TlsGetValue(key);
326+
SetLastError(error);
327+
return result;
319328
}
320329

321330
void

0 commit comments

Comments
 (0)