diff options
author | Andreas Rottmann <a.rottmann@gmx.at> | 2011-05-27 16:09:04 +0200 |
---|---|---|
committer | Andreas Rottmann <a.rottmann@gmx.at> | 2011-05-27 16:09:04 +0200 |
commit | dfb572a7bf37d70e46d91d62955fe3e404fdcc58 (patch) | |
tree | 91fc4be6e3b0e5fc57699586b817e35c7c70af43 | |
parent | 0687e826a12e45cec9fcf14ed642f176d230afb9 (diff) | |
download | guile-dfb572a7bf37d70e46d91d62955fe3e404fdcc58.tar.gz |
Tweak R6RS transcoded ports flushing
* libguile/r6rs-ports.c (tp_flush): Only operate on the underlying port
when it is open.
-rw-r--r-- | libguile/r6rs-ports.c | 13 |
1 files 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 |