Use `scm_gc malloc_pointerless ()' in `scm_i allocate_string_pointers ()'.
authorLudovic Courtès <ludo@gnu.org>
Sun, 18 Jan 2009 14:33:37 +0000 (15:33 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 18 Jan 2009 15:02:04 +0000 (16:02 +0100)
* libguile/dynl.c (free_string_pointers): Remove.
  (scm_dynamic_args_call): Remove reference to `free_string_pointers ()'
  and remove dynwind.

* libguile/posix.c (free_string_pointers): Remove.
  (scm_execl, scm_execlp, scm_execle, scm_environ): Remove references
  to `free_string_pointers ()'.

* libguile/simpos.c (free_string_pointers): Remove.
  (scm_system_star): Remove reference to `free_string_pointers ()',
  remove enclosing dynwind.

* libguile/strings.c (scm_i_allocate_string_pointers): Use
  `scm_gc_malloc_pointerless ()' and `scm_gc_malloc ()'
  instead of `scm_malloc ()' and `scm_to_locale_string ()',
  so that the result is automatically GC'd when no longer
  referenced.  Remove unneeded dynwind.
  (scm_i_free_string_pointers): Remove.

* libguile/strings.h (scm_i_free_string_pointers): Remove declaration.

libguile/dynl.c
libguile/posix.c
libguile/simpos.c
libguile/strings.c
libguile/strings.h

index 42fd395..1326b8b 100644 (file)
@@ -1,7 +1,7 @@
 /* dynl.c - dynamic linking
  *
  * Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002,
- * 2003, 2008 Free Software Foundation, Inc.
+ * 2003, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -262,12 +262,6 @@ SCM_DEFINE (scm_dynamic_call, "dynamic-call", 2, 0, 0,
 }
 #undef FUNC_NAME
 
-static void
-free_string_pointers (void *data)
-{
-  scm_i_free_string_pointers ((char **)data);
-}
-
 SCM_DEFINE (scm_dynamic_args_call, "dynamic-args-call", 3, 0, 0, 
             (SCM func, SCM dobj, SCM args),
            "Call the C function indicated by @var{func} and @var{dobj},\n"
@@ -288,21 +282,16 @@ SCM_DEFINE (scm_dynamic_args_call, "dynamic-args-call", 3, 0, 0,
   int result, argc;
   char **argv;
 
-  scm_dynwind_begin (0);
-
   if (scm_is_string (func))
     func = scm_dynamic_func (func, dobj);
 
   fptr = (int (*) (int, char **)) scm_to_ulong (func);
 
   argv = scm_i_allocate_string_pointers (args);
-  scm_dynwind_unwind_handler (free_string_pointers, argv,
-                             SCM_F_WIND_EXPLICITLY);
   for (argc = 0; argv[argc]; argc++)
     ;
   result = (*fptr) (argc, argv);
 
-  scm_dynwind_end ();
   return scm_from_int (result);
 }
 #undef FUNC_NAME
index 00e0fa1..b5082fa 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -943,12 +943,6 @@ SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
 #undef FUNC_NAME
 #endif /* HAVE_TCSETPGRP */
 
-static void
-free_string_pointers (void *data)
-{
-  scm_i_free_string_pointers ((char **)data);
-}
-
 SCM_DEFINE (scm_execl, "execl", 1, 0, 1, 
             (SCM filename, SCM args),
            "Executes the file named by @var{path} as a new process image.\n"
@@ -971,8 +965,6 @@ SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
   scm_dynwind_free (exec_file);
 
   exec_argv = scm_i_allocate_string_pointers (args);
-  scm_dynwind_unwind_handler (free_string_pointers, exec_argv, 
-                           SCM_F_WIND_EXPLICITLY);
 
   execv (exec_file,
 #ifdef __MINGW32__
@@ -1007,8 +999,6 @@ SCM_DEFINE (scm_execlp, "execlp", 1, 0, 1,
   scm_dynwind_free (exec_file);
 
   exec_argv = scm_i_allocate_string_pointers (args);
-  scm_dynwind_unwind_handler (free_string_pointers, exec_argv, 
-                           SCM_F_WIND_EXPLICITLY);
 
   execvp (exec_file,
 #ifdef __MINGW32__
@@ -1047,12 +1037,7 @@ SCM_DEFINE (scm_execle, "execle", 2, 0, 1,
   scm_dynwind_free (exec_file);
 
   exec_argv = scm_i_allocate_string_pointers (args);
-  scm_dynwind_unwind_handler (free_string_pointers, exec_argv,
-                           SCM_F_WIND_EXPLICITLY);
-
   exec_env = scm_i_allocate_string_pointers (env);
-  scm_dynwind_unwind_handler (free_string_pointers, exec_env,
-                           SCM_F_WIND_EXPLICITLY);
 
   execve (exec_file,
 #ifdef __MINGW32__
@@ -1136,19 +1121,7 @@ SCM_DEFINE (scm_environ, "environ", 0, 1, 0,
     return scm_makfromstrs (-1, environ);
   else
     {
-      char **new_environ;
-
-      new_environ = scm_i_allocate_string_pointers (env);
-      /* Free the old environment, except when called for the first
-       * time.
-       */
-      {
-       static int first = 1;
-       if (!first)
-         scm_i_free_string_pointers (environ);
-       first = 0;
-      }
-      environ = new_environ;
+      environ = scm_i_allocate_string_pointers (env);
       return SCM_UNSPECIFIED;
     }
 }
index 402e4dc..e4c27b7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003, 2004 Free Software
+/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2003, 2004, 2009 Free Software
  * Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
@@ -88,11 +88,6 @@ SCM_DEFINE (scm_system, "system", 0, 1, 0,
 #ifdef HAVE_SYSTEM
 #ifdef HAVE_WAITPID
 
-static void
-free_string_pointers (void *data)
-{
-  scm_i_free_string_pointers ((char **)data);
-}
 
 SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
            (SCM args),
@@ -127,12 +122,8 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
       int pid;
       char **execargv;
 
-      scm_dynwind_begin (0);
-
       /* allocate before fork */
       execargv = scm_i_allocate_string_pointers (args);
-      scm_dynwind_unwind_handler (free_string_pointers, execargv,
-                                 SCM_F_WIND_EXPLICITLY);
 
       /* make sure the child can't kill us (as per normal system call) */
       sig_ign = scm_from_long ((unsigned long) SIG_IGN);
@@ -148,7 +139,6 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
           execvp (execargv[0], execargv);
           SCM_SYSERROR;
           /* not reached.  */
-         scm_dynwind_end ();
           return SCM_BOOL_F;
         }
       else
@@ -165,7 +155,6 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
           scm_sigaction (sigint, SCM_CAR (oldint), SCM_CDR (oldint));
           scm_sigaction (sigquit, SCM_CAR (oldquit), SCM_CDR (oldquit));
 
-         scm_dynwind_end ();
           return scm_from_int (status);
         }
     }
index 9188a0d..6e3b0a3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,2000,2001, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,2000,2001, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -30,7 +30,6 @@
 #include "libguile/strings.h"
 #include "libguile/deprecation.h"
 #include "libguile/validate.h"
-#include "libguile/dynwind.h"
 
 \f
 
@@ -949,6 +948,7 @@ scm_makfromstrs (int argc, char **argv)
 
 char **
 scm_i_allocate_string_pointers (SCM list)
+#define FUNC_NAME "scm_i_allocate_string_pointers"
 {
   char **result;
   int len = scm_ilength (list);
@@ -957,34 +957,31 @@ scm_i_allocate_string_pointers (SCM list)
   if (len < 0)
     scm_wrong_type_arg_msg (NULL, 0, list, "proper list");
 
-  scm_dynwind_begin (0);
-
-  result = (char **) scm_malloc ((len + 1) * sizeof (char *));
+  result = scm_gc_malloc ((len + 1) * sizeof (char *),
+                         "string pointers");
   result[len] = NULL;
-  scm_dynwind_unwind_handler (free, result, 0);
 
   /* The list might be have been modified in another thread, so
      we check LIST before each access.
    */
   for (i = 0; i < len && scm_is_pair (list); i++)
     {
-      result[i] = scm_to_locale_string (SCM_CAR (list));
+      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);
+      result[i][len] = '\0';
+
       list = SCM_CDR (list);
     }
 
-  scm_dynwind_end ();
   return result;
 }
-
-void
-scm_i_free_string_pointers (char **pointers)
-{
-  int i;
-  
-  for (i = 0; pointers[i]; i++)
-    free (pointers[i]);
-  free (pointers);
-}
+#undef FUNC_NAME
 
 void
 scm_i_get_substring_spec (size_t len,
index e81ee3d..e705325 100644 (file)
@@ -138,7 +138,6 @@ SCM_INTERNAL SCM scm_i_symbol_substring (SCM sym, size_t start, size_t end);
 /* internal utility functions. */
 
 SCM_INTERNAL char **scm_i_allocate_string_pointers (SCM list);
-SCM_INTERNAL void scm_i_free_string_pointers (char **pointers);
 SCM_INTERNAL void scm_i_get_substring_spec (size_t len,
                                            SCM start, size_t *cstart,
                                            SCM end, size_t *cend);