1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-15 16:23:49 +03:00

r4790: added type checking helper macros in talloc. These take advantage of

the type names that talloc already keeps around for pointers, and
allows the user to type check void* private pointers. It can also be
used to implement polymorphism in C, as I'm sure someone would have
pointed out to me sooner or later :-)
This commit is contained in:
Andrew Tridgell
2005-01-16 23:21:52 +00:00
committed by Gerald (Jerry) Carter
parent 128e97cef6
commit c283e1a3ef
4 changed files with 107 additions and 9 deletions

View File

@@ -424,6 +424,23 @@ const char *talloc_get_name(const void *ptr)
return "UNNAMED";
}
/*
check if a pointer has the given name. If it does, return the pointer,
otherwise return NULL
*/
void *talloc_check_name(const void *ptr, const char *name)
{
const char *pname;
if (ptr == NULL) return NULL;
pname = talloc_get_name(ptr);
if (pname == name || strcmp(pname, name) == 0) {
return discard_const_p(void, ptr);
}
return NULL;
}
/*
this is for compatibility with older versions of talloc
*/
@@ -1029,3 +1046,5 @@ void *talloc_autofree_context(void)
}
return cleanup_context;
}