add wl_abort private function

On many places in the code we use wl_log + abort or wl_log + assert(0).
Replace these with one call to wl_abort, so that we don't mix abort(),
assert(0) and we'll save few lines

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
This commit is contained in:
Marek Chalupa 2015-11-16 11:49:02 +01:00 committed by Bryce Harrington
parent 5660ea414f
commit c7bada036d
5 changed files with 30 additions and 24 deletions

View file

@ -33,7 +33,6 @@
#include <stdio.h>
#include <errno.h>
#include <sys/uio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
@ -569,16 +568,12 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
case 'h':
fd = args[i].h;
dup_fd = wl_os_dupfd_cloexec(fd, 0);
if (dup_fd < 0) {
wl_log("dup failed: %m");
abort();
}
if (dup_fd < 0)
wl_abort("dup failed: %s\n", strerror(errno));
closure->args[i].h = dup_fd;
break;
default:
wl_log("unhandled format code: '%c'\n",
arg.type);
assert(0);
wl_abort("unhandled format code: '%c'\n", arg.type);
break;
}
}
@ -771,8 +766,7 @@ wl_connection_demarshal(struct wl_connection *connection,
closure->args[i].h = fd;
break;
default:
wl_log("unknown type\n");
assert(0);
wl_abort("unknown type\n");
break;
}
}
@ -906,8 +900,7 @@ convert_arguments_to_ffi(const char *signature, uint32_t flags,
ffi_args[i] = &args[i].h;
break;
default:
wl_log("unknown type\n");
assert(0);
wl_abort("unknown type\n");
break;
}
}
@ -938,9 +931,8 @@ wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
implementation = target->implementation;
if (!implementation[opcode]) {
wl_log("listener function for opcode %u of %s is NULL\n",
opcode, target->interface->name);
abort();
wl_abort("listener function for opcode %u of %s is NULL\n",
opcode, target->interface->name);
}
ffi_call(&cif, implementation[opcode], NULL, ffi_args);
}

View file

@ -597,18 +597,14 @@ wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,
}
closure = wl_closure_marshal(&proxy->object, opcode, args, message);
if (closure == NULL) {
wl_log("Error marshalling request: %m\n");
abort();
}
if (closure == NULL)
wl_abort("Error marshalling request: %s\n", strerror(errno));
if (debug_client)
wl_closure_print(closure, &proxy->object, true);
if (wl_closure_send(closure, proxy->display->connection)) {
wl_log("Error sending request: %m\n");
abort();
}
if (wl_closure_send(closure, proxy->display->connection))
wl_abort("Error sending request: %s\n", strerror(errno));
wl_closure_destroy(closure);

View file

@ -209,6 +209,7 @@ wl_closure_destroy(struct wl_closure *closure);
extern wl_log_func_t wl_log_handler;
void wl_log(const char *fmt, ...);
void wl_abort(const char *fmt, ...);
struct wl_display;

View file

@ -385,3 +385,15 @@ wl_log(const char *fmt, ...)
wl_log_handler(fmt, argp);
va_end(argp);
}
void
wl_abort(const char *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
wl_log_handler(fmt, argp);
va_end(argp);
abort();
}

View file

@ -31,8 +31,8 @@
#include "test-runner.h"
#include "wayland-util.h"
#include "wayland-private.h"
#define WL_HIDE_DEPRECATED
#include "test-compositor.h"
extern int leak_check_enabled;
@ -56,6 +56,11 @@ FAIL_TEST(fail_abort)
abort();
}
FAIL_TEST(fail_wl_abort)
{
wl_abort("Abort the program\n");
}
FAIL_TEST(fail_kill)
{
kill(getpid(), SIGTERM);