fix position counting with internal read
shortcut
The primitive `read` uses a shortcut --- a private "ungetc" implementation --- that did not count position correctly for non-ASCII characters. Closes #1599
This commit is contained in:
parent
6c9dbea31f
commit
69d7636770
|
@ -920,6 +920,31 @@
|
|||
void)))
|
||||
exn:fail:read?))
|
||||
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Check whether `read` counts correctly
|
||||
;; (because `read` may cheat internally with a private "unget")
|
||||
|
||||
(let ()
|
||||
(define p
|
||||
(let ([in (open-input-string "(…)abcdef")])
|
||||
(make-input-port
|
||||
"unicode"
|
||||
(lambda (s)
|
||||
(read-bytes-avail!* s in))
|
||||
(lambda (s skip default)
|
||||
(peek-bytes-avail!* s skip #f in))
|
||||
void
|
||||
#f
|
||||
#f
|
||||
#f
|
||||
void
|
||||
1)))
|
||||
|
||||
(test 0 file-position p)
|
||||
(void (read p))
|
||||
(test 5 file-position p)
|
||||
(test "abcde" read-string 5 p))
|
||||
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(report-errs)
|
||||
|
|
|
@ -3662,6 +3662,9 @@ scheme_ungetc (int ch, Scheme_Object *port)
|
|||
us[0] = ch;
|
||||
len = scheme_utf8_encode_all(us, 1, e);
|
||||
|
||||
if (ip->p.position > (len - 1))
|
||||
ip->p.position -= (len - 1);
|
||||
|
||||
if (ip->ungotten_count + len >= 24)
|
||||
scheme_signal_error("ungetc overflow");
|
||||
while (len) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user