gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / guile / scm-string.c
index 63c60f068a347e7a9ca724ba6db7df0f564c61ae..1de4cf59e995aeee2659347bf1bd0e0cc33baa6b 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB/Scheme charset interface.
 
-   Copyright (C) 2014-2018 Free Software Foundation, Inc.
+   Copyright (C) 2014-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -48,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.  */
@@ -63,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;
 }
@@ -113,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)
 {
@@ -136,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;
@@ -214,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);
This page took 0.037526 seconds and 4 git commands to generate.