fix position counting in `read-byte'

Merge to 5.2.1
(cherry picked from commit c723aeeb6a)
This commit is contained in:
Matthew Flatt 2012-01-19 12:33:59 -07:00 committed by Ryan Culpepper
parent fd8230152d
commit c59a7bd8b2
2 changed files with 26 additions and 4 deletions

View File

@ -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)

View File

@ -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;
}