From javier.gutierrez at web.de Mon Nov 8 02:31:14 2021 From: javier.gutierrez at web.de (Javier Gutierrez) Date: Mon Nov 8 09:20:45 2021 Subject: [xsd-users] Core dump on xercesc_3_2::RefVectorOf::~RefVectorOf() Message-ID: <002d01d7d472$a0ed5e70$e2c81b50$@web.de> Hello Boris, I am trying to implement the embedded sample into my project. I have put the creation and loading of the grammar pool into the constructor of a class. Then the parsing of the XML into a member function. For that I have the grammar pool (xercesc::XMLGrammarPool) and the parser (xercesc::DOMLSParser) as private members If I don't have a destructor defined, everything runs fine. Once I define the destructor I get a core dump. Any idea how to overcome the problem? Environment: * Ubuntu 18.04 * xsd-4.0.0-x86_64-linux-gnu * Gcc 10.3.0 * Xercesc 3.2 Here the back-trace: Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) where #0 0x0000000000000000 in ?? () #1 0x00007ffff79d33a9 in xercesc_3_2::RefVectorOf::~RefVectorOf() () from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so #2 0x00007ffff79d30a9 in xercesc_3_2::DOMStringListImpl::~DOMStringListImpl() () from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so #3 0x00007ffff7a52c20 in xercesc_3_2::DOMLSParserImpl::~DOMLSParserImpl() () from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so #4 0x00007ffff7a52d09 in xercesc_3_2::DOMLSParserImpl::~DOMLSParserImpl() () from /usr/lib/x86_64-linux-gnu/libxerces-c-3.2.so #5 0x000055555555c5d7 in xsd::cxx::xml::dom::auto_ptr::reset (x=0x0, this=0x7fffffffdae8) at ../../../../libxsd/xsd/cxx/xml/dom/auto-ptr.hxx:216 #6 xsd::cxx::xml::dom::auto_ptr::~auto_ptr (this=0x7fffffffdae8, __in_chrg=) at ../../../../libxsd/xsd/cxx/xml/dom/auto-ptr.hxx:120 #7 XsdWrapper::~XsdWrapper (this=0x7fffffffdae0, __in_chrg=) at driver.cxx:191 #8 0x000055555555be27 in main (argc=, argv=0x7fffffffdb30) at driver.cxx:210 Here the driver.cxx adapted to recreate the problem: // file : examples/cxx/tree/embedded/driver.cxx // copyright : not copyrighted - public domain #include // std::auto_ptr #include #include #include #include // chLatin_* #include #include // xercesc::Grammar #include #include #include #include #include #include #include #include "library.hxx" #include "library-schema.hxx" #include "grammar-input-stream.hxx" using namespace std; class XsdWrapper { private: std::unique_ptr gp; xsd::cxx::xml::dom::auto_ptr parser; xsd::cxx::tree::error_handler eh; public: XsdWrapper() { // We need to initialize the Xerces-C++ runtime because we // are doing the XML-to-DOM parsing ourselves. // xercesc::XMLPlatformUtils::Initialize (); try { namespace xml = xsd::cxx::xml; // Create and load the grammar pool. // xercesc::MemoryManager* mm (xercesc::XMLPlatformUtils::fgMemoryManager); gp = std::make_unique (mm); try { grammar_input_stream is (library_schema, sizeof (library_schema)); gp->deserializeGrammars(&is); } catch(const xercesc::XSerializationException& e) { cerr << "unable to load schema: " << xml::transcode (e.getMessage ()) << endl; // return 1; } // Lock the grammar pool. This is necessary if we plan to use the // same grammar pool in multiple threads (this way we can reuse the // same grammar in multiple parsers). Locking the pool disallows any // modifications to the pool, such as an attempt by one of the threads // to cache additional schemas. // gp->lockPool (); // Get an implementation of the Load-Store (LS) interface. // const XMLCh ls_id [] = {xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull}; xercesc::DOMImplementation* impl ( xercesc::DOMImplementationRegistry::getDOMImplementation (ls_id)); parser.reset ( impl->createLSParser ( xercesc::DOMImplementationLS::MODE_SYNCHRONOUS, 0, mm, gp.get ())); xercesc::DOMConfiguration* conf (parser->getDomConfig ()); // Discard comment nodes in the document. // conf->setParameter (xercesc::XMLUni::fgDOMComments, false); // Enable datatype normalization. // conf->setParameter (xercesc::XMLUni::fgDOMDatatypeNormalization, true); // Do not create EntityReference nodes in the DOM tree. No // EntityReference nodes will be created, only the nodes // corresponding to their fully expanded substitution text // will be created. // conf->setParameter (xercesc::XMLUni::fgDOMEntities, false); // Perform namespace processing. // conf->setParameter (xercesc::XMLUni::fgDOMNamespaces, true); // Do not include ignorable whitespace in the DOM tree. // conf->setParameter (xercesc::XMLUni::fgDOMElementContentWhitespace, false); // Enable validation. // conf->setParameter (xercesc::XMLUni::fgDOMValidate, true); conf->setParameter (xercesc::XMLUni::fgXercesSchema, true); conf->setParameter (xercesc::XMLUni::fgXercesSchemaFullChecking, false); // Xerces-C++ 3.1.0 is the first version with working multi import // support. // #if _XERCES_VERSION >= 30100 conf->setParameter (xercesc::XMLUni::fgXercesHandleMultipleImports, true); #endif // Use the loaded grammar during parsing. // conf->setParameter (xercesc::XMLUni::fgXercesUseCachedGrammarInParse, true); // Disable loading schemas via other means (e.g., schemaLocation). // conf->setParameter (xercesc::XMLUni::fgXercesLoadSchema, false); // We will release the DOM document ourselves. // conf->setParameter (xercesc::XMLUni::fgXercesUserAdoptsDOMDocument, true); // Set error handler. // xml::dom::bits::error_handler_proxy ehp (eh); conf->setParameter (xercesc::XMLUni::fgDOMErrorHandler, &ehp); } catch (const xml_schema::exception& e) { cerr << e << endl; // r = 1; } } void parse(const std::string &inputFileName) { try { // Parse XML documents. // for (unsigned long i (0); i < 10; ++i) { ifstream ifs; ifs.exceptions (ifstream::badbit | ifstream::failbit); ifs.open (inputFileName); // Wrap the standard input stream. // xsd::cxx::xml::sax::std_input_source isrc (ifs, inputFileName); xercesc::Wrapper4InputSource wrap (&isrc, false); // Parse XML to DOM. // xml_schema::dom::auto_ptr doc (parser->parse (&wrap)); eh.throw_if_failed (); // Parse DOM to the object model. // auto_ptr c (library::catalog_ (*doc)); cerr << "catalog with " << c->book ().size () << " books" << endl; } } catch (const xml_schema::exception& e) { cerr << e << endl; // r = 1; } catch (const std::ios_base::failure&) { cerr << inputFileName << ": unable to open or read failure" << endl; // r = 1; } } ~XsdWrapper() { xercesc::XMLPlatformUtils::Terminate (); } }; int main (int argc, char* argv[]) { if (argc != 2) { cerr << "usage: " << argv[0] << " library.xml" << endl; return 1; } int r (0); XsdWrapper xsdWrapper; xsdWrapper.parse(argv[1]); return r; } Thanks and best regards, Javier Gutierrez -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 6009 bytes Desc: not available Url : https://codesynthesis.com/pipermail/xsd-users/attachments/20211108/f5082871/smime.bin From boris at codesynthesis.com Mon Nov 8 09:31:45 2021 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 8 09:29:38 2021 Subject: [xsd-users] Core dump on xercesc_3_2::RefVectorOf::~RefVectorOf() In-Reply-To: <002d01d7d472$a0ed5e70$e2c81b50$@web.de> References: <002d01d7d472$a0ed5e70$e2c81b50$@web.de> Message-ID: Javier Gutierrez writes: > class XsdWrapper > { > private: > std::unique_ptr gp; > xsd::cxx::xml::dom::auto_ptr parser; > xsd::cxx::tree::error_handler eh; > > [...] > > ~XsdWrapper() > { > xercesc::XMLPlatformUtils::Terminate (); > } Think in which order things will be destroyed here?