This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: Smart pointer pretty printers


On 02/03/17 19:10 +0100, Juraj Oršulić wrote:
On Fri, Feb 24, 2017 at 5:36 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
For a patch this size we do, so I'm not going to look at your patch.
It will probably be simpler to just do it myself, and not worry about
paperwork.

If you want to contribue in future then please do complete the
necessary paperwork anyway:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/appendix_contributing.html#contrib.list

Hi Jonathan,

I have completed the assignment.

I am resubmitting the patch from the last time, this time as an
attachment (since the previous was broken by newlines). As before,
there are two versions of the patch: the one that I obtained by editing
printers.py on Ubuntu 16.04, which ships with gcc 5.4.0; and the
other, for the current printers.py from the gcc repo (I assume it's gcc
6?), which needs a slightly different patch because the unique_ptr
printer has significantly changed.

I have been using the gcc 5 patch without problems.  I have not tested
the gcc 6 patch, but since it is very similar, I don't expect any
problems.

Let me know if you want me to expand this for other iterators.

I don't like the change for std::vector iterators, because it makes it
appear as though the iterator stores a pointer. Although that's true
internally, conceptually it's not how we should think about iterators.

An iterator refers to a value, not a pointer. However, the current
code has a serious flaw that it always dereferences the pointer, even
for the end iterator (which is https://gcc.gnu.org/PR59170 and is
worse than displaying the value as a pointer!)

There's certainly scope for improvement, but I'm not sure this is the
right solution.


@@ -322,9 +328,17 @@ class StdVectorIteratorPrinter:

    def __init__(self, typename, val):
        self.val = val
+        self.pointer = self.val['_M_current']
+
+    def children(self):
+        if not self.pointer:
+            return []
+        return [('operator->()', self.pointer)]

    def to_string(self):
-        return self.val['_M_current'].dereference()
+        if not self.pointer:
+             return 'non-dereferenceable iterator for std::vector'
+        return ('std::vector<%s>::iterator' % (str(self.pointer.type.target())))

class StdTuplePrinter:
    "Print a std::tuple"


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