~ubuntu-branches/debian/sid/gcc-4.8/sid

« back to all changes in this revision

Viewing changes to .svn/pristine/69/697c14a7d270948b19ad0fc28bf97f14d490e612.svn-base

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-12-19 19:48:34 UTC
  • Revision ID: package-import@ubuntu.com-20141219194834-4dz1q7rrn5pad823
Tags: 4.8.4-1
* GCC 4.8.4 release.
  - Fix PR target/61407 (darwin), PR middle-end/58624 (ice),
    PR sanitizer/64265 (wrong code).
* Require recent binutils to pass go test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# DP: libstdc++ pretty-printers: Backport Python 3 support from mainline
 
2
 
 
3
2014-08-13  Samuel Bronson  <naesten@gmail.com>
 
4
 
 
5
        Backport r212453 from trunk
 
6
        2014-07-11  Samuel Bronson  <naesten@gmail.com>
 
7
                    Matthias Klose  <doko@ubuntu.com>
 
8
 
 
9
        PR libstdc++/58962
 
10
        * python/libstdcxx/v6/printers.py: Port to Python 2+3
 
11
        (imap): New compat function.
 
12
        (izip): Likewise.
 
13
        (Iterator): New mixin to allow writing iterators in Python 3 style
 
14
        regardless of which version we're running on.
 
15
        [Python3] (long) New compat alias for "int".
 
16
        * testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)
 
17
 
 
18
        Backport r210625 from trunk
 
19
        2014-05-19  Jonathan Wakely  <jwakely@redhat.com>
 
20
 
 
21
        * python/libstdcxx/v6/printers.py: Use Python3 raise syntax.
 
22
 
 
23
--- a/src/libstdc++-v3/python/libstdcxx/v6/printers.py
 
24
+++ b/src/libstdc++-v3/python/libstdcxx/v6/printers.py
 
25
@@ -1,4 +1,4 @@
 
26
-# Pretty-printers for libstc++.
 
27
+# Pretty-printers for libstdc++.
 
28
 
 
29
 # Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
30
 
 
31
@@ -18,6 +18,50 @@
 
32
 import gdb
 
33
 import itertools
 
34
 import re
 
35
+import sys
 
36
+
 
37
+### Python 2 + Python 3 compatibility code
 
38
+
 
39
+# Resources about compatibility:
 
40
+#
 
41
+#  * <http://pythonhosted.org/six/>: Documentation of the "six" module
 
42
+
 
43
+# FIXME: The handling of e.g. std::basic_string (at least on char)
 
44
+# probably needs updating to work with Python 3's new string rules.
 
45
+#
 
46
+# In particular, Python 3 has a separate type (called byte) for
 
47
+# bytestrings, and a special b"" syntax for the byte literals; the old
 
48
+# str() type has been redefined to always store Unicode text.
 
49
+#
 
50
+# We probably can't do much about this until this GDB PR is addressed:
 
51
+# <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
 
52
+
 
53
+if sys.version_info[0] > 2:
 
54
+    ### Python 3 stuff
 
55
+    Iterator = object
 
56
+    # Python 3 folds these into the normal functions.
 
57
+    imap = map
 
58
+    izip = zip
 
59
+    # Also, int subsumes long
 
60
+    long = int
 
61
+else:
 
62
+    ### Python 2 stuff
 
63
+    class Iterator:
 
64
+        """Compatibility mixin for iterators
 
65
+
 
66
+        Instead of writing next() methods for iterators, write
 
67
+        __next__() methods and use this mixin to make them work in
 
68
+        Python 2 as well as Python 3.
 
69
+
 
70
+        Idea stolen from the "six" documentation:
 
71
+        <http://pythonhosted.org/six/#six.Iterator>
 
72
+        """
 
73
+
 
74
+        def next(self):
 
75
+            return self.__next__()
 
76
+
 
77
+    # In Python 2, we still need these from itertools
 
78
+    from itertools import imap, izip
 
79
 
 
80
 # Try to use the new-style pretty-printing if available.
 
81
 _use_gdb_pp = True
 
82
@@ -51,7 +95,7 @@ def find_type(orig, name):
 
83
         # anything fancier here.
 
84
         field = typ.fields()[0]
 
85
         if not field.is_base_class:
 
86
-            raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
 
87
+            raise ValueError("Cannot find type %s::%s" % (str(orig), name))
 
88
         typ = field.type
 
89
 
 
90
 class SharedPointerPrinter:
 
91
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 
92
 class StdListPrinter:
 
93
     "Print a std::list"
 
94
 
 
95
-    class _iterator:
 
96
+    class _iterator(Iterator):
 
97
         def __init__(self, nodetype, head):
 
98
             self.nodetype = nodetype
 
99
             self.base = head['_M_next']
 
100
@@ -97,7 +141,7 @@ class StdListPrinter:
 
101
         def __iter__(self):
 
102
             return self
 
103
 
 
104
-        def next(self):
 
105
+        def __next__(self):
 
106
             if self.base == self.head:
 
107
                 raise StopIteration
 
108
             elt = self.base.cast(self.nodetype).dereference()
 
109
@@ -135,7 +179,7 @@ class StdListIteratorPrinter:
 
110
 class StdSlistPrinter:
 
111
     "Print a __gnu_cxx::slist"
 
112
 
 
113
-    class _iterator:
 
114
+    class _iterator(Iterator):
 
115
         def __init__(self, nodetype, head):
 
116
             self.nodetype = nodetype
 
117
             self.base = head['_M_head']['_M_next']
 
118
@@ -144,7 +188,7 @@ class StdSlistPrinter:
 
119
         def __iter__(self):
 
120
             return self
 
121
 
 
122
-        def next(self):
 
123
+        def __next__(self):
 
124
             if self.base == 0:
 
125
                 raise StopIteration
 
126
             elt = self.base.cast(self.nodetype).dereference()
 
127
@@ -180,7 +224,7 @@ class StdSlistIteratorPrinter:
 
128
 class StdVectorPrinter:
 
129
     "Print a std::vector"
 
130
 
 
131
-    class _iterator:
 
132
+    class _iterator(Iterator):
 
133
         def __init__ (self, start, finish, bitvec):
 
134
             self.bitvec = bitvec
 
135
             if bitvec:
 
136
@@ -198,7 +242,7 @@ class StdVectorPrinter:
 
137
         def __iter__(self):
 
138
             return self
 
139
 
 
140
-        def next(self):
 
141
+        def __next__(self):
 
142
             count = self.count
 
143
             self.count = self.count + 1
 
144
             if self.bitvec:
 
145
@@ -265,7 +309,7 @@ class StdVectorIteratorPrinter:
 
146
 class StdTuplePrinter:
 
147
     "Print a std::tuple"
 
148
 
 
149
-    class _iterator:
 
150
+    class _iterator(Iterator):
 
151
         def __init__ (self, head):
 
152
             self.head = head
 
153
 
 
154
@@ -276,20 +320,20 @@ class StdTuplePrinter:
 
155
                 # Set the actual head to the first pair.
 
156
                 self.head  = self.head.cast (nodes[0].type)
 
157
             elif len (nodes) != 0:
 
158
-                raise ValueError, "Top of tuple tree does not consist of a single node."
 
159
+                raise ValueError("Top of tuple tree does not consist of a single node.")
 
160
             self.count = 0
 
161
 
 
162
         def __iter__ (self):
 
163
             return self
 
164
 
 
165
-        def next (self):
 
166
+        def __next__ (self):
 
167
             nodes = self.head.type.fields ()
 
168
             # Check for further recursions in the inheritance tree.
 
169
             if len (nodes) == 0:
 
170
                 raise StopIteration
 
171
             # Check that this iteration has an expected structure.
 
172
             if len (nodes) != 2:
 
173
-                raise ValueError, "Cannot parse more than 2 nodes in a tuple tree."
 
174
+                raise ValueError("Cannot parse more than 2 nodes in a tuple tree.")
 
175
 
 
176
             # - Left node is the next recursion parent.
 
177
             # - Right node is the actual class contained in the tuple.
 
178
@@ -341,7 +385,7 @@ class StdStackOrQueuePrinter:
 
179
             return self.visualizer.display_hint ()
 
180
         return None
 
181
 
 
182
-class RbtreeIterator:
 
183
+class RbtreeIterator(Iterator):
 
184
     def __init__(self, rbtree):
 
185
         self.size = rbtree['_M_t']['_M_impl']['_M_node_count']
 
186
         self.node = rbtree['_M_t']['_M_impl']['_M_header']['_M_left']
 
187
@@ -353,7 +397,7 @@ class RbtreeIterator:
 
188
     def __len__(self):
 
189
         return int (self.size)
 
190
 
 
191
-    def next(self):
 
192
+    def __next__(self):
 
193
         if self.count == self.size:
 
194
             raise StopIteration
 
195
         result = self.node
 
196
@@ -405,7 +449,7 @@ class StdMapPrinter:
 
197
     "Print a std::map or std::multimap"
 
198
 
 
199
     # Turn an RbtreeIterator into a pretty-print iterator.
 
200
-    class _iter:
 
201
+    class _iter(Iterator):
 
202
         def __init__(self, rbiter, type):
 
203
             self.rbiter = rbiter
 
204
             self.count = 0
 
205
@@ -414,9 +458,9 @@ class StdMapPrinter:
 
206
         def __iter__(self):
 
207
             return self
 
208
 
 
209
-        def next(self):
 
210
+        def __next__(self):
 
211
             if self.count % 2 == 0:
 
212
-                n = self.rbiter.next()
 
213
+                n = next(self.rbiter)
 
214
                 n = n.cast(self.type).dereference()['_M_value_field']
 
215
                 self.pair = n
 
216
                 item = n['first']
 
217
@@ -447,7 +491,7 @@ class StdSetPrinter:
 
218
     "Print a std::set or std::multiset"
 
219
 
 
220
     # Turn an RbtreeIterator into a pretty-print iterator.
 
221
-    class _iter:
 
222
+    class _iter(Iterator):
 
223
         def __init__(self, rbiter, type):
 
224
             self.rbiter = rbiter
 
225
             self.count = 0
 
226
@@ -456,8 +500,8 @@ class StdSetPrinter:
 
227
         def __iter__(self):
 
228
             return self
 
229
 
 
230
-        def next(self):
 
231
-            item = self.rbiter.next()
 
232
+        def __next__(self):
 
233
+            item = next(self.rbiter)
 
234
             item = item.cast(self.type).dereference()['_M_value_field']
 
235
             # FIXME: this is weird ... what to do?
 
236
             # Maybe a 'set' display hint?
 
237
@@ -522,7 +566,7 @@ class StdBitsetPrinter:
 
238
 class StdDequePrinter:
 
239
     "Print a std::deque"
 
240
 
 
241
-    class _iter:
 
242
+    class _iter(Iterator):
 
243
         def __init__(self, node, start, end, last, buffer_size):
 
244
             self.node = node
 
245
             self.p = start
 
246
@@ -534,7 +578,7 @@ class StdDequePrinter:
 
247
         def __iter__(self):
 
248
             return self
 
249
 
 
250
-        def next(self):
 
251
+        def __next__(self):
 
252
             if self.p == self.last:
 
253
                 raise StopIteration
 
254
 
 
255
@@ -619,7 +663,7 @@ class StdStringPrinter:
 
256
     def display_hint (self):
 
257
         return 'string'
 
258
 
 
259
-class Tr1HashtableIterator:
 
260
+class Tr1HashtableIterator(Iterator):
 
261
     def __init__ (self, hash):
 
262
         self.node = hash['_M_bbegin']['_M_node']['_M_nxt']
 
263
         self.node_type = find_type(hash.type, '__node_type').pointer()
 
264
@@ -627,7 +671,7 @@ class Tr1HashtableIterator:
 
265
     def __iter__ (self):
 
266
         return self
 
267
 
 
268
-    def next (self):
 
269
+    def __next__ (self):
 
270
         if self.node == 0:
 
271
             raise StopIteration
 
272
         node = self.node.cast(self.node_type)
 
273
@@ -655,8 +699,8 @@ class Tr1UnorderedSetPrinter:
 
274
         return '[%d]' % i
 
275
 
 
276
     def children (self):
 
277
-        counter = itertools.imap (self.format_count, itertools.count())
 
278
-        return itertools.izip (counter, Tr1HashtableIterator (self.hashtable()))
 
279
+        counter = imap (self.format_count, itertools.count())
 
280
+        return izip (counter, Tr1HashtableIterator (self.hashtable()))
 
281
 
 
282
 class Tr1UnorderedMapPrinter:
 
283
     "Print a tr1::unordered_map"
 
284
@@ -688,11 +732,11 @@ class Tr1UnorderedMapPrinter:
 
285
         return '[%d]' % i
 
286
 
 
287
     def children (self):
 
288
-        counter = itertools.imap (self.format_count, itertools.count())
 
289
+        counter = imap (self.format_count, itertools.count())
 
290
         # Map over the hash table and flatten the result.
 
291
-        data = self.flatten (itertools.imap (self.format_one, Tr1HashtableIterator (self.hashtable())))
 
292
+        data = self.flatten (imap (self.format_one, Tr1HashtableIterator (self.hashtable())))
 
293
         # Zip the two iterators together.
 
294
-        return itertools.izip (counter, data)
 
295
+        return izip (counter, data)
 
296
 
 
297
     def display_hint (self):
 
298
         return 'map'
 
299
@@ -700,7 +744,7 @@ class Tr1UnorderedMapPrinter:
 
300
 class StdForwardListPrinter:
 
301
     "Print a std::forward_list"
 
302
 
 
303
-    class _iterator:
 
304
+    class _iterator(Iterator):
 
305
         def __init__(self, nodetype, head):
 
306
             self.nodetype = nodetype
 
307
             self.base = head['_M_next']
 
308
@@ -709,7 +753,7 @@ class StdForwardListPrinter:
 
309
         def __iter__(self):
 
310
             return self
 
311
 
 
312
-        def next(self):
 
313
+        def __next__(self):
 
314
             if self.base == 0:
 
315
                 raise StopIteration
 
316
             elt = self.base.cast(self.nodetype).dereference()
 
317
@@ -764,7 +808,7 @@ class Printer(object):
 
318
         # A small sanity check.
 
319
         # FIXME
 
320
         if not self.compiled_rx.match(name + '<>'):
 
321
-            raise ValueError, 'libstdc++ programming error: "%s" does not match' % name
 
322
+            raise ValueError('libstdc++ programming error: "%s" does not match' % name)
 
323
         printer = RxPrinter(name, function)
 
324
         self.subprinters.append(printer)
 
325
         self.lookup[name] = printer
 
326
--- a/src/libstdc++-v3/testsuite/lib/gdb-test.exp
 
327
+++ b/src/libstdc++-v3/testsuite/lib/gdb-test.exp
 
328
@@ -91,7 +91,7 @@ proc gdb-test { marker {selector {}} } {
 
329
        }
 
330
     }
 
331
 
 
332
-    set do_whatis_tests [gdb_batch_check "python print gdb.type_printers" \
 
333
+    set do_whatis_tests [gdb_batch_check "python print(gdb.type_printers)" \
 
334
                           "\\\[\\\]"]
 
335
     if {!$do_whatis_tests} {
 
336
        send_log "skipping 'whatis' tests - gdb too old"
 
337
@@ -252,6 +252,6 @@ proc gdb_batch_check {command pattern} {
 
338
 # but not earlier versions.
 
339
 # Return 1 if the version is ok, 0 otherwise.
 
340
 proc gdb_version_check {} {
 
341
-    return [gdb_batch_check "python print gdb.lookup_global_symbol" \
 
342
+    return [gdb_batch_check "python print(gdb.lookup_global_symbol)" \
 
343
              "<built-in function lookup_global_symbol>"]
 
344
 }
 
345