Re: GList and GSList data abstraction



Kevin Lai <laik@tnt.stanford.edu> writes:
> There doesn't appear to be a way to access the data field of GList and
> GSList without using g_list_nth_data() (which is overkill) or doing a
> direct "list->data" (which violates data abstraction). The included
> patch allows applications to avoid doing either by adding
> g_list_data() and g_slist_data() macros. 
>

It doesn't hurt to have the macro, but realistically you aren't
gaining any benefit; so much code already uses ->data directly that
it's impossible to ever change, and the abstraction is useless.

> +#define g_list_data(list)	((list) ? (((GList *)(list))->data) : NULL)
>  

If list is NULL then it's an empty list with no elements, and code
accessing the data in an empty list is broken - so probably you don't
want to silently accept an off-by-one error like that.

I would say either make it a function with g_return_if_fail, or just
let it segfault (NULL will always segfault in an easy-to-find way).

Havoc



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]