public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] A couple minor _versioned_namespace patches
@ 2023-10-03 17:18 Tom Tromey
  2023-10-03 17:18 ` [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py Tom Tromey
  2023-10-03 17:18 ` [PATCH 2/2] libstdc++: _versioned_namespace is always non-None Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2023-10-03 17:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++

While I was working on the flake8/black patches, flake8 pointed out a
bug in xmethods.py.  This is fixed in patch 1.  Then I found the
checks of _versioned_namespace to be a bit odd, so I wrote patch 2.

Tested on x86-64 Fedora 36.

Tom



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py
  2023-10-03 17:18 [PATCH 0/2] A couple minor _versioned_namespace patches Tom Tromey
@ 2023-10-03 17:18 ` Tom Tromey
  2023-10-03 22:57   ` Jonathan Wakely
  2023-10-03 17:18 ` [PATCH 2/2] libstdc++: _versioned_namespace is always non-None Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-10-03 17:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Tom Tromey

flake8 pointed out that is_specialization_of in xmethods.py looks at a
global that wasn't added to the file.  This patch correct the
oversight.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/xmethods.py (_versioned_namespace):
	Define.
---
 libstdc++-v3/python/libstdcxx/v6/xmethods.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
index 844c8a2105a..8ccf57c4d6b 100644
--- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -28,6 +28,8 @@ def get_bool_type():
 def get_std_size_type():
     return gdb.lookup_type('std::size_t')
 
+_versioned_namespace = '__8::'
+
 def is_specialization_of(x, template_name):
     """
     Test whether a type is a specialization of the named class template.
-- 
2.40.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] libstdc++: _versioned_namespace is always non-None
  2023-10-03 17:18 [PATCH 0/2] A couple minor _versioned_namespace patches Tom Tromey
  2023-10-03 17:18 ` [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py Tom Tromey
@ 2023-10-03 17:18 ` Tom Tromey
  2023-10-03 22:55   ` Jonathan Wakely
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2023-10-03 17:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Tom Tromey

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.
---
 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 23efbd171ec..e370551cbe1 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -139,7 +139,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)
@@ -211,16 +211,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):
@@ -2355,7 +2352,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)
@@ -2527,7 +2524,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:
@@ -2628,7 +2625,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 8ccf57c4d6b..42e60eb57b1 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):
-- 
2.40.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] libstdc++: _versioned_namespace is always non-None
  2023-10-03 17:18 ` [PATCH 2/2] libstdc++: _versioned_namespace is always non-None Tom Tromey
@ 2023-10-03 22:55   ` Jonathan Wakely
  2023-10-03 22:57     ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2023-10-03 22:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 4437 bytes --]

On Tue, 3 Oct 2023, 19:27 Tom Tromey, <tromey@adacore.com> wrote:

> 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.
>

ok for trunk, but we should just remove that bit from xmethods.py as the
variable is never even set in that file.



> 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.
> ---
>  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 23efbd171ec..e370551cbe1 100644
> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
> @@ -139,7 +139,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)
> @@ -211,16 +211,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):
> @@ -2355,7 +2352,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)
> @@ -2527,7 +2524,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:
> @@ -2628,7 +2625,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 8ccf57c4d6b..42e60eb57b1 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):
> --
> 2.40.1
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] libstdc++: _versioned_namespace is always non-None
  2023-10-03 22:55   ` Jonathan Wakely
@ 2023-10-03 22:57     ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2023-10-03 22:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 4684 bytes --]

On Tue, 3 Oct 2023, 23:55 Jonathan Wakely, <jwakely.gcc@gmail.com> wrote:

>
>
> On Tue, 3 Oct 2023, 19:27 Tom Tromey, <tromey@adacore.com> wrote:
>
>> 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.
>>
>
> ok for trunk, but we should just remove that bit from xmethods.py as the
> variable is never even set in that file.
>

Oh I see you already addressed that in another patch :-)


>
>
>> 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.
>> ---
>>  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 23efbd171ec..e370551cbe1 100644
>> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
>> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
>> @@ -139,7 +139,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)
>> @@ -211,16 +211,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):
>> @@ -2355,7 +2352,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)
>> @@ -2527,7 +2524,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:
>> @@ -2628,7 +2625,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 8ccf57c4d6b..42e60eb57b1 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):
>> --
>> 2.40.1
>>
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py
  2023-10-03 17:18 ` [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py Tom Tromey
@ 2023-10-03 22:57   ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2023-10-03 22:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]

On Tue, 3 Oct 2023, 18:19 Tom Tromey, <tromey@adacore.com> wrote:

> flake8 pointed out that is_specialization_of in xmethods.py looks at a
> global that wasn't added to the file.  This patch correct the
> oversight.
>

OK, thanks



>
> libstdc++-v3/ChangeLog:
>
>         * python/libstdcxx/v6/xmethods.py (_versioned_namespace):
>         Define.
> ---
>  libstdc++-v3/python/libstdcxx/v6/xmethods.py | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
> b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
> index 844c8a2105a..8ccf57c4d6b 100644
> --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
> @@ -28,6 +28,8 @@ def get_bool_type():
>  def get_std_size_type():
>      return gdb.lookup_type('std::size_t')
>
> +_versioned_namespace = '__8::'
> +
>  def is_specialization_of(x, template_name):
>      """
>      Test whether a type is a specialization of the named class template.
> --
> 2.40.1
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-03 22:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03 17:18 [PATCH 0/2] A couple minor _versioned_namespace patches Tom Tromey
2023-10-03 17:18 ` [PATCH 1/2] libstdc++: Define _versioned_namespace in xmethods.py Tom Tromey
2023-10-03 22:57   ` Jonathan Wakely
2023-10-03 17:18 ` [PATCH 2/2] libstdc++: _versioned_namespace is always non-None Tom Tromey
2023-10-03 22:55   ` Jonathan Wakely
2023-10-03 22:57     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).