From e1f7333e2e320dd82e2ecaa460b20c26ed04a097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 8 Oct 2015 10:17:57 +0100 Subject: [PATCH] bad call order in dopeek --- os/charsio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/os/charsio.c b/os/charsio.c index 53dad4fe1..f8d73ad0e 100644 --- a/os/charsio.c +++ b/os/charsio.c @@ -104,6 +104,7 @@ plUnGetc( int sno, int ch ) static Int dopeek( int sno ) { + CACHE_REGS Int ocharcount, olinecount, olinepos; StreamDesc *s; Int ch; @@ -117,13 +118,13 @@ static Int dopeek( int sno ) s->linecount = olinecount; s->linepos = olinepos; /* buffer the character */ - if (s->encoding == LOCAL_encoding)) { + if (s->encoding == LOCAL_encoding) { ungetwc( ch, s-> file ); } else { /* do the ungetc as if a write .. */ int (*f)(int, int) = s->stream_putc; s->stream_putc = plUnGetc; - put_wchar( ch, sno ); + put_wchar( sno, ch ); s->stream_putc = f; } return ch; @@ -826,9 +827,11 @@ peek_code_1 ( USES_REGS1 ) Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek_code/2"); return FALSE; } - if ((ch = dopeek( sno )) < 0) - return false; + if ((ch = dopeek( sno )) < 0) { UNLOCK(GLOBAL_Stream[sno].streamlock); + return false; + } + UNLOCK(GLOBAL_Stream[sno].streamlock); return(Yap_unify_constant(ARG1,MkIntTerm(ch))); }