clients & tests: Unify multiple definitions of x*alloc and related functions

Direct fail_on_null calls now produce output like:

    [weston-info] clients/weston-info.c:714: out of memory

xmalloc, et al produce output on failure like:

    [weston-info] out of memory (-1)

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Bryce Harrington
2016-03-16 14:15:18 -07:00
committed by Pekka Paalanen
parent 4e221f0327
commit e99e4bf2b9
23 changed files with 150 additions and 159 deletions
+1
View File
@@ -41,6 +41,7 @@
#include "window.h"
#include "shared/helpers.h"
#include "shared/xalloc.h"
struct clickdot {
struct display *display;
+1
View File
@@ -50,6 +50,7 @@
#include <wayland-client.h>
#include "src/vertex-clipping.h"
#include "shared/xalloc.h"
#include "window.h"
typedef float GLfloat;
+1
View File
@@ -46,6 +46,7 @@
#include "shared/cairo-util.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "weston-desktop-shell-client-protocol.h"
+1
View File
@@ -42,6 +42,7 @@
#include "window.h"
#include "shared/cairo-util.h"
#include "shared/helpers.h"
#include "shared/xalloc.h"
struct dnd_drag;
+1
View File
@@ -37,6 +37,7 @@
#include <pango/pangocairo.h>
#include "shared/helpers.h"
#include "shared/xalloc.h"
#include "window.h"
#include "text-input-unstable-v1-client-protocol.h"
+1 -12
View File
@@ -40,6 +40,7 @@
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "ivi-application-client-protocol.h"
#include "ivi-hmi-controller-client-protocol.h"
@@ -163,18 +164,6 @@ hmi_homescreen_setting {
int32_t screen_num;
};
static void *
fail_on_null(void *p, size_t size, char *file, int32_t line)
{
if (size && !p) {
fprintf(stderr, "%s(%d) %zd: out of memory\n",
file, line, size);
exit(EXIT_FAILURE);
}
return p;
}
static void *
mem_alloc(size_t size, char *file, int32_t line)
{
+1
View File
@@ -34,6 +34,7 @@
#include "window.h"
#include "input-method-unstable-v1-client-protocol.h"
#include "text-input-unstable-v1-client-protocol.h"
#include "shared/xalloc.h"
struct keyboard;
+1 -14
View File
@@ -40,6 +40,7 @@
#include <wayland-client.h>
#include "shared/os-compatibility.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
struct device {
@@ -83,20 +84,6 @@ static const struct wl_buffer_listener buffer_listener = {
buffer_release
};
static inline void *
xzalloc(size_t s)
{
void *p;
p = zalloc(s);
if (p == NULL) {
fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
exit(EXIT_FAILURE);
}
return p;
}
static int
attach_buffer(struct window *window, int width, int height)
{
+1
View File
@@ -35,6 +35,7 @@
#include <wayland-client.h>
#include "window.h"
#include "shared/xalloc.h"
struct spring {
double current;
+1 -15
View File
@@ -38,6 +38,7 @@
#include <wayland-client.h>
#include "weston-screenshooter-client-protocol.h"
#include "shared/os-compatibility.h"
#include "shared/xalloc.h"
/* The screenshooter is a good example of a custom object exposed by
* the compositor and serves as a test bed for implementing client
@@ -79,21 +80,6 @@ display_handle_geometry(void *data,
}
}
static void *
xmalloc(size_t size)
{
void *p;
p = malloc(size);
if (p == NULL) {
fprintf(stderr, "%s: out of memory\n",
program_invocation_short_name);
exit(EXIT_FAILURE);
}
return p;
}
static void
display_handle_mode(void *data,
struct wl_output *wl_output,
+1
View File
@@ -42,6 +42,7 @@
#include <EGL/eglext.h>
#include "shared/helpers.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "window.h"
+1
View File
@@ -45,6 +45,7 @@
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/xalloc.h"
#include "window.h"
static int option_fullscreen;
+1 -29
View File
@@ -34,6 +34,7 @@
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "presentation-time-client-protocol.h"
@@ -119,35 +120,6 @@ struct weston_info {
bool roundtrip_needed;
};
static void *
fail_on_null(void *p)
{
if (p == NULL) {
fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
exit(EXIT_FAILURE);
}
return p;
}
static void *
xmalloc(size_t s)
{
return fail_on_null(malloc(s));
}
static void *
xzalloc(size_t s)
{
return fail_on_null(zalloc(s));
}
static char *
xstrdup(const char *s)
{
return fail_on_null(strdup(s));
}
static void
print_global_info(void *data)
{
+5 -39
View File
@@ -68,6 +68,7 @@ typedef void *EGLContext;
#include <wayland-client.h>
#include "shared/cairo-util.h"
#include "shared/helpers.h"
#include "shared/xalloc.h"
#include "shared/zalloc.h"
#include "xdg-shell-unstable-v5-client-protocol.h"
#include "text-cursor-position-client-protocol.h"
@@ -4746,7 +4747,7 @@ window_create(struct display *display)
window->xdg_surface =
xdg_shell_get_xdg_surface(window->display->xdg_shell,
window->main_surface->surface);
fail_on_null(window->xdg_surface);
fail_on_null(window->xdg_surface, 0, __FILE__, __LINE__);
xdg_surface_set_user_data(window->xdg_surface, window);
xdg_surface_add_listener(window->xdg_surface,
@@ -4757,7 +4758,7 @@ window_create(struct display *display)
window->ivi_surface =
ivi_application_surface_create(display->ivi_application,
id_ivisurf, window->main_surface->surface);
fail_on_null(window->ivi_surface);
fail_on_null(window->ivi_surface, 0, __FILE__, __LINE__);
ivi_surface_add_listener(window->ivi_surface,
&ivi_surface_listener, window);
@@ -4947,7 +4948,7 @@ create_menu(struct display *display,
menu->widget = window_add_widget(menu->window, menu);
menu->frame = frame_create(window->display->theme, 0, 0,
FRAME_BUTTON_NONE, NULL);
fail_on_null(menu->frame);
fail_on_null(menu->frame, 0, __FILE__, __LINE__);
menu->entries = entries;
menu->count = count;
menu->release_count = 0;
@@ -5024,7 +5025,7 @@ window_show_menu(struct display *display,
display_get_serial(window->display),
window->x - ix,
window->y - iy);
fail_on_null(window->xdg_popup);
fail_on_null(window->xdg_popup, 0, __FILE__, __LINE__);
xdg_popup_set_user_data(window->xdg_popup, window);
xdg_popup_add_listener(window->xdg_popup,
@@ -6027,38 +6028,3 @@ keysym_modifiers_get_mask(struct wl_array *modifiers_map,
return 1 << index;
}
void *
fail_on_null(void *p)
{
if (p == NULL) {
fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
exit(EXIT_FAILURE);
}
return p;
}
void *
xmalloc(size_t s)
{
return fail_on_null(malloc(s));
}
void *
xzalloc(size_t s)
{
return fail_on_null(zalloc(s));
}
char *
xstrdup(const char *s)
{
return fail_on_null(strdup(s));
}
void *
xrealloc(char *p, size_t s)
{
return fail_on_null(realloc(p, s));
}
-11
View File
@@ -51,17 +51,6 @@ struct rectangle {
int32_t height;
};
void *
fail_on_null(void *p);
void *
xmalloc(size_t s);
void *
xzalloc(size_t s);
char *
xstrdup(const char *s);
void *
xrealloc(char *p, size_t s);
struct display *
display_create(int *argc, char *argv[]);