[libxml++] Validators: Move _xmlValidCtxt pointer to DtdValidator



commit a82fb4d25c6f6aac7a76f3cc5498771b2615a6d0
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu Sep 24 17:20:17 2015 +0200

    Validators: Move _xmlValidCtxt pointer to DtdValidator
    
    * libxml++/validators/validator.[h|cc]:
    * libxml++/validators/dtdvalidator.[h|cc]: Rename _xmlValidCtxt* valid_ to
    context_ and move it from Validator to DtdValidator.
    Rename initialize_valid() to initialize_context().
    * libxml++/validators/schemavalidatorbase.[h|cc]:
    * libxml++/validators/relaxngvalidator.[h|cc]:
    * libxml++/validators/xsdvalidator.[h|cc]: Rename initialize_valid() to
    initialize_context(). Bug #754673.

 libxml++/validators/dtdvalidator.cc        |   44 +++++++++++++++++++++------
 libxml++/validators/dtdvalidator.h         |    2 +
 libxml++/validators/relaxngvalidator.cc    |    6 ++--
 libxml++/validators/relaxngvalidator.h     |    2 +-
 libxml++/validators/schemavalidatorbase.cc |    4 +-
 libxml++/validators/schemavalidatorbase.h  |    2 +-
 libxml++/validators/validator.cc           |   25 ++--------------
 libxml++/validators/validator.h            |    3 +-
 libxml++/validators/xsdvalidator.cc        |    8 ++--
 libxml++/validators/xsdvalidator.h         |    2 +-
 10 files changed, 52 insertions(+), 46 deletions(-)
---
diff --git a/libxml++/validators/dtdvalidator.cc b/libxml++/validators/dtdvalidator.cc
index 210064f..14f9126 100644
--- a/libxml++/validators/dtdvalidator.cc
+++ b/libxml++/validators/dtdvalidator.cc
@@ -22,18 +22,18 @@ namespace xmlpp
 {
 
 DtdValidator::DtdValidator()
-: dtd_(nullptr)
+: context_(nullptr), dtd_(nullptr)
 {
 }
 
 DtdValidator::DtdValidator(const Glib::ustring& file)
-: dtd_(nullptr)
+: context_(nullptr), dtd_(nullptr)
 {
   parse_subset("",file);
 }
 
 DtdValidator::DtdValidator(const Glib::ustring& external, const Glib::ustring& system)
-: dtd_(nullptr)
+: context_(nullptr), dtd_(nullptr)
 {
   parse_subset(external,system);
 }
@@ -41,7 +41,6 @@ DtdValidator::DtdValidator(const Glib::ustring& external, const Glib::ustring& s
 DtdValidator::~DtdValidator()
 {
   release_underlying();
-  Validator::release_underlying();
 }
 
 void DtdValidator::parse_file(const Glib::ustring& filename)
@@ -93,9 +92,32 @@ void DtdValidator::parse_stream(std::istream& in)
   dtd_ = static_cast<Dtd*>(dtd->_private);
 }
 
+void DtdValidator::initialize_context()
+{
+  Validator::initialize_context();
+
+  if (context_)
+  {
+    //Tell the validation context about the callbacks:
+    context_->error = &callback_validity_error;
+    context_->warning = &callback_validity_warning;
+
+    //Allow the callback_validity_*() methods to retrieve the C++ instance:
+    context_->userData = this;
+  }
+}
+
 void DtdValidator::release_underlying()
 {
-  if(dtd_)
+  if (context_)
+  {
+    context_->userData = nullptr; //Not really necessary.
+
+    xmlFreeValidCtxt(context_);
+    context_ = nullptr;
+  }
+
+  if (dtd_)
   {
     //Make a local pointer to the underlying xmlDtd object as the wrapper is destroyed first.
     //After free_wrappers is called dtd_ will be invalid (e.g. delete dtd_)
@@ -104,6 +126,8 @@ void DtdValidator::release_underlying()
     xmlFreeDtd(dtd);
     dtd_ = nullptr;
   }
+
+  Validator::release_underlying();
 }
 
 DtdValidator::operator bool() const noexcept
@@ -134,18 +158,18 @@ void DtdValidator::validate(const Document* document)
   }
 
   // A context is required at this stage only
-  if (!valid_)
-    valid_ = xmlNewValidCtxt();
+  if (!context_)
+    context_ = xmlNewValidCtxt();
 
-  if(!valid_)
+  if(!context_)
   {
     throw internal_error("Couldn't create validation context");
   }
 
   xmlResetLastError();
-  initialize_valid();
+  initialize_context();
 
-  const bool res = (bool)xmlValidateDtd( valid_, (xmlDoc*)document->cobj(), dtd_->cobj() );
+  const bool res = (bool)xmlValidateDtd( context_, (xmlDoc*)document->cobj(), dtd_->cobj() );
 
   if (!res)
   {
diff --git a/libxml++/validators/dtdvalidator.h b/libxml++/validators/dtdvalidator.h
index aaa7a8d..0ee0c71 100644
--- a/libxml++/validators/dtdvalidator.h
+++ b/libxml++/validators/dtdvalidator.h
@@ -95,8 +95,10 @@ public:
   void validate(const Document* document) override;
 
 protected:
+  void initialize_context() override;
   void release_underlying() override;
 
+  _xmlValidCtxt* context_;
   Dtd* dtd_;
 };
 
diff --git a/libxml++/validators/relaxngvalidator.cc b/libxml++/validators/relaxngvalidator.cc
index bbd9c9a..8e92365 100644
--- a/libxml++/validators/relaxngvalidator.cc
+++ b/libxml++/validators/relaxngvalidator.cc
@@ -123,10 +123,10 @@ RelaxNGValidator::operator bool() const noexcept
 }
 
 
-void RelaxNGValidator::initialize_valid()
+void RelaxNGValidator::initialize_context()
 {
   xmlRelaxNGSetValidErrors(pimpl_->context, &callback_validity_error, &callback_validity_warning, this);
-  SchemaValidatorBase::initialize_valid();
+  SchemaValidatorBase::initialize_context();
 }
 
 void RelaxNGValidator::validate(const Document* document)
@@ -145,7 +145,7 @@ void RelaxNGValidator::validate(const Document* document)
     throw internal_error("RelaxNGValidator::validate(): Could not create validating context");
 
   xmlResetLastError();
-  initialize_valid();
+  initialize_context();
 
   const int res = xmlRelaxNGValidateDoc(pimpl_->context, const_cast<xmlDoc*>(document->cobj()));
   if (res != 0)
diff --git a/libxml++/validators/relaxngvalidator.h b/libxml++/validators/relaxngvalidator.h
index 38051c6..a12b710 100644
--- a/libxml++/validators/relaxngvalidator.h
+++ b/libxml++/validators/relaxngvalidator.h
@@ -148,7 +148,7 @@ public:
   void validate(const Glib::ustring& filename) override;
 
 protected:
-  void initialize_valid() override;
+  void initialize_context() override;
   void release_underlying() override;
 
 private:
diff --git a/libxml++/validators/schemavalidatorbase.cc b/libxml++/validators/schemavalidatorbase.cc
index 04aa74c..f282452 100644
--- a/libxml++/validators/schemavalidatorbase.cc
+++ b/libxml++/validators/schemavalidatorbase.cc
@@ -36,9 +36,9 @@ void SchemaValidatorBase::release_underlying()
   Validator::release_underlying();
 }
 
-void SchemaValidatorBase::initialize_valid()
+void SchemaValidatorBase::initialize_context()
 {
-  Validator::initialize_valid();
+  Validator::initialize_context();
 }
 
 } // namespace xmlpp
diff --git a/libxml++/validators/schemavalidatorbase.h b/libxml++/validators/schemavalidatorbase.h
index 18a6a35..f5b7f86 100644
--- a/libxml++/validators/schemavalidatorbase.h
+++ b/libxml++/validators/schemavalidatorbase.h
@@ -89,7 +89,7 @@ public:
   virtual void validate(const Glib::ustring& filename) = 0;
 
 protected:
-  void initialize_valid() override;
+  void initialize_context() override;
   void release_underlying() override;
 };
 
diff --git a/libxml++/validators/validator.cc b/libxml++/validators/validator.cc
index 71e5999..cd5d42d 100644
--- a/libxml++/validators/validator.cc
+++ b/libxml++/validators/validator.cc
@@ -15,7 +15,7 @@
 namespace xmlpp {
 
 Validator::Validator()
-: valid_(nullptr), exception_ptr_(nullptr)
+: exception_ptr_(nullptr)
 {
 }
 
@@ -24,34 +24,15 @@ Validator::~Validator()
   release_underlying();
 }
 
-void Validator::initialize_valid()
+void Validator::initialize_context()
 {
-  // valid_ is used only by DtdValidator.
-  //TODO: When we can break ABI, move valid_ to DtdValidator.
-  if (valid_)
-  {
-    //Tell the validation context about the callbacks:
-    valid_->error = &callback_validity_error;
-    valid_->warning = &callback_validity_warning;
-
-    //Allow the callback_validity_*() methods to retrieve the C++ instance:
-    valid_->userData = this;
-  }
-
-  //Clear these temporary buffers too:
+  //Clear these temporary buffers:
   validate_error_.erase();
   validate_warning_.erase();
 }
 
 void Validator::release_underlying()
 {
-  if(valid_)
-  {
-    valid_->userData = nullptr; //Not really necessary.
-
-    xmlFreeValidCtxt(valid_);
-    valid_ = nullptr;
-  }
 }
 
 void Validator::on_validity_error(const Glib::ustring& message)
diff --git a/libxml++/validators/validator.h b/libxml++/validators/validator.h
index e46f899..e25a176 100644
--- a/libxml++/validators/validator.h
+++ b/libxml++/validators/validator.h
@@ -62,7 +62,7 @@ public:
   explicit virtual operator bool() const noexcept = 0;
 
 protected:
-  virtual void initialize_valid();
+  virtual void initialize_context();
   virtual void release_underlying();
 
   virtual void on_validity_error(const Glib::ustring& message);
@@ -76,7 +76,6 @@ protected:
   static void callback_validity_error(void* ctx, const char* msg, ...);
   static void callback_validity_warning(void* ctx, const char* msg, ...);
 
-  _xmlValidCtxt* valid_;
   std::exception_ptr exception_ptr_;
   // Built gradually - used in an exception at the end of validation.
   Glib::ustring validate_error_;
diff --git a/libxml++/validators/xsdvalidator.cc b/libxml++/validators/xsdvalidator.cc
index 0dd8a09..44be9a0 100644
--- a/libxml++/validators/xsdvalidator.cc
+++ b/libxml++/validators/xsdvalidator.cc
@@ -120,10 +120,10 @@ XsdValidator::operator bool() const noexcept
 }
 
 
-void XsdValidator::initialize_valid()
+void XsdValidator::initialize_context()
 {
   xmlSchemaSetValidErrors(pimpl_->context, &callback_validity_error, &callback_validity_warning, this);
-  SchemaValidatorBase::initialize_valid();
+  SchemaValidatorBase::initialize_context();
 }
 
 
@@ -143,7 +143,7 @@ void XsdValidator::validate(const Document* document)
     throw internal_error("XsdValidator::validate(): Could not create validating context");
 
   xmlResetLastError();
-  initialize_valid();
+  initialize_context();
 
   const int res = xmlSchemaValidateDoc(pimpl_->context, const_cast<xmlDoc*>(document->cobj()));
   if (res != 0)
@@ -170,7 +170,7 @@ void XsdValidator::validate(const Glib::ustring& filename)
     throw internal_error("XsdValidator::validate(): Could not create validating context");
 
   xmlResetLastError();
-  initialize_valid();
+  initialize_context();
 
   const int res = xmlSchemaValidateFile(pimpl_->context, filename.c_str(), 0);
   if (res != 0)
diff --git a/libxml++/validators/xsdvalidator.h b/libxml++/validators/xsdvalidator.h
index 9f784bb..2269afb 100644
--- a/libxml++/validators/xsdvalidator.h
+++ b/libxml++/validators/xsdvalidator.h
@@ -138,7 +138,7 @@ public:
   void validate(const Glib::ustring& filename) override;
 
 protected:
-  void initialize_valid() override;
+  void initialize_context() override;
   void release_underlying() override;
 
 private:


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