1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 22:10:21 +02:00

locking for write, lfwrite

* libguile/ports.c (scm_c_write_unlocked, scm_c_write)
  (scm_lfwrite_unlocked, scm_lfwrite): Add locking and _unlocked
  variants.  Change uses to _unlocked.
This commit is contained in:
Andy Wingo 2011-11-08 00:46:41 +01:00
parent 0607ebbfcf
commit f209aeee9f
6 changed files with 46 additions and 27 deletions

View file

@ -5318,7 +5318,7 @@ int
scm_print_real (SCM sexp, SCM port, scm_print_state *pstate SCM_UNUSED)
{
char num_buf[FLOBUFLEN];
scm_lfwrite (num_buf, iflo2str (sexp, num_buf, 10), port);
scm_lfwrite_unlocked (num_buf, iflo2str (sexp, num_buf, 10), port);
return !0;
}
@ -5326,7 +5326,7 @@ void
scm_i_print_double (double val, SCM port)
{
char num_buf[FLOBUFLEN];
scm_lfwrite (num_buf, idbl2str (val, num_buf, 10), port);
scm_lfwrite_unlocked (num_buf, idbl2str (val, num_buf, 10), port);
}
int
@ -5334,7 +5334,7 @@ scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate SCM_UNUSED)
{
char num_buf[FLOBUFLEN];
scm_lfwrite (num_buf, iflo2str (sexp, num_buf, 10), port);
scm_lfwrite_unlocked (num_buf, iflo2str (sexp, num_buf, 10), port);
return !0;
}
@ -5342,7 +5342,7 @@ void
scm_i_print_complex (double real, double imag, SCM port)
{
char num_buf[FLOBUFLEN];
scm_lfwrite (num_buf, icmplx2str (real, imag, num_buf, 10), port);
scm_lfwrite_unlocked (num_buf, icmplx2str (real, imag, num_buf, 10), port);
}
int
@ -5360,7 +5360,7 @@ scm_bigprint (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
{
char *str = mpz_get_str (NULL, 10, SCM_I_BIG_MPZ (exp));
scm_remember_upto_here_1 (exp);
scm_lfwrite (str, (size_t) strlen (str), port);
scm_lfwrite_unlocked (str, (size_t) strlen (str), port);
free (str);
return !0;
}

View file

@ -355,9 +355,10 @@ SCM_DEFINE (scm_write_objcode, "write-objcode", 2, 0, 0,
cookie[SCM_OBJCODE_ENDIANNESS_OFFSET] = endianness;
cookie[SCM_OBJCODE_WORD_SIZE_OFFSET] = word_size;
scm_c_write (port, cookie, strlen (SCM_OBJCODE_COOKIE));
scm_c_write (port, SCM_OBJCODE_DATA (objcode),
sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode));
scm_c_write_unlocked (port, cookie, strlen (SCM_OBJCODE_COOKIE));
scm_c_write_unlocked (port, SCM_OBJCODE_DATA (objcode),
sizeof (struct scm_objcode)
+ SCM_OBJCODE_TOTAL_LEN (objcode));
return SCM_UNSPECIFIED;
}

View file

@ -2174,7 +2174,7 @@ scm_puts (const char *s, SCM port)
* Warning: Doesn't update port line and column counts!
*/
void
scm_c_write (SCM port, const void *ptr, size_t size)
scm_c_write_unlocked (SCM port, const void *ptr, size_t size)
#define FUNC_NAME "scm_c_write"
{
scm_t_port *pt;
@ -2195,12 +2195,20 @@ scm_c_write (SCM port, const void *ptr, size_t size)
}
#undef FUNC_NAME
void
scm_c_write (SCM port, const void *ptr, size_t size)
{
scm_c_lock_port (port);
scm_c_write_unlocked (port, ptr, size);
scm_c_unlock_port (port);
}
/* scm_lfwrite
*
* This function differs from scm_c_write; it updates port line and
* column. */
void
scm_lfwrite (const char *ptr, size_t size, SCM port)
scm_lfwrite_unlocked (const char *ptr, size_t size, SCM port)
{
scm_t_port *pt = SCM_PTAB_ENTRY (port);
scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (port);
@ -2217,6 +2225,14 @@ scm_lfwrite (const char *ptr, size_t size, SCM port)
pt->rw_active = SCM_PORT_WRITE;
}
void
scm_lfwrite (const char *ptr, size_t size, SCM port)
{
scm_c_lock_port (port);
scm_lfwrite_unlocked (ptr, size, port);
scm_c_unlock_port (port);
}
/* Write STR to PORT from START inclusive to END exclusive. */
void
scm_lfwrite_substr (SCM str, size_t start, size_t end, SCM port)

