<div dir="ltr"><div>This sure looks correct to me.<br><br></div>Using assert(0) seems like it was a mistake, as it would not happen if NDEBUG was defined but it appears the code is relying on it. And since it was already doing a call to wl_log no overhead was reduced by the removal.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 16, 2015 at 2:49 AM, Marek Chalupa <span dir="ltr"><<a href="mailto:mchqwerty@gmail.com" target="_blank">mchqwerty@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On many places in the code we use wl_log + abort or wl_log + assert(0).<br>
Replace these with one call to wl_abort, so that we don't mix abort(),<br>
assert(0) and we'll save few lines<br>
<br>
Signed-off-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>><br>
---<br>
src/connection.c | 22 +++++++---------------<br>
src/wayland-client.c | 12 ++++--------<br>
src/wayland-private.h | 1 +<br>
src/wayland-util.c | 12 ++++++++++++<br>
tests/sanity-test.c | 7 ++++++-<br>
5 files changed, 30 insertions(+), 24 deletions(-)<br>
<br>
diff --git a/src/connection.c b/src/connection.c<br>
index b3d9bd4..6742f19 100644<br>
--- a/src/connection.c<br>
+++ b/src/connection.c<br>
@@ -33,7 +33,6 @@<br>
#include <stdio.h><br>
#include <errno.h><br>
#include <sys/uio.h><br>
-#include <assert.h><br>
#include <fcntl.h><br>
#include <unistd.h><br>
#include <sys/types.h><br>
@@ -569,16 +568,12 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,<br>
case 'h':<br>
fd = args[i].h;<br>
dup_fd = wl_os_dupfd_cloexec(fd, 0);<br>
- if (dup_fd < 0) {<br>
- wl_log("dup failed: %m");<br>
- abort();<br>
- }<br>
+ if (dup_fd < 0)<br>
+ wl_abort("dup failed: %s\n", strerror(errno));<br>
closure->args[i].h = dup_fd;<br>
break;<br>
default:<br>
- wl_log("unhandled format code: '%c'\n",<br>
- arg.type);<br>
- assert(0);<br>
+ wl_abort("unhandled format code: '%c'\n", arg.type);<br>
break;<br>
}<br>
}<br>
@@ -771,8 +766,7 @@ wl_connection_demarshal(struct wl_connection *connection,<br>
closure->args[i].h = fd;<br>
break;<br>
default:<br>
- wl_log("unknown type\n");<br>
- assert(0);<br>
+ wl_abort("unknown type\n");<br>
break;<br>
}<br>
}<br>
@@ -906,8 +900,7 @@ convert_arguments_to_ffi(const char *signature, uint32_t flags,<br>
ffi_args[i] = &args[i].h;<br>
break;<br>
default:<br>
- wl_log("unknown type\n");<br>
- assert(0);<br>
+ wl_abort("unknown type\n");<br>
break;<br>
}<br>
}<br>
@@ -938,9 +931,8 @@ wl_closure_invoke(struct wl_closure *closure, uint32_t flags,<br>
<br>
implementation = target->implementation;<br>
if (!implementation[opcode]) {<br>
- wl_log("listener function for opcode %u of %s is NULL\n",<br>
- opcode, target->interface->name);<br>
- abort();<br>
+ wl_abort("listener function for opcode %u of %s is NULL\n",<br>
+ opcode, target->interface->name);<br>
}<br>
ffi_call(&cif, implementation[opcode], NULL, ffi_args);<br>
}<br>
diff --git a/src/wayland-client.c b/src/wayland-client.c<br>
index b1c600f..509be08 100644<br>
--- a/src/wayland-client.c<br>
+++ b/src/wayland-client.c<br>
@@ -597,18 +597,14 @@ wl_proxy_marshal_array_constructor(struct wl_proxy *proxy,<br>
}<br>
<br>
closure = wl_closure_marshal(&proxy->object, opcode, args, message);<br>
- if (closure == NULL) {<br>
- wl_log("Error marshalling request: %m\n");<br>
- abort();<br>
- }<br>
+ if (closure == NULL)<br>
+ wl_abort("Error marshalling request: %s\n", strerror(errno));<br>
<br>
if (debug_client)<br>
wl_closure_print(closure, &proxy->object, true);<br>
<br>
- if (wl_closure_send(closure, proxy->display->connection)) {<br>
- wl_log("Error sending request: %m\n");<br>
- abort();<br>
- }<br>
+ if (wl_closure_send(closure, proxy->display->connection))<br>
+ wl_abort("Error sending request: %s\n", strerror(errno));<br>
<br>
wl_closure_destroy(closure);<br>
<br>
diff --git a/src/wayland-private.h b/src/wayland-private.h<br>
index da9040a..58ac952 100644<br>
--- a/src/wayland-private.h<br>
+++ b/src/wayland-private.h<br>
@@ -209,6 +209,7 @@ wl_closure_destroy(struct wl_closure *closure);<br>
extern wl_log_func_t wl_log_handler;<br>
<br>
void wl_log(const char *fmt, ...);<br>
+void wl_abort(const char *fmt, ...);<br>
<br>
struct wl_display;<br>
<br>
diff --git a/src/wayland-util.c b/src/wayland-util.c<br>
index 00265e9..e782309 100644<br>
--- a/src/wayland-util.c<br>
+++ b/src/wayland-util.c<br>
@@ -385,3 +385,15 @@ wl_log(const char *fmt, ...)<br>
wl_log_handler(fmt, argp);<br>
va_end(argp);<br>
}<br>
+<br>
+void<br>
+wl_abort(const char *fmt, ...)<br>
+{<br>
+ va_list argp;<br>
+<br>
+ va_start(argp, fmt);<br>
+ wl_log_handler(fmt, argp);<br>
+ va_end(argp);<br>
+<br>
+ abort();<br>
+}<br>
diff --git a/tests/sanity-test.c b/tests/sanity-test.c<br>
index 3f589b5..65d986d 100644<br>
--- a/tests/sanity-test.c<br>
+++ b/tests/sanity-test.c<br>
@@ -31,8 +31,8 @@<br>
<br>
#include "test-runner.h"<br>
#include "wayland-util.h"<br>
+#include "wayland-private.h"<br>
<br>
-#define WL_HIDE_DEPRECATED<br>
#include "test-compositor.h"<br>
<br>
extern int leak_check_enabled;<br>
@@ -56,6 +56,11 @@ FAIL_TEST(fail_abort)<br>
abort();<br>
}<br>
<br>
+FAIL_TEST(fail_wl_abort)<br>
+{<br>
+ wl_abort("Abort the program\n");<br>
+}<br>
+<br>
FAIL_TEST(fail_kill)<br>
{<br>
kill(getpid(), SIGTERM);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>