fix realloc and friends (obs from Nuno Fonseca).
This commit is contained in:
parent
d746afaa32
commit
b16623d026
24
C/alloc.c
24
C/alloc.c
@ -64,9 +64,11 @@ static char SccsId[] = "%W% %G%";
|
||||
#if USE_SYSTEM_MALLOC
|
||||
#define my_malloc(sz) malloc(sz)
|
||||
#define my_realloc(ptr, sz, osz, safe) realloc(ptr, sz)
|
||||
#define my_realloc0(ptr, sz) realloc0(ptr, sz)
|
||||
#define my_free(ptr) free(ptr)
|
||||
#else
|
||||
#define my_malloc(sz) Yap_dlmalloc(sz)
|
||||
#define my_realloc0(ptr, sz) Yap_dlrealloc(ptr, sz)
|
||||
#define my_free(sz) Yap_dlfree(sz)
|
||||
|
||||
static char * my_realloc(char *ptr, UInt sz, UInt osz, int safe)
|
||||
@ -152,6 +154,28 @@ Yap_AllocCodeSpace(unsigned long int size)
|
||||
return call_malloc(size);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
call_realloc(char *p, unsigned long int size)
|
||||
{
|
||||
char *out;
|
||||
#if INSTRUMENT_MALLOC
|
||||
if (mallocs % 1024*4 == 0)
|
||||
minfo('A');
|
||||
mallocs++;
|
||||
tmalloc += size;
|
||||
#endif
|
||||
Yap_PrologMode |= MallocMode;
|
||||
out = (char *) my_realloc0(p, size);
|
||||
Yap_PrologMode &= ~MallocMode;
|
||||
return out;
|
||||
}
|
||||
|
||||
char *
|
||||
Yap_ReallocCodeSpace(char *p, unsigned long int size)
|
||||
{
|
||||
return call_realloc(p, size);
|
||||
}
|
||||
|
||||
void
|
||||
Yap_FreeCodeSpace(char *p)
|
||||
{
|
||||
|
@ -1304,7 +1304,7 @@ X_API void *
|
||||
YAP_ReallocSpaceFromYap(void *ptr,unsigned int size) {
|
||||
void *new_ptr;
|
||||
BACKUP_MACHINE_REGS();
|
||||
while ((new_ptr = Yap_ExpandPreAllocCodeSpace(size,ptr,TRUE)) == NULL) {
|
||||
while ((new_ptr = Yap_ReallocCodeSpace(size,ptr)) == NULL) {
|
||||
if (!Yap_growheap(FALSE, size, NULL)) {
|
||||
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return NULL;
|
||||
@ -1325,7 +1325,6 @@ YAP_AllocSpaceFromYap(unsigned int size)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
RECOVER_MACHINE_REGS();
|
||||
return ptr;
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
fprintf(Yap_stderr,"%lld %p ", vsc_count, TR);
|
||||
fprintf(Yap_stderr,"%lld ",vsc_count);
|
||||
#if defined(THREADS) || defined(YAPOR)
|
||||
fprintf(Yap_stderr,"(%d)", worker_id);
|
||||
#endif
|
||||
|
@ -91,6 +91,7 @@ void STD_PROTO(Yap_init_agc, (void));
|
||||
void STD_PROTO(Yap_FreeCodeSpace,(char *));
|
||||
char *STD_PROTO(Yap_AllocAtomSpace,(unsigned long int));
|
||||
char *STD_PROTO(Yap_AllocCodeSpace,(unsigned long int));
|
||||
char *STD_PROTO(Yap_ReallocCodeSpace,(char *,unsigned long int));
|
||||
ADDR STD_PROTO(Yap_AllocFromForeignArea,(Int));
|
||||
int STD_PROTO(Yap_ExtendWorkSpace,(Int));
|
||||
void STD_PROTO(Yap_FreeAtomSpace,(char *));
|
||||
|
@ -2204,19 +2204,19 @@ PL_set_engine(PL_engine_t engine, PL_engine_t *old)
|
||||
X_API void *
|
||||
PL_malloc(int sz)
|
||||
{
|
||||
return YAP_AllocSpaceFromYap(sz);
|
||||
return (void *)Yap_AllocCodeSpace((long unsigned int)sz);
|
||||
}
|
||||
|
||||
X_API void *
|
||||
PL_realloc(void *ptr, int sz)
|
||||
{
|
||||
return YAP_ReallocSpaceFromYap(ptr,sz);
|
||||
return Yap_ReallocCodeSpace((char *)ptr,(long unsigned int)sz);
|
||||
}
|
||||
|
||||
X_API void
|
||||
PL_free(void *obj)
|
||||
{
|
||||
return YAP_FreeSpaceFromYap(obj);
|
||||
return Yap_FreeCodeSpace((char *)obj);
|
||||
}
|
||||
|
||||
X_API int
|
||||
|
Reference in New Issue
Block a user