Lionel Ulmer lionel.ulmer@free.fr writes:
When discussing with Ove yesterday on #WineHQ about the handling of X errors, he told me about an idea of his : using exceptions to handle X errors.
The main problem with that is that I don't think you can jump out of Xlib without corrupting its state. Also you'd need to properly unlock the tsx11 lock in case of exception, which will probably require an finally handler around each X call.
My idea was to have the following two functions:
void X11DRV_expect_error( unsigned char request, unsigned char error, XID id ); int X11DRV_check_error(void);
You'd call X11DRV_expect_error before doing an X call that can fail; then if an X error happens that matches what you expect, the X error handler will simply set a flag and ignore the error (if it doesn't match you get the standard error handling). Then after the call you use X11DRV_check_error to see if your error happened or not. Would this work for what you need?
The main problem with that is that I don't think you can jump out of Xlib without corrupting its state. Also you'd need to properly unlock the tsx11 lock in case of exception, which will probably require an finally handler around each X call.
Well, seems you are right about X not liking the 'longjmp' stuff (I asked on the XPert mailing list to confirm :-) ).
My idea was to have the following two functions:
void X11DRV_expect_error( unsigned char request, unsigned char error, XID id ); int X11DRV_check_error(void);
You'd call X11DRV_expect_error before doing an X call that can fail; then if an X error happens that matches what you expect, the X error handler will simply set a flag and ignore the error (if it doesn't match you get the standard error handling). Then after the call you use X11DRV_check_error to see if your error happened or not. Would this work for what you need?
Yeah, this would work (and is about what I already did in the XShm and WGL code to detect X errors, except that I just set a global variable in case of error :-) ).
The only problems I could see with this approach is that :
- it cannot 'expect' more than one kind of error at the same time
- I am not sure that the parameters thing are really a good idea. Are we sure that the error code are the same on all X servers ? Are they standardized ?
Lionel