diff options
author | Andy Wingo <wingo@pobox.com> | 2011-11-07 20:17:22 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-11-08 00:54:57 +0100 |
commit | 0d959103f985bbb60959c7ef4738235527792e47 (patch) | |
tree | 514c436298c4ed91f308711b1b7fd0f0bfe4eb58 | |
parent | b262d3065c03cbde552cdfbce5819544f2e2dfea (diff) | |
download | guile-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.
-rw-r--r-- | libguile/ports.c | 40 | ||||
-rw-r--r-- | libguile/ports.h | 10 | ||||
-rw-r--r-- | libguile/read.c | 14 |
3 files changed, 45 insertions, 19 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) diff --git a/libguile/ports.h b/libguile/ports.h index d9493e54c..2bb2ac46f 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -305,8 +305,10 @@ SCM_API SCM scm_set_port_revealed_x (SCM port, SCM rcount); SCM_API SCM scm_adjust_port_revealed_x (SCM port, SCM addend); /* Input. */ -SCM_INLINE int scm_get_byte_or_eof (SCM port); -SCM_INLINE int scm_peek_byte_or_eof (SCM port); +SCM_API int scm_get_byte_or_eof (SCM port); +SCM_API int scm_peek_byte_or_eof (SCM port); +SCM_INLINE int scm_get_byte_or_eof_unlocked (SCM port); +SCM_INLINE int scm_peek_byte_or_eof_unlocked (SCM port); SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size); SCM_API scm_t_wchar scm_getc (SCM port); SCM_API SCM scm_read_char (SCM port); @@ -398,7 +400,7 @@ scm_c_unlock_port (SCM port) } SCM_INLINE_IMPLEMENTATION int -scm_get_byte_or_eof (SCM port) +scm_get_byte_or_eof_unlocked (SCM port) { int c; scm_t_port *pt = SCM_PTAB_ENTRY (port); @@ -423,7 +425,7 @@ scm_get_byte_or_eof (SCM port) /* Like `scm_get_byte_or_eof' but does not change PORT's `read_pos'. */ SCM_INLINE_IMPLEMENTATION int -scm_peek_byte_or_eof (SCM port) +scm_peek_byte_or_eof_unlocked (SCM port) { int c; scm_t_port *pt = SCM_PTAB_ENTRY (port); diff --git a/libguile/read.c b/libguile/read.c index 4b9c24864..06decc83d 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -216,7 +216,7 @@ read_token (SCM port, char *buf, const size_t buf_size, size_t *read) { int chr; - chr = scm_get_byte_or_eof (port); + chr = scm_get_byte_or_eof_unlocked (port); if (chr == EOF) return 0; @@ -857,9 +857,9 @@ scm_read_semicolon_comment (int chr, SCM port) /* We use the get_byte here because there is no need to get the locale correct with comment input. This presumes that newline always represents itself no matter what the encoding is. */ - for (c = scm_get_byte_or_eof (port); + for (c = scm_get_byte_or_eof_unlocked (port); (c != EOF) && (c != '\n'); - c = scm_get_byte_or_eof (port)); + c = scm_get_byte_or_eof_unlocked (port)); return SCM_UNSPECIFIED; } @@ -1097,25 +1097,25 @@ static SCM scm_read_shebang (scm_t_wchar chr, SCM port) { int c = 0; - if ((c = scm_get_byte_or_eof (port)) != 'r') + if ((c = scm_get_byte_or_eof_unlocked (port)) != 'r') { scm_ungetc (c, port); return scm_read_scsh_block_comment (chr, port); } - if ((c = scm_get_byte_or_eof (port)) != '6') + if ((c = scm_get_byte_or_eof_unlocked (port)) != '6') { scm_ungetc (c, port); scm_ungetc ('r', port); return scm_read_scsh_block_comment (chr, port); } - if ((c = scm_get_byte_or_eof (port)) != 'r') + if ((c = scm_get_byte_or_eof_unlocked (port)) != 'r') { scm_ungetc (c, port); scm_ungetc ('6', port); scm_ungetc ('r', port); return scm_read_scsh_block_comment (chr, port); } - if ((c = scm_get_byte_or_eof (port)) != 's') + if ((c = scm_get_byte_or_eof_unlocked (port)) != 's') { scm_ungetc (c, port); scm_ungetc ('r', port); |