]> Git Repo - binutils.git/blobdiff - gdb/python/py-lazy-string.c
Turn gdbpy_ref into a template
[binutils.git] / gdb / python / py-lazy-string.c
index 3a02a3b6367cc782cb97f148a24b63d911a7e12e..4af4566ef647d7b46140e854c7e31d6f1bff1083 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to lazy strings.
 
-   Copyright (C) 2010-2012 Free Software Foundation, Inc.
+   Copyright (C) 2010-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "python-internal.h"
 #include "charset.h"
 #include "value.h"
-#include "exceptions.h"
 #include "valprint.h"
 #include "language.h"
-#include "gdb_assert.h"
 
 typedef struct {
   PyObject_HEAD
@@ -47,7 +45,8 @@ typedef struct {
   struct type *type;
 } lazy_string_object;
 
-static PyTypeObject lazy_string_object_type;
+extern PyTypeObject lazy_string_object_type
+    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("lazy_string_object");
 
 static PyObject *
 stpy_get_address (PyObject *self, void *closure)
@@ -97,20 +96,23 @@ stpy_convert_to_value  (PyObject *self, PyObject *args)
 {
   lazy_string_object *self_string = (lazy_string_object *) self;
   struct value *val = NULL;
-  volatile struct gdb_exception except;
 
   if (self_string->address == 0)
     {
-      PyErr_SetString (PyExc_MemoryError,
+      PyErr_SetString (gdbpy_gdb_memory_error,
                       _("Cannot create a value from NULL."));
       return NULL;
     }
 
-  TRY_CATCH (except, RETURN_MASK_ALL)
+  TRY
     {
       val = value_at_lazy (self_string->type, self_string->address);
     }
-  GDB_PY_HANDLE_EXCEPTION (except);
+  CATCH (except, RETURN_MASK_ALL)
+    {
+      GDB_PY_HANDLE_EXCEPTION (except);
+    }
+  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -131,7 +133,7 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
 
   if (address == 0 && length != 0)
     {
-      PyErr_SetString (PyExc_MemoryError,
+      PyErr_SetString (gdbpy_gdb_memory_error,
                       _("Cannot create a lazy string with address 0x0, " \
                         "and a non-zero length."));
       return NULL;
@@ -159,13 +161,14 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
   return (PyObject *) str_obj;
 }
 
-void
+int
 gdbpy_initialize_lazy_string (void)
 {
   if (PyType_Ready (&lazy_string_object_type) < 0)
-    return;
+    return -1;
 
   Py_INCREF (&lazy_string_object_type);
+  return 0;
 }
 
 /* Determine whether the printer object pointed to by OBJ is a
@@ -177,14 +180,13 @@ gdbpy_is_lazy_string (PyObject *result)
 }
 
 /* Extract the parameters from the lazy string object STRING.
-   ENCODING will either be set to NULL, or will be allocated with
-   xmalloc, in which case the callers is responsible for freeing
-   it.  */
+   ENCODING may be set to NULL, if no encoding is found.  */
 
 void
 gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
                           struct type **str_type,
-                          long *length, char **encoding)
+                          long *length,
+                          gdb::unique_xmalloc_ptr<char> *encoding)
 {
   lazy_string_object *lazy;
 
@@ -195,7 +197,7 @@ gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr,
   *addr = lazy->address;
   *str_type = lazy->type;
   *length = lazy->length;
-  *encoding = lazy->encoding ? xstrdup (lazy->encoding) : NULL;
+  encoding->reset (lazy->encoding ? xstrdup (lazy->encoding) : NULL);
 }
 
 \f
@@ -215,7 +217,7 @@ static PyGetSetDef lazy_string_object_getset[] = {
   { NULL }  /* Sentinel */
 };
 
-static PyTypeObject lazy_string_object_type = {
+PyTypeObject lazy_string_object_type = {
   PyVarObject_HEAD_INIT (NULL, 0)
   "gdb.LazyString",              /*tp_name*/
   sizeof (lazy_string_object),   /*tp_basicsize*/
This page took 0.030219 seconds and 4 git commands to generate.