1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Replace scm_getc with scm_getc_unlocked

* libguile/ports.h (scm_getc_unlocked): Remove, or rather rename to
  scm_getc.  This probably introduces some thread-related bugs but we'll
  fix them in a different way.
* libguile/ports.c (scm_getc): Rename from scm_getc_unlocked, replacing
  the locky implementation.
  (scm_read_char): Use scm_getc.
* libguile/r6rs-ports.c (scm_get_string_n_x): Use scm_getc.
* libguile/rdelim.c (scm_read_delimited_x, scm_read_line): Use
  scm_getc.
* libguile/read.c: Use scm_getc.
This commit is contained in:
Andy Wingo 2016-04-22 21:45:55 +02:00
parent 9632b24c4d
commit cd83872df8
5 changed files with 36 additions and 51 deletions

View file

@ -1936,7 +1936,7 @@ get_codepoint (SCM port, scm_t_wchar *codepoint,
/* Read a codepoint from PORT and return it. */ /* Read a codepoint from PORT and return it. */
scm_t_wchar scm_t_wchar
scm_getc_unlocked (SCM port) scm_getc (SCM port)
#define FUNC_NAME "scm_getc" #define FUNC_NAME "scm_getc"
{ {
int err; int err;
@ -1954,20 +1954,6 @@ scm_getc_unlocked (SCM port)
} }
#undef FUNC_NAME #undef FUNC_NAME
scm_t_wchar
scm_getc (SCM port)
{
scm_i_pthread_mutex_t *lock;
scm_t_wchar ret;
scm_c_lock_port (port, &lock);
ret = scm_getc_unlocked (port);
if (lock)
scm_i_pthread_mutex_unlock (lock);
return ret;
}
SCM_DEFINE (scm_read_char, "read-char", 0, 1, 0, SCM_DEFINE (scm_read_char, "read-char", 0, 1, 0,
(SCM port), (SCM port),
"Return the next character available from @var{port}, updating\n" "Return the next character available from @var{port}, updating\n"
@ -1983,7 +1969,7 @@ SCM_DEFINE (scm_read_char, "read-char", 0, 1, 0,
if (SCM_UNBNDP (port)) if (SCM_UNBNDP (port))
port = scm_current_input_port (); port = scm_current_input_port ();
SCM_VALIDATE_OPINPORT (1, port); SCM_VALIDATE_OPINPORT (1, port);
c = scm_getc_unlocked (port); c = scm_getc (port);
if (EOF == c) if (EOF == c)
return SCM_EOF_VAL; return SCM_EOF_VAL;
return SCM_MAKE_CHAR (c); return SCM_MAKE_CHAR (c);

View file

@ -300,7 +300,6 @@ SCM_API int scm_peek_byte_or_eof (SCM port);
SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size); SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size);
SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count); SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count);
SCM_API scm_t_wchar scm_getc (SCM port); SCM_API scm_t_wchar scm_getc (SCM port);
SCM_API scm_t_wchar scm_getc_unlocked (SCM port);
SCM_API SCM scm_read_char (SCM port); SCM_API SCM scm_read_char (SCM port);
/* Pushback. */ /* Pushback. */

View file

@ -1053,7 +1053,7 @@ SCM_DEFINE (scm_get_string_n_x,
for (j = c_start; j < c_end; j++) for (j = c_start; j < c_end; j++)
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
if (c == EOF) if (c == EOF)
{ {
size_t chars_read = j - c_start; size_t chars_read = j - c_start;

View file

@ -79,7 +79,7 @@ SCM_DEFINE (scm_read_delimited_x, "%read-delimited!", 3, 3, 0,
{ {
size_t k; size_t k;
c = scm_getc_unlocked (port); c = scm_getc (port);
for (k = 0; k < num_delims; k++) for (k = 0; k < num_delims; k++)
{ {
if (scm_i_string_ref (delims, k) == c) if (scm_i_string_ref (delims, k) == c)
@ -149,7 +149,7 @@ SCM_DEFINE (scm_read_line, "%read-line", 0, 1, 0,
} }
else else
{ {
buf[index] = scm_getc_unlocked (port); buf[index] = scm_getc (port);
switch (buf[index]) switch (buf[index])
{ {
case EOF: case EOF:

View file

@ -335,7 +335,7 @@ flush_ws (SCM port, scm_t_read_opts *opts, const char *eoferr)
{ {
scm_t_wchar c; scm_t_wchar c;
while (1) while (1)
switch (c = scm_getc_unlocked (port)) switch (c = scm_getc (port))
{ {
case EOF: case EOF:
goteof: goteof:
@ -350,7 +350,7 @@ flush_ws (SCM port, scm_t_read_opts *opts, const char *eoferr)
case ';': case ';':
lp: lp:
switch (c = scm_getc_unlocked (port)) switch (c = scm_getc (port))
{ {
case EOF: case EOF:
goto goteof; goto goteof;
@ -362,7 +362,7 @@ flush_ws (SCM port, scm_t_read_opts *opts, const char *eoferr)
break; break;
case '#': case '#':
switch (c = scm_getc_unlocked (port)) switch (c = scm_getc (port))
{ {
case EOF: case EOF:
eoferr = "read_sharp"; eoferr = "read_sharp";
@ -557,7 +557,7 @@ scm_read_sexp (scm_t_wchar chr, SCM port, scm_t_read_opts *opts)
c = 0; \ c = 0; \
while (i < ndigits) \ while (i < ndigits) \
{ \ { \
a = scm_getc_unlocked (port); \ a = scm_getc (port); \
if (a == EOF) \ if (a == EOF) \
goto str_eof; \ goto str_eof; \
if (terminator \ if (terminator \
@ -587,7 +587,7 @@ skip_intraline_whitespace (SCM port)
do do
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
if (c == EOF) if (c == EOF)
return; return;
} }
@ -614,7 +614,7 @@ scm_read_string_like_syntax (int chr, SCM port, scm_t_read_opts *opts)
long line = SCM_LINUM (port); long line = SCM_LINUM (port);
int column = SCM_COL (port) - 1; int column = SCM_COL (port) - 1;
while (chr != (c = scm_getc_unlocked (port))) while (chr != (c = scm_getc (port)))
{ {
if (c == EOF) if (c == EOF)
{ {
@ -634,7 +634,7 @@ scm_read_string_like_syntax (int chr, SCM port, scm_t_read_opts *opts)
if (c == '\\') if (c == '\\')
{ {
switch (c = scm_getc_unlocked (port)) switch (c = scm_getc (port))
{ {
case EOF: case EOF:
goto str_eof; goto str_eof;
@ -876,7 +876,7 @@ scm_read_quote (int chr, SCM port, scm_t_read_opts *opts)
{ {
scm_t_wchar c; scm_t_wchar c;
c = scm_getc_unlocked (port); c = scm_getc (port);
if ('@' == c) if ('@' == c)
p = scm_sym_uq_splicing; p = scm_sym_uq_splicing;
else else
@ -923,7 +923,7 @@ scm_read_syntax (int chr, SCM port, scm_t_read_opts *opts)
{ {
int c; int c;
c = scm_getc_unlocked (port); c = scm_getc (port);
if ('@' == c) if ('@' == c)
p = sym_unsyntax_splicing; p = sym_unsyntax_splicing;
else else
@ -987,7 +987,7 @@ try_read_ci_chars (SCM port, const char *expected_chars)
while (num_chars_read < num_chars_wanted) while (num_chars_read < num_chars_wanted)
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
if (c == EOF) if (c == EOF)
break; break;
else if (c_tolower (c) != expected_chars[num_chars_read]) else if (c_tolower (c) != expected_chars[num_chars_read])
@ -1049,7 +1049,7 @@ scm_read_character (scm_t_wchar chr, SCM port, scm_t_read_opts *opts)
if (bytes_read == 0) if (bytes_read == 0)
{ {
chr = scm_getc_unlocked (port); chr = scm_getc (port);
if (chr == EOF) if (chr == EOF)
scm_i_input_error (FUNC_NAME, port, "unexpected end of file " scm_i_input_error (FUNC_NAME, port, "unexpected end of file "
"while reading character", SCM_EOL); "while reading character", SCM_EOL);
@ -1181,7 +1181,7 @@ read_decimal_integer (SCM port, int c, ssize_t *resp)
if (c == '-') if (c == '-')
{ {
sign = -1; sign = -1;
c = scm_getc_unlocked (port); c = scm_getc (port);
} }
while ('0' <= c && c <= '9') while ('0' <= c && c <= '9')
@ -1191,7 +1191,7 @@ read_decimal_integer (SCM port, int c, ssize_t *resp)
"number too large", SCM_EOL); "number too large", SCM_EOL);
res = 10*res + c-'0'; res = 10*res + c-'0';
got_it = 1; got_it = 1;
c = scm_getc_unlocked (port); c = scm_getc (port);
} }
if (got_it) if (got_it)
@ -1222,7 +1222,7 @@ scm_read_array (int c, SCM port, scm_t_read_opts *opts, long line, int column)
/* Disambiguate between '#f' and uniform floating point vectors. */ /* Disambiguate between '#f' and uniform floating point vectors. */
if (c == 'f') if (c == 'f')
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
if (c != '3' && c != '6') if (c != '3' && c != '6')
{ {
if (c == 'a' && try_read_ci_chars (port, "lse")) if (c == 'a' && try_read_ci_chars (port, "lse"))
@ -1251,7 +1251,7 @@ scm_read_array (int c, SCM port, scm_t_read_opts *opts, long line, int column)
&& tag_len < sizeof tag_buf / sizeof tag_buf[0]) && tag_len < sizeof tag_buf / sizeof tag_buf[0])
{ {
tag_buf[tag_len++] = c; tag_buf[tag_len++] = c;
c = scm_getc_unlocked (port); c = scm_getc (port);
} }
if (tag_len == 0) if (tag_len == 0)
tag = SCM_BOOL_T; tag = SCM_BOOL_T;
@ -1275,7 +1275,7 @@ scm_read_array (int c, SCM port, scm_t_read_opts *opts, long line, int column)
if (c == '@') if (c == '@')
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
c = read_decimal_integer (port, c, &lbnd); c = read_decimal_integer (port, c, &lbnd);
} }
@ -1283,7 +1283,7 @@ scm_read_array (int c, SCM port, scm_t_read_opts *opts, long line, int column)
if (c == ':') if (c == ':')
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
c = read_decimal_integer (port, c, &len); c = read_decimal_integer (port, c, &len);
if (len < 0) if (len < 0)
scm_i_input_error (NULL, port, scm_i_input_error (NULL, port,
@ -1345,15 +1345,15 @@ static SCM
scm_read_bytevector (scm_t_wchar chr, SCM port, scm_t_read_opts *opts, scm_read_bytevector (scm_t_wchar chr, SCM port, scm_t_read_opts *opts,
long line, int column) long line, int column)
{ {
chr = scm_getc_unlocked (port); chr = scm_getc (port);
if (chr != 'u') if (chr != 'u')
goto syntax; goto syntax;
chr = scm_getc_unlocked (port); chr = scm_getc (port);
if (chr != '8') if (chr != '8')
goto syntax; goto syntax;
chr = scm_getc_unlocked (port); chr = scm_getc (port);
if (chr != '(') if (chr != '(')
goto syntax; goto syntax;
@ -1376,9 +1376,9 @@ scm_read_guile_bit_vector (scm_t_wchar chr, SCM port, scm_t_read_opts *opts,
terribly inefficient but who cares? */ terribly inefficient but who cares? */
SCM s_bits = SCM_EOL; SCM s_bits = SCM_EOL;
for (chr = scm_getc_unlocked (port); for (chr = scm_getc (port);
(chr != EOF) && ((chr == '0') || (chr == '1')); (chr != EOF) && ((chr == '0') || (chr == '1'));
chr = scm_getc_unlocked (port)) chr = scm_getc (port))
{ {
s_bits = scm_cons ((chr == '0') ? SCM_BOOL_F : SCM_BOOL_T, s_bits); s_bits = scm_cons ((chr == '0') ? SCM_BOOL_F : SCM_BOOL_T, s_bits);
} }
@ -1398,7 +1398,7 @@ scm_read_scsh_block_comment (scm_t_wchar chr, SCM port)
for (;;) for (;;)
{ {
int c = scm_getc_unlocked (port); int c = scm_getc (port);
if (c == EOF) if (c == EOF)
scm_i_input_error ("skip_block_comment", port, scm_i_input_error ("skip_block_comment", port,
@ -1431,7 +1431,7 @@ scm_read_shebang (scm_t_wchar chr, SCM port, scm_t_read_opts *opts)
while (i <= READER_DIRECTIVE_NAME_MAX_SIZE) while (i <= READER_DIRECTIVE_NAME_MAX_SIZE)
{ {
c = scm_getc_unlocked (port); c = scm_getc (port);
if (c == EOF) if (c == EOF)
scm_i_input_error ("skip_block_comment", port, scm_i_input_error ("skip_block_comment", port,
"unterminated `#! ... !#' comment", SCM_EOL); "unterminated `#! ... !#' comment", SCM_EOL);
@ -1477,7 +1477,7 @@ scm_read_r6rs_block_comment (scm_t_wchar chr, SCM port)
nested. So care must be taken. */ nested. So care must be taken. */
int nesting_level = 1; int nesting_level = 1;
int a = scm_getc_unlocked (port); int a = scm_getc (port);
if (a == EOF) if (a == EOF)
scm_i_input_error ("scm_read_r6rs_block_comment", port, scm_i_input_error ("scm_read_r6rs_block_comment", port,
@ -1485,7 +1485,7 @@ scm_read_r6rs_block_comment (scm_t_wchar chr, SCM port)
while (nesting_level > 0) while (nesting_level > 0)
{ {
int b = scm_getc_unlocked (port); int b = scm_getc (port);
if (b == EOF) if (b == EOF)
scm_i_input_error ("scm_read_r6rs_block_comment", port, scm_i_input_error ("scm_read_r6rs_block_comment", port,
@ -1537,7 +1537,7 @@ scm_read_extended_symbol (scm_t_wchar chr, SCM port)
buf = scm_i_string_start_writing (buf); buf = scm_i_string_start_writing (buf);
while ((chr = scm_getc_unlocked (port)) != EOF) while ((chr = scm_getc (port)) != EOF)
{ {
if (saw_brace) if (saw_brace)
{ {
@ -1564,7 +1564,7 @@ scm_read_extended_symbol (scm_t_wchar chr, SCM port)
that the extended read syntax would never put a `\' before that the extended read syntax would never put a `\' before
an `x'. For now, we just ignore other instances of an `x'. For now, we just ignore other instances of
backslash in the string. */ backslash in the string. */
switch ((chr = scm_getc_unlocked (port))) switch ((chr = scm_getc (port)))
{ {
case EOF: case EOF:
goto done; goto done;
@ -1653,7 +1653,7 @@ scm_read_sharp (scm_t_wchar chr, SCM port, scm_t_read_opts *opts,
{ {
SCM result; SCM result;
chr = scm_getc_unlocked (port); chr = scm_getc (port);
result = scm_read_sharp_extension (chr, port, opts); result = scm_read_sharp_extension (chr, port, opts);
if (!scm_is_eq (result, SCM_UNSPECIFIED)) if (!scm_is_eq (result, SCM_UNSPECIFIED))
@ -1743,7 +1743,7 @@ read_inner_expression (SCM port, scm_t_read_opts *opts)
{ {
scm_t_wchar chr; scm_t_wchar chr;
chr = scm_getc_unlocked (port); chr = scm_getc (port);
switch (chr) switch (chr)
{ {
@ -1881,7 +1881,7 @@ scm_read_expression (SCM port, scm_t_read_opts *opts)
new expression. For example, f{n - 1}(x) => ((f (- n 1)) x). */ new expression. For example, f{n - 1}(x) => ((f (- n 1)) x). */
for (;;) for (;;)
{ {
int chr = scm_getc_unlocked (port); int chr = scm_getc (port);
if (chr == '(') if (chr == '(')
/* e(...) => (e ...) */ /* e(...) => (e ...) */