public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCHv2 2/2] gdb/guile: Have gdbscm_safe_source_script return a unique_ptr
Date: Wed,  5 May 2021 22:01:41 +0100	[thread overview]
Message-ID: <17720e44850a8a0ed172812da5ce6a3919f9bb4e.1620248278.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1620248278.git.andrew.burgess@embecosm.com>

Change gdbscm_safe_source_script to return a
gdb::unique_xmalloc_ptr<char> instead of a raw char*.  Update the
users of this function.

There should be no user visible change after this commit.

gdb/ChangeLog:

	* guile/guile-internal.h (gdbscm_safe_source_script): Change
	function return type.
	* guile/guile.c (gdbscm_source_script): Update to handle change in
	gdbscm_safe_source_script.
	* guile/scm-objfile.c (gdbscm_source_objfile_script): Likewise.
	* guile/scm-safe-call.c (gdbscm_safe_source_script): Change return
	type.
---
 gdb/ChangeLog              | 10 ++++++++++
 gdb/guile/guile-internal.h |  3 ++-
 gdb/guile/guile.c          |  7 ++-----
 gdb/guile/scm-objfile.c    |  9 ++-------
 gdb/guile/scm-safe-call.c  |  4 ++--
 5 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h
index c48547a41cd..73fa3803dfd 100644
--- a/gdb/guile/guile-internal.h
+++ b/gdb/guile/guile-internal.h
@@ -408,7 +408,8 @@ extern SCM gdbscm_unsafe_call_1 (SCM proc, SCM arg0);
 extern gdb::unique_xmalloc_ptr<char> gdbscm_safe_eval_string
   (const char *string, int display_result);
 
-extern char *gdbscm_safe_source_script (const char *filename);
+extern gdb::unique_xmalloc_ptr<char> gdbscm_safe_source_script
+  (const char *filename);
 
 extern void gdbscm_enter_repl (void);
 \f
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index c6959f5b713..71d61f375b3 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -270,13 +270,10 @@ static void
 gdbscm_source_script (const struct extension_language_defn *extlang,
 		      FILE *file, const char *filename)
 {
-  char *msg = gdbscm_safe_source_script (filename);
+  gdb::unique_xmalloc_ptr<char> msg = gdbscm_safe_source_script (filename);
 
   if (msg != NULL)
-    {
-      fprintf_filtered (gdb_stderr, "%s\n", msg);
-      xfree (msg);
-    }
+    fprintf_filtered (gdb_stderr, "%s\n", msg.get ());
 }
 \f
 /* (execute string [#:from-tty boolean] [#:to-string boolean])
diff --git a/gdb/guile/scm-objfile.c b/gdb/guile/scm-objfile.c
index 30e63f374e7..cc8bbe63a70 100644
--- a/gdb/guile/scm-objfile.c
+++ b/gdb/guile/scm-objfile.c
@@ -310,16 +310,11 @@ gdbscm_source_objfile_script (const struct extension_language_defn *extlang,
 			      struct objfile *objfile, FILE *file,
 			      const char *filename)
 {
-  char *msg;
-
   ofscm_current_objfile = objfile;
 
-  msg = gdbscm_safe_source_script (filename);
+  gdb::unique_xmalloc_ptr<char> msg = gdbscm_safe_source_script (filename);
   if (msg != NULL)
-    {
-      fprintf_filtered (gdb_stderr, "%s", msg);
-      xfree (msg);
-    }
+    fprintf_filtered (gdb_stderr, "%s", msg.get ());
 
   ofscm_current_objfile = NULL;
 }
diff --git a/gdb/guile/scm-safe-call.c b/gdb/guile/scm-safe-call.c
index 5bea970239b..a475774f921 100644
--- a/gdb/guile/scm-safe-call.c
+++ b/gdb/guile/scm-safe-call.c
@@ -432,7 +432,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
@@ -454,7 +454,7 @@ gdbscm_safe_source_script (const char *filename)
 			      (void *) filename);
 
   if (result != NULL)
-    return xstrdup (result);
+    return make_unique_xstrdup (result);
   return NULL;
 }
 \f
-- 
2.25.4


  parent reply	other threads:[~2021-05-05 21:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 17:40 [PATCH] gdb/guile: perform tilde expansion when sourcing guile scripts Andrew Burgess
2021-05-05 19:11 ` Tom Tromey
2021-05-05 21:01   ` [PATCHv2 0/2] " Andrew Burgess
2021-05-05 21:01     ` [PATCHv2 1/2] " Andrew Burgess
2021-05-06  2:23       ` Simon Marchi
2021-05-07 10:29         ` Andrew Burgess
2021-05-07 14:55           ` Simon Marchi
2021-05-07 21:23             ` Andrew Burgess
2021-05-05 21:01     ` Andrew Burgess [this message]
2021-05-06  2:28       ` [PATCHv2 2/2] gdb/guile: Have gdbscm_safe_source_script return a unique_ptr Simon Marchi
2021-05-06  2:32         ` Simon Marchi
2021-05-07  8:55           ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17720e44850a8a0ed172812da5ce6a3919f9bb4e.1620248278.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).