[libxml++] Work around some platforms' lack of support for std::exception_ptr



commit 6d57f92e1faf51adb23bb3776c67a050e0fa02dd
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Oct 29 09:37:10 2015 +0100

    Work around some platforms' lack of support for std::exception_ptr
    
    * libxml++/exceptions/exception.[cc|h]:
    * libxml++/exceptions/internal_error.[cc|h]:
    * libxml++/exceptions/parse_error.[cc|h]:
    * libxml++/exceptions/validity_error.[cc|h]: Reintroduce Raise() and Clone(),
    now renamed to raise() and clone().
    * libxml++/exceptions/wrapped_exception.[cc|h]: Reintroduced files, now
    with the wrapped_exception class declared only if LIBXMLXX_HAVE_EXCEPTION_PTR
    is defined.
    * libxml++/filelist.am: Add wrapped_exception.h.
    * libxml++/parsers/parser.[cc|h]: Replace std::exception_ptr exception_ptr_
    by std::unique_ptr<xmlpp::exception> exception_.
    * libxml++/parsers/saxparser.cc: exception_ptr_ -> exception_
    * libxml++/parsers/saxparser.h: Note in the class description that some
    exceptions are replaced by xmlpp::exception if std::exception_ptr is not
    supported.
    * libxml++/validators/validator.[cc|h]: Replace std::exception_ptr
    exception_ptr_ by std::unique_ptr<xmlpp::exception> exception_.
    * examples/sax_exception/myparser.[cc|h]: Reintroduce Raise() and Clone(),
    now renamed to raise() and clone().
    * tests/saxparser_chunk_parsing_inconsistent_state/main.cc:
    * tests/saxparser_parse_double_free/main.cc:
    * tests/saxparser_parse_stream_inconsistent_state/main.cc: Catch
    xmlpp::exception, if LIBXMLXX_HAVE_EXCEPTION_PTR is not defined.
    Bug #757042.
    
    The substitution of exception_ for exception_ptr_ in Parser and Validator
    breaks ABI. The ABI of libxml++ 3.x has not yet been frozen.
    
    Thanks to Daniel Trebbien <dtrebbien gmail com>, who supplied a patch for
    libxml++ 2.40.

 examples/sax_exception/myparser.cc                 |   10 +++
 examples/sax_exception/myparser.h                  |    2 +
 libxml++/exceptions/exception.cc                   |   10 +++
 libxml++/exceptions/exception.h                    |    3 +
 libxml++/exceptions/internal_error.cc              |   10 +++
 libxml++/exceptions/internal_error.h               |    3 +
 libxml++/exceptions/parse_error.cc                 |   10 +++
 libxml++/exceptions/parse_error.h                  |    3 +
 libxml++/exceptions/validity_error.cc              |   10 +++
 libxml++/exceptions/validity_error.h               |    3 +
 libxml++/exceptions/wrapped_exception.cc           |   46 ++++++++++++++
 libxml++/exceptions/wrapped_exception.h            |   56 +++++++++++++++++
 libxml++/filelist.am                               |    3 +-
 libxml++/parsers/parser.cc                         |   65 ++++++++++---------
 libxml++/parsers/parser.h                          |    3 +-
 libxml++/parsers/saxparser.cc                      |   12 ++--
 libxml++/parsers/saxparser.h                       |    5 ++
 libxml++/validators/validator.cc                   |   61 ++++++++++---------
 libxml++/validators/validator.h                    |    4 +-
 .../main.cc                                        |   13 +++-
 tests/saxparser_parse_double_free/main.cc          |   46 +++++++++++++-
 .../main.cc                                        |   13 +++-
 22 files changed, 313 insertions(+), 78 deletions(-)
---
diff --git a/examples/sax_exception/myparser.cc b/examples/sax_exception/myparser.cc
index 9c9013d..70f8bda 100644
--- a/examples/sax_exception/myparser.cc
+++ b/examples/sax_exception/myparser.cc
@@ -34,6 +34,16 @@ MyException::~MyException() throw ()
 {
 }
 
+void MyException::raise() const
+{
+  throw *this;
+}
+
+xmlpp::exception* MyException::clone() const
+{
+  return new MyException(*this);
+}
+
 /*
  * MySaxParser implementation
  */
diff --git a/examples/sax_exception/myparser.h b/examples/sax_exception/myparser.h
index 3e1c2ee..6c2376d 100644
--- a/examples/sax_exception/myparser.h
+++ b/examples/sax_exception/myparser.h
@@ -27,6 +27,8 @@ class MyException: public xmlpp::exception
   public:
     MyException();
     ~MyException() noexcept override;
+    void raise() const override;
+    xmlpp::exception* clone() const override;
 };
 
 class MySaxParser : public xmlpp::SaxParser
diff --git a/libxml++/exceptions/exception.cc b/libxml++/exceptions/exception.cc
index 6042c37..e7fbf51 100644
--- a/libxml++/exceptions/exception.cc
+++ b/libxml++/exceptions/exception.cc
@@ -19,6 +19,16 @@ const char* exception::what() const noexcept
   return message_.c_str();
 }
 
+void exception::raise() const
+{
+  throw *this;
+}
+
+exception* exception::clone() const
+{
+  return new exception(*this);
+}
+
 Glib::ustring format_xml_error(const _xmlError* error)
 {
   if (!error)
diff --git a/libxml++/exceptions/exception.h b/libxml++/exceptions/exception.h
index cb02717..7fbaf1e 100644
--- a/libxml++/exceptions/exception.h
+++ b/libxml++/exceptions/exception.h
@@ -44,6 +44,9 @@ public:
 
   const char* what() const noexcept override;
 
+  virtual void raise() const;
+  virtual exception* clone() const;
+
 private:
   Glib::ustring message_;
 };
diff --git a/libxml++/exceptions/internal_error.cc b/libxml++/exceptions/internal_error.cc
index 9f48cac..2bdbe1c 100644
--- a/libxml++/exceptions/internal_error.cc
+++ b/libxml++/exceptions/internal_error.cc
@@ -10,4 +10,14 @@ internal_error::internal_error(const Glib::ustring& message)
 internal_error::~internal_error() noexcept
 {}
 
+void internal_error::raise() const
+{
+  throw *this;
+}
+
+exception* internal_error::clone() const
+{
+  return new internal_error(*this);
+}
+
 } //namespace xmlpp
diff --git a/libxml++/exceptions/internal_error.h b/libxml++/exceptions/internal_error.h
index e43d452..07912cb 100644
--- a/libxml++/exceptions/internal_error.h
+++ b/libxml++/exceptions/internal_error.h
@@ -29,6 +29,9 @@ class internal_error : public exception
 public:
   explicit internal_error(const Glib::ustring& message);
   ~internal_error() noexcept override;
+
+  void raise() const override;
+  exception* clone() const override;
 };
 
 } // namespace xmlpp
diff --git a/libxml++/exceptions/parse_error.cc b/libxml++/exceptions/parse_error.cc
index 96bd53e..a83a3fc 100644
--- a/libxml++/exceptions/parse_error.cc
+++ b/libxml++/exceptions/parse_error.cc
@@ -10,4 +10,14 @@ parse_error::parse_error(const Glib::ustring& message)
 parse_error::~parse_error() noexcept
 {}
 
+void parse_error::raise() const
+{
+  throw *this;
+}
+
+exception* parse_error::clone() const
+{
+  return new parse_error(*this);
+}
+
 } //namespace xmlpp
diff --git a/libxml++/exceptions/parse_error.h b/libxml++/exceptions/parse_error.h
index 3b386d8..724f931 100644
--- a/libxml++/exceptions/parse_error.h
+++ b/libxml++/exceptions/parse_error.h
@@ -32,6 +32,9 @@ class parse_error : public exception
 public:
   explicit parse_error(const Glib::ustring& message);
   ~parse_error() noexcept override;
+
+  void raise() const override;
+  exception* clone() const override;
 };
 
 } // namespace xmlpp
diff --git a/libxml++/exceptions/validity_error.cc b/libxml++/exceptions/validity_error.cc
index b0fdc24..81006b6 100644
--- a/libxml++/exceptions/validity_error.cc
+++ b/libxml++/exceptions/validity_error.cc
@@ -10,4 +10,14 @@ validity_error::validity_error(const Glib::ustring& message)
 validity_error::~validity_error() noexcept
 {}
 
