public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/2] Use obstack in ada_encode_1
Date: Fri,  2 Oct 2020 14:26:04 -0600	[thread overview]
Message-ID: <20201002202604.1517475-3-tromey@adacore.com> (raw)
In-Reply-To: <20201002202604.1517475-1-tromey@adacore.com>

I'd eventually like to get rid of the GROW_VECT macro; and since I had
already touched ada_encode_1 I decided to start here.  This patch
removes the use of the macro in favor of using an obstack in this
function.

2020-10-02  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_encode_1): Use an obstack.
---
 gdb/ChangeLog  |  4 ++++
 gdb/ada-lang.c | 26 +++++++-------------------
 2 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2502d2847b2..dfe9d44959f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -926,25 +926,17 @@ const struct ada_opname_map ada_opname_table[] = {
 static const char *
 ada_encode_1 (const char *decoded, bool throw_errors)
 {
-  static char *encoding_buffer = NULL;
-  static size_t encoding_buffer_size = 0;
+  static auto_obstack encoding_buffer;
   const char *p;
-  int k;
 
   if (decoded == NULL)
     return NULL;
 
-  GROW_VECT (encoding_buffer, encoding_buffer_size,
-             2 * strlen (decoded) + 10);
-
-  k = 0;
+  encoding_buffer.clear ();
   for (p = decoded; *p != '\0'; p += 1)
     {
       if (*p == '.')
-        {
-          encoding_buffer[k] = encoding_buffer[k + 1] = '_';
-          k += 2;
-        }
+	obstack_grow_str (&encoding_buffer, "__");
       else if (*p == '"')
         {
           const struct ada_opname_map *mapping;
@@ -960,19 +952,15 @@ ada_encode_1 (const char *decoded, bool throw_errors)
 	      else
 		return NULL;
 	    }
-          strcpy (encoding_buffer + k, mapping->encoded);
-          k += strlen (mapping->encoded);
+	  obstack_grow_str (&encoding_buffer, mapping->encoded);
           break;
         }
       else
-        {
-          encoding_buffer[k] = *p;
-          k += 1;
-        }
+	obstack_1grow (&encoding_buffer, *p);
     }
 
-  encoding_buffer[k] = '\0';
-  return encoding_buffer;
+  obstack_1grow (&encoding_buffer, '\0');
+  return (const char *) obstack_finish (&encoding_buffer);
 }
 
 /* The "encoded" form of DECODED, according to GNAT conventions.
-- 
2.26.2


  parent reply	other threads:[~2020-10-02 20:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02 20:26 [PATCH 0/2] ada_encode rewrites Tom Tromey
2020-10-02 20:26 ` [PATCH 1/2] Constify ada_encode return type Tom Tromey
2020-10-02 21:51   ` Simon Marchi
2020-10-07 18:26     ` Tom Tromey
2020-10-02 20:26 ` Tom Tromey [this message]
2020-10-02 21:54   ` [PATCH 2/2] Use obstack in ada_encode_1 Simon Marchi
2020-10-07 18:35     ` Tom Tromey
2020-10-07 18:36       ` Simon Marchi
2020-10-09 20:14       ` Joel Brobecker

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=20201002202604.1517475-3-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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).