From bc3678da65831f81c9151a57b4272563d1df582e Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 23 Feb 2020 17:45:05 +0100 Subject: ta: change API; ta_set_parent() and ta_set_destructor() never fail The previous change ensured that these cannot fail anymore (much like in original talloc). Change the APIs to not return a success value anymore, to "cement" this. --- ta/ta_utils.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'ta/ta_utils.c') diff --git a/ta/ta_utils.c b/ta/ta_utils.c index cc122b58a2..8d729a9028 100644 --- a/ta/ta_utils.c +++ b/ta/ta_utils.c @@ -44,21 +44,11 @@ size_t ta_calc_prealloc_elems(size_t nextidx) return (nextidx + 1) * 2; } -static void dummy_dtor(void *p){} - -/* Create an empty (size 0) TA allocation, which is prepared in a way such that - * using it as parent with ta_set_parent() always succeed. Calling - * ta_set_destructor() on it will always succeed as well. +/* Create an empty (size 0) TA allocation. */ void *ta_new_context(void *ta_parent) { - void *new = ta_alloc_size(ta_parent, 0); - // Force it to allocate an extended header. - if (!ta_set_destructor(new, dummy_dtor)) { - ta_free(new); - new = NULL; - } - return new; + return ta_alloc_size(ta_parent, 0); } /* Set parent of ptr to ta_parent, return the ptr. @@ -68,8 +58,7 @@ void *ta_new_context(void *ta_parent) */ void *ta_steal_(void *ta_parent, void *ptr) { - if (!ta_set_parent(ptr, ta_parent)) - return NULL; + ta_set_parent(ptr, ta_parent); return ptr; } @@ -138,10 +127,7 @@ char *ta_strndup(void *ta_parent, const char *str, size_t n) return NULL; char *new = NULL; strndup_append_at(&new, 0, str, n); - if (!ta_set_parent(new, ta_parent)) { - ta_free(new); - new = NULL; - } + ta_set_parent(new, ta_parent); return new; } @@ -229,7 +215,8 @@ char *ta_vasprintf(void *ta_parent, const char *fmt, va_list ap) { char *res = NULL; ta_vasprintf_append_at(&res, 0, fmt, ap); - if (!res || !ta_set_parent(res, ta_parent)) { + ta_set_parent(res, ta_parent); + if (!res) { ta_free(res); return NULL; } @@ -303,7 +290,7 @@ char *ta_oom_s(char *s) void *ta_xsteal_(void *ta_parent, void *ptr) { - ta_oom_b(ta_set_parent(ptr, ta_parent)); + ta_set_parent(ptr, ta_parent); return ptr; } -- cgit v1.2.3