more memory allocation fixes.

This commit is contained in:
Vítor Santos Costa II 2010-04-15 22:49:25 +01:00
parent c4b12d5cbe
commit 052c20a29b
4 changed files with 24 additions and 34 deletions

View File

@ -3836,21 +3836,23 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
int clause_has_dbterm = FALSE;
#if USE_SYSTEM_MALLOC
if (!Yap_LabelFirstArray && max_label <= DEFAULT_NLABELS) {
Yap_LabelFirstArray = (Int *)Yap_AllocCodeSpace(sizeof(Int)*DEFAULT_NLABELS);
Yap_LabelFirstArraySz = DEFAULT_NLABELS;
if (!Yap_LabelFirstArray) {
save_machine_regs();
longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
if (!cip->label_offset) {
if (!Yap_LabelFirstArray && max_label <= DEFAULT_NLABELS) {
Yap_LabelFirstArray = (Int *)Yap_AllocCodeSpace(sizeof(Int)*DEFAULT_NLABELS);
Yap_LabelFirstArraySz = DEFAULT_NLABELS;
if (!Yap_LabelFirstArray) {
save_machine_regs();
longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
}
}
}
if (Yap_LabelFirstArray && max_label <= Yap_LabelFirstArraySz) {
cip->label_offset = Yap_LabelFirstArray;
} else {
cip->label_offset = (Int *)Yap_AllocCodeSpace(sizeof(Int)*max_label);
if (!cip->label_offset) {
save_machine_regs();
longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
if (Yap_LabelFirstArray && max_label <= Yap_LabelFirstArraySz) {
cip->label_offset = Yap_LabelFirstArray;
} else {
cip->label_offset = (Int *)Yap_AllocCodeSpace(sizeof(Int)*max_label);
if (!cip->label_offset) {
save_machine_regs();
longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH);
}
}
}
#else
@ -3875,10 +3877,6 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
UInt osize;
if(!(x = fetch_clause_space(&t,size,cip,&osize))){
#if USE_SYSTEM_MALLOC
if (cip->label_offset != Yap_LabelFirstArray)
Yap_FreeCodeSpace((ADDR)cip->label_offset);
#endif
return NULL;
}
cl = (LogUpdClause *)((CODEADDR)x-(UInt)size);
@ -3893,10 +3891,6 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
StaticClause *cl;
UInt osize;
if(!(x = fetch_clause_space(&t,size,cip,&osize))) {
#if USE_SYSTEM_MALLOC
if (cip->label_offset != Yap_LabelFirstArray)
Yap_FreeCodeSpace((ADDR)cip->label_offset);
#endif
return NULL;
}
cl = (StaticClause *)((CODEADDR)x-(UInt)size);
@ -3906,10 +3900,6 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
cl->usc.ClSource = x;
cl->ClSize = osize;
ProfEnd=code_p;
#if USE_SYSTEM_MALLOC
if (cip->label_offset != Yap_LabelFirstArray)
Yap_FreeCodeSpace((ADDR)cip->label_offset);
#endif
return entry_code;
} else {
while ((cip->code_addr = (yamop *) Yap_AllocCodeSpace(size)) == NULL) {
@ -3917,10 +3907,6 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
if (!Yap_growheap(TRUE, size, cip)) {
Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Size = size;
#if USE_SYSTEM_MALLOC
if (cip->label_offset != Yap_LabelFirstArray)
Yap_FreeCodeSpace((ADDR)cip->label_offset);
#endif
return NULL;
}
}
@ -3944,10 +3930,6 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates
Yap_inform_profiler_of_clause(entry_code, ProfEnd, ap, mode == ASSEMBLING_INDEX);
}
#endif /* LOW_PROF */
#if USE_SYSTEM_MALLOC
if (cip->label_offset != Yap_LabelFirstArray)
Yap_FreeCodeSpace((ADDR)cip->label_offset);
#endif
return entry_code;
}

View File

@ -3405,6 +3405,7 @@ Yap_cclause(volatile Term inp_clause, int NOfArgs, Term mod, volatile Term src)
cglobs.cint.BlobsStart = cglobs.cint.icpc = NULL;
cglobs.cint.dbterml = NULL;
cglobs.cint.blks = NULL;
cglobs.cint.label_offset = NULL;
cglobs.cint.freep =
cglobs.cint.freep0 =
(char *) (H + maxvnum+(sizeof(Int)/sizeof(CELL))*MaxTemps+MaxTemps);

View File

@ -170,7 +170,12 @@ Yap_ReleaseCMem (struct intermediates *cip)
p = nextp;
}
cip->blks = NULL;
if (cip->label_offset &&
cip->label_offset != Yap_LabelFirstArray) {
Yap_FreeCodeSpace((ADDR)cip->label_offset);
}
#endif
cip->label_offset = NULL;
}
char *

View File

@ -3419,6 +3419,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc)
Yap_BuildMegaClause(ap);
cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL;
cint.expand_block = NULL;
cint.label_offset = NULL;
Yap_ErrorMessage = NULL;
if (compile_index(&cint) == (UInt)FAILCODE) {
Yap_ReleaseCMem(&cint);
@ -4499,6 +4500,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) {
cint.blks = NULL;
cint.cls = NULL;
cint.code_addr = NULL;
cint.label_offset = NULL;
if ((cb = setjmp(cint.CompilerBotch)) == 3) {
restore_machine_regs();
/* grow stack */