mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-01 23:30:28 +02:00
Move string-pointer-array handling to posix.c
* libguile/posix.c (free_string_pointers): (free_string_pointers_on_unwind): (allocate_string_pointers): Move here from string.c, and use malloc/free instead of GC facilities. Adapt all users. * libguile/strings.h: * libguile/strings.c (scm_i_allocate_string_pointers): Remove.
This commit is contained in:
parent
ce2f7847e8
commit
a793d371cd
3 changed files with 65 additions and 55 deletions
|
@ -2430,52 +2430,6 @@ scm_makfromstrs (int argc, char **argv)
|
|||
return lst;
|
||||
}
|
||||
|
||||
/* Return a newly allocated array of char pointers to each of the strings
|
||||
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 list_len = scm_ilength (list);
|
||||
int i;
|
||||
|
||||
if (list_len < 0)
|
||||
scm_wrong_type_arg_msg (NULL, 0, list, "proper list");
|
||||
|
||||
result = scm_gc_malloc ((list_len + 1) * sizeof (char *),
|
||||
"string pointers");
|
||||
result[list_len] = NULL;
|
||||
|
||||
/* The list might have been modified in another thread, so
|
||||
we check LIST before each access.
|
||||
*/
|
||||
for (i = 0; i < list_len && scm_is_pair (list); i++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
void
|
||||
scm_i_get_substring_spec (size_t len,
|
||||
SCM start, size_t *cstart,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue