summaryrefslogtreecommitdiffstats
path: root/ta/ta_utils.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-23 17:45:05 +0100
committerwm4 <wm4@nowhere>2020-02-23 17:45:05 +0100
commitbc3678da65831f81c9151a57b4272563d1df582e (patch)
tree60b474353f6fa0738e715492f5bf3cd8c6772771 /ta/ta_utils.c
parentf6615f00eeb05f072af24d132a78786c65e6aa80 (diff)
downloadmpv-bc3678da65831f81c9151a57b4272563d1df582e.tar.bz2
mpv-bc3678da65831f81c9151a57b4272563d1df582e.tar.xz
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.
Diffstat (limited to 'ta/ta_utils.c')
-rw-r--r--ta/ta_utils.c27
1 files changed, 7 insertions, 20 deletions
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;
}