pesky ^C and abort fixes (I hope)

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@236 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-12-18 22:01:26 +00:00
parent 7e22cb486f
commit 2b78d7ce14
12 changed files with 42 additions and 32 deletions

View File

@ -298,7 +298,7 @@ absmi(int inp)
restore_absmi_regs(old_regs); restore_absmi_regs(old_regs);
#endif #endif
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve space in growheap");
FAIL(); FAIL();
} }
goto reset_absmi; goto reset_absmi;
@ -2077,7 +2077,7 @@ absmi(int inp)
} }
if (PrologMode & AbortMode) { if (PrologMode & AbortMode) {
PrologMode &= ~AbortMode; PrologMode &= ~AbortMode;
Abort(""); Error(PURE_ABORT, TermNil, "");
} }
JMPNext(); JMPNext();
} }

View File

@ -12,7 +12,7 @@
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: allocating space * * comments: allocating space *
* version:$Id: alloc.c,v 1.9 2001-09-24 14:35:58 vsc Exp $ * * version:$Id: alloc.c,v 1.10 2001-12-18 22:01:26 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
@ -254,7 +254,7 @@ AllocHeap(unsigned int size)
UNLOCK(HeapTopLock); UNLOCK(HeapTopLock);
} }
/* we destroyed the stack */ /* we destroyed the stack */
Abort("Stack Crashed against Heap..."); Error(SYSTEM_ERROR, TermNil, "Stack Crashed against Heap...");
return(NULL); return(NULL);
} else { } else {
if (HeapTop + size * sizeof(CELL) + sizeof(YAP_SEG_SIZE) < Addr(AuxSp)) { if (HeapTop + size * sizeof(CELL) + sizeof(YAP_SEG_SIZE) < Addr(AuxSp)) {

View File

@ -432,7 +432,7 @@ AllocateStaticArraySpace(StaticArrayEntry *p, static_array_types atype, Int arra
while ((p->ValueOfVE.floats = (Float *) AllocAtomSpace(asize) ) == NULL) { while ((p->ValueOfVE.floats = (Float *) AllocAtomSpace(asize) ) == NULL) {
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve space in growheap");
return; return;
} }
YAPEnterCriticalSection(); YAPEnterCriticalSection();

View File

@ -390,7 +390,7 @@ YapAllocSpaceFromYap(unsigned int size)
if ((ptr = AllocCodeSpace(size)) == NULL) { if ((ptr = AllocCodeSpace(size)) == NULL) {
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve space in growheap");
return(NULL); return(NULL);
} }
} }

View File

@ -369,8 +369,6 @@ ShutdownYAP(int value)
exit(value); exit(value);
} }
static int in_error = FALSE;
yamop * yamop *
Error (yap_error_number type, Term where, char *format,...) Error (yap_error_number type, Term where, char *format,...)
{ {
@ -382,8 +380,10 @@ Error (yap_error_number type, Term where, char *format,...)
char *tp = p; char *tp = p;
int psize = 512; int psize = 512;
if (in_error) /* disallow recursive error handling */
if (PrologMode & InErrorMode)
return(P); return(P);
PrologMode |= InErrorMode;
va_start (ap, format); va_start (ap, format);
/* now build the error string */ /* now build the error string */
if (format != NULL) if (format != NULL)
@ -1821,7 +1821,7 @@ Error (yap_error_number type, Term where, char *format,...)
while (B->cp_b != NULL && B->cp_ap != (yamop *) NOCODE) while (B->cp_b != NULL && B->cp_ap != (yamop *) NOCODE)
B = B->cp_b; B = B->cp_b;
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
in_error = FALSE; PrologMode &= ~InErrorMode;
return(P); return(P);
} }
/* make the abstract machine jump where we want them to jump to */ /* make the abstract machine jump where we want them to jump to */
@ -1836,7 +1836,7 @@ Error (yap_error_number type, Term where, char *format,...)
#endif /* YAPOR */ #endif /* YAPOR */
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
} }
in_error = FALSE; PrologMode &= ~InErrorMode;
return(P); return(P);
} }

View File

@ -2118,7 +2118,7 @@ update_relocation_chain(CELL_PTR current, CELL_PTR dest)
} }
#ifdef DEBUG #ifdef DEBUG
else { else {
Abort("[GC] ATOMIC in relocation chain"); Error(SYSTEM_ERROR, TermNil, "ATOMIC in a GC relocation chain");
} }
#endif #endif
} }
@ -2664,7 +2664,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
if (HeapTop >= GlobalBase - MinHeapGap) { if (HeapTop >= GlobalBase - MinHeapGap) {
*--ASP = (CELL)current_env; *--ASP = (CELL)current_env;
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP could not grow heap before garbage collection ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap before garbage collection");
return(FALSE); return(FALSE);
} }
current_env = (CELL *)*ASP; current_env = (CELL *)*ASP;

