[PATCH v3 08/21] Use regex::compile wrapper instead of regcomp.
Giuliano Procida
gprocida@google.com
Mon Apr 27 16:01:07 GMT 2020
Hi.
On Mon, 27 Apr 2020 at 12:34, Matthias Maennich <maennich@google.com> wrote:
>
> On Fri, Apr 24, 2020 at 10:21:19AM +0100, Giuliano Procida wrote:
> >This patch eliminates all calls to regcomp except that by
> >regex::compile itself.
> >
> > * src/abg-corpus-priv.h: Mechanically substitute use of
> > regcomp with regex::compile wrapper.
> > * src/abg-suppression-priv.h: Ditto.
> >
> >There are no behavioural changes.
> >
> >Signed-off-by: Giuliano Procida <gprocida@google.com>
> >---
> > src/abg-corpus-priv.h | 16 +--
> > src/abg-suppression-priv.h | 198 ++++++-------------------------------
> > 2 files changed, 38 insertions(+), 176 deletions(-)
> >
> >diff --git a/src/abg-corpus-priv.h b/src/abg-corpus-priv.h
> >index e65f7c8f..544fac54 100644
> >--- a/src/abg-corpus-priv.h
> >+++ b/src/abg-corpus-priv.h
> >@@ -123,8 +123,8 @@ public:
> > i != fns_suppress_regexps_.end();
> > ++i)
> > {
> >- regex_t_sptr r = sptr_utils::build_sptr(new regex_t);
> >- if (regcomp(r.get(), i->c_str(), REG_EXTENDED) == 0)
> >+ regex_t_sptr r = regex::compile(*i);
> >+ if (r)
> > compiled_fns_suppress_regexp_.push_back(r);
> > }
> > }
> >@@ -145,8 +145,8 @@ public:
> > i != fns_keep_regexps_.end();
> > ++i)
> > {
> >- regex_t_sptr r = sptr_utils::build_sptr(new regex_t);
> >- if (regcomp(r.get(), i->c_str(), REG_EXTENDED) == 0)
> >+ regex_t_sptr r = regex::compile(*i);
> >+ if (r)
> > compiled_fns_keep_regexps_.push_back(r);
> > }
> > }
> >@@ -167,8 +167,8 @@ public:
> > i != vars_suppress_regexps_.end();
> > ++i)
> > {
> >- regex_t_sptr r = sptr_utils::build_sptr(new regex_t);
> >- if (regcomp(r.get(), i->c_str(), REG_EXTENDED) == 0)
> >+ regex_t_sptr r = regex::compile(*i);
> >+ if (r)
> > compiled_vars_suppress_regexp_.push_back(r);
> > }
> > }
> >@@ -189,8 +189,8 @@ public:
> > i != vars_keep_regexps_.end();
> > ++i)
> > {
> >- regex_t_sptr r = sptr_utils::build_sptr(new regex_t);
> >- if (regcomp(r.get(), i->c_str(), REG_EXTENDED) == 0)
> >+ regex_t_sptr r = regex::compile(*i);
> >+ if (r)
> > compiled_vars_keep_regexps_.push_back(r);
> > }
> > }
> >diff --git a/src/abg-suppression-priv.h b/src/abg-suppression-priv.h
> >index c37ceff6..4959cdbb 100644
> >--- a/src/abg-suppression-priv.h
> >+++ b/src/abg-suppression-priv.h
> >@@ -91,17 +91,8 @@ public:
> > const regex::regex_t_sptr&
> > get_file_name_regex() const
> > {
> >- if (!file_name_regex_)
> >- {
> >- if (!file_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- file_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- file_name_regex_ = r;
> >- }
> >- }
> >+ if (!file_name_regex_ && !file_name_regex_str_.empty())
>
> Those made me thinkg whether regex::compile should return NULL for empty
> regex strings? Not necessarily something to address in this change.
This code changes again in later patches. We get to the point where we
could distinguish empty regexes from missing regexes.
If I were doing this from scratch, I'd make empty regexes consistently
mean "match all strings". At the moment they always mean "regex
absent" due to the way the parsing works, probably. There is no error
handling at the moment, but we could explicitly choose to make empty
regexes a parse error later.
> Reviewed-by: Matthias Maennich <maennich@google.com>
>
> Cheers,
> Matthias
>
> >+ file_name_regex_ = regex::compile(file_name_regex_str_);
> > return file_name_regex_;
> > }
> >
> >@@ -116,17 +107,8 @@ public:
> > const regex::regex_t_sptr&
> > get_file_name_not_regex() const
> > {
> >- if (!file_name_not_regex_)
> >- {
> >- if (!file_name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- file_name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- file_name_not_regex_ = r;
> >- }
> >- }
> >+ if (!file_name_not_regex_ && !file_name_not_regex_str_.empty())
> >+ file_name_not_regex_ = regex::compile(file_name_not_regex_str_);
> > return file_name_not_regex_;
> > }
> >
> >@@ -141,17 +123,8 @@ public:
> > const regex::regex_t_sptr&
> > get_soname_regex() const
> > {
> >- if (!soname_regex_)
> >- {
> >- if (!soname_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- soname_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- soname_regex_ = r;
> >- }
> >- }
> >+ if (!soname_regex_ && !soname_regex_str_.empty())
> >+ soname_regex_ = regex::compile(soname_regex_str_);
> > return soname_regex_;
> > }
> >
> >@@ -166,17 +139,8 @@ public:
> > const regex::regex_t_sptr&
> > get_soname_not_regex() const
> > {
> >- if (!soname_not_regex_)
> >- {
> >- if (!soname_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- soname_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- soname_not_regex_ = r;
> >- }
> >- }
> >+ if (!soname_not_regex_ && !soname_not_regex_str_.empty())
> >+ soname_not_regex_ = regex::compile(soname_not_regex_str_);
> > return soname_not_regex_;
> > }
> >
> >@@ -282,13 +246,7 @@ class function_suppression::parameter_spec::priv
> > get_type_name_regex() const
> > {
> > if (!type_name_regex_ && !type_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- type_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- type_name_regex_ = r;
> >- }
> >+ type_name_regex_ = regex::compile(type_name_regex_str_);
> > return type_name_regex_;
> > }
> > }; // end class function_suppression::parameter_spec::priv
> >@@ -361,13 +319,7 @@ struct function_suppression::priv
> > get_name_regex() const
> > {
> > if (!name_regex_ && !name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- name_regex_ = r;
> >- }
> >+ name_regex_ = regex::compile(name_regex_str_);
> > return name_regex_;
> > }
> >
> >@@ -384,13 +336,7 @@ struct function_suppression::priv
> > get_name_not_regex() const
> > {
> > if (!name_not_regex_ && !name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- name_not_regex_ = r;
> >- }
> >+ name_not_regex_ = regex::compile(name_not_regex_str_);
> > return name_not_regex_;
> > }
> >
> >@@ -407,13 +353,7 @@ struct function_suppression::priv
> > get_return_type_regex() const
> > {
> > if (!return_type_regex_ && !return_type_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- return_type_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- return_type_regex_ = r;
> >- }
> >+ return_type_regex_ = regex::compile(return_type_regex_str_);
> > return return_type_regex_;
> > }
> >
> >@@ -430,13 +370,7 @@ struct function_suppression::priv
> > get_symbol_name_regex() const
> > {
> > if (!symbol_name_regex_ && !symbol_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- symbol_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_name_regex_ = r;
> >- }
> >+ symbol_name_regex_ = regex::compile(symbol_name_regex_str_);
> > return symbol_name_regex_;
> > }
> >
> >@@ -453,13 +387,7 @@ struct function_suppression::priv
> > get_symbol_name_not_regex() const
> > {
> > if (!symbol_name_not_regex_ && !symbol_name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- symbol_name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_name_not_regex_ = r;
> >- }
> >+ symbol_name_not_regex_ = regex::compile(symbol_name_not_regex_str_);
> > return symbol_name_not_regex_;
> > }
> >
> >@@ -475,14 +403,8 @@ struct function_suppression::priv
> > const regex::regex_t_sptr
> > get_symbol_version_regex() const
> > {
> >- if (!symbol_version_regex_ && ! symbol_version_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- symbol_version_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_version_regex_ = r;
> >- }
> >+ if (!symbol_version_regex_ && !symbol_version_regex_str_.empty())
> >+ symbol_version_regex_ = regex::compile(symbol_version_regex_str_);
> > return symbol_version_regex_;
> > }
> > }; // end class function_suppression::priv
> >@@ -609,13 +531,7 @@ struct variable_suppression::priv
> > get_name_regex() const
> > {
> > if (!name_regex_ && !name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- name_regex_ = r;
> >- }
> >+ name_regex_ = regex::compile(name_regex_str_);
> > return name_regex_;
> > }
> >
> >@@ -632,13 +548,7 @@ struct variable_suppression::priv
> > get_name_not_regex() const
> > {
> > if (!name_not_regex_ && !name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- name_not_regex_ = r;
> >- }
> >+ name_not_regex_ = regex::compile(name_not_regex_str_);
> > return name_not_regex_;
> > }
> >
> >@@ -655,13 +565,7 @@ struct variable_suppression::priv
> > get_symbol_name_regex() const
> > {
> > if (!symbol_name_regex_ && !symbol_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- symbol_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_name_regex_ = r;
> >- }
> >+ symbol_name_regex_ = regex::compile(symbol_name_regex_str_);
> > return symbol_name_regex_;
> > }
> >
> >@@ -678,12 +582,7 @@ struct variable_suppression::priv
> > get_symbol_name_not_regex() const
> > {
> > if (!symbol_name_not_regex_ && !symbol_name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(), symbol_name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_name_not_regex_ = r;
> >- }
> >+ symbol_name_not_regex_ = regex::compile(symbol_name_not_regex_str_);
> > return symbol_name_not_regex_;
> > }
> >
> >@@ -700,13 +599,7 @@ struct variable_suppression::priv
> > get_symbol_version_regex() const
> > {
> > if (!symbol_version_regex_ && !symbol_version_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- symbol_version_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- symbol_version_regex_ = r;
> >- }
> >+ symbol_version_regex_ = regex::compile(symbol_version_regex_str_);
> > return symbol_version_regex_;
> > }
> >
> >@@ -723,13 +616,7 @@ struct variable_suppression::priv
> > get_type_name_regex() const
> > {
> > if (!type_name_regex_ && !type_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- type_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- type_name_regex_ = r;
> >- }
> >+ type_name_regex_ = regex::compile(type_name_regex_str_);
> > return type_name_regex_;
> > }
> > };// end class variable_supppression::priv
> >@@ -809,17 +696,8 @@ public:
> > const regex::regex_t_sptr
> > get_type_name_regex() const
> > {
> >- if (!type_name_regex_)
> >- {
> >- if (!type_name_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- type_name_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- type_name_regex_ = r;
> >- }
> >- }
> >+ if (!type_name_regex_ && !type_name_regex_str_.empty())
> >+ type_name_regex_ = regex::compile(type_name_regex_str_);
> > return type_name_regex_;
> > }
> >
> >@@ -841,17 +719,8 @@ public:
> > const regex::regex_t_sptr
> > get_type_name_not_regex() const
> > {
> >- if (!type_name_not_regex_)
> >- {
> >- if (!type_name_not_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- type_name_not_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- type_name_not_regex_ = r;
> >- }
> >- }
> >+ if (!type_name_not_regex_ && !type_name_not_regex_str_.empty())
> >+ type_name_not_regex_ = regex::compile(type_name_not_regex_str_);
> > return type_name_not_regex_;
> > }
> >
> >@@ -886,17 +755,10 @@ public:
> > const regex::regex_t_sptr
> > get_source_location_to_keep_regex() const
> > {
> >- if (!source_location_to_keep_regex_)
> >- {
> >- if (!source_location_to_keep_regex_str_.empty())
> >- {
> >- regex::regex_t_sptr r = sptr_utils::build_sptr<regex_t>();
> >- if (regcomp(r.get(),
> >- source_location_to_keep_regex_str_.c_str(),
> >- REG_EXTENDED) == 0)
> >- source_location_to_keep_regex_ = r;
> >- }
> >- }
> >+ if (!source_location_to_keep_regex_
> >+ && !source_location_to_keep_regex_str_.empty())
> >+ source_location_to_keep_regex_ =
> >+ regex::compile(source_location_to_keep_regex_str_);
> > return source_location_to_keep_regex_;
> > }
> >
> >--
> >2.26.2.303.gf8c07b1a785-goog
> >
More information about the Libabigail
mailing list