libprelude/master: Update GnuLib code.

[email protected] Mon, 8 Jun 2009 14:24:01 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 562e8a51177875b5990eb6244fcb4a7b622c73bc
Author: Yoann Vandoorselaere <[email protected]>
Date:   Mon Jun 8 13:19:36 2009 +0200

    Update GnuLib code.


========================================

 libmissing/alignof.h            |   32 ++++++++++++++++++++++++++------
 libmissing/tests/test-alignof.c |   10 +++++++++-
 libmissing/tests/zerosize-ptr.h |    4 +++-
 3 files changed, 38 insertions(+), 8 deletions(-)

========================================

diff --git a/libmissing/alignof.h b/libmissing/alignof.h
index 3ef287b..28ce79c 100644
--- a/libmissing/alignof.h
+++ b/libmissing/alignof.h
@@ -20,14 +20,34 @@
 
 #include <stddef.h>
 
-/* Determine the alignment of a type at compile time.  */
-#if defined __GNUC__
-# define alignof __alignof__
-#elif defined __cplusplus
+/* Determine the alignment of a structure slot (field) of a given type,
+   at compile time.  Note that the result depends on the ABI.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __cplusplus
   template <class type> struct alignof_helper { char __slot1; type __slot2; };
-# define alignof(type) offsetof (alignof_helper<type>, __slot2)
+# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
+#else
+# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+#endif
+
+/* Determine the good alignment of a object of the given type at compile time.
+   Note that this is not necessarily the same as alignof_slot(type).
+   For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
+   - when -malign-double is not specified:  alignof_slot(double) = 4,
+   - when -malign-double is specified:      alignof_slot(double) = 8.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#if defined __GNUC__
+# define alignof_type __alignof__
 #else
-# define alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+# define alignof_type alignof_slot
 #endif
 
+/* alignof is an alias for alignof_slot semantics, since that's what most
+   callers need.
+   Note: The result cannot be used as a value for an 'enum' constant,
+   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#define alignof alignof_slot
+
 #endif /* _ALIGNOF_H */
diff --git a/libmissing/tests/test-alignof.c b/libmissing/tests/test-alignof.c
index 851cbf0..d42bdf5 100644
--- a/libmissing/tests/test-alignof.c
+++ b/libmissing/tests/test-alignof.c
@@ -21,9 +21,11 @@
 #include <alignof.h>
 
 #include <stddef.h>
+#include <stdint.h>
 
 #include "verify.h"
 
+typedef long double longdouble;
 typedef struct { char a[1]; } struct1;
 typedef struct { char a[2]; } struct2;
 typedef struct { char a[3]; } struct3;
@@ -31,7 +33,9 @@ typedef struct { char a[4]; } struct4;
 
 #define CHECK(type) \
   typedef struct { char slot1; type slot2; } type##_helper; \
-  verify (alignof (type) == offsetof (type##_helper, slot2));
+  verify (alignof_slot (type) == offsetof (type##_helper, slot2)); \
+  const int type##_slot_alignment = alignof_slot (type); \
+  const int type##_type_alignment = alignof_type (type);
 
 CHECK (char)
 CHECK (short)
@@ -39,6 +43,10 @@ CHECK (int)
 CHECK (long)
 CHECK (float)
 CHECK (double)
+CHECK (longdouble)
+#ifdef INT64_MAX
+CHECK (int64_t)
+#endif
 CHECK (struct1)
 CHECK (struct2)
 CHECK (struct3)
diff --git a/libmissing/tests/zerosize-ptr.h b/libmissing/tests/zerosize-ptr.h
index 9918ac7..a38a2cf 100644
--- a/libmissing/tests/zerosize-ptr.h
+++ b/libmissing/tests/zerosize-ptr.h
@@ -35,7 +35,9 @@
 # endif
 #endif
 
-/* Return a pointer to a zero-size object in memory, if possible.
+/* Return a pointer to a zero-size object in memory (that is, actually, a
+   pointer to a page boundary where the previous page is readable and writable
+   and the next page is neither readable not writable), if possible.
    Return NULL otherwise.  */
 
 static void *
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog