[PATCH weston v3 03/15] tests: Add an xmalloc helper function
Bryce Harrington
bryce at osg.samsung.com
Thu May 21 01:39:25 PDT 2015
Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
tests/weston-test-client-helper.c | 11 +++++++++++
tests/weston-test-client-helper.h | 16 ++++++++++------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 00fdf8f..080bb62 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -32,6 +32,17 @@
#include "../shared/os-compatibility.h"
#include "weston-test-client-helper.h"
+void *
+fail_on_null(void *p)
+{
+ if (p == NULL) {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+ return p;
+}
+
+
int
surface_contains(struct surface *surface, int x, int y)
{
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index b46f158..43a5aa7 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -132,15 +132,19 @@ struct surface {
void *data;
};
+void *
+fail_on_null(void *p);
+
static inline void *
-xzalloc(size_t size)
+xzalloc(size_t s)
{
- void *p;
-
- p = calloc(1, size);
- assert(p);
+ return fail_on_null(calloc(1, s));
+}
- return p;
+static inline void *
+xmalloc(size_t s)
+{
+ return fail_on_null(malloc(s));
}
struct client *
--
1.9.1
More information about the wayland-devel
mailing list