mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 22:10:21 +02:00
scm_setvbuf doesn't throw away current buffers
* libguile/ports.c (scm_drain_input): Slight optimization. * libguile/fports.c (scm_setvbuf): If there is buffered output, flush it. If there is input, drain it, and then unread it after updating the buffers. Much more sensible than dropping it silently...
This commit is contained in:
parent
4595600a08
commit
67a72dc13c
2 changed files with 21 additions and 3 deletions
|
@ -170,6 +170,7 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
|||
{
|
||||
int cmode;
|
||||
long csize;
|
||||
SCM drained;
|
||||
scm_t_port *pt;
|
||||
|
||||
port = SCM_COERCE_OUTPORT (port);
|
||||
|
@ -205,7 +206,14 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
|||
|
||||
pt = SCM_PTAB_ENTRY (port);
|
||||
|
||||
/* silently discards buffered and put-back chars. */
|
||||
if (SCM_INPUT_PORT_P (port))
|
||||
drained = scm_drain_input (port);
|
||||
else
|
||||
drained = scm_nullstr;
|
||||
|
||||
if (SCM_OUTPUT_PORT_P (port))
|
||||
scm_flush (port);
|
||||
|
||||
if (pt->read_buf == pt->putback_buf)
|
||||
{
|
||||
pt->read_buf = pt->saved_read_buf;
|
||||
|
@ -219,6 +227,10 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
|||
scm_gc_free (pt->write_buf, pt->write_buf_size, "port buffer");
|
||||
|
||||
scm_fport_buffer_add (port, csize, csize);
|
||||
|
||||
if (scm_is_true (drained) && scm_c_string_length (drained))
|
||||
scm_unread_string (drained, port);
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
|
|
@ -347,8 +347,14 @@ SCM_DEFINE (scm_drain_input, "drain-input", 1, 0, 0,
|
|||
if (pt->read_buf == pt->putback_buf)
|
||||
count += pt->saved_read_end - pt->saved_read_pos;
|
||||
|
||||
result = scm_i_make_string (count, &data);
|
||||
scm_take_from_input_buffers (port, data, count);
|
||||
if (count)
|
||||
{
|
||||
result = scm_i_make_string (count, &data);
|
||||
scm_take_from_input_buffers (port, data, count);
|
||||
}
|
||||
else
|
||||
result = scm_nullstr;
|
||||
|
||||
return result;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue