[webkit-changes] cvs commit: JavaScriptCore/kxmlcore PassRefPtr.h
RefPtr.h
Darin
darin at opensource.apple.com
Thu Dec 22 08:48:08 PST 2005
darin 05/12/22 08:48:08
Modified: . ChangeLog
kxmlcore PassRefPtr.h RefPtr.h
Log:
Reviewed by Maciej.
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6191
RefPtr/PassRefPtr have a leak issue, operator== issues
* 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.
Revision Changes Path
1.920 +29 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.919
retrieving revision 1.920
diff -u -r1.919 -r1.920
--- ChangeLog 22 Dec 2005 01:40:52 -0000 1.919
+++ ChangeLog 22 Dec 2005 16:48:06 -0000 1.920
@@ -1,3 +1,32 @@
+2005-12-22 Darin Adler <darin at apple.com>
+
+ Reviewed by Maciej.
+
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6191
+ RefPtr/PassRefPtr have a leak issue, operator== issues
+
+ * 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.
+
2005-12-21 Timothy Hatcher <timothy at apple.com>
* JavaScriptCore.xcodeproj/project.pbxproj:
1.6 +33 -33 JavaScriptCore/kxmlcore/PassRefPtr.h
Index: PassRefPtr.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kxmlcore/PassRefPtr.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PassRefPtr.h 20 Dec 2005 20:12:48 -0000 1.5
+++ PassRefPtr.h 22 Dec 2005 16:48:08 -0000 1.6
@@ -43,8 +43,8 @@
public:
PassRefPtr() : m_ptr(0) {}
PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
- PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {}
+ template <typename U> PassRefPtr(PassRefPtr<U>& o) : m_ptr(o.release()) { }
~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
@@ -55,11 +55,10 @@
T *release() { T *tmp = m_ptr; m_ptr = 0; return tmp; }
- static PassRefPtr<T> adopt(T *ptr)
- {
- PassRefPtr result;
- result.m_ptr = ptr;
- return result;
+ template <typename U> static PassRefPtr<T> adopt(U* ptr)
+ {
+ PassRefPtr result((PassRefPtr_Ref<T>(ptr)));
+ return result;
}
T& operator*() const { return *m_ptr; }
@@ -71,9 +70,10 @@
typedef T* (PassRefPtr::*UnspecifiedBoolType)() const;
operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::get : 0; }
- PassRefPtr& operator=(const RefPtr<T>&);
PassRefPtr& operator=(T *);
PassRefPtr& operator=(PassRefPtr&);
+ template <typename U> PassRefPtr& operator=(PassRefPtr<U>&);
+ template <typename U> PassRefPtr& operator=(const RefPtr<U>&);
PassRefPtr(PassRefPtr_Ref<T> ref) : m_ptr(ref.m_ptr) { }
@@ -85,23 +85,14 @@
return *this;
}
- template<typename U>
- operator PassRefPtr_Ref<U>()
- {
- return PassRefPtr_Ref<U>(release());
- }
-
- template<typename U>
- operator PassRefPtr<U>()
- {
- return PassRefPtr<U>(this->release());
- }
+ template <typename U> operator PassRefPtr_Ref<U>() { return PassRefPtr_Ref<U>(release()); }
+ template <typename U> operator PassRefPtr<U>() { return PassRefPtr_Ref<U>(release()); }
private:
T *m_ptr;
};
- template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<T>& o)
+ template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o)
{
T *optr = o.m_ptr;
if (optr)
@@ -112,7 +103,7 @@
return *this;
}
- template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T *optr)
+ template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr)
{
if (optr)
optr->ref();
@@ -122,7 +113,16 @@
return *this;
}
- template <class T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref)
+ template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<T>& ref)
+ {
+ T *optr = ref.release();
+ if (T *ptr = m_ptr)
+ ptr->deref();
+ m_ptr = optr;
+ return *this;
+ }
+
+ template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(PassRefPtr<U>& ref)
{
T *optr = ref.release();
if (T *ptr = m_ptr)
@@ -131,62 +131,62 @@
return *this;
}
- template <class T> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
{
return a.get() == b.get();
}
- template <class T> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() == b.get();
}
- template <class T> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<U>& b)
{
return a.get() == b.get();
}
- template <class T> inline bool operator==(const PassRefPtr<T>& a, const T *b)
+ template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b)
{
return a.get() == b;
}
- template <class T> inline bool operator==(const T *a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<U>& b)
{
return a == b.get();
}
- template <class T> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
{
return a.get() != b.get();
}
- template <class T> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() != b.get();
}
- template <class T> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<U>& b)
{
return a.get() != b.get();
}
- template <class T> inline bool operator!=(const PassRefPtr<T>& a, const T *b)
+ template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b)
{
return a.get() != b;
}
- template <class T> inline bool operator!=(const T *a, const PassRefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<U>& b)
{
return a != b.get();
}
- template <class T, class U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
+ template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
{
return PassRefPtr<T>::adopt(static_cast<T *>(p.release()));
}
- template <class T, class U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
+ template <typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
{
return PassRefPtr<T>::adopt(const_cast<T *>(p.release()));
}
1.8 +64 -22 JavaScriptCore/kxmlcore/RefPtr.h
Index: RefPtr.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kxmlcore/RefPtr.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RefPtr.h 20 Dec 2005 20:12:48 -0000 1.7
+++ RefPtr.h 22 Dec 2005 16:48:08 -0000 1.8
@@ -25,19 +25,21 @@
namespace KXMLCore {
- template <class T> class PassRefPtr;
- template <class T> class PassRefPtr_Ref;
+ template <typename T> class PassRefPtr;
+ template <typename T> class PassRefPtr_Ref;
- template <class T> class RefPtr
+ template <typename T> class RefPtr
{
public:
RefPtr() : m_ptr(0) {}
RefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->ref(); }
+ template <typename U> RefPtr(PassRefPtr<U>&);
+ template <typename U> RefPtr(PassRefPtr_Ref<U>);
~RefPtr() { if (T *ptr = m_ptr) ptr->deref(); }
- template <class U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
+ template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }
T *get() const { return m_ptr; }
@@ -54,33 +56,73 @@
RefPtr& operator=(T *);
RefPtr& operator=(PassRefPtr<T>&);
RefPtr& operator=(PassRefPtr_Ref<T>);
+ template <typename U> RefPtr& operator=(const RefPtr<U>&);
+ template <typename U> RefPtr& operator=(PassRefPtr<U>&);
+ template <typename U> RefPtr& operator=(PassRefPtr_Ref<U>);
private:
T *m_ptr;
};
- template <class T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
+ template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr_Ref<U> ref)
+ : m_ptr(ref.m_ptr)
+ {
+ }
+
+ template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr<U>& o)
+ : m_ptr(o.release())
+ {
+ }
+
+ template <typename T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
+ {
+ T *optr = o.m_ptr;
+ if (optr)
+ optr->ref();
+ if (m_ptr)
+ m_ptr->deref();
+ m_ptr = optr;
+ return *this;
+ }
+
+ template <typename T> template <typename U> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
{
T *optr = o.m_ptr;
if (optr)
optr->ref();
- if (T *ptr = m_ptr)
- ptr->deref();
+ if (m_ptr)
+ m_ptr->deref();
m_ptr = optr;
return *this;
}
- template <class T> inline RefPtr<T>& RefPtr<T>::operator=(T *optr)
+ template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
{
if (optr)
optr->ref();
- if (T *ptr = m_ptr)
- ptr->deref();
+ if (m_ptr)
+ m_ptr->deref();
m_ptr = optr;
return *this;
}
- template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref)
+ template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<U> ref)
+ {
+ if (m_ptr)
+ m_ptr->deref();
+ m_ptr = ref.m_ptr;
+ return *this;
+ }
+
+ template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
+ {
+ if (m_ptr)
+ m_ptr->deref();
+ m_ptr = o.release();
+ return *this;
+ }
+
+ template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref)
{
if (m_ptr)
m_ptr->deref();
@@ -88,50 +130,50 @@
return *this;
}
- template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)
+ template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<U>& o)
{
- if (T *ptr = m_ptr)
- ptr->deref();
+ if (m_ptr)
+ m_ptr->deref();
m_ptr = o.release();
return *this;
}
- template <class T> inline bool operator==(const RefPtr<T>& a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() == b.get();
}
- template <class T> inline bool operator==(const RefPtr<T>& a, const T *b)
+ template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
{
return a.get() == b;
}
- template <class T> inline bool operator==(const T *a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
{
return a == b.get();
}
- template <class T> inline bool operator!=(const RefPtr<T>& a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() != b.get();
}
- template <class T> inline bool operator!=(const RefPtr<T>& a, const T *b)
+ template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
{
return a.get() != b;
}
- template <class T> inline bool operator!=(const T *a, const RefPtr<T>& b)
+ template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
{
return a != b.get();
}
- template <class T, class U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
+ template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
{
return RefPtr<T>(static_cast<T *>(p.get()));
}
- template <class T, class U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
+ template <typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
{
return RefPtr<T>(const_cast<T *>(p.get()));
}
More information about the webkit-changes
mailing list