glib dependency for the X Server

Carsten Haitzler (The Rasterman) raster at rasterman.com
Mon Apr 3 17:24:09 PDT 2006


On Mon, 03 Apr 2006 08:33:34 -0700 Ian Romanick <idr at us.ibm.com> babbled:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Carsten Haitzler (The Rasterman) wrote:
> > struct _XD_List /** A linked list node */
> > {
> >    void    *data; /**< Pointer to list element payload */
> >    XD_List *next; /**< Next member in the list */
> >    XD_List *prev; /**< Previous member in the list */
> >    void    *accounting; /**< Private list accounting info - don't touch */
> > };
> 
> What's disappointing here is that having the do NULL pointer checks on
> list element pointers was solved 20 years ago on the Amiga.

bit instead now all lists require allocation of a list header - as opposed to 0
bytes for an empty list (beyond the pointer to it). it also requires special
treatment of the head as opposed to members. glib's list style is simple and
convenient and i mimicked it as i liked it and was used to it. you also have
removed allocation of new nodes (1 null check) from the example (and are just
avoiding showing it). you also miss the fact that initilising an empty list is
more expensive and more work than simply starting with calloc()ed memory that's
already NULL'ed out (so your lists start empty).

really - its neither one way or another. you pay the price somewhere in some
way. either in code complexity, more setup complexity (and forgetting to set up
your list and finding the bugs for that) etc. etc.

> See:
> 
> http://www.aros.org/documentation/developers/app-dev/exec-library.php#exec-lists
> 
> struct list {
>     struct node * head;
>     struct node * null;
>     struct node * tail;
> };
> 
> struct node {
>     struct node * next;
>     struct node * prev;
> };
> 
> int is_list_empty( const struct list * l )
> {
>     /* Using (l->head == (struct node *) & l->null) also works.
>      */
>     return (l->head->next == NULL);
> }
> 
> void list_init( struct list * l )
> {
>     l->head = (struct node *) & l->null;
>     l->null = NULL;
>     l->tail = (struct node *) & l->head;
> }
> 
> void append_node( struct list * l, struct node * n )
> {
>     l->tail->next = n;
>     n->next = (struct node *) & l->null;
> 
>     n->prev = l->tail;
>     l->tail = n;
> }
> 
> void remove_node( struct node * n )
> {
>     n->next->prev = n->prev;
>     n->prev->next = n->next;
>     n->next = NULL;
>     n->prev = NULL;
> }
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (GNU/Linux)
> 
> iD8DBQFEMUBOX1gOwKyEAw8RAtzWAJ9ViOy8dA7sCbjgpSps/el4roz6EwCgi62E
> IotIYTeBlMqpBYiJTzB+Hzc=
> =C9mz
> -----END PGP SIGNATURE-----
> _______________________________________________
> xorg mailing list
> xorg at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xorg
> 


-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    raster at rasterman.com
裸好多
Tokyo, Japan (東京 日本)



More information about the xorg mailing list