public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA 0/2] two more minor cleanup removals
@ 2018-02-09 12:55 Tom Tromey
  2018-02-09 12:55 ` [RFA 2/2] Use gdb::unique_xmalloc_ptr in auto_load_section_scripts Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey @ 2018-02-09 12:55 UTC (permalink / raw)
  To: gdb-patches

This short series removes a couple more cleanups.

Regression tested by the buildbot.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFA 2/2] Use gdb::unique_xmalloc_ptr in auto_load_section_scripts
  2018-02-09 12:55 [RFA 0/2] two more minor cleanup removals Tom Tromey
@ 2018-02-09 12:55 ` Tom Tromey
  2018-02-09 12:56 ` [RFA 1/2] Use std::string in execute_script_contents Tom Tromey
  2018-02-09 12:59 ` [RFA 0/2] two more minor cleanup removals Pedro Alves
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-02-09 12:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes auto_load_section_scripts to use gdb::unique_xmalloc_ptr,
allowing the removal of a cleanup.

2018-02-09  Tom Tromey  <tom@tromey.com>

	* auto-load.c (auto_load_section_scripts): Use
	gdb::unique_xmalloc_ptr.
---
 gdb/ChangeLog   | 5 +++++
 gdb/auto-load.c | 6 ++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index adc3d19d3b..9e03aa2908 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2018-02-09  Tom Tromey  <tom@tromey.com>
 
+	* auto-load.c (auto_load_section_scripts): Use
+	gdb::unique_xmalloc_ptr.
+
+2018-02-09  Tom Tromey  <tom@tromey.com>
+
 	* auto-load.c (execute_script_contents): Use std::string.
 
 2018-02-09  Joel Brobecker  <brobecker@adacore.com>
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 1f3d366a56..b79341faf6 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -1153,13 +1153,11 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name)
 	     section_name, bfd_get_filename (abfd));
   else
     {
-      struct cleanup *cleanups;
-      char *p = (char *) data;
+      gdb::unique_xmalloc_ptr<bfd_byte> data_holder (data);
 
-      cleanups = make_cleanup (xfree, p);
+      char *p = (char *) data;
       source_section_scripts (objfile, section_name, p,
 			      p + bfd_get_section_size (scripts_sect));
-      do_cleanups (cleanups);
     }
 }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFA 1/2] Use std::string in execute_script_contents
  2018-02-09 12:55 [RFA 0/2] two more minor cleanup removals Tom Tromey
  2018-02-09 12:55 ` [RFA 2/2] Use gdb::unique_xmalloc_ptr in auto_load_section_scripts Tom Tromey
@ 2018-02-09 12:56 ` Tom Tromey
  2018-02-09 12:59 ` [RFA 0/2] two more minor cleanup removals Pedro Alves
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-02-09 12:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes execute_script_contents to use a std::string, allowing
the removal of a cleanup.

2018-02-09  Tom Tromey  <tom@tromey.com>

	* auto-load.c (execute_script_contents): Use std::string.
---
 gdb/ChangeLog   |  4 ++++
 gdb/auto-load.c | 17 +++++------------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3e5b324472..adc3d19d3b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2018-02-09  Tom Tromey  <tom@tromey.com>
+
+	* auto-load.c (execute_script_contents): Use std::string.
+
 2018-02-09  Joel Brobecker  <brobecker@adacore.com>
 
 	* NEWS <Changes in GDB 8.1>: Clarify that "rbreak" is a new
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 30c8b89e8e..1f3d366a56 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -989,23 +989,21 @@ execute_script_contents (struct auto_load_pspace_info *pspace_info,
 {
   objfile_script_executor_func *executor;
   const char *newline, *script_text;
-  char *name;
+  const char *name;
   int is_safe, in_hash_table;
-  struct cleanup *cleanups;
-
-  cleanups = make_cleanup (null_cleanup, NULL);
 
   /* The first line of the script is the name of the script.
      It must not contain any kind of space character.  */
   name = NULL;
   newline = strchr (script, '\n');
+  std::string name_holder;
   if (newline != NULL)
     {
-      char *buf, *p;
+      const char *buf, *p;
 
       /* Put the name in a buffer and validate it.  */
-      buf = xstrndup (script, newline - script);
-      make_cleanup (xfree, buf);
+      name_holder = std::string (script, newline - script);
+      buf = name_holder.c_str ();
       for (p = buf; *p != '\0'; ++p)
 	{
 	  if (isspace (*p))
@@ -1022,7 +1020,6 @@ execute_script_contents (struct auto_load_pspace_info *pspace_info,
 Missing/bad script name in entry at offset %u in section %s\n\
 of file %s."),
 	       offset, section_name, objfile_name (objfile));
-      do_cleanups (cleanups);
       return;
     }
   script_text = newline + 1;
@@ -1035,7 +1032,6 @@ of file %s."),
       maybe_print_unsupported_script_warning (pspace_info, objfile, language,
 					      section_name, offset);
       maybe_add_script_text (pspace_info, 0, name, language);
-      do_cleanups (cleanups);
       return;
     }
 
@@ -1043,7 +1039,6 @@ of file %s."),
   if (!ext_lang_auto_load_enabled (language))
     {
       /* No message is printed, just skip it.  */
-      do_cleanups (cleanups);
       return;
     }
 
@@ -1059,8 +1054,6 @@ of file %s."),
   /* If this file is not currently loaded, load it.  */
   if (is_safe && !in_hash_table)
     executor (language, objfile, name, script_text);
-
-  do_cleanups (cleanups);
 }
 
 /* Load scripts specified in OBJFILE.
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA 0/2] two more minor cleanup removals
  2018-02-09 12:55 [RFA 0/2] two more minor cleanup removals Tom Tromey
  2018-02-09 12:55 ` [RFA 2/2] Use gdb::unique_xmalloc_ptr in auto_load_section_scripts Tom Tromey
  2018-02-09 12:56 ` [RFA 1/2] Use std::string in execute_script_contents Tom Tromey
@ 2018-02-09 12:59 ` Pedro Alves
  2 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2018-02-09 12:59 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/09/2018 12:55 PM, Tom Tromey wrote:
> This short series removes a couple more cleanups.
> 
> Regression tested by the buildbot.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-09 12:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-09 12:55 [RFA 0/2] two more minor cleanup removals Tom Tromey
2018-02-09 12:55 ` [RFA 2/2] Use gdb::unique_xmalloc_ptr in auto_load_section_scripts Tom Tromey
2018-02-09 12:56 ` [RFA 1/2] Use std::string in execute_script_contents Tom Tromey
2018-02-09 12:59 ` [RFA 0/2] two more minor cleanup removals Pedro Alves

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).