From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 579C33840C0F for ; Sun, 28 Jun 2020 16:56:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 579C33840C0F X-ASG-Debug-ID: 1593363391-0c856e6bfb489e0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id hIdQDCdu9mOybs6J (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 28 Jun 2020 12:56:31 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from localhost.localdomain (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) by smtp.ebox.ca (Postfix) with ESMTP id 99C69441B21; Sun, 28 Jun 2020 12:56:31 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 173-246-6-90.qc.cable.ebox.net[173.246.6.90] X-Barracuda-Apparent-Source-IP: 173.246.6.90 X-Barracuda-RBL-IP: 173.246.6.90 To: gdb-patches@sourceware.org Subject: [PATCH 3/3] gdb: make macro_stringify return a gdb::unique_xmalloc_ptr Date: Sun, 28 Jun 2020 12:56:28 -0400 X-ASG-Orig-Subj: [PATCH 3/3] gdb: make macro_stringify return a gdb::unique_xmalloc_ptr Message-Id: <20200628165628.96730-4-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628165628.96730-1-simon.marchi@polymtl.ca> References: <20200628165628.96730-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1593363391 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2651 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.82869 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-15.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Jun 2020 16:56:33 -0000 The change to macro_stringify is straightforward. This allows removing the manual memory management in fixup_definition. gdb/ChangeLog: * macroexp.h (macro_stringify): Return gdb::unique_xmalloc_ptr. * macroexp.c (macro_stringify): Likewise. * macrotab.c (fixup_definition): Update. Change-Id: Id7db8988bdbd569dd51c4f4655b00eb26db277cb --- gdb/macroexp.c | 4 ++-- gdb/macroexp.h | 6 ++---- gdb/macrotab.c | 14 ++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/gdb/macroexp.c b/gdb/macroexp.c index e1d185d30c8e..5f749ffe8928 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -698,7 +698,7 @@ stringify (struct macro_buffer *dest, const char *arg, int len) /* See macroexp.h. */ -char * +gdb::unique_xmalloc_ptr macro_stringify (const char *str) { int len = strlen (str); @@ -707,7 +707,7 @@ macro_stringify (const char *str) stringify (&buffer, str, len); buffer.appendc ('\0'); - return buffer.release ().release (); + return buffer.release (); } diff --git a/gdb/macroexp.h b/gdb/macroexp.h index 511991cacd20..2e29d02d34bd 100644 --- a/gdb/macroexp.h +++ b/gdb/macroexp.h @@ -78,9 +78,7 @@ int macro_is_identifier_nondigit (int c); int macro_is_digit (int c); -/* Stringify STR according to C rules and return an xmalloc'd pointer - to the result. */ - -char *macro_stringify (const char *str); +/* Stringify STR according to C rules and return a null-terminated string. */ +gdb::unique_xmalloc_ptr macro_stringify (const char *str); #endif /* MACROEXP_H */ diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 63cd30148ac2..0fefe8faaacf 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -882,25 +882,19 @@ macro_undef (struct macro_source_file *source, int line, static struct macro_definition * fixup_definition (const char *filename, int line, struct macro_definition *def) { - static char *saved_expansion; - - if (saved_expansion) - { - xfree (saved_expansion); - saved_expansion = NULL; - } + gdb::unique_xmalloc_ptr saved_expansion; if (def->kind == macro_object_like) { if (def->argc == macro_FILE) { saved_expansion = macro_stringify (filename); - def->replacement = saved_expansion; + def->replacement = saved_expansion.get (); } else if (def->argc == macro_LINE) { - saved_expansion = xstrprintf ("%d", line); - def->replacement = saved_expansion; + saved_expansion.reset (xstrprintf ("%d", line)); + def->replacement = saved_expansion.get (); } } -- 2.27.0