fix case when we do an ungetc after we have found an EOF
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1720 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
29642223bb
commit
a728bed4f8
96
C/iopreds.c
96
C/iopreds.c
@ -2702,6 +2702,9 @@ p_past_eof (void)
|
|||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
out = Stream[sno].status & Eof_Stream_f;
|
out = Stream[sno].status & Eof_Stream_f;
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return out;
|
return out;
|
||||||
@ -2721,9 +2724,16 @@ p_peek_byte (void)
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
status = Stream[sno].status;
|
status = Stream[sno].status;
|
||||||
if (!(status & Binary_Stream_f)) {
|
if (!(status & Binary_Stream_f)) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek/2");
|
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek/2");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
|
ch = MkIntTerm(Stream[sno].och);
|
||||||
|
/* sequence of peeks */
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
|
return Yap_unify_constant(ARG2,ch);
|
||||||
|
}
|
||||||
if (status & Eof_Stream_f) {
|
if (status & Eof_Stream_f) {
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "peek/2");
|
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "peek/2");
|
||||||
@ -2762,16 +2772,21 @@ p_peek (void)
|
|||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
status = Stream[sno].status;
|
status = Stream[sno].status;
|
||||||
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
if (status & Binary_Stream_f) {
|
||||||
if (status & Binary_Stream_f) {
|
UNLOCK(Stream[sno].streamlock);
|
||||||
UNLOCK(Stream[sno].streamlock);
|
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek/2");
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek/2");
|
return FALSE;
|
||||||
return(FALSE);
|
}
|
||||||
} else if (status & (Eof_Error_Stream_f)) {
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
UNLOCK(Stream[sno].streamlock);
|
ch = MkIntTerm(Stream[sno].och);
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "peek/2");
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return(FALSE);
|
/* sequence of peeks */
|
||||||
}
|
return Yap_unify_constant(ARG2,ch);
|
||||||
|
}
|
||||||
|
if (status & Eof_Error_Stream_f) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
|
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "peek/2");
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
s = Stream+sno;
|
s = Stream+sno;
|
||||||
ocharcount = s->charcount;
|
ocharcount = s->charcount;
|
||||||
@ -3617,6 +3632,14 @@ p_get (void)
|
|||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
|
ch = PlUnGetc(sno);
|
||||||
|
if (ch <= 32 && ch >= 0) {
|
||||||
|
/* done */
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
|
return (Yap_unify_constant (ARG2, MkIntTerm (ch)));
|
||||||
|
}
|
||||||
|
}
|
||||||
status = Stream[sno].status;
|
status = Stream[sno].status;
|
||||||
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
||||||
if (status & Binary_Stream_f) {
|
if (status & Binary_Stream_f) {
|
||||||
@ -3643,19 +3666,23 @@ p_get0 (void)
|
|||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
status = Stream[sno].status;
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
out = PlUnGetc(sno);
|
||||||
if (status & Binary_Stream_f) {
|
} else {
|
||||||
UNLOCK(Stream[sno].streamlock);
|
status = Stream[sno].status;
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get0/2");
|
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
||||||
return(FALSE);
|
if (status & Binary_Stream_f) {
|
||||||
} else if (status & (Eof_Error_Stream_f)) {
|
UNLOCK(Stream[sno].streamlock);
|
||||||
UNLOCK(Stream[sno].streamlock);
|
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get0/2");
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "get0/2");
|
return(FALSE);
|
||||||
return(FALSE);
|
} else if (status & (Eof_Error_Stream_f)) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
|
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "get0/2");
|
||||||
|
return(FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
out = Stream[sno].stream_getc(sno);
|
||||||
}
|
}
|
||||||
out = Stream[sno].stream_getc(sno);
|
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return (Yap_unify_constant (ARG2, MkIntTerm (out)) );
|
return (Yap_unify_constant (ARG2, MkIntTerm (out)) );
|
||||||
}
|
}
|
||||||
@ -3679,9 +3706,17 @@ p_get0_line_codes (void)
|
|||||||
int sno = CheckStream (ARG1, Input_Stream_f, "get0/2");
|
int sno = CheckStream (ARG1, Input_Stream_f, "get0/2");
|
||||||
Int status;
|
Int status;
|
||||||
Term out;
|
Term out;
|
||||||
|
Int ch = '\0';
|
||||||
|
int rewind;
|
||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
|
ch = PlUnGetc(sno);
|
||||||
|
rewind = TRUE;
|
||||||
|
} else {
|
||||||
|
rewind = FALSE;
|
||||||
|
}
|
||||||
status = Stream[sno].status;
|
status = Stream[sno].status;
|
||||||
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
if (status & (Binary_Stream_f|Eof_Stream_f)) {
|
||||||
if (status & Binary_Stream_f) {
|
if (status & Binary_Stream_f) {
|
||||||
@ -3696,7 +3731,10 @@ p_get0_line_codes (void)
|
|||||||
}
|
}
|
||||||
out = read_line(sno);
|
out = read_line(sno);
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return(Yap_unify(out,ARG2));
|
if (rewind)
|
||||||
|
return Yap_unify(MkPairTerm(MkIntegerTerm(ch),out), ARG2);
|
||||||
|
else
|
||||||
|
return Yap_unify(out,ARG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
@ -3715,12 +3753,16 @@ p_get_byte (void)
|
|||||||
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "get_byte/2");
|
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "get_byte/2");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
if ((status & (Eof_Stream_f|Eof_Error_Stream_f)) == (Eof_Stream_f|Eof_Error_Stream_f)) {
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
UNLOCK(Stream[sno].streamlock);
|
out = MkIntTerm(PlUnGetc(sno));
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "get_byte/2");
|
} else {
|
||||||
return(FALSE);
|
if ((status & (Eof_Stream_f|Eof_Error_Stream_f)) == (Eof_Stream_f|Eof_Error_Stream_f)) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
|
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "get_byte/2");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
out = MkIntTerm (Stream[sno].stream_getc(sno));
|
||||||
}
|
}
|
||||||
out = MkIntTerm (Stream[sno].stream_getc(sno));
|
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return (Yap_unify_constant (ARG2, out));
|
return (Yap_unify_constant (ARG2, out));
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
<h2>Yap-5.1.2:</h2>
|
<h2>Yap-5.1.2:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li> FIXED: if peek finds EOF get should not return an error (obs
|
||||||
|
from Miguel Filgueiras).</li>
|
||||||
<li> FIXED: allow overflows on timestamps.</li>
|
<li> FIXED: allow overflows on timestamps.</li>
|
||||||
<li> FIXED: more fixes for new dynamic code and stack shifting.</li>
|
<li> FIXED: more fixes for new dynamic code and stack shifting.</li>
|
||||||
<li> FIXED: if we can generate index on an sub-argument and the
|
<li> FIXED: if we can generate index on an sub-argument and the
|
||||||
|
Reference in New Issue
Block a user