[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Checking alignment of data types
From: |
Paul Eggert |
Subject: |
Re: Checking alignment of data types |
Date: |
15 Mar 2004 14:00:53 -0800 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
OK, I installed the following patch to implement AC_CHECK_ALIGNOF.
2004-03-15 Paul Eggert <address@hidden>
* NEWS: New macro AC_CHECK_ALIGNOF.
* doc/autoconf.texi (Generic Compiler Characteristics): Document it.
* lib/autoconf/types.m4 (AC_CHECK_SIZEOF): Use long int rather than int;
avoid "a `$1'" since this isn't grammatical if $1 begins with a vowel.
(AC_CHECK_ALIGNOF): New macro.
* tests/mktests.sh (ac_exclude_list): Exclude AC_CHECK_ALIGNOF.
* tests/semantics.at (AC_CHECK_ALIGNOF): Add tests similar to
those for sizeof.
Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.325
diff -p -u -r1.325 NEWS
--- NEWS 27 Jan 2004 20:07:12 -0000 1.325
+++ NEWS 15 Mar 2004 21:56:17 -0000
@@ -1,3 +1,8 @@
+* Major changes in Autoconf 2.59b
+
+** AC_CHECK_ALIGNOF
+ New macro that computes the default alignment of a type.
+
* Major changes in Autoconf 2.59a
** AC_PROG_GREP
@@ -1176,8 +1181,8 @@ Various bug fixes.
-----
-Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003
-Free Software Foundation, Inc.
+Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
+2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Autoconf.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.802
diff -p -u -r1.802 autoconf.texi
--- doc/autoconf.texi 19 Feb 2004 23:21:41 -0000 1.802
+++ doc/autoconf.texi 15 Mar 2004 21:56:37 -0000
@@ -5310,6 +5310,16 @@ AC_CHECK_SIZEOF(int *)
defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
@end defmac
address@hidden AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, default-includes})
address@hidden
+Define @address@hidden (@pxref{Standard Symbols}) to be the
+alignment in bytes of @var{type}. If @samp{type} is unknown, it gets a size
+of 0. If no @var{includes} are specified, the default includes are used
+(@pxref{Default Includes}). If you provide @var{include}, be sure to
+include @file{stddef.h} and @file{stdio.h} which are required for this
+macro to work correctly.
address@hidden defmac
+
@defmac AC_LANG_WERROR
@acindex{LANG_WERROR}
Normally Autoconf ignores warnings generated by the compiler, linker, and
Index: lib/autoconf/types.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/types.m4,v
retrieving revision 1.25
diff -p -u -r1.25 types.m4
--- lib/autoconf/types.m4 30 Jan 2004 14:21:36 -0000 1.25
+++ lib/autoconf/types.m4 15 Mar 2004 21:56:38 -0000
@@ -389,11 +389,11 @@ AC_DEFUN([AC_CHECK_SIZEOF],
AC_CHECK_TYPE([$1], [], [], [$3])
AC_CACHE_CHECK([size of $1], AS_TR_SH([ac_cv_sizeof_$1]),
[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
- # The cast to unsigned long works around a bug in the HP C Compiler
+ # The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
# This bug is HP SR number 8606223364.
- _AC_COMPUTE_INT([(long) (sizeof ($1))],
+ _AC_COMPUTE_INT([(long int) (sizeof ($1))],
[AS_TR_SH([ac_cv_sizeof_$1])],
[AC_INCLUDES_DEFAULT([$3])],
[AC_MSG_FAILURE([cannot compute sizeof ($1), 77])])
@@ -401,14 +401,32 @@ else
AS_TR_SH([ac_cv_sizeof_$1])=0
fi])dnl
AC_DEFINE_UNQUOTED(AS_TR_CPP(sizeof_$1), $AS_TR_SH([ac_cv_sizeof_$1]),
- [The size of a `$1', as computed by sizeof.])
+ [The size of `$1', as computed by sizeof.])
])# AC_CHECK_SIZEOF
+# AC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
+# -----------------------------------------------------
+AC_DEFUN([AC_CHECK_ALIGNOF],
+[AS_LITERAL_IF([$1], [],
+ [AC_FATAL([$0: requires literal arguments])])dnl
+AC_CHECK_TYPE([$1], [], [], [$2])
+AC_CACHE_CHECK([alignment of $1], AS_TR_SH([ac_cv_alignof_$1]),
+[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
+ _AC_COMPUTE_INT([offsetof (struct { char x; $1 y; }, y)],
+ [AS_TR_SH([ac_cv_alignof_$1])],
+ [AC_INCLUDES_DEFAULT([$2])
+#ifndef offsetof
+# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
+#endif],
+ [AC_MSG_FAILURE([cannot compute alignment of ($1), 77])])
+else
+ AS_TR_SH([ac_cv_alignof_$1])=0
+fi])dnl
+AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1), $AS_TR_SH([ac_cv_alignof_$1]),
+ [The normal alignment of `$1', in bytes.])
+])# AC_CHECK_ALIGNOF
-# ---------------- #
-# Generic checks. #
-# ---------------- #
# AU::AC_INT_16_BITS
# ------------------
Index: tests/mktests.sh
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/mktests.sh,v
retrieving revision 1.38
diff -p -u -r1.38 mktests.sh
--- tests/mktests.sh 26 Jan 2004 23:23:32 -0000 1.38
+++ tests/mktests.sh 15 Mar 2004 21:56:38 -0000
@@ -82,7 +82,7 @@ exclude_list='^ac_cv_prog_(gcc|gxx|g77)$
# - AC_CANONICALIZE, AC_PREFIX_PROGRAM, AC_PREREQ
# Need an argument.
#
-# - AC_CHECK decl, file, func, header, lib, member, prog, sizeof, type
+# - AC_CHECK alignof, decl, file, func, header, lib, member, prog, sizeof, type
# Performed in the semantics tests.
#
# - AC_CONFIG
@@ -131,7 +131,7 @@ exclude_list='^ac_cv_prog_(gcc|gxx|g77)$
#
ac_exclude_list='^AC_ARG_VAR$
^AC_CANONICALIZE|AC_PREFIX_PROGRAM|AC_PREREQ$
-^AC_CHECK_(DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|TOOL|TYPE)S?$
+^AC_CHECK_(ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|TOOL|TYPE)S?$
^AC_CONFIG
^AC_(F77|FC)_FUNC$
^AC_FC_(FUNC|FREEFORM|SRCEXT)$
Index: tests/semantics.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/semantics.at,v
retrieving revision 1.43
diff -p -u -r1.43 semantics.at
--- tests/semantics.at 22 May 2003 13:24:08 -0000 1.43
+++ tests/semantics.at 15 Mar 2004 21:56:38 -0000
@@ -2,7 +2,7 @@
AT_BANNER([Semantics.])
-# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2002, 2004 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
@@ -236,6 +236,43 @@ AT_CHECK_MACRO([AC_CHECK_MEMBERS],
[AT_CHECK_DEFINES(
[/* #undef HAVE_STRUCT_YES_S_NO */
#define HAVE_STRUCT_YES_S_YES 1
+])])
+
+
+# AC_CHECK_ALIGNOF
+# ----------------
+# Not cross-compiling.
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
+[[AC_CHECK_ALIGNOF(char)
+AC_CHECK_ALIGNOF(charchar,
+[[#include <stddef.h>
+#include <stdio.h>
+typedef char charchar[2];]])
+AC_CHECK_ALIGNOF(charcharchar)
+]],
+[AT_CHECK_DEFINES(
+[#define ALIGNOF_CHAR 1
+#define ALIGNOF_CHARCHAR 1
+#define ALIGNOF_CHARCHARCHAR 0
+])])
+
+
+# AC_CHECK_ALIGNOF
+# ----------------
+AT_CHECK_MACRO([AC_CHECK_ALIGNOF],
+[[# Exercise the code used when cross-compiling
+cross_compiling=yes
+AC_CHECK_ALIGNOF(char)
+AC_CHECK_ALIGNOF(charchar,
+[[#include <stddef.h>
+#include <stdio.h>
+typedef char charchar[2];]])
+AC_CHECK_ALIGNOF(charcharchar)
+]],
+[AT_CHECK_DEFINES(
+[#define ALIGNOF_CHAR 1
+#define ALIGNOF_CHARCHAR 1
+#define ALIGNOF_CHARCHARCHAR 0
])])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Checking alignment of data types,
Paul Eggert <=