+2016-03-30 Doug Evans <dje@google.com>
+
+ * python/py-utils.c (host_string_to_python_string): New function.
+ * python/python-internal.h (host_string_to_python_string): Declare it.
+ * python/py-*.c (*): Update all calls to
+ PyString_Decode (str, strlen (str), host_charset (), NULL);
+ to use host_string_to_python_string instead.
+
2016-03-30 Marcin KoĆcielnicki <koriakin@0x04.net>
* remote.c (remote_check_symbols): Allocate own buffer for reply.
str = event_location_to_string (obj->bp->location);
if (! str)
str = "";
- return PyString_Decode (str, strlen (str), host_charset (), NULL);
+ return host_string_to_python_string (str);
}
/* Python function to get the breakpoint expression. */
if (! str)
str = "";
- return PyString_Decode (str, strlen (str), host_charset (), NULL);
+ return host_string_to_python_string (str);
}
/* Python function to get the condition expression of a breakpoint. */
if (! str)
Py_RETURN_NONE;
- return PyString_Decode (str, strlen (str), host_charset (), NULL);
+ return host_string_to_python_string (str);
}
/* Returns 0 on success. Returns -1 on error, with a python exception set.
ui_out_redirect (current_uiout, NULL);
cmdstr = ui_file_xstrdup (string_file, &length);
make_cleanup (xfree, cmdstr);
- result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL);
+ result = host_string_to_python_string (cmdstr);
do_cleanups (chain);
return result;
}
objfile_object *obj = (objfile_object *) self;
if (obj->objfile)
- return PyString_Decode (objfile_name (obj->objfile),
- strlen (objfile_name (obj->objfile)),
- host_charset (), NULL);
+ return host_string_to_python_string (objfile_name (obj->objfile));
Py_RETURN_NONE;
}
{
const char *username = obj->objfile->original_name;
- return PyString_Decode (username, strlen (username),
- host_charset (), NULL);
+ return host_string_to_python_string (username);
}
Py_RETURN_NONE;
char *hex_form = make_hex_string (build_id->data, build_id->size);
PyObject *result;
- result = PyString_Decode (hex_form, strlen (hex_form),
- host_charset (), NULL);
+ result = host_string_to_python_string (hex_form);
xfree (hex_form);
return result;
}
struct objfile *objfile = obj->pspace->symfile_object_file;
if (objfile)
- return PyString_Decode (objfile_name (objfile),
- strlen (objfile_name (objfile)),
- host_charset (), NULL);
+ return host_string_to_python_string (objfile_name (objfile));
}
Py_RETURN_NONE;
}
STPY_REQUIRE_VALID (self, symtab);
filename = symtab_to_filename_for_display (symtab);
- str_obj = PyString_Decode (filename, strlen (filename),
- host_charset (), NULL);
+ str_obj = host_string_to_python_string (filename);
return str_obj;
}
{
const char *producer = COMPUNIT_PRODUCER (cust);
- return PyString_Decode (producer, strlen (producer),
- host_charset (), NULL);
+ return host_string_to_python_string (producer);
}
Py_RETURN_NONE;
fullname = symtab_to_fullname (symtab);
- return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
+ return host_string_to_python_string (fullname);
}
/* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
return result;
}
+/* Convert a host string to a python string. */
+
+PyObject *
+host_string_to_python_string (const char *str)
+{
+ return PyString_Decode (str, strlen (str), host_charset (), NULL);
+}
+
/* Return true if OBJ is a Python string or unicode object, false
otherwise. */
char *python_string_to_target_string (PyObject *obj);
PyObject *python_string_to_target_python_string (PyObject *obj);
char *python_string_to_host_string (PyObject *obj);
+PyObject *host_string_to_python_string (const char *str);
int gdbpy_is_string (PyObject *obj);
char *gdbpy_obj_to_string (PyObject *obj);
char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue);
if (! str)
str = "";
- return PyString_Decode (str, strlen (str), host_charset (), NULL);
+ return host_string_to_python_string (str);
}
case var_boolean:
soname = solib_name_from_address (current_program_space, pc);
if (soname)
- str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL);
+ str_obj = host_string_to_python_string (soname);
else
{
str_obj = Py_None;