mirror of
https://github.com/postgres/postgres.git
synced 2025-12-04 12:02:48 +03:00
Revise memutils.h to use alignment information gathered by
configure, instead of having a bunch of crufty platform-specific guesses.
This commit is contained in:
@@ -896,6 +896,70 @@ fi
|
||||
AC_DEFINE_UNQUOTED(INT64_FORMAT, $INT64_FORMAT)
|
||||
|
||||
|
||||
dnl Determine memory alignment requirements for the basic C datatypes.
|
||||
|
||||
dnl CHECK_ALIGNOF(TYPE)
|
||||
dnl This is modeled on the standard autoconf macro AC_CHECK_SIZEOF,
|
||||
dnl except it finds the alignment requirement of the type instead of the size.
|
||||
dnl The defined symbol is named ALIGNOF_TYPE, where the type name is
|
||||
dnl converted in the same way as for AC_CHECK_SIZEOF.
|
||||
dnl If cross-compiling, sizeof(type) is used as a default assumption.
|
||||
|
||||
AC_DEFUN(CHECK_ALIGNOF,
|
||||
[changequote(<<, >>)dnl
|
||||
dnl The name to #define.
|
||||
define(<<AC_TYPE_NAME>>, translit(alignof_$1, [a-z *], [A-Z_P]))dnl
|
||||
dnl The cache variable name.
|
||||
define(<<AC_CV_NAME>>, translit(ac_cv_alignof_$1, [ *], [_p]))dnl
|
||||
changequote([, ])dnl
|
||||
AC_MSG_CHECKING(alignment of $1)
|
||||
AC_CACHE_VAL(AC_CV_NAME,
|
||||
[AC_TRY_RUN([#include <stdio.h>
|
||||
struct { char filler; $1 field; } mystruct;
|
||||
main()
|
||||
{
|
||||
FILE *f=fopen("conftestval", "w");
|
||||
if (!f) exit(1);
|
||||
fprintf(f, "%d\n", ((char*) & mystruct.field) - ((char*) & mystruct));
|
||||
exit(0);
|
||||
}], AC_CV_NAME=`cat conftestval`,
|
||||
AC_CV_NAME='sizeof($1)',
|
||||
AC_CV_NAME='sizeof($1)')])dnl
|
||||
AC_MSG_RESULT($AC_CV_NAME)
|
||||
AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME)
|
||||
undefine([AC_TYPE_NAME])dnl
|
||||
undefine([AC_CV_NAME])dnl
|
||||
])
|
||||
|
||||
CHECK_ALIGNOF(short)
|
||||
CHECK_ALIGNOF(int)
|
||||
CHECK_ALIGNOF(long)
|
||||
if [[ $HAVE_LONG_LONG_INT_64 -eq 1 ]] ; then
|
||||
CHECK_ALIGNOF(long long int)
|
||||
fi
|
||||
CHECK_ALIGNOF(double)
|
||||
|
||||
dnl Compute maximum alignment of any basic type.
|
||||
dnl We assume long's alignment is at least as strong as char, short, or int;
|
||||
dnl but we must check long long (if it exists) and double.
|
||||
|
||||
if [[ $ac_cv_alignof_double != 'sizeof(double)' ]] ; then
|
||||
MAX_ALIGNOF="$ac_cv_alignof_long"
|
||||
if [[ $MAX_ALIGNOF -lt $ac_cv_alignof_double ]] ; then
|
||||
MAX_ALIGNOF="$ac_cv_alignof_double"
|
||||
fi
|
||||
if [[ $HAVE_LONG_LONG_INT_64 -eq 1 ]] ; then
|
||||
if [[ $MAX_ALIGNOF -lt $ac_cv_alignof_long_long_int ]] ; then
|
||||
MAX_ALIGNOF="$ac_cv_alignof_long_long_int"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
dnl cross-compiling: assume that double's alignment is worst case
|
||||
MAX_ALIGNOF="$ac_cv_alignof_double"
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF)
|
||||
|
||||
|
||||
dnl Check to see if platform has POSIX signal interface.
|
||||
dnl NOTE: if this test fails then POSIX signals definitely don't work.
|
||||
dnl It could be that the test compiles but the POSIX routines don't
|
||||
|
||||
Reference in New Issue
Block a user