View file

@ -344,7 +344,9 @@ SCM_INLINE void scm_putc_unlocked (char c, SCM port);
SCM_API void scm_puts (const char *str_data, SCM port);
SCM_INLINE void scm_puts_unlocked (const char *str_data, SCM port);
SCM_API void scm_c_write (SCM port, const void *buffer, size_t size);
SCM_API void scm_c_write_unlocked (SCM port, const void *buffer, size_t size);
SCM_API void scm_lfwrite (const char *ptr, size_t size, SCM port);
SCM_API void scm_lfwrite_unlocked (const char *ptr, size_t size, SCM port);
SCM_INTERNAL void scm_lfwrite_substr (SCM str, size_t start, size_t end,
SCM port);
@ -462,14 +464,14 @@ SCM_INLINE_IMPLEMENTATION void
scm_putc_unlocked (char c, SCM port)
{
SCM_ASSERT_TYPE (SCM_OPOUTPORTP (port), port, 0, NULL, "output port");
scm_lfwrite (&c, 1, port);
scm_lfwrite_unlocked (&c, 1, port);
}
SCM_INLINE_IMPLEMENTATION void
scm_puts_unlocked (const char *s, SCM port)
{
SCM_ASSERT_TYPE (SCM_OPOUTPORTP (port), port, 0, NULL, "output port");
scm_lfwrite (s, strlen (s), port);
scm_lfwrite_unlocked (s, strlen (s), port);
}
#endif /* SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES */

View file

