TCC – dynarray_add

This is very common function in TCC state.

here is main logical.

1
2
3
4
5
6
7
dynarray_add(void ***ptab, int *nb_ptr, void *data) 
{
...
pp= *ptab; nb=*nb_ptr;
pp[nb++] = data;
...
}

what dynarray_add do is simple. input array has just 3 parts that is double pointer, index and value.

then assign data to double pointer just like assign string to char array.

Here is sample call stack, it call to add pathname into library_paths.

1
2
3
dynarray_add(p_ary, p_nb_ary, str.data);
tcc_split_path(TCCState *s, void ***p_ary, int *p_nb_ary, const char *in)
tcc_split_path(s, (void ***)&s->library_paths, &s->nb_library_paths, pathname);

the define of library_paths is following

1
2
3
4
5
6
struct TCCState {
...
    char **library_paths;
    int nb_library_paths;
...
}