1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-21 12:10:26 +02:00

Add a static version of 'scm_fill_input' to ports.c.

* libguile/ports.c (scm_i_fill_input): New static function, containing
  the code that was previously in 'scm_fill_input'.
  (scm_fill_input): Simply call 'scm_i_fill_input'.
  (scm_c_read): Use 'scm_i_fill_input'.
This commit is contained in:
Mark H Weaver 2013-04-02 13:33:14 -04:00
parent 05d7f76296
commit 187fa0b9e7

View file

@ -1419,8 +1419,8 @@ scm_getc (SCM port)
/* this should only be called when the read buffer is empty. it /* this should only be called when the read buffer is empty. it
tries to refill the read buffer. it returns the first char from tries to refill the read buffer. it returns the first char from
the port, which is either EOF or *(pt->read_pos). */ the port, which is either EOF or *(pt->read_pos). */
int static int
scm_fill_input (SCM port) scm_i_fill_input (SCM port)
{ {
scm_t_port *pt = SCM_PTAB_ENTRY (port); scm_t_port *pt = SCM_PTAB_ENTRY (port);
@ -1439,6 +1439,12 @@ scm_fill_input (SCM port)
return scm_ptobs[SCM_PTOBNUM (port)].fill_input (port); return scm_ptobs[SCM_PTOBNUM (port)].fill_input (port);
} }
int
scm_fill_input (SCM port)
{
return scm_i_fill_input (port);
}
/* scm_lfwrite /* scm_lfwrite
* *
@ -1547,8 +1553,8 @@ scm_c_read (SCM port, void *buffer, size_t size)
if (size == 0) if (size == 0)
return n_read; return n_read;
/* Now we will call scm_fill_input repeatedly until we have read the /* Now we will call scm_i_fill_input repeatedly until we have read the
requested number of bytes. (Note that a single scm_fill_input requested number of bytes. (Note that a single scm_i_fill_input
call does not guarantee to fill the whole of the port's read call does not guarantee to fill the whole of the port's read
buffer.) */ buffer.) */
if (pt->read_buf_size <= 1 && pt->encoding == NULL) if (pt->read_buf_size <= 1 && pt->encoding == NULL)
@ -1556,12 +1562,12 @@ scm_c_read (SCM port, void *buffer, size_t size)
/* The port that we are reading from is unbuffered - i.e. does /* The port that we are reading from is unbuffered - i.e. does
not have its own persistent buffer - but we have a buffer, not have its own persistent buffer - but we have a buffer,
provided by our caller, that is the right size for the data provided by our caller, that is the right size for the data
that is wanted. For the following scm_fill_input calls, that is wanted. For the following scm_i_fill_input calls,
therefore, we use the buffer in hand as the port's read therefore, we use the buffer in hand as the port's read
buffer. buffer.
We need to make sure that the port's normal (1 byte) buffer We need to make sure that the port's normal (1 byte) buffer
is reinstated in case one of the scm_fill_input () calls is reinstated in case one of the scm_i_fill_input () calls
throws an exception; we use the scm_dynwind_* API to achieve throws an exception; we use the scm_dynwind_* API to achieve
that. that.
@ -1578,9 +1584,9 @@ scm_c_read (SCM port, void *buffer, size_t size)
scm_dynwind_rewind_handler (swap_buffer, &psb, SCM_F_WIND_EXPLICITLY); scm_dynwind_rewind_handler (swap_buffer, &psb, SCM_F_WIND_EXPLICITLY);
scm_dynwind_unwind_handler (swap_buffer, &psb, SCM_F_WIND_EXPLICITLY); scm_dynwind_unwind_handler (swap_buffer, &psb, SCM_F_WIND_EXPLICITLY);
/* Call scm_fill_input until we have all the bytes that we need, /* Call scm_i_fill_input until we have all the bytes that we need,
or we hit EOF. */ or we hit EOF. */
while (pt->read_buf_size && (scm_fill_input (port) != EOF)) while (pt->read_buf_size && (scm_i_fill_input (port) != EOF))
{ {
pt->read_buf_size -= (pt->read_end - pt->read_pos); pt->read_buf_size -= (pt->read_end - pt->read_pos);
pt->read_pos = pt->read_buf = pt->read_end; pt->read_pos = pt->read_buf = pt->read_end;
@ -1604,7 +1610,7 @@ scm_c_read (SCM port, void *buffer, size_t size)
that a custom port implementation's entry points (in that a custom port implementation's entry points (in
particular, fill_input) can rely on the buffer always being particular, fill_input) can rely on the buffer always being
the same as they first set up. */ the same as they first set up. */
while (size && (scm_fill_input (port) != EOF)) while (size && (scm_i_fill_input (port) != EOF))
{ {
n_available = min (size, pt->read_end - pt->read_pos); n_available = min (size, pt->read_end - pt->read_pos);
memcpy (buffer, pt->read_pos, n_available); memcpy (buffer, pt->read_pos, n_available);