[PATCH v2] winex11.drv: Preserve last error in x11drv_thread_data().

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v2] winex11.drv: Preserve last error in x11drv_thread_data().

Rafał Harabień
Issue was caused by TlsGetValue always resetting error to ERROR_SUCCESS.
This change fixes GetCursorPos resetting last-error randomly.

Signed-off-by: Rafał Harabień <[hidden email]>
---
 dlls/user32/tests/input.c | 10 +++++++++-
 dlls/winex11.drv/x11drv.h |  7 ++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c
index 8f2576d..0b72835 100644
--- a/dlls/user32/tests/input.c
+++ b/dlls/user32/tests/input.c
@@ -1928,8 +1928,16 @@ static void test_Input_mouse(void)
     DWORD thread_id;
     POINT pt, pt_org;
     MSG msg;
+    BOOL ret;
 
-    GetCursorPos(&pt_org);
+    SetLastError(0xdeadbeef);
+    ret = GetCursorPos(NULL);
+    ok(!ret, "GetCursorPos succeed\n");
+    ok(GetLastError() == 0xdeadbeef || GetLastError() == ERROR_NOACCESS, "error %lu\n", GetLastError());
+
+    ret = GetCursorPos(&pt_org);
+    ok(ret, "GetCursorPos failed\n");
+    ok(GetLastError() == 0xdeadbeef, "error %lu\n", GetLastError());
 
     button_win = CreateWindowA("button", "button", WS_VISIBLE | WS_POPUP,
             100, 100, 100, 100, 0, NULL, NULL, NULL);
diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h
index 721c082..6786a08 100644
--- a/dlls/winex11.drv/x11drv.h
+++ b/dlls/winex11.drv/x11drv.h
@@ -345,7 +345,12 @@ extern DWORD thread_data_tls_index DECLSPEC_HIDDEN;
 
 static inline struct x11drv_thread_data *x11drv_thread_data(void)
 {
-    return TlsGetValue( thread_data_tls_index );
+    /* TlsGetValue always resets last error */
+    unsigned long err = GetLastError();
+    struct x11drv_thread_data *data = TlsGetValue( thread_data_tls_index );
+    if (err != ERROR_SUCCESS && GetLastError() == ERROR_SUCCESS)
+        SetLastError(err);
+    return data;
 }
 
 /* retrieve the thread display, or NULL if not created yet */
--
2.7.4



Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] winex11.drv: Preserve last error in x11drv_thread_data().

Marvin-2
Hi,

While running your changed tests on Windows, I think I found new failures.
Being a bot and all I'm not very good at pattern recognition, so I might be
wrong, but could you please double-check?
Full results can be found at
https://testbot.winehq.org/JobDetails.pl?Key=34138

Your paranoid android.


=== wvistau64 (32 bit input) ===
input.c:1940: Test failed: error 998

=== w2008s64 (32 bit input) ===
input.c:1940: Test failed: error 998

=== w7u (32 bit input) ===
input.c:1940: Test failed: error 998

=== w7pro64 (32 bit input) ===
input.c:1940: Test failed: error 998

=== w8 (32 bit input) ===
input.c:1940: Test failed: error 998

=== w864 (32 bit input) ===
input.c:1940: Test failed: error 998

=== w1064 (32 bit input) ===
input.c:1940: Test failed: error 998

=== wvistau64 (64 bit input) ===
input.c:1940: Test failed: error 998

=== w2008s64 (64 bit input) ===
input.c:1940: Test failed: error 998

=== w7pro64 (64 bit input) ===
input.c:1940: Test failed: error 998

=== w864 (64 bit input) ===
input.c:1940: Test failed: error 998

=== w1064 (64 bit input) ===
input.c:1940: Test failed: error 998