View File

@ -1410,7 +1410,7 @@ PredIsIndexable(PredEntry *ap)
#endif #endif
if ((indx_out = assemble(ASSEMBLING_INDEX)) == NIL) { if ((indx_out = assemble(ASSEMBLING_INDEX)) == NIL) {
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP failed to reserve space in growheap ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve space in growheap");
return(FALSE); return(FALSE);
} }
goto restart_index; goto restart_index;

View File

@ -635,7 +635,7 @@ MemPutc(int sno, int ch)
char *newbuf; char *newbuf;
if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) { if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) {
Abort("[ SYSTEM ERROR: YAP could not grow heap for writing to string ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap for writing to string");
} }
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
memmove((void *)newbuf, (void *)s->u.mem_string.buf, (size_t)((s->u.mem_string.pos)*sizeof(char))); memmove((void *)newbuf, (void *)s->u.mem_string.buf, (size_t)((s->u.mem_string.pos)*sizeof(char)));
@ -912,8 +912,9 @@ ReadlineGetc(int sno)
PrologMode &= ~InterruptMode; PrologMode &= ~InterruptMode;
ProcessSIGINT(); ProcessSIGINT();
if (PrologMode & AbortMode) { if (PrologMode & AbortMode) {
PrologMode &= ~AbortMode; Error(PURE_ABORT, TermNil, NULL);
Abort(""); ErrorMessage = "Abort";
return(console_post_process_read_char(EOF, s, sno));
} }
continue; continue;
} }
@ -1281,8 +1282,9 @@ ConsoleGetc(int sno)
ProcessSIGINT(); ProcessSIGINT();
newline = TRUE; newline = TRUE;
if (PrologMode & AbortMode) { if (PrologMode & AbortMode) {
PrologMode &= ~AbortMode; Error(PURE_ABORT, TermNil, NULL);
Abort(""); ErrorMessage = "Abort";
return(console_post_process_read_char(EOF, s, sno));
} }
goto restart; goto restart;
} }
@ -1929,7 +1931,7 @@ p_open_mem_read_stream (void) /* $open_mem_read_stream(+List,-Stream) */
} }
while ((nbuf = (char *)AllocAtomSpace((sl+1)*sizeof(char))) == NULL) { while ((nbuf = (char *)AllocAtomSpace((sl+1)*sizeof(char))) == NULL) {
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP could not grow heap in open_mem_read_stream ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap in open_mem_read_stream");
return(FALSE); return(FALSE);
} }
} }
@ -1983,7 +1985,7 @@ p_open_mem_write_stream (void) /* $open_mem_write_stream(-Stream) */
while ((nbuf = (char *)AllocAtomSpace(page_size*sizeof(char))) == NULL) { while ((nbuf = (char *)AllocAtomSpace(page_size*sizeof(char))) == NULL) {
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP could not grow heap in open_mem_write_stream ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap in open_mem_write_stream");
return(FALSE); return(FALSE);
} }
} }
@ -2432,7 +2434,7 @@ p_peek_mem_write_stream (void)
while (H + 1024 >= ASP) { while (H + 1024 >= ASP) {
H = HI; H = HI;
if (!gc(3, ENV, P)) { if (!gc(3, ENV, P)) {
Abort("[ SYSTEM ERROR: YAP could not grow stack in peek_mem_write_stream/2 ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow stack in peek_mem_write_stream/2");
return(FALSE); return(FALSE);
} }
i = 0; i = 0;
@ -2790,6 +2792,11 @@ p_read (void)
if ((Stream[c_input_stream].status & Eof_Stream_f) if ((Stream[c_input_stream].status & Eof_Stream_f)
&& !eot_before_eof) { && !eot_before_eof) {
if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) { if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) {
/* we got the end of file from an abort */
if (ErrorMessage == "Abort") {
TR = old_TR;
return(FALSE);
}
/* we need to force the next reading to also give end of file.*/ /* we need to force the next reading to also give end of file.*/
Stream[c_input_stream].status |= Push_Eof_Stream_f; Stream[c_input_stream].status |= Push_Eof_Stream_f;
ErrorMessage = "[ Error: end of file found before end of term ]"; ErrorMessage = "[ Error: end of file found before end of term ]";
@ -3525,7 +3532,7 @@ format_putc(int sno, int ch) {
char *newbuf; char *newbuf;
if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) { if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) {
Abort("[ SYSTEM ERROR: YAP could not grow heap for format/2 ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap for format/2");
return(EOF); return(EOF);
} }
#if HAVE_MEMMOVE #if HAVE_MEMMOVE
@ -4629,7 +4636,7 @@ p_char_conversion(void)
CharConversionTable2 = AllocCodeSpace(NUMBER_OF_CHARS*sizeof(char)); CharConversionTable2 = AllocCodeSpace(NUMBER_OF_CHARS*sizeof(char));
while (CharConversionTable2 == NULL) { while (CharConversionTable2 == NULL) {
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP could not grow heap in char_conversion/2 ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap in char_conversion/2");
return(FALSE); return(FALSE);
} }
} }

View File

@ -689,6 +689,9 @@ token(void)
eat up the escape sequence. */ eat up the escape sequence. */
ErrorMessage = "invalid escape sequence"; ErrorMessage = "invalid escape sequence";
} }
} else if (chtype[ch] == EF) {
ReleasePreAllocCodeSpace((CODEADDR)TokImage);
return (eot_tok);
} else { } else {
*charp++ = ch; *charp++ = ch;
my_get_quoted_ch(); my_get_quoted_ch();

View File

@ -653,7 +653,7 @@ p_atom_concat(void)
if (cptr+sz >= top-1024) { if (cptr+sz >= top-1024) {
ReleasePreAllocCodeSpace((ADDR)cpt0); ReleasePreAllocCodeSpace((ADDR)cpt0);
if (!growheap(FALSE)) { if (!growheap(FALSE)) {
Abort("[ SYSTEM ERROR: YAP could not grow heap in recorda/3 ]\n"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap in recorda/3 ]\n");
return(FALSE); return(FALSE);
} }
goto restart; goto restart;

View File

@ -993,8 +993,7 @@ SearchForTrailFault(void)
if ((TR > (tr_fr_ptr)TrailTop-1024 && if ((TR > (tr_fr_ptr)TrailTop-1024 &&
TR < (tr_fr_ptr)TrailTop+(64*1024))|| DBTrailOverflow()) { TR < (tr_fr_ptr)TrailTop+(64*1024))|| DBTrailOverflow()) {
if (!growtrail(64 * 1024L)) { if (!growtrail(64 * 1024L)) {
YP_fprintf(YP_stderr, "[ ERROR: YAP failed to reserve %ld bytes in growtrail ]\n",64*1024L); Error(SYSTEM_ERROR, TermNil, "YAP failed to reserve %ld bytes in growtrail", 64*1024L);
Abort("");
} }
/* just in case, make sure the OS keeps the signal handler. */ /* just in case, make sure the OS keeps the signal handler. */
/* my_signal_info(SIGSEGV, HandleSIGSEGV); */ /* my_signal_info(SIGSEGV, HandleSIGSEGV); */
@ -1270,7 +1269,7 @@ ReceiveSignal (int s)
#ifndef MPW #ifndef MPW
case SIGFPE: case SIGFPE:
my_signal (SIGFPE, HandleMatherr); my_signal (SIGFPE, HandleMatherr);
Abort ("[ Fatal error: floating point exception ]"); Error (SYSTEM_ERROR, TermNil, "floating point exception ]");
break; break;
#endif #endif
#if !defined(LIGHT) && !defined(_WIN32) #if !defined(LIGHT) && !defined(_WIN32)

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.13 2001-12-17 18:31:11 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.14 2001-12-18 22:01:26 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -773,7 +773,8 @@ typedef enum {
UserMode = 2, /* Normal mode */ UserMode = 2, /* Normal mode */
CritMode = 4, /* If we are meddling with the heap */ CritMode = 4, /* If we are meddling with the heap */
AbortMode = 8, /* expecting to abort */ AbortMode = 8, /* expecting to abort */
InterruptMode = 16 /* under an interrupt */ InterruptMode = 16, /* under an interrupt */
InErrorMode = 32 /* under an interrupt */
} prolog_exec_mode; } prolog_exec_mode;
extern prolog_exec_mode PrologMode; extern prolog_exec_mode PrologMode;
@ -831,7 +832,7 @@ extern int yap_argc;
} \ } \
if (PrologMode & AbortMode) { \ if (PrologMode & AbortMode) { \
PrologMode &= ~AbortMode; \ PrologMode &= ~AbortMode; \
Abort(""); \ Error(PURE_ABORT, TermNil, ""); \
} \ } \
GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \ GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \
UNLOCK(GLOBAL_LOCKS_heap_access); \ UNLOCK(GLOBAL_LOCKS_heap_access); \
@ -854,7 +855,7 @@ extern int yap_argc;
} \ } \
if (PrologMode & AbortMode) { \ if (PrologMode & AbortMode) { \
PrologMode &= ~AbortMode; \ PrologMode &= ~AbortMode; \
Abort(""); \ Error(PURE_ABORT, TermNil, ""); \
} \ } \
} \ } \
} }