週刊nmosh - 改行コードの変換 / Customポートの怪
全然週刊じゃない! ...年内に1リリースはしたいところだが。。
R7RSライブラリをDraft 7相当に更新、現在Chibi-schemeのtest suiteで150/1009 Fail。殆どはexact/inexact mismatchとreader関連。
改行コードの変換
nmoshは伝統的にutf8→stringで改行コードを\nに正規化していたが、これをやめてverbatimに出力されるようにした。これはindustriaライブラリのIRCテストで発覚。
(utf8->string #vu8(13 10) ;; => "\r\n" or "\n" ?
R6RS的にはこの辺の挙動は未定義で、素直に実装する つまり、utf8→stringの度にUTF-8のtranscoderを生成するなら、\nになるのが自然な気もする。
ただ、通常の人間はutf8→stringやstring→utf8をbytevector表現のASCII文字列をScheme文字列に変換する目的で使うので、control sequenceの類は変換しないのが期待値というのもそれなりに理解できる。
Customポートの怪
さらにIndustriaのテストで発覚した問題に、customポートでclose手続きが呼ばれないというものがある。
簡単なテスト:
(import (rnrs)) (define (gen-err) (error 'gen-err "GEN-ERR")) (define (error-on-close) (gen-err)) (define (bogus-rw . b) #t) (define (closetest p) (write (guard (c ((and (message-condition? c) (string=? (condition-message c) "GEN-ERR")) 'ok-closetest)) (close-port p))) (newline)) (define (check) (define ti (make-custom-textual-input-port "ti" bogus-rw #f #f error-on-close)) (define bi (make-custom-binary-input-port "bi" bogus-rw #f #f error-on-close)) (define to (make-custom-textual-output-port "to" bogus-rw #f #f error-on-close)) (define bo (make-custom-binary-output-port "bo" bogus-rw #f #f error-on-close)) (define tio (make-custom-textual-input/output-port "tio" bogus-rw bogus-rw #f #f error-on-close)) (define bio (make-custom-binary-input/output-port "bio" bogus-rw bogus-rw #f #f error-on-close)) (closetest ti) (closetest bi) (closetest to) (closetest bo) (closetest tio) (closetest bio)) (check)
nmoshだとcustom-text-input-portでしかclose手続きが呼ばれない。Racketのような他のR6RSでは呼ばれるので明確にこれはバグな気がするが。。
ちゃんとcloseに割り当てた手続きを呼ぶコードは全部の組み合わせで書かれているので、何らかの理由でこれらのC++側のコードが呼ばれてこないことになる。