diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-16 23:21:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:08:55 -0500 |
commit | 7b79694eadc288592729567c3caa7c70f6662760 (patch) | |
tree | e33deb9389d3268095cf90ead49b44c359e1b8ea /source4/lib/talloc/talloc.c | |
parent | 0a5fd5421c02cb4df21eec30bf216df65cd7641b (diff) | |
download | samba-7b79694eadc288592729567c3caa7c70f6662760.tar.gz samba-7b79694eadc288592729567c3caa7c70f6662760.tar.bz2 samba-7b79694eadc288592729567c3caa7c70f6662760.zip |
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 used to be commit c283e1a3efac3a92e29a35856e20eb61ef4c221e)
Diffstat (limited to 'source4/lib/talloc/talloc.c')
-rw-r--r-- | source4/lib/talloc/talloc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index e05b196592..f6f7e899d1 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -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; } + + |