public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Remove host_hex_value
Date: Fri, 4 Feb 2022 11:37:44 +0000	[thread overview]
Message-ID: <20220204113744.GA1917497@redhat.com> (raw)
In-Reply-To: <20220203191249.890726-1-tromey@adacore.com>

* Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> [2022-02-03 12:12:49 -0700]:

> I noticed that host_hex_value is redundant, because gdbsupport already
> has fromhex.  This patch removes the former in favor of the latter.
> 
> Regression tested on x86-64 Fedora 34.

LGTM.

Thanks,
Andrew

> ---
>  gdb/c-lang.c            |  6 +++---
>  gdb/charset.c           | 14 --------------
>  gdb/charset.h           |  5 -----
>  gdb/mi/mi-parse.c       |  4 ++--
>  gdb/python/py-objfile.c |  2 +-
>  gdb/utils.c             |  4 ++--
>  6 files changed, 8 insertions(+), 27 deletions(-)
> 
> diff --git a/gdb/c-lang.c b/gdb/c-lang.c
> index ed7554fadea..1f7cac7bef1 100644
> --- a/gdb/c-lang.c
> +++ b/gdb/c-lang.c
> @@ -410,7 +410,7 @@ convert_ucn (const char *p, const char *limit, const char *dest_charset,
>    int i;
>  
>    for (i = 0; i < length && p < limit && ISXDIGIT (*p); ++i, ++p)
> -    result = (result << 4) + host_hex_value (*p);
> +    result = (result << 4) + fromhex (*p);
>  
>    for (i = 3; i >= 0; --i)
>      {
> @@ -454,7 +454,7 @@ convert_octal (struct type *type, const char *p,
>         i < 3 && p < limit && ISDIGIT (*p) && *p != '8' && *p != '9';
>         ++i)
>      {
> -      value = 8 * value + host_hex_value (*p);
> +      value = 8 * value + fromhex (*p);
>        ++p;
>      }
>  
> @@ -476,7 +476,7 @@ convert_hex (struct type *type, const char *p,
>  
>    while (p < limit && ISXDIGIT (*p))
>      {
> -      value = 16 * value + host_hex_value (*p);
> +      value = 16 * value + fromhex (*p);
>        ++p;
>      }
>  
> diff --git a/gdb/charset.c b/gdb/charset.c
> index bf205ae087c..84c60a4e5d6 100644
> --- a/gdb/charset.c
> +++ b/gdb/charset.c
> @@ -463,20 +463,6 @@ host_letter_to_control_character (char c)
>    return c & 0237;
>  }
>  
> -/* Convert a host character, C, to its hex value.  C must already have
> -   been validated using isxdigit.  */
> -
> -int
> -host_hex_value (char c)
> -{
> -  if (isdigit (c))
> -    return c - '0';
> -  if (c >= 'a' && c <= 'f')
> -    return 10 + c - 'a';
> -  gdb_assert (c >= 'A' && c <= 'F');
> -  return 10 + c - 'A';
> -}
> -
>  \f
>  /* Public character management functions.  */
>  
> diff --git a/gdb/charset.h b/gdb/charset.h
> index 871f0d856ac..7a7041f10f2 100644
> --- a/gdb/charset.h
> +++ b/gdb/charset.h
> @@ -159,9 +159,4 @@ class wchar_iterator
>     character.  */
>  char host_letter_to_control_character (char c);
>  
> -/* Convert a hex digit character to its numeric value.  E.g., 'f' is
> -   converted to 15.  This function assumes that C is a valid hex
> -   digit.  Both upper- and lower-case letters are recognized.  */
> -int host_hex_value (char c);
> -
>  #endif /* CHARSET_H */
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index d5febced153..dfa7b462714 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -57,7 +57,7 @@ mi_parse_escape (const char **string_ptr)
>        case '6':
>        case '7':
>  	{
> -	  int i = host_hex_value (c);
> +	  int i = fromhex (c);
>  	  int count = 0;
>  
>  	  while (++count < 3)
> @@ -67,7 +67,7 @@ mi_parse_escape (const char **string_ptr)
>  		{
>  		  (*string_ptr)++;
>  		  i *= 8;
> -		  i += host_hex_value (c);
> +		  i += fromhex (c);
>  		}
>  	      else
>  		{
> diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
> index 48d2eb306d1..8c568799843 100644
> --- a/gdb/python/py-objfile.c
> +++ b/gdb/python/py-objfile.c
> @@ -550,7 +550,7 @@ objfpy_build_id_matches (const struct bfd_build_id *build_id,
>    for (i = 0; i < build_id->size; ++i)
>      {
>        char c1 = string[i * 2], c2 = string[i * 2 + 1];
> -      int byte = (host_hex_value (c1) << 4) | host_hex_value (c2);
> +      int byte = (fromhex (c1) << 4) | fromhex (c2);
>  
>        if (byte != build_id->data[i])
>  	return 0;
> diff --git a/gdb/utils.c b/gdb/utils.c
> index 152fa9b630a..dcb42138d39 100644
> --- a/gdb/utils.c
> +++ b/gdb/utils.c
> @@ -1078,7 +1078,7 @@ parse_escape (struct gdbarch *gdbarch, const char **string_ptr)
>        case '6':
>        case '7':
>  	{
> -	  int i = host_hex_value (c);
> +	  int i = fromhex (c);
>  	  int count = 0;
>  	  while (++count < 3)
>  	    {
> @@ -1087,7 +1087,7 @@ parse_escape (struct gdbarch *gdbarch, const char **string_ptr)
>  		{
>  		  (*string_ptr)++;
>  		  i *= 8;
> -		  i += host_hex_value (c);
> +		  i += fromhex (c);
>  		}
>  	      else
>  		{
> -- 
> 2.31.1
> 


      reply	other threads:[~2022-02-04 11:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 19:12 Tom Tromey
2022-02-04 11:37 ` Andrew Burgess [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220204113744.GA1917497@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).