gdb: do autoload before notifying Python side in new_objfile event
[deliverable/binutils-gdb.git] / gdb / python / py-lazy-string.c
index ab3f411743951e1f94cd89bd80383686417242c3..336cecb7361f2603f1190a826a93148201bff992 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to lazy strings.
 
-   Copyright (C) 2010-2017 Free Software Foundation, Inc.
+   Copyright (C) 2010-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -24,7 +24,7 @@
 #include "valprint.h"
 #include "language.h"
 
-typedef struct {
+struct lazy_string_object {
   PyObject_HEAD
 
   /*  Holds the address of the lazy string.  */
@@ -51,7 +51,7 @@ typedef struct {
      This is recorded as a PyObject so that we take advantage of support for
      preserving the type should its owning objfile go away.  */
   PyObject *type;
-} lazy_string_object;
+};
 
 extern PyTypeObject lazy_string_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("lazy_string_object");
@@ -61,7 +61,7 @@ stpy_get_address (PyObject *self, void *closure)
 {
   lazy_string_object *self_string = (lazy_string_object *) self;
 
-  return gdb_py_long_from_ulongest (self_string->address);
+  return gdb_py_object_from_ulongest (self_string->address).release ();
 }
 
 static PyObject *
@@ -88,7 +88,7 @@ stpy_get_length (PyObject *self, void *closure)
 {
   lazy_string_object *self_string = (lazy_string_object *) self;
 
-  return PyLong_FromLong (self_string->length);
+  return gdb_py_object_from_longest (self_string->length).release ();
 }
 
 static PyObject *
@@ -113,14 +113,14 @@ stpy_convert_to_value (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       struct type *type = type_object_to_type (self_string->type);
       struct type *realtype;
 
       gdb_assert (type != NULL);
       realtype = check_typedef (type);
-      switch (TYPE_CODE (realtype))
+      switch (realtype->code ())
        {
        case TYPE_CODE_PTR:
          /* If a length is specified we need to convert this to an array
@@ -142,11 +142,10 @@ stpy_convert_to_value (PyObject *self, PyObject *args)
          break;
        }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -157,6 +156,7 @@ stpy_dealloc (PyObject *self)
   lazy_string_object *self_string = (lazy_string_object *) self;
 
   xfree (self_string->encoding);
+  Py_TYPE (self)->tp_free (self);
 }
 
 /* Low level routine to create a <gdb.LazyString> object.
@@ -194,7 +194,7 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
     }
 
   realtype = check_typedef (type);
-  switch (TYPE_CODE (realtype))
+  switch (realtype->code ())
     {
     case TYPE_CODE_ARRAY:
       {
@@ -258,7 +258,7 @@ stpy_lazy_string_elt_type (lazy_string_object *lazy)
   gdb_assert (type != NULL);
   realtype = check_typedef (type);
 
-  switch (TYPE_CODE (realtype))
+  switch (realtype->code ())
     {
     case TYPE_CODE_PTR:
     case TYPE_CODE_ARRAY:
@@ -300,7 +300,7 @@ static PyMethodDef lazy_string_object_methods[] = {
 };
 
 
-static PyGetSetDef lazy_string_object_getset[] = {
+static gdb_PyGetSetDef lazy_string_object_getset[] = {
   { "address", stpy_get_address, NULL, "Address of the string.", NULL },
   { "encoding", stpy_get_encoding, NULL, "Encoding of the string.", NULL },
   { "length", stpy_get_length, NULL, "Length of the string.", NULL },
This page took 0.02604 seconds and 4 git commands to generate.