[PATCH 6/7] libstdc++: Fix regex escapes in pretty-printers

Tom Tromey tromey@adacore.com
Thu Sep 28 17:46:29 GMT 2023


flake8 pointed out that some regexes in the pretty-printers are
missing a backslash.  This patch fixes these.

libstdc++-v3/ChangeLog:

        * python/libstdcxx/v6/printers.py
	(StdExpAnyPrinter.__init__, StdExpOptionalPrinter.__init__):
	Add missing backslash.
	* python/libstdcxx/v6/xmethods.py
	(ArrayMethodsMatcher.match, DequeMethodsMatcher.match)
	(ForwardListMethodsMatcher.match, ListMethodsMatcher.match)
	(VectorMethodsMatcher.match)
	(AssociativeContainerMethodsMatcher.match)
	(UniquePtrGetWorker.__call__, UniquePtrMethodsMatcher.match)
	(SharedPtrSubscriptWorker.__call__)
	(SharedPtrMethodsMatcher.match): Add missing backslash.
---
 libstdc++-v3/python/libstdcxx/v6/printers.py |  6 +++---
 libstdc++-v3/python/libstdcxx/v6/xmethods.py | 22 ++++++++++----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 94ac9232da7..d125236b777 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1344,7 +1344,7 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
     def __init__(self, typename, val):
         self._typename = strip_versioned_namespace(typename)
         self._typename = re.sub(
-            '^std::experimental::fundamentals_v\d::', 'std::experimental::', self._typename, 1)
+            '^std::experimental::fundamentals_v\\d::', 'std::experimental::', self._typename, 1)
         self._val = val
         self._contained_type = None
         contained_value = None
@@ -1377,7 +1377,7 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
                 mgrtypes = []
                 for s in strings:
                     try:
-                        x = re.sub("std::string(?!\w)", s, m.group(1))
+                        x = re.sub("std::string(?!\\w)", s, m.group(1))
                         # The following lookup might raise gdb.error if the
                         # manager function was never instantiated for 's' in the
                         # program, because there will be no such type.
@@ -1425,7 +1425,7 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter):
     def __init__(self, typename, val):
         typename = strip_versioned_namespace(typename)
         self._typename = re.sub(
-            '^std::(experimental::|)(fundamentals_v\d::|)(.*)', r'std::\1\3', typename, 1)
+            '^std::(experimental::|)(fundamentals_v\\d::|)(.*)', r'std::\1\3', typename, 1)
         payload = val['_M_payload']
         if self._typename.startswith('std::experimental'):
             engaged = val['_M_engaged']
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
index 025b1b86ed0..eafecbb148e 100644
--- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -159,7 +159,7 @@ class ArrayMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?array<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?array<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -284,7 +284,7 @@ class DequeMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?deque<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?deque<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -332,7 +332,7 @@ class ForwardListMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?forward_list<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?forward_list<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -419,7 +419,7 @@ class ListMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?(__cxx11::)?list<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?(__cxx11::)?list<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -542,7 +542,7 @@ class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?vector<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?vector<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -595,7 +595,7 @@ class AssociativeContainerMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?%s<.*>$' % self._name, class_type.tag):
+        if not re.match('^std::(__\\d+::)?%s<.*>$' % self._name, class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -629,9 +629,9 @@ class UniquePtrGetWorker(gdb.xmethod.XMethodWorker):
     def __call__(self, obj):
         impl_type = obj.dereference().type.fields()[0].type.tag
         # Check for new implementations first:
-        if re.match('^std::(__\d+::)?__uniq_ptr_(data|impl)<.*>$', impl_type):
+        if re.match('^std::(__\\d+::)?__uniq_ptr_(data|impl)<.*>$', impl_type):
             tuple_member = obj['_M_t']['_M_t']
-        elif re.match('^std::(__\d+::)?tuple<.*>$', impl_type):
+        elif re.match('^std::(__\\d+::)?tuple<.*>$', impl_type):
             tuple_member = obj['_M_t']
         else:
             return None
@@ -696,7 +696,7 @@ class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?unique_ptr<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?unique_ptr<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
@@ -768,7 +768,7 @@ class SharedPtrSubscriptWorker(SharedPtrGetWorker):
 
     def __call__(self, obj, index):
         # Check bounds if _elem_type is an array of known bound
-        m = re.match('.*\[(\d+)]$', str(self._elem_type))
+        m = re.match('.*\\[(\\d+)]$', str(self._elem_type))
         if m and index >= int(m.group(1)):
             raise IndexError('shared_ptr<%s> index "%d" should not be >= %d.' %
                              (self._elem_type, int(index), int(m.group(1))))
@@ -823,7 +823,7 @@ class SharedPtrMethodsMatcher(gdb.xmethod.XMethodMatcher):
         self.methods = [self._method_dict[m] for m in self._method_dict]
 
     def match(self, class_type, method_name):
-        if not re.match('^std::(__\d+::)?shared_ptr<.*>$', class_type.tag):
+        if not re.match('^std::(__\\d+::)?shared_ptr<.*>$', class_type.tag):
             return None
         method = self._method_dict.get(method_name)
         if method is None or not method.enabled:
-- 
2.40.1



More information about the Libstdc++ mailing list