fix regexp-match when start position is beyond input port EOF

svn: r9629
This commit is contained in:
Matthew Flatt 2008-05-03 14:16:06 +00:00
parent f8c14d0c21
commit aeb79839c6
4 changed files with 32 additions and 3 deletions

View File

@ -1054,13 +1054,22 @@
(test "my cerveza Mi Mi Mi" regexp-replace r2 "mi cerveza Mi Mi Mi" insert) (test "my cerveza Mi Mi Mi" regexp-replace r2 "mi cerveza Mi Mi Mi" insert)
(test "my cerveza My Mi Mi" regexp-replace* r2 "mi cerveza Mi Mi Mi" insert) (test "my cerveza My Mi Mi" regexp-replace* r2 "mi cerveza Mi Mi Mi" insert)
(test "bbb" regexp-replace* "a" "aaa" "b") (test "bbb" regexp-replace* "a" "aaa" "b")
(test '(#"") regexp-match "" (open-input-string "123") 3)
(test '(#"") regexp-match "$" (open-input-string "123") 3)
(test '(#"") regexp-match-peek "" (open-input-string "123") 3)
;; Test weird port offsets: ;; Test weird port offsets:
(define (test-weird-offset regexp-match regexp-match-positions) (define (test-weird-offset regexp-match regexp-match-positions)
(test #f regexp-match "e" (open-input-string "")) (test #f regexp-match "e" (open-input-string ""))
(test #f regexp-match "e" (open-input-string "") (expt 2 100)) (test #f regexp-match "e" (open-input-string "") (expt 2 100))
(test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101)) (test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101))
(test '((3 . 4)) regexp-match-positions "e" (open-input-string "eaae") 2 (expt 2 101))) (test #f regexp-match "e" (open-input-string "") (expt 2 100) (expt 2 101))
(test '((3 . 4)) regexp-match-positions "e" (open-input-string "eaae") 2 (expt 2 101))
(test #f regexp-match "" (open-input-string "123") 4)
(test #f regexp-match-positions "" (open-input-string "123") 4)
(test #f regexp-match "" (open-input-string "123") 999)
(test #f regexp-match-positions "" (open-input-string "123") 999)
(test #f regexp-match "" (open-input-string "123") (expt 2 101)))
(test-weird-offset regexp-match regexp-match-positions) (test-weird-offset regexp-match regexp-match-positions)
(test-weird-offset regexp-match-peek regexp-match-peek-positions) (test-weird-offset regexp-match-peek regexp-match-peek-positions)

View File

@ -184,9 +184,12 @@
(eval `(require 'f)) (eval `(require 'f))
(let ([finished '(f b e a d c b d c b d c b c)]) (let ([finished '(f b e a d c b d c b d c b c)])
(test finished values l) (test finished values l)
(let ([n2 (make-empty-namespace)])
(namespace-attach-module n ''f) (namespace-attach-module n ''f)
(test finished values l) (test finished values l)
(parameterize ([current-namespace (make-empty-namespace)])
(namespace-attach-module n ''f)
(test finished values l)
(namespace-require 'scheme/base)
(eval `(require 'a)) (eval `(require 'a))
(eval `(require 'f)) (eval `(require 'f))
(test finished values l))))) (test finished values l)))))

View File

@ -78,6 +78,10 @@
(values 70 80 90))) (values 70 80 90)))
70 80 90) 70 80 90)
(test/unspec
(when (file-exists? "io-tmp2")
(delete-file "io-tmp2")))
(test (input-port? (current-input-port)) #t) (test (input-port? (current-input-port)) #t)
(test (binary-port? (current-input-port)) #f) (test (binary-port? (current-input-port)) #f)
(test (textual-port? (current-input-port)) #t) (test (textual-port? (current-input-port)) #t)

View File

@ -2434,6 +2434,19 @@ regexec(const char *who,
if (peek) { if (peek) {
peekskip = portstart; peekskip = portstart;
dropped = portstart; dropped = portstart;
/* Make sure that's there's not an EOF before peekskip: */
if (!SAME_OBJ(peekskip, scheme_make_integer(0))) {
char tmp[1];
long got;
got = scheme_get_byte_string_unless("regexp-match", port,
tmp, 0, 1, 1,
1, scheme_bin_minus(peekskip, scheme_make_integer(1)),
unless_evt);
if (got == EOF) {
/* Hit EOF before peekstart, so cannot match */
return 0;
}
}
} else { } else {
/* In non-peek port mode, skip over portstart chars: */ /* In non-peek port mode, skip over portstart chars: */
long amt, got; long amt, got;
@ -2460,7 +2473,7 @@ regexec(const char *who,
if (discard_oport) if (discard_oport)
scheme_put_byte_string(who, discard_oport, drain, 0, got, 0); scheme_put_byte_string(who, discard_oport, drain, 0, got, 0);
dropped = scheme_bin_plus(dropped, scheme_make_integer(amt)); dropped = scheme_bin_plus(dropped, scheme_make_integer(got));
delta = scheme_bin_minus(portstart, dropped); delta = scheme_bin_minus(portstart, dropped);
if (scheme_bin_gt(scheme_make_integer(amt), delta)) if (scheme_bin_gt(scheme_make_integer(amt), delta))
amt = SCHEME_INT_VAL(delta); amt = SCHEME_INT_VAL(delta);