Fix leaky handling of `scm_take_locale_{symbol,string} ()'.
authorLudovic Courtès <ludo@gnu.org>
Mon, 31 Aug 2009 22:38:40 +0000 (00:38 +0200)
committerLudovic Courtès <ludo@gnu.org>
Mon, 31 Aug 2009 22:38:40 +0000 (00:38 +0200)
* 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.

libguile/strings.c
libguile/strings.h

index dfa0690..d252b4a 100644 (file)
@@ -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;
 }
 
index 95dc7ac..fff7c97 100644 (file)
@@ -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 */