scx/c/xlib/error.c

65 lines
2.0 KiB
C

#include "xlib.h"
#include <stdio.h>
s48_value internal_x_error_handler_binding = S48_FALSE;
s48_value internal_x_fatal_error_handler_binding = S48_FALSE;
/* Default error handlers of the Xlib */
extern int _XDefaultIOError();
extern int _XDefaultError();
static X_Fatal_Error (Display* d) {
//Reset_IO (0); //??
// call the scheme-func internal-x-fatal-error-handler, which does the rest.
s48_call_scheme(S48_SHARED_BINDING_REF(internal_x_fatal_error_handler_binding),
1, SCX_ENTER_DISPLAY(d));
// In case the scheme error handler does not exit (or none exists):
_XDefaultIOError (d);
// And if event the default handler does not exit:
exit (1);
/*NOTREACHED*/
}
static X_Error(Display* d, XErrorEvent* ep) {
s48_value args = s48_make_vector(7, S48_FALSE);
s48_value a = S48_FALSE, r = S48_FALSE;
int max_s = 1024;
char s[max_s];
S48_DECLARE_GC_PROTECT(2);
//Reset_IO (0); //??
S48_GC_PROTECT_2(args, a);
S48_VECTOR_SET(args, 0, SCX_ENTER_DISPLAY(d));
S48_VECTOR_SET(args, 1, s48_enter_integer(ep->serial));
S48_VECTOR_SET(args, 2, s48_enter_integer(ep->error_code));
S48_VECTOR_SET(args, 3, s48_enter_integer(ep->request_code));
S48_VECTOR_SET(args, 4, s48_enter_integer(ep->minor_code));
S48_VECTOR_SET(args, 5, s48_enter_integer((unsigned long)ep->resourceid));
XGetErrorText(d, ep->error_code, s, max_s);
S48_VECTOR_SET(args, 6, s48_enter_string(s));
r = s48_call_scheme(S48_SHARED_BINDING_REF(internal_x_error_handler_binding),
1, args);
S48_GC_UNPROTECT();
if S48_FALSE_P( r )
_XDefaultError (d, ep);
}
void scx_init_error() {
S48_GC_PROTECT_GLOBAL(internal_x_error_handler_binding);
S48_GC_PROTECT_GLOBAL(internal_x_fatal_error_handler_binding);
internal_x_error_handler_binding =
s48_get_imported_binding("internal-x-error-handler");
internal_x_fatal_error_handler_binding =
s48_get_imported_binding("internal-x-fatal-error-handler");
(void)XSetIOErrorHandler (X_Fatal_Error);
(void)XSetErrorHandler (X_Error);
}