fix issue 184. clean up xcode project.

This commit is contained in:
Lee Thomason 2014-10-30 13:25:12 -07:00
parent d211bb1351
commit f07b952296
4 changed files with 68 additions and 25 deletions

View File

@ -1623,24 +1623,7 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
XMLDocument::~XMLDocument() XMLDocument::~XMLDocument()
{ {
DeleteChildren(); Clear();
delete [] _charBuffer;
#if 0
_textPool.Trace( "text" );
_elementPool.Trace( "element" );
_commentPool.Trace( "comment" );
_attributePool.Trace( "attribute" );
#endif
#ifdef DEBUG
if ( Error() == false ) {
TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() );
TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() );
TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() );
TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() );
}
#endif
} }
@ -1654,6 +1637,22 @@ void XMLDocument::Clear()
delete [] _charBuffer; delete [] _charBuffer;
_charBuffer = 0; _charBuffer = 0;
#if 0
_textPool.Trace( "text" );
_elementPool.Trace( "element" );
_commentPool.Trace( "comment" );
_attributePool.Trace( "attribute" );
#endif
#ifdef DEBUG
if ( Error() == false ) {
TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() );
TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() );
TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() );
TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() );
}
#endif
} }
@ -1821,6 +1820,16 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
ptrdiff_t delta = p - start; // skip initial whitespace, BOM, etc. ptrdiff_t delta = p - start; // skip initial whitespace, BOM, etc.
ParseDeep( _charBuffer+delta, 0 ); ParseDeep( _charBuffer+delta, 0 );
if (_errorID) {
// clean up now essentially dangling memory.
// and the parse fail can put objects in the
// pools that are dead and inaccessible.
DeleteChildren();
_elementPool.Clear();
_attributePool.Clear();
_textPool.Clear();
_commentPool.Clear();
}
return _errorID; return _errorID;
} }

View File

@ -122,9 +122,9 @@ inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
/* Versioning, past 1.0.14: /* Versioning, past 1.0.14:
http://semver.org/ http://semver.org/
*/ */
static const int TIXML2_MAJOR_VERSION = 2; static const int TIXML2_MAJOR_VERSION = 2;
static const int TIXML2_MINOR_VERSION = 2; static const int TIXML2_MINOR_VERSION = 2;
static const int TIXML2_PATCH_VERSION = 0; static const int TIXML2_PATCH_VERSION = 0;
namespace tinyxml2 namespace tinyxml2
{ {
@ -261,7 +261,7 @@ public:
return _mem[i]; return _mem[i];
} }
const T& PeekTop() const { const T& PeekTop() const {
TIXMLASSERT( _size > 0 ); TIXMLASSERT( _size > 0 );
return _mem[ _size - 1]; return _mem[ _size - 1];
} }
@ -317,6 +317,7 @@ public:
virtual void* Alloc() = 0; virtual void* Alloc() = 0;
virtual void Free( void* ) = 0; virtual void Free( void* ) = 0;
virtual void SetTracked() = 0; virtual void SetTracked() = 0;
virtual void Clear() = 0;
}; };
@ -329,10 +330,20 @@ class MemPoolT : public MemPool
public: public:
MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
~MemPoolT() { ~MemPoolT() {
Clear();
}
void Clear() {
// Delete the blocks. // Delete the blocks.
for( int i=0; i<_blockPtrs.Size(); ++i ) { while( !_blockPtrs.Empty()) {
delete _blockPtrs[i]; Block* b = _blockPtrs.Pop();
delete b;
} }
_root = 0;
_currentAllocs = 0;
_nAllocs = 0;
_maxAllocs = 0;
_nUntracked = 0;
} }
virtual int ItemSize() const { virtual int ItemSize() const {
@ -365,6 +376,7 @@ public:
_nUntracked++; _nUntracked++;
return result; return result;
} }
virtual void Free( void* mem ) { virtual void Free( void* mem ) {
if ( !mem ) { if ( !mem ) {
return; return;

View File

@ -96,6 +96,9 @@
/* Begin PBXProject section */ /* Begin PBXProject section */
037AE058151CCC5200E0F29F /* Project object */ = { 037AE058151CCC5200E0F29F /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
};
buildConfigurationList = 037AE05B151CCC5200E0F29F /* Build configuration list for PBXProject "tinyxml2" */; buildConfigurationList = 037AE05B151CCC5200E0F29F /* Build configuration list for PBXProject "tinyxml2" */;
compatibilityVersion = "Xcode 3.2"; compatibilityVersion = "Xcode 3.2";
developmentRegion = English; developmentRegion = English;
@ -134,6 +137,8 @@
buildSettings = { buildSettings = {
CONFIGURATION_BUILD_DIR = "$(SYMROOT)/Debug"; CONFIGURATION_BUILD_DIR = "$(SYMROOT)/Debug";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
"GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = DEBUG;
ONLY_ACTIVE_ARCH = YES;
SYMROOT = build; SYMROOT = build;
}; };
name = Debug; name = Debug;
@ -156,6 +161,7 @@
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = /usr/local/bin; INSTALL_PATH = /usr/local/bin;
MACOSX_DEPLOYMENT_TARGET = "";
PREBINDING = NO; PREBINDING = NO;
PRODUCT_NAME = xmltest; PRODUCT_NAME = xmltest;
}; };
@ -171,6 +177,7 @@
GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
INSTALL_PATH = /usr/local/bin; INSTALL_PATH = /usr/local/bin;
MACOSX_DEPLOYMENT_TARGET = "";
PREBINDING = NO; PREBINDING = NO;
PRODUCT_NAME = tinyxml2; PRODUCT_NAME = tinyxml2;
ZERO_LINK = NO; ZERO_LINK = NO;

View File

@ -1363,7 +1363,22 @@ int main( int argc, const char ** argv )
*/ */
} }
#endif #endif
{
// Issue #184
// If it doesn't assert, it passes. Caused by objects
// getting created during parsing which are then
// inaccessible in the memory pools.
{
XMLDocument doc;
doc.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>");
}
{
XMLDocument doc;
doc.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test>");
doc.Clear();
}
}
// ----------- Performance tracking -------------- // ----------- Performance tracking --------------