From e3553c49506965be4c1d1c9d7e2e5be6bb6525a7 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 8 May 2018 21:56:42 -0700 Subject: [PATCH] Implement replace-binary-port! on generic I/O ports. --- src/runtime/generic-io.scm | 28 ++++++++++++++++++++++++++-- src/runtime/runtime.pkg | 3 ++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/runtime/generic-io.scm b/src/runtime/generic-io.scm index 21e56c92d..1d8b6d9df 100644 --- a/src/runtime/generic-io.scm +++ b/src/runtime/generic-io.scm @@ -107,8 +107,8 @@ USA. (define-record-type (%make-gstate input-buffer output-buffer coder-name normalizer-name extra) gstate? - (input-buffer gstate-input-buffer) - (output-buffer gstate-output-buffer) + (input-buffer gstate-input-buffer set-gstate-input-buffer!) + (output-buffer gstate-output-buffer set-gstate-output-buffer!) (coder-name gstate-coder-name set-gstate-coder-name!) (normalizer-name gstate-normalizer-name @@ -130,6 +130,30 @@ USA. (guarantee index-fixnum? index 'generic-i/o-port-modifier) (lambda (port object) (vector-set! (gstate-extra (textual-port-state port)) index object))) + +(define (replace-binary-port! port binary-port) + (let ((gstate (textual-port-state port))) + (set-gstate-input-buffer! + gstate + (and (binary-input-port? binary-port) + (let ((buffer + (make-input-buffer binary-port + (gstate-coder-name gstate) + (gstate-normalizer-name gstate) + 'replace-binary-port!))) + + (set-input-buffer-port! buffer port) + buffer))) + (set-gstate-output-buffer! + gstate + (and (binary-output-port? binary-port) + (let ((buffer + (make-output-buffer binary-port + (gstate-coder-name gstate) + (gstate-normalizer-name gstate) + 'gstate-replace-binary-port!))) + (set-output-buffer-port! buffer port) + buffer))))) (define generic-type00) (define generic-type10) diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index b94da19af..fbae99218 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -2335,7 +2335,8 @@ USA. generic-io/set-buffer-contents generic-io/unread-char make-generic-i/o-port - make-gstate) + make-gstate + replace-binary-port!) (export (runtime file-i/o-port) generic-i/o-port->binary-port generic-i/o-port-type -- 2.25.1