[vlc-devel] [PATCH 1/3] vlc_list: helpers for doubly linked lists

Romain Vimont rom1v at videolabs.io
Mon Jun 11 17:14:47 CEST 2018


On Mon, Jun 11, 2018 at 01:27:12PM +0300, RĂ©mi Denis-Courmont wrote:
> I am storing the head so that the head expression is expansion-safe. In practice, the compiler should be able to optimize it away. Likewise, it should be able to optimize the constant offset away.

Since the offset is compile-time constant, I would not store it at all.

> Point is that an iterator is unavoidable in the general case. With that in mind, I'd rather leverage the iterator to make the code as safe as possible.
> 
> I already replaced goal with head to make the iteration safe against removal.

OK, so you want the safe foreach version only.

> @@ -124,9 +120,12 @@ static inline int info_category_DeleteInfo(info_category_t *cat, const char *nam
> 
>  static inline void info_category_Delete(info_category_t *cat)
>  {
> -    for (int i = 0; i < cat->i_infos; i++)
> -        info_Delete(cat->pp_infos[i]);
> -    free(cat->pp_infos);
> +    info_t *info;
> +
> +    while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) {
> +        vlc_list_remove(&info->node);
> +        info_Delete(info);
> +    }
>      free(cat->psz_name);
>      free(cat);
>  }

Once you have implemented the safe version, you could probably use it
here :)


More information about the vlc-devel mailing list