+2018-11-04 Tom Tromey <tom@tromey.com>
+
+ * python/python.c (gdbpy_parameter_value): Update.
+ * python/python-internal.h (python_string_to_unicode)
+ (python_string_to_target_python_string)
+ (host_string_to_python_string): Return gdbpy_ref.
+ * python/py-utils.c (python_string_to_unicode)
+ (unicode_to_encoded_python_string)
+ (unicode_to_target_python_string)
+ (python_string_to_target_string)
+ (python_string_to_target_python_string): Return gdbpy_ref.
+ (python_string_to_host_string): Update.
+ (host_string_to_python_string): Return gdbpy_ref.
+ * python/py-symtab.c (stpy_get_filename, stpy_get_producer)
+ (stpy_fullname): Update.
+ * python/py-progspace.c (pspy_get_filename, pspy_solib_name):
+ Update.
+ * python/py-prettyprint.c (print_string_repr): Update.
+ * python/py-objfile.c (objfpy_get_filename, objfpy_get_username)
+ (objfpy_get_build_id): Update.
+ * python/py-breakpoint.c (bppy_get_location)
+ (bppy_get_expression, bppy_get_condition, bppy_get_commands):
+ Update.
+
2018-11-04 Tom Tromey <tom@tromey.com>
* python/python-internal.h (gdb_py_object_from_longest)
str = event_location_to_string (location);
if (! str)
str = "";
- return host_string_to_python_string (str);
+ return host_string_to_python_string (str).release ();
}
/* Python function to get the breakpoint expression. */
if (! str)
str = "";
- return host_string_to_python_string (str);
+ return host_string_to_python_string (str).release ();
}
/* Python function to get the condition expression of a breakpoint. */
if (! str)
Py_RETURN_NONE;
- return host_string_to_python_string (str);
+ return host_string_to_python_string (str).release ();
}
/* Returns 0 on success. Returns -1 on error, with a python exception set.
END_CATCH
current_uiout->redirect (NULL);
- return host_string_to_python_string (stb.c_str ());
+ return host_string_to_python_string (stb.c_str ()).release ();
}
/* Set the commands attached to a breakpoint. Returns 0 on success.
objfile_object *obj = (objfile_object *) self;
if (obj->objfile)
- return host_string_to_python_string (objfile_name (obj->objfile));
+ return (host_string_to_python_string (objfile_name (obj->objfile))
+ .release ());
Py_RETURN_NONE;
}
{
const char *username = obj->objfile->original_name;
- return host_string_to_python_string (username);
+ return host_string_to_python_string (username).release ();
}
Py_RETURN_NONE;
char *hex_form = make_hex_string (build_id->data, build_id->size);
PyObject *result;
- result = host_string_to_python_string (hex_form);
+ result = host_string_to_python_string (hex_form).release ();
xfree (hex_form);
return result;
}
else
{
gdbpy_ref<> string
- (python_string_to_target_python_string (py_str.get ()));
+ = python_string_to_target_python_string (py_str.get ());
if (string != NULL)
{
char *output;
struct objfile *objfile = obj->pspace->symfile_object_file;
if (objfile)
- return host_string_to_python_string (objfile_name (objfile));
+ return (host_string_to_python_string (objfile_name (objfile))
+ .release ());
}
Py_RETURN_NONE;
}
soname = solib_name_from_address (self->pspace, pc);
if (soname == nullptr)
Py_RETURN_NONE;
- return host_string_to_python_string (soname);
+ return host_string_to_python_string (soname).release ();
}
/* Return the innermost lexical block containing the specified pc value,
STPY_REQUIRE_VALID (self, symtab);
filename = symtab_to_filename_for_display (symtab);
- str_obj = host_string_to_python_string (filename);
+ str_obj = host_string_to_python_string (filename).release ();
return str_obj;
}
{
const char *producer = COMPUNIT_PRODUCER (cust);
- return host_string_to_python_string (producer);
+ return host_string_to_python_string (producer).release ();
}
Py_RETURN_NONE;
fullname = symtab_to_fullname (symtab);
- return host_string_to_python_string (fullname);
+ return host_string_to_python_string (fullname).release ();
}
/* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
If the given object is not one of the mentioned string types, NULL is
returned, with the TypeError python exception set. */
-PyObject *
+gdbpy_ref<>
python_string_to_unicode (PyObject *obj)
{
PyObject *unicode_str;
unicode_str = NULL;
}
- return unicode_str;
+ return gdbpy_ref<> (unicode_str);
}
/* Returns a newly allocated string with the contents of the given unicode
object converted to a named charset. If an error occurs during
the conversion, NULL will be returned and a python exception will
be set. */
-static PyObject *
+static gdbpy_ref<>
unicode_to_encoded_python_string (PyObject *unicode_str, const char *charset)
{
/* Translate string to named charset. */
- return PyUnicode_AsEncodedString (unicode_str, charset, NULL);
+ return gdbpy_ref<> (PyUnicode_AsEncodedString (unicode_str, charset, NULL));
}
/* Returns a newly allocated string with the contents of the given
object converted to the target's charset. If an error occurs
during the conversion, NULL will be returned and a python exception
will be set. */
-static PyObject *
+static gdbpy_ref<>
unicode_to_target_python_string (PyObject *unicode_str)
{
return unicode_to_encoded_python_string (unicode_str,
gdb::unique_xmalloc_ptr<char>
python_string_to_target_string (PyObject *obj)
{
- gdbpy_ref<> str (python_string_to_unicode (obj));
+ gdbpy_ref<> str = python_string_to_unicode (obj);
if (str == NULL)
return NULL;
set.
In Python 3, the returned object is a "bytes" object (not a string). */
-PyObject *
+gdbpy_ref<>
python_string_to_target_python_string (PyObject *obj)
{
- gdbpy_ref<> str (python_string_to_unicode (obj));
+ gdbpy_ref<> str = python_string_to_unicode (obj);
if (str == NULL)
- return NULL;
+ return str;
return unicode_to_target_python_string (str.get ());
}
gdb::unique_xmalloc_ptr<char>
python_string_to_host_string (PyObject *obj)
{
- gdbpy_ref<> str (python_string_to_unicode (obj));
+ gdbpy_ref<> str = python_string_to_unicode (obj);
if (str == NULL)
return NULL;
/* Convert a host string to a python string. */
-PyObject *
+gdbpy_ref<>
host_string_to_python_string (const char *str)
{
- return PyString_Decode (str, strlen (str), host_charset (), NULL);
+ return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (),
+ NULL));
}
/* Return true if OBJ is a Python string or unicode object, false
void gdbpy_print_stack (void);
void gdbpy_handle_exception () ATTRIBUTE_NORETURN;
-PyObject *python_string_to_unicode (PyObject *obj);
+gdbpy_ref<> python_string_to_unicode (PyObject *obj);
gdb::unique_xmalloc_ptr<char> unicode_to_target_string (PyObject *unicode_str);
gdb::unique_xmalloc_ptr<char> python_string_to_target_string (PyObject *obj);
-PyObject *python_string_to_target_python_string (PyObject *obj);
+gdbpy_ref<> python_string_to_target_python_string (PyObject *obj);
gdb::unique_xmalloc_ptr<char> python_string_to_host_string (PyObject *obj);
-PyObject *host_string_to_python_string (const char *str);
+gdbpy_ref<> host_string_to_python_string (const char *str);
int gdbpy_is_string (PyObject *obj);
gdb::unique_xmalloc_ptr<char> gdbpy_obj_to_string (PyObject *obj);
gdb::unique_xmalloc_ptr<char> gdbpy_exception_to_string (PyObject *ptype,
if (! str)
str = "";
- return host_string_to_python_string (str);
+ return host_string_to_python_string (str).release ();
}
case var_boolean: