int Yap_SWIHandleError(const char *s, ...) { CACHE_REGS yap_error_number err = LOCAL_Error_TYPE; char *serr; if (s) { serr = (char *)s; } switch (err) { case RESOURCE_ERROR_STACK: if (!Yap_gc(2, ENV, gc_P(P, CP))) { Yap_Error(RESOURCE_ERROR_STACK, TermNil, serr); return (FALSE); } return TRUE; case RESOURCE_ERROR_AUXILIARY_STACK: if (LOCAL_MAX_SIZE < (char *)AuxSp - AuxBase) { LOCAL_MAX_SIZE += 1024; } if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) { /* crash in flames */ Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, ARG1, serr); return FALSE; } return true; case RESOURCE_ERROR_HEAP: if (!Yap_growheap(false, 0, NULL)) { Yap_Error(RESOURCE_ERROR_HEAP, ARG2, serr); return false; } default: Yap_Error(err, TermNil, serr); return false; } }
bool Yap_HandleError__(const char *file, const char *function, int lineno, const char *s, ...) { CACHE_REGS yap_error_number err = LOCAL_Error_TYPE; const char *serr; arity_t arity = 2; if (LOCAL_ErrorMessage) { serr = LOCAL_ErrorMessage; } else { serr = s; } if (P != FAILCODE) { if (P->opc == Yap_opcode(_try_c) || P->opc == Yap_opcode(_try_userc) || P->opc == Yap_opcode(_retry_c) || P->opc == Yap_opcode(_retry_userc)) { arity = P->y_u.OtapFs.p->ArityOfPE; } else { arity = PREVOP(P, Osbpp)->y_u.Osbpp.p->ArityOfPE; } } switch (err) { case RESOURCE_ERROR_STACK: if (!Yap_gc(arity, ENV, gc_P(P, CP))) { Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_STACK, ARG1, serr); return false; } LOCAL_PrologMode = UserMode; return true; case RESOURCE_ERROR_AUXILIARY_STACK: if (LOCAL_MAX_SIZE < (char *)AuxSp - AuxBase) { LOCAL_MAX_SIZE += 1024; } if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) { /* crash in flames */ Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK, ARG1, serr); return false; } LOCAL_PrologMode = UserMode; return true; case RESOURCE_ERROR_HEAP: if (!Yap_growheap(FALSE, 0, NULL)) { Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_HEAP, ARG2, serr); return false; } default: if (LOCAL_PrologMode == UserMode) Yap_ThrowError__(file, function, lineno, err, LOCAL_RawTerm, serr); else LOCAL_PrologMode &= ~InErrorMode; return false; } }
int Yap_SWIHandleError( const char *s, ... ) { CACHE_REGS yap_error_number err = LOCAL_Error_TYPE; char *serr; LOCAL_Error_TYPE = YAP_NO_ERROR; if (LOCAL_ErrorMessage) { serr = LOCAL_ErrorMessage; } else { serr = (char *)s; } switch (err) { case OUT_OF_STACK_ERROR: if (!Yap_gc(2, ENV, gc_P(P,CP))) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, serr); return(FALSE); } return TRUE; case OUT_OF_AUXSPACE_ERROR: if (LOCAL_MAX_SIZE < (char *)AuxSp-AuxBase) { LOCAL_MAX_SIZE += 1024; } if (!Yap_ExpandPreAllocCodeSpace(0,NULL, TRUE)) { /* crash in flames */ Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, serr); return FALSE; } return TRUE; case OUT_OF_HEAP_ERROR: if (!Yap_growheap(FALSE, 0, NULL)) { Yap_Error(OUT_OF_HEAP_ERROR, ARG2, serr); return FALSE; } default: Yap_Error(err, LOCAL_Error_Term, serr); return(FALSE); } }
bool Yap_HandleError__(const char *file, const char *function, int lineno, const char *s, ...) { CACHE_REGS yap_error_number err = LOCAL_Error_TYPE; const char *serr; if (LOCAL_ErrorMessage) { serr = LOCAL_ErrorMessage; } else { serr = s; } switch (err) { case RESOURCE_ERROR_STACK: if (!Yap_gc(2, ENV, gc_P(P, CP))) { Yap_Error__(file, function, lineno, RESOURCE_ERROR_STACK, ARG1, serr); return false; } return true; case RESOURCE_ERROR_AUXILIARY_STACK: if (LOCAL_MAX_SIZE < (char *)AuxSp - AuxBase) { LOCAL_MAX_SIZE += 1024; } if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) { /* crash in flames */ Yap_Error__(file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK, ARG1, serr); return false; } return true; case RESOURCE_ERROR_HEAP: if (!Yap_growheap(FALSE, 0, NULL)) { Yap_Error__(file, function, lineno, RESOURCE_ERROR_HEAP, ARG2, serr); return false; } default: Yap_Error__(file, function, lineno, err, TermNil, serr); return false; } }
static char *ensure_space(size_t sz) { CACHE_REGS char *s; s = (char *)Yap_PreAllocCodeSpace(); while (s + sz >= (char *)AuxSp) { #if USE_SYSTEM_MALLOC /* may require stack expansion */ if (!Yap_ExpandPreAllocCodeSpace(sz, NULL, TRUE)) { s = NULL; break; } s = (char *)Yap_PreAllocCodeSpace(); #else s = NULL; #endif } if (!s) { s = (char *)TR; while (s + sz >= LOCAL_TrailTop) { if (!Yap_growtrail(sz / sizeof(CELL), FALSE)) { s = NULL; break; } s = (char *)TR; } } if (!s) { s = (char *)HR; if (s + sz >= (char *)ASP) { Yap_Error(RESOURCE_ERROR_STACK, TermNil, "not enough space to write bignum: it requires %d bytes", sz); s = NULL; } } return s; }