[binutils-gdb] Factorize macro definition code in macrotab.c

Philippe Waroquiers philippe@sourceware.org
Wed Feb 6 20:07:00 GMT 2019


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

commit ab9268d2f88414f202651eb5ffbd61c7927fb0c3
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date:   Sat Jan 26 12:32:45 2019 +0100

    Factorize macro definition code in macrotab.c
    
    When first fixing splay tree key leaks in macrotab.c, some duplicated code
    logic was factorized.
    The key leaks will be fixed in libiberty, but the code factorization
    is better kept in any case.
    
    gdb/ChangeLog
    2019-02-06  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    
    	* macrotab.c (macro_define_internal): New function that
    	factorizes macro_define_object_internal and macro_define_function
    	code.
    	(macro_define_object_internal): Use macro_define_internal.
    	(macro_define_function): Likewise.

Diff:
---
 gdb/ChangeLog  |  8 ++++++++
 gdb/macrotab.c | 59 +++++++++++++++++++++++++++++-----------------------------
 2 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 87cba1c..c5c08ec 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2019-02-06  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
+	* macrotab.c (macro_define_internal): New function that
+	factorizes macro_define_object_internal and macro_define_function
+	code.
+	(macro_define_object_internal): Use macro_define_internal.
+	(macro_define_function): Likewise.
+
+2019-02-06  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
 	* macrocmd.c (extract_identifier): Return
 	a gdb::unique_xmalloc_ptr<char> instead of a char *, and update
 	callers.
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index 7fcab46..f7ce26f 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -743,21 +743,26 @@ check_for_redefinition (struct macro_source_file *source, int line,
     return 0;
 }
 
-/* A helper function to define a new object-like macro.  */
+/* A helper function to define a new object-like or function-like macro
+   according to KIND.  When KIND is macro_object_like,
+   the macro_special_kind must be provided as ARGC, and ARGV must be NULL.
+   When KIND is macro_function_like, ARGC and ARGV are giving the function
+   arguments.  */
 
 static void
-macro_define_object_internal (struct macro_source_file *source, int line,
-			      const char *name, const char *replacement,
-			      enum macro_special_kind kind)
+macro_define_internal (struct macro_source_file *source, int line,
+                       const char *name, enum macro_kind kind,
+		       int argc, const char **argv,
+                       const char *replacement)
 {
   struct macro_table *t = source->table;
   struct macro_key *k = NULL;
   struct macro_definition *d;
 
   if (! t->redef_ok)
-    k = check_for_redefinition (source, line, 
-				name, macro_object_like,
-				0, 0,
+    k = check_for_redefinition (source, line,
+				name, kind,
+				argc, argv,
 				replacement);
 
   /* If we're redefining a symbol, and the existing key would be
@@ -774,10 +779,23 @@ macro_define_object_internal (struct macro_source_file *source, int line,
     return;
 
   k = new_macro_key (t, name, source, line);
-  d = new_macro_definition (t, macro_object_like, kind, 0, replacement);
+  d = new_macro_definition (t, kind, argc, argv, replacement);
   splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
 }
 
+/* A helper function to define a new object-like macro.  */
+
+static void
+macro_define_object_internal (struct macro_source_file *source, int line,
+			      const char *name, const char *replacement,
+			      enum macro_special_kind special_kind)
+{
+  macro_define_internal (source, line,
+			 name, macro_object_like,
+			 special_kind, NULL,
+			 replacement);
+}
+
 void
 macro_define_object (struct macro_source_file *source, int line,
 		     const char *name, const char *replacement)
@@ -802,29 +820,12 @@ macro_define_function (struct macro_source_file *source, int line,
                        const char *name, int argc, const char **argv,
                        const char *replacement)
 {
-  struct macro_table *t = source->table;
-  struct macro_key *k = NULL;
-  struct macro_definition *d;
-
-  if (! t->redef_ok)
-    k = check_for_redefinition (source, line,
-				name, macro_function_like,
-				argc, argv,
-				replacement);
-
-  /* See comments about duplicate keys in macro_define_object.  */
-  if (k && ! key_compare (k, name, source, line))
-    return;
-
-  /* We should also check here that all the argument names in ARGV are
-     distinct.  */
-
-  k = new_macro_key (t, name, source, line);
-  d = new_macro_definition (t, macro_function_like, argc, argv, replacement);
-  splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
+  macro_define_internal (source, line,
+			 name, macro_function_like,
+			 argc, argv,
+			 replacement);
 }
 
-
 void
 macro_undef (struct macro_source_file *source, int line,
              const char *name)



More information about the Gdb-cvs mailing list