summaryrefslogtreecommitdiff
path: root/libguile/ports.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-11-07 20:17:22 +0100
committerAndy Wingo <wingo@pobox.com>2011-11-08 00:54:57 +0100
commit0d959103f985bbb60959c7ef4738235527792e47 (patch)
tree514c436298c4ed91f308711b1b7fd0f0bfe4eb58 /libguile/ports.c
parentb262d3065c03cbde552cdfbce5819544f2e2dfea (diff)
downloadguile-0d959103f985bbb60959c7ef4738235527792e47.tar.gz
threadsafe get-byte-or-eof, peek-byte-or-eof
* libguile/ports.h (scm_get_byte_or_eof_unlocked): (scm_peek_byte_or_eof_unlocked): Rename, adding _unlocked. * libguile/ports.c (scm_get_byte_or_eof, scm_peek_byte_or_eof): Add locking implementations. Adapt callers to use _unlocked variants; they will do locking. * libguile/read.c (read_token, scm_read_semicolon_comment) (scm_read_shebang): Use unlocked variants. We will add locking later.
Diffstat (limited to 'libguile/ports.c')
-rw-r--r--libguile/ports.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/libguile/ports.c b/libguile/ports.c
index c89ae1732..50e73dd35 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1167,6 +1167,30 @@ SCM_DEFINE (scm_adjust_port_revealed_x, "adjust-port-revealed!", 2, 0, 0,
/* Input. */
+int
+scm_get_byte_or_eof (SCM port)
+{
+ int ret;
+
+ scm_c_lock_port (port);
+ ret = scm_get_byte_or_eof_unlocked (port);
+ scm_c_unlock_port (port);
+
+ return ret;
+}
+
+int
+scm_peek_byte_or_eof (SCM port)
+{
+ int ret;
+
+ scm_c_lock_port (port);
+ ret = scm_peek_byte_or_eof_unlocked (port);
+ scm_c_unlock_port (port);
+
+ return ret;
+}
+
/* scm_c_read
*
* Used by an application to read arbitrary number of bytes from an
@@ -1391,7 +1415,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
*len = 0;
pt = SCM_PTAB_ENTRY (port);
- byte = scm_get_byte_or_eof (port);
+ byte = scm_get_byte_or_eof_unlocked (port);
if (byte == EOF)
{
*codepoint = EOF;
@@ -1407,7 +1431,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
else if (buf[0] >= 0xc2 && buf[0] <= 0xdf)
{
/* 2-byte form. */
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY ((byte & 0xc0) != 0x80))
@@ -1423,7 +1447,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
else if ((buf[0] & 0xf0) == 0xe0)
{
/* 3-byte form. */
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY ((byte & 0xc0) != 0x80
@@ -1435,7 +1459,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
buf[1] = (scm_t_uint8) byte;
*len = 2;
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY ((byte & 0xc0) != 0x80))
@@ -1452,7 +1476,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
else if (buf[0] >= 0xf0 && buf[0] <= 0xf4)
{
/* 4-byte form. */
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY (((byte & 0xc0) != 0x80)
@@ -1464,7 +1488,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
buf[1] = (scm_t_uint8) byte;
*len = 2;
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY ((byte & 0xc0) != 0x80))
@@ -1474,7 +1498,7 @@ get_utf8_codepoint (SCM port, scm_t_wchar *codepoint,
buf[2] = (scm_t_uint8) byte;
*len = 3;
- byte = scm_peek_byte_or_eof (port);
+ byte = scm_peek_byte_or_eof_unlocked (port);
ASSERT_NOT_EOF (byte);
if (SCM_UNLIKELY ((byte & 0xc0) != 0x80))
@@ -1529,7 +1553,7 @@ get_iconv_codepoint (SCM port, scm_t_wchar *codepoint,
char *input;
size_t input_left, output_left, done;
- byte_read = scm_get_byte_or_eof (port);
+ byte_read = scm_get_byte_or_eof_unlocked (port);
if (byte_read == EOF)
{
if (bytes_consumed == 0)