Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH]
@ 2012-01-18  4:35 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
  0 siblings, 2 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2012-01-18  4:35 UTC (permalink / raw)
  To: gdb-patches

Hi,

I believe this is a rather obvious patch, but I decided to ask anyway.
This is a pretty simple cleanup on parse.c: the creation of
`initialize_expout' and `reallocate_expout' to handle cases when one
needs to do those actions on expout.

This patch is going to be important for the coming SystemTap patches
that I plan to submit this week, and I know GDB has a rule to avoid
premature modification of the code before a patch is posted, but I
believe this is a good cleanup to have in any case.

This patch also relates to the parser cleanup that I am working on.

Ok to apply?

-- 
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..b11070c 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 used to initialize an struct expression that is going
+   to be used to store expression elements.  The arguments are the
+   parser_state PS containing the EXPOUT, the INITIAL_SIZE of the expression,
+   the language LANG parsed to build this expression, and the GDBARCH
+   pointer.  */
+
+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 reallocates the EXPOUT inside PS in order to
+   eliminate any unused space.  It is generally used when the expression
+   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.  */


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

end of thread, other threads:[~2012-01-18 12:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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       ` [PATCH] Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox