Skip to content

Commit ab9268d

Browse files
author
Philippe Waroquiers
committed
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 <[email protected]> * 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.
1 parent bb0da2b commit ab9268d

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

gdb/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-02-06 Philippe Waroquiers <[email protected]>
2+
3+
* macrotab.c (macro_define_internal): New function that
4+
factorizes macro_define_object_internal and macro_define_function
5+
code.
6+
(macro_define_object_internal): Use macro_define_internal.
7+
(macro_define_function): Likewise.
8+
19
2019-02-06 Philippe Waroquiers <[email protected]>
210

311
* macrocmd.c (extract_identifier): Return

gdb/macrotab.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -743,21 +743,26 @@ check_for_redefinition (struct macro_source_file *source, int line,
743743
return 0;
744744
}
745745

746-
/* A helper function to define a new object-like macro. */
746+
/* A helper function to define a new object-like or function-like macro
747+
according to KIND. When KIND is macro_object_like,
748+
the macro_special_kind must be provided as ARGC, and ARGV must be NULL.
749+
When KIND is macro_function_like, ARGC and ARGV are giving the function
750+
arguments. */
747751

748752
static void
749-
macro_define_object_internal (struct macro_source_file *source, int line,
750-
const char *name, const char *replacement,
751-
enum macro_special_kind kind)
753+
macro_define_internal (struct macro_source_file *source, int line,
754+
const char *name, enum macro_kind kind,
755+
int argc, const char **argv,
756+
const char *replacement)
752757
{
753758
struct macro_table *t = source->table;
754759
struct macro_key *k = NULL;
755760
struct macro_definition *d;
756761

757762
if (! t->redef_ok)
758-
k = check_for_redefinition (source, line,
759-
name, macro_object_like,
760-
0, 0,
763+
k = check_for_redefinition (source, line,
764+
name, kind,
765+
argc, argv,
761766
replacement);
762767

763768
/* 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,
774779
return;
775780

776781
k = new_macro_key (t, name, source, line);
777-
d = new_macro_definition (t, macro_object_like, kind, 0, replacement);
782+
d = new_macro_definition (t, kind, argc, argv, replacement);
778783
splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
779784
}
780785

786+
/* A helper function to define a new object-like macro. */
787+
788+
static void
789+
macro_define_object_internal (struct macro_source_file *source, int line,
790+
const char *name, const char *replacement,
791+
enum macro_special_kind special_kind)
792+
{
793+
macro_define_internal (source, line,
794+
name, macro_object_like,
795+
special_kind, NULL,
796+
replacement);
797+
}
798+
781799
void
782800
macro_define_object (struct macro_source_file *source, int line,
783801
const char *name, const char *replacement)
@@ -802,29 +820,12 @@ macro_define_function (struct macro_source_file *source, int line,
802820
const char *name, int argc, const char **argv,
803821
const char *replacement)
804822
{
805-
struct macro_table *t = source->table;
806-
struct macro_key *k = NULL;
807-
struct macro_definition *d;
808-
809-
if (! t->redef_ok)
810-
k = check_for_redefinition (source, line,
811-
name, macro_function_like,
812-
argc, argv,
813-
replacement);
814-
815-
/* See comments about duplicate keys in macro_define_object. */
816-
if (k && ! key_compare (k, name, source, line))
817-
return;
818-
819-
/* We should also check here that all the argument names in ARGV are
820-
distinct. */
821-
822-
k = new_macro_key (t, name, source, line);
823-
d = new_macro_definition (t, macro_function_like, argc, argv, replacement);
824-
splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
823+
macro_define_internal (source, line,
824+
name, macro_function_like,
825+
argc, argv,
826+
replacement);
825827
}
826828

827-
828829
void
829830
macro_undef (struct macro_source_file *source, int line,
830831
const char *name)

0 commit comments

Comments
 (0)