[PATCH 5/7] Add error handling to read_suppressions.
Giuliano Procida
gprocida@google.com
Mon Aug 17 09:38:17 GMT 2020
The top-level parsing functions read_suppresions (one file-scoped
overload and two externally-visible overloads) have no error handling.
This change makes each return a success status and adds placeholders
for where error messages might be emitted.
There are no behavioural changes.
* include/abg-suppression.h (read_suppresions): Change return
type to bool.
* src/abg-suppression.cc (read_suppresions): In the static
worker overload, return parse success status. In the wrapper
overloads return false if ini config parsing fails.
Signed-off-by: Giuliano Procida <gprocida@google.com>
---
include/abg-suppression.h | 4 +--
src/abg-suppression.cc | 57 +++++++++++++++++++++++++++++----------
2 files changed, 45 insertions(+), 16 deletions(-)
diff --git a/include/abg-suppression.h b/include/abg-suppression.h
index 6383b9322..dbb52de35 100644
--- a/include/abg-suppression.h
+++ b/include/abg-suppression.h
@@ -130,11 +130,11 @@ public:
const suppression_base& suppr);
}; // end class suppression_base
-void
+bool
read_suppressions(std::istream& input,
suppressions_type& suppressions);
-void
+bool
read_suppressions(const string& file_path,
suppressions_type& suppressions);
diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index 736c7f51f..fb97a124b 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -372,10 +372,12 @@ read_file_suppression(const ini::config::section& section,
///
/// @param suppressions out parameter. The vector of suppressions to
/// append the newly read suppressions to.
-static void
-read_suppressions(const ini::config& config,
- suppressions_type& suppressions)
+///
+/// @return whether the parse was successful.
+static bool
+read_suppressions(const ini::config& config, suppressions_type& suppressions)
{
+ bool success = true;
for (ini::config::sections_type::const_iterator i =
config.get_sections().begin();
i != config.get_sections().end();
@@ -383,18 +385,31 @@ read_suppressions(const ini::config& config,
{
const ini::config::section_sptr& section = *i;
const std::string& name = section->get_name();
+ bool section_success;
suppression_sptr s;
if (name == "suppress_type")
- read_type_suppression(*section, s);
+ section_success = read_type_suppression(*section, s);
else if (name == "suppress_function")
- read_function_suppression(*section, s);
+ section_success = read_function_suppression(*section, s);
else if (name == "suppress_variable")
- read_variable_suppression(*section, s);
+ section_success = read_variable_suppression(*section, s);
else if (name == "suppress_file")
- read_file_suppression(*section, s);
- if (s)
+ section_success = read_file_suppression(*section, s);
+ else
+ {
+ // TODO: maybe emit unknown section name error
+ success = false;
+ continue;
+ }
+ if (section_success)
suppressions.push_back(s);
+ else
+ {
+ // TODO: maybe emit section parse failure message
+ success = false;
+ }
}
+ return success;
}
/// Read suppressions specifications from an input stream.
@@ -403,12 +418,19 @@ read_suppressions(const ini::config& config,
///
/// @param suppressions the vector of suppressions to append the newly
/// read suppressions to.
-void
+///
+/// @return whether the parse was successful
+bool
read_suppressions(std::istream& input,
suppressions_type& suppressions)
{
- if (ini::config_sptr config = ini::read_config(input))
- read_suppressions(*config, suppressions);
+ ini::config_sptr config = ini::read_config(input);
+ if (!config)
+ {
+ // TODO: maybe report ini configuration parse failure
+ return false;
+ }
+ return read_suppressions(*config, suppressions);
}
/// Read suppressions specifications from an input file on disk.
@@ -417,12 +439,19 @@ read_suppressions(std::istream& input,
///
/// @param suppressions the vector of suppressions to append the newly
/// read suppressions to.
-void
+///
+/// @return whether the parse was successful
+bool
read_suppressions(const string& file_path,
suppressions_type& suppressions)
{
- if (ini::config_sptr config = ini::read_config(file_path))
- read_suppressions(*config, suppressions);
+ ini::config_sptr config = ini::read_config(file_path);
+ if (!config)
+ {
+ // TODO: maybe report ini configuration file_path parse failure
+ return false;
+ }
+ return read_suppressions(*config, suppressions);
}
// </suppression_base stuff>
--
2.28.0.220.ged08abb693-goog
More information about the Libabigail
mailing list