[uim-commit] r2933 - in branches/r5rs/sigscheme: . m4 src
yamaken at freedesktop.org
yamaken at freedesktop.org
Tue Jan 17 14:14:52 PST 2006
Author: yamaken
Date: 2006-01-17 14:14:43 -0800 (Tue, 17 Jan 2006)
New Revision: 2933
Added:
branches/r5rs/sigscheme/m4/
branches/r5rs/sigscheme/m4/Makefile.am
branches/r5rs/sigscheme/m4/ax_check_page_aligned_malloc.m4
Modified:
branches/r5rs/sigscheme/Makefile.am
branches/r5rs/sigscheme/autogen.sh
branches/r5rs/sigscheme/configure.in
branches/r5rs/sigscheme/src/alloc.c
Log:
* sigscheme/autogen.sh
- Add '-I m4' to aclocal
* sigscheme/Makefile.am
- (SUBDIRS): Add m4
* sigscheme/m4/Makefile.am
- New file
- (EXTRA_DIST):
* New variable
* Add ax_check_page_aligned_malloc.m4
* sigscheme/m4/ax_check_page_aligned_malloc.m4
- New file from the autoconf macro archive
* sigscheme/configure.in
- Add check for unistd.h and getpagesize
- Add AX_CHECK_PAGE_ALIGNED_MALLOC
- Add m4/Makefile to AC_CONFIG_FILES
* sigscheme/src/alloc.c
- Include config.h
- Include unistd.h if HAVE_GETPAGESIZE
- (scm_malloc_aligned): Add size check for page-aligned malloc(3)
Modified: branches/r5rs/sigscheme/Makefile.am
===================================================================
--- branches/r5rs/sigscheme/Makefile.am 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/Makefile.am 2006-01-17 22:14:43 UTC (rev 2933)
@@ -1 +1 @@
-SUBDIRS = src
+SUBDIRS = m4 src
Modified: branches/r5rs/sigscheme/autogen.sh
===================================================================
--- branches/r5rs/sigscheme/autogen.sh 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/autogen.sh 2006-01-17 22:14:43 UTC (rev 2933)
@@ -2,7 +2,7 @@
# Notice: Automake 1.8.3 or later is required.
-aclocal \
+aclocal -I m4 \
&& libtoolize --force --copy \
&& autoheader \
&& automake --add-missing --foreign --copy \
Modified: branches/r5rs/sigscheme/configure.in
===================================================================
--- branches/r5rs/sigscheme/configure.in 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/configure.in 2006-01-17 22:14:43 UTC (rev 2933)
@@ -18,7 +18,8 @@
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([limits.h malloc.h stddef.h stdint.h stdlib.h string.h])
+AC_CHECK_HEADERS([limits.h malloc.h stddef.h stdint.h stdlib.h string.h \
+ unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@@ -38,7 +39,6 @@
#AC_CHECK_SIZEOF(double)
#AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(void *)
-
AC_CHECK_SIZEOF(size_t)
# Do not assume (sizeof(int32_t) == 4) and so on (i.e. do not (CHAR_BIT == 8)).
@@ -60,8 +60,10 @@
# FIXME: provide alternative source code
# AC_REPLACE_FUNCS([asprintf vasprintf])
-AC_CHECK_FUNCS([fileno asprintf vasprintf posix_memalign])
+AC_CHECK_FUNCS([fileno asprintf vasprintf posix_memalign getpagesize])
+AX_CHECK_PAGE_ALIGNED_MALLOC
+
# Configure Option
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug],
@@ -82,5 +84,6 @@
fi
AC_CONFIG_FILES([Makefile
+ m4/Makefile
src/Makefile])
AC_OUTPUT
Added: branches/r5rs/sigscheme/m4/Makefile.am
===================================================================
--- branches/r5rs/sigscheme/m4/Makefile.am 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/m4/Makefile.am 2006-01-17 22:14:43 UTC (rev 2933)
@@ -0,0 +1 @@
+EXTRA_DIST = ax_check_page_aligned_malloc.m4
Added: branches/r5rs/sigscheme/m4/ax_check_page_aligned_malloc.m4
===================================================================
--- branches/r5rs/sigscheme/m4/ax_check_page_aligned_malloc.m4 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/m4/ax_check_page_aligned_malloc.m4 2006-01-17 22:14:43 UTC (rev 2933)
@@ -0,0 +1,57 @@
+dnl @synopsis AX_CHECK_PAGE_ALIGNED_MALLOC
+dnl
+dnl Some operating systems (generally, BSD Unix variants) lack a
+dnl posix_memalign function, a memalign function, and a working
+dnl (meaning, the memory can be freed) valloc function. To make up for
+dnl it, the malloc function promises to return page-aligned addresses
+dnl if more than one page's worth of memory is allocated.
+dnl AX_CHECK_PAGE_ALIGNED_MALLOC checks for this condition and defines
+dnl HAVE_PAGE_ALIGNED_MALLOC if the condition holds.
+dnl
+dnl As an aside, note that valloc'd memory cannot safely be freed on
+dnl all operating systems. (Again, some flavors of BSD are the
+dnl troublemakers.) It's best to avoid using valloc in favor of
+dnl posix_memalign, memalign, or an aligned malloc as detected by
+dnl AX_CHECK_PAGE_ALIGNED_MALLOC.
+dnl
+dnl Caveat: AX_CHECK_PAGE_ALIGNED_MALLOC takes a probabalistic
+dnl approach. If 100 calls to malloc all return page-aligned addresses,
+dnl it assumes that all calls will behave likewise. It is therefore
+dnl possible -- albeit extremely unlikely -- that
+dnl AX_CHECK_PAGE_ALIGNED_MALLOC can return a false positive.
+dnl
+dnl @category C
+dnl @author Scott Pakin <pakin at uiuc.edu>
+dnl @version 2005-01-22
+dnl @license AllPermissive
+
+AC_DEFUN([AX_CHECK_PAGE_ALIGNED_MALLOC],
+[AC_CACHE_CHECK([if large mallocs guarantee page-alignment],
+ [ax_cv_func_malloc_aligned],
+ [AC_TRY_RUN([
+#include <stdio.h>
+#include <stdlib.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+int main()
+{
+ int pagesize = getpagesize();
+ int i;
+
+ for (i=0; i<100; i++)
+ if ((unsigned long)malloc(pagesize+1) & (pagesize-1))
+ exit (1);
+ exit (0);
+}
+ ],
+ [ax_cv_func_malloc_aligned=yes],
+ [ax_cv_func_malloc_aligned=no],
+ [ax_cv_func_malloc_aligned=no])
+ ])
+if test "$ax_cv_func_malloc_aligned" = yes ; then
+ AC_DEFINE([HAVE_PAGE_ALIGNED_MALLOC], [1],
+ [Define if `malloc'ing more than one page always returns a page-aligned address.])
+fi
+])
Modified: branches/r5rs/sigscheme/src/alloc.c
===================================================================
--- branches/r5rs/sigscheme/src/alloc.c 2006-01-17 17:49:23 UTC (rev 2932)
+++ branches/r5rs/sigscheme/src/alloc.c 2006-01-17 22:14:43 UTC (rev 2933)
@@ -32,15 +32,18 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===========================================================================*/
+#include "config.h"
+
/*=======================================
System Include
=======================================*/
#include <stdint.h> /* FIXME: make C99-independent */
#include <stdlib.h>
#include <string.h>
+#if HAVE_GETPAGESIZE
+#include <unistd.h>
+#endif
-#include <assert.h>
-
/*=======================================
Local Include
=======================================*/
@@ -84,8 +87,13 @@
* BSD 4.4. The function posix_memalign() comes from POSIX 1003.1d.
*/
posix_memalign(&p, ALIGN_CELL, size);
+#elif (HAVE_PAGE_ALIGNED_MALLOC && HAVE_GETPAGESIZE)
+ if ((size_t)getpagesize() <= size || size <= sizeof(void *))
+ p = scm_malloc(size);
+ else
+ ERR("cannot ensure memory alignment");
#else
- p = scm_malloc(size);
+#error "This platform is not supported yet"
#endif
SCM_ENSURE_ALLOCATED(p);
/* heaps must be aligned to sizeof(ScmCell) */
More information about the uim-commit
mailing list