diff options
-rw-r--r-- | libguile/dynl.c | 13 | ||||
-rw-r--r-- | libguile/posix.c | 31 | ||||
-rw-r--r-- | libguile/simpos.c | 13 | ||||
-rw-r--r-- | libguile/strings.c | 33 | ||||
-rw-r--r-- | libguile/strings.h | 1 |
5 files changed, 19 insertions, 72 deletions
diff --git a/libguile/dynl.c b/libguile/dynl.c index 42fd3955b..1326b8bd4 100644 --- a/libguile/dynl.c +++ b/libguile/dynl.c @@ -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 diff --git a/libguile/posix.c b/libguile/posix.c index 00e0fa1a3..b5082fa0a 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -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; } } diff --git a/libguile/simpos.c b/libguile/simpos.c index 402e4dc88..e4c27b7e7 100644 --- a/libguile/simpos.c +++ b/libguile/simpos.c @@ -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); } } diff --git a/libguile/strings.c b/libguile/strings.c index 9188a0da1..6e3b0a347 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -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" @@ -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, diff --git a/libguile/strings.h b/libguile/strings.h index e81ee3d98..e7053257f 100644 --- a/libguile/strings.h +++ b/libguile/strings.h @@ -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); |