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:
12
C/alloc.c
12
C/alloc.c
@@ -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)) {
|
||||
|
48
C/arith1.c
48
C/arith1.c
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user