shared: Print .c file/line number in x* routines
Switches from inline to pre-processor definitions in order to utilize
__FILE__ and __LINE__ from the .c file in order to display the location
of memory allocation failures when failing.
Now xmalloc, et al calls will produce:
[weston-info] clients/weston-info.c:714: out of memory (1024)
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
committed by
Pekka Paalanen
parent
e99e4bf2b9
commit
ae5d7198f7
+4
-24
@@ -38,30 +38,10 @@ extern "C" {
|
|||||||
void *
|
void *
|
||||||
fail_on_null(void *p, size_t size, char *file, int32_t line);
|
fail_on_null(void *p, size_t size, char *file, int32_t line);
|
||||||
|
|
||||||
static inline void *
|
#define xmalloc(s) (fail_on_null(malloc(s), (s), __FILE__, __LINE__))
|
||||||
xmalloc(size_t s)
|
#define xzalloc(s) (fail_on_null(zalloc(s), (s), __FILE__, __LINE__))
|
||||||
{
|
#define xstrdup(s) (fail_on_null(strdup(s), 0, __FILE__, __LINE__))
|
||||||
return fail_on_null(malloc(s), s, NULL, 0);
|
#define xrealloc(p, s) (fail_on_null(realloc(p, s), (s), __FILE__, __LINE__))
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *
|
|
||||||
xzalloc(size_t s)
|
|
||||||
{
|
|
||||||
return fail_on_null(zalloc(s), s, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline char *
|
|
||||||
xstrdup(const char *s)
|
|
||||||
{
|
|
||||||
return fail_on_null(strdup(s), 0, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *
|
|
||||||
xrealloc(char *p, size_t s)
|
|
||||||
{
|
|
||||||
return fail_on_null(realloc(p, s), s, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user