lkml.org 
[lkml]   [2008]   [Mar]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH -mm 1/5] list.h: add list_singleton
From
Date
On Fri, 2008-03-14 at 18:22 -0400, Masami Hiramatsu wrote:
> Andrew Morton wrote:
> > If your usage pattern is:
> >
> > struct foo {
> > ...
> > struct list_head bar_list; /* A list of `struct bar's */
> > };
> >
> > struct bar {
> > struct list_head list; /* Attached to foo.bar_list */
> > ...
> > };
> >
> > then yes, list_singleton() makes sense.
> >
> > But in other usage patterns it does not:
> >
> > struct foo {
> > struct bar *bar_list;
> > ...
> > };
> >
> > struct bar {
> > struct list_head list; /* All the other bars go here */
> > ...
> > };
> >
> > In the second case, emptiness is signified by foo.bar_list==NULL. And in
> > this case, code which does
> >
> > if (foo->bar_list && list_singleton(&foo->bar_list->list))
> >
> > will fail if there is a single item on the list!
> >
> > The second usage pattern is uncommon and list_empty() also returns
> > misleading answers when list_heads are used this way.
>
> I agreed. I assume that list_singleton() is used like as list_empty().
>
>
> > So I guess we can proceed with your list_singleton(), but I'd just like to
> > flag this possible confusion, see what people think..

May I kindly ask to please not use the singleton name like this. It does
not implement the singleton pattern and will be a great confusion for
everybody who expects it to.




\
 
 \ /
  Last update: 2008-03-15 23:39    [W:0.056 / U:0.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site