Remove ALL_PSPACE_OBJFILES
[deliverable/binutils-gdb.git] / gdb / guile / scm-string.c
index 25f1d67bc56789749873cadfc18d29dc7c06c86b..56de8d1ab61dfd259678880a9f2bc2ec25d326be 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB/Scheme charset interface.
 
-   Copyright (C) 2014 Free Software Foundation, Inc.
+   Copyright (C) 2014-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    conventions, et.al.  */
 
 #include "defs.h"
-#include <stdarg.h>
 #include "charset.h"
 #include "guile-internal.h"
 
+/* Convert STRING to an int.
+   STRING must be a valid integer.  */
+
+int
+gdbscm_scm_string_to_int (SCM string)
+{
+  char *s = scm_to_latin1_string (string);
+  int r = atoi (s);
+
+  free (s);
+  return r;
+}
+
 /* Convert a C (latin1) string to an SCM string.
    "latin1" is chosen because Guile won't throw an exception.  */
 
@@ -36,13 +48,12 @@ gdbscm_scm_from_c_string (const char *string)
 
 /* Convert an SCM string to a C (latin1) string.
    "latin1" is chosen because Guile won't throw an exception.
-   Space for the result is allocated with malloc, caller must free.
    It is an error to call this if STRING is not a string.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 gdbscm_scm_to_c_string (SCM string)
 {
-  return scm_to_latin1_string (string);
+  return gdb::unique_xmalloc_ptr<char> (scm_to_latin1_string (string));
 }
 
 /* Use printf to construct a Scheme string.  */
@@ -51,14 +62,12 @@ SCM
 gdbscm_scm_from_printf (const char *format, ...)
 {
   va_list args;
-  char *string;
   SCM result;
 
   va_start (args, format);
-  string = xstrvprintf (format, args);
+  std::string string = string_vprintf (format, args);
   va_end (args);
-  result = scm_from_latin1_string (string);
-  xfree (string);
+  result = scm_from_latin1_string (string.c_str ());
 
   return result;
 }
@@ -71,7 +80,7 @@ struct scm_to_stringn_data
   SCM string;
   size_t *lenp;
   const char *charset;
-  int conversion_kind;
+  scm_t_string_failed_conversion_handler conversion_kind;
   char *result;
 };
 
@@ -81,7 +90,7 @@ struct scm_to_stringn_data
 static SCM
 gdbscm_call_scm_to_stringn (void *datap)
 {
-  struct scm_to_stringn_data *data = datap;
+  struct scm_to_stringn_data *data = (struct scm_to_stringn_data *) datap;
 
   data->result = scm_to_stringn (data->string, data->lenp, data->charset,
                                 data->conversion_kind);
@@ -101,10 +110,9 @@ gdbscm_call_scm_to_stringn (void *datap)
    If STRICT is zero, then escape sequences are used for characters that
    can't be converted, and EXCEPT_SCMP may be passed as NULL.
 
-   Space for the result is allocated with malloc, caller must free.
    It is an error to call this if STRING is not a string.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 gdbscm_scm_to_string (SCM string, size_t *lenp,
                      const char *charset, int strict, SCM *except_scmp)
 {
@@ -124,7 +132,7 @@ gdbscm_scm_to_string (SCM string, size_t *lenp,
   if (gdbscm_is_false (scm_result))
     {
       gdb_assert (data.result != NULL);
-      return data.result;
+      return gdb::unique_xmalloc_ptr<char> (data.result);
     }
   gdb_assert (gdbscm_is_exception (scm_result));
   *except_scmp = scm_result;
@@ -139,7 +147,7 @@ struct scm_from_stringn_data
   const char *string;
   size_t len;
   const char *charset;
-  int conversion_kind;
+  scm_t_string_failed_conversion_handler conversion_kind;
   SCM result;
 };
 
@@ -149,7 +157,7 @@ struct scm_from_stringn_data
 static SCM
 gdbscm_call_scm_from_stringn (void *datap)
 {
-  struct scm_from_stringn_data *data = datap;
+  struct scm_from_stringn_data *data = (struct scm_from_stringn_data *) datap;
 
   data->result = scm_from_stringn (data->string, data->len, data->charset,
                                   data->conversion_kind);
@@ -202,10 +210,9 @@ gdbscm_scm_from_string (const char *string, size_t len,
 
    Returns NULL if there is a conversion error, with the exception object
    stored in *EXCEPT_SCMP.
-   Space for the result is allocated with malloc, caller must free.
    It is an error to call this if STRING is not a string.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except_scmp)
 {
   return gdbscm_scm_to_string (string, lenp, host_charset (), 1, except_scmp);
@@ -229,8 +236,6 @@ static SCM
 gdbscm_string_to_argv (SCM string_scm)
 {
   char *string;
-  char **c_argv;
-  int i;
   SCM result = SCM_EOL;
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "s",
@@ -242,11 +247,10 @@ gdbscm_string_to_argv (SCM string_scm)
       return SCM_EOL;
     }
 
-  c_argv = gdb_buildargv (string);
-  for (i = 0; c_argv[i] != NULL; ++i)
-    result = scm_cons (gdbscm_scm_from_c_string (c_argv[i]), result);
+  gdb_argv c_argv (string);
+  for (char *arg : c_argv)
+    result = scm_cons (gdbscm_scm_from_c_string (arg), result);
 
-  freeargv (c_argv);
   xfree (string);
 
   return scm_reverse_x (result, SCM_EOL);
@@ -256,7 +260,7 @@ gdbscm_string_to_argv (SCM string_scm)
 
 static const scheme_function string_functions[] =
 {
-  { "string->argv", 1, 0, 0, gdbscm_string_to_argv,
+  { "string->argv", 1, 0, 0, as_a_scm_t_subr (gdbscm_string_to_argv),
   "\
 Convert a string to a list of strings split up according to\n\
 gdb's argv parsing rules." },
This page took 0.027427 seconds and 4 git commands to generate.