/* General utility routines for GDB/Python.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Copyright (C) 2008-2016 Free Software Foundation, Inc.
This file is part of GDB.
static void
py_decref (void *p)
{
- PyObject *py = p;
+ PyObject *py = (PyObject *) p;
Py_DECREF (py);
}
static void
py_xdecref (void *p)
{
- PyObject *py = p;
+ PyObject *py = (PyObject *) p;
Py_XDECREF (py);
}
As an added bonus, the functions accepts a unicode string and returns it
right away, so callers don't need to check which kind of string they've
- got. In Python 3, all strings are Unicode so this case is always the
+ got. In Python 3, all strings are Unicode so this case is always the
one that applies.
If the given object is not one of the mentioned string types, NULL is
if (str == NULL)
return NULL;
- result = unicode_to_encoded_string (str, host_charset ());
+ result = unicode_to_encoded_string (str, host_charset ());
Py_DECREF (str);
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. */
}
/* Convert a GDB exception to the appropriate Python exception.
-
+
This sets the Python error indicator. */
void
{
if (gdbpy_is_value_object (obj))
{
- volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
*addr = value_as_address (value_object_to_value (obj));
}
- GDB_PY_SET_HANDLE_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDB_PY_SET_HANDLE_EXCEPTION (except);
+ }
+ END_CATCH
}
else
{
gdb_py_generic_dict (PyObject *self, void *closure)
{
PyObject *result;
- PyTypeObject *type_obj = closure;
+ PyTypeObject *type_obj = (PyTypeObject *) closure;
char *raw_ptr;
raw_ptr = (char *) self + type_obj->tp_dictoffset;