diff options
author | Andy Wingo <wingo@pobox.com> | 2012-02-14 14:30:48 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2012-02-17 12:11:35 +0100 |
commit | 8dfb7bbfd908ca883d0fdd0d868e13e6b20803ae (patch) | |
tree | a9de6d013851758e47cab732e79039b51c44187a /libguile/bytevectors.c | |
parent | 6a97b1f93aace5c7c976aef51d36b3ae9cfd5630 (diff) | |
download | guile-8dfb7bbfd908ca883d0fdd0d868e13e6b20803ae.tar.gz |
wrap iconv_open / iconv_close with a lock to help in thread/fork issues
* libguile/bytevectors.c (STRING_TO_UTF, scm_string_to_utf8)
(UTF_TO_STRING):
* libguile/ports.c (open_iconv_descriptors, close_iconv_descriptors):
* libguile/strings.c (scm_from_stringn, scm_to_stringn): Wrap operations
that acquire and destroy iconv contexts with a mutex. While iconv is
threadsafe, internally it uses a lock, and we need to make sure when
we fork() that no one has that lock -- so we surround it with another
one. Gross.
Diffstat (limited to 'libguile/bytevectors.c')
-rw-r--r-- | libguile/bytevectors.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 668c46d17..6ea60f823 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -1934,10 +1934,12 @@ utf_encoding_name (char *name, size_t utf_width, SCM endianness) c_strlen = scm_i_string_length (str); \ if (scm_i_is_narrow_string (str)) \ { \ + scm_i_lock_iconv (); \ err = mem_iconveh (scm_i_string_chars (str), c_strlen, \ "ISO-8859-1", c_utf_name, \ iconveh_question_mark, NULL, \ &c_utf, &c_utf_len); \ + scm_i_unlock_iconv (); \ if (SCM_UNLIKELY (err)) \ scm_syserror_msg (FUNC_NAME, "failed to convert string: ~A", \ scm_list_1 (str), err); \ @@ -1945,10 +1947,12 @@ utf_encoding_name (char *name, size_t utf_width, SCM endianness) else \ { \ const scm_t_wchar *wbuf = scm_i_string_wide_chars (str); \ + scm_i_lock_iconv (); \ c_utf = u32_conv_to_encoding (c_utf_name, \ iconveh_question_mark, \ (scm_t_uint32 *) wbuf, \ c_strlen, NULL, NULL, &c_utf_len); \ + scm_i_unlock_iconv (); \ if (SCM_UNLIKELY (c_utf == NULL)) \ scm_syserror_msg (FUNC_NAME, "failed to convert string: ~A", \ scm_list_1 (str), errno); \ @@ -2050,10 +2054,12 @@ SCM_DEFINE (scm_string_to_utf32, "string->utf32", c_utf = (char *) SCM_BYTEVECTOR_CONTENTS (utf); \ utf_encoding_name (c_utf_name, (_utf_width), endianness); \ \ + scm_i_lock_iconv (); \ err = mem_iconveh (c_utf, c_utf_len, \ c_utf_name, "UTF-8", \ iconveh_question_mark, NULL, \ &c_str, &c_strlen); \ + scm_i_unlock_iconv (); \ if (SCM_UNLIKELY (err)) \ scm_syserror_msg (FUNC_NAME, "failed to convert to string: ~A", \ scm_list_1 (utf), err); \ |