diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-11-05 16:06:08 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-11-06 12:51:52 +1000 |
commit | 23d40ceea9c903b676b21bd5793fa1bcf94f142b (patch) | |
tree | ad990b5e7fd8e1487980650644a152ab7c7714e0 | |
parent | d2d3999a229e9f63804351c483f920cb405bb32a (diff) |
common/helper: fix error trap for stack-local XError
The error Xlib passes to the error handler is stack-local. Saving its
address is entertaining, but largely useless.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | tests/common/helpers.cpp | 14 | ||||
-rw-r--r-- | tests/common/helpers.h | 2 | ||||
-rw-r--r-- | tests/server/barriers-validity.cpp | 8 |
3 files changed, 13 insertions, 11 deletions
diff --git a/tests/common/helpers.cpp b/tests/common/helpers.cpp index aa6079c..2484e80 100644 --- a/tests/common/helpers.cpp +++ b/tests/common/helpers.cpp @@ -132,9 +132,10 @@ void DeviceSetEnabled(Display *dpy, int deviceid, bool enabled) /* Basic error trapping */ static struct { bool is_trapping; - XErrorEvent *error; + bool have_error; + XErrorEvent error; XErrorHandler prev_error_handler; -} trap_state = { false, NULL, NULL }; +} trap_state; static int ErrorHandler(Display *dpy, @@ -143,7 +144,8 @@ ErrorHandler(Display *dpy, if (!trap_state.is_trapping) ADD_FAILURE() << "Error trap received error while not trapping. WTF?"; - trap_state.error = error; + trap_state.have_error = true; + trap_state.error = *error; return 0; } @@ -156,7 +158,7 @@ void SetErrorTrap(Display *dpy) { trap_state.is_trapping = true; } -XErrorEvent * ReleaseErrorTrap(Display *dpy) { +const XErrorEvent* ReleaseErrorTrap(Display *dpy) { if (!trap_state.is_trapping) ADD_FAILURE() << "ReleaseErrorTrap() called while not trapping."; @@ -164,9 +166,9 @@ XErrorEvent * ReleaseErrorTrap(Display *dpy) { XSetErrorHandler(trap_state.prev_error_handler); trap_state.prev_error_handler = NULL; - XErrorEvent *error = trap_state.error; - trap_state.error = NULL; + const XErrorEvent *error = trap_state.have_error ? &trap_state.error : NULL; trap_state.is_trapping = false; + trap_state.have_error = false; return error; } diff --git a/tests/common/helpers.h b/tests/common/helpers.h index 43f7c76..be2f9e7 100644 --- a/tests/common/helpers.h +++ b/tests/common/helpers.h @@ -92,7 +92,7 @@ void SetErrorTrap(Display *dpy); * * @return An XErrorEvent that was trapped. */ -XErrorEvent * ReleaseErrorTrap(Display *dpy); +const XErrorEvent* ReleaseErrorTrap(Display *dpy); #define ASSERT_ERROR(err, code) \ ASSERT_TRUE(err != NULL) << ("Expected " #code); \ diff --git a/tests/server/barriers-validity.cpp b/tests/server/barriers-validity.cpp index 8aa9343..61d1cec 100644 --- a/tests/server/barriers-validity.cpp +++ b/tests/server/barriers-validity.cpp @@ -43,7 +43,7 @@ TEST_F(BarrierSimpleTest, DestroyInvalidBarrier) SetErrorTrap(Display()); XFixesDestroyPointerBarrier(Display(), -1); - XErrorEvent *error = ReleaseErrorTrap(Display()); + const XErrorEvent *error = ReleaseErrorTrap(Display()); ASSERT_ERROR(error, xfixes_error_base + BadBarrier); } @@ -83,7 +83,7 @@ TEST_P(BarrierZeroLength, InvalidZeroLengthBarrier) SetErrorTrap(dpy); XFixesCreatePointerBarrier(dpy, root, 20, 20, 20, 20, directions, 0, NULL); - XErrorEvent *error = ReleaseErrorTrap(dpy); + const XErrorEvent *error = ReleaseErrorTrap(dpy); ASSERT_ERROR(error, BadValue); } @@ -104,7 +104,7 @@ TEST_P(BarrierNonZeroArea, InvalidNonZeroAreaBarrier) SetErrorTrap(dpy); XFixesCreatePointerBarrier(dpy, root, 20, 20, 40, 40, directions, 0, NULL); - XErrorEvent *error = ReleaseErrorTrap(dpy); + const XErrorEvent *error = ReleaseErrorTrap(dpy); ASSERT_ERROR(error, BadValue); } INSTANTIATE_TEST_CASE_P(, BarrierNonZeroArea, VALID_DIRECTIONS); @@ -143,7 +143,7 @@ TEST_P(BarrierConflictingDirections, InvalidConflictingDirectionsBarrier) SetErrorTrap(dpy); XFixesCreatePointerBarrier(dpy, root, x1, y1, x2, y2, directions, 0, NULL); - XErrorEvent *error = ReleaseErrorTrap(dpy); + const XErrorEvent *error = ReleaseErrorTrap(dpy); /* Nonsensical directions are ignored -- they don't * raise a BadValue. Unfortunately, there's no way |