Updated to the latest aapl. This completely eliminates the shallowCopy
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 8 Feb 2007 19:14:57 +0000 (19:14 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 8 Feb 2007 19:14:57 +0000 (19:14 +0000)
function. With that, a definite memory leak is fixed.

git-svn-id: http://svn.complang.org/ragel/trunk@89 052ea7fc-9027-0410-9066-f65837a77df0

aapl/avlcommon.h
aapl/svector.h
aapl/vector.h
redfsm/redfsm.cpp

index 1984531..a404444 100644 (file)
@@ -598,7 +598,9 @@ template <AVLMEL_TEMPDEF> void AvlTree<AVLMEL_TEMPUSE>::
        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 <AVLMEL_TEMPDEF> void AvlTree<AVLMEL_TEMPUSE>::
        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;
index ff9e97c..db3a565 100644 (file)
@@ -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 <class T, class Resize> SVector<T, Resize>::
-               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 <class T, class Resize> SVector<T, Resize>::
        }
 }
 
-#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 <class T, class Resize> SVector<T, Resize>::
-               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 <class T, class Resize> SVector<T, Resize> &
        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 <class T, class Resize> SVector<T, Resize> &
-               SVector<T, Resize>::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 <class T, class Resize> SVector<T, Resize>::
                Iter::Iter( const SVector &v ) 
index c33e35b..81c522e 100644 (file)
@@ -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<class T, class Resize> Vector<T, Resize>::
-               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 <class T, class Resize> Vector<T, Resize>::Iter::Iter( const Vector &v ) 
 {
@@ -624,20 +605,22 @@ template<class T, class Resize> void Vector<T, Resize>::
 }
 
 /**
- * \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<class T, class Resize> void Vector<T, Resize>::
-               shallowCopy( const Vector &v )
+               transfer( Vector &v )
 {
+       empty();
+
        BaseTable::data = v.data;
        BaseTable::tabLen = v.tabLen;
        BaseTable::allocLen = v.allocLen;
+
+       v.abandon();
 }
 
 /**
index 1b6d419..797d7a4 100644 (file)
@@ -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;