From: thurston Date: Thu, 8 Feb 2007 19:14:57 +0000 (+0000) Subject: Updated to the latest aapl. This completely eliminates the shallowCopy X-Git-Tag: 2.0_alpha~397 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b1e68f0f816d4006690df0657e95f26f7e7ca14;p=external%2Fragel.git Updated to the latest aapl. This completely eliminates the shallowCopy function. With that, a definite memory leak is fixed. git-svn-id: http://svn.complang.org/ragel/trunk@89 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/aapl/avlcommon.h b/aapl/avlcommon.h index 1984531..a404444 100644 --- a/aapl/avlcommon.h +++ b/aapl/avlcommon.h @@ -598,7 +598,9 @@ template void AvlTree:: root = other.root; #ifdef WALKABLE - BASELIST::shallowCopy( other ); + BASELIST::head = other.BASELIST::head; + BASELIST::tail = other.BASELIST::tail; + BASELIST::listLen = other.BASELIST::listLen; #else head = other.head; tail = other.tail; @@ -636,7 +638,9 @@ template void AvlTree:: root = other.root; #ifdef WALKABLE - BASELIST::shallowCopy( other ); + BASELIST::head = other.BASELIST::head; + BASELIST::tail = other.BASELIST::tail; + BASELIST::listLen = other.BASELIST::listLen; #else head = other.head; tail = other.tail; diff --git a/aapl/svector.h b/aapl/svector.h index ff9e97c..db3a565 100644 --- a/aapl/svector.h +++ b/aapl/svector.h @@ -103,9 +103,6 @@ public: /* Shallow copy. */ SVector( const SVector &v ); - /* Shallow copy. */ - SVector(STabHead *head); - /** * \brief Free all memory used by the vector. * @@ -128,9 +125,6 @@ public: /* Perform a shallow copy of another vector. */ SVector &operator=( const SVector &v ); - /* Perform a shallow copy of another vector by the header. */ - SVector &operator=( STabHead *head ); - /*@{*/ /** @@ -490,32 +484,6 @@ protected: void downResizeDup(long len); }; -#if 0 -/* Create a vector with an intial number of elements and size. */ -template SVector:: - SVector( long size, long allocLen ) -{ - /* Allocate the space if we are given a positive allocLen. */ - if ( allocLen > 0 ) { - /* Allocate the data needed. */ - STabHead *head = (STabHead*) malloc( sizeof(STabHead) + - sizeof(T) * allocLen ); - if ( head == 0 ) - throw std::bad_alloc(); - - /* Set up the header and save the data pointer. */ - head->refCount = 1; - head->allocLen = allocLen; - head->tabLen = 0; - BaseTable::data = (T*) (head + 1); - } - - /* Grow to the size specified. If we did not have enough space - * allocated that is ok. Table will be grown to the right size. */ - setAsNew( size ); -} -#endif - /** * \brief Perform a shallow copy of the vector. * @@ -535,26 +503,6 @@ template SVector:: } } -#if 0 -/** - * \brief Perform a shallow copy of the vector from only the header. - * - * Takes a reference to the contents specified by the header. - */ -template SVector:: - SVector(STabHead *head) -{ - /* Take a reference to other, if the header is no-null. */ - if ( head == 0 ) - BaseTable::data = 0; - else { - head->refCount += 1; - BaseTable::data = (T*) (head + 1); - } -} -#endif - - /** * \brief Shallow copy another vector into this vector. * @@ -581,30 +529,6 @@ template SVector & return *this; } -/** - * \brief Shallow copy another vector into this vector from only the header. - * - * Takes a reference to the other header vector. The contents of this vector - * are first emptied. - * - * \returns A reference to this. - */ -template SVector & - SVector::operator=( STabHead *head ) -{ - /* First clean out the current contents. */ - empty(); - - /* Take a reference to other, if the header is no-null. */ - if ( head == 0 ) - BaseTable::data = 0; - else { - head->refCount += 1; - BaseTable::data = (T*) (head + 1); - } - return *this; -} - /* Init a vector iterator with just a vector. */ template SVector:: Iter::Iter( const SVector &v ) diff --git a/aapl/vector.h b/aapl/vector.h index c33e35b..81c522e 100644 --- a/aapl/vector.h +++ b/aapl/vector.h @@ -106,9 +106,9 @@ public: /* Abandon the contents of the vector without deleteing. */ void abandon(); - /* Performs a shallow copy of another vector into this vector. If this - * vector is non-empty then its contents are lost (not freed). */ - void shallowCopy( const Vector &v ); + /* Transfers the elements of another vector into this vector. First emptys + * the current vector. */ + void transfer( Vector &v ); /* Perform a deep copy of another vector into this vector. */ Vector &operator=( const Vector &v ); @@ -470,25 +470,6 @@ protected: void downResize(long len); }; -#if 0 -/* Create a vector with an intial number of elements and size. */ -template Vector:: - Vector( long size, long allocLen ) -{ - /* Allocate the space if we are given a positive allocLen. */ - BaseTable::allocLen = allocLen; - if ( allocLen > 0 ) { - BaseTable::data = (T*) malloc(sizeof(T) * BaseTable::allocLen); - if ( BaseTable::data == 0 ) - throw std::bad_alloc(); - } - - /* Grow to the size specified. If we did not have enough space - * allocated that is ok. Table will be grown to right size. */ - setAsNew( size ); -} -#endif - /* Init a vector iterator with just a vector. */ template Vector::Iter::Iter( const Vector &v ) { @@ -624,20 +605,22 @@ template void Vector:: } /** - * \brief Shallow copy another vector into this vector. + * \brief Transfer the contents of another vector into this vector. * - * The dynamic array of the other vector is copied into this vector by - * reference. If this vector is non-empty then its contents are lost. This - * routine must be used with care. After a shallow copy one vector should - * abandon its contents to prevent both destructors from attempting to free - * the common array. + * The dynamic array of the other vector is moved into this vector by + * reference. If this vector is non-empty then its contents are first deleted. + * Afterward the other vector will be empty. */ template void Vector:: - shallowCopy( const Vector &v ) + transfer( Vector &v ) { + empty(); + BaseTable::data = v.data; BaseTable::tabLen = v.tabLen; BaseTable::allocLen = v.allocLen; + + v.abandon(); } /** diff --git a/redfsm/redfsm.cpp b/redfsm/redfsm.cpp index 1b6d419..797d7a4 100644 --- a/redfsm/redfsm.cpp +++ b/redfsm/redfsm.cpp @@ -325,8 +325,7 @@ void RedFsmAp::moveToDefault( RedTransAp *defTrans, RedStateAp *state ) } /* Save off the range we just created into the state's range. */ - state->outRange.shallowCopy( outRange ); - outRange.abandon(); + state->outRange.transfer( outRange ); /* Store the default. */ state->defTrans = defTrans;