From dfb572a7bf37d70e46d91d62955fe3e404fdcc58 Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Fri, 27 May 2011 16:09:04 +0200 Subject: [PATCH] Tweak R6RS transcoded ports flushing * libguile/r6rs-ports.c (tp_flush): Only operate on the underlying port when it is open. --- libguile/r6rs-ports.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c index f12af1671..6eff97d5b 100644 --- a/libguile/r6rs-ports.c +++ b/libguile/r6rs-ports.c @@ -1177,12 +1177,21 @@ tp_flush (SCM port) scm_t_port *c_port = SCM_PTAB_ENTRY (port); size_t count = c_port->write_pos - c_port->write_buf; - scm_c_write (binary_port, c_port->write_buf, count); + /* As the runtime will try to flush all ports upon exit, we test for + the underlying port still being open here. Otherwise, when you + would explicitly close the underlying port and the transcoded port + still had data outstanding, you'd get an exception on Guile exit. + + We just throw away the data when the underlying port is closed. */ + + if (SCM_OPOUTPORTP (binary_port)) + scm_c_write (binary_port, c_port->write_buf, count); c_port->write_pos = c_port->write_buf; c_port->rw_active = SCM_PORT_NEITHER; - scm_force_output (binary_port); + if (SCM_OPOUTPORTP (binary_port)) + scm_force_output (binary_port); } static int