From 2db3829b82443323e5ea4156de797f316813a001 Mon Sep 17 00:00:00 2001 From: vsc Date: Mon, 6 Oct 2003 14:16:23 +0000 Subject: [PATCH] bug in EOF processing when doing read. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@885 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/errors.c | 6 +++++- C/iopreds.c | 30 +++++++++++++++++------------- C/scanner.c | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/C/errors.c b/C/errors.c index 4f3833c48..482a80b59 100644 --- a/C/errors.c +++ b/C/errors.c @@ -1580,7 +1580,11 @@ Yap_Error (yap_error_number type, Term where, char *format,...) } if (type != PURE_ABORT) { /* This is used by some complex procedures to detect there was an error */ - Yap_ErrorMessage = RepAtom(AtomOfTerm(nt[0]))->StrOfAE; + if (IsAtomTerm(nt[0])) { + Yap_ErrorMessage = RepAtom(AtomOfTerm(nt[0]))->StrOfAE; + } else { + Yap_ErrorMessage = RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE; + } } switch (type) { case OUT_OF_HEAP_ERROR: diff --git a/C/iopreds.c b/C/iopreds.c index 34513beeb..72260af8f 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -2983,23 +2983,27 @@ do_read(int inp_stream) /* preserve value of H after scanning: otherwise we may lose strings and floats */ old_H = H; - if ((Stream[inp_stream].status & Eof_Stream_f) - && !Yap_eot_before_eof) { - if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) { - /* we got the end of file from an abort */ - if (Yap_ErrorMessage == "Abort") { + if (Stream[inp_stream].status & Eof_Stream_f) { + if (Yap_eot_before_eof) { + /* next read should give out an end of file */ + Stream[inp_stream].status |= Push_Eof_Stream_f; + } else { + if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) { + /* we got the end of file from an abort */ + if (Yap_ErrorMessage == "Abort") { TR = old_TR; return(FALSE); } - /* we need to force the next reading to also give end of file.*/ - Stream[inp_stream].status |= Push_Eof_Stream_f; - Yap_ErrorMessage = "end of file found before end of term"; - } else { - /* restore TR */ - TR = old_TR; + /* we need to force the next reading to also give end of file.*/ + Stream[inp_stream].status |= Push_Eof_Stream_f; + Yap_ErrorMessage = "end of file found before end of term"; + } else { + /* restore TR */ + TR = old_TR; - return (Yap_unify(MkIntegerTerm(StartLine = Stream[inp_stream].linecount),ARG4) && - Yap_unify_constant (ARG2, MkAtomTerm (AtomEof))); + return (Yap_unify(MkIntegerTerm(StartLine = Stream[inp_stream].linecount),ARG4) && + Yap_unify_constant (ARG2, MkAtomTerm (AtomEof))); + } } } repeat_cycle: diff --git a/C/scanner.c b/C/scanner.c index 0cc649516..8070113fa 100644 --- a/C/scanner.c +++ b/C/scanner.c @@ -884,7 +884,7 @@ Yap_tokenizer(int inp_stream) if(Yap_Option[2]) fprintf(Yap_stderr,"[Token %d %ld]",Ord(kind),(unsigned long int)t->TokInfo); #endif if (Yap_ErrorMessage) { - /* insert an error token to inform the system on what happened */ + /* insert an error token to inform the system of what happened */ TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry)); if (e == NULL) { Yap_ErrorMessage = "not enough stack space to read in term";