From 262362d4487e61981de1686cba658a906650d6c6 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Thu, 2 Mar 2017 06:43:27 +0300 Subject: [PATCH 01/13] tinyxml2 rev. 92c0ef327f --- libs/tinyxml2/tinyxml2.cpp | 48 +++++++++++--------------------------- libs/tinyxml2/tinyxml2.h | 31 +++++++++++++++++------- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 691ade7d6a..d3adddc2bd 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -678,46 +678,34 @@ char* XMLDocument::Identify( char* p, XMLNode** node ) TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool XMLNode* returnNode = 0; if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLDeclaration( this ); + returnNode = CreateUnlinkedNode( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; - returnNode->_memPool = &_commentPool; p += xmlHeaderLen; } else if ( XMLUtil::StringEqual( p, commentHeader, commentHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLComment( this ); + returnNode = CreateUnlinkedNode( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; - returnNode->_memPool = &_commentPool; p += commentHeaderLen; } else if ( XMLUtil::StringEqual( p, cdataHeader, cdataHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - XMLText* text = new (_textPool.Alloc()) XMLText( this ); + XMLText* text = CreateUnlinkedNode( _textPool ); returnNode = text; returnNode->_parseLineNum = _parseCurLineNum; - returnNode->_memPool = &_textPool; p += cdataHeaderLen; text->SetCData( true ); } else if ( XMLUtil::StringEqual( p, dtdHeader, dtdHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() ); - returnNode = new (_commentPool.Alloc()) XMLUnknown( this ); + returnNode = CreateUnlinkedNode( _commentPool ); returnNode->_parseLineNum = _parseCurLineNum; - returnNode->_memPool = &_commentPool; p += dtdHeaderLen; } else if ( XMLUtil::StringEqual( p, elementHeader, elementHeaderLen ) ) { - TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() ); - returnNode = new (_elementPool.Alloc()) XMLElement( this ); + returnNode = CreateUnlinkedNode( _elementPool ); returnNode->_parseLineNum = _parseCurLineNum; - returnNode->_memPool = &_elementPool; p += elementHeaderLen; } else { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - returnNode = new (_textPool.Alloc()) XMLText( this ); - returnNode->_memPool = &_textPool; + returnNode = CreateUnlinkedNode( _textPool ); returnNode->_parseLineNum = _parseCurLineNum; // Report line of first non-whitespace character p = start; // Back it up, all the text counts. _parseCurLineNum = startLine; @@ -2007,7 +1995,7 @@ void XMLDocument::Clear() _commentPool.Trace( "comment" ); _attributePool.Trace( "attribute" ); #endif - + #ifdef DEBUG if ( !hadError ) { TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); @@ -2021,9 +2009,7 @@ void XMLDocument::Clear() XMLElement* XMLDocument::NewElement( const char* name ) { - TIXMLASSERT( sizeof( XMLElement ) == _elementPool.ItemSize() ); - XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this ); - ele->_memPool = &_elementPool; + XMLElement* ele = CreateUnlinkedNode( _elementPool ); ele->SetName( name ); return ele; } @@ -2031,9 +2017,7 @@ XMLElement* XMLDocument::NewElement( const char* name ) XMLComment* XMLDocument::NewComment( const char* str ) { - TIXMLASSERT( sizeof( XMLComment ) == _commentPool.ItemSize() ); - XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this ); - comment->_memPool = &_commentPool; + XMLComment* comment = CreateUnlinkedNode( _commentPool ); comment->SetValue( str ); return comment; } @@ -2041,9 +2025,7 @@ XMLComment* XMLDocument::NewComment( const char* str ) XMLText* XMLDocument::NewText( const char* str ) { - TIXMLASSERT( sizeof( XMLText ) == _textPool.ItemSize() ); - XMLText* text = new (_textPool.Alloc()) XMLText( this ); - text->_memPool = &_textPool; + XMLText* text = CreateUnlinkedNode( _textPool ); text->SetValue( str ); return text; } @@ -2051,9 +2033,7 @@ XMLText* XMLDocument::NewText( const char* str ) XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) { - TIXMLASSERT( sizeof( XMLDeclaration ) == _commentPool.ItemSize() ); - XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this ); - dec->_memPool = &_commentPool; + XMLDeclaration* dec = CreateUnlinkedNode( _commentPool ); dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); return dec; } @@ -2061,9 +2041,7 @@ XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) XMLUnknown* XMLDocument::NewUnknown( const char* str ) { - TIXMLASSERT( sizeof( XMLUnknown ) == _commentPool.ItemSize() ); - XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this ); - unk->_memPool = &_commentPool; + XMLUnknown* unk = CreateUnlinkedNode( _commentPool ); unk->SetValue( str ); return unk; } @@ -2255,7 +2233,7 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2, { TIXMLASSERT( error >= 0 && error < XML_ERROR_COUNT ); _errorID = error; - + _errorStr1.Reset(); _errorStr2.Reset(); _errorLineNum = lineNum; diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 61420e15d4..55a22d9ec1 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -549,7 +549,7 @@ class TINYXML2_LIB XMLUtil // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't // correct, but simple, and usually works. static bool IsWhiteSpace( char p ) { - return !IsUTF8Continuation(p) && std::isspace( static_cast(p) ); + return !IsUTF8Continuation(p) && isspace( static_cast(p) ); } inline static bool IsNameStartChar( unsigned char ch ) { @@ -565,7 +565,7 @@ class TINYXML2_LIB XMLUtil inline static bool IsNameChar( unsigned char ch ) { return IsNameStartChar( ch ) - || std::isdigit( ch ) + || isdigit( ch ) || ch == '.' || ch == '-'; } @@ -1646,7 +1646,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode /** Load an XML file from disk. You are responsible - for providing and closing the FILE*. + for providing and closing the FILE*. NOTE: The file should be opened as binary ("rb") not text in order for TinyXML-2 to correctly @@ -1655,7 +1655,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode Returns XML_SUCCESS (0) on success, or an errorID. */ - XMLError LoadFile( std::FILE* ); + XMLError LoadFile( FILE* ); /** Save the XML file to disk. @@ -1671,7 +1671,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode Returns XML_SUCCESS (0) on success, or an errorID. */ - XMLError SaveFile( std::FILE* fp, bool compact = false ); + XMLError SaveFile( FILE* fp, bool compact = false ); bool ProcessEntities() const { return _processEntities; @@ -1794,7 +1794,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode } /// If there is an error, print it to stdout. void PrintError() const; - + /// Clear the document, resetting it to the initial state. void Clear(); @@ -1830,8 +1830,21 @@ class TINYXML2_LIB XMLDocument : public XMLNode static const char* _errorNames[XML_ERROR_COUNT]; void Parse(); + + template + NodeType* CreateUnlinkedNode( MemPoolT& pool ); }; +template +inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT& pool ) +{ + TIXMLASSERT( sizeof( NodeType ) == PoolElementSize ); + TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() ); + NodeType* returnNode = new (pool.Alloc()) NodeType( this ); + TIXMLASSERT( returnNode ); + returnNode->_memPool = &pool; + return returnNode; +} /** A XMLHandle is a class that wraps a node pointer with null checks; this is @@ -2088,7 +2101,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor If 'compact' is set to true, then output is created with only required whitespace and newlines. */ - XMLPrinter( std::FILE* file=0, bool compact = false, int depth = 0 ); + XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 ); virtual ~XMLPrinter() {} /** If streaming, write the BOM and declaration. */ @@ -2101,7 +2114,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void PushAttribute( const char* name, const char* value ); void PushAttribute( const char* name, int value ); void PushAttribute( const char* name, unsigned value ); - void PushAttribute( const char* name, int64_t value ); + void PushAttribute(const char* name, int64_t value); void PushAttribute( const char* name, bool value ); void PushAttribute( const char* name, double value ); /// If streaming, close the Element. @@ -2182,7 +2195,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. bool _firstElement; - std::FILE* _fp; + FILE* _fp; int _depth; int _textDepth; bool _processEntities; From 0047265f950a5d0abe7ba7f21241a823f929e61e Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Wed, 8 Mar 2017 05:52:00 +0300 Subject: [PATCH 02/13] tinyxml2 rev. 395ea09f83 --- libs/tinyxml2/tinyxml2.cpp | 5 +++-- libs/tinyxml2/tinyxml2.h | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index d3adddc2bd..87c1a99f68 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -1838,6 +1838,7 @@ XMLAttribute* XMLElement::CreateAttribute() { TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); + TIXMLASSERT( attrib ); attrib->_memPool = &_document->_attributePool; attrib->_memPool->SetTracked(); return attrib; @@ -1956,12 +1957,12 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { }; -XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : +XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : XMLNode( 0 ), _writeBOM( false ), _processEntities( processEntities ), _errorID(XML_SUCCESS), - _whitespace( whitespace ), + _whitespaceMode( whitespaceMode ), _errorLineNum( 0 ), _charBuffer( 0 ), _parseCurLineNum( 0 ) diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 55a22d9ec1..bfd2204d20 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -1613,7 +1613,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode friend class XMLElement; public: /// constructor - XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ); + XMLDocument( bool processEntities = true, Whitespace whitespaceMode = PRESERVE_WHITESPACE ); ~XMLDocument(); virtual XMLDocument* ToDocument() { @@ -1677,7 +1677,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode return _processEntities; } Whitespace WhitespaceMode() const { - return _whitespace; + return _whitespaceMode; } /** @@ -1815,7 +1815,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode bool _writeBOM; bool _processEntities; XMLError _errorID; - Whitespace _whitespace; + Whitespace _whitespaceMode; mutable StrPair _errorStr1; mutable StrPair _errorStr2; int _errorLineNum; From 53c9dacd4b995761fff4b8e03ddce181aaf34b60 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Fri, 7 Apr 2017 07:02:45 +0300 Subject: [PATCH 03/13] tinyxml2 rev. 2b0453f43e --- libs/tinyxml2/tinyxml2.cpp | 5 +++-- libs/tinyxml2/tinyxml2.h | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 87c1a99f68..0d6e2bc20c 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -1133,6 +1133,7 @@ XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const bool XMLText::ShallowEqual( const XMLNode* compare ) const { + TIXMLASSERT( compare ); const XMLText* text = compare->ToText(); return ( text && XMLUtil::StringEqual( text->Value(), Value() ) ); } @@ -1448,7 +1449,7 @@ void XMLAttribute::SetAttribute( float v ) // --------- XMLElement ---------- // XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), - _closingType( 0 ), + _closingType( OPEN ), _rootAttribute( 0 ) { } @@ -1867,7 +1868,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair, int* curLineNumPtr ) } p = ParseAttributes( p, curLineNumPtr ); - if ( !p || !*p || _closingType ) { + if ( !p || !*p || _closingType != OPEN ) { return p; } diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index bfd2204d20..17e576a61a 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -1559,12 +1559,12 @@ class TINYXML2_LIB XMLElement : public XMLNode float FloatText(float defaultValue = 0) const; // internal: - enum { + enum ElementClosingType { OPEN, // CLOSED, // CLOSING // }; - int ClosingType() const { + ElementClosingType ClosingType() const { return _closingType; } virtual XMLNode* ShallowClone( XMLDocument* document ) const; @@ -1589,7 +1589,7 @@ class TINYXML2_LIB XMLElement : public XMLNode XMLAttribute* CreateAttribute(); enum { BUF_SIZE = 200 }; - int _closingType; + ElementClosingType _closingType; // The attribute list is ordered; there is no 'lastAttribute' // because the list needs to be scanned for dupes before adding // a new attribute. From 8b181219266467f0b57b63cf03916d32e8dd6002 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Thu, 20 Apr 2017 09:46:16 +0300 Subject: [PATCH 04/13] tinyxml2 rev. b840b7e673 --- libs/tinyxml2/tinyxml2.cpp | 10 +++++----- libs/tinyxml2/tinyxml2.h | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 0d6e2bc20c..152e3d22de 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -955,7 +955,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const } -char* XMLNode::ParseDeep( char* p, StrPair* parentEnd, int* curLineNumPtr ) +char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // This is a recursive method, but thinking about it "at the current level" // it is a pretty simple flat list: @@ -1020,8 +1020,8 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd, int* curLineNumPtr ) if ( ele ) { // We read the end tag. Return it to the parent. if ( ele->ClosingType() == XMLElement::CLOSING ) { - if ( parentEnd ) { - ele->_value.TransferTo( parentEnd ); + if ( parentEndTag ) { + ele->_value.TransferTo( parentEndTag ); } node->_memPool->SetTracked(); // created and then immediately deleted. DeleteNode( node ); @@ -1849,7 +1849,7 @@ XMLAttribute* XMLElement::CreateAttribute() // // foobar // -char* XMLElement::ParseDeep( char* p, StrPair* strPair, int* curLineNumPtr ) +char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) { // Read the element name. p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr ); @@ -1872,7 +1872,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* strPair, int* curLineNumPtr ) return p; } - p = XMLNode::ParseDeep( p, strPair, curLineNumPtr ); + p = XMLNode::ParseDeep( p, parentEndTag, curLineNumPtr ); return p; } diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 17e576a61a..087b551d47 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -907,7 +907,7 @@ class TINYXML2_LIB XMLNode XMLNode( XMLDocument* ); virtual ~XMLNode(); - virtual char* ParseDeep( char*, StrPair*, int* ); + virtual char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); XMLDocument* _document; XMLNode* _parent; @@ -975,7 +975,7 @@ class TINYXML2_LIB XMLText : public XMLNode XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} virtual ~XMLText() {} - char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: bool _isCData; @@ -1006,7 +1006,7 @@ class TINYXML2_LIB XMLComment : public XMLNode XMLComment( XMLDocument* doc ); virtual ~XMLComment(); - char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr); private: XMLComment( const XMLComment& ); // not supported @@ -1045,7 +1045,7 @@ class TINYXML2_LIB XMLDeclaration : public XMLNode XMLDeclaration( XMLDocument* doc ); virtual ~XMLDeclaration(); - char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLDeclaration( const XMLDeclaration& ); // not supported @@ -1080,7 +1080,7 @@ class TINYXML2_LIB XMLUnknown : public XMLNode XMLUnknown( XMLDocument* doc ); virtual ~XMLUnknown(); - char* ParseDeep( char*, StrPair* endTag, int* curLineNumPtr ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLUnknown( const XMLUnknown& ); // not supported @@ -1571,7 +1571,7 @@ class TINYXML2_LIB XMLElement : public XMLNode virtual bool ShallowEqual( const XMLNode* compare ) const; protected: - char* ParseDeep( char* p, StrPair* endTag, int* curLineNumPtr ); + char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ); private: XMLElement( XMLDocument* doc ); From 83955a0464e59c1fce9dddb8475a3372e9a939b4 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Thu, 15 Jun 2017 07:20:44 +0300 Subject: [PATCH 05/13] tinyxml2 rev. e84f68a68a --- libs/tinyxml2/tinyxml2.cpp | 34 +++++++++++++++++++++++++++++++--- libs/tinyxml2/tinyxml2.h | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 152e3d22de..3182c5ae8f 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -797,9 +797,11 @@ void XMLNode::Unlink( XMLNode* child ) if ( child->_prev ) { child->_prev->_next = child->_next; + child->_prev = 0; } if ( child->_next ) { child->_next->_prev = child->_prev; + child->_next = 0; } child->_parent = 0; } @@ -811,6 +813,9 @@ void XMLNode::DeleteChild( XMLNode* node ) TIXMLASSERT( node->_document == _document ); TIXMLASSERT( node->_parent == this ); Unlink( node ); + TIXMLASSERT(node->_prev == 0); + TIXMLASSERT(node->_next == 0); + TIXMLASSERT(node->_parent == 0); DeleteNode( node ); } @@ -1055,11 +1060,16 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) return 0; } -void XMLNode::DeleteNode( XMLNode* node ) +/*static*/ void XMLNode::DeleteNode( XMLNode* node ) { if ( node == 0 ) { return; } + TIXMLASSERT(node->_document); + if (!node->ToDocument()) { + node->_document->MarkInUse(node); + } + MemPool* pool = node->_memPool; node->~XMLNode(); pool->Free( node ); @@ -1070,10 +1080,13 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const TIXMLASSERT( insertThis ); TIXMLASSERT( insertThis->_document == _document ); - if ( insertThis->_parent ) + if (insertThis->_parent) { insertThis->_parent->Unlink( insertThis ); - else + } + else { + insertThis->_document->MarkInUse(insertThis); insertThis->_memPool->SetTracked(); + } } const XMLElement* XMLNode::ToElementWithName( const char* name ) const @@ -1979,9 +1992,24 @@ XMLDocument::~XMLDocument() } +void XMLDocument::MarkInUse(XMLNode* node) +{ + TIXMLASSERT(node->_parent == 0); + + for (int i = 0; i < _unlinked.Size(); ++i) { + if (node == _unlinked[i]) { + _unlinked.SwapRemove(i); + break; + } + } +} + void XMLDocument::Clear() { DeleteChildren(); + while( _unlinked.Size()) { + DeleteNode(_unlinked[0]); // Will remove from _unlinked as part of delete. + } #ifdef DEBUG const bool hadError = Error(); diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 087b551d47..864c8b9d86 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -264,6 +264,13 @@ class DynArray return _allocated; } + void SwapRemove(int i) { + TIXMLASSERT(i >= 0); + TIXMLASSERT(i < _size); + _mem[i] = _mem[_size - 1]; + --_size; + } + const T* Mem() const { TIXMLASSERT( _mem ); return _mem; @@ -284,6 +291,7 @@ class DynArray TIXMLASSERT( cap <= INT_MAX / 2 ); int newAllocated = cap * 2; T* newMem = new T[newAllocated]; + TIXMLASSERT( newAllocated >= _size ); memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs if ( _mem != _pool ) { delete [] _mem; @@ -1801,6 +1809,9 @@ class TINYXML2_LIB XMLDocument : public XMLNode // internal char* Identify( char* p, XMLNode** node ); + // internal + void MarkInUse(XMLNode*); + virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { return 0; } @@ -1821,6 +1832,13 @@ class TINYXML2_LIB XMLDocument : public XMLNode int _errorLineNum; char* _charBuffer; int _parseCurLineNum; + // Memory tracking does add some overhead. + // However, the code assumes that you don't + // have a bunch of unlinked nodes around. + // Therefore it takes less memory to track + // in the document vs. a linked list in the XMLNode, + // and the performance is the same. + DynArray _unlinked; MemPoolT< sizeof(XMLElement) > _elementPool; MemPoolT< sizeof(XMLAttribute) > _attributePool; @@ -1843,6 +1861,8 @@ inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT& poo NodeType* returnNode = new (pool.Alloc()) NodeType( this ); TIXMLASSERT( returnNode ); returnNode->_memPool = &pool; + + _unlinked.Push(returnNode); return returnNode; } @@ -2176,6 +2196,7 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor void ClearBuffer() { _buffer.Clear(); _buffer.Push(0); + _firstElement = true; } protected: From aa2a769d4948e6496bb8387b9e409f3cc2f3ac5a Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Sat, 17 Jun 2017 10:28:23 +0300 Subject: [PATCH 06/13] tinyxml2 rev. 9e2d29b373 --- libs/tinyxml2/tinyxml2.cpp | 30 ++++++++++++++++++++++++++++-- libs/tinyxml2/tinyxml2.h | 32 ++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 3182c5ae8f..603be82c3a 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -772,6 +772,18 @@ void XMLNode::SetValue( const char* str, bool staticMem ) } } +XMLNode* XMLNode::DeepClone(XMLDocument* document) const +{ + XMLNode* clone = this->ShallowClone(document); + if (!clone) return 0; + + for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { + XMLNode* childClone = child->DeepClone(document); + TIXMLASSERT(childClone); + clone->InsertEndChild(childClone); + } + return clone; +} void XMLNode::DeleteChildren() { @@ -797,12 +809,12 @@ void XMLNode::Unlink( XMLNode* child ) if ( child->_prev ) { child->_prev->_next = child->_next; - child->_prev = 0; } if ( child->_next ) { child->_next->_prev = child->_prev; - child->_next = 0; } + child->_next = 0; + child->_prev = 0; child->_parent = 0; } @@ -1994,6 +2006,7 @@ XMLDocument::~XMLDocument() void XMLDocument::MarkInUse(XMLNode* node) { + TIXMLASSERT(node); TIXMLASSERT(node->_parent == 0); for (int i = 0; i < _unlinked.Size(); ++i) { @@ -2037,6 +2050,19 @@ void XMLDocument::Clear() } +void XMLDocument::DeepCopy(XMLDocument* target) +{ + TIXMLASSERT(target); + if (target == this) { + return; // technically success - a no-op. + } + + target->Clear(); + for (const XMLNode* node = this->FirstChild(); node; node = node->NextSibling()) { + target->InsertEndChild(node->DeepClone(target)); + } +} + XMLElement* XMLDocument::NewElement( const char* name ) { XMLElement* ele = CreateUnlinkedNode( _elementPool ); diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 864c8b9d86..3465f2f154 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -53,7 +53,7 @@ distribution. AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h */ -#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) +#if defined( _DEBUG ) || defined (__DEBUG__) # ifndef DEBUG # define DEBUG # endif @@ -265,8 +265,8 @@ class DynArray } void SwapRemove(int i) { - TIXMLASSERT(i >= 0); - TIXMLASSERT(i < _size); + TIXMLASSERT(i >= 0 && i < _size); + TIXMLASSERT(_size > 0); _mem[i] = _mem[_size - 1]; --_size; } @@ -865,6 +865,21 @@ class TINYXML2_LIB XMLNode */ virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; + /** + Make a copy of this node and all its children. + + If the 'document' is null, then the nodes will + be allocated in the current document. If document + is specified, the memory will be allocated is the + specified XMLDocument. + + NOTE: This is probably not the correct tool to + copy a document, since XMLDocuments can have multiple + top level XMLNodes. You probably want to use + XMLDocument::DeepCopy() + */ + XMLNode* DeepClone( XMLDocument* document ) const; + /** Test if 2 nodes are the same, but don't test children. The 2 nodes do not need to be in the same Document. @@ -1806,7 +1821,16 @@ class TINYXML2_LIB XMLDocument : public XMLNode /// Clear the document, resetting it to the initial state. void Clear(); - // internal + /** + Copies this document to a target document. + The target will be completely cleared before the copy. + If you want to copy a sub-tree, see XMLNode::DeepClone(). + + NOTE: that the 'target' must be non-null. + */ + void DeepCopy(XMLDocument* target); + + // internal char* Identify( char* p, XMLNode** node ); // internal From 3c4d1ac45f33e922856866a29f18511d6d85e771 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Thu, 22 Jun 2017 13:24:01 +0300 Subject: [PATCH 07/13] tinyxml2 rev. 369f306b37 --- libs/tinyxml2/tinyxml2.cpp | 10 +++++----- libs/tinyxml2/tinyxml2.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 603be82c3a..d14089fb0e 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -772,13 +772,13 @@ void XMLNode::SetValue( const char* str, bool staticMem ) } } -XMLNode* XMLNode::DeepClone(XMLDocument* document) const +XMLNode* XMLNode::DeepClone(XMLDocument* target) const { - XMLNode* clone = this->ShallowClone(document); + XMLNode* clone = this->ShallowClone(target); if (!clone) return 0; for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) { - XMLNode* childClone = child->DeepClone(document); + XMLNode* childClone = child->DeepClone(target); TIXMLASSERT(childClone); clone->InsertEndChild(childClone); } @@ -1966,10 +1966,10 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = { "XML_ERROR_FILE_NOT_FOUND", "XML_ERROR_FILE_COULD_NOT_BE_OPENED", "XML_ERROR_FILE_READ_ERROR", - "XML_ERROR_ELEMENT_MISMATCH", + "UNUSED_XML_ERROR_ELEMENT_MISMATCH", "XML_ERROR_PARSING_ELEMENT", "XML_ERROR_PARSING_ATTRIBUTE", - "XML_ERROR_IDENTIFYING_TAG", + "UNUSED_XML_ERROR_IDENTIFYING_TAG", "XML_ERROR_PARSING_TEXT", "XML_ERROR_PARSING_CDATA", "XML_ERROR_PARSING_COMMENT", diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 3465f2f154..2b80a37ed4 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -513,10 +513,10 @@ enum XMLError { XML_ERROR_FILE_NOT_FOUND, XML_ERROR_FILE_COULD_NOT_BE_OPENED, XML_ERROR_FILE_READ_ERROR, - XML_ERROR_ELEMENT_MISMATCH, + UNUSED_XML_ERROR_ELEMENT_MISMATCH, // remove at next major version XML_ERROR_PARSING_ELEMENT, XML_ERROR_PARSING_ATTRIBUTE, - XML_ERROR_IDENTIFYING_TAG, + UNUSED_XML_ERROR_IDENTIFYING_TAG, // remove at next major version XML_ERROR_PARSING_TEXT, XML_ERROR_PARSING_CDATA, XML_ERROR_PARSING_COMMENT, @@ -868,8 +868,8 @@ class TINYXML2_LIB XMLNode /** Make a copy of this node and all its children. - If the 'document' is null, then the nodes will - be allocated in the current document. If document + If the 'target' is null, then the nodes will + be allocated in the current document. If 'target' is specified, the memory will be allocated is the specified XMLDocument. @@ -878,7 +878,7 @@ class TINYXML2_LIB XMLNode top level XMLNodes. You probably want to use XMLDocument::DeepCopy() */ - XMLNode* DeepClone( XMLDocument* document ) const; + XMLNode* DeepClone( XMLDocument* target ) const; /** Test if 2 nodes are the same, but don't test children. From cdd535960cde0a7f99b58928369f8a797d882633 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Wed, 28 Jun 2017 07:02:59 +0300 Subject: [PATCH 08/13] tinyxml2 rev. 37bc3aca42 --- libs/tinyxml2/tinyxml2.cpp | 10 ++++++++++ libs/tinyxml2/tinyxml2.h | 12 +++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index d14089fb0e..3043ab3a4f 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -2308,6 +2308,16 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2, return errorName; } +const char* XMLDocument::GetErrorStr1() const +{ + return _errorStr1.GetStr(); +} + +const char* XMLDocument::GetErrorStr2() const +{ + return _errorStr2.GetStr(); +} + const char* XMLDocument::ErrorName() const { return ErrorIDToName(_errorID); diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index 2b80a37ed4..e6a0ced1fb 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -98,7 +98,7 @@ distribution. /* Versioning, past 1.0.14: http://semver.org/ */ -static const int TIXML2_MAJOR_VERSION = 4; +static const int TIXML2_MAJOR_VERSION = 5; static const int TIXML2_MINOR_VERSION = 0; static const int TIXML2_PATCH_VERSION = 1; @@ -1803,13 +1803,11 @@ class TINYXML2_LIB XMLDocument : public XMLNode static const char* ErrorIDToName(XMLError errorID); /// Return a possibly helpful diagnostic location or string. - const char* GetErrorStr1() const { - return _errorStr1.GetStr(); - } + const char* GetErrorStr1() const; + /// Return a possibly helpful secondary diagnostic location or string. - const char* GetErrorStr2() const { - return _errorStr2.GetStr(); - } + const char* GetErrorStr2() const; + /// Return the line where the error occured, or zero if unknown. int GetErrorLineNum() const { From 743ebee0794b1642290a14488252806bf7051950 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Sat, 29 Jul 2017 12:42:29 +0300 Subject: [PATCH 09/13] tinyxml2 rev. 02d2764fd7 --- libs/tinyxml2/tinyxml2.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index e6a0ced1fb..a372b413bc 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -341,8 +341,8 @@ class MemPoolT : public MemPool void Clear() { // Delete the blocks. while( !_blockPtrs.Empty()) { - Block* b = _blockPtrs.Pop(); - delete b; + Block* lastBlock = _blockPtrs.Pop(); + delete lastBlock; } _root = 0; _currentAllocs = 0; From 09c5518287f8e06b10669be4d46a9b09b51e0d77 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Tue, 8 Aug 2017 07:09:45 +0300 Subject: [PATCH 10/13] tinxml2 rev. c11a7c5ca0 --- libs/tinyxml2/tinyxml2.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 3043ab3a4f..8a3f857faa 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -424,20 +424,24 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length output += *length; - // Scary scary fall throughs. + // Scary scary fall throughs are annotated with carefully designed comments + // to suppress compiler warnings such as -Wimplicit-fallthrough in gcc switch (*length) { case 4: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 3: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 2: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; + //fall through case 1: --output; *output = (char)(input | FIRST_BYTE_MARK[*length]); From 8664ae7fce7102ed322f8ac9c2fc053995de4e59 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Sat, 26 Aug 2017 07:32:12 +0300 Subject: [PATCH 11/13] tinxml2 rev. d69e2c0d08 --- libs/tinyxml2/tinyxml2.cpp | 2 +- libs/tinyxml2/tinyxml2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 8a3f857faa..5cdedbbe3f 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -2054,7 +2054,7 @@ void XMLDocument::Clear() } -void XMLDocument::DeepCopy(XMLDocument* target) +void XMLDocument::DeepCopy(XMLDocument* target) const { TIXMLASSERT(target); if (target == this) { diff --git a/libs/tinyxml2/tinyxml2.h b/libs/tinyxml2/tinyxml2.h index a372b413bc..7b5bb0ebd0 100644 --- a/libs/tinyxml2/tinyxml2.h +++ b/libs/tinyxml2/tinyxml2.h @@ -1826,7 +1826,7 @@ class TINYXML2_LIB XMLDocument : public XMLNode NOTE: that the 'target' must be non-null. */ - void DeepCopy(XMLDocument* target); + void DeepCopy(XMLDocument* target) const; // internal char* Identify( char* p, XMLNode** node ); From 461ba845a6067550a297e9572f83ab034b30b777 Mon Sep 17 00:00:00 2001 From: Michael Lukashov Date: Wed, 30 Aug 2017 07:11:58 +0300 Subject: [PATCH 12/13] tinxml2 rev. 4b173cbcf1 --- libs/tinyxml2/tinyxml2.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index 5cdedbbe3f..a8a4a2069f 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -2380,8 +2380,9 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : } for( int i=0; i Date: Sun, 22 Oct 2017 08:31:55 +0300 Subject: [PATCH 13/13] tinxml2 rev. 8b83b23876 --- libs/tinyxml2/tinyxml2.cpp | 21 +++++++++++++++++++-- libs/tinyxml2/tinyxml2.h | 35 +++++++++++++++++------------------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/libs/tinyxml2/tinyxml2.cpp b/libs/tinyxml2/tinyxml2.cpp index a8a4a2069f..953debf547 100644 --- a/libs/tinyxml2/tinyxml2.cpp +++ b/libs/tinyxml2/tinyxml2.cpp @@ -741,6 +741,7 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const XMLNode::XMLNode( XMLDocument* doc ) : _document( doc ), _parent( 0 ), + _value(), _parseLineNum( 0 ), _firstChild( 0 ), _lastChild( 0 ), _prev( 0 ), _next( 0 ), @@ -911,6 +912,13 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ) TIXMLASSERT( false ); return 0; } + if ( afterThis == addThis ) { + // Current state: BeforeThis -> AddThis -> OneAfterAddThis + // Now AddThis must disappear from it's location and then + // reappear between BeforeThis and OneAfterAddThis. + // So just leave it where it is. + return addThis; + } if ( afterThis->_next == 0 ) { // The last node or the only node. @@ -1993,9 +2001,16 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) : _processEntities( processEntities ), _errorID(XML_SUCCESS), _whitespaceMode( whitespaceMode ), + _errorStr1(), + _errorStr2(), _errorLineNum( 0 ), _charBuffer( 0 ), - _parseCurLineNum( 0 ) + _parseCurLineNum( 0 ), + _unlinked(), + _elementPool(), + _attributePool(), + _textPool(), + _commentPool() { // avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+) _document = this; @@ -2367,12 +2382,14 @@ void XMLDocument::Parse() XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) : _elementJustOpened( false ), + _stack(), _firstElement( true ), _fp( file ), _depth( depth ), _textDepth( -1 ), _processEntities( true ), - _compactMode( compact ) + _compactMode( compact ), + _buffer() { for( int i=0; i class DynArray { public: - DynArray() { - _mem = _pool; - _allocated = INITIAL_SIZE; - _size = 0; + DynArray() : + _mem( _pool ), + _allocated( INITIAL_SIZE ), + _size( 0 ) + { } ~DynArray() { @@ -333,7 +334,7 @@ template< int ITEM_SIZE > class MemPoolT : public MemPool { public: - MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} + MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} ~MemPoolT() { Clear(); } @@ -1211,7 +1212,7 @@ class TINYXML2_LIB XMLAttribute private: enum { BUF_SIZE = 200 }; - XMLAttribute() : _parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} + XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {} virtual ~XMLAttribute() {} XMLAttribute( const XMLAttribute& ); // not supported @@ -1947,16 +1948,13 @@ class TINYXML2_LIB XMLHandle { public: /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - XMLHandle( XMLNode* node ) { - _node = node; + XMLHandle( XMLNode* node ) : _node( node ) { } /// Create a handle from a node. - XMLHandle( XMLNode& node ) { - _node = &node; + XMLHandle( XMLNode& node ) : _node( &node ) { } /// Copy constructor - XMLHandle( const XMLHandle& ref ) { - _node = ref._node; + XMLHandle( const XMLHandle& ref ) : _node( ref._node ) { } /// Assignment XMLHandle& operator=( const XMLHandle& ref ) { @@ -2030,14 +2028,11 @@ class TINYXML2_LIB XMLHandle class TINYXML2_LIB XMLConstHandle { public: - XMLConstHandle( const XMLNode* node ) { - _node = node; + XMLConstHandle( const XMLNode* node ) : _node( node ) { } - XMLConstHandle( const XMLNode& node ) { - _node = &node; + XMLConstHandle( const XMLNode& node ) : _node( &node ) { } - XMLConstHandle( const XMLConstHandle& ref ) { - _node = ref._node; + XMLConstHandle( const XMLConstHandle& ref ) : _node( ref._node ) { } XMLConstHandle& operator=( const XMLConstHandle& ref ) { @@ -2252,6 +2247,10 @@ class TINYXML2_LIB XMLPrinter : public XMLVisitor bool _restrictedEntityFlag[ENTITY_RANGE]; DynArray< char, 20 > _buffer; + + // Prohibit cloning, intentionally not implemented + XMLPrinter( const XMLPrinter& ); + XMLPrinter& operator=( const XMLPrinter& ); };