gdb/python: use return values of add_setshow functions in add_setshow_generic

In add_setshow_generic, we create set/show commands using add_setshow_*
functions, then look up the commands by name to set the context pointer.
It would be simpler and more efficient to use the return values of the
add_setshow_* functions, do that.

gdb/ChangeLog:

	* python/py-param.c (add_setshow_generic): Use return values of
	add_setshow functions.

Change-Id: I04d50736e1001ddb732d81e088468876df9c88ff
This commit is contained in:
Simon Marchi 2021-05-27 13:59:00 -04:00
parent 9f26053690
commit 7bd22f56a3
2 changed files with 71 additions and 67 deletions

View File

@ -1,3 +1,8 @@
2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
* python/py-param.c (add_setshow_generic): Use return values of
add_setshow functions.
2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
* mi/mi-main.c (_initialize_mi_main):

View File

@ -465,113 +465,112 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *param = NULL;
const char *tmp_name = NULL;
set_show_commands commands;
switch (parmclass)
{
case var_boolean:
add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
&self->value.boolval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
&self->value.boolval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_auto_boolean:
add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
&self->value.autoboolval,
set_doc, show_doc, help_doc,
get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
&self->value.autoboolval,
set_doc, show_doc, help_doc,
get_set_value, get_show_value,
set_list, show_list);
break;
case var_uinteger:
add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
&self->value.uintval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
&self->value.uintval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_integer:
add_setshow_integer_cmd (cmd_name.get (), cmdclass,
&self->value.intval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list); break;
commands = add_setshow_integer_cmd (cmd_name.get (), cmdclass,
&self->value.intval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_string:
add_setshow_string_cmd (cmd_name.get (), cmdclass,
&self->value.stringval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list); break;
commands = add_setshow_string_cmd (cmd_name.get (), cmdclass,
&self->value.stringval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_string_noescape:
add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
&self->value.stringval,
set_doc, show_doc, help_doc,
get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
&self->value.stringval,
set_doc, show_doc, help_doc,
get_set_value, get_show_value,
set_list, show_list);
break;
case var_optional_filename:
add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
&self->value.stringval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list,
show_list);
commands = add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
&self->value.stringval,
set_doc, show_doc, help_doc,
get_set_value,
get_show_value, set_list,
show_list);
break;
case var_filename:
add_setshow_filename_cmd (cmd_name.get (), cmdclass,
&self->value.stringval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list); break;
commands = add_setshow_filename_cmd (cmd_name.get (), cmdclass,
&self->value.stringval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_zinteger:
add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
&self->value.intval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
&self->value.intval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
break;
case var_zuinteger:
add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
&self->value.uintval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
&self->value.uintval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list,
show_list);
break;
case var_zuinteger_unlimited:
add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
&self->value.intval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value,
set_list, show_list);
commands = add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
&self->value.intval,
set_doc, show_doc,
help_doc, get_set_value,
get_show_value, set_list,
show_list);
break;
case var_enum:
add_setshow_enum_cmd (cmd_name.get (), cmdclass, self->enumeration,
&self->value.cstringval, set_doc, show_doc,
help_doc, get_set_value, get_show_value,
set_list, show_list);
commands = add_setshow_enum_cmd (cmd_name.get (), cmdclass,
self->enumeration,
&self->value.cstringval, set_doc,
show_doc, help_doc, get_set_value,
get_show_value, set_list, show_list);
/* Initialize the value, just in case. */
self->value.cstringval = self->enumeration[0];
break;
default:
gdb_assert_not_reached ("Unhandled parameter class.");
}
/* Lookup created parameter, and register Python object against the
parameter context. Perform this task against both lists. */
tmp_name = cmd_name.get ();
param = lookup_cmd (&tmp_name, *show_list, "", NULL, 0, 1);
if (param)
set_cmd_context (param, self);
tmp_name = cmd_name.get ();
param = lookup_cmd (&tmp_name, *set_list, "", NULL, 0, 1);
if (param)
set_cmd_context (param, self);
/* Register Python objects in both commands' context. */
set_cmd_context (commands.set, self);
set_cmd_context (commands.show, self);
/* We (unfortunately) currently leak the command name. */
cmd_name.release ();