Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 May 2009 16:39:20 +0000 (16:39 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 May 2009 16:39:20 +0000 (16:39 +0000)
        <https://bugs.webkit.org/show_bug.cgi?id=25495>

        Reviewed by Oliver Hunt.

JavaScriptCore:

        * GNUmakefile.am: Added OwnPtrCommon.h and PassOwnPtr.h.
        * JavaScriptCore.vcproj/WTF/WTF.vcproj: Ditto.
        * JavaScriptCore.xcodeproj/project.pbxproj: Ditto.

        * wtf/OwnPtr.h:
        (WTF::OwnPtr::OwnPtr): Added constructors that take a
        PassOwnPtr.  Also added a copy constructor declaration that's
        required when assigning a PassOwnPtr to a stack-based OwnPtr.
        (WTF::operator=): Added assignment operator methods that take a
        PassOwnPtr.
        (WTF::swap): Reformatted.
        (WTF::operator==): Whitespace changes.
        (WTF::operator!=): Ditto.

        * wtf/OwnPtrCommon.h: Added.
        (WTF::deleteOwnedPtr):

        * wtf/PassOwnPtr.h: Added.
        (WTF::PassOwnPtr::PassOwnPtr):
        (WTF::PassOwnPtr::~PassOwnPtr):
        (WTF::PassOwnPtr::get):
        (WTF::PassOwnPtr::clear):
        (WTF::PassOwnPtr::release):
        (WTF::PassOwnPtr::operator*):
        (WTF::PassOwnPtr::operator->):
        (WTF::PassOwnPtr::operator!):
        (WTF::PassOwnPtr::operator UnspecifiedBoolType):
        (WTF::::operator):
        (WTF::operator==):
        (WTF::operator!=):
        (WTF::static_pointer_cast):
        (WTF::const_pointer_cast):
        (WTF::getPtr):

JavaScriptGlue:

        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.

WebCore:

        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.
        * WebCore.vcproj/WebCore.vcproj: Added OwnPtrCommon.h and
        PassOwnPtr.h.

WebKit/mac:

        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.

WebKitTools:

        * DumpRenderTree/ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
        * DumpRenderTree/ForwardingHeaders/wtf/PassOwnPtr.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@44095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/GNUmakefile.am
JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/wtf/OwnPtr.h
JavaScriptCore/wtf/OwnPtrCommon.h [new file with mode: 0644]
JavaScriptCore/wtf/PassOwnPtr.h [new file with mode: 0644]
JavaScriptGlue/ChangeLog
JavaScriptGlue/ForwardingHeaders/wtf/OwnPtrCommon.h [new file with mode: 0644]
JavaScriptGlue/ForwardingHeaders/wtf/PassOwnPtr.h [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ForwardingHeaders/wtf/OwnPtrCommon.h [new file with mode: 0644]
WebCore/ForwardingHeaders/wtf/PassOwnPtr.h [new file with mode: 0644]
WebCore/WebCore.vcproj/WebCore.vcproj
WebKit/mac/ChangeLog
WebKit/mac/ForwardingHeaders/wtf/OwnPtrCommon.h [new file with mode: 0644]
WebKit/mac/ForwardingHeaders/wtf/PassOwnPtr.h [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/OwnPtrCommon.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/PassOwnPtr.h [new file with mode: 0644]

index f2c0d91..5b5eb84 100644 (file)
@@ -1,3 +1,45 @@
+2009-05-23  David Kilzer  <ddkilzer@apple.com>
+
+        Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
+
+        <https://bugs.webkit.org/show_bug.cgi?id=25495>
+
+        Reviewed by Oliver Hunt.
+
+        * GNUmakefile.am: Added OwnPtrCommon.h and PassOwnPtr.h.
+        * JavaScriptCore.vcproj/WTF/WTF.vcproj: Ditto.
+        * JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
+
+        * wtf/OwnPtr.h:
+        (WTF::OwnPtr::OwnPtr): Added constructors that take a
+        PassOwnPtr.  Also added a copy constructor declaration that's
+        required when assigning a PassOwnPtr to a stack-based OwnPtr.
+        (WTF::operator=): Added assignment operator methods that take a
+        PassOwnPtr.
+        (WTF::swap): Reformatted.
+        (WTF::operator==): Whitespace changes.
+        (WTF::operator!=): Ditto.
+
+        * wtf/OwnPtrCommon.h: Added.
+        (WTF::deleteOwnedPtr):
+
+        * wtf/PassOwnPtr.h: Added.
+        (WTF::PassOwnPtr::PassOwnPtr):
+        (WTF::PassOwnPtr::~PassOwnPtr):
+        (WTF::PassOwnPtr::get):
+        (WTF::PassOwnPtr::clear):
+        (WTF::PassOwnPtr::release):
+        (WTF::PassOwnPtr::operator*):
+        (WTF::PassOwnPtr::operator->):
+        (WTF::PassOwnPtr::operator!):
+        (WTF::PassOwnPtr::operator UnspecifiedBoolType):
+        (WTF::::operator):
+        (WTF::operator==):
+        (WTF::operator!=):
+        (WTF::static_pointer_cast):
+        (WTF::const_pointer_cast):
+        (WTF::getPtr):
+
 2009-05-23  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 4728504..15fcfbb 100644 (file)
@@ -237,6 +237,8 @@ javascriptcore_sources += \
        JavaScriptCore/wtf/NotFound.h \
        JavaScriptCore/wtf/OwnArrayPtr.h \
        JavaScriptCore/wtf/OwnPtr.h \
+       JavaScriptCore/wtf/OwnPtrCommon.h \
+       JavaScriptCore/wtf/PassOwnPtr.h \
        JavaScriptCore/wtf/PassRefPtr.h \
        JavaScriptCore/wtf/Platform.h \
        JavaScriptCore/wtf/PtrAndFlags.h \
index ee58b0b..a0cc025 100644 (file)
                        >\r
                </File>\r
                <File\r
+                       RelativePath="..\..\wtf\OwnPtrCommon.h"\r
+                       >\r
+               </File>\r
+               <File\r
                        RelativePath="..\..\wtf\OwnPtrWin.cpp"\r
                        >\r
                </File>\r
                <File\r
+                       RelativePath="..\..\wtf\PassOwnPtr.h"\r
+                       >\r
+               </File>\r
+               <File\r
                        RelativePath="..\..\wtf\PassRefPtr.h"\r
                        >\r
                </File>\r
index dc8b898..1e758b9 100644 (file)
@@ -98,6 +98,8 @@
                180B9BFE0F16E94D009BDBC5 /* CurrentTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */; };
                1C61516C0EBAC7A00031376F /* ProfilerServer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C61516A0EBAC7A00031376F /* ProfilerServer.mm */; settings = {COMPILER_FLAGS = "-fno-strict-aliasing"; }; };
                1C61516D0EBAC7A00031376F /* ProfilerServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C61516B0EBAC7A00031376F /* ProfilerServer.h */; };
