From patchwork Sat Jan 26 22:31:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 31219 Received: (qmail 12650 invoked by alias); 26 Jan 2019 22:31:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 12615 invoked by uid 89); 26 Jan 2019 22:31:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mailsec106.isp.belgacom.be Received: from mailsec106.isp.belgacom.be (HELO mailsec106.isp.belgacom.be) (195.238.20.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 26 Jan 2019 22:31:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1548541898; x=1580077898; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X66Q33onTr34uUOaUqCECu2A+H5JROmGZuH/Ndc2c5I=; b=gEWt6OWJOmbg4uJ2OfwPhN9cvgBxj8Jddd9d3FU8AJGj7eLUskAKjG3G rfw+2UDcynhKuGKuHq9LjxuRkCub2w==; Received: from 30.202-67-87.adsl-dyn.isp.belgacom.be (HELO md.home) ([87.67.202.30]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 26 Jan 2019 23:31:25 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv3 2/2] Factorize macro definition code in macrotab.c Date: Sat, 26 Jan 2019 23:31:17 +0100 Message-Id: <20190126223117.6718-3-philippe.waroquiers@skynet.be> In-Reply-To: <20190126223117.6718-1-philippe.waroquiers@skynet.be> References: <20190126223117.6718-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes When first fixing splay tree key leaks in macrotab.c, some duplicated code logic was factorized. The key leaks will be fixed in libiberty, but the code factorization is better kept in any case. gdb/ChangeLog 2019-01-26 Philippe Waroquiers * macrotab.c (macro_define_internal): New function that factorizes macro_define_object_internal and macro_define_function code. (macro_define_object_internal): Use macro_define_internal. (macro_define_function): Likewise. --- gdb/macrotab.c | 59 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 7fcab4691b..f7178bdc25 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -743,21 +743,26 @@ check_for_redefinition (struct macro_source_file *source, int line, return 0; } -/* A helper function to define a new object-like macro. */ +/* A helper function to define a new object-like or function-like macro + according to KIND. When KIND is macro_object_like, + the macro_special_kind must be provided as ARGC, and ARGV must be NULL. + When KIND is macro_function_like, ARGC and ARGV are giving the function + arguments. */ static void -macro_define_object_internal (struct macro_source_file *source, int line, - const char *name, const char *replacement, - enum macro_special_kind kind) +macro_define_internal (struct macro_source_file *source, int line, + const char *name, enum macro_kind kind, + int argc, const char **argv, + const char *replacement) { struct macro_table *t = source->table; struct macro_key *k = NULL; struct macro_definition *d; if (! t->redef_ok) - k = check_for_redefinition (source, line, - name, macro_object_like, - 0, 0, + k = check_for_redefinition (source, line, + name, kind, + argc, argv, replacement); /* If we're redefining a symbol, and the existing key would be @@ -774,10 +779,23 @@ macro_define_object_internal (struct macro_source_file *source, int line, return; k = new_macro_key (t, name, source, line); - d = new_macro_definition (t, macro_object_like, kind, 0, replacement); + d = new_macro_definition (t, kind, argc, argv, replacement); splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); } +/* A helper function to define a new object-like macro. */ + +static void +macro_define_object_internal (struct macro_source_file *source, int line, + const char *name, const char *replacement, + enum macro_special_kind special_kind) +{ + macro_define_internal (source, line, + name, macro_object_like, + special_kind, 0, + replacement); +} + void macro_define_object (struct macro_source_file *source, int line, const char *name, const char *replacement) @@ -802,29 +820,12 @@ macro_define_function (struct macro_source_file *source, int line, const char *name, int argc, const char **argv, const char *replacement) { - struct macro_table *t = source->table; - struct macro_key *k = NULL; - struct macro_definition *d; - - if (! t->redef_ok) - k = check_for_redefinition (source, line, - name, macro_function_like, - argc, argv, - replacement); - - /* See comments about duplicate keys in macro_define_object. */ - if (k && ! key_compare (k, name, source, line)) - return; - - /* We should also check here that all the argument names in ARGV are - distinct. */ - - k = new_macro_key (t, name, source, line); - d = new_macro_definition (t, macro_function_like, argc, argv, replacement); - splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); + macro_define_internal (source, line, + name, macro_function_like, + argc, argv, + replacement); } - void macro_undef (struct macro_source_file *source, int line, const char *name)