[Xquartz-changes] xserver: Branch 'master' - 2 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Tue Aug 28 20:10:43 PDT 2012


 include/list.h |   10 ++++++----
 test/list.c    |    4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit 71689522b1a41e945d92bbf05760d8cf2571b1b4
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Aug 28 10:06:51 2012 -0700

    list: Use offsetof() to determine member offsets within a structure
    
    Some compilers have difficulty with the previous implementation which
    relies on undefined behavior according to the C standard.  Using
    offsetof() from <stddef.h> (which most likely just uses
    __builtin_offsetof on modern compilers) allows us to accomplish this
    without ambiguity.
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/include/list.h b/include/list.h
index d54a207..ae5431c 100644
--- a/include/list.h
+++ b/include/list.h
@@ -26,6 +26,8 @@
 #ifndef _XORG_LIST_H_
 #define _XORG_LIST_H_
 
+#include <stddef.h> /* offsetof() */
+
 /**
  * @file Classic doubly-link circular list implementation.
  * For real usage examples of the linked list, see the file test/list.c
@@ -232,7 +234,7 @@ xorg_list_is_empty(struct xorg_list *head)
  */
 #ifndef container_of
 #define container_of(ptr, type, member) \
-    (type *)((char *)(ptr) - (char *) &((type *)0)->member)
+    (type *)((char *)(ptr) - (char *) offsetof(type, member))
 #endif
 
 /**
@@ -271,9 +273,9 @@ xorg_list_is_empty(struct xorg_list *head)
 #define xorg_list_last_entry(ptr, type, member) \
     xorg_list_entry((ptr)->prev, type, member)
 
-#define __container_of(ptr, sample, member)				\
-    (void *)((char *)(ptr)						\
-	     - ((char *)&(sample)->member - (char *)(sample)))
+#define __container_of(ptr, sample, member)			\
+    container_of(ptr, typeof(*sample), member)
+
 /**
  * Loop through the list given by head and set pos to struct in the list.
  *
commit c75c947b6e9bc725821b28835f3667c4aabef9ee
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Aug 28 12:43:55 2012 -0700

    test/list: Fix test_xorg_list_del test
    
    We never use child[2], so it's state is undefined.
    
    This issue seems to have existed since the test was first
    written: 92788e677be79bd04e5ef140f4ced50ad8b1bf8e
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/list.c b/test/list.c
index 82d2327..f9f54ee 100644
--- a/test/list.c
+++ b/test/list.c
@@ -137,7 +137,7 @@ static void
 test_xorg_list_del(void)
 {
     struct parent parent = { 0 };
-    struct child child[3];
+    struct child child[2];
     struct child *c;
 
     xorg_list_init(&parent.children);
@@ -178,8 +178,8 @@ test_xorg_list_del(void)
     xorg_list_add(&child[0].node, &parent.children);
     xorg_list_del(&parent.children);
     assert(xorg_list_is_empty(&parent.children));
+    assert(!xorg_list_is_empty(&child[0].node));
     assert(!xorg_list_is_empty(&child[1].node));
-    assert(!xorg_list_is_empty(&child[2].node));
 }
 
 static void


More information about the Xquartz-changes mailing list