1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

talloc: add talloc_get_type_abort()

metze
This commit is contained in:
Stefan Metzmacher 2009-03-03 18:01:01 +01:00
parent 4b2955aa7d
commit b6f479d441
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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);