mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-24 18:57:01 +08:00
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:
@ -296,14 +296,8 @@ python_interactive_command (const char *arg, int from_tty)
|
||||
|
||||
if (arg && *arg)
|
||||
{
|
||||
int len = strlen (arg);
|
||||
char *script = (char *) xmalloc (len + 2);
|
||||
|
||||
strcpy (script, arg);
|
||||
script[len] = '\n';
|
||||
script[len + 1] = '\0';
|
||||
err = eval_python_command (script);
|
||||
xfree (script);
|
||||
std::string script = std::string (arg) + "\n";
|
||||
err = eval_python_command (script.c_str ());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -495,29 +489,25 @@ gdbpy_parameter_value (enum var_types type, void *var)
|
||||
static PyObject *
|
||||
gdbpy_parameter (PyObject *self, PyObject *args)
|
||||
{
|
||||
struct gdb_exception except = exception_none;
|
||||
struct cmd_list_element *alias, *prefix, *cmd;
|
||||
const char *arg;
|
||||
char *newarg;
|
||||
int found = -1;
|
||||
|
||||
if (! PyArg_ParseTuple (args, "s", &arg))
|
||||
return NULL;
|
||||
|
||||
newarg = concat ("show ", arg, (char *) NULL);
|
||||
std::string newarg = std::string ("show ") + arg;
|
||||
|
||||
TRY
|
||||
{
|
||||
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
|
||||
found = lookup_cmd_composition (newarg.c_str (), &alias, &prefix, &cmd);
|
||||
}
|
||||
CATCH (ex, RETURN_MASK_ALL)
|
||||
{
|
||||
except = ex;
|
||||
GDB_PY_HANDLE_EXCEPTION (ex);
|
||||
}
|
||||
END_CATCH
|
||||
|
||||
xfree (newarg);
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
if (!found)
|
||||
return PyErr_Format (PyExc_RuntimeError,
|
||||
_("Could not find parameter `%s'."), arg);
|
||||
|
Reference in New Issue
Block a user