From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <346-iXggKCsgu352qwrou22uzs.q20zwpopwuowz6285qsAo5s.25u@flex--gprocida.bounces.google.com> Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id CFF86389365C for ; Fri, 24 Apr 2020 09:22:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CFF86389365C Received: by mail-wm1-x34a.google.com with SMTP id t62so3565095wma.0 for ; Fri, 24 Apr 2020 02:22:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/HXBMSX/Omuxkt2AWnh7S8yudfrQGnA52A+9tQymHuw=; b=cpZJFp5sNdpO4ki3RWMUaDqCBnzp9WOtRwQyzzJ/BqoR9hyLEM9KdIfKneRsROBxVL i+vP0ESGKVUm5HdDQWrvY7CXrkSNUUAOP8dU6wEbj41CYnwYfR5LegOLTlRV8rbNAWMO K7HTOcSrVsaqjtFnads15Jslr/wlnqRtRMKgAuyMYbf7YWJ9UpQdN8wh/V6cLYKM59KQ D+Z5LdxOupdEWc8LVsNF94/hkPgemdxAzH6w4v13cz9JkT0Q+UntKS42hGJC5cLGYeWX mRmiN8f8AlycNccjDjB5UHVT88JoZg3UtSfuROD2dt0iZ7s9no0nyVXWe+CgXfKTTU+E ZCLQ== X-Gm-Message-State: AGi0PuaNBas3z80kKyBETComjQipJTZ2W0G6PJGOmEFMNCs/1/zvodKD aL327/JcaV7RqaQ3vvBhvpAF5v0HMRVIuqZjrts3BwdMZACN4fO0GXZinaV2TjNlwzoak9uh5JH Px9CLDrm3cr2L40iwjczGS+Y+C9Kvoq53TeioIb9g/9sutB5njwdqTVxHcxVwe1OfWpr0Apc= X-Google-Smtp-Source: APiQypLrSaBkzXKaMcOsbPsoGdQh/0d2G8f+gc2p309qjeICgPtzcw7eeQqHcRmsAE2veEGI9iM90xW1eMjzTg== X-Received: by 2002:adf:fe45:: with SMTP id m5mr10687917wrs.124.1587720163675; Fri, 24 Apr 2020 02:22:43 -0700 (PDT) Date: Fri, 24 Apr 2020 10:21:29 +0100 In-Reply-To: <20200424092132.150547-1-gprocida@google.com> Message-Id: <20200424092132.150547-19-gprocida@google.com> Mime-Version: 1.0 References: <20200423154441.170531-1-gprocida@google.com> <20200424092132.150547-1-gprocida@google.com> X-Mailer: git-send-email 2.26.2.303.gf8c07b1a785-goog Subject: [PATCH v3 18/21] Refactor suppression property regex parsing. From: Giuliano Procida To: libabigail@sourceware.org Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com, maennich@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-33.8 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL 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: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libabigail mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Apr 2020 09:22:46 -0000 This patch introduces a helper function to look up a key in an ini configuration section and get a compiled regex value. All regex look-ups now use this. There are no behavioural changes. Signed-off-by: Giuliano Procida --- src/abg-suppression.cc | 215 ++++++++++++----------------------------- 1 file changed, 61 insertions(+), 154 deletions(-) diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc index 84c9b78f..8b3631fd 100644 --- a/src/abg-suppression.cc +++ b/src/abg-suppression.cc @@ -1619,6 +1619,30 @@ maybe_get_string_prop(const ini::config::section& section, return true; } +/// Maybe compile a property to a regex. +/// +/// Attempt to find a simple property in an ini section and compile it +/// to a regex. +/// +/// @param section the ini section to look in +/// +/// @param prop the property name +/// +/// @param r the regex to compile into +/// +/// @return whether the property was found +static bool +maybe_get_regex_prop(const ini::config::section& section, + const std::string& name, + regex_t_sptr& regex) +{ + string str; + if (!maybe_get_string_prop(section, name, str)) + return false; + regex = regex::compile(str); + return true; +} + /// Read a type suppression from an instance of ini::config::section /// and build a @ref type_suppression as a result. /// @@ -1641,45 +1665,23 @@ read_type_suppression(const ini::config::section& section) string label_str; maybe_get_string_prop(section, "label", label_str); - ini::simple_property_sptr file_name_regex_prop = - is_simple_property(section.find_property("file_name_regexp")); regex_t_sptr file_name_regex; - if (file_name_regex_prop) - file_name_regex = - regex::compile(file_name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "file_name_regexp", file_name_regex); - ini::simple_property_sptr file_name_not_regex_prop = - is_simple_property(section.find_property("file_name_not_regexp")); regex_t_sptr file_name_not_regex; - if (file_name_not_regex_prop) - file_name_not_regex = - regex::compile(file_name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "file_name_not_regexp", file_name_not_regex); - ini::simple_property_sptr soname_regex_prop = - is_simple_property(section.find_property("soname_regexp")); regex_t_sptr soname_regex; - if (soname_regex_prop) - soname_regex = regex::compile(soname_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_regexp", soname_regex); - ini::simple_property_sptr soname_not_regex_prop = - is_simple_property(section.find_property("soname_not_regexp")); regex_t_sptr soname_not_regex; - if (soname_not_regex_prop) - soname_not_regex = - regex::compile(soname_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_not_regexp", soname_not_regex); - ini::simple_property_sptr name_regex_prop = - is_simple_property(section.find_property("name_regexp")); regex_t_sptr name_regex; - if (name_regex_prop) - name_regex = regex::compile(name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_regexp", name_regex); - ini::simple_property_sptr name_not_regex_prop = - is_simple_property(section.find_property("name_not_regexp")); regex_t_sptr name_not_regex; - if (name_not_regex_prop) - name_not_regex = - regex::compile(name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_not_regexp", name_not_regex); string name_str; maybe_get_string_prop(section, "name", name_str); @@ -1706,12 +1708,8 @@ read_type_suppression(const ini::config::section& section) } } - ini::simple_property_sptr srcloc_not_regexp_prop = - is_simple_property(section.find_property("source_location_not_regexp")); regex_t_sptr srcloc_not_regex; - if (srcloc_not_regexp_prop) - srcloc_not_regex = - regex::compile(srcloc_not_regexp_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "source_location_not_regexp", srcloc_not_regex); std::string type_kind_str; bool consider_type_kind = @@ -3195,85 +3193,47 @@ read_function_suppression(const ini::config::section& section) string label_str; maybe_get_string_prop(section, "label", label_str); - ini::simple_property_sptr file_name_regex_prop = - is_simple_property(section.find_property("file_name_regexp")); regex_t_sptr file_name_regex; - if (file_name_regex_prop) - file_name_regex = - regex::compile(file_name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "file_name_regexp", file_name_regex); - ini::simple_property_sptr file_name_not_regex_prop = - is_simple_property(section.find_property("file_name_not_regexp")); regex_t_sptr file_name_not_regex; - if (file_name_not_regex_prop) - file_name_not_regex = - regex::compile(file_name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "file_name_not_regexp", file_name_not_regex); - ini::simple_property_sptr soname_regex_prop = - is_simple_property(section.find_property("soname_regexp")); regex_t_sptr soname_regex; - if (soname_regex_prop) - soname_regex = regex::compile(soname_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_regexp", soname_regex); - ini::simple_property_sptr soname_not_regex_prop = - is_simple_property(section.find_property("soname_not_regexp")); regex_t_sptr soname_not_regex; - if (soname_not_regex_prop) - soname_not_regex = - regex::compile(soname_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_not_regexp", soname_not_regex); string name; maybe_get_string_prop(section, "name", name); - ini::simple_property_sptr name_regex_prop = - is_simple_property(section.find_property("name_regexp")); regex_t_sptr name_regex; - if (name_regex_prop) - name_regex = regex::compile(name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_regexp", name_regex); - ini::simple_property_sptr name_not_regex_prop = - is_simple_property(section.find_property("name_not_regexp")); regex_t_sptr name_not_regex; - if (name_not_regex_prop) - name_not_regex = - regex::compile(name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_not_regexp", name_not_regex); string return_type_name; maybe_get_string_prop(section, "return_type_name", return_type_name); - ini::simple_property_sptr return_type_regex_prop = - is_simple_property(section.find_property("return_type_regexp")); regex_t_sptr return_type_regex; - if (return_type_regex_prop) - return_type_regex = - regex::compile(return_type_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "return_type_regexp", return_type_regex); string sym_name; maybe_get_string_prop(section, "symbol_name", sym_name); - ini::simple_property_sptr sym_name_regex_prop = - is_simple_property(section.find_property("symbol_name_regexp")); regex_t_sptr sym_name_regex; - if (sym_name_regex_prop) - sym_name_regex = - regex::compile(sym_name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_name_regexp", sym_name_regex); - ini::simple_property_sptr sym_name_not_regex_prop = - is_simple_property(section.find_property("symbol_name_not_regexp")); regex_t_sptr sym_name_not_regex; - if (sym_name_not_regex_prop) - sym_name_not_regex = - regex::compile(sym_name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_name_not_regexp", sym_name_not_regex); string sym_version; maybe_get_string_prop(section, "symbol_version", sym_version); - ini::simple_property_sptr sym_ver_regex_prop = - is_simple_property(section.find_property("symbol_version_regexp")); regex_t_sptr sym_ver_regex; - if (sym_ver_regex_prop) - sym_ver_regex = - regex::compile(sym_ver_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_version_regexp", sym_ver_regex); string allow_other_aliases; maybe_get_string_prop(section, "allow_other_aliases", allow_other_aliases); @@ -4025,85 +3985,47 @@ read_variable_suppression(const ini::config::section& section) string label_str; maybe_get_string_prop(section, "label", label_str); - ini::simple_property_sptr file_name_regex_prop = - is_simple_property(section.find_property("file_name_regexp")); regex_t_sptr file_name_regex; - if (file_name_regex_prop) - file_name_regex = - regex::compile(file_name_regex_prop->get_value()->as_string()); - - ini::simple_property_sptr file_name_not_regex_prop = - is_simple_property(section.find_property("file_name_not_regexp")); - regex_t_sptr file_name_not_regex; - if (file_name_not_regex_prop) - file_name_not_regex = - regex::compile(file_name_not_regex_prop->get_value()->as_string()); - - ini::simple_property_sptr soname_regex_prop = - is_simple_property(section.find_property("soname_regexp")); + maybe_get_regex_prop(section, "file_name_regexp", file_name_regex); + + regex_t_sptr file_name_not_regex; + maybe_get_regex_prop(section, "file_name_not_regexp", file_name_not_regex); + regex_t_sptr soname_regex; - if (soname_regex_prop) - soname_regex = regex::compile(soname_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_regexp", soname_regex); - ini::simple_property_sptr soname_not_regex_prop = - is_simple_property(section.find_property("soname_not_regexp")); regex_t_sptr soname_not_regex; - if (soname_not_regex_prop) - soname_not_regex = - regex::compile(soname_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_not_regexp", soname_not_regex); string name_str; maybe_get_string_prop(section, "name", name_str); - ini::simple_property_sptr name_regex_prop = - is_simple_property(section.find_property("name_regexp")); regex_t_sptr name_regex; - if (name_regex_prop) - name_regex = regex::compile(name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_regexp", name_regex); - ini::simple_property_sptr name_not_regex_prop = - is_simple_property(section.find_property("name_not_regexp")); regex_t_sptr name_not_regex; - if (name_not_regex_prop) - name_not_regex = - regex::compile(name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "name_not_regexp", name_not_regex); string symbol_name; maybe_get_string_prop(section, "symbol_name", symbol_name); - ini::simple_property_sptr sym_name_regex_prop = - is_simple_property(section.find_property("symbol_name_regexp")); regex_t_sptr symbol_name_regex; - if (sym_name_regex_prop) - symbol_name_regex = - regex::compile(sym_name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_name_regexp", symbol_name_regex); - ini::simple_property_sptr sym_name_not_regex_prop = - is_simple_property(section.find_property("symbol_name_not_regexp")); regex_t_sptr symbol_name_not_regex; - if (sym_name_not_regex_prop) - symbol_name_not_regex = - regex::compile(sym_name_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_name_not_regexp", symbol_name_not_regex); string symbol_version; maybe_get_string_prop(section, "symbol_version", symbol_version); - ini::simple_property_sptr sym_version_regex_prop = - is_simple_property(section.find_property("symbol_version_regexp")); regex_t_sptr symbol_version_regex; - if (sym_version_regex_prop) - symbol_version_regex = - regex::compile(sym_version_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "symbol_version_regexp", symbol_version_regex); string type_name_str; maybe_get_string_prop(section, "type_name", type_name_str); - ini::simple_property_sptr type_name_regex_prop = - is_simple_property(section.find_property("type_name_regexp")); regex_t_sptr type_name_regex; - if (type_name_regex_prop) - type_name_regex = - regex::compile(type_name_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "type_name_regexp", type_name_regex); result.reset(new variable_suppression(label_str, name_str, @@ -4246,32 +4168,17 @@ read_file_suppression(const ini::config::section& section) string label_str; maybe_get_string_prop(section, "label", label_str); - ini::simple_property_sptr file_name_regex_prop = - is_simple_property(section.find_property("file_name_regexp")); regex_t_sptr file_name_regex; - if (file_name_regex_prop) - file_name_regex = - regex::compile(file_name_regex_prop->get_value()->as_string()); - - ini::simple_property_sptr file_name_not_regex_prop = - is_simple_property(section.find_property("file_name_not_regexp")); - regex_t_sptr file_name_not_regex; - if (file_name_not_regex_prop) - file_name_not_regex = - regex::compile(file_name_not_regex_prop->get_value()->as_string()); - - ini::simple_property_sptr soname_regex_prop = - is_simple_property(section.find_property("soname_regexp")); + maybe_get_regex_prop(section, "file_name_regexp", file_name_regex); + + regex_t_sptr file_name_not_regex; + maybe_get_regex_prop(section, "file_name_not_regexp", file_name_not_regex); + regex_t_sptr soname_regex; - if (soname_regex_prop) - soname_regex = regex::compile(soname_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_regexp", soname_regex); - ini::simple_property_sptr soname_not_regex_prop = - is_simple_property(section.find_property("soname_not_regexp")); regex_t_sptr soname_not_regex; - if (soname_not_regex_prop) - soname_not_regex = - regex::compile(soname_not_regex_prop->get_value()->as_string()); + maybe_get_regex_prop(section, "soname_not_regexp", soname_not_regex); result.reset(new file_suppression(label_str, file_name_regex, -- 2.26.2.303.gf8c07b1a785-goog