bug in EOF processing when doing read.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@885 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2003-10-06 14:16:23 +00:00
parent 32301f0060
commit 2db3829b82
3 changed files with 23 additions and 15 deletions

View File

@ -1580,7 +1580,11 @@ Yap_Error (yap_error_number type, Term where, char *format,...)
} }
if (type != PURE_ABORT) { if (type != PURE_ABORT) {
/* This is used by some complex procedures to detect there was an error */ /* 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) { switch (type) {
case OUT_OF_HEAP_ERROR: case OUT_OF_HEAP_ERROR:

View File

@ -2983,23 +2983,27 @@ do_read(int inp_stream)
/* preserve value of H after scanning: otherwise we may lose strings /* preserve value of H after scanning: otherwise we may lose strings
and floats */ and floats */
old_H = H; old_H = H;
if ((Stream[inp_stream].status & Eof_Stream_f) if (Stream[inp_stream].status & Eof_Stream_f) {
&& !Yap_eot_before_eof) { if (Yap_eot_before_eof) {
if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) { /* next read should give out an end of file */
/* we got the end of file from an abort */ Stream[inp_stream].status |= Push_Eof_Stream_f;
if (Yap_ErrorMessage == "Abort") { } 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; TR = old_TR;
return(FALSE); 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[inp_stream].status |= Push_Eof_Stream_f; Stream[inp_stream].status |= Push_Eof_Stream_f;
Yap_ErrorMessage = "end of file found before end of term"; Yap_ErrorMessage = "end of file found before end of term";
} else { } else {
/* restore TR */ /* restore TR */
TR = old_TR; TR = old_TR;
return (Yap_unify(MkIntegerTerm(StartLine = Stream[inp_stream].linecount),ARG4) && return (Yap_unify(MkIntegerTerm(StartLine = Stream[inp_stream].linecount),ARG4) &&
Yap_unify_constant (ARG2, MkAtomTerm (AtomEof))); Yap_unify_constant (ARG2, MkAtomTerm (AtomEof)));
}
} }
} }
repeat_cycle: repeat_cycle:

View File

@ -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); if(Yap_Option[2]) fprintf(Yap_stderr,"[Token %d %ld]",Ord(kind),(unsigned long int)t->TokInfo);
#endif #endif
if (Yap_ErrorMessage) { 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)); TokEntry *e = (TokEntry *) AllocScannerMemory(sizeof(TokEntry));
if (e == NULL) { if (e == NULL) {
Yap_ErrorMessage = "not enough stack space to read in term"; Yap_ErrorMessage = "not enough stack space to read in term";