xcb: Remove useless error handling

All the *_reply() functions in XCB return a pointer to their result and as last
argument they get a xcb_generic_error_t** where pointers to errors are stored,
if any occurs.

However, a request can either fail or succeed. This means that if the returned
result is a NULL pointer, then an error occurred and the other way around: If
the error pointer is set to non-NULL, then the function must have returned NULL.

Thus, all the code, which just checks if an error occurred and which does not
care about the exact error code, does not need to get the error pointer at all.
In this case, xcb will free() the error internally.

While doing this, I noticed that _cairo_xcb_connection_get_image() always
succeeds and thus its return value can be replaced with the GetImage result.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2013-09-16 12:45:21 +02:00
parent 440624cdf2
commit 9c75065ece
4 changed files with 22 additions and 44 deletions

View file

@ -283,32 +283,20 @@ _cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection,
}
}
cairo_status_t
xcb_get_image_reply_t *
_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection,
xcb_drawable_t src,
int16_t src_x,
int16_t src_y,
uint16_t width,
uint16_t height,
xcb_get_image_reply_t **reply)
uint16_t height)
{
xcb_generic_error_t *error;
*reply = xcb_get_image_reply (connection->xcb_connection,
xcb_get_image (connection->xcb_connection,
XCB_IMAGE_FORMAT_Z_PIXMAP,
src,
src_x, src_y,
width, height,
(uint32_t) -1),
&error);
if (error) {
free (error);
free (*reply);
*reply = NULL;
}
return CAIRO_STATUS_SUCCESS;
return xcb_get_image_reply (connection->xcb_connection,
xcb_get_image (connection->xcb_connection,
XCB_IMAGE_FORMAT_Z_PIXMAP,
src,
src_x, src_y,
width, height,
(uint32_t) -1),
NULL);
}

View file

@ -82,7 +82,6 @@ _cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection,
uint32_t offset)
{
xcb_shm_get_image_reply_t *reply;
xcb_generic_error_t *error;
assert (connection->flags & CAIRO_XCB_HAS_SHM);
reply = xcb_shm_get_image_reply (connection->xcb_connection,
@ -93,12 +92,11 @@ _cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection,
(uint32_t) -1,
XCB_IMAGE_FORMAT_Z_PIXMAP,
shmseg, offset),
&error);
NULL);
free (reply);
if (error) {
if (!reply) {
/* an error here should be impossible */
free (error);
return _cairo_error (CAIRO_STATUS_READ_ERROR);
}

View file

@ -505,14 +505,13 @@ _cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection,
uint8_t depth,
void *data);
cairo_private cairo_status_t
cairo_private xcb_get_image_reply_t *
_cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection,
xcb_drawable_t src,
int16_t src_x,
int16_t src_y,
uint16_t width,
uint16_t height,
xcb_get_image_reply_t **reply);
uint16_t height);
cairo_private void
_cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection,

View file

@ -382,13 +382,10 @@ _get_image (cairo_xcb_surface_t *surface,
}
}
status = _cairo_xcb_connection_get_image (connection,
surface->drawable,
x, y,
width, height,
&reply);
if (unlikely (status))
goto FAIL;
reply =_cairo_xcb_connection_get_image (connection,
surface->drawable,
x, y,
width, height);
if (reply == NULL && ! surface->owns_pixmap) {
/* xcb_get_image_t from a window is dangerous because it can
@ -422,15 +419,11 @@ _get_image (cairo_xcb_surface_t *surface,
_cairo_xcb_screen_put_gc (surface->screen, surface->depth, gc);
status = _cairo_xcb_connection_get_image (connection,
pixmap,
0, 0,
width, height,
&reply);
reply = _cairo_xcb_connection_get_image (connection,
pixmap,
0, 0,
width, height);
_cairo_xcb_connection_free_pixmap (connection, pixmap);
if (unlikely (status))
goto FAIL;
}
if (unlikely (reply == NULL)) {