This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Python: iterator for deep traversal of gdb.Type struct/union fields


> -----Original Message-----
> From: Tom Tromey [mailto:tromey@redhat.com] 
> Sent: Thursday, October 27, 2011 3:57 PM
> To: Koning, Paul
> Cc: dje@google.com; gdb-patches@sourceware.org
> Subject: Re: [RFA] Python: iterator for deep traversal of gdb.Type struct/union fields
> 
>>>>>> "Paul" ==   <Paul_Koning@Dell.com> writes:
> 
>>> Hi.  Is it too late to change the name to deep_items?
>>> 
>>> I like consistency in the user-facing API and we've been using 
>>> foo_bar (as does PEP008).
>>> 
>>> [Or is there a special reason for eliding the underscore?]
> 
> Paul> No problem that I know of.  It's a trivial change to make if 
> Paul> that's desired.
> 
> Yeah, I think so.
> 
> I was unaware that this is in PEP 8.
> 
> Also, could you write a NEWS item?  I'd like to try to put all Python additions into NEWS.

Like this?

	paul

ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* python/lib/gdb/types.py (deep_items): Rename from deepitems.
	* NEWS: Mention deep_items.

doc/ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* gdb.texinfo (gdb.types): Rename deepitems to deep_items.

testsuite/ChangeLog:

2011-10-27  Paul Koning  <paul_koning@dell.com>

	* gdb.python/lib-types.exp (deep_items): Rename from deepitems.

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.461
diff -u -r1.461 NEWS
--- NEWS	24 Oct 2011 11:49:26 -0000	1.461
+++ NEWS	27 Oct 2011 21:21:31 -0000
@@ -56,6 +56,12 @@
   ** A new event "gdb.new_objfile" has been added, triggered by loading a
      new object file.
 
+  ** A new function, "deep_items" has been added to the gdb.types
+     module in the GDB Python modules library.  This function returns
+     an iterator over the fields of a struct or union type.  Unlike
+     the standard Python "iteritems" method, it will recursively traverse
+     any anonymous fields.
+
 * libthread-db-search-path now supports two special values: $sdir and $pdir.
   $sdir specifies the default system locations of shared libraries.
   $pdir specifies the directory where the libpthread used by the application
Index: python/lib/gdb/types.py
===================================================================
RCS file: /cvs/src/src/gdb/python/lib/gdb/types.py,v
retrieving revision 1.3
diff -u -r1.3 types.py
--- python/lib/gdb/types.py	26 Oct 2011 15:09:40 -0000	1.3
+++ python/lib/gdb/types.py	27 Oct 2011 21:21:35 -0000
@@ -91,7 +91,7 @@
     return enum_dict
 
 
-def deepitems (type_):
+def deep_items (type_):
     """Return an iterator that recursively traverses anonymous fields.
 
     Arguments:
@@ -107,5 +107,5 @@
         if k:
             yield k, v
         else:
-            for i in deepitems (v.type):
+            for i in deep_items (v.type):
                 yield i
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.883
diff -u -r1.883 gdb.texinfo
--- doc/gdb.texinfo	27 Oct 2011 11:04:26 -0000	1.883
+++ doc/gdb.texinfo	27 Oct 2011 21:21:35 -0000
@@ -24438,10 +24438,10 @@
 @item make_enum_dict (@var{enum_type})
 Return a Python @code{dictionary} type produced from @var{enum_type}.
 
-@item deepitems (@var{type})
+@item deep_items (@var{type})
 Returns a Python iterator similar to the standard
 @code{gdb.Type.iteritems} method, except that the iterator returned
-by @code{deepitems} will recursively traverse anonymous struct or
+by @code{deep_items} will recursively traverse anonymous struct or
 union fields.  For example:
 
 @smallexample
@@ -24462,7 +24462,7 @@
 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
 (@value{GDBP}) python print struct_a.keys ()
 @{['a', '']@}
-(@value{GDBP}) python print [k for k,v in gdb.types.deepitems(struct_a)]
+(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
 @{['a', 'b0', 'b1']@}
 @end smallexample
 
Index: testsuite/gdb.python/lib-types.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/lib-types.exp,v
retrieving revision 1.4
diff -u -r1.4 lib-types.exp
--- testsuite/gdb.python/lib-types.exp	26 Oct 2011 15:10:11 -0000	1.4
+++ testsuite/gdb.python/lib-types.exp	27 Oct 2011 21:21:36 -0000
@@ -139,7 +139,7 @@
 gdb_test_no_output "python enum1_list.sort ()"
 gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]}
 
-# test deepitems
+# test deep_items
 gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')"
 gdb_test "python print struct_a.keys ()" {\['a', '', 'c', ''\]}
-gdb_test "python print \[k for k,v in gdb.types.deepitems(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]}
+gdb_test "python print \[k for k,v in gdb.types.deep_items(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]