aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-cmd.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-12-26 11:05:57 -0700
committerTom Tromey <tom@tromey.com>2018-12-27 10:50:43 -0700
commit075c55e0cc0a68eeab777027213c2f545618e844 (patch)
treed5ff42efac40742af8ce1401ef36ae43fc4df79d /gdb/python/py-cmd.c
parent293bf1a719e88e063e75ae467c5aec101b59fbf6 (diff)
downloadgdb-075c55e0cc0a68eeab777027213c2f545618e844.zip
gdb-075c55e0cc0a68eeab777027213c2f545618e844.tar.gz
gdb-075c55e0cc0a68eeab777027213c2f545618e844.tar.bz2
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.
Diffstat (limited to 'gdb/python/py-cmd.c')
-rw-r--r--gdb/python/py-cmd.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index d560b3a..0e39730 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -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;
}