gh-116012: Preserve GetLastError() across calls to TlsGetValue on Windows (GH-116014)

This commit is contained in:
Steve Dower 2024-02-28 13:58:25 +00:00 committed by GitHub
parent 647053fed1
commit 9578288a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 10 deletions

View File

@ -0,0 +1 @@
Ensure the value of ``GetLastError()`` is preserved across GIL operations.

View File

@ -2528,16 +2528,7 @@ PyGILState_Check(void)
return 0;
}
#ifdef MS_WINDOWS
int err = GetLastError();
#endif
PyThreadState *tcur = gilstate_tss_get(runtime);
#ifdef MS_WINDOWS
SetLastError(err);
#endif
return (tstate == tcur);
}

View File

@ -513,5 +513,10 @@ void *
PyThread_tss_get(Py_tss_t *key)
{
assert(key != NULL);
return TlsGetValue(key->_key);
int err = GetLastError();
void *r = TlsGetValue(key->_key);
if (r || !GetLastError()) {
SetLastError(err);
}
return r;
}