From c59a7bd8b2b77b9b97deadd52642d93c6d486cbe Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 19 Jan 2012 12:33:59 -0700 Subject: [PATCH] fix position counting in `read-byte' Merge to 5.2.1 (cherry picked from commit c723aeeb6a772fc20b4a89095018459c1a123fc4) --- collects/tests/racket/port.rktl | 21 +++++++++++++++++++++ src/racket/src/port.c | 9 +++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/collects/tests/racket/port.rktl b/collects/tests/racket/port.rktl index 79be4433c6..62a9420545 100644 --- a/collects/tests/racket/port.rktl +++ b/collects/tests/racket/port.rktl @@ -717,6 +717,27 @@ (test t2 sync t2) (test oc sync/timeout 0 oc)) +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; eof should not advance port position + +(let () + (define (check read-byte) + (define-values (i o) (make-pipe)) + (test 0 file-position i) + (write-byte 10 o) + (close-output-port o) + (test 0 file-position i) + (test 10 read-byte i) + (test 1 file-position i) + (test eof read-byte i) + (test 1 file-position i)) + (check read-byte) + (check (lambda (i) + (define c (read-char i)) + (if (char? c) + (char->integer c) + c)))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (report-errs) diff --git a/src/racket/src/port.c b/src/racket/src/port.c index a26f044393..72aa99f971 100644 --- a/src/racket/src/port.c +++ b/src/racket/src/port.c @@ -3201,10 +3201,11 @@ static MZ_INLINE intptr_t get_one_byte(GC_CAN_IGNORE const char *who, if (v == SCHEME_SPECIAL) { scheme_bad_time_for_special(who, port); } - - ip = (Scheme_Input_Port *)port; /* since ignored by GC */ - if (ip->p.position >= 0) - ip->p.position++; + if (v != EOF) { + ip = (Scheme_Input_Port *)port; /* since `ip is ignored by GC */ + if (ip->p.position >= 0) + ip->p.position++; + } return v; }