+               4409D8470FAF80A200523B87 /* OwnPtrCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               44DD48530FAEA85000D6B4EB /* PassOwnPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
                5D53726F0E1C54880021E549 /* Tracing.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D53726E0E1C54880021E549 /* Tracing.h */; };
                5D5D8AB60E0D0A7200F9C692 /* jsc in Copy Into Framework */ = {isa = PBXBuildFile; fileRef = 932F5BE10822A1C700736975 /* jsc */; };
                5D5D8AD10E0D0EBE00F9C692 /* libedit.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D5D8AD00E0D0EBE00F9C692 /* libedit.dylib */; };
                1C9051450BA9E8A70081E9D0 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
                1CAA8B4A0D32C39A0041BCFF /* JavaScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScript.h; sourceTree = "<group>"; };
                1CAA8B4B0D32C39A0041BCFF /* JavaScriptCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptCore.h; sourceTree = "<group>"; };
+               440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtrCommon.h; sourceTree = "<group>"; };
                449097EE0F8F81B50076A327 /* FeatureDefines.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = FeatureDefines.xcconfig; sourceTree = "<group>"; };
+               44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PassOwnPtr.h; sourceTree = "<group>"; };
                45E12D8806A49B0F00E9DF84 /* jsc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsc.cpp; sourceTree = "<group>"; tabWidth = 4; };
                5186111D0CC824830081412B /* Deque.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Deque.h; sourceTree = "<group>"; };
                51F0EB6105C86C6B00E6DF1B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
                                C0A2723F0E509F1E00E96E15 /* NotFound.h */,
                                9303F5A409911A5800AD71B8 /* OwnArrayPtr.h */,
                                9303F567099118FA00AD71B8 /* OwnPtr.h */,
+                               440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */,
+                               44DD48520FAEA85000D6B4EB /* PassOwnPtr.h */,
                                6580F795094070560082C219 /* PassRefPtr.h */,
                                65D6D87E09B5A32E0002E4D7 /* Platform.h */,
                                0B1F921B0F17502D0036468E /* PtrAndFlags.h */,
                                BC18C4480E16F5CD00B34460 /* Operations.h in Headers */,
                                BC18C4490E16F5CD00B34460 /* OwnArrayPtr.h in Headers */,
                                BC18C44A0E16F5CD00B34460 /* OwnPtr.h in Headers */,
+                               4409D8470FAF80A200523B87 /* OwnPtrCommon.h in Headers */,
                                BC18C44B0E16F5CD00B34460 /* Parser.h in Headers */,
+                               44DD48530FAEA85000D6B4EB /* PassOwnPtr.h in Headers */,
                                BC18C44C0E16F5CD00B34460 /* PassRefPtr.h in Headers */,
                                BC18C44F0E16F5CD00B34460 /* Platform.h in Headers */,
                                BC18C4500E16F5CD00B34460 /* Profile.h in Headers */,
index af939e7..9e4bd32 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *  Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Library General Public
 
 #include "Assertions.h"
 #include "Noncopyable.h"
+#include "OwnPtrCommon.h"
 #include "TypeTraits.h"
 #include <algorithm>
 #include <memory>
 
-#if PLATFORM(WIN)
-
-typedef struct HBITMAP__* HBITMAP;
-typedef struct HBRUSH__* HBRUSH;
-typedef struct HFONT__* HFONT;
-typedef struct HPALETTE__* HPALETTE;
-typedef struct HPEN__* HPEN;
-typedef struct HRGN__* HRGN;
-
-#endif
-
 namespace WTF {
 
     // Unlike most of our smart pointers, OwnPtr can take either the pointer type or the pointed-to type.
 
-    template <typename T> inline void deleteOwnedPtr(T* ptr)
-    {
-        typedef char known[sizeof(T) ? 1 : -1];
-        if (sizeof(known))
-            delete ptr;
-    }
-
-#if PLATFORM(WIN)
-    void deleteOwnedPtr(HBITMAP);
-    void deleteOwnedPtr(HBRUSH);
-    void deleteOwnedPtr(HFONT);
-    void deleteOwnedPtr(HPALETTE);
-    void deleteOwnedPtr(HPEN);
-    void deleteOwnedPtr(HRGN);
-#endif
+    template <typename T> class PassOwnPtr;
 
     template <typename T> class OwnPtr : Noncopyable {
     public:
@@ -65,6 +41,15 @@ namespace WTF {
 
         explicit OwnPtr(PtrType ptr = 0) : m_ptr(ptr) { }
         OwnPtr(std::auto_ptr<ValueType> autoPtr) : m_ptr(autoPtr.release()) { }
+        // See comment in PassOwnPtr.h for why this takes a const reference.
+        template <typename U> OwnPtr(const PassOwnPtr<U>& o);
+
+        // This copy constructor is used implicitly by gcc when it generates
+        // transients for assigning a PassOwnPtr<T> object to a stack-allocated
+        // OwnPtr<T> object.  It should never be called explicitly and gcc
+        // should optimize away the constructor when generating code.
+        OwnPtr(const OwnPtr<ValueType>& o);
+
         ~OwnPtr() { deleteOwnedPtr(m_ptr); }
 
         PtrType get() const { return m_ptr; }
@@ -86,19 +71,50 @@ namespace WTF {
         typedef PtrType OwnPtr::*UnspecifiedBoolType;
         operator UnspecifiedBoolType() const { return m_ptr ? &OwnPtr::m_ptr : 0; }
 
+        OwnPtr& operator=(const PassOwnPtr<T>&);
+        template <typename U> OwnPtr& operator=(const PassOwnPtr<U>&);
+
         void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); }
 
     private:
         PtrType m_ptr;
     };
-    
-    template <typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) { a.swap(b); }
+
+    template <typename T> template <typename U> inline OwnPtr<T>::OwnPtr(const PassOwnPtr<U>& o)
+        : m_ptr(o.release())
+    {
+    }
+
+    template <typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<T>& o)
+    {
+        T* ptr = m_ptr;
+        m_ptr = o.release();
+        ASSERT(!ptr || m_ptr != ptr);
+        if (ptr)
+            deleteOwnedPtr(ptr);
+        return *this;
+    }
+
+    template <typename T> template <typename U> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr<U>& o)
+    {
+        T* ptr = m_ptr;
+        m_ptr = o.release();
+        ASSERT(!ptr || m_ptr != ptr);
+        if (ptr)
+            deleteOwnedPtr(ptr);
+        return *this;
+    }
+
+    template <typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b)
+    {
+        a.swap(b);
+    }
 
     template <typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b)
-    { 
+    {
         return a.get() == b; 
     }
-    
+
     template <typename T, typename U> inline bool operator==(T* a, const OwnPtr<U>& b) 
     {
         return a == b.get(); 
@@ -110,10 +126,10 @@ namespace WTF {
     }
 
     template <typename T, typename U> inline bool operator!=(T* a, const OwnPtr<U>& b)
-    { 
+    {
         return a != b.get(); 
     }
-    
+
     template <typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>& p)
     {
         return p.get();
diff --git a/JavaScriptCore/wtf/OwnPtrCommon.h b/JavaScriptCore/wtf/OwnPtrCommon.h
new file mode 100644 (file)
index 0000000..6cd8bdd
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef WTF_OwnPtrCommon_h
+#define WTF_OwnPtrCommon_h
+
+#if PLATFORM(WIN)
+typedef struct HBITMAP__* HBITMAP;
+typedef struct HBRUSH__* HBRUSH;
+typedef struct HFONT__* HFONT;
+typedef struct HPALETTE__* HPALETTE;
+typedef struct HPEN__* HPEN;
+typedef struct HRGN__* HRGN;
+#endif
+
+namespace WTF {
+
+    template <typename T> inline void deleteOwnedPtr(T* ptr)
+    {
+        typedef char known[sizeof(T) ? 1 : -1];
+        if (sizeof(known))
+            delete ptr;
+    }
+
+#if PLATFORM(WIN)
+    void deleteOwnedPtr(HBITMAP);
+    void deleteOwnedPtr(HBRUSH);
+    void deleteOwnedPtr(HFONT);
+    void deleteOwnedPtr(HPALETTE);
+    void deleteOwnedPtr(HPEN);
+    void deleteOwnedPtr(HRGN);
+#endif
+
+} // namespace WTF
+
+#endif // WTF_OwnPtrCommon_h
diff --git a/JavaScriptCore/wtf/PassOwnPtr.h b/JavaScriptCore/wtf/PassOwnPtr.h
new file mode 100644 (file)
index 0000000..ae70457
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef WTF_PassOwnPtr_h
+#define WTF_PassOwnPtr_h
+
+#include "Assertions.h"
+#include "OwnPtrCommon.h"
+#include "TypeTraits.h"
+
+namespace WTF {
+
+    // Unlike most of our smart pointers, PassOwnPtr can take either the pointer type or the pointed-to type.
+
+    template <typename T> class OwnPtr;
+
+    template <typename T> class PassOwnPtr {
+    public:
+        typedef typename RemovePointer<T>::Type ValueType;
+        typedef ValueType* PtrType;
+
+        PassOwnPtr(PtrType ptr = 0) : m_ptr(ptr) { }
+        // It somewhat breaks the type system to allow transfer of ownership out of
+        // a const PassOwnPtr. However, it makes it much easier to work with PassOwnPtr
+        // temporaries, and we don't really have a need to use real const PassOwnPtrs 
+        // anyway.
+        PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.release()) { }
+        template <typename U> PassOwnPtr(const PassOwnPtr<U>& o) : m_ptr(o.release()) { }
+
+        ~PassOwnPtr() { deleteOwnedPtr(m_ptr); }
+
+        PtrType get() const { return m_ptr; }
+
+        void clear() { m_ptr = 0; }
+        PtrType release() const { PtrType ptr = m_ptr; m_ptr = 0; return ptr; }
+
+        ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; }
+        PtrType operator->() const { ASSERT(m_ptr); return m_ptr; }
+
+        bool operator!() const { return !m_ptr; }
+
+        // This conversion operator allows implicit conversion to bool but not to other integer types.
+        typedef PtrType PassOwnPtr::*UnspecifiedBoolType;
+        operator UnspecifiedBoolType() const { return m_ptr ? &PassOwnPtr::m_ptr : 0; }
+
+        PassOwnPtr& operator=(T*);
+        PassOwnPtr& operator=(const PassOwnPtr<T>&);
+        template <typename U> PassOwnPtr& operator=(const PassOwnPtr<U>&);
+
+    private:
+        mutable PtrType m_ptr;
+    };
+
+    template <typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(T* optr)
+    {
+        T* ptr = m_ptr;
+        m_ptr = optr;
+        ASSERT(!ptr || m_ptr != ptr);
+        if (ptr)
+            deleteOwnedPtr(ptr);
+        return *this;
+    }
+
+    template <typename T> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<T>& optr)
+    {
+        T* ptr = m_ptr;
+        m_ptr = optr.release();
+        ASSERT(!ptr || m_ptr != ptr);
+        if (ptr)
+            deleteOwnedPtr(ptr);
+        return *this;
+    }
+
+    template <typename T> template <typename U> inline PassOwnPtr<T>& PassOwnPtr<T>::operator=(const PassOwnPtr<U>& optr)
+    {
+        T* ptr = m_ptr;
+        m_ptr = optr.release();
+        ASSERT(!ptr || m_ptr != ptr);
+        if (ptr)
+            deleteOwnedPtr(ptr);
+        return *this;
+    }
+
+    template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) 
+    {
+        return a.get() == b.get(); 
+    }
+
+    template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, const OwnPtr<U>& b) 
+    {
+        return a.get() == b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator==(const OwnPtr<T>& a, const PassOwnPtr<U>& b) 
+    {
+        return a.get() == b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator==(const PassOwnPtr<T>& a, U* b) 
+    {
+        return a.get() == b; 
+    }
+    
+    template <typename T, typename U> inline bool operator==(T* a, const PassOwnPtr<U>& b) 
+    {
+        return a == b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const PassOwnPtr<U>& b) 
+    {
+        return a.get() != b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, const OwnPtr<U>& b) 
+    {
+        return a.get() != b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, const PassOwnPtr<U>& b) 
+    {
+        return a.get() != b.get(); 
+    }
+    
+    template <typename T, typename U> inline bool operator!=(const PassOwnPtr<T>& a, U* b)
+    {
+        return a.get() != b; 
+    }
+    
+    template <typename T, typename U> inline bool operator!=(T* a, const PassOwnPtr<U>& b) 
+    {
+        return a != b.get(); 
+    }
+
+    template <typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(const PassOwnPtr<U>& p) 
+    {
+        return PassOwnPtr<T>(static_cast<T*>(p.release())); 
+    }
+
+    template <typename T, typename U> inline PassOwnPtr<T> const_pointer_cast(const PassOwnPtr<U>& p) 
+    {
+        return PassOwnPtr<T>(const_cast<T*>(p.release())); 
+    }
+
+    template <typename T> inline T* getPtr(const PassOwnPtr<T>& p)
+    {
+        return p.get();
+    }
+
+} // namespace WTF
+
+using WTF::PassOwnPtr;
+using WTF::const_pointer_cast;
+using WTF::static_pointer_cast;
+
+#endif // WTF_PassOwnPtr_h
index cafc15c..6e0a87b 100644 (file)
@@ -1,3 +1,14 @@
+2009-05-23  David Kilzer  <ddkilzer@apple.com>
+
+        Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
+
+        <https://bugs.webkit.org/show_bug.cgi?id=25495>
+
+        Reviewed by Oliver Hunt.
+
+        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
+        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.
+
 2009-05-14  Mark Rowe  <mrowe@apple.com>
 
         Rubber-stamped by Darin Adler.
diff --git a/JavaScriptGlue/ForwardingHeaders/wtf/OwnPtrCommon.h b/JavaScriptGlue/ForwardingHeaders/wtf/OwnPtrCommon.h
new file mode 100644 (file)
index 0000000..4917541
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/OwnPtrCommon.h>
diff --git a/JavaScriptGlue/ForwardingHeaders/wtf/PassOwnPtr.h b/JavaScriptGlue/ForwardingHeaders/wtf/PassOwnPtr.h
new file mode 100644 (file)
index 0000000..6064e88
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassOwnPtr.h>
index 25fc87c..078ebc8 100644 (file)
@@ -1,5 +1,18 @@
 2009-05-23  David Kilzer  <ddkilzer@apple.com>
 
+        Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
+
+        <https://bugs.webkit.org/show_bug.cgi?id=25495>
+
+        Reviewed by Oliver Hunt.
+
+        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
+        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.
+        * WebCore.vcproj/WebCore.vcproj: Added OwnPtrCommon.h and
+        PassOwnPtr.h.
+
+2009-05-23  David Kilzer  <ddkilzer@apple.com>
+
         Fix Mac builds by backing out r44093
 
         * bindings/js/JSCustomPositionCallback.cpp:
diff --git a/WebCore/ForwardingHeaders/wtf/OwnPtrCommon.h b/WebCore/ForwardingHeaders/wtf/OwnPtrCommon.h
new file mode 100644 (file)
index 0000000..5826031
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_PassOwnPtr_h
+#define WebCore_FWD_PassOwnPtr_h
+#include <JavaScriptCore/PassOwnPtr.h>
+#endif
diff --git a/WebCore/ForwardingHeaders/wtf/PassOwnPtr.h b/WebCore/ForwardingHeaders/wtf/PassOwnPtr.h
new file mode 100644 (file)
index 0000000..5826031
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_PassOwnPtr_h
+#define WebCore_FWD_PassOwnPtr_h
+#include <JavaScriptCore/PassOwnPtr.h>
+#endif
index 83fde39..f7f501c 100644 (file)
                                        >\r
                                </File>\r
                                <File\r
+                                       RelativePath="..\ForwardingHeaders\wtf\OwnPtrCommon.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath="..\ForwardingHeaders\wtf\PassOwnPtr.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\ForwardingHeaders\wtf\PassRefPtr.h"\r
                                        >\r
                                </File>\r
index e6386c0..dbc8a60 100644 (file)
@@ -1,3 +1,14 @@
+2009-05-23  David Kilzer  <ddkilzer@apple.com>
+
+        Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
+
+        <https://bugs.webkit.org/show_bug.cgi?id=25495>
+
+        Reviewed by Oliver Hunt.
+
+        * ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
+        * ForwardingHeaders/wtf/PassOwnPtr.h: Added.
+
 2009-05-22  Darin Adler  <darin@apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/WebKit/mac/ForwardingHeaders/wtf/OwnPtrCommon.h b/WebKit/mac/ForwardingHeaders/wtf/OwnPtrCommon.h
new file mode 100644 (file)
index 0000000..efffb81
--- /dev/null
@@ -0,0 +1 @@
+#import <JavaScriptCore/PassOwnPtr.h>
diff --git a/WebKit/mac/ForwardingHeaders/wtf/PassOwnPtr.h b/WebKit/mac/ForwardingHeaders/wtf/PassOwnPtr.h
new file mode 100644 (file)
index 0000000..efffb81
--- /dev/null
@@ -0,0 +1 @@
+#import <JavaScriptCore/PassOwnPtr.h>
index 722145f..46cf9c2 100644 (file)
@@ -1,5 +1,16 @@
 2009-05-23  David Kilzer  <ddkilzer@apple.com>
 
+        Part 1 of 2: Bug 25495: Implement PassOwnPtr and replace uses of std::auto_ptr
+
+        <https://bugs.webkit.org/show_bug.cgi?id=25495>
+
+        Reviewed by Oliver Hunt.
+
+        * DumpRenderTree/ForwardingHeaders/wtf/OwnPtrCommon.h: Added.
+        * DumpRenderTree/ForwardingHeaders/wtf/PassOwnPtr.h: Added.
+
+2009-05-23  David Kilzer  <ddkilzer@apple.com>
+
         resolve-ChangeLogs: Add missing newline to status message
 
         * Scripts/resolve-ChangeLogs: Added newline to status message
diff --git a/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/OwnPtrCommon.h b/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/OwnPtrCommon.h
new file mode 100644 (file)
index 0000000..6064e88
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassOwnPtr.h>
diff --git a/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/PassOwnPtr.h b/WebKitTools/DumpRenderTree/ForwardingHeaders/wtf/PassOwnPtr.h
new file mode 100644 (file)
index 0000000..6064e88
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/PassOwnPtr.h>