From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32323 invoked by alias); 27 Oct 2008 19:30:53 -0000 Received: (qmail 32314 invoked by uid 22791); 27 Oct 2008 19:30:52 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 27 Oct 2008 19:30:06 +0000 Received: (qmail 15794 invoked from network); 27 Oct 2008 19:30:02 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 27 Oct 2008 19:30:02 -0000 From: Pedro Alves 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 User-Agent: KMail/1.9.9 References: <200810242358.11089.pedro@codesourcery.com> <20081025155358.GG29998@adacore.com> <200810271148.00324.pedro@codesourcery.com> In-Reply-To: <200810271148.00324.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_MbhBJFmsPQb1sxn" Message-Id: <200810271930.20830.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-10/txt/msg00667.txt.bz2 --Boundary-00=_MbhBJFmsPQb1sxn Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1259 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 --Boundary-00=_MbhBJFmsPQb1sxn Content-Type: text/x-diff; charset="iso-8859-1"; name="fix_xfree.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix_xfree.diff" Content-length: 1798 2008-10-27 Pedro Alves * 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 #include @@ -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) { --Boundary-00=_MbhBJFmsPQb1sxn--