allow using malloc for memory allocation

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@477 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-05-19 19:04:33 +00:00
parent 008cd709a1
commit 9674c91da6
7 changed files with 196 additions and 46 deletions

View File

@ -12,7 +12,7 @@
* Last rev: *
* mods: *
* comments: allocating space *
* version:$Id: alloc.c,v 1.18 2002-03-12 04:07:09 vsc Exp $ *
* version:$Id: alloc.c,v 1.19 2002-05-19 19:04:33 vsc Exp $ *
*************************************************************************/
#ifdef SCCS
static char SccsId[] = "%W% %G%";
@ -27,6 +27,9 @@ static char SccsId[] = "%W% %G%";
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if HAVE_MEMORY_H
#include <memory.h>
#endif
@ -848,7 +851,12 @@ static int total_space;
MALLOC_T
InitWorkSpace(Int s)
{
MALLOC_T ptr = (MALLOC_T)malloc(MAX_SPACE);
MALLOC_T ptr;
#ifdef M_MMAP_MAX
mallopt(M_MMAP_MAX, 0);
#endif
ptr = (MALLOC_T)malloc(MAX_SPACE);
total_space = s;
if (ptr == ((MALLOC_T) - 1)) {

View File

@ -1129,13 +1129,13 @@ p_floor(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is floor(%s)", IntegerOfTerm(t));
P = (yamop *)FAILCODE;
free(s);
FreeCodeSpace(s);
RERROR();
} else {
Error(TYPE_ERROR_FLOAT, t, "X is floor(t)");
@ -1167,12 +1167,12 @@ p_floor(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is floor(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1225,12 +1225,12 @@ p_ceiling(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is ceiling(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1263,12 +1263,12 @@ p_ceiling(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is ceiling(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1321,12 +1321,12 @@ p_round(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is round(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1359,12 +1359,12 @@ p_round(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s == NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is round(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1417,12 +1417,12 @@ p_truncate(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is truncate(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1455,12 +1455,12 @@ p_truncate(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s == NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is truncate(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1725,12 +1725,12 @@ p_ffracp(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s != NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1763,12 +1763,12 @@ p_ffracp(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s == NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1817,12 +1817,12 @@ p_fintp(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = BigIntOfTerm(t);
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s == NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {
@ -1855,12 +1855,12 @@ p_fintp(Term t E_ARGS)
if (yap_flags[LANGUAGE_MODE_FLAG] == 1) { /* iso */
MP_INT *big = v.big;
Int sz = 2+mpz_sizeinbase(big,10);
char *s = malloc(sz);
char *s = AllocCodeSpace(sz);
if (s == NULL) {
mpz_get_str(s, 10, BigIntOfTerm(t));
Error(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%s)", IntegerOfTerm(t));
free(s);
FreeCodeSpace(s);
P = (yamop *)FAILCODE;
RERROR();
} else {

View File

@ -49,7 +49,7 @@ Int LoadForeign( StringList ofiles, StringList libs,
return LOAD_FAILLED;
}
ofiles->handle = malloc( sizeof(shl_t) );
ofiles->handle = AllocCodeSpace( sizeof(shl_t) );
*(shl_t *)ofiles->handle = shl_load( FileNameBuf, BIND_DEFERRED, 0 );
if( *(shl_t *)ofiles->handle == NULL ) {
strerror_r( errno, LoadMsg, 512 );
@ -110,7 +110,7 @@ void ShutdownLoadForeign( void )
perror( NULL );
return;
}
free( objs->handle );
FreeCodeSpace( objs->handle );
objs = objs->next;
}
@ -122,7 +122,7 @@ void ShutdownLoadForeign( void )
perror( NULL );
return;
}
free( libs->handle );
FreeCodeSpace( libs->handle );
libs = libs->next;
}
f_code = f_code->next;

View File

@ -58,6 +58,7 @@
#undef HAVE_IEEEFP_H
#undef HAVE_IO_H
#undef HAVE_LIMITS_H
#undef HAVE_MALLOC_H
#undef HAVE_MEMORY_H
#undef HAVE_NETDB_H
#undef HAVE_NETINET_IN_H
@ -235,9 +236,10 @@
#define MSHIFTOFFS 1
#define USE_MMAP (HAVE_MMAP)
#define USE_SHM (HAVE_SHMAT & !HAVE_MMAP)
#define USE_SBRK (HAVE_SBRK & !HAVE_MMAP & !HAVE_SHMAT)
#undef USE_MALLOC
#define USE_MMAP (HAVE_MMAP & !USE_MALLOC)
#define USE_SHM (HAVE_SHMAT & !HAVE_MMAP & !USE_MALLOC)
#define USE_SBRK (HAVE_SBRK & !HAVE_MMAP & !HAVE_SHMAT & !USE_MALLOC)
/* for OSes that do not allow user access to the first
quadrant of the memory space */

132
configure vendored
View File

@ -838,6 +838,7 @@ Optional Features:
--enable-debug-yap enable C-debugging for YAP
--enable-cygwin use cygwin library in WIN32
--enable-dynamic-loading compile Yap as a DLL
--enable-use-malloc use malloc to allocate memory
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -2049,6 +2050,13 @@ if test "${enable_dynamic_loading+set}" = set; then
else
dynamic_loading=no
fi;
# Check whether --enable-use_malloc or --disable-use_malloc was given.
if test "${enable_use_malloc+set}" = set; then
enableval="$enable_use_malloc"
use_malloc="$enableval"
else
use_malloc=no
fi;
# Check whether --with-gmp or --without-gmp was given.
@ -4964,8 +4972,122 @@ done
for ac_header in fenv.h fpu_control.h ieeefp.h io.h limits.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
else
# Is the header compilable?
echo "$as_me:$LINENO: checking $ac_header usability" >&5
echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
$ac_includes_default
#include <$ac_header>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_header_compiler=yes
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
ac_header_compiler=no
fi
rm -f conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
echo "${ECHO_T}$ac_header_compiler" >&6
for ac_header in fenv.h fpu_control.h ieeefp.h io.h limits.h memory.h
# Is the header present?
echo "$as_me:$LINENO: checking $ac_header presence" >&5
echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
#include "confdefs.h"
#include <$ac_header>
_ACEOF
if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
(eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
ac_status=$?
egrep -v '^ *\+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_c_preproc_warn_flag
else
ac_cpp_err=
fi
else
ac_cpp_err=yes
fi
if test -z "$ac_cpp_err"; then
ac_header_preproc=yes
else
echo "$as_me: failed program was:" >&5
cat conftest.$ac_ext >&5
ac_header_preproc=no
fi
rm -f conftest.err conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
echo "${ECHO_T}$ac_header_preproc" >&6
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc in
yes:no )
{ echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;};;
no:yes )
{ echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;};;
esac
echo "$as_me:$LINENO: checking for $ac_header" >&5
echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
if eval "test \"\${$as_ac_Header+set}\" = set"; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
eval "$as_ac_Header=$ac_header_preproc"
fi
echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
fi
if test `eval echo '${'$as_ac_Header'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
fi
done
for ac_header in malloc.h memory.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
@ -10685,6 +10807,14 @@ _ACEOF
fi
if test $use_malloc = yes
then
cat >>confdefs.h <<\_ACEOF
#define USE_MALLOC 1
_ACEOF
fi
mkdir -p library/regex
mkdir -p library/system
mkdir -p library/mpi

View File

@ -48,6 +48,9 @@ AC_ARG_ENABLE(cygwin,
AC_ARG_ENABLE(dynamic_loading,
[ --enable-dynamic-loading compile Yap as a DLL ],
dynamic_loading="$enableval", dynamic_loading=no)
AC_ARG_ENABLE(use_malloc,
[ --enable-use-malloc use malloc to allocate memory ],
use_malloc="$enableval", use_malloc=no)
AC_ARG_WITH(gmp,
[ --with-gmp[=DIR] use GNU Multiple Precision in DIR],
@ -567,7 +570,8 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(arpa/inet.h ctype.h direct.h dirent.h dlfcn.h)
AC_CHECK_HEADERS(errno.h fcntl.h)
AC_CHECK_HEADERS(fenv.h fpu_control.h ieeefp.h io.h limits.h memory.h)
AC_CHECK_HEADERS(fenv.h fpu_control.h ieeefp.h io.h limits.h)
AC_CHECK_HEADERS(malloc.h memory.h)
AC_CHECK_HEADERS(netdb.h netinet/in.h regex.h)
AC_CHECK_HEADERS(siginfo.h signal.h stdarg.h string.h stropts.h)
AC_CHECK_HEADERS(sys/conf.h sys/file.h)
@ -835,6 +839,12 @@ else
AC_DEFINE(BROKEN_FFLUSH_NULL,1)
fi
dnl disable smart memory management
if test $use_malloc = yes
then
AC_DEFINE(USE_MALLOC,1)
fi
mkdir -p library/regex
mkdir -p library/system
mkdir -p library/mpi

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 *
* mods: *
* comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.24 2002-03-12 04:07:10 vsc Exp $ *
* version: $Id: Yap.h.m4,v 1.25 2002-05-19 19:04:33 vsc Exp $ *
*************************************************************************/
#include "config.h"
@ -249,11 +249,11 @@ extern char Option[20];
#endif
#endif /* !IN_SECOND_QUADRANT */
#if defined(MMAP_ADDR) && (HAVE_MMAP || HAVE_SHMAT || _WIN32) && !__simplescalar__
#if defined(MMAP_ADDR) && (USE_MMAP || USE_SHMAT || _WIN32) && !__simplescalar__
#define HEAP_INIT_BASE (MMAP_ADDR)
#define AtomBase ((char *)MMAP_ADDR)
#else
#define HEAP_INIT_BASE (HeapBase)
#define HEAP_INIT_BASE ((CELL)HeapBase)
#define AtomBase (HeapBase)
#endif
@ -616,6 +616,15 @@ and RefOfTerm(t) : Term -> DBRef = ...
#define TermSize sizeof(Term)
/************* variables related to memory allocation *******************/
/* must be before TermExt.h */
extern ADDR HeapBase,
LocalBase,
GlobalBase,
TrailBase, TrailTop,
ForeignCodeBase, ForeignCodeTop, ForeignCodeMax;
/* applies to unbound variables */
Destructor(Term, VarOf, Term *, t, t)
#if SBA
@ -660,15 +669,6 @@ Inline(IsIntTerm, int, Term, t, CHKTAG((t), NumberTag))
#endif
/************* variables related to memory allocation *******************/
/* must be before TermExt.h */
extern ADDR HeapBase,
LocalBase,
GlobalBase,
TrailBase, TrailTop,
ForeignCodeBase, ForeignCodeTop, ForeignCodeMax;
/*
There are two types of functors: