~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to sigscheme/m4/ax_check_page_aligned_malloc.m4

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2008-06-25 19:56:33 UTC
  • mfrom: (3.1.18 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080625195633-8jljph4rfq00l8o7
Tags: 1:1.5.1-2
* uim-tcode: provide tutcode-custom.scm, tutcode-bushudic.scm
  and tutcode-rule.scm (Closes: #482659)
* Fix FTBFS: segv during compile (Closes: #483078).
  I personally think this bug is not specific for uim but is a optimization
  problem on gcc-4.3.1. (https://bugs.freedesktop.org/show_bug.cgi?id=16477)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl @synopsis AX_CHECK_PAGE_ALIGNED_MALLOC
 
2
dnl
 
3
dnl Some operating systems (generally, BSD Unix variants) lack a
 
4
dnl posix_memalign function, a memalign function, and a working
 
5
dnl (meaning, the memory can be freed) valloc function. To make up for
 
6
dnl it, the malloc function promises to return page-aligned addresses
 
7
dnl if more than one page's worth of memory is allocated.
 
8
dnl AX_CHECK_PAGE_ALIGNED_MALLOC checks for this condition and defines
 
9
dnl HAVE_PAGE_ALIGNED_MALLOC if the condition holds.
 
10
dnl
 
11
dnl As an aside, note that valloc'd memory cannot safely be freed on
 
12
dnl all operating systems. (Again, some flavors of BSD are the
 
13
dnl troublemakers.) It's best to avoid using valloc in favor of
 
14
dnl posix_memalign, memalign, or an aligned malloc as detected by
 
15
dnl AX_CHECK_PAGE_ALIGNED_MALLOC.
 
16
dnl
 
17
dnl Caveat: AX_CHECK_PAGE_ALIGNED_MALLOC takes a probabalistic
 
18
dnl approach. If 100 calls to malloc all return page-aligned addresses,
 
19
dnl it assumes that all calls will behave likewise. It is therefore
 
20
dnl possible -- albeit extremely unlikely -- that
 
21
dnl AX_CHECK_PAGE_ALIGNED_MALLOC can return a false positive.
 
22
dnl
 
23
dnl @category C
 
24
dnl @author Scott Pakin <pakin@uiuc.edu>
 
25
dnl @version 2005-01-22
 
26
dnl @license AllPermissive
 
27
 
 
28
AC_DEFUN([AX_CHECK_PAGE_ALIGNED_MALLOC],
 
29
[AC_CACHE_CHECK([if large mallocs guarantee page-alignment],
 
30
  [ax_cv_func_malloc_aligned],
 
31
  [AC_TRY_RUN([
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#if HAVE_UNISTD_H
 
35
# include <unistd.h>
 
36
#endif
 
37
 
 
38
int main()
 
39
{
 
40
  int pagesize = getpagesize();
 
41
  int i;
 
42
 
 
43
  for (i=0; i<100; i++)
 
44
    if ((unsigned long)malloc(pagesize+1) & (pagesize-1))
 
45
      exit (1);
 
46
  exit (0);
 
47
}
 
48
              ],
 
49
     [ax_cv_func_malloc_aligned=yes],
 
50
     [ax_cv_func_malloc_aligned=no],
 
51
     [ax_cv_func_malloc_aligned=no])
 
52
  ])
 
53
if test "$ax_cv_func_malloc_aligned" = yes ; then
 
54
  AC_DEFINE([HAVE_PAGE_ALIGNED_MALLOC], [1],
 
55
    [Define if `malloc'ing more than one page always returns a page-aligned address.])
 
56
fi
 
57
])