more exo stuff.

This commit is contained in:
Vitor Santos Costa 2013-05-01 11:34:55 -05:00
parent 923be33404
commit 34bf9bb311
2 changed files with 14 additions and 13 deletions

21
C/exo.c
View File

@ -222,7 +222,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
UInt ncls = ap->cs.p_code.NOfClauses, j;
CELL *base = NULL;
struct index_t *i;
size_t sz;
size_t sz, dsz;
yamop *ptr;
UInt *bnds = LOCAL_ibnds;
@ -244,21 +244,22 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
i->bmap = bmap;
i->is_key = FALSE;
i->hsize = 2*ncls;
dsz = sizeof(BITS32)*(ncls+i->hsize);
if (count) {
if (!(base = (CELL *)Yap_AllocCodeSpace(sizeof(BITS32)*(ncls+i->hsize)))) {
if (!(base = (CELL *)Yap_AllocCodeSpace(dsz))) {
CACHE_REGS
save_machine_regs();
LOCAL_Error_Size = sizeof(CELL)*(ncls+i->hsize);
LOCAL_Error_Size = dsz;
LOCAL_ErrorMessage = "not enough space to generate indices";
Yap_FreeCodeSpace((void *)i);
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, LOCAL_ErrorMessage);
return NULL;
}
bzero(base, sizeof(CELL)*(ncls+i->hsize));
bzero(base, dsz);
}
i->size = sizeof(CELL)*(ncls+i->hsize)+sz+sizeof(struct index_t);
i->key = (CELL *)base;
i->links = (CELL *)(base+i->hsize);
i->size = sz+dsz+sizeof(struct index_t);
i->key = (BITS32 *)base;
i->links = (BITS32 *)(base+i->hsize);
i->ncollisions = i->nentries = i->ntrys = 0;
i->cls = (CELL *)((ADDR)ap->cs.p_code.FirstClause+2*sizeof(struct index_t *));
*ip = i;
@ -271,7 +272,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
} else {
sz = (ncls+i->hsize)*sizeof(BITS32);
}
if (base != realloc(base, sz))
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
return FALSE;
bzero(base, sz);
i->key = (CELL *)base;
@ -284,7 +285,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
#endif
if (!i->ntrys && !i->is_key) {
i->is_key = TRUE;
if (base != realloc(base, i->hsize*sizeof(BITS32)))
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, i->hsize*sizeof(BITS32)))
return FALSE;
}
/* our hash table is just too large */
@ -296,7 +297,7 @@ add_index(struct index_t **ip, UInt bmap, PredEntry *ap, UInt count)
} else {
sz = (ncls+i->hsize)*sizeof(BITS32);
}
if (base != realloc(base, sz))
if (base != (CELL *)Yap_ReallocCodeSpace((char *)base, sz))
return FALSE;
bzero(base, sz);
i->key = (CELL *)base;

View File

@ -79,7 +79,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
/* handle ll variables */
sz = sizeof(BITS32)*(ncls);
/* allocate space */
if (!(it->udi_data = malloc(sz)))
if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
return;
sorted = (BITS32*)it->udi_data;
for (i=0; i< ncls; i++)
@ -92,7 +92,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
/* be conservative */
sz = sizeof(BITS32)*(2*it->ntrys+it->nentries);
/* allocate space */
if (!(it->udi_data = malloc(sz)))
if (!(it->udi_data = (BITS32*)Yap_AllocCodeSpace(sz)))
return;
sorted0 = sorted = (BITS32 *)it->udi_data;
sorted++; /* leave an initial hole */
@ -120,7 +120,7 @@ compare(const BITS32 *ip, Int j USES_REGS) {
}
}
sz = sizeof(BITS32)*(sorted-sorted0);
it->udi_data = (BITS32 *)realloc(it->udi_data, sz);
it->udi_data = (BITS32 *)Yap_ReallocCodeSpace((char *)it->udi_data, sz);
}
it->is_udi = i+1;
code = it->code;