Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH]
Date: Wed, 18 Jan 2012 14:34:00 -0000	[thread overview]
Message-ID: <m362g96usz.fsf@redhat.com> (raw)
In-Reply-To: <20120118121803.GC31383@adacore.com> (Joel Brobecker's message of	"Wed, 18 Jan 2012 16:18:03 +0400")

On Wednesday, January 18 2012, Joel Brobecker wrote:

>> >> 2012-01-18  Sergio Durigan Junior  <sergiodj@redhat.com>
>> >> 
>> >> 	* parse.c (initialize_expout): New function.
>> >> 	(reallocate_expout): Likewise.
>> >> 	(parse_exp_in_context): Use `initialize_expout' and
>> >> 	`reallocate_expout' when appropriate.
>> >
>> > FWIW, it seems OK to me on its own. I like the fact that you made
>> > the initial_size and gdbarch parameters.
>
> Sorry for nit-picking, but since it's very minor and can easily
> be deal with...

No problem, that's why I sent the patch :-).

>> +/* Helper function used to initialize an struct expression that is going
>> +   to be used to store expression elements.  The arguments are the
>> +   INITIAL_SIZE of the expression, the language LANG parsed to build this
>> +   expression, and the GDBARCH pointer.  */
>
> Suggested re-phrasing:
>
> /* Helper function to initialize the expout, expout_size, expout_ptr
>    trio before it is used to store expression elements created during
>    the parsing of an expression.  INITIAL_SIZE is the initial size of
>    the expout array.  LANG is the language used to parse the expression.
>    And GDBARCH is the gdbarch to use during parsing.  */
>
>> +/* Helper function that reallocates the EXPOUT in order to eliminate any
>> +   unused space.  It is generally used when the expression has just been
>> +   parsed and created.  */
>
> Suggest:
>
> /* Helper function that frees any unsed space in the expout array.
>    It is generally used when the parser has just been parsed and
>    created.  */
>
> (otherwise, remove "the" before "EXPOUT").
>
> Ok with those fixes.

Fixed and committed the version below.
      http://sourceware.org/ml/gdb-cvs/2012-01/msg00153.html

Thanks.

-- 
Sergio

2012-01-18  Sergio Durigan Junior  <sergiodj@redhat.com>

	* parse.c (initialize_expout): New function.
	(reallocate_expout): Likewise.
	(parse_exp_in_context): Use `initialize_expout' and
	`reallocate_expout' when appropriate.

diff --git a/gdb/parse.c b/gdb/parse.c
index f405dc5..32a3bd6 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -182,6 +182,41 @@ free_funcalls (void *ignore)
 /* This page contains the functions for adding data to the struct expression
    being constructed.  */
 
+/* Helper function to initialize the expout, expout_size, expout_ptr
+   trio before it is used to store expression elements created during
+   the parsing of an expression.  INITIAL_SIZE is the initial size of
+   the expout array.  LANG is the language used to parse the expression.
+   And GDBARCH is the gdbarch to use during parsing.  */
+
+static void
+initialize_expout (int initial_size, const struct language_defn *lang,
+		   struct gdbarch *gdbarch)
+{
+  expout_size = initial_size;
+  expout_ptr = 0;
+  expout = xmalloc (sizeof (struct expression)
+		    + EXP_ELEM_TO_BYTES (expout_size));
+  expout->language_defn = lang;
+  expout->gdbarch = gdbarch;
+}
+
+/* Helper function that frees any unsed space in the expout array.
+   It is generally used when the parser has just been parsed and
+   created.  */
+
+static void
+reallocate_expout (void)
+{
+  /* Record the actual number of expression elements, and then
+     reallocate the expression memory so that we free up any
+     excess elements.  */
+
+  expout->nelts = expout_ptr;
+  expout = xrealloc ((char *) expout,
+		     sizeof (struct expression)
+		     + EXP_ELEM_TO_BYTES (expout_ptr));
+}
+
 /* Add one element to the end of the expression.  */
 
 /* To avoid a bug in the Sun 4 compiler, we pass things that can fit into
@@ -1156,12 +1191,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
   else
     lang = current_language;
 
-  expout_size = 10;
-  expout_ptr = 0;
-  expout = (struct expression *)
-    xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size));
-  expout->language_defn = lang;
-  expout->gdbarch = get_current_arch ();
+  initialize_expout (10, lang, get_current_arch ());
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
@@ -1179,14 +1209,7 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
 
   discard_cleanups (old_chain);
 
-  /* Record the actual number of expression elements, and then
-     reallocate the expression memory so that we free up any
-     excess elements.  */
-
-  expout->nelts = expout_ptr;
-  expout = (struct expression *)
-    xrealloc ((char *) expout,
-	      sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));
+  reallocate_expout ();
 
   /* Convert expression from postfix form as generated by yacc
      parser, to a prefix form.  */


  reply	other threads:[~2012-01-18 12:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18  4:35 [PATCH] Sergio Durigan Junior
2012-01-18  4:52 ` [PATCH] Add initialize and reallocate methods to parser expout Sergio Durigan Junior
2012-01-18  5:04 ` [PATCH] Joel Brobecker
2012-01-18  5:17   ` [PATCH] Sergio Durigan Junior
2012-01-18 12:48     ` [PATCH] Joel Brobecker
2012-01-18 14:34       ` Sergio Durigan Junior [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-01-23 19:10 [patch] Doug Evans
2009-05-06  0:35 [PATCH] Maxim Grigoriev
2004-04-18 13:09 [PATCH] Mark Kettenis
2004-04-09 16:31 [PATCH] Mark Kettenis
2003-10-30 20:21 [PATCH] Mark Kettenis
2003-10-30 19:36 [PATCH] Mark Kettenis
2003-03-01 13:09 [PATCH] Mark Kettenis
2003-03-03 17:33 ` [PATCH] David Carlton

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=m362g96usz.fsf@redhat.com \
    --to=sergiodj@redhat.com \
    --cc=brobecker@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