Title: [221560] trunk/Source
Revision
221560
Author
[email protected]
Date
2017-09-03 18:00:25 -0700 (Sun, 03 Sep 2017)

Log Message

[WTF] Add C++03 allocator interface for GCC < 6
https://bugs.webkit.org/show_bug.cgi?id=176301

Reviewed by Darin Adler.

Source/_javascript_Core:

* dfg/DFGObjectAllocationSinkingPhase.cpp:

Source/WTF:

Unfortunately, std::list in GCC < 6 does not support C++11 allocator interface.
This patch adds C++03 allocator interface to FastAllocator to make it usable
for std::list. It also allows us to use FastAllocator for data structures that
only support C++03 interface.

* wtf/FastMalloc.h:
(WTF::FastAllocator::allocate):
(WTF::FastAllocator::construct):
(WTF::FastAllocator::destroy):
(WTF::FastAllocator::max_size const):
(WTF::FastAllocator::select_on_container_copy_construction const):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (221559 => 221560)


--- trunk/Source/_javascript_Core/ChangeLog	2017-09-03 22:28:04 UTC (rev 221559)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-09-04 01:00:25 UTC (rev 221560)
@@ -1,3 +1,12 @@
+2017-09-03  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Add C++03 allocator interface for GCC < 6
+        https://bugs.webkit.org/show_bug.cgi?id=176301
+
+        Reviewed by Darin Adler.
+
+        * dfg/DFGObjectAllocationSinkingPhase.cpp:
+
 2017-09-03  Chris Dumez  <[email protected]>
 
         Unreviewed, rolling out r221555.

Modified: trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp (221559 => 221560)


--- trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp	2017-09-03 22:28:04 UTC (rev 221559)
+++ trunk/Source/_javascript_Core/dfg/DFGObjectAllocationSinkingPhase.cpp	2017-09-04 01:00:25 UTC (rev 221560)
@@ -1361,7 +1361,7 @@
         // Nodes without remaining unmaterialized fields will be
         // materialized first - amongst the remaining unmaterialized
         // nodes
-        std::list<Allocation> toMaterialize;
+        std::list<Allocation, FastAllocator<Allocation>> toMaterialize;
         auto firstPos = toMaterialize.begin();
         auto materializeFirst = [&] (Allocation&& allocation) {
             materialize(allocation.identifier());

Modified: trunk/Source/WTF/ChangeLog (221559 => 221560)


--- trunk/Source/WTF/ChangeLog	2017-09-03 22:28:04 UTC (rev 221559)
+++ trunk/Source/WTF/ChangeLog	2017-09-04 01:00:25 UTC (rev 221560)
@@ -1,3 +1,22 @@
+2017-09-03  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Add C++03 allocator interface for GCC < 6
+        https://bugs.webkit.org/show_bug.cgi?id=176301
+
+        Reviewed by Darin Adler.
+
+        Unfortunately, std::list in GCC < 6 does not support C++11 allocator interface.
+        This patch adds C++03 allocator interface to FastAllocator to make it usable
+        for std::list. It also allows us to use FastAllocator for data structures that
+        only support C++03 interface.
+
+        * wtf/FastMalloc.h:
+        (WTF::FastAllocator::allocate):
+        (WTF::FastAllocator::construct):
+        (WTF::FastAllocator::destroy):
+        (WTF::FastAllocator::max_size const):
+        (WTF::FastAllocator::select_on_container_copy_construction const):
+
 2017-09-03  Chris Dumez  <[email protected]>
 
         Unreviewed, rolling out r221552.

Modified: trunk/Source/WTF/wtf/FastMalloc.h (221559 => 221560)


--- trunk/Source/WTF/wtf/FastMalloc.h	2017-09-03 22:28:04 UTC (rev 221559)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2017-09-04 01:00:25 UTC (rev 221560)
@@ -124,6 +124,61 @@
     {
         fastFree(pointer);
     }
+
+#if COMPILER(GCC)
+#if !GCC_VERSION_AT_LEAST(6, 0, 0)
+    // This allocator also supports pre-C++11 STL allocator interface. This is a workaround for GCC < 6, which std::list
+    // does not support C++11 allocator.
+    // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55409
+
+    using pointer = value_type*;
+    using const_pointer = typename std::pointer_traits<pointer>::template rebind<value_type const>;
+    using void_pointer = typename std::pointer_traits<pointer>::template rebind<void>;
+    using const_void_pointer = typename std::pointer_traits<pointer>::template rebind<const void>;
+
+    using reference = T&;
+    using const_reference = const T&;
+
+    using difference_type = typename std::pointer_traits<pointer>::difference_type;
+    using size_type = std::make_unsigned_t<difference_type>;
+
+    template <class U> struct rebind {
+        using other = FastAllocator<U>;
+    };
+
+    value_type* allocate(std::size_t count, const_void_pointer)
+    {
+        return allocate(count);
+    }
+
+    template <class U, class ...Args>
+    void construct(U* p, Args&& ...args)
+    {
+        new (const_cast<void*>(static_cast<const void*>(p))) U(std::forward<Args>(args)...);
+    }
+
+    template <class U>
+    void destroy(U* p)
+    {
+        p->~U();
+    }
+
+    std::size_t max_size() const
+    {
+        return std::numeric_limits<size_type>::max();
+    }
+
+    FastAllocator<T> select_on_container_copy_construction() const
+    {
+        return *this;
+    }
+
+    using propagate_on_container_copy_assignment = std::false_type;
+    using propagate_on_container_move_assignment = std::false_type;
+    using propagate_on_container_swap = std::false_type;
+    using is_always_equal = std::is_empty<FastAllocator>;
+#endif // !GCC_VERSION_AT_LEAST(6, 0, 0)
+#endif // COMPILER(GCC)
 };
 
 template<typename T, typename U> inline bool operator==(const FastAllocator<T>&, const FastAllocator<U>&) { return true; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to