Remove cleanups from macro_define_command
This removes cleanups from macro_define_command, by introducing a new struct temporary_macro_definition that cleans up after itself. 2018-02-08 Tom Tromey <tom@tromey.com> * macrocmd.c (struct temporary_macro_definition): New. (macro_define_command): Use temporary_macro_definition. Remove cleanups. (free_macro_definition_ptr): Remove.
This commit is contained in:
parent
0354904bda
commit
84f27c6fcb
2 changed files with 27 additions and 20 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2018-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* macrocmd.c (struct temporary_macro_definition): New.
|
||||||
|
(macro_define_command): Use temporary_macro_definition. Remove
|
||||||
|
cleanups.
|
||||||
|
(free_macro_definition_ptr): Remove.
|
||||||
|
|
||||||
2018-02-08 Tom Tromey <tom@tromey.com>
|
2018-02-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* macroexp.c (maybe_expand): Use std::string.
|
* macroexp.c (maybe_expand): Use std::string.
|
||||||
|
|
|
@ -324,35 +324,37 @@ extract_identifier (const char **expp, int is_parameter)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function to clean up a temporarily-constructed macro object.
|
struct temporary_macro_definition : public macro_definition
|
||||||
This assumes that the contents were all allocated with xmalloc. */
|
{
|
||||||
static void
|
temporary_macro_definition ()
|
||||||
free_macro_definition_ptr (void *ptr)
|
{
|
||||||
|
table = nullptr;
|
||||||
|
kind = macro_object_like;
|
||||||
|
argc = 0;
|
||||||
|
argv = nullptr;
|
||||||
|
replacement = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
~temporary_macro_definition ()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct macro_definition *loc = (struct macro_definition *) ptr;
|
|
||||||
|
|
||||||
for (i = 0; i < loc->argc; ++i)
|
for (i = 0; i < argc; ++i)
|
||||||
xfree ((char *) loc->argv[i]);
|
xfree ((char *) argv[i]);
|
||||||
xfree ((char *) loc->argv);
|
xfree ((char *) argv);
|
||||||
/* Note that the 'replacement' field is not allocated. */
|
/* Note that the 'replacement' field is not allocated. */
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
macro_define_command (const char *exp, int from_tty)
|
macro_define_command (const char *exp, int from_tty)
|
||||||
{
|
{
|
||||||
struct macro_definition new_macro;
|
temporary_macro_definition new_macro;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
struct cleanup *cleanup_chain;
|
|
||||||
|
|
||||||
if (!exp)
|
if (!exp)
|
||||||
error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));
|
error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]"));
|
||||||
|
|
||||||
cleanup_chain = make_cleanup (free_macro_definition_ptr, &new_macro);
|
|
||||||
make_cleanup (free_current_contents, &name);
|
|
||||||
|
|
||||||
memset (&new_macro, 0, sizeof (struct macro_definition));
|
|
||||||
|
|
||||||
skip_ws (&exp);
|
skip_ws (&exp);
|
||||||
name = extract_identifier (&exp, 0);
|
name = extract_identifier (&exp, 0);
|
||||||
if (! name)
|
if (! name)
|
||||||
|
@ -415,8 +417,6 @@ macro_define_command (const char *exp, int from_tty)
|
||||||
skip_ws (&exp);
|
skip_ws (&exp);
|
||||||
macro_define_object (macro_main (macro_user_macros), -1, name, exp);
|
macro_define_object (macro_main (macro_user_macros), -1, name, exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cleanups (cleanup_chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue