This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] gdb: Remove a cleanup from find_overload_match


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=06d3e5b0046d69e3da3450d2eb07c29f0c1a189a

commit 06d3e5b0046d69e3da3450d2eb07c29f0c1a189a
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Mon Dec 31 17:41:38 2018 +0000

    gdb: Remove a cleanup from find_overload_match
    
    This patch changes cp-support.c:cp_func_name to return a
    'gdb::unique_xmalloc_ptr<char>' instead of a 'char *'.  This allows a
    cleanup to be removed from valops.c:find_overload_match.
    
    gdb/ChangeLog:
    
    	* compile/compile-cplus-types.c
    	(compile_cplus_instance::decl_name): Handle changes to
    	cp_func_name.
    	* cp-support.c (cp_func_name): Update header comment, update
    	return type.
    	* cp-support.h (cp_func_name): Update return type in declaration.
    	* valops.c (find_overload_match): Move temp_func local to top
    	level of function and change its type.  Use temp_func to hold and
    	delete temporary string obtained from cp_func_name.

Diff:
---
 gdb/ChangeLog                     | 12 ++++++++++++
 gdb/compile/compile-cplus-types.c |  4 ++--
 gdb/cp-support.c                  |  9 ++++-----
 gdb/cp-support.h                  |  2 +-
 gdb/valops.c                      | 10 ++++------
 5 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4850082..3e677dc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@
 2019-01-03  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* compile/compile-cplus-types.c
+	(compile_cplus_instance::decl_name): Handle changes to
+	cp_func_name.
+	* cp-support.c (cp_func_name): Update header comment, update
+	return type.
+	* cp-support.h (cp_func_name): Update return type in declaration.
+	* valops.c (find_overload_match): Move temp_func local to top
+	level of function and change its type.  Use temp_func to hold and
+	delete temporary string obtained from cp_func_name.
+
+2019-01-03  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* remote.c (remote_target::remote_check_symbols): Convert `msg` to
 	gdb::char_vector, remove cleanup, and update uses of `msg`.
 
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 3de0d8e..910a874 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -63,9 +63,9 @@ compile_cplus_instance::decl_name (const char *natural)
   if (natural == nullptr)
     return nullptr;
 
-  char *name = cp_func_name (natural);
+  gdb::unique_xmalloc_ptr<char> name = cp_func_name (natural);
   if (name != nullptr)
-    return gdb::unique_xmalloc_ptr<char> (name);
+    return name;
 
   return gdb::unique_xmalloc_ptr<char> (xstrdup (natural));
 }
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 2024f87..489bcca 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -808,10 +808,9 @@ method_name_from_physname (const char *physname)
 /* If FULL_NAME is the demangled name of a C++ function (including an
    arg list, possibly including namespace/class qualifications),
    return a new string containing only the function name (without the
-   arg list/class qualifications).  Otherwise, return NULL.  The
-   caller is responsible for freeing the memory in question.  */
+   arg list/class qualifications).  Otherwise, return NULL.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 cp_func_name (const char *full_name)
 {
   gdb::unique_xmalloc_ptr<char> ret;
@@ -820,14 +819,14 @@ cp_func_name (const char *full_name)
 
   info = cp_demangled_name_to_comp (full_name, NULL);
   if (!info)
-    return NULL;
+    return nullptr;
 
   ret_comp = unqualified_name_from_comp (info->tree);
 
   if (ret_comp != NULL)
     ret = cp_comp_to_string (ret_comp, 10);
 
-  return ret.release ();
+  return ret;
 }
 
 /* Helper for cp_remove_params.  DEMANGLED_NAME is the name of a
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 32fafe4..2677e1b 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -96,7 +96,7 @@ extern unsigned int cp_find_first_component (const char *name);
 
 extern unsigned int cp_entire_prefix_len (const char *name);
 
-extern char *cp_func_name (const char *full_name);
+extern gdb::unique_xmalloc_ptr<char> cp_func_name (const char *full_name);
 
 extern gdb::unique_xmalloc_ptr<char> cp_remove_params
   (const char *demanged_name);
diff --git a/gdb/valops.c b/gdb/valops.c
index caf3162..1a9d6a6 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2520,6 +2520,7 @@ find_overload_match (gdb::array_view<value *> args,
 
   const char *obj_type_name = NULL;
   const char *func_name = NULL;
+  gdb::unique_xmalloc_ptr<char> temp_func;
   enum oload_classification match_quality;
   enum oload_classification method_match_quality = INCOMPATIBLE;
   enum oload_classification src_method_match_quality = INCOMPATIBLE;
@@ -2666,20 +2667,17 @@ find_overload_match (gdb::array_view<value *> args,
               && TYPE_CODE (check_typedef (SYMBOL_TYPE (fsym)))
 	      == TYPE_CODE_FUNC)
             {
-	      char *temp_func;
-
 	      temp_func = cp_func_name (qualified_name);
 
 	      /* If cp_func_name did not remove anything, the name of the
 	         symbol did not include scope or argument types - it was
 	         probably a C-style function.  */
-	      if (temp_func)
+	      if (temp_func != nullptr)
 		{
-		  make_cleanup (xfree, temp_func);
-		  if (strcmp (temp_func, qualified_name) == 0)
+		  if (strcmp (temp_func.get (), qualified_name) == 0)
 		    func_name = NULL;
 		  else
-		    func_name = temp_func;
+		    func_name = temp_func.get ();
 		}
             }
         }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]