fixing bug in flushed output on custom ports

This commit is contained in:
Alex Shinn 2018-06-23 19:21:38 +08:00
parent f16e889e04
commit f5a228ee9e
2 changed files with 15 additions and 1 deletions

View file

@ -179,7 +179,7 @@
(lambda (bv start end)
(do ((i start (+ i 1))
(x 0 (+ x (bytevector-u8-ref bv i))))
((= i end) (set! sum x)))))))
((= i end) (set! sum (+ sum x))))))))
(write-bytevector #u8(0 1 2 3) out)
(flush-output out)
(test 6 sum)
@ -187,6 +187,19 @@
(flush-output out)
(test 106 sum))
(let* ((ls '())
(out (make-custom-output-port
(lambda (str start end)
(set! ls (cons (substring str start end) ls))
(- end start)))))
(display "Test1\n" out)
(flush-output out)
(display "Test2\n" out)
(flush-output out)
(display "Test3\n" out)
(flush-output out)
(test "Test1\nTest2\nTest3\n" (string-concatenate (reverse ls))))
(test "file-position"
'(0 1 2)
(let* ((p (open-input-file "/etc/passwd"))

1
sexp.c
View file

@ -1471,6 +1471,7 @@ int sexp_buffered_flush (sexp ctx, sexp p, int forcep) {
tmp = sexp_list2(ctx, SEXP_ZERO, sexp_make_fixnum(sexp_port_offset(p)));
tmp = sexp_cons(ctx, sexp_port_binaryp(p) ? sexp_string_bytes(sexp_port_buffer(p)) : sexp_port_buffer(p), tmp);
tmp = sexp_apply(ctx, sexp_port_writer(p), tmp);
sexp_port_offset(p) = 0;
res = (sexp_fixnump(tmp) && sexp_unbox_fixnum(tmp) > 0) ? 0 : -1;
} else { /* string port */
tmp = sexp_c_string(ctx, sexp_port_buf(p), off);