summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2009-09-01 00:38:40 +0200
committerLudovic Courtès <ludo@gnu.org>2009-09-01 00:38:40 +0200
commit13a9455669c2a8d1e4ed59cb8736bf23e91eaa55 (patch)
tree80a237ae1e3c7e74c398574b6962d65e4f047c70
parent4812ce85ddf1d04c49436ada34152ac7751a8b50 (diff)
downloadguile-13a9455669c2a8d1e4ed59cb8736bf23e91eaa55.tar.gz
Fix leaky handling of `scm_take_locale_{symbol,string} ()'.
* libguile/strings.c (scm_i_take_stringbufn, scm_i_c_take_symbol): Remove. (scm_take_locale_stringn): Rewrite in terms of `scm_from_locale_stringn ()'. * libguile/strings.h (scm_i_c_take_symbol, scm_i_take_stringbufn): Remove declarations.
-rw-r--r--libguile/strings.c43
-rw-r--r--libguile/strings.h4
2 files changed, 6 insertions, 41 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index dfa069095..d252b4a08 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -164,17 +164,6 @@ make_wide_stringbuf (size_t len)
(scm_t_bits) len, (scm_t_bits) 0);
}
-/* Return a new stringbuf whose underlying storage consists of the LEN+1
- octets pointed to by STR (the last octet is zero). */
-SCM
-scm_i_take_stringbufn (char *str, size_t len)
-{
- scm_gc_register_collectable_memory (str, len + 1, "stringbuf");
-
- return scm_double_cell (STRINGBUF_TAG, (scm_t_bits) str,
- (scm_t_bits) len, (scm_t_bits) 0);
-}
-
/* Convert a stringbuf containing 8-bit Latin-1-encoded characters to
one containing 32-bit UCS-4-encoded characters. */
static void
@@ -744,18 +733,6 @@ scm_i_c_make_symbol (const char *name, size_t len,
(scm_t_bits) hash, SCM_UNPACK (props));
}
-/* Return a new symbol that uses the LEN bytes pointed to by NAME as its
- underlying storage. */
-SCM
-scm_i_c_take_symbol (char *name, size_t len,
- scm_t_bits flags, unsigned long hash, SCM props)
-{
- SCM buf = scm_i_take_stringbufn (name, len);
-
- return scm_double_cell (scm_tc7_symbol | flags, SCM_UNPACK (buf),
- (scm_t_bits) hash, SCM_UNPACK (props));
-}
-
/* Returns the number of characters in SYM. This may be different
from the memory size of SYM. */
size_t
@@ -1556,25 +1533,17 @@ scm_i_from_utf8_string (const scm_t_uint8 *str)
/* Create a new scheme string from the C string STR. The memory of
STR may be used directly as storage for the new string. */
+/* FIXME: GC-wise, the only way to use the memory area pointed to by STR
+ would be to register a finalizer to eventually free(3) STR, which isn't
+ worth it. Should we just deprecate the `scm_take_' functions? */
SCM
scm_take_locale_stringn (char *str, size_t len)
{
- SCM buf, res;
+ SCM res;
- if (len == (size_t) -1)
- len = strlen (str);
- else
- {
- /* Ensure STR is null terminated. A realloc for 1 extra byte should
- often be satisfied from the alignment padding after the block, with
- no actual data movement. */
- str = scm_realloc (str, len + 1);
- str[len] = '\0';
- }
+ res = scm_from_locale_stringn (str, len);
+ free (str);
- buf = scm_i_take_stringbufn (str, len);
- res = scm_double_cell (STRING_TAG,
- SCM_UNPACK (buf), (scm_t_bits) 0, (scm_t_bits) len);
return res;
}
diff --git a/libguile/strings.h b/libguile/strings.h
index 95dc7ac3e..fff7c97bd 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -164,9 +164,6 @@ SCM_INTERNAL SCM scm_i_make_symbol (SCM name, scm_t_bits flags,
SCM_INTERNAL SCM
scm_i_c_make_symbol (const char *name, size_t len,
scm_t_bits flags, unsigned long hash, SCM props);
-SCM_INTERNAL SCM
-scm_i_c_take_symbol (char *name, size_t len,
- scm_t_bits flags, unsigned long hash, SCM props);
SCM_INTERNAL const char *scm_i_symbol_chars (SCM sym);
SCM_INTERNAL const scm_t_wchar *scm_i_symbol_wide_chars (SCM sym);
SCM_INTERNAL size_t scm_i_symbol_length (SCM sym);
@@ -181,7 +178,6 @@ SCM_INTERNAL char **scm_i_allocate_string_pointers (SCM list);
SCM_INTERNAL void scm_i_get_substring_spec (size_t len,
SCM start, size_t *cstart,
SCM end, size_t *cend);
-SCM_INTERNAL SCM scm_i_take_stringbufn (char *str, size_t len);
/* Debugging functions */