+void validity_error::raise() const
+{
+  throw *this;
+}
+
+exception* validity_error::clone() const
+{
+  return new validity_error(*this);
+}
+
 } //namespace xmlpp
diff --git a/libxml++/exceptions/validity_error.h b/libxml++/exceptions/validity_error.h
index 503eeb3..e264e4b 100644
--- a/libxml++/exceptions/validity_error.h
+++ b/libxml++/exceptions/validity_error.h
@@ -32,6 +32,9 @@ class validity_error : public parse_error
 public:
   explicit validity_error(const Glib::ustring& message);
   ~validity_error() noexcept override;
+
+  void raise() const override;
+  exception* clone() const override;
 };
 
 } // namespace xmlpp
diff --git a/libxml++/exceptions/wrapped_exception.cc b/libxml++/exceptions/wrapped_exception.cc
new file mode 100644
index 0000000..062dbeb
--- /dev/null
+++ b/libxml++/exceptions/wrapped_exception.cc
@@ -0,0 +1,46 @@
+/* Copyright (C) 2015  The libxml++ development team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "wrapped_exception.h"
+
+namespace xmlpp
+{
+
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
+
+wrapped_exception::wrapped_exception(std::exception_ptr exception_ptr)
+  : exception("Wrapped exception"), exception_ptr_(exception_ptr)
+{
+}
+
+wrapped_exception::~wrapped_exception() noexcept
+{
+}
+
+void wrapped_exception::raise() const
+{
+  std::rethrow_exception(exception_ptr_);
+}
+
+exception* wrapped_exception::clone() const
+{
+  return new wrapped_exception(exception_ptr_);
+}
+
+#endif // LIBXMLXX_HAVE_EXCEPTION_PTR
+
+} // namespace xmlpp
diff --git a/libxml++/exceptions/wrapped_exception.h b/libxml++/exceptions/wrapped_exception.h
new file mode 100644
index 0000000..ffcafea
--- /dev/null
+++ b/libxml++/exceptions/wrapped_exception.h
@@ -0,0 +1,56 @@
+/* Copyright (C) 2015  The libxml++ development team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __LIBXMLPP_WRAPPED_EXCEPTION_H
+#define __LIBXMLPP_WRAPPED_EXCEPTION_H
+
+#include <exception>
+
+#include <libxml++/exceptions/exception.h>
+#include <libxml++config.h>
+
+namespace xmlpp
+{
+
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+/** Helper class for propagating an exception through C code.
+ * Should not be used by applications.
+ * Does not exist in systems that don't support std::exception_ptr.
+ *
+ * @newin{2,40}
+ */
+class wrapped_exception : public exception
+{
+public:
+  explicit wrapped_exception(std::exception_ptr exception_ptr);
+  ~wrapped_exception() noexcept override;
+
+  void raise() const override;
+  exception* clone() const override;
+
+private:
+  std::exception_ptr exception_ptr_;
+};
+#endif //DOXYGEN_SHOULD_SKIP_THIS
+
+#endif // LIBXMLXX_HAVE_EXCEPTION_PTR
+
+} // namespace xmlpp
+
+#endif // __LIBXMLPP_WRAPPED_EXCEPTION_H
diff --git a/libxml++/filelist.am b/libxml++/filelist.am
index aeedd0c..ee338a8 100644
--- a/libxml++/filelist.am
+++ b/libxml++/filelist.am
@@ -15,7 +15,8 @@ h_exceptions_sources_public = \
   exceptions/exception.h \
   exceptions/parse_error.h \
   exceptions/validity_error.h \
-  exceptions/internal_error.h
+  exceptions/internal_error.h \
+  exceptions/wrapped_exception.h
 h_io_sources_public = \
   io/istreamparserinputbuffer.h \
   io/outputbuffer.h \
diff --git a/libxml++/parsers/parser.cc b/libxml++/parsers/parser.cc
index 019ffc1..503987a 100644
--- a/libxml++/parsers/parser.cc
+++ b/libxml++/parsers/parser.cc
@@ -4,6 +4,7 @@
  * included with libxml++ as the file COPYING.
  */
 
+#include "libxml++/exceptions/wrapped_exception.h"
 #include "libxml++/parsers/parser.h"
 
 #include <libxml/parser.h>
@@ -34,7 +35,7 @@ struct Parser::Impl
 };
 
 Parser::Parser()
-: context_(nullptr), exception_ptr_(nullptr), pimpl_(new Impl)
+: context_(nullptr), exception_(nullptr), pimpl_(new Impl)
 {
 }
 
@@ -193,20 +194,7 @@ void Parser::on_validity_warning(const Glib::ustring& message)
 
 void Parser::check_for_error_and_warning_messages()
 {
-  Glib::ustring msg;
-  try
-  {
-    if (exception_ptr_)
-      std::rethrow_exception(exception_ptr_);
-  }
-  catch (const std::exception& e)
-  {
-    msg = e.what();
-  }
-  catch (...)
-  {
-    msg = "Unknown exception\n";
-  }
+  Glib::ustring msg(exception_ ? exception_->what() : "");
   bool parser_msg = false;
   bool validity_msg = false;
 
@@ -238,17 +226,10 @@ void Parser::check_for_error_and_warning_messages()
     pimpl_->validate_warning_.erase();
   }
 
-  try
-  {
-    if (validity_msg)
-      throw validity_error(msg);
-    else if (parser_msg)
-      throw parse_error(msg);
-  }
-  catch (...)
-  {
-    exception_ptr_ = std::current_exception();
-  }
+  if (validity_msg)
+    exception_.reset(new validity_error(msg));
+  else if (parser_msg)
+    exception_.reset(new parse_error(msg));
 }
   
 //static
@@ -339,7 +320,30 @@ void Parser::callback_error_or_warning(MsgType msg_type, void* ctx,
 
 void Parser::handle_exception()
 {
-  exception_ptr_ = std::current_exception();
+  try
+  {
+    throw; // Re-throw current exception
+  }
+  catch (const exception& e)
+  {
+    exception_.reset(e.clone());
+  }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
+  catch (...)
+  {
+    exception_.reset(new wrapped_exception(std::current_exception()));
+  }
+#else
+  catch (const std::exception& e)
+  {
+    exception_.reset(new exception(e.what()));
+  }
+  catch (...)
+  {
+    exception_.reset(new exception("An exception was thrown that is not derived from std::exception or 
xmlpp::exception.\n"
+      "It could not be caught and rethrown because this platform does not support std::exception_ptr."));
+  }
+#endif
 
   if (context_)
     xmlStopParser(context_);
@@ -351,11 +355,10 @@ void Parser::check_for_exception()
 {
   check_for_error_and_warning_messages();
   
-  if (exception_ptr_)
+  if (exception_)
   {
-    std::exception_ptr tmp(exception_ptr_);
-    exception_ptr_ = nullptr;
-    std::rethrow_exception(tmp);
+    std::unique_ptr<exception> tmp(std::move(exception_));
+    tmp->raise();
   }
 }
 
diff --git a/libxml++/parsers/parser.h b/libxml++/parsers/parser.h
index 4384b9f..71e65a2 100644
--- a/libxml++/parsers/parser.h
+++ b/libxml++/parsers/parser.h
@@ -19,7 +19,6 @@
 #include <istream>
 #include <cstdarg> // va_list
 #include <memory> // std::unique_ptr
-#include <exception> // std::exception_ptr
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 extern "C" {
@@ -198,7 +197,7 @@ protected:
                                         const char* msg, va_list var_args);
 
   _xmlParserCtxt* context_;
-  std::exception_ptr exception_ptr_;
+  std::unique_ptr<exception> exception_;
 
 private:
   struct Impl;
diff --git a/libxml++/parsers/saxparser.cc b/libxml++/parsers/saxparser.cc
index acbb9a2..473f90d 100644
--- a/libxml++/parsers/saxparser.cc
+++ b/libxml++/parsers/saxparser.cc
@@ -240,7 +240,7 @@ void SaxParser::parse_stream(std::istream& in)
   // encoding it uses. See the XML specification. Thus use std::string.
   int firstParseError = XML_ERR_OK;
   std::string line;
-  while (!exception_ptr_ && std::getline(in, line))
+  while (!exception_ && std::getline(in, line))
   {
     // since getline does not get the line separator, we have to add it since the parser care
     // about layout in certain cases.
@@ -256,7 +256,7 @@ void SaxParser::parse_stream(std::istream& in)
       firstParseError = parseError;
   }
 
-  if (!exception_ptr_)
+  if (!exception_)
   {
      //This is called just to terminate parsing.
     const int parseError = xmlParseChunk(context_, nullptr /* chunk */, 0 /* size */, 1 /* terminate (1 or 
0) */);
@@ -308,7 +308,7 @@ void SaxParser::parse_chunk_raw(const unsigned char* contents, size_type bytes_c
     xmlCtxtResetLastError(context_);
   
   int parseError = XML_ERR_OK;
-  if (!exception_ptr_)
+  if (!exception_)
     parseError = xmlParseChunk(context_, (const char*)contents, bytes_count, 0 /* don't terminate */);
 
   check_for_exception();
@@ -344,7 +344,7 @@ void SaxParser::finish_chunk_parsing()
     xmlCtxtResetLastError(context_);
 
   int parseError = XML_ERR_OK;
-  if (!exception_ptr_)
+  if (!exception_)
     //This is called just to terminate parsing.
     parseError = xmlParseChunk(context_, nullptr /* chunk */, 0 /* size */, 1 /* terminate (1 or 0) */);
 
@@ -433,7 +433,7 @@ void SaxParserCallback::end_document(void* context)
   auto the_context = static_cast<_xmlParserCtxt*>(context);
   auto parser = static_cast<SaxParser*>(the_context->_private);
 
-  if (parser->exception_ptr_)
+  if (parser->exception_)
     return;
 
   try
@@ -546,7 +546,7 @@ void SaxParserCallback::error(void* context, const char* fmt, ...)
   auto the_context = static_cast<_xmlParserCtxt*>(context);
   auto parser = static_cast<SaxParser*>(the_context->_private);
 
-  if (parser->exception_ptr_)
+  if (parser->exception_)
     return;
 
   va_list arg;
diff --git a/libxml++/parsers/saxparser.h b/libxml++/parsers/saxparser.h
index 58cab4d..cba267b 100644
--- a/libxml++/parsers/saxparser.h
+++ b/libxml++/parsers/saxparser.h
@@ -25,6 +25,11 @@ namespace xmlpp {
 /** SAX XML parser.
  * Derive your own class and override the on_*() methods.
  * SAX = Simple API for XML
+ *
+ * In a system that does not support std::exception_ptr: If an overridden on_*()
+ * method throws an exception which is not derived from xmlpp::exception,
+ * that exception is replaced by a xmlpp::exception before it is propagated
+ * out of the parse method, such as parse_file().
  */
 class SaxParser : public Parser
 {
diff --git a/libxml++/validators/validator.cc b/libxml++/validators/validator.cc
index 4858cee..69d0276 100644
--- a/libxml++/validators/validator.cc
+++ b/libxml++/validators/validator.cc
@@ -5,6 +5,7 @@
  * included with libxml++ as the file COPYING.
  */
 
+#include "libxml++/exceptions/wrapped_exception.h"
 #include "libxml++/validators/validator.h"
 
 #include <libxml/parser.h>
@@ -15,7 +16,7 @@
 namespace xmlpp {
 
 Validator::Validator()
-: exception_ptr_(nullptr)
+: exception_(nullptr)
 {
 }
 
@@ -49,20 +50,7 @@ void Validator::on_validity_warning(const Glib::ustring& message)
 
 void Validator::check_for_validity_messages()
 {
-  Glib::ustring msg;
-  try
-  {
-    if (exception_ptr_)
-      std::rethrow_exception(exception_ptr_);
-  }
-  catch (const std::exception& e)
-  {
-    msg = e.what();
-  }
-  catch (...)
-  {
-    msg = "Unknown exception\n";
-  }
+  Glib::ustring msg(exception_ ? exception_->what() : "");
   bool validity_msg = false;
 
   if (!validate_error_.empty())
@@ -79,15 +67,8 @@ void Validator::check_for_validity_messages()
     validate_warning_.erase();
   }
 
-  try
-  {
-    if (validity_msg)
-      throw validity_error(msg);
-  }
-  catch (...)
-  {
-    exception_ptr_ = std::current_exception();
-  }
+  if (validity_msg)
+    exception_.reset(new validity_error(msg));
 }
 
 void Validator::callback_validity_error(void* valid_, const char* msg, ...)
@@ -138,7 +119,30 @@ void Validator::callback_validity_warning(void* valid_, const char* msg, ...)
 
 void Validator::handle_exception()
 {
-  exception_ptr_ = std::current_exception();
+  try
+  {
+    throw; // Re-throw current exception
+  }
+  catch (const exception& e)
+  {
+    exception_.reset(e.clone());
+  }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
+  catch (...)
+  {
+    exception_.reset(new wrapped_exception(std::current_exception()));
+  }
+#else
+  catch (const std::exception& e)
+  {
+    exception_.reset(new exception(e.what()));
+  }
+  catch (...)
+  {
+    exception_.reset(new exception("An exception was thrown that is not derived from std::exception or 
xmlpp::exception.\n"
+      "It could not be caught and rethrown because this platform does not support std::exception_ptr."));
+  }
+#endif
 
   // Don't delete the DTD validation context or schema validation context
   // while validating. It would cause accesses to deallocated memory in libxml2
@@ -156,11 +160,10 @@ void Validator::check_for_exception()
 {
   check_for_validity_messages();
   
-  if (exception_ptr_)
+  if (exception_)
   {
-    std::exception_ptr tmp(exception_ptr_);
-    exception_ptr_ = nullptr;
-    std::rethrow_exception(tmp);
+    std::unique_ptr<exception> tmp(std::move(exception_));
+    tmp->raise();
   }
 }
 
diff --git a/libxml++/validators/validator.h b/libxml++/validators/validator.h
index 93f443f..ed32460 100644
--- a/libxml++/validators/validator.h
+++ b/libxml++/validators/validator.h
@@ -15,7 +15,7 @@
 #include <libxml++/noncopyable.h>
 #include <libxml++/exceptions/validity_error.h>
 #include <libxml++/exceptions/internal_error.h>
-#include <exception> // std::exception_ptr
+#include <memory> // std::unique_ptr
 #include <string>
 
 extern "C" {
@@ -77,7 +77,7 @@ protected:
   static void callback_validity_error(void* ctx, const char* msg, ...);
   static void callback_validity_warning(void* ctx, const char* msg, ...);
 
-  std::exception_ptr exception_ptr_;
+  std::unique_ptr<exception> exception_;
   // Built gradually - used in an exception at the end of validation.
   Glib::ustring validate_error_;
   Glib::ustring validate_warning_;
diff --git a/tests/saxparser_chunk_parsing_inconsistent_state/main.cc 
b/tests/saxparser_chunk_parsing_inconsistent_state/main.cc
index 5e34233..136bfb7 100644
--- a/tests/saxparser_chunk_parsing_inconsistent_state/main.cc
+++ b/tests/saxparser_chunk_parsing_inconsistent_state/main.cc
@@ -15,13 +15,14 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <config.h>
+#include <libxml++/libxml++.h>
+
 #include <cstdlib>
 #include <glibmm.h>
 #include <sstream>
 #include <stdexcept>
 
-#include <libxml++/libxml++.h>
-
 class MySaxParser : public xmlpp::SaxParser
 {
 protected:
@@ -48,7 +49,11 @@ int main()
       parser.parse_chunk("<?");
       parser.finish_chunk_parsing();
     }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
     catch(const std::runtime_error& e)
+#else
+    catch(const xmlpp::exception& e)
+#endif
     {
       exceptionThrown = true;
       g_assert_cmpstr(e.what(), ==, "on_error() called");
@@ -68,7 +73,11 @@ int main()
       // error should not have been thrown.
       g_assert_not_reached();
     }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
     catch(const std::runtime_error& e)
+#else
+    catch(const xmlpp::exception& e)
+#endif
     {
       exceptionThrown = true;
       g_assert_cmpstr(e.what(), ==, "some custom runtime exception");
diff --git a/tests/saxparser_parse_double_free/main.cc b/tests/saxparser_parse_double_free/main.cc
index faaf964..e1bd3b6 100644
--- a/tests/saxparser_parse_double_free/main.cc
+++ b/tests/saxparser_parse_double_free/main.cc
@@ -15,13 +15,13 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <config.h>
+#include <libxml++/libxml++.h>
+
 #include <cstdlib>
 #include <glibmm.h>
 #include <stdexcept>
 
-#include <libxml++/libxml++.h>
-
-
 class OnCdataBlockTestParser : public xmlpp::SaxParser
 {
 protected:
@@ -40,7 +40,11 @@ void test_on_cdata_block()
   {
     parser.parse_memory("<root><![CDATA[some CDATA]]></root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_cdata_block runtime exception");
@@ -67,7 +71,11 @@ void test_on_characters()
   {
     parser.parse_memory("<root>abc</root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_characters runtime exception");
@@ -94,7 +102,11 @@ void test_on_comment()
   {
     parser.parse_memory("<root><!--a comment--></root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_comment runtime exception");
@@ -120,7 +132,11 @@ void test_on_end_document()
   {
     parser.parse_memory("<root></root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_end_document runtime exception");
@@ -147,7 +163,11 @@ void test_on_end_element()
   {
     parser.parse_memory("<a:root xmlns:a=\"urn:test\"></a:root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_end_element runtime exception");
@@ -177,7 +197,11 @@ void test_on_entity_declaration()
   {
     parser.parse_memory("<!DOCTYPE MyDocument [<!ENTITY number \"42\">]><root></root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_entity_declaration runtime exception");
@@ -203,7 +227,11 @@ void test_on_error()
   {
     parser.parse_memory("<root>&unknown;</root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_error runtime exception");
@@ -235,7 +263,11 @@ void test_on_get_entity()
   {
     parser.parse_memory("<!DOCTYPE MyDocument [<!ENTITY number \"42\">]><root>&number;</root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_get_entity runtime exception");
@@ -261,7 +293,11 @@ void test_on_start_document()
   {
     parser.parse_memory("<root></root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_start_document runtime exception");
@@ -289,7 +325,11 @@ void test_on_start_element()
   {
     parser.parse_memory("<b:root xmlns:b=\"urn:test\" someattr=\"test\"></b:root>");
   }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
   catch(const std::runtime_error& e)
+#else
+  catch(const xmlpp::exception& e)
+#endif
   {
     exceptionThrown = true;
     g_assert_cmpstr(e.what(), ==, "on_start_element runtime exception");
diff --git a/tests/saxparser_parse_stream_inconsistent_state/main.cc 
b/tests/saxparser_parse_stream_inconsistent_state/main.cc
index ea8cf44..4fd1320 100644
--- a/tests/saxparser_parse_stream_inconsistent_state/main.cc
+++ b/tests/saxparser_parse_stream_inconsistent_state/main.cc
@@ -15,13 +15,14 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <config.h>
+#include <libxml++/libxml++.h>
+
 #include <cstdlib>
 #include <glibmm.h>
 #include <sstream>
 #include <stdexcept>
 
-#include <libxml++/libxml++.h>
-
 class MySaxParser : public xmlpp::SaxParser
 {
 protected:
@@ -44,7 +45,11 @@ int main()
       std::stringstream ss("<root></root>");
       parser.parse_stream(ss);
     }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
     catch(const std::runtime_error& e)
+#else
+    catch(const xmlpp::exception& e)
+#endif
     {
       exceptionThrown = true;
       g_assert_cmpstr(e.what(), ==, "some custom runtime exception");
@@ -64,7 +69,11 @@ int main()
       // error should not have been thrown.
       g_assert_not_reached();
     }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
     catch(const std::runtime_error& e)
+#else
+    catch(const xmlpp::exception& e)
+#endif
     {
       exceptionThrown = true;
       g_assert_cmpstr(e.what(), ==, "some custom runtime exception");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]