xutil: do not return pointer, init struct instead

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-09-18 16:58:10 +02:00
parent 4193e81fa8
commit 49abc66089
3 changed files with 18 additions and 21 deletions

View File

@ -249,21 +249,19 @@ xerror(void *data __attribute__ ((unused)),
xcb_connection_t *c __attribute__ ((unused)), xcb_connection_t *c __attribute__ ((unused)),
xcb_generic_error_t *e) xcb_generic_error_t *e)
{ {
xutil_error_t *err = xutil_error_get(e); xutil_error_t err;
if(!err)
if(!xutil_error_init(e, &err))
return 0; return 0;
/* ignore this */
if(e->error_code == XUTIL_BAD_WINDOW if(e->error_code == XUTIL_BAD_WINDOW
|| (e->error_code == XUTIL_BAD_MATCH && err->request_code == XCB_SET_INPUT_FOCUS) || (e->error_code == XUTIL_BAD_MATCH && err.request_code == XCB_SET_INPUT_FOCUS)
|| (e->error_code == XUTIL_BAD_VALUE && err->request_code == XCB_KILL_CLIENT) || (e->error_code == XUTIL_BAD_VALUE && err.request_code == XCB_KILL_CLIENT)
|| (err->request_code == XCB_CONFIGURE_WINDOW && e->error_code == XUTIL_BAD_MATCH)) || (err.request_code == XCB_CONFIGURE_WINDOW && e->error_code == XUTIL_BAD_MATCH))
{ goto bailout;
xutil_error_delete(err);
return 0;
}
warn("fatal error: request=%s, error=%s", err->request_label, err->error_label); warn("X error: request=%s, error=%s", err.request_label, err.error_label);
xutil_error_delete(err);
/* /*
* Xlib code was using default X error handler, namely * Xlib code was using default X error handler, namely
@ -274,8 +272,10 @@ xerror(void *data __attribute__ ((unused)),
* \todo display more informations about the error (like the Xlib default error handler) * \todo display more informations about the error (like the Xlib default error handler)
*/ */
if(e->error_code == XUTIL_BAD_IMPLEMENTATION) if(e->error_code == XUTIL_BAD_IMPLEMENTATION)
exit(EXIT_FAILURE); fatal("X error: request=%s, error=%s", err.request_label, err.error_label);
bailout:
xutil_error_wipe(&err);
return 0; return 0;
} }

View File

@ -299,14 +299,12 @@ xutil_label_request[] =
"NoOperation", "NoOperation",
}; };
xutil_error_t * bool
xutil_error_get(const xcb_generic_error_t *e) xutil_error_init(const xcb_generic_error_t *e, xutil_error_t *err)
{ {
if(e->response_type != 0) if(e->response_type != 0)
/* This is not an error, this _should_ not happen */ /* This is not an error, this _should_ not happen */
return NULL; return false;
xutil_error_t *err = p_new(xutil_error_t, 1);
/* /*
* Get the request code, taken from 'xcb-util/wm'. I can't figure * Get the request code, taken from 'xcb-util/wm'. I can't figure
@ -329,7 +327,7 @@ xutil_error_get(const xcb_generic_error_t *e)
else else
err->error_label = a_strdup(xutil_label_error[e->error_code]); err->error_label = a_strdup(xutil_label_error[e->error_code]);
return err; return true;
} }
/** Link a name to a key symbol */ /** Link a name to a key symbol */

View File

@ -111,17 +111,16 @@ typedef struct
char *error_label; char *error_label;
} xutil_error_t; } xutil_error_t;
xutil_error_t *xutil_error_get(const xcb_generic_error_t *); bool xutil_error_init(const xcb_generic_error_t *, xutil_error_t *);
xcb_keysym_t xutil_key_mask_fromstr(const char *); xcb_keysym_t xutil_key_mask_fromstr(const char *);
unsigned int xutil_button_fromint(int); unsigned int xutil_button_fromint(int);
xcb_cursor_t xutil_cursor_new(xcb_connection_t *, unsigned int); xcb_cursor_t xutil_cursor_new(xcb_connection_t *, unsigned int);
static inline void static inline void
xutil_error_delete(xutil_error_t *err) xutil_error_wipe(xutil_error_t *err)
{ {
p_delete(&err->error_label); p_delete(&err->error_label);
p_delete(&err->request_label); p_delete(&err->request_label);
p_delete(&err);
} }
/* Get the informations about the screen. /* Get the informations about the screen.