summaryrefslogtreecommitdiff
path: root/libguile/ports-internal.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-04-18 00:19:24 +0200
committerAndy Wingo <wingo@pobox.com>2016-04-18 00:19:24 +0200
commit10dc6d043e0b76f36461f0a04160a4d2f411413e (patch)
tree8db15c2fc01ec50601aa6442ad63aad0a07a65b9 /libguile/ports-internal.h
parentb869344a4f238ad66ab33e08de5c7b66ed823fc3 (diff)
downloadguile-10dc6d043e0b76f36461f0a04160a4d2f411413e.tar.gz
Remove "buf" field from port buffers
* libguile/ports-internal.h (scm_port_buffer_reset_end): New helper. (scm_port_buffer_putback): New helper. * libguile/ports.h (scm_t_port_buffer): Remove "buf" field. (scm_get_byte_or_eof_unlocked, scm_peek_byte_or_eof_unlocked): Adapt. * libguile/ports.c (scm_c_make_port_buffer): No more "buf" field. (scm_i_unget_bytes_unlocked): Use helper. * libguile/read.c (scm_i_scan_for_encoding): No more "buf" field.
Diffstat (limited to 'libguile/ports-internal.h')
-rw-r--r--libguile/ports-internal.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/libguile/ports-internal.h b/libguile/ports-internal.h
index b3f15e187..14d00c2a6 100644
--- a/libguile/ports-internal.h
+++ b/libguile/ports-internal.h
@@ -22,6 +22,8 @@
#ifndef SCM_PORTS_INTERNAL
#define SCM_PORTS_INTERNAL
+#include <assert.h>
+
#include "libguile/_scm.h"
#include "libguile/ports.h"
@@ -37,6 +39,12 @@ scm_port_buffer_reset (scm_t_port_buffer *buf)
buf->cur = buf->end = 0;
}
+static inline void
+scm_port_buffer_reset_end (scm_t_port_buffer *buf)
+{
+ buf->cur = buf->end = scm_port_buffer_size (buf);
+}
+
static inline size_t
scm_port_buffer_can_take (scm_t_port_buffer *buf)
{
@@ -96,6 +104,18 @@ scm_port_buffer_put (scm_t_port_buffer *buf, const scm_t_uint8 *src,
return count;
}
+static inline void
+scm_port_buffer_putback (scm_t_port_buffer *buf, const scm_t_uint8 *src,
+ size_t count)
+{
+ assert (count <= 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);
+}
+
enum scm_port_encoding_mode {
SCM_PORT_ENCODING_MODE_UTF8,
SCM_PORT_ENCODING_MODE_LATIN1,