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

Remove port rw_active field

* libguile/ports.h (scm_t_port_rw_active): Move type definition to
  ports-internal.h.
  (scm_t_port): Remove rw_active field.  It's sufficient to check the
  port buffer cursors.
* libguile/read.c (scm_i_scan_for_encoding): Just call
  scm_flush_unlocked; it's idempotent.
* libguile/ports.c (scm_c_make_port_with_encoding): Remove rw_active
  field.
  (scm_c_read_bytes_unlocked, scm_c_read, scm_i_unget_bytes_unlocked)
  (scm_end_input_unlocked, scm_flush_unlocked, scm_fill_input_unlocked)
  (scm_port_write_buffer, scm_port_read_buffer)
  (scm_c_write_bytes_unlocked, scm_c_write_unlocked, scm_seek): Remove
  management of rw_active field.
This commit is contained in:
Andy Wingo 2016-04-22 21:08:30 +02:00
parent 4934b69ddf
commit 69a1b83f31
4 changed files with 17 additions and 70 deletions

View file

@ -232,6 +232,12 @@ typedef struct scm_port_internal scm_t_port_internal;
#define SCM_PORT_GET_INTERNAL(x) (SCM_PTAB_ENTRY(x)->internal)
typedef enum scm_t_port_rw_active {
SCM_PORT_NEITHER = 0,
SCM_PORT_READ = 1,
SCM_PORT_WRITE = 2
} scm_t_port_rw_active;
SCM_INTERNAL scm_t_iconv_descriptors *
scm_i_port_iconv_descriptors (SCM port, scm_t_port_rw_active mode);

View file

@ -698,7 +698,6 @@ scm_c_make_port_with_encoding (scm_t_bits tag, unsigned long mode_bits,
/* By default, any port type with a seek function has random-access
ports. */
entry->rw_random = ptob->seek != NULL;
entry->rw_active = SCM_PORT_NEITHER;
entry->port = ret;
entry->stream = stream;
@ -1502,11 +1501,7 @@ scm_c_read_bytes_unlocked (SCM port, SCM dst, size_t start, size_t count)
read_buf = pt->read_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_WRITE)
scm_flush_unlocked (port);
pt->rw_active = SCM_PORT_READ;
}
scm_flush_unlocked (port);
/* Take bytes first from the port's read buffer. */
{
@ -1569,16 +1564,7 @@ scm_c_read (SCM port, void *buffer, size_t size)
read_buf = pt->read_buf;
if (pt->rw_random)
{
int needs_flush;
scm_i_pthread_mutex_lock (pt->lock);
needs_flush = pt->rw_active == SCM_PORT_WRITE;
pt->rw_active = SCM_PORT_READ;
scm_i_pthread_mutex_unlock (pt->lock);
if (needs_flush)
scm_flush (port);
}
scm_flush (port);
while (copied < size)
{
@ -2033,11 +2019,7 @@ scm_i_unget_bytes_unlocked (const scm_t_uint8 *buf, size_t len, SCM port)
SCM read_buf = pt->read_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_WRITE)
scm_flush_unlocked (port);
pt->rw_active = SCM_PORT_READ;
}
scm_flush_unlocked (port);
if (scm_port_buffer_can_putback (read_buf) < len)
{
@ -2488,7 +2470,6 @@ scm_end_input_unlocked (SCM port)
if (discarded != 0)
SCM_PORT_DESCRIPTOR (port)->seek (port, -discarded, SEEK_CUR);
pt->rw_active = SCM_PORT_NEITHER;
}
void
@ -2531,7 +2512,6 @@ scm_flush_unlocked (SCM port)
SCM buf = SCM_PTAB_ENTRY (port)->write_buf;
if (scm_port_buffer_can_take (buf))
scm_i_write_unlocked (port, buf);
SCM_PTAB_ENTRY (port)->rw_active = SCM_PORT_NEITHER;
}
void
@ -2555,11 +2535,7 @@ scm_fill_input_unlocked (SCM port)
return read_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_WRITE)
scm_flush_unlocked (pt->port);
pt->rw_active = SCM_PORT_READ;
}
scm_flush_unlocked (pt->port);
/* It could be that putback caused us to enlarge the buffer; now that
we've read all the bytes we need to shrink it again. */
@ -2587,11 +2563,7 @@ SCM_DEFINE (scm_port_read_buffer, "port-read-buffer", 1, 0, 0,
pt = SCM_PTAB_ENTRY (port);
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_WRITE)
scm_flush (pt->port);
pt->rw_active = SCM_PORT_READ;
}
scm_flush (pt->port);
return pt->read_buf;
}
@ -2611,11 +2583,7 @@ SCM_DEFINE (scm_port_write_buffer, "port-write-buffer", 1, 0, 0,
pt = SCM_PTAB_ENTRY (port);
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_READ)
scm_end_input (pt->port);
pt->rw_active = SCM_PORT_WRITE;
}
scm_end_input (pt->port);
return pt->write_buf;
}
@ -2698,11 +2666,7 @@ scm_c_write_bytes_unlocked (SCM port, SCM src, size_t start, size_t count)
write_buf = pt->write_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_READ)
scm_end_input_unlocked (port);
pt->rw_active = SCM_PORT_WRITE;
}
scm_end_input_unlocked (port);
if (count < scm_port_buffer_size (write_buf))
{
@ -2759,11 +2723,7 @@ scm_c_write_unlocked (SCM port, const void *ptr, size_t size)
write_buf = pt->write_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_READ)
scm_end_input_unlocked (port);
pt->rw_active = SCM_PORT_WRITE;
}
scm_end_input_unlocked (port);
while (written < size)
{
@ -2937,11 +2897,8 @@ SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
/* FIXME: Avoid flushing buffers for SEEK_CUR with an offset of
0. */
if (pt->rw_active == SCM_PORT_READ)
scm_end_input_unlocked (pt->port);
else if (pt->rw_active == SCM_PORT_WRITE)
scm_flush_unlocked (pt->port);
pt->rw_active = SCM_PORT_NEITHER;
scm_end_input_unlocked (pt->port);
scm_flush_unlocked (pt->port);
rv = ptob->seek (fd_port, off, how);

View file

@ -41,13 +41,6 @@
/* values for the rw_active flag. */
typedef enum scm_t_port_rw_active {
SCM_PORT_NEITHER = 0,
SCM_PORT_READ = 1,
SCM_PORT_WRITE = 2
} scm_t_port_rw_active;
/* An internal-only structure defined in ports-internal.h. */
struct scm_port_internal;
@ -123,11 +116,6 @@ typedef struct
and so on. */
int rw_random;
/* For random access ports, indicates which of the buffers is
currently in use. Can be SCM_PORT_WRITE, SCM_PORT_READ, or
SCM_PORT_NEITHER. */
scm_t_port_rw_active rw_active;
/* Character encoding support. */
char *encoding;
scm_t_string_failed_conversion_handler ilseq_handler;

View file

@ -2068,11 +2068,7 @@ scm_i_scan_for_encoding (SCM port)
buf = pt->read_buf;
if (pt->rw_random)
{
if (pt->rw_active == SCM_PORT_WRITE)
scm_flush_unlocked (port);
pt->rw_active = SCM_PORT_READ;
}
scm_flush_unlocked (port);
if (scm_port_buffer_can_take (buf) == 0)
{