]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116012: Preserve GetLastError() across calls to TlsGetValue on Windows (GH-116014)
authorSteve Dower <steve.dower@python.org>
Wed, 28 Feb 2024 13:58:25 +0000 (13:58 +0000)
committerGitHub <noreply@github.com>
Wed, 28 Feb 2024 13:58:25 +0000 (13:58 +0000)
Misc/NEWS.d/next/Windows/2024-02-27-23-21-55.gh-issue-116012.B9_IwM.rst [new file with mode: 0644]
Python/pystate.c
Python/thread_nt.h

diff --git a/Misc/NEWS.d/next/Windows/2024-02-27-23-21-55.gh-issue-116012.B9_IwM.rst b/Misc/NEWS.d/next/Windows/2024-02-27-23-21-55.gh-issue-116012.B9_IwM.rst
new file mode 100644 (file)
index 0000000..a55e5b1
--- /dev/null
@@ -0,0 +1 @@
+Ensure the value of ``GetLastError()`` is preserved across GIL operations.
index a80c1b7fb9c8665bfb57e87c855a8b79f3451ad4..a370fff857af8529e92ed2589b897bc786e76659 100644 (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);
 }
 
index 7922b2d7e848454fdcf172cd8d5911a23d0c9af2..9dca833ff203ca99a28d92b9997f65ed4c1b972c 100644 (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;
 }