diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-03-03 18:01:01 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-03-03 18:07:33 +0100 |
commit | b6f479d4413511fbd742e7c8464cec67501f539c (patch) | |
tree | c52c6fcbd6724a1600ea6a30cea3f535b4cf2f62 /lib/talloc | |
parent | 4b2955aa7dbcf06629d24d3ea35c6dfa8c4156b9 (diff) | |
download | samba-b6f479d4413511fbd742e7c8464cec67501f539c.tar.gz samba-b6f479d4413511fbd742e7c8464cec67501f539c.tar.bz2 samba-b6f479d4413511fbd742e7c8464cec67501f539c.zip |
talloc: add talloc_get_type_abort()
metze
Diffstat (limited to 'lib/talloc')
-rw-r--r-- | lib/talloc/talloc.c | 24 | ||||
-rw-r--r-- | lib/talloc/talloc.h | 2 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 1f7e52439f..c472e9fda9 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -806,6 +806,30 @@ void *talloc_check_name(const void *ptr, const char *name) return NULL; } +static void talloc_abort_type_missmatch(const char *location, + const char *name, + const char *expected) +{ + TALLOC_ABORT("Type missmatch"); +} + +void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location) +{ + const char *pname; + + if (unlikely(ptr == NULL)) { + talloc_abort_type_missmatch(location, NULL, name); + return NULL; + } + + pname = talloc_get_name(ptr); + if (likely(pname == name || strcmp(pname, name) == 0)) { + return discard_const_p(void, ptr); + } + + talloc_abort_type_missmatch(location, pname, name); + return NULL; +} /* this is for compatibility with older versions of talloc diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h index 5431971655..002e06e52d 100644 --- a/lib/talloc/talloc.h +++ b/lib/talloc/talloc.h @@ -102,6 +102,7 @@ typedef void TALLOC_CTX; #define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type) #define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type) +#define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__) #define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type) @@ -129,6 +130,7 @@ void *talloc_named(const void *context, size_t size, void *talloc_named_const(const void *context, size_t size, const char *name); const char *talloc_get_name(const void *ptr); void *talloc_check_name(const void *ptr, const char *name); +void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location); void *talloc_parent(const void *ptr); const char *talloc_parent_name(const void *ptr); void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); |