summaryrefslogtreecommitdiff
path: root/gl
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2009-06-03 12:38:03 +0200
committerSimon Josefsson <simon@josefsson.org>2009-06-03 12:38:03 +0200
commit44370b5c7a42fd97005ac7f143ddebf6d4da8284 (patch)
treedfeabb5dbeaf6a7031c75d5cc260319b15bc8413 /gl
parentdd14a82a9c31d173a4c5aeb17be06755cbf183da (diff)
downloadgnutls-44370b5c7a42fd97005ac7f143ddebf6d4da8284.tar.gz
Update gnulib files.
Diffstat (limited to 'gl')
-rw-r--r--gl/Makefile.am2
-rw-r--r--gl/alignof.h32
-rw-r--r--gl/m4/gnulib-cache.m44
-rw-r--r--gl/m4/gnulib-comp.m41
-rw-r--r--gl/tests/Makefile.am9
-rw-r--r--gl/tests/test-alignof.c57
6 files changed, 96 insertions, 9 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index e04d7f4540..c6c10ea680 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -9,7 +9,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --libtool --macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax perror pmccabe2html progname read-file readline recv select send setsockopt shutdown socket sockets sys_stat version-etc-fsf warnings
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --libtool --macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax perror pmccabe2html progname read-file readline recv select send setsockopt shutdown socket sockets sys_stat version-etc-fsf warnings
AUTOMAKE_OPTIONS = 1.5 gnits
diff --git a/gl/alignof.h b/gl/alignof.h
index 896382b0f2..0d2099cfd3 100644
--- a/gl/alignof.h
+++ b/gl/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/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index a55309bd7f..628c187630 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --libtool --macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax perror pmccabe2html progname read-file readline recv select send setsockopt shutdown socket sockets sys_stat version-etc-fsf warnings
+# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --libtool --macro-prefix=gl --no-vc-files accept arpa_inet autobuild bind close connect error fdl-1.3 gendocs getaddrinfo getline getpass-gnu gnupload gpl-3.0 inet_ntop inet_pton lgpl-2.1 listen maintainer-makefile manywarnings minmax perror pmccabe2html progname read-file readline recv select send setsockopt shutdown socket sockets sys_stat version-etc-fsf warnings
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gl/override])
@@ -57,7 +57,7 @@ gl_MODULES([
version-etc-fsf
warnings
])
-gl_AVOID([alignof-tests])
+gl_AVOID([])
gl_SOURCE_BASE([gl])
gl_M4_BASE([gl/m4])
gl_PO_BASE([])
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index df5963f79d..42ad7b2500 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -485,6 +485,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/wchar_t.m4
m4/wint_t.m4
m4/xsize.m4
+ tests/test-alignof.c
tests/test-alloca-opt.c
tests/test-arpa_inet.c
tests/test-c-ctype.c
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index 421303a3a8..a37a580ca7 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -42,6 +42,15 @@ libtests_a_DEPENDENCIES = $(gltests_LIBOBJS)
EXTRA_libtests_a_SOURCES =
AM_LIBTOOLFLAGS = --preserve-dup-deps
+## begin gnulib module alignof-tests
+
+TESTS += test-alignof
+check_PROGRAMS += test-alignof
+
+EXTRA_DIST += test-alignof.c
+
+## end gnulib module alignof-tests
+
## begin gnulib module alloca-opt-tests
TESTS += test-alloca-opt
diff --git a/gl/tests/test-alignof.c b/gl/tests/test-alignof.c
new file mode 100644
index 0000000000..93d5dedc21
--- /dev/null
+++ b/gl/tests/test-alignof.c
@@ -0,0 +1,57 @@
+/* Test of <alignof.h>.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2009. */
+
+#include <config.h>
+
+#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;
+typedef struct { char a[4]; } struct4;
+
+#define CHECK(type) \
+ typedef struct { char slot1; type slot2; } type##_helper; \
+ 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)
+CHECK (int)
+CHECK (long)
+CHECK (float)
+CHECK (double)
+CHECK (long double)
+CHECK (int64_t)
+CHECK (struct1)
+CHECK (struct2)
+CHECK (struct3)
+CHECK (struct4)
+
+int
+main ()
+{
+ return 0;
+}