]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/guile/scm-safe-call.c
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / guile / scm-safe-call.c
index 147d7f5e7f63a137ad23f4dff4261a1e0a704e00..aee02bf8364384bb13c400b2af90fd30eb2560ae 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB/Scheme support for safe calls into the Guile interpreter.
 
-   Copyright (C) 2014 Free Software Foundation, Inc.
+   Copyright (C) 2014-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #include "defs.h"
 #include "filenames.h"
-#include "gdb_assert.h"
 #include "guile-internal.h"
+#include "gdbsupport/pathstuff.h"
 
 /* Struct to marshall args to scscm_safe_call_body.  */
 
 struct c_data
 {
-  void *(*func) (void *);
+  const char *(*func) (void *);
   void *data;
   /* An error message or NULL for success.  */
-  void *result;
+  const char *result;
 };
 
 /* Struct to marshall args through gdbscm_with_catch.  */
@@ -98,7 +98,7 @@ scscm_nop_unwind_handler (void *data, SCM key, SCM args)
 static SCM
 scscm_recording_pre_unwind_handler (void *datap, SCM key, SCM args)
 {
-  struct with_catch_data *data = datap;
+  struct with_catch_data *data = (struct with_catch_data *) datap;
   excp_matcher_func *matcher = data->excp_matcher;
 
   if (matcher != NULL && matcher (key))
@@ -127,7 +127,7 @@ scscm_recording_pre_unwind_handler (void *datap, SCM key, SCM args)
 static SCM
 scscm_recording_unwind_handler (void *datap, SCM key, SCM args)
 {
-  struct with_catch_data *data = datap;
+  struct with_catch_data *data = (struct with_catch_data *) datap;
 
   /* We need to record the stack in the exception since we're about to
      throw and lose the location that got the exception.  We do this by
@@ -148,7 +148,7 @@ scscm_recording_unwind_handler (void *datap, SCM key, SCM args)
 static void *
 gdbscm_with_catch (void *data)
 {
-  struct with_catch_data *d = data;
+  struct with_catch_data *d = (struct with_catch_data *) data;
 
   d->catch_result
     = scm_c_catch (SCM_BOOL_T,
@@ -156,6 +156,10 @@ gdbscm_with_catch (void *data)
                   d->unwind_handler, d,
                   d->pre_unwind_handler, d);
 
+#if HAVE_GUILE_MANUAL_FINALIZATION
+  scm_run_finalizers ();
+#endif
+
   return NULL;
 }
 
@@ -164,8 +168,8 @@ gdbscm_with_catch (void *data)
    The result if NULL if no exception occurred, otherwise it is a statically
    allocated error message (caller must *not* free).  */
 
-void *
-gdbscm_with_guile (void *(*func) (void *), void *data)
+const char *
+gdbscm_with_guile (const char *(*func) (void *), void *data)
 {
   struct c_data c_data;
   struct with_catch_data catch_data;
@@ -227,7 +231,7 @@ gdbscm_call_guile (SCM (*func) (void *), void *data,
 static SCM
 scscm_call_0_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_call_0 (args[0]);
 }
@@ -245,7 +249,7 @@ gdbscm_safe_call_0 (SCM proc, excp_matcher_func *ok_excps)
 static SCM
 scscm_call_1_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_call_1 (args[0], args[1]);
 }
@@ -263,7 +267,7 @@ gdbscm_safe_call_1 (SCM proc, SCM arg0, excp_matcher_func *ok_excps)
 static SCM
 scscm_call_2_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_call_2 (args[0], args[1], args[2]);
 }
@@ -281,7 +285,7 @@ gdbscm_safe_call_2 (SCM proc, SCM arg0, SCM arg1, excp_matcher_func *ok_excps)
 static SCM
 scscm_call_3_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_call_3 (args[0], args[1], args[2], args[3]);
 }
@@ -300,7 +304,7 @@ gdbscm_safe_call_3 (SCM proc, SCM arg1, SCM arg2, SCM arg3,
 static SCM
 scscm_call_4_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_call_4 (args[0], args[1], args[2], args[3], args[4]);
 }
@@ -319,7 +323,7 @@ gdbscm_safe_call_4 (SCM proc, SCM arg1, SCM arg2, SCM arg3, SCM arg4,
 static SCM
 scscm_apply_1_body (void *argsp)
 {
-  SCM *args = argsp;
+  SCM *args = (SCM *) argsp;
 
   return scm_apply_1 (args[0], args[1], args[2]);
 }
@@ -364,12 +368,13 @@ struct eval_scheme_string_data
 };
 
 /* Wrapper to eval a C string in the Guile interpreter.
-   This is passed to scm_with_guile.  */
+   This is passed to gdbscm_with_guile.  */
 
-static void *
+static const char *
 scscm_eval_scheme_string (void *datap)
 {
-  struct eval_scheme_string_data *data = datap;
+  struct eval_scheme_string_data *data
+    = (struct eval_scheme_string_data *) datap;
   SCM result = scm_c_eval_string (data->string);
 
   if (data->display_result && !scm_is_eq (result, SCM_UNSPECIFIED))
@@ -388,18 +393,18 @@ scscm_eval_scheme_string (void *datap)
    and preventing continuation capture.
    The result is NULL if no exception occurred.  Otherwise, the exception is
    printed according to "set guile print-stack" and the result is an error
-   message allocated with malloc, caller must free.  */
+   message.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 gdbscm_safe_eval_string (const char *string, int display_result)
 {
   struct eval_scheme_string_data data = { string, display_result };
-  void *result;
+  const char *result;
 
   result = gdbscm_with_guile (scscm_eval_scheme_string, (void *) &data);
 
   if (result != NULL)
-    return xstrdup (result);
+    return make_unique_xstrdup (result);
   return NULL;
 }
 \f
@@ -407,10 +412,10 @@ gdbscm_safe_eval_string (const char *string, int display_result)
 
 /* Helper function for gdbscm_safe_source_scheme_script.  */
 
-static void *
+static const char *
 scscm_source_scheme_script (void *data)
 {
-  const char *filename = data;
+  const char *filename = (const char *) data;
 
   /* The Guile docs don't specify what the result is.
      Maybe it's SCM_UNSPECIFIED, but the docs should specify that. :-) */
@@ -426,7 +431,7 @@ scscm_source_scheme_script (void *data)
    printed according to "set guile print-stack" and the result is an error
    message allocated with malloc, caller must free.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 gdbscm_safe_source_script (const char *filename)
 {
   /* scm_c_primitive_load_path only looks in %load-path for files with
@@ -434,21 +439,20 @@ gdbscm_safe_source_script (const char *filename)
      %load-path, but we don't want %load-path to be searched.  At least not
      by default.  This function is invoked by the "source" GDB command which
      already has its own path search support.  */
-  char *abs_filename = NULL;
-  void *result;
+  gdb::unique_xmalloc_ptr<char> abs_filename;
+  const char *result;
 
   if (!IS_ABSOLUTE_PATH (filename))
     {
       abs_filename = gdb_realpath (filename);
-      filename = abs_filename;
+      filename = abs_filename.get ();
     }
 
   result = gdbscm_with_guile (scscm_source_scheme_script,
                              (void *) filename);
 
-  xfree (abs_filename);
   if (result != NULL)
-    return xstrdup (result);
+    return make_unique_xstrdup (result);
   return NULL;
 }
 \f