mirror of https://github.com/mpv-player/mpv
ta: add ta_get_parent()
Sometimes useful for debugging. Also fix a random typo elsewhere.
This commit is contained in:
parent
729843b85e
commit
027ae815ec
12
ta/ta.c
12
ta/ta.c
|
@ -97,7 +97,7 @@ void ta_set_parent(void *ptr, void *ta_parent)
|
|||
ch->prev->next = ch->next;
|
||||
if (ch->next)
|
||||
ch->next->prev = ch->prev;
|
||||
// If ch was the firs child, change child link of old parent
|
||||
// If ch was the first child, change child link of old parent
|
||||
if (ch->parent) {
|
||||
assert(ch->parent->child == ch);
|
||||
ch->parent->child = ch->next;
|
||||
|
@ -119,6 +119,16 @@ void ta_set_parent(void *ptr, void *ta_parent)
|
|||
}
|
||||
}
|
||||
|
||||
/* Return the parent allocation, or NULL if none or if ptr==NULL.
|
||||
*
|
||||
* Warning: do not use this for program logic, or I'll be sad.
|
||||
*/
|
||||
void *ta_get_parent(void *ptr)
|
||||
{
|
||||
struct ta_header *ch = get_header(ptr);
|
||||
return ch ? ch->parent : NULL;
|
||||
}
|
||||
|
||||
/* Allocate size bytes of memory. If ta_parent is not NULL, this is used as
|
||||
* parent allocation (if ta_parent is freed, this allocation is automatically
|
||||
* freed as well). size==0 allocates a block of size 0 (i.e. returns non-NULL).
|
||||
|
|
1
ta/ta.h
1
ta/ta.h
|
@ -52,6 +52,7 @@ void ta_free(void *ptr);
|
|||
void ta_free_children(void *ptr);
|
||||
void ta_set_destructor(void *ptr, void (*destructor)(void *));
|
||||
void ta_set_parent(void *ptr, void *ta_parent);
|
||||
void *ta_get_parent(void *ptr);
|
||||
|
||||
// Utility functions
|
||||
size_t ta_calc_array_size(size_t element_size, size_t count);
|
||||
|
|
Loading…
Reference in New Issue