gdb: Use vector::emplace_back
[deliverable/binutils-gdb.git] / gdb / python / py-utils.c
index bbbdef4ad5b5cb8579d13512ea5a0bad03b729ee..2e2121d6d687d4093e01f4a3658176eaf0d89663 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -29,7 +29,7 @@
 static void
 py_decref (void *p)
 {
-  PyObject *py = p;
+  PyObject *py = (PyObject *) p;
 
   Py_DECREF (py);
 }
@@ -50,7 +50,7 @@ make_cleanup_py_decref (PyObject *py)
 static void
 py_xdecref (void *p)
 {
-  PyObject *py = p;
+  PyObject *py = (PyObject *) p;
 
   Py_XDECREF (py);
 }
@@ -71,7 +71,7 @@ make_cleanup_py_xdecref (PyObject *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
@@ -216,11 +216,19 @@ python_string_to_host_string (PyObject *obj)
   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.  */
 
@@ -288,7 +296,7 @@ gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue)
 }
 
 /* Convert a GDB exception to the appropriate Python exception.
-   
+
    This sets the Python error indicator.  */
 
 void
@@ -316,13 +324,16 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
 {
   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
     {
@@ -417,7 +428,7 @@ PyObject *
 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;
This page took 0.044461 seconds and 4 git commands to generate.