|
|
|
dnl Copyright (C) 2002-2004, 2006-2007, 2009-2023 Free Software Foundation, |
|
dnl Inc. |
|
dnl This file is free software; the Free Software Foundation |
|
dnl gives unlimited permission to copy and/or distribute it, |
|
dnl with or without modifications, as long as this notice is preserved. |
|
|
|
AC_DEFUN([gl_FUNC_ALLOCA], |
|
[ |
|
AC_REQUIRE([AC_FUNC_ALLOCA]) |
|
if test $ac_cv_func_alloca_works = no; then |
|
gl_PREREQ_ALLOCA |
|
fi |
|
|
|
|
|
if test $ac_cv_working_alloca_h = yes; then |
|
AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [ |
|
AC_EGREP_CPP([Need own alloca], [ |
|
|
|
Need own alloca |
|
|
|
], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no]) |
|
]) |
|
if test $gl_cv_rpl_alloca = yes; then |
|
dnl OK, alloca can be implemented through a compiler built-in. |
|
AC_DEFINE([HAVE_ALLOCA], [1], |
|
[Define to 1 if you have 'alloca' after including <alloca.h>, |
|
a header that may be supplied by this distribution.]) |
|
GL_GENERATE_ALLOCA_H=true |
|
else |
|
dnl alloca exists as a library function, i.e. it is slow and probably |
|
dnl a memory leak. Don't define HAVE_ALLOCA in this case. |
|
GL_GENERATE_ALLOCA_H=false |
|
fi |
|
else |
|
GL_GENERATE_ALLOCA_H=true |
|
fi |
|
|
|
if test $ac_cv_working_alloca_h = yes; then |
|
HAVE_ALLOCA_H=1 |
|
else |
|
HAVE_ALLOCA_H=0 |
|
fi |
|
AC_SUBST([HAVE_ALLOCA_H]) |
|
]) |
|
|
|
|
|
|
|
AC_DEFUN([gl_PREREQ_ALLOCA], [:]) |
|
|
|
m4_version_prereq([2.70], [], [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m4_define([_AC_LIBOBJ_ALLOCA], |
|
[ |
|
|
|
|
|
|
|
AC_LIBSOURCES(alloca.c) |
|
AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl |
|
AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.]) |
|
|
|
AC_CACHE_CHECK([stack direction for C alloca], |
|
[ac_cv_c_stack_direction], |
|
[AC_RUN_IFELSE([AC_LANG_SOURCE( |
|
[AC_INCLUDES_DEFAULT |
|
int |
|
find_stack_direction (int *addr, int depth) |
|
{ |
|
int dir, dummy = 0; |
|
if (! addr) |
|
addr = &dummy; |
|
*addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; |
|
dir = depth ? find_stack_direction (addr, depth - 1) : 0; |
|
return dir + dummy; |
|
} |
|
|
|
int |
|
main (int argc, char **argv) |
|
{ |
|
return find_stack_direction (0, argc + !argv + 20) < 0; |
|
}])], |
|
[ac_cv_c_stack_direction=1], |
|
[ac_cv_c_stack_direction=-1], |
|
[ac_cv_c_stack_direction=0])]) |
|
AH_VERBATIM([STACK_DIRECTION], |
|
[/* If using the C implementation of alloca, define if you know the |
|
direction of stack growth for your system; otherwise it will be |
|
automatically deduced at runtime. |
|
STACK_DIRECTION > 0 => grows toward higher addresses |
|
STACK_DIRECTION < 0 => grows toward lower addresses |
|
STACK_DIRECTION = 0 => direction of growth unknown */ |
|
|
|
AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) |
|
]) |
|
]) |
|
|