beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / m4 / ax_check_aligned_access_required.m4
blob3f0872679bc2c6f2f0055dbb5b0b49cf289bcf31
1 dnl @synopsis AX_CHECK_ALIGNED_ACCESS_REQUIRED
2 dnl
3 dnl Copyright (C) 2006, 2009 Guido U. Draheim <guidod@gmx.de>
4 dnl Copyright (C) 2010 Peter Breitenlohner <tex-live@tug.org>
5 dnl
6 dnl This file is free software; the copyright holders
7 dnl give unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
9 dnl
10 dnl While the x86 CPUs allow access to memory objects to be unaligned
11 dnl it happens that most of the modern designs require objects to be
12 dnl aligned - or they will fail with a buserror. That mode is quite known
13 dnl by big-endian machines (sparc, etc) however the alpha cpu is little-
14 dnl endian.
15 dnl
16 dnl The following function will test for aligned access to be required and
17 dnl set a config.h define HAVE_ALIGNED_ACCESS_REQUIRED (name derived by
18 dnl standard usage). Structures loaded from a file (or mmapped to memory)
19 dnl should be accessed per-byte in that case to avoid segfault type errors.
20 dnl
21 dnl @category C
22 dnl @author Guido U. Draheim <guidod@gmx.de>
23 dnl @author Peter Breitenlohner <tex-live@tug.org>
24 dnl @version 2010-02-01
25 dnl @license GPLWithACException
26 dnl @license BSD
28 AC_DEFUN([AX_CHECK_ALIGNED_ACCESS_REQUIRED],
29 [AC_CACHE_CHECK([if pointers to integers require aligned access],
30   [ax_cv_have_aligned_access_required],
31 [if test "$cross_compiling" = "yes"; then
32   case "$host_cpu" in alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
33     ax_cv_have_aligned_access_required="yes"
34   ;; esac
35 else
36   AC_TRY_RUN([
37 #include <stdio.h>
38 #include <stdlib.h>
40 int main()
42   char* string = malloc(40);
43   int i;
44   for (i=0; i < 40; i++) string[[i]] = i;
45   {
46      void* s = string;
47      int* p = s+1;
48      int* q = s+2;
50      if (*p == *q) { return 1; }
51   }
52   return 0;
54               ],
55      [ax_cv_have_aligned_access_required=yes],
56      [ax_cv_have_aligned_access_required=no],
57      [ax_cv_have_aligned_access_required=no])
58   ])
60 if test "$ax_cv_have_aligned_access_required" = yes ; then
61   AC_DEFINE([HAVE_ALIGNED_ACCESS_REQUIRED], [1],
62     [Define if pointers to integers require aligned access])