public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-tromey-python: gdb
Date: Sun, 16 Nov 2008 22:18:00 -0000	[thread overview]
Message-ID: <20081116221848.7126.qmail@sourceware.org> (raw)

The branch, archer-tromey-python has been updated
       via  5cdfaa4b6fea4493eb6dda47d27807a12beef384 (commit)
      from  e97eeebcadd8e1ced9e9e428c6809e01a94dbfac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 5cdfaa4b6fea4493eb6dda47d27807a12beef384
Author: Tom Tromey <tromey@redhat.com>
Date:   Sun Nov 16 15:18:27 2008 -0700

    gdb
    	* python/python-type.c (type_object_type): Add extra fields.
    	(gdbpy_initialize_types): Don't set tp_new.  Ready new type.
    	(pyty_field_object): New type.
    	(field_object_type): New global.
    	(field_dealloc): New function.
    	(field_new): Likewise.
    	(convert_field): Create field objects.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Update.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog            |   10 ++++
 gdb/doc/ChangeLog        |    4 ++
 gdb/doc/gdb.texinfo      |   15 ++---
 gdb/python/python-type.c |  126 ++++++++++++++++++++++++++++++++++++++++------
 4 files changed, 131 insertions(+), 24 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9de4746..7c4bf4e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 2008-11-16  Tom Tromey  <tromey@redhat.com>
 
+	* python/python-type.c (type_object_type): Add extra fields.
+	(gdbpy_initialize_types): Don't set tp_new.  Ready new type.
+	(pyty_field_object): New type.
+	(field_object_type): New global.
+	(field_dealloc): New function.
+	(field_new): Likewise.
+	(convert_field): Create field objects.
+
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
 	* python/python-type.c (typy_code): New function.
 	(struct pyty_code): New type.
 	(ENTRY): New define.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 0b85f5c..e205dea 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -2,6 +2,10 @@
 
 	* gdb.texinfo (Types From Inferior): Update.
 
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Types From Inferior): Update.
+
 2008-11-13  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document gdb.get_objfiles and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6a38009..eb24ece 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17937,28 +17937,25 @@ Return the type code for this type.  The type code will be one of the
 @end defmethod
 
 @defmethod Type fields
-Return a sequence of all fields of this type.  If this type has no
-fields, the sequence will be empty.
-
 For structure and union types, this method returns the fields.  Range
 types have two fields, the minimum and maximum values.  Enum types
 have one field per enum constant.  Function and method types have one
 field per parameter.  The base types of C++ classes are also
-represented as fields.
+represented as fields.  If the type has no fields, or does not fit
+into one of these categories, an empty sequence will be returned.
 
-Each field is a dictionary, with some pre-defined elements:
+Each field is an object, with some pre-defined attributes:
 @table @code
 @item bitpos
-This element is not available for @code{static} fields.  For
+This attribute is not available for @code{static} fields.  For
 non-@code{static} fields, the value is the bit position of the field.
 
 @item name
-The name of the field.  This element is not available for anonymous
-fields.
+The name of the field, or @code{None} for anonymous fields.
 
 @item artificial
 This is @code{True} if the field is artificial, usually meaning that
-it was provided by the compiler and not the user.  This value is
+it was provided by the compiler and not the user.  This attribute is
 always provided, and is @code{False} if the field is not artificial.
 
 @item bitsize
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index f24a023..31af1ed 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -50,6 +50,17 @@ typedef struct pyty_type_object
 
 static PyTypeObject type_object_type;
 
+/* A Field object.  */
+typedef struct pyty_field_object
+{
+  PyObject_HEAD
+
+  /* Dictionary holding our attributes.  */
+  PyObject *dict;
+} field_object;
+
+static PyTypeObject field_object_type;
+
 /* This is used to initialize various gdb.TYPE_ constants.  */
 struct pyty_code
 {
@@ -96,6 +107,31 @@ static struct pyty_code pyty_codes[] =
 
 \f
 
+static void
+field_dealloc (PyObject *obj)
+{
+  field_object *f = (field_object *) obj;
+  Py_XDECREF (f->dict);
+}
+
+static PyObject *
+field_new (void)
+{
+  field_object *result = PyObject_New (field_object, &field_object_type);
+  if (result)
+    {
+      result->dict = PyDict_New ();
+      if (!result->dict)
+	{
+	  Py_DECREF (result);
+	  result = NULL;
+	}
+    }
+  return (PyObject *) result;
+}
+
+\f
+
 /* Return the code for this type.  */
 static PyObject *
 typy_code (PyObject *self, PyObject *args)
@@ -109,10 +145,10 @@ typy_code (PyObject *self, PyObject *args)
 static PyObject *
 convert_field (PyObject *self, struct type *type, int field)
 {
-  PyObject *dict = PyDict_New ();
+  PyObject *result = field_new ();
   PyObject *arg;
 
-  if (!dict)
+  if (!result)
     return NULL;
 
   if (!TYPE_FIELD_STATIC (type, field))
@@ -121,42 +157,45 @@ convert_field (PyObject *self, struct type *type, int field)
       if (!arg)
 	goto fail;
 
-      if (PyDict_SetItemString (dict, "bitpos", arg) < 0)
+      if (PyObject_SetAttrString (result, "bitpos", arg) < 0)
 	goto failarg;
     }
 
   if (TYPE_FIELD_NAME (type, field))
+    arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
+  else
     {
-      arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
-      if (!arg)
-	goto fail;
-      if (PyDict_SetItemString (dict, "name", arg) < 0)
-	goto failarg;
+      arg = Py_None;
+      Py_INCREF (arg);
     }
+  if (!arg)
+    goto fail;
+  if (PyObject_SetAttrString (result, "name", arg) < 0)
+    goto failarg;
 
   arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False;
   Py_INCREF (arg);
-  if (PyDict_SetItemString (dict, "artificial", arg) < 0)
+  if (PyObject_SetAttrString (result, "artificial", arg) < 0)
     goto failarg;
 
   arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
   if (!arg)
     goto fail;
-  if (PyDict_SetItemString (dict, "bitsize", arg) < 0)
+  if (PyObject_SetAttrString (result, "bitsize", arg) < 0)
     goto failarg;
 
   arg = type_to_type_object (self, TYPE_FIELD_TYPE (type, field));
   if (!arg)
     goto fail;
-  if (PyDict_SetItemString (dict, "type", arg) < 0)
+  if (PyObject_SetAttrString (result, "type", arg) < 0)
     goto failarg;
 
-  return dict;
+  return result;
 
  failarg:
   Py_DECREF (arg);
  fail:
-  Py_DECREF (dict);
+  Py_DECREF (result);
   return NULL;
 }
 
@@ -169,6 +208,9 @@ typy_fields (PyObject *self, PyObject *args)
   int i;
   struct type *type = ((type_object *) self)->type;
 
+  /* We would like to make a tuple here, make fields immutable, and
+     then memoize the result (and perhaps make Field.type() lazy).
+     However, that can lead to cycles.  */
   result = PyList_New (0);
 
   for (i = 0; i < TYPE_NFIELDS (type); ++i)
@@ -624,9 +666,10 @@ gdbpy_initialize_types (void)
   typy_objfile_data_key
     = register_objfile_data_with_cleanup (clean_up_objfile_types);
 
-  type_object_type.tp_new = typy_new;
   if (PyType_Ready (&type_object_type) < 0)
     return;
+  if (PyType_Ready (&field_object_type) < 0)
+    return;
 
   for (i = 0; pyty_codes[i].name; ++i)
     {
@@ -691,5 +734,58 @@ static PyTypeObject type_object_type =
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  type_object_methods		  /* tp_methods */
+  type_object_methods,		  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  0,				  /* tp_dictoffset */
+  0,				  /* tp_init */
+  0,				  /* tp_alloc */
+  typy_new,			  /* tp_new */
+};
+
+static PyTypeObject field_object_type =
+{
+  PyObject_HEAD_INIT (NULL)
+  0,				  /*ob_size*/
+  "gdb.Field",			  /*tp_name*/
+  sizeof (field_object),	  /*tp_basicsize*/
+  0,				  /*tp_itemsize*/
+  field_dealloc,		  /*tp_dealloc*/
+  0,				  /*tp_print*/
+  0,				  /*tp_getattr*/
+  0,				  /*tp_setattr*/
+  0,				  /*tp_compare*/
+  0,				  /*tp_repr*/
+  0,				  /*tp_as_number*/
+  0,				  /*tp_as_sequence*/
+  0,				  /*tp_as_mapping*/
+  0,				  /*tp_hash */
+  0,				  /*tp_call*/
+  0,				  /*tp_str*/
+  0,				  /*tp_getattro*/
+  0,				  /*tp_setattro*/
+  0,				  /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
+  "GDB field object",		  /* tp_doc */
+  0,				  /* tp_traverse */
+  0,				  /* tp_clear */
+  0,				  /* tp_richcompare */
+  0,				  /* tp_weaklistoffset */
+  0,				  /* tp_iter */
+  0,				  /* tp_iternext */
+  0,				  /* tp_methods */
+  0,				  /* tp_members */
+  0,				  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  offsetof (field_object, dict),  /* tp_dictoffset */
+  0,				  /* tp_init */
+  0,				  /* tp_alloc */
+  0,				  /* tp_new */
 };


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2008-11-16 22:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-16 22:18 tromey [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-04-07 20:28 tromey
2009-03-24 17:27 tromey
2009-02-05 19:56 tromey
2008-12-17 23:10 tromey
2008-12-15 22:38 tromey
2008-12-13  0:37 tromey
2008-12-12 23:54 tromey
2008-12-10 15:28 tromey
2008-12-09  0:33 tromey
2008-12-02 21:29 tromey
2008-12-01 19:10 tromey
2008-11-25 21:17 tromey
2008-11-21 18:25 tromey
2008-11-18 18:52 tromey
2008-11-18 15:54 tromey
2008-11-17 15:45 tromey
2008-11-16 16:56 tromey
2008-11-12  1:54 tromey
2008-11-10 14:15 tromey
2008-11-06 21:11 tromey
2008-11-06 19:58 tromey
2008-10-23 22:27 tromey
2008-10-23 21:28 tromey
2008-10-22 18:18 tromey
2008-10-21 18:32 tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081116221848.7126.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).