Ignore:
Timestamp:
Oct 5, 2011, 3:23:03 PM (14 years ago)
Author:
Adam Roben
Message:

Ensure RetainPtr::hashTableDeletedValue returns a pointer, not a pointer to a pointer

RetainPtr's behavior of allowing the template parameter to be either a pointer type or a
pointed-to type confused us when we implemented hashTableDeletedValue.

Fixes <http://webkit.org/b/69414> <rdar://problem/10236833> Using RetainPtr as the key type
in HashMap/HashSet fails to compile

Reviewed by John Sullivan.

Source/JavaScriptCore:

  • wtf/RetainPtr.h:

(WTF::RetainPtr::hashTableDeletedValue): Changed to use the PtrType typedef rather than T*,
since T might itself be a pointer.

(WTF::PtrHash<RetainPtr<P> >): Updated this to use PtrType everywhere, even though T* didn't
seem to be causing a problem.

Tools:

Add tests for using RetainPtrs inside HashMap and HashSet

  • TestWebKitAPI/Tests/WTF/cf/RetainPtrHashing.cpp: Added.

(TestWebKitAPI::TEST): Show that RetainPtr can be used inside HashSet and as both the key
and value type of HashMap.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/win/TestWebKitAPI.vcproj:

Added new file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/RetainPtr.h

    r83664 r96757  
    104104
    105105    private:
    106         static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
     106        static PtrType hashTableDeletedValue() { return reinterpret_cast<PtrType>(-1); }
    107107
    108108        PtrType m_ptr;
     
    237237    template<typename P> struct HashTraits<RetainPtr<P> > : SimpleClassHashTraits<RetainPtr<P> > { };
    238238   
    239     template<typename P> struct PtrHash<RetainPtr<P> > : PtrHash<P*> {
    240         using PtrHash<P*>::hash;
     239    template<typename P> struct PtrHash<RetainPtr<P> > : PtrHash<typename RetainPtr<P>::PtrType> {
     240        using PtrHash<typename RetainPtr<P>::PtrType>::hash;
    241241        static unsigned hash(const RetainPtr<P>& key) { return hash(key.get()); }
    242         using PtrHash<P*>::equal;
     242        using PtrHash<typename RetainPtr<P>::PtrType>::equal;
    243243        static bool equal(const RetainPtr<P>& a, const RetainPtr<P>& b) { return a == b; }
    244         static bool equal(P* a, const RetainPtr<P>& b) { return a == b; }
    245         static bool equal(const RetainPtr<P>& a, P* b) { return a == b; }
     244        static bool equal(typename RetainPtr<P>::PtrType a, const RetainPtr<P>& b) { return a == b; }
     245        static bool equal(const RetainPtr<P>& a, typename RetainPtr<P>::PtrType b) { return a == b; }
    246246    };
    247247   
Note: See TracChangeset for help on using the changeset viewer.