Avoid throwing exceptions inside XML parser

This addresses an issue found in ARM builds on Mac M1.
The XML parser makes use of exceptions to stop the parsing.
This causes an ABORT on M1/clang for whatever reason.
The new implementation requests the reader to stop
and stores the exception until it is needed.
This commit is contained in:
Matthias Koefferlein 2024-06-02 18:22:15 +02:00
parent 4b0a3dff64
commit 46bb28d4e4
2 changed files with 18 additions and 5 deletions

View File

@ -233,14 +233,14 @@ ImageProxy::get_image () const
if (! m_byte_data.empty ()) {
std::list<std::string>::const_iterator s = m_byte_data.begin ();
for (size_t i = 0; i < m_height; ++i) {
for (size_t i = 0; i < m_height && s != m_byte_data.end (); ++i) {
string_to_pixels<unsigned char, unsigned char> (img.get (), *s++, i, m_width, m_color);
}
} else {
std::list<std::string>::const_iterator s = m_data.begin ();
for (size_t i = 0; i < m_height; ++i) {
for (size_t i = 0; i < m_height && s != m_data.end (); ++i) {
string_to_pixels<float, unsigned char> (img.get (), *s++, i, m_width, m_color);
}

View File

@ -403,9 +403,15 @@ public:
void setDocumentLocator (QXmlLocator *locator);
const tl::XMLLocatedException *exception () const
{
return m_error.get ();
}
private:
QXmlLocator *mp_locator;
XMLStructureHandler *mp_struct_handler;
std::unique_ptr<tl::XMLLocatedException> m_error;
};
// --------------------------------------------------------------------------------------------------------
@ -479,13 +485,17 @@ SAXHandler::characters (const QString &t)
bool
SAXHandler::error (const QXmlParseException &ex)
{
throw tl::XMLLocatedException (tl::to_string (ex.message ()), ex.lineNumber (), ex.columnNumber ());
m_error.reset (new tl::XMLLocatedException (tl::to_string (ex.message ()), ex.lineNumber (), ex.columnNumber ()));
// stop reading
return false;
}
bool
SAXHandler::fatalError (const QXmlParseException &ex)
{
throw tl::XMLLocatedException (tl::to_string (ex.message ()), ex.lineNumber (), ex.columnNumber ());
m_error.reset (new tl::XMLLocatedException (tl::to_string (ex.message ()), ex.lineNumber (), ex.columnNumber ()));
// stop reading
return false;
}
bool
@ -765,7 +775,10 @@ XMLParser::parse (XMLSource &source, XMLStructureHandler &struct_handler)
mp_data->setContentHandler (&handler);
mp_data->setErrorHandler (&handler);
mp_data->parse (source.source (), false /*=not incremental*/);
bool result = mp_data->parse (source.source (), false /*=not incremental*/);
if (! result && handler.exception ()) {
throw tl::XMLLocatedException (*handler.exception ());
}
}
bool