Avoid some manual memory management in Python

This changes a few places in the Python code to avoid manual memory
management, in favor of letting std::string do the work.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* python/python.c (compute_python_string): Return std::string.
	(gdbpy_eval_from_control_command): Update.
	(do_start_initialization): Use std::string.
	* python/py-varobj.c (py_varobj_iter_next): Use string_printf, not
	xstrprintf.
	* python/py-breakpoint.c (local_setattro): Use string_printf, not
	xstrprintf.
This commit is contained in:
Tom Tromey 2017-04-30 22:10:41 -06:00
parent 3c9ebddd93
commit 7f968c899f
4 changed files with 29 additions and 42 deletions

View file

@ -71,7 +71,6 @@ py_varobj_iter_next (struct varobj_iter *self)
if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
{
PyObject *type, *value, *trace;
char *name_str;
PyErr_Fetch (&type, &value, &trace);
gdb::unique_xmalloc_ptr<char>
@ -85,10 +84,10 @@ py_varobj_iter_next (struct varobj_iter *self)
return NULL;
}
name_str = xstrprintf ("<error at %d>",
self->next_raw_index++);
item.reset (Py_BuildValue ("(ss)", name_str, value_str.get ()));
xfree (name_str);
std::string name_str = string_printf ("<error at %d>",
self->next_raw_index++);
item.reset (Py_BuildValue ("(ss)", name_str.c_str (),
value_str.get ()));
if (item == NULL)
{
gdbpy_print_stack ();