Changeset 215450 in webkit
- Timestamp:
- Apr 17, 2017, 10:37:45 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r215429 r215450 1 2017-04-17 Alex Christensen <achristensen@webkit.org> 2 3 Allow Variants of RetainPtrs 4 https://bugs.webkit.org/show_bug.cgi?id=170923 5 6 Reviewed by Tim Horton and Sam Weinig. 7 8 * wtf/RetainPtr.h: 9 (WTF::RetainPtr::operator&): Deleted. 10 Operator& was causing a compile error when making Variant<RetainPtr<T>, ...> 11 and because it is strange and only used once, let's just remove it. 12 * wtf/Variant.h: 13 (WTF::get): 14 (WTF::get_if): 15 Use std::addressof instead of operator& which could be overloaded to return any type with any meaning. 16 1 17 2017-04-17 Youenn Fablet <youenn@apple.com> 2 18 -
trunk/Source/WTF/wtf/RetainPtr.h
r204567 r215450 89 89 bool operator!() const { return !m_ptr; } 90 90 91 #if !(defined (__OBJC__) && __has_feature(objc_arc))92 // This function is useful for passing RetainPtrs to functions that return93 // CF types as out parameters.94 PtrType* operator&()95 {96 // Require that the pointer is null, to prevent leaks.97 ASSERT(!m_ptr);98 99 return (PtrType*)&m_ptr;100 }101 #endif102 103 91 // This conversion operator allows implicit conversion to bool but not to other integer types. 104 92 typedef StorageType RetainPtr::*UnspecifiedBoolType; -
trunk/Source/WTF/wtf/Variant.h
r207627 r215450 1789 1789 return *( 1790 1790 (_Index!=__v.index()) 1791 ? &__throw_bad_variant_access<typename __indexed_type<_Index,_Types...>::__type const&>("Bad Variant index in get")1792 : &__variant_accessor<_Index,_Types...>::get(__v)1791 ? std::addressof(__throw_bad_variant_access<typename __indexed_type<_Index,_Types...>::__type const&>("Bad Variant index in get")) 1792 : std::addressof(__variant_accessor<_Index,_Types...>::get(__v)) 1793 1793 ); 1794 1794 } … … 1798 1798 return *( 1799 1799 (_Index!=__v.index()) 1800 ? &__throw_bad_variant_access<typename __indexed_type<_Index,_Types...>::__type&>("Bad Variant index in get")1801 : &__variant_accessor<_Index,_Types...>::get(__v)1800 ? std::addressof(__throw_bad_variant_access<typename __indexed_type<_Index,_Types...>::__type&>("Bad Variant index in get")) 1801 : std::addressof(__variant_accessor<_Index,_Types...>::get(__v)) 1802 1802 ); 1803 1803 } … … 1819 1819 template<typename _Type,typename ... _Types> 1820 1820 constexpr std::add_pointer_t<_Type> get_if(Variant<_Types...>& __v){ 1821 return (__type_index<_Type,_Types...>::__value!=__v.index())?nullptr: &get<_Type>(__v);1821 return (__type_index<_Type,_Types...>::__value!=__v.index())?nullptr:std::addressof(get<_Type>(__v)); 1822 1822 } 1823 1823 1824 1824 template<typename _Type,typename ... _Types> 1825 1825 constexpr std::add_pointer_t<_Type const> get_if(Variant<_Types...> const& __v){ 1826 return (__type_index<_Type,_Types...>::__value!=__v.index())?nullptr: &get<_Type>(__v);1826 return (__type_index<_Type,_Types...>::__value!=__v.index())?nullptr:std::addressof(get<_Type>(__v)); 1827 1827 } 1828 1828 … … 1830 1830 constexpr std::add_pointer_t<typename __indexed_type<_Index,_Types...>::__type> get_if(Variant<_Types...>& __v){ 1831 1831 return ((_Index!=__v.index())?nullptr: 1832 &__variant_accessor<_Index,_Types...>::get(__v));1832 std::addressof(__variant_accessor<_Index,_Types...>::get(__v))); 1833 1833 } 1834 1834 … … 1837 1837 Variant<_Types...> const& __v){ 1838 1838 return ((_Index!=__v.index())?nullptr: 1839 &__variant_accessor<_Index,_Types...>::get(__v));1839 std::addressof(__variant_accessor<_Index,_Types...>::get(__v))); 1840 1840 } 1841 1841 -
trunk/Source/WebCore/ChangeLog
r215447 r215450 1 2017-04-17 Alex Christensen <achristensen@webkit.org> 2 3 Allow Variants of RetainPtrs 4 https://bugs.webkit.org/show_bug.cgi?id=170923 5 6 Reviewed by Tim Horton and Sam Weinig. 7 8 No change in behavior. Just updated the one class that used RetainPtr::operator& to cleanly initialize 9 RetainPtrs instead of taking the address of a smart pointer and forcing a value inside of it. 10 11 * platform/mac/SSLKeyGeneratorMac.mm: 12 (WebCore::signedPublicKeyAndChallengeString): 13 1 14 2017-04-17 Fujii Hironori <Hironori.Fujii@sony.com> 2 15 -
trunk/Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm
r209822 r215450 129 129 SignedPublicKeyAndChallenge signedPublicKeyAndChallenge { }; 130 130 131 RetainPtr<SecAccessRef> access; 132 if (SecAccessCreate(keyDescription.createCFString().get(), nullptr, &access) != noErr) 133 return String(); 134 135 RetainPtr<CFArrayRef> acls; 136 if (SecAccessCopySelectedACLList(access.get(), CSSM_ACL_AUTHORIZATION_DECRYPT, &acls) != noErr) 137 return String(); 131 SecAccessRef accessRef { nullptr }; 132 if (SecAccessCreate(keyDescription.createCFString().get(), nullptr, &accessRef) != noErr) 133 return String(); 134 RetainPtr<SecAccessRef> access = adoptCF(accessRef); 135 136 CFArrayRef aclsRef { nullptr }; 137 if (SecAccessCopySelectedACLList(access.get(), CSSM_ACL_AUTHORIZATION_DECRYPT, &aclsRef) != noErr) 138 return String(); 139 RetainPtr<CFArrayRef> acls = adoptCF(aclsRef); 138 140 139 141 SecACLRef acl = (SecACLRef)(CFArrayGetValueAtIndex(acls.get(), 0)); 140 142 141 143 // Passing nullptr to SecTrustedApplicationCreateFromPath tells that function to assume the application bundle. 142 RetainPtr<SecTrustedApplicationRef> trustedApp; 143 if (SecTrustedApplicationCreateFromPath(nullptr, &trustedApp) != noErr) 144 return String(); 144 SecTrustedApplicationRef trustedAppRef { nullptr }; 145 if (SecTrustedApplicationCreateFromPath(nullptr, &trustedAppRef) != noErr) 146 return String(); 147 RetainPtr<SecTrustedApplicationRef> trustedApp = adoptCF(trustedAppRef); 145 148 146 149 const CSSM_ACL_KEYCHAIN_PROMPT_SELECTOR defaultSelector = { … … 150 153 return String(); 151 154 152 RetainPtr<SecKeyRef> publicKey; 153 RetainPtr<SecKeyRef> privateKey; 154 if (SecKeyCreatePair(nullptr, CSSM_ALGID_RSA, keySize, 0, CSSM_KEYUSE_ANY, CSSM_KEYATTR_PERMANENT | CSSM_KEYATTR_EXTRACTABLE | CSSM_KEYATTR_RETURN_REF, CSSM_KEYUSE_ANY, CSSM_KEYATTR_SENSITIVE | CSSM_KEYATTR_RETURN_REF | CSSM_KEYATTR_PERMANENT | CSSM_KEYATTR_EXTRACTABLE, access.get(), &publicKey, &privateKey) != noErr) 155 return String(); 155 SecKeyRef publicKeyRef { nullptr }; 156 SecKeyRef privateKeyRef { nullptr }; 157 if (SecKeyCreatePair(nullptr, CSSM_ALGID_RSA, keySize, 0, CSSM_KEYUSE_ANY, CSSM_KEYATTR_PERMANENT | CSSM_KEYATTR_EXTRACTABLE | CSSM_KEYATTR_RETURN_REF, CSSM_KEYUSE_ANY, CSSM_KEYATTR_SENSITIVE | CSSM_KEYATTR_RETURN_REF | CSSM_KEYATTR_PERMANENT | CSSM_KEYATTR_EXTRACTABLE, access.get(), &publicKeyRef, &privateKeyRef) != noErr) 158 return String(); 159 RetainPtr<SecKeyRef> publicKey = adoptCF(publicKeyRef); 160 RetainPtr<SecKeyRef> privateKey = adoptCF(privateKeyRef); 156 161 157 162 CSSM_CSP_HANDLE cspHandle; -
trunk/Tools/ChangeLog
r215441 r215450 1 2017-04-17 Alex Christensen <achristensen@webkit.org> 2 3 Allow Variants of RetainPtrs 4 https://bugs.webkit.org/show_bug.cgi?id=170923 5 6 Reviewed by Tim Horton and Sam Weinig. 7 8 * TestWebKitAPI/Tests/WTF/Variant.cpp: 9 (TestWebKitAPI::TEST): 10 Add tests for RetainPtr and for another class with overloaded operator& to verify such classes can 11 work in Variants. 12 1 13 2017-04-17 Brady Eidson <beidson@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WTF/Variant.cpp
r207627 r215450 110 110 } 111 111 112 #if USE(CF) 113 TEST(WTF_Variant, RetainPtr) 114 { 115 enum class Type { 116 None, 117 RefPtr, 118 RetainPtr, 119 }; 120 121 Type type = Type::None; 122 123 auto visitor = WTF::makeVisitor( 124 [&](const RefPtr<RefLogger>&) { type = Type::RefPtr; }, 125 [&](const RetainPtr<CFDataRef>&) { type = Type::RetainPtr; } 126 ); 127 128 RefPtr<RefLogger> refPtr; 129 RetainPtr<CFDataRef> retainPtr; 130 Variant<RefPtr<RefLogger>, RetainPtr<CFDataRef>> variant(WTFMove(refPtr)); 131 WTF::visit(visitor, variant); 132 EXPECT_TRUE(Type::RefPtr == type); 133 134 variant = WTFMove(retainPtr); 135 WTF::visit(visitor, variant); 136 EXPECT_TRUE(Type::RetainPtr == type); 137 } 138 #endif 139 112 140 TEST(WTF_Variant, VisitorUsingMakeVisitor) 113 141 { … … 226 254 } 227 255 228 } 256 template<class T> 257 class Holder { 258 public: 259 T data; 260 261 Holder(T data) : data(data) { } 262 263 T* operator&() { return &data; } 264 }; 265 266 TEST(WTF_Variant, OperatorAmpersand) 267 { 268 Variant<Holder<int>, int> v = Holder<int>(10); 269 EXPECT_TRUE(WTF::get<Holder<int>>(v).data == 10); 270 271 v = 20; 272 EXPECT_TRUE(WTF::get<int>(v) == 20); 273 } 274 275 }
Note:
See TracChangeset
for help on using the changeset viewer.