Remove more calls to xfree from Python
This changes the Python code to remove some more calls to xfree, in favor of self-managing data structures. Tested on x86-64 Fedora 28. gdb/ChangeLog 2018-12-27 Tom Tromey <tom@tromey.com> * python/python.c (python_interactive_command): Use std::string. (gdbpy_parameter): Likewise. * python/py-utils.c (unicode_to_encoded_string): Update comment. * python/py-symtab.c (salpy_str): Use PyString_FromFormat. * python/py-record-btrace.c (recpy_bt_insn_data): Use byte_vector. * python/py-objfile.c (objfpy_get_build_id): Use unique_xmalloc_ptr. * python/py-inferior.c (infpy_read_memory): Use unique_xmalloc_ptr. * python/py-cmd.c (gdbpy_parse_command_name): Use std::string.
This commit is contained in:
parent
293bf1a719
commit
075c55e0cc
8 changed files with 40 additions and 57 deletions
|
@ -362,7 +362,6 @@ gdbpy_parse_command_name (const char *name,
|
|||
struct cmd_list_element *elt;
|
||||
int len = strlen (name);
|
||||
int i, lastchar;
|
||||
char *prefix_text;
|
||||
const char *prefix_text2;
|
||||
char *result;
|
||||
|
||||
|
@ -395,31 +394,26 @@ gdbpy_parse_command_name (const char *name,
|
|||
return result;
|
||||
}
|
||||
|
||||
prefix_text = (char *) xmalloc (i + 2);
|
||||
memcpy (prefix_text, name, i + 1);
|
||||
prefix_text[i + 1] = '\0';
|
||||
std::string prefix_text (name, i + 1);
|
||||
|
||||
prefix_text2 = prefix_text;
|
||||
prefix_text2 = prefix_text.c_str ();
|
||||
elt = lookup_cmd_1 (&prefix_text2, *start_list, NULL, 1);
|
||||
if (elt == NULL || elt == CMD_LIST_AMBIGUOUS)
|
||||
{
|
||||
PyErr_Format (PyExc_RuntimeError, _("Could not find command prefix %s."),
|
||||
prefix_text);
|
||||
xfree (prefix_text);
|
||||
prefix_text.c_str ());
|
||||
xfree (result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (elt->prefixlist)
|
||||
{
|
||||
xfree (prefix_text);
|
||||
*base_list = elt->prefixlist;
|
||||
return result;
|
||||
}
|
||||
|
||||
PyErr_Format (PyExc_RuntimeError, _("'%s' is not a prefix command."),
|
||||
prefix_text);
|
||||
xfree (prefix_text);
|
||||
prefix_text.c_str ());
|
||||
xfree (result);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue