From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id E04913838A0C; Mon, 13 Nov 2023 15:45:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E04913838A0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699890317; bh=FsN/WDsRecFDCN7gG0SOUJ7RFPjjFK0qUw6GX8orZDY=; h=From:To:Subject:Date:From; b=ZZifHQRxJEBJ/2LheBQuATmHgGluCCOlLFeswi6ieITKkKMnwXUAvD/8U4N/p8vf0 HvNXImbHb9ENPYbhKeCDKDXbWTgla/ne2Zw3jaWIVngYqH2c53AxKNVMtXWNTkH15V 26SsLgJ1N4hwVZ2bj+D3VPUqn8oa5JZugWOOklVc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9974] libstdc++: _versioned_namespace is always non-None X-Act-Checkin: gcc X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 40969ebf74dc01efdd1136f39268074e0a34032a X-Git-Newrev: a530c288c8ea46f3760ca3adb44eaf2d773492d1 Message-Id: <20231113154517.E04913838A0C@sourceware.org> Date: Mon, 13 Nov 2023 15:45:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a530c288c8ea46f3760ca3adb44eaf2d773492d1 commit r12-9974-ga530c288c8ea46f3760ca3adb44eaf2d773492d1 Author: Tom Tromey Date: Tue Oct 3 11:14:45 2023 -0600 libstdc++: _versioned_namespace is always non-None Some code in the pretty-printers seems to assume that the _versioned_namespace global might be None (or the empty string). However, doesn't occur, as the variable is never reassigned. libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py: Assume that _versioned_namespace is non-None. * python/libstdcxx/v6/xmethods.py (is_specialization_of): Assume that _versioned_namespace is non-None. (cherry picked from commit d342c9de6a1534cbce324bcc3c7c0898ff74d386) Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 15 ++++++--------- libstdc++-v3/python/libstdcxx/v6/xmethods.py | 3 +-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index c0472f8396c..51995b93806 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -118,7 +118,7 @@ def lookup_templ_spec(templ, *args): except gdb.error as e: # Type not found, try again in versioned namespace. global _versioned_namespace - if _versioned_namespace and _versioned_namespace not in templ: + if _versioned_namespace not in templ: t = t.replace('::', '::' + _versioned_namespace, 1) try: return gdb.lookup_type(t) @@ -185,16 +185,13 @@ def is_specialization_of(x, template_name): global _versioned_namespace if isinstance(x, gdb.Type): x = x.tag - if _versioned_namespace: - template_name = '(%s)?%s' % (_versioned_namespace, template_name) + template_name = '(%s)?%s' % (_versioned_namespace, template_name) return re.match('^std::%s<.*>$' % template_name, x) is not None def strip_versioned_namespace(typename): global _versioned_namespace - if _versioned_namespace: - return typename.replace(_versioned_namespace, '') - return typename + return typename.replace(_versioned_namespace, '') def strip_inline_namespaces(type_str): @@ -1953,7 +1950,7 @@ class Printer(object): # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION. def add_version(self, base, name, function): self.add(base + name, function) - if _versioned_namespace and '__cxx11' not in base: + if '__cxx11' not in base: vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base) self.add(vbase + name, function) @@ -2125,7 +2122,7 @@ def add_one_template_type_printer(obj, name, defargs): printer = TemplateTypePrinter('std::__debug::' + name, defargs) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace and '__cxx11' not in name: + if '__cxx11' not in name: # Add second type printer for same type in versioned namespace: ns = 'std::' + _versioned_namespace # PR 86112 Cannot use dict comprehension here: @@ -2217,7 +2214,7 @@ class FilteringTypePrinter(object): def add_one_type_printer(obj, template, name, targ1=None): printer = FilteringTypePrinter('std::' + template, 'std::' + name, targ1) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace and '__cxx11' not in template: + if '__cxx11' not in template: ns = 'std::' + _versioned_namespace printer = FilteringTypePrinter(ns + template, ns + name, targ1) gdb.types.register_type_printer(obj, printer) diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 16f7a116e01..c627f8ba800 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -39,8 +39,7 @@ def is_specialization_of(x, template_name): """ if isinstance(x, gdb.Type): x = x.tag - if _versioned_namespace: - template_name = '(%s)?%s' % (_versioned_namespace, template_name) + template_name = '(%s)?%s' % (_versioned_namespace, template_name) return re.match(r'^std::(__\d::)?%s<.*>$' % template_name, x) is not None class LibStdCxxXMethod(gdb.xmethod.XMethod):