Changeset 11727 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Dec 22, 2005, 8:48:08 AM (19 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • kxmlcore/PassRefPtr.h: (KXMLCore::PassRefPtr::PassRefPtr): Remove non-template constructor that takes RefPtr since the constructor template that takes RefPtr should be sufficient. Add a constructor template that takes PassRefPtr&. (KXMLCore::PassRefPtr::adopt): Use PassRefPtr_Ref to avoid setting pointer first to 0 and then to the pointer. (KXMLCore::PassRefPtr::operator=): Added template versions that take PassRefPtr& and RefPtr parameters. (KXMLCore::PassRefPtr::operator PassRefPtr<U>): Changed to fix leak -- old version would release and then ref. (KXMLCore::operator==): Make templates have two parameters so you can mix types. Also remove unneeded const in raw pointer versions. (KXMLCore::operator!=): Ditto.
  • kxmlcore/RefPtr.h: (KXMLCore::RefPtr::RefPtr): Add constructor template that takes PassRefPtr. (KXMLCore::RefPtr::operator=): Add assignment operator templates that take RefPtr and PassRefPtr. (KXMLCore::operator==): Make templates have two parameters so you can mix types. Also remove unneeded const in raw pointer versions. (KXMLCore::operator!=): Ditto.
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r11721 r11727  
     12005-12-22  Darin Adler  <[email protected]>
     2
     3        Reviewed by Maciej.
     4
     5        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6191
     6          RefPtr/PassRefPtr have a leak issue, operator== issues
     7
     8        * kxmlcore/PassRefPtr.h:
     9        (KXMLCore::PassRefPtr::PassRefPtr): Remove non-template constructor that takes RefPtr
     10        since the constructor template that takes RefPtr should be sufficient. Add a constructor
     11        template that takes PassRefPtr&.
     12        (KXMLCore::PassRefPtr::adopt): Use PassRefPtr_Ref to avoid setting pointer first to
     13        0 and then to the pointer.
     14        (KXMLCore::PassRefPtr::operator=): Added template versions that take PassRefPtr& and
     15        RefPtr parameters.
     16        (KXMLCore::PassRefPtr::operator PassRefPtr<U>): Changed to fix leak -- old version
     17        would release and then ref.
     18        (KXMLCore::operator==): Make templates have two parameters so you can mix types.
     19        Also remove unneeded const in raw pointer versions.
     20        (KXMLCore::operator!=): Ditto.
     21
     22        * kxmlcore/RefPtr.h:
     23        (KXMLCore::RefPtr::RefPtr): Add constructor template that takes PassRefPtr.
     24        (KXMLCore::RefPtr::operator=): Add assignment operator templates that take
     25        RefPtr and PassRefPtr.
     26        (KXMLCore::operator==): Make templates have two parameters so you can mix types.
     27        Also remove unneeded const in raw pointer versions.
     28        (KXMLCore::operator!=): Ditto.
     29
    1302005-12-21  Timothy Hatcher  <[email protected]>
    231
  • trunk/JavaScriptCore/kxmlcore/PassRefPtr.h

    r11684 r11727  
    4444        PassRefPtr() : m_ptr(0) {}
    4545        PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
    46         PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
    4746        PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {}
     47        template <typename U> PassRefPtr(PassRefPtr<U>& o) : m_ptr(o.release()) { }
    4848
    4949        ~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
     
    5656        T *release() { T *tmp = m_ptr; m_ptr = 0; return tmp; }
    5757
    58         static PassRefPtr<T> adopt(T *ptr)
    59         {
    60             PassRefPtr result;
    61             result.m_ptr = ptr;
    62             return result;
     58        template <typename U> static PassRefPtr<T> adopt(U* ptr)
     59        {
     60            PassRefPtr result((PassRefPtr_Ref<T>(ptr)));
     61            return result;
    6362        }
    6463       
     
    7271        operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::get : 0; }
    7372       
    74         PassRefPtr& operator=(const RefPtr<T>&);
    7573        PassRefPtr& operator=(T *);
    7674        PassRefPtr& operator=(PassRefPtr&);
     75        template <typename U> PassRefPtr& operator=(PassRefPtr<U>&);
     76        template <typename U> PassRefPtr& operator=(const RefPtr<U>&);
    7777
    7878        PassRefPtr(PassRefPtr_Ref<T> ref) : m_ptr(ref.m_ptr) { }
     
    8686        }
    8787
    88         template<typename U>
    89         operator PassRefPtr_Ref<U>()
    90         {
    91             return PassRefPtr_Ref<U>(release());
    92         }
    93 
    94         template<typename U>
    95         operator PassRefPtr<U>()
    96         {
    97             return PassRefPtr<U>(this->release());
    98         }
     88        template <typename U> operator PassRefPtr_Ref<U>() { return PassRefPtr_Ref<U>(release()); }
     89        template <typename U> operator PassRefPtr<U>() { return PassRefPtr_Ref<U>(release()); }
    9990       
    10091    private:
     
    10293    };
    10394   
    104     template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<T>& o)
     95    template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o)
    10596    {
    10697        T *optr = o.m_ptr;
     
    113104    }
    114105   
    115     template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T *optr)
     106    template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr)
    116107    {
    117108        if (optr)
     
    123114    }
    124115
    125     template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref)
     116    template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref)
    126117    {
    127118        T *optr = ref.release();
     
    132123    }
    133124   
    134     template <class T> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<T>& b)
     125    template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<U>& ref)
     126    {
     127        T *optr = ref.release();
     128        if (T *ptr = m_ptr)
     129            ptr->deref();
     130        m_ptr = optr;
     131        return *this;
     132    }
     133   
     134    template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
    135135    {
    136136        return a.get() == b.get();
    137137    }
    138138
    139     template <class T> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<T>& b)
     139    template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<U>& b)
    140140    {
    141141        return a.get() == b.get();
    142142    }
    143143
    144     template <class T> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<T>& b)
     144    template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<U>& b)
    145145    {
    146146        return a.get() == b.get();
    147147    }
    148148
    149     template <class T> inline bool operator==(const PassRefPtr<T>& a, const T *b)
     149    template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b)
    150150    {
    151151        return a.get() == b;
    152152    }
    153153   
    154     template <class T> inline bool operator==(const T *a, const PassRefPtr<T>& b)
     154    template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<U>& b)
    155155    {
    156156        return a == b.get();
    157157    }
    158158   
    159     template <class T> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<T>& b)
     159    template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
    160160    {
    161161        return a.get() != b.get();
    162162    }
    163163
    164     template <class T> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<T>& b)
     164    template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b)
    165165    {
    166166        return a.get() != b.get();
    167167    }
    168168
    169     template <class T> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<T>& b)
     169    template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<U>& b)
    170170    {
    171171        return a.get() != b.get();
    172172    }
    173173
    174     template <class T> inline bool operator!=(const PassRefPtr<T>& a, const T *b)
     174    template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b)
    175175    {
    176176        return a.get() != b;
    177177    }
    178178
    179     template <class T> inline bool operator!=(const T *a, const PassRefPtr<T>& b)
     179    template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<U>& b)
    180180    {
    181181        return a != b.get();
    182182    }
    183183   
    184     template <class T, class U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
     184    template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
    185185    {
    186186        return PassRefPtr<T>::adopt(static_cast<T *>(p.release()));
    187187    }
    188188
    189     template <class T, class U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
     189    template <typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
    190190    {
    191191        return PassRefPtr<T>::adopt(const_cast<T *>(p.release()));
  • trunk/JavaScriptCore/kxmlcore/RefPtr.h

    r11684 r11727  
    2626namespace KXMLCore {
    2727
    28     template <class T> class PassRefPtr;
    29     template <class T> class PassRefPtr_Ref;
     28    template <typename T> class PassRefPtr;
     29    template <typename T> class PassRefPtr_Ref;
    3030
    31     template <class T> class RefPtr
     31    template <typename T> class RefPtr
    3232    {
    3333    public:
     
    3535        RefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
    3636        RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->ref(); }
     37        template <typename U> RefPtr(PassRefPtr<U>&);
     38        template <typename U> RefPtr(PassRefPtr_Ref<U>);
    3739
    3840        ~RefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
    3941       
    40         template <class U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
     42        template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
    4143       
    4244        T *get() const { return m_ptr; }
     
    5557        RefPtr& operator=(PassRefPtr<T>&);
    5658        RefPtr& operator=(PassRefPtr_Ref<T>);
     59        template <typename U> RefPtr& operator=(const RefPtr<U>&);
     60        template <typename U> RefPtr& operator=(PassRefPtr<U>&);
     61        template <typename U> RefPtr& operator=(PassRefPtr_Ref<U>);
    5762
    5863    private:
     
    6065    };
    6166   
    62     template <class T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
     67    template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr_Ref<U> ref)
     68        : m_ptr(ref.m_ptr)
     69    {
     70    }
     71   
     72    template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr<U>& o)
     73        : m_ptr(o.release())
     74    {
     75    }
     76
     77    template <typename T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
    6378    {
    6479        T *optr = o.m_ptr;
    6580        if (optr)
    6681            optr->ref();
    67         if (T *ptr = m_ptr)
    68             ptr->deref();
     82        if (m_ptr)
     83            m_ptr->deref();
    6984        m_ptr = optr;
    7085        return *this;
    7186    }
    7287   
    73     template <class T> inline RefPtr<T>& RefPtr<T>::operator=(T *optr)
     88    template <typename T> template <typename U> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
     89    {
     90        T *optr = o.m_ptr;
     91        if (optr)
     92            optr->ref();
     93        if (m_ptr)
     94            m_ptr->deref();
     95        m_ptr = optr;
     96        return *this;
     97    }
     98   
     99    template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
    74100    {
    75101        if (optr)
    76102            optr->ref();
    77         if (T *ptr = m_ptr)
    78             ptr->deref();
     103        if (m_ptr)
     104            m_ptr->deref();
    79105        m_ptr = optr;
    80106        return *this;
    81107    }
    82108
    83     template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref)
     109    template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<U> ref)
    84110    {
    85111        if (m_ptr)
     
    89115    }
    90116   
    91     template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
     117    template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
    92118    {
    93         if (T *ptr = m_ptr)
    94             ptr->deref();
     119        if (m_ptr)
     120            m_ptr->deref();
    95121        m_ptr = o.release();
    96122        return *this;
    97123    }
    98124
    99     template <class T> inline bool operator==(const RefPtr<T>& a, const RefPtr<T>& b)
     125    template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref)
     126    {
     127        if (m_ptr)
     128            m_ptr->deref();
     129        m_ptr = ref.m_ptr;
     130        return *this;
     131    }
     132   
     133    template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<U>& o)
     134    {
     135        if (m_ptr)
     136            m_ptr->deref();
     137        m_ptr = o.release();
     138        return *this;
     139    }
     140
     141    template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
    100142    {
    101143        return a.get() == b.get();
    102144    }
    103145
    104     template <class T> inline bool operator==(const RefPtr<T>& a, const T *b)
     146    template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
    105147    {
    106148        return a.get() == b;
    107149    }
    108150   
    109     template <class T> inline bool operator==(const T *a, const RefPtr<T>& b)
     151    template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
    110152    {
    111153        return a == b.get();
    112154    }
    113155   
    114     template <class T> inline bool operator!=(const RefPtr<T>& a, const RefPtr<T>& b)
     156    template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
    115157    {
    116158        return a.get() != b.get();
    117159    }
    118160
    119     template <class T> inline bool operator!=(const RefPtr<T>& a, const T *b)
     161    template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
    120162    {
    121163        return a.get() != b;
    122164    }
    123165
    124     template <class T> inline bool operator!=(const T *a, const RefPtr<T>& b)
     166    template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
    125167    {
    126168        return a != b.get();
    127169    }
    128170   
    129     template <class T, class U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
     171    template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
    130172    {
    131173        return RefPtr<T>(static_cast<T *>(p.get()));
    132174    }
    133175
    134     template <class T, class U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
     176    template <typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
    135177    {
    136178        return RefPtr<T>(const_cast<T *>(p.get()));
Note: See TracChangeset for help on using the changeset viewer.