summaryrefslogtreecommitdiff
path: root/libguile/strings.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-06-18 00:45:19 +0200
committerAndy Wingo <wingo@pobox.com>2011-06-18 01:07:20 +0200
commit78f0ef20a77dd745a8fa4c1ac1fae4d42b481adf (patch)
tree3345f81ef4b52c46898deb998d365fca563f90b9 /libguile/strings.c
parent25711fa4caf815ffdf6000045534b2bf8f73740b (diff)
parentc245d16a5b18afdb68356f8343e6af7b3c32935b (diff)
downloadguile-78f0ef20a77dd745a8fa4c1ac1fae4d42b481adf.tar.gz
Merge remote-tracking branch 'local-2.0/stable-2.0'
Conflicts: module/ice-9/psyntax-pp.scm module/language/tree-il/compile-glil.scm
Diffstat (limited to 'libguile/strings.c')
-rw-r--r--libguile/strings.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index e54c27d32..b43ccaba2 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -2052,8 +2052,9 @@ SCM_DEFINE (scm_string_normalize_nfkd, "string-normalize-nfkd", 1, 0, 0,
}
#undef FUNC_NAME
-/* converts C scm_array of strings to SCM scm_list of strings. */
-/* If argc < 0, a null terminated scm_array is assumed. */
+/* converts C scm_array of strings to SCM scm_list of strings.
+ If argc < 0, a null terminated scm_array is assumed.
+ The current locale encoding is assumed */
SCM
scm_makfromstrs (int argc, char **argv)
{
@@ -2067,37 +2068,43 @@ scm_makfromstrs (int argc, char **argv)
}
/* Return a newly allocated array of char pointers to each of the strings
- in args, with a terminating NULL pointer. */
+ in args, with a terminating NULL pointer. The strings are encoded using
+ the current locale. */
char **
scm_i_allocate_string_pointers (SCM list)
#define FUNC_NAME "scm_i_allocate_string_pointers"
{
char **result;
- int len = scm_ilength (list);
+ int list_len = scm_ilength (list);
int i;
- if (len < 0)
+ if (list_len < 0)
scm_wrong_type_arg_msg (NULL, 0, list, "proper list");
- result = scm_gc_malloc ((len + 1) * sizeof (char *),
+ result = scm_gc_malloc ((list_len + 1) * sizeof (char *),
"string pointers");
- result[len] = NULL;
+ result[list_len] = NULL;
- /* The list might be have been modified in another thread, so
+ /* The list might have been modified in another thread, so
we check LIST before each access.
*/
- for (i = 0; i < len && scm_is_pair (list); i++)
+ for (i = 0; i < list_len && scm_is_pair (list); i++)
{
- SCM str;
- size_t len;
-
- str = SCM_CAR (list);
- len = scm_c_string_length (str);
-
- result[i] = scm_gc_malloc_pointerless (len + 1, "string pointers");
- memcpy (result[i], scm_i_string_chars (str), len);
+ SCM str = SCM_CAR (list);
+ size_t len; /* String length in bytes */
+ char *c_str = scm_to_locale_stringn (str, &len);
+
+ /* OPTIMIZE-ME: Right now, scm_to_locale_stringn always uses
+ scm_malloc to allocate the returned string, which must be
+ explicitly deallocated. This forces us to copy the string a
+ second time into a new buffer. Ideally there would be variants
+ of scm_to_*_stringn that can return garbage-collected buffers. */
+
+ result[i] = scm_gc_malloc_pointerless (len + 1, "string");
+ memcpy (result[i], c_str, len);
result[i][len] = '\0';
+ free (c_str);
list = SCM_CDR (list);
}