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:
committed by
Gerald (Jerry) Carter
parent
128e97cef6
commit
c283e1a3ef
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user