@ -393,7 +393,7 @@ print_extended_symbol (SCM sym, SCM port)
len = scm_i_symbol_length (sym);
strategy = scm_i_get_conversion_strategy (port);
scm_lfwrite ("#{", 2, port);
scm_lfwrite_unlocked ("#{", 2, port);
for (pos = 0; pos < len; pos++)
{
@ -416,7 +416,7 @@ print_extended_symbol (SCM sym, SCM port)
}
}
scm_lfwrite ("}#", 2, port);
scm_lfwrite_unlocked ("}#", 2, port);
}
/* FIXME: allow R6RS hex escapes instead of #{...}#. */
@ -836,7 +836,7 @@ display_string_as_utf8 (const void *str, int narrow_p, size_t len,
/* INPUT was successfully converted, entirely; print the
result. */
scm_lfwrite (utf8_buf, utf8_len, port);
scm_lfwrite_unlocked (utf8_buf, utf8_len, port);
printed += i - printed;
}
@ -897,7 +897,7 @@ display_string_using_iconv (const void *str, int narrow_p, size_t len,
iconv (pt->output_cd, NULL, NULL, NULL, NULL);
/* Print the OUTPUT_LEN bytes successfully converted. */
scm_lfwrite (encoded_output, output_len, port);
scm_lfwrite_unlocked (encoded_output, output_len, port);
/* See how many input codepoints these OUTPUT_LEN bytes
corresponds to. */
@ -932,7 +932,7 @@ display_string_using_iconv (const void *str, int narrow_p, size_t len,
{
/* INPUT was successfully converted, entirely; print the
result. */
scm_lfwrite (encoded_output, output_len, port);
scm_lfwrite_unlocked (encoded_output, output_len, port);
codepoints_read = i - printed;
printed += codepoints_read;
}
@ -1012,7 +1012,7 @@ write_character_escaped (scm_t_wchar ch, int string_escapes_p, SCM port)
/* Use special escapes for some C0 controls. */
buf[0] = '\\';
buf[1] = escapes[ch - 0x07];
scm_lfwrite (buf, 2, port);
scm_lfwrite_unlocked (buf, 2, port);
}
else if (!SCM_R6RS_ESCAPES_P)
{
@ -1022,7 +1022,7 @@ write_character_escaped (scm_t_wchar ch, int string_escapes_p, SCM port)
buf[1] = 'x';
buf[2] = hex[ch / 16];
buf[3] = hex[ch % 16];
scm_lfwrite (buf, 4, port);
scm_lfwrite_unlocked (buf, 4, port);
}
else if (ch <= 0xFFFF)
{
@ -1032,7 +1032,7 @@ write_character_escaped (scm_t_wchar ch, int string_escapes_p, SCM port)
buf[3] = hex[(ch & 0xF00) >> 8];
buf[4] = hex[(ch & 0xF0) >> 4];
buf[5] = hex[(ch & 0xF)];
scm_lfwrite (buf, 6, port);
scm_lfwrite_unlocked (buf, 6, port);
}
else if (ch > 0xFFFF)
{
@ -1044,7 +1044,7 @@ write_character_escaped (scm_t_wchar ch, int string_escapes_p, SCM port)
buf[5] = hex[(ch & 0xF00) >> 8];
buf[6] = hex[(ch & 0xF0) >> 4];
buf[7] = hex[(ch & 0xF)];
scm_lfwrite (buf, 8, port);
scm_lfwrite_unlocked (buf, 8, port);
}
}
else
@ -1067,7 +1067,7 @@ write_character_escaped (scm_t_wchar ch, int string_escapes_p, SCM port)
buf[i] = 'x';
i --;
buf[i] = '\\';
scm_lfwrite (buf + i, 9 - i, port);
scm_lfwrite_unlocked (buf + i, 9 - i, port);
}
}
else
@ -1142,14 +1142,14 @@ void
scm_intprint (scm_t_intmax n, int radix, SCM port)
{
char num_buf[SCM_INTBUFLEN];
scm_lfwrite (num_buf, scm_iint2str (n, radix, num_buf), port);
scm_lfwrite_unlocked (num_buf, scm_iint2str (n, radix, num_buf), port);
}
void
scm_uintprint (scm_t_uintmax n, int radix, SCM port)
{
char num_buf[SCM_INTBUFLEN];
scm_lfwrite (num_buf, scm_iuint2str (n, radix, num_buf), port);
scm_lfwrite_unlocked (num_buf, scm_iuint2str (n, radix, num_buf), port);
}
/* Print an object of unrecognized type.

View file

@ -731,7 +731,7 @@ SCM_DEFINE (scm_put_bytevector, "put-bytevector", 2, 2, 0,
else
c_start = 0, c_count = c_len;
scm_c_write (port, c_bv + c_start, c_count);
scm_c_write_unlocked (port, c_bv + c_start, c_count);
return SCM_UNSPECIFIED;
}
@ -1094,7 +1094,7 @@ make_tp (SCM binary_port, unsigned long mode)
static void
tp_write (SCM port, const void *data, size_t size)
{
scm_c_write (SCM_TP_BINARY_PORT (port), data, size);
scm_c_write_unlocked (SCM_TP_BINARY_PORT (port), data, size);
}
static int
@ -1149,7 +1149,7 @@ tp_flush (SCM port)
We just throw away the data when the underlying port is closed. */
if (SCM_OPOUTPORTP (binary_port))
scm_c_write (binary_port, c_port->write_buf, count);
scm_c_write_unlocked (binary_port, c_port->write_buf, count);
c_port->write_pos = c_port->write_buf;
c_port->rw_active = SCM_PORT_NEITHER;