Re: [PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-30 Thread Tom Tromey
 I don't think this comment is applicable.
 The libstdc++ pretty-printers use gdb.Value.lazy_string, not the
 built-in Python types.

Samuel Hmm, doesn't that just make it a timebomb -- a value that will
Samuel explode if, at some point in the future, someone tries to treat
Samuel it as a string?

I don't think so.
The results from the pretty-printer, when called from gdb, are generally
either printed or discarded.
In any case the comment still doesn't seem correct.

Tom


Re: [PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-25 Thread Samuel Bronson
Tom Tromey tro...@redhat.com writes:

 Samuel == Samuel Bronson naes...@gmail.com writes:

 Samuel +# FIXME: The handling of e.g. std::basic_string (at least on char)
 Samuel +# probably needs updating to work with Python 3's new string rules.
 Samuel +#
 Samuel +# In particular, Python 3 has a separate type (called byte) for
 Samuel +# bytestrings, and a special b syntax for the byte literals; the 
 old
 Samuel +# str() type has been redefined to always store Unicode text.
 Samuel +#
 Samuel +# We probably can't do much about this until GDB get their act
 Samuel +# together: https://sourceware.org/bugzilla/show_bug.cgi?id=17138

 I don't think this comment is applicable.
 The libstdc++ pretty-printers use gdb.Value.lazy_string, not the
 built-in Python types.

Hmm, doesn't that just make it a timebomb -- a value that will explode
if, at some point in the future, someone tries to treat it as a string?

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


Re: [PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-21 Thread Tom Tromey
 Samuel == Samuel Bronson naes...@gmail.com writes:

Samuel +# FIXME: The handling of e.g. std::basic_string (at least on char)
Samuel +# probably needs updating to work with Python 3's new string rules.
Samuel +#
Samuel +# In particular, Python 3 has a separate type (called byte) for
Samuel +# bytestrings, and a special b syntax for the byte literals; the old
Samuel +# str() type has been redefined to always store Unicode text.
Samuel +#
Samuel +# We probably can't do much about this until GDB get their act
Samuel +# together: https://sourceware.org/bugzilla/show_bug.cgi?id=17138

I don't think this comment is applicable.
The libstdc++ pretty-printers use gdb.Value.lazy_string, not the
built-in Python types.

Tom


Re: [PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-11 Thread Jonathan Wakely

On 10/07/14 22:48 -0400, Samuel Bronson wrote:

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
  (imap): New compat function.
  (izip): Likewise.
  (Iterator): New mixin to allow writing iterators in Python 3 style
  regardless of which version we're running on.
  [Python3] (long) New compat alias for int.
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)


Thanks, I've committed this with a few tiny changes to the comments
(s/compatability/compatibility/ and the comment about your GDB PR).

I'm not planning to backport this myself, but if the patch applies
cleanly or if someone else does the work then I have no objections to
it going on the release branches (after the branch reopens post-4.9.1
of course).

Thanks very much for doing this.


[PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-10 Thread Samuel Bronson

Loosely based on Matthias Klose's earlier patch
http://patchwork.ozlabs.org/patch/287368/.

This time with his name spelled correctly; sorry about that!

Tested with:

$ make check-target-libstdc++-v3 RUNTESTFLAGS='--directory 
libstdc++-prettyprinters'

libstdc++-v3/

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
  (imap): New compat function.
  (izip): Likewise.
  (Iterator): New mixin to allow writing iterators in Python 3 style
  regardless of which version we're running on.
  [Python3] (long) New compat alias for int.
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Signed-off-by: Matthias Klose d...@ubuntu.com
Signed-off-by: Samuel Bronson naes...@gmail.com
---
 libstdc++-v3/python/libstdcxx/v6/printers.py | 110 +++
 libstdc++-v3/testsuite/lib/gdb-test.exp  |   4 +-
 2 files changed, 79 insertions(+), 35 deletions(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 623a815..313b08d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1,4 +1,4 @@
-# Pretty-printers for libstc++.
+# Pretty-printers for libstdc++.
 
 # Copyright (C) 2008-2014 Free Software Foundation, Inc.
 
@@ -18,6 +18,50 @@
 import gdb
 import itertools
 import re
+import sys
+
+### Python 2 + Python 3 compatability code
+
+# Resources about compatability:
+#
+#  * http://pythonhosted.org/six/: Documentation of the six module
+
+# FIXME: The handling of e.g. std::basic_string (at least on char)
+# probably needs updating to work with Python 3's new string rules.
+#
+# In particular, Python 3 has a separate type (called byte) for
+# bytestrings, and a special b syntax for the byte literals; the old
+# str() type has been redefined to always store Unicode text.
+#
+# We probably can't do much about this until GDB get their act
+# together: https://sourceware.org/bugzilla/show_bug.cgi?id=17138
+
+if sys.version_info[0]  2:
+### Python 3 stuff
+Iterator = object
+# Python 3 folds these into the normal functions.
+imap = map
+izip = zip
+# Also, int subsumes long
+long = int
+else:
+### Python 2 stuff
+class Iterator:
+Compatability mixin for iterators
+
+Instead of writing next() methods for iterators, write
+__next__() methods and use this mixin to make them work in
+Python 2 as well as Python 3.
+
+Idea stolen from the six documentation:
+http://pythonhosted.org/six/#six.Iterator
+
+
+def next(self):
+return self.__next__()
+
+# In Python 2, we still need these from itertools
+from itertools import imap, izip
 
 # Try to use the new-style pretty-printing if available.
 _use_gdb_pp = True
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 class StdListPrinter:
 Print a std::list
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_next']
@@ -97,7 +141,7 @@ class StdListPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == self.head:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -135,7 +179,7 @@ class StdListIteratorPrinter:
 class StdSlistPrinter:
 Print a __gnu_cxx::slist
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_head']['_M_next']
@@ -144,7 +188,7 @@ class StdSlistPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == 0:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -180,7 +224,7 @@ class StdSlistIteratorPrinter:
 class StdVectorPrinter:
 Print a std::vector
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, start, finish, bitvec):
 self.bitvec = bitvec
 if bitvec:
@@ -198,7 +242,7 @@ class StdVectorPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 count = self.count
 self.count = self.count + 1
 if self.bitvec:
@@ -265,7 +309,7 @@ class StdVectorIteratorPrinter:
 class StdTuplePrinter:
 Print a std::tuple
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, head):
 self.head = head
 
@@ -282,7 +326,7 @@ class StdTuplePrinter:
 def __iter__ (self):
 return self
 
-def next (self):
+def __next__ (self):
 nodes = self.head.type.fields ()
 # Check