* python/py-arch.c (arch_object_type): Use
[deliverable/binutils-gdb.git] / gdb / python / py-symtab.c
index e9e38b2f3c7708f30df5f0aa8f24af436117ecf0..94c05be90a2a6170e6ce1f0867fd3de1273d871d 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to symbol tables.
 
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -37,7 +37,8 @@ typedef struct stpy_symtab_object {
   struct stpy_symtab_object *next;
 } symtab_object;
 
-static PyTypeObject symtab_object_type;
+static PyTypeObject symtab_object_type
+    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object");
 static const struct objfile_data *stpy_objfile_data_key;
 
 /* Require a valid symbol table.  All access to symtab_object->symtab
@@ -67,7 +68,8 @@ typedef struct salpy_sal_object {
   struct salpy_sal_object *next;
 } sal_object;
 
-static PyTypeObject sal_object_type;
+static PyTypeObject sal_object_type
+    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
 static const struct objfile_data *salpy_objfile_data_key;
 
 /* Require a valid symbol table and line object.  All access to
@@ -91,7 +93,7 @@ stpy_str (PyObject *self)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  result = PyString_FromString (symtab->filename);
+  result = PyString_FromString (symtab_to_filename_for_display (symtab));
 
   return result;
 }
@@ -101,11 +103,12 @@ stpy_get_filename (PyObject *self, void *closure)
 {
   PyObject *str_obj;
   struct symtab *symtab = NULL;
+  const char *filename;
 
   STPY_REQUIRE_VALID (self, symtab);
+  filename = symtab_to_filename_for_display (symtab);
 
-  str_obj = PyString_Decode (symtab->filename,
-                            strlen (symtab->filename),
+  str_obj = PyString_Decode (filename, strlen (filename),
                             host_charset (), NULL);
   return str_obj;
 }
@@ -126,17 +129,14 @@ stpy_get_objfile (PyObject *self, void *closure)
 static PyObject *
 stpy_fullname (PyObject *self, PyObject *args)
 {
-  char *fullname;
+  const char *fullname;
   struct symtab *symtab = NULL;
 
   STPY_REQUIRE_VALID (self, symtab);
 
   fullname = symtab_to_fullname (symtab);
-  if (fullname)
-    return PyString_Decode (fullname, strlen (fullname),
-                           host_charset (), NULL);
 
-  Py_RETURN_NONE;
+  return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
 }
 
 /* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
@@ -189,7 +189,8 @@ stpy_static_block (PyObject *self, PyObject *args)
 static PyObject *
 salpy_str (PyObject *self)
 {
-  char *s, *filename;
+  char *s;
+  const char *filename;
   sal_object *sal_obj;
   PyObject *result;
   struct symtab_and_line *sal = NULL;
@@ -198,7 +199,7 @@ salpy_str (PyObject *self)
 
   sal_obj = (sal_object *) self;
   filename = (sal_obj->symtab == (symtab_object *) Py_None)
-    ? "<unknown>" : sal_obj->symtab->symtab->filename;
+    ? "<unknown>" : symtab_to_filename_for_display (sal_obj->symtab->symtab);
 
   s = xstrprintf ("symbol and line for %s, line %d", filename,
                  sal->line);
@@ -237,6 +238,22 @@ salpy_get_pc (PyObject *self, void *closure)
   return gdb_py_long_from_ulongest (sal->pc);
 }
 
+/* Implementation of the get method for the 'last' attribute of
+   gdb.Symtab_and_line.  */
+
+static PyObject *
+salpy_get_last (PyObject *self, void *closure)
+{
+  struct symtab_and_line *sal = NULL;
+
+  SALPY_REQUIRE_VALID (self, sal);
+
+  if (sal->end > 0)
+    return gdb_py_long_from_ulongest (sal->end - 1);
+  else
+    Py_RETURN_NONE;
+}
+
 static PyObject *
 salpy_get_line (PyObject *self, void *closure)
 {
@@ -291,7 +308,7 @@ salpy_dealloc (PyObject *self)
 
   Py_DECREF (self_sal->symtab);
   xfree (self_sal->sal);
-  self_sal->ob_type->tp_free (self);
+  Py_TYPE (self)->tp_free (self);
 }
 
 /* Given a sal, and a sal_object that has previously been allocated
@@ -454,7 +471,10 @@ del_objfile_sal (struct objfile *objfile, void *datum)
     {
       sal_object *next = obj->next;
 
-      obj->symtab = NULL;
+      Py_DECREF (obj->symtab);
+      obj->symtab = (symtab_object *) Py_None;
+      Py_INCREF (Py_None);
+
       obj->next = NULL;
       obj->prev = NULL;
       xfree (obj->sal);
@@ -520,8 +540,7 @@ Return the static block of the symbol table." },
 };
 
 static PyTypeObject symtab_object_type = {
-  PyObject_HEAD_INIT (NULL)
-  0,                             /*ob_size*/
+  PyVarObject_HEAD_INIT (NULL, 0)
   "gdb.Symtab",                          /*tp_name*/
   sizeof (symtab_object),        /*tp_basicsize*/
   0,                             /*tp_itemsize*/
@@ -556,6 +575,8 @@ static PyTypeObject symtab_object_type = {
 static PyGetSetDef sal_object_getset[] = {
   { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
   { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
+  { "last", salpy_get_last, NULL,
+    "Return the symtab_and_line's last address.", NULL },
   { "line", salpy_get_line, NULL,
     "Return the symtab_and_line's line.", NULL },
   {NULL}  /* Sentinel */
@@ -569,8 +590,7 @@ Return true if this symbol table and line is valid, false if not." },
 };
 
 static PyTypeObject sal_object_type = {
-  PyObject_HEAD_INIT (NULL)
-  0,                             /*ob_size*/
+  PyVarObject_HEAD_INIT (NULL, 0)
   "gdb.Symtab_and_line",         /*tp_name*/
   sizeof (sal_object),           /*tp_basicsize*/
   0,                             /*tp_itemsize*/
This page took 0.025169 seconds and 4 git commands to generate.