fix some uses of peek-bytes-avail! that do not expect specials

Closes #3572
This commit is contained in:
Matthew Flatt 2020-12-21 08:06:43 -07:00
parent c93e4f1328
commit 0041354e1f
5 changed files with 55 additions and 15 deletions

View File

@ -1605,6 +1605,19 @@
(#"^(E)?(?(1)aa|a)*$" #"aaa" (#"aaa" #f))
(#"^(E)?(?(1)aa|a)*$" #"aaaa" (#"aaaa" #f))))
(let ()
(define out (open-output-bytes))
(define infinite-voids
(make-input-port
'voids
(lambda (s) (lambda args 'void))
(lambda (skip s evt) (lambda args 'void))
void))
(err/rt-test (regexp-match #rx"." infinite-voids)
exn:fail:contract?
#rx"non-character in an unsupported context"))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test unicode-property patterns

View File

@ -1,5 +1,6 @@
#lang racket/base
(require file/unzip
file/gunzip
racket/runtime-path
racket/port
tests/eli-tester)
@ -27,7 +28,18 @@
(call-with-input-file* unzip-me.zip test-with-unzip)
(call-with-input-file* unzip-me.zip
(lambda(in_port) (test-with-unzip (input-port-append #f in_port))))
(test-with-unzip-entry))
(test-with-unzip-entry)
(test (let ()
(define out (open-output-bytes))
(define infinite-voids
(make-input-port
'voids
(lambda (s) (lambda args 'void))
(lambda (skip s evt) (lambda args 'void))
void))
(inflate infinite-voids out))
=error> "non-character in an unsupported context"))
(provide tests)
(module+ main (tests))

View File

@ -288,13 +288,18 @@
(set! buf-pos (min MAX-LOOKAHEAD buf-max)))
;; Peek (not read) some available bytes:
(let ([got (peek-bytes-avail! buffer buf-pos #f input-port buf-pos BUFFER-SIZE)])
(if (eof-object? got)
(cond
[(eof-object? got)
;; Treat an EOF as a -1 "byte":
(begin
(bytes-set! buffer buf-pos 255)
(set! buf-max (add1 buf-pos)))
(set! buf-max (add1 buf-pos))]
[(fixnum? got)
;; Got normal bytes:
(set! buf-max (+ buf-pos got))))
(set! buf-max (+ buf-pos got))]
[else
(raise-arguments-error 'inflate
"non-character in an unsupported context"
"port" input-port)]))
(READBITS n))
(let ([v (bytes-ref buffer buf-pos)])
(set! buf-pos (add1 buf-pos))

View File

@ -5028,13 +5028,19 @@
len_0))))))
(if (eof-object? n_0)
#f
(if (not (fixnum? n_0))
(raise-arguments-error
'regexp-match
"non-character in an unsupported context"
"port"
(lazy-bytes-in s_0))
(if (zero? n_0)
(begin (set-lazy-bytes-failed?! s_0 #t) #f)
(begin
(set-lazy-bytes-end!
s_0
(+ n_0 len_0 discarded-count_0))
#t))))
#t)))))
(let ((max-peek_0 (lazy-bytes-max-peek s_0)))
(let ((prefix-len_0
(if max-peek_0 (lazy-bytes-prefix-len s_0) #f)))

View File

@ -113,6 +113,10 @@
len))
(cond
[(eof-object? n) #f]
[(not (fixnum? n))
(raise-arguments-error 'regexp-match
"non-character in an unsupported context"
"port" (lazy-bytes-in s))]
[(zero? n)
;; would block or progress evt became ready
(set-lazy-bytes-failed?! s #t)