Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Re: A couple of uses of xmalloc and xfree in a couple of .y files
Date: Mon, 27 Oct 2008 22:38:00 -0000	[thread overview]
Message-ID: <200810271930.20830.pedro@codesourcery.com> (raw)
In-Reply-To: <200810271148.00324.pedro@codesourcery.com>

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

On Monday 27 October 2008 11:48:00, Pedro Alves wrote:
> Ok, I think that makes for: one "funny we don't do it", one "got mildly
> tickled by the inconsistency, although doesn't care that much, but
> wrote the patch anyway", one "non-silent don't care", a bunch of
> silent don't care's, and one "it's useful".
> 
> I believe that's a positive balance.  :-)
> 
> Checked in.
> 

Grrrrr, things are never that simple...

Somehow, I missed rebuilding this file (.y.c doesn't depend on
Makefile.in), so I missed this breakage:

 cp-name-parser.c.tmp: In function 'cpname_parse':
 cp-name-parser.c.tmp:1990: warning: implicit declaration of function 'xfree'

The fix is to include "defs.h" instead of "config.h" directly, as the
other .y files do.  While doing that, I hit the fact that there's an
external parse_escape function in utils.c, declared in defs.h that now
colides with the static cp-name-parse.y:parse_escape.  They're mostly the
same, but this file it also buildable as a standalone program, so I just
renamed the one in cp-name-parser.y.  The xfree issue is described in the
patch itself.

Phew, hope the attached (already commited) settles it.  I made sure
that `make test-cp-name-parser' still links the standalone
test program.

-- 
Pedro Alves

[-- Attachment #2: fix_xfree.diff --]
[-- Type: text/x-diff, Size: 1798 bytes --]

2008-10-27  Pedro Alves  <pedro@codesourcery.com>

	* cp-name-parser.y: Include defs.h instead of config.h.
	(parse_escape): Rename to ...
	(cp_parse_escape): ... this.
	(yylex): Update.
	(xfree) [TEST_CPNAMES]: New.

---
 gdb/cp-name-parser.y |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Index: src/gdb/cp-name-parser.y
===================================================================
--- src.orig/gdb/cp-name-parser.y	2008-10-27 18:40:25.000000000 +0000
+++ src/gdb/cp-name-parser.y	2008-10-27 19:16:47.000000000 +0000
@@ -31,7 +31,7 @@ Boston, MA 02110-1301, USA.  */
 
 %{
 
-#include "config.h"
+#include "defs.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1462,7 +1462,7 @@ c_parse_backslash (int host_char, int *t
    after the zeros.  A value of 0 does not mean end of string.  */
 
 static int
-parse_escape (const char **string_ptr)
+cp_parse_escape (const char **string_ptr)
 {
   int target_char;
   int c = *(*string_ptr)++;
@@ -1483,7 +1483,7 @@ parse_escape (const char **string_ptr)
 	  if (c == '?')
 	    return 0177;
 	  else if (c == '\\')
-	    target_char = parse_escape (string_ptr);
+	    target_char = cp_parse_escape (string_ptr);
 	  else
 	    target_char = c;
 
@@ -1581,7 +1581,7 @@ yylex (void)
       lexptr++;
       c = *lexptr++;
       if (c == '\\')
-	c = parse_escape (&lexptr);
+	c = cp_parse_escape (&lexptr);
       else if (c == '\'')
 	{
 	  yyerror ("empty character constant");
@@ -2084,6 +2084,16 @@ trim_chars (char *lexptr, char **extra_c
   return c;
 }
 
+/* When this file is built as a standalone program, xmalloc comes from
+   libiberty --- in which case we have to provide xfree ourselves.  */
+
+void
+xfree (void *ptr)
+{
+  if (ptr != NULL)
+    free (ptr);
+}
+
 int
 main (int argc, char **argv)
 {

      reply	other threads:[~2008-10-27 19:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-24 22:58 Pedro Alves
2008-10-25  0:14 ` Joel Brobecker
2008-10-25  1:58   ` Daniel Jacobowitz
2008-10-25  2:37     ` Pedro Alves
2008-10-25  6:33       ` Daniel Jacobowitz
2008-10-25 15:54       ` Joel Brobecker
2008-10-27 11:48         ` Pedro Alves
2008-10-27 22:38           ` Pedro Alves [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=200810271930.20830.pedro@codesourcery.com \
    --to=pedro@codesourcery.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