Use module 'alignof'.
authorBruno Haible <bruno@clisp.org>
Fri, 8 May 2009 11:21:34 +0000 (13:21 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 8 May 2009 11:21:34 +0000 (13:21 +0200)
ChangeLog
lib/malloca.h
modules/malloca

index 68b3f8ed25d4e43ee9c300e28bfd491f635dd4da..92c696a2bacf9a787bc3f36b8ee7c3f3846579e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-05-08  Bruno Haible  <bruno@clisp.org>
 
+       Use module 'alignof'.
+       * lib/malloca.h: Include alignof.h.
+       (sa_alignof): Remove macro.
+       (sa_alignment_*): Use the alignof macro.
+       * modules/malloca (Depends-on): Add alignof.
+
        New module 'alignof'.
        * lib/alignof.h: New file.
        * modules/alignof: New file.
index 5bb2d47348438109a962e64471e01a70f1815cda..2bf8501522732e6cfab2982a42e53521f1db92ea 100644 (file)
@@ -1,5 +1,5 @@
 /* Safe automatic memory allocation.
-   Copyright (C) 2003-2007 Free Software Foundation, Inc.
+   Copyright (C) 2003-2007, 2009 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -23,6 +23,8 @@
 #include <stddef.h>
 #include <stdlib.h>
 
+#include "alignof.h"
+
 
 #ifdef __cplusplus
 extern "C" {
@@ -92,34 +94,16 @@ extern void * nmalloca (size_t n, size_t s);
 
 /* ------------------- Auxiliary, non-public definitions ------------------- */
 
-/* Determine the alignment of a type at compile time.  */
-#if defined __GNUC__
-# define sa_alignof __alignof__
-#elif defined __cplusplus
-  template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
-# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
-#elif defined __hpux
-  /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
-     values.  */
-# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
-#elif defined _AIX
-  /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
-     values.  */
-# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
-#else
-# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
-#endif
-
 enum
 {
 /* The desired alignment of memory allocations is the maximum alignment
    among all elementary types.  */
-  sa_alignment_long = sa_alignof (long),
-  sa_alignment_double = sa_alignof (double),
+  sa_alignment_long = alignof (long),
+  sa_alignment_double = alignof (double),
 #if HAVE_LONG_LONG_INT
-  sa_alignment_longlong = sa_alignof (long long),
+  sa_alignment_longlong = alignof (long long),
 #endif
-  sa_alignment_longdouble = sa_alignof (long double),
+  sa_alignment_longdouble = alignof (long double),
   sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
 #if HAVE_LONG_LONG_INT
                      | (sa_alignment_longlong - 1)
index d54bf3061f73354261d61f5a244b9210a0c44d6e..a132c3941d2062eb5e2b7dae5fda040e41955a1a 100644 (file)
@@ -10,6 +10,7 @@ m4/eealloc.m4
 m4/longlong.m4
 
 Depends-on:
+alignof
 alloca-opt
 
 configure.ac: