summaryrefslogtreecommitdiff
path: root/libguile/ports-internal.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-04-19 19:50:21 +0200
committerAndy Wingo <wingo@pobox.com>2016-04-19 20:02:05 +0200
commitffb4347d5330fbd2b3e78d761613955f83aeef3d (patch)
treee4e0d3fa781937bf3ecb93a29e93c67ad98c64b9 /libguile/ports-internal.h
parent10dc6d043e0b76f36461f0a04160a4d2f411413e (diff)
Port buffer cur/next pointers are Scheme values
* libguile/ports.h (scm_t_port_buffer): Change "cur" and "end" members to be SCM values, in preparation for changing port buffers to be Scheme vectors. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt. * libguile/ports.c (scm_c_make_port_buffer): Initialize cur and end members. (looking_at_bytes): Use helper instead of incrementing cur. (scm_i_read_unlocked): Adapt to end type change. (CONSUME_PEEKED_BYTE): Use helper instead of incrementing cur. (scm_i_unget_bytes_unlocked): Use helper instead of comparing cur. (scm_i_write_unlocked): Fix for changing end/cur types. * libguile/read.c (scm_i_scan_for_encoding): Use helpers instead of addressing cursors directly. * libguile/rw.c (scm_write_string_partial): Likewise. * libguile/ports-internal.h (scm_port_buffer_reset): (scm_port_buffer_reset_end, scm_port_buffer_can_take): (scm_port_buffer_can_put, scm_port_buffer_can_putback): (scm_port_buffer_did_take, scm_port_buffer_did_put): (scm_port_buffer_take_pointer, scm_port_buffer_put_pointer): (scm_port_buffer_putback): Adapt to data types.
Diffstat (limited to 'libguile/ports-internal.h')
-rw-r--r--libguile/ports-internal.h29
1 files changed, 18 insertions, 11 deletions
diff --git a/libguile/ports-internal.h b/libguile/ports-internal.h
index 14d00c2a6..862d85800 100644
--- a/libguile/ports-internal.h
+++ b/libguile/ports-internal.h
@@ -36,51 +36,57 @@ scm_port_buffer_size (scm_t_port_buffer *buf)
static inline void
scm_port_buffer_reset (scm_t_port_buffer *buf)
{
- buf->cur = buf->end = 0;
+ buf->cur = buf->end = SCM_INUM0;
}
static inline void
scm_port_buffer_reset_end (scm_t_port_buffer *buf)
{
- buf->cur = buf->end = scm_port_buffer_size (buf);
+ buf->cur = buf->end = scm_from_size_t (scm_port_buffer_size (buf));
}
static inline size_t
scm_port_buffer_can_take (scm_t_port_buffer *buf)
{
- return buf->end - buf->cur;
+ return scm_to_size_t (buf->end) - scm_to_size_t (buf->cur);
}
static inline size_t
scm_port_buffer_can_put (scm_t_port_buffer *buf)
{
- return scm_port_buffer_size (buf) - buf->end;
+ return scm_port_buffer_size (buf) - scm_to_size_t (buf->end);
+}
+
+static inline size_t
+scm_port_buffer_can_putback (scm_t_port_buffer *buf)
+{
+ return scm_to_size_t (buf->cur);
}
static inline void
scm_port_buffer_did_take (scm_t_port_buffer *buf, size_t count)
{
- buf->cur += count;
+ buf->cur = scm_from_size_t (scm_to_size_t (buf->cur) + count);
}
static inline void
scm_port_buffer_did_put (scm_t_port_buffer *buf, size_t count)
{
- buf->end += count;
+ buf->end = scm_from_size_t (scm_to_size_t (buf->end) + count);
}
static inline const scm_t_uint8 *
scm_port_buffer_take_pointer (scm_t_port_buffer *buf)
{
signed char *ret = SCM_BYTEVECTOR_CONTENTS (buf->bytevector);
- return ((scm_t_uint8 *) ret) + buf->cur;
+ return ((scm_t_uint8 *) ret) + scm_to_size_t (buf->cur);
}
static inline scm_t_uint8 *
scm_port_buffer_put_pointer (scm_t_port_buffer *buf)
{
signed char *ret = SCM_BYTEVECTOR_CONTENTS (buf->bytevector);
- return ((scm_t_uint8 *) ret) + buf->end;
+ return ((scm_t_uint8 *) ret) + scm_to_size_t (buf->end);
}
static inline size_t
@@ -108,12 +114,13 @@ static inline void
scm_port_buffer_putback (scm_t_port_buffer *buf, const scm_t_uint8 *src,
size_t count)
{
- assert (count <= buf->cur);
+ assert (count <= scm_to_size_t (buf->cur));
/* Sometimes used to move around data within a buffer, so we must use
memmove. */
- buf->cur -= count;
- memmove (SCM_BYTEVECTOR_CONTENTS (buf->bytevector) + buf->cur, src, count);
+ buf->cur = scm_from_size_t (scm_to_size_t (buf->cur) - count);
+ memmove (SCM_BYTEVECTOR_CONTENTS (buf->bytevector) + scm_to_size_t (buf->cur),
+ src, count);
}
enum scm_port_encoding_mode {