From: Carl Worth Date: Tue, 25 May 2010 21:40:47 +0000 (-0700) Subject: Add xtalloc_reference. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9bb796f33ac67abdf6c0bf55a06b0d8448caa3d3;p=mesa.git Add xtalloc_reference. Yet another talloc wrapper that should come in handy. --- diff --git a/glcpp.h b/glcpp.h index 503731b85b3..6171ce8b4a0 100644 --- a/glcpp.h +++ b/glcpp.h @@ -164,4 +164,10 @@ xtalloc_strndup (const void *t, const char *p, size_t n); char * xtalloc_asprintf (const void *t, const char *fmt, ...); +void * +_xtalloc_reference_loc (const void *context, + const void *ptr, const char *location); + +#define xtalloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_xtalloc_reference_loc((ctx),(ptr), __location__) + #endif diff --git a/xtalloc.c b/xtalloc.c index e52d12ac6b2..656ac2d6cb5 100644 --- a/xtalloc.c +++ b/xtalloc.c @@ -82,3 +82,18 @@ xtalloc_asprintf (const void *t, const char *fmt, ...) va_end(ap); return ret; } + +void * +_xtalloc_reference_loc (const void *context, + const void *ptr, const char *location) +{ + void *ret; + + ret = _talloc_reference_loc (context, ptr, location); + if (ret == NULL) { + fprintf (stderr, "Out of memory.\n"); + exit (1); + } + + return ret; +}