WebKit Bugzilla
Attachment 370340 Details for
Bug 188799
: WeakPtr breaks vtables when upcasting to base classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
WIP patch to use static_cast instead of reinterpret_cast
ro.txt (text/plain), 6.51 KB, created by
Geoffrey Garen
on 2019-05-21 14:07:02 PDT
(
hide
)
Description:
WIP patch to use static_cast instead of reinterpret_cast
Filename:
MIME Type:
Creator:
Geoffrey Garen
Created:
2019-05-21 14:07:02 PDT
Size:
6.51 KB
patch
obsolete
>Index: Source/WTF/wtf/WeakHashSet.h >=================================================================== >--- Source/WTF/wtf/WeakHashSet.h (revision 245523) >+++ Source/WTF/wtf/WeakHashSet.h (working copy) >@@ -35,7 +35,7 @@ namespace WTF { > template <typename T> > class WeakHashSet { > public: >- typedef HashSet<Ref<WeakReference<T>>> WeakReferenceSet; >+ typedef HashSet<Ref<WeakReference<T::WeakValueType>>> WeakReferenceSet; > > class WeakHashSetConstIterator : public std::iterator<std::forward_iterator_tag, T, std::ptrdiff_t, const T*, const T&> { > private: >@@ -96,7 +96,7 @@ public: > template <typename U> > bool remove(const U& value) > { >- auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get()); >+ auto& weakReference = value.weakPtrFactory().m_ref; > if (!weakReference) > return false; > return m_set.remove(weakReference); >@@ -105,7 +105,7 @@ public: > template <typename U> > bool contains(const U& value) const > { >- auto* weakReference = weak_reference_downcast<T>(value.weakPtrFactory().m_ref.get()); >+ auto& weakReference = value.weakPtrFactory().m_ref; > if (!weakReference) > return false; > return m_set.contains(weakReference); >@@ -145,9 +145,9 @@ private: > WeakReferenceSet m_set; > }; > >-template<typename T> struct HashTraits<Ref<WeakReference<T>>> : RefHashTraits<WeakReference<T>> { >+template<typename T> struct HashTraits<Ref<WeakReference<T::WeakValueType>>> : RefHashTraits<WeakReference<T::WeakValueType>>> { > static const bool hasIsReleasedWeakValueFunction = true; >- static bool isReleasedWeakValue(const Ref<WeakReference<T>>& value) >+ static bool isReleasedWeakValue(const Ref<WeakReference<T::WeakValueType>>& value) > { > return !value.isHashTableDeletedValue() && !value.isHashTableEmptyValue() && !value.get().get(); > } >Index: Source/WTF/wtf/WeakPtr.h >=================================================================== >--- Source/WTF/wtf/WeakPtr.h (revision 245523) >+++ Source/WTF/wtf/WeakPtr.h (working copy) >@@ -67,21 +67,23 @@ template<typename T> > class WeakPtr { > WTF_MAKE_FAST_ALLOCATED; > public: >+ typedef typename T::WeakValueType WeakValueType; >+ > WeakPtr() { } > WeakPtr(std::nullptr_t) { } >- WeakPtr(Ref<WeakReference<T>>&& ref) : m_ref(std::forward<Ref<WeakReference<T>>>(ref)) { } >+ WeakPtr(Ref<WeakReference<WeakValueType>>&& ref) : m_ref(std::forward<Ref<WeakReference<WeakValueType>>>(ref)) { } > template<typename U> WeakPtr(const WeakPtr<U>&); > template<typename U> WeakPtr(WeakPtr<U>&&); > >- T* get() const { return m_ref ? m_ref->get() : nullptr; } >+ T* get() const { return m_ref ? static_cast<T*>(m_ref->get()) : nullptr; } > explicit operator bool() const { return m_ref && m_ref->get(); } > > WeakPtr& operator=(std::nullptr_t) { m_ref = nullptr; return *this; } > template<typename U> WeakPtr& operator=(const WeakPtr<U>&); > template<typename U> WeakPtr& operator=(WeakPtr<U>&&); > >- T* operator->() const { return m_ref->get(); } >- T& operator*() const { return *m_ref->get(); } >+ T* operator->() const { return static_cast<T*>(m_ref->get()); } >+ T& operator*() const { return *static_cast<T*>(m_ref->get()); } > > void clear() { m_ref = nullptr; } > >@@ -90,7 +92,7 @@ private: > template<typename> friend class WeakPtr; > template<typename U> friend WeakPtr<U> makeWeakPtr(U&); > >- RefPtr<WeakReference<T>> m_ref; >+ RefPtr<WeakReference<WeakValueType>> m_ref; > }; > > // Note: you probably want to inherit from CanMakeWeakPtr rather than use this directly. >@@ -138,6 +140,8 @@ private: > > template<typename T> class CanMakeWeakPtr { > public: >+ typedef T WeakValueType; >+ > const WeakPtrFactory<T>& weakPtrFactory() const { return m_weakFactory; } > WeakPtrFactory<T>& weakPtrFactory() { return m_weakFactory; } > >@@ -181,7 +185,7 @@ template<typename T> template<typename U > > template<typename T> inline WeakPtr<T> makeWeakPtr(T& ref) > { >- return { adoptRef(*weak_reference_downcast<T>(ref.weakPtrFactory().createWeakPtr(ref).m_ref.leakRef())) }; >+ return { ref.weakPtrFactory().createWeakPtr(ref) }; > } > > template<typename T> inline WeakPtr<T> makeWeakPtr(T* ptr) >Index: Source/WebCore/platform/Widget.cpp >=================================================================== >--- Source/WebCore/platform/Widget.cpp (revision 245523) >+++ Source/WebCore/platform/Widget.cpp (working copy) >@@ -42,12 +42,17 @@ void Widget::init(PlatformWidget widget) > retainPlatformWidget(); > } > >+ScrollView* Widget::parent() const >+{ >+ return static_cast<ScrollView*>(m_parent.get()); >+} >+ > void Widget::setParent(ScrollView* view) > { > ASSERT(!view || !m_parent); > if (!view || !view->isVisible()) > setParentVisible(false); >- m_parent = makeWeakPtr(view); >+ m_parent = makeWeakPtr(static_cast<Widget*>(view)); > if (view && view->isVisible()) > setParentVisible(true); > } >Index: Source/WebCore/platform/Widget.h >=================================================================== >--- Source/WebCore/platform/Widget.h (revision 245523) >+++ Source/WebCore/platform/Widget.h (working copy) >@@ -140,7 +140,7 @@ public: > > WEBCORE_EXPORT void removeFromParent(); > WEBCORE_EXPORT virtual void setParent(ScrollView* view); >- ScrollView* parent() const { return m_parent.get(); } >+ ScrollView* parent() const; > FrameView* root() const; > > virtual void handleEvent(Event&) { } >@@ -215,7 +215,7 @@ private: > bool m_selfVisible { false }; > bool m_parentVisible { false }; > >- WeakPtr<ScrollView> m_parent; >+ WeakPtr<Widget> m_parent; > #if !PLATFORM(COCOA) > PlatformWidget m_widget; > #else >Index: Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h >=================================================================== >--- Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h (revision 245523) >+++ Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h (working copy) >@@ -26,6 +26,7 @@ > #pragma once > > #include "LegacyCDMSession.h" >+#include "MediaPlayerPrivateAVFoundationObjC.h" > #include <wtf/RetainPtr.h> > #include <wtf/WeakPtr.h> > #include <wtf/text/WTFString.h> >@@ -37,8 +38,6 @@ OBJC_CLASS WebCDMSessionAVFoundationObjC > > namespace WebCore { > >-class MediaPlayerPrivateAVFoundationObjC; >- > class CDMSessionAVFoundationObjC : public LegacyCDMSession, public CanMakeWeakPtr<CDMSessionAVFoundationObjC> { > public: > CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent, LegacyCDMSessionClient*);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 188799
:
370317
|
370321
| 370340 |
370386
|
370776
|
370790
|
370792
|
370794
|
370809