From 93e8257255d32ae79c1d2a0f077f111ee46d6392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 3 Apr 2025 11:56:06 +0200 Subject: [PATCH] workaround possible optimisation that would alter the value of the erase_counter The code is still not legal but works in practise. fix similar to 5853673267 --- STL_Extension/include/CGAL/Compact_container.h | 18 ++++++++++++++++++ .../CGAL/Concurrent_compact_container.h | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 9b6cb202e93..be4ff0f757c 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -177,6 +177,8 @@ namespace internal { template static void set_erase_counter(Element &, unsigned int) {} template + static void restore_erase_counter(Element*, unsigned int) {} + template static void increment_erase_counter(Element &) {} }; @@ -192,12 +194,24 @@ namespace internal { return e.erase_counter(); } + template + static unsigned int erase_counter(Element* e) + { + return e->erase_counter(); + } + template static void set_erase_counter(Element &e, unsigned int c) { e.set_erase_counter(c); } + template + static void restore_erase_counter(Element* e, unsigned int c) + { + e->set_erase_counter(c); + } + template static void increment_erase_counter(Element &e) { @@ -402,9 +416,11 @@ public: pointer ret = free_list; free_list = clean_pointee(ret); const auto ts = Time_stamper::time_stamp(ret); + const auto ec = EraseCounterStrategy::erase_counter(ret); new (ret) value_type(std::forward(args)...); Time_stamper::restore_timestamp(ret, ts); Time_stamper::set_time_stamp(ret, time_stamp); + EraseCounterStrategy::restore_erase_counter(ret, ec); CGAL_assertion(type(ret) == USED); ++size_; return iterator(ret, 0); @@ -435,8 +451,10 @@ public: CGAL_precondition(type(ptr) == USED); EraseCounterStrategy::increment_erase_counter(*x); const auto ts = Time_stamper::time_stamp(ptr); + const auto ec = EraseCounterStrategy::erase_counter(*x); std::allocator_traits::destroy(alloc, ptr); Time_stamper::restore_timestamp(ptr, ts); + EraseCounterStrategy::restore_erase_counter(ptr, ec); put_on_free_list(ptr); --size_; diff --git a/STL_Extension/include/CGAL/Concurrent_compact_container.h b/STL_Extension/include/CGAL/Concurrent_compact_container.h index 653ea056e74..0672e8b8117 100644 --- a/STL_Extension/include/CGAL/Concurrent_compact_container.h +++ b/STL_Extension/include/CGAL/Concurrent_compact_container.h @@ -80,6 +80,8 @@ namespace CCC_internal { template static void set_erase_counter(Element &, unsigned int) {} template + static void restore_erase_counter(Element*, unsigned int) {} + template static void increment_erase_counter(Element &) {} }; @@ -95,12 +97,24 @@ namespace CCC_internal { return e.erase_counter(); } + template + static unsigned int erase_counter(Element* e) + { + return e->erase_counter(); + } + template static void set_erase_counter(Element &e, unsigned int c) { e.set_erase_counter(c); } + template + static void restore_erase_counter(Element* e, unsigned int c) + { + e->set_erase_counter(c); + } + template static void increment_erase_counter(Element &e) { @@ -353,9 +367,11 @@ public: pointer ret = init_insert(fl); auto erase_counter = EraseCounterStrategy::erase_counter(*ret); const auto ts = Time_stamper::time_stamp(ret); + const auto ec = EraseCounterStrategy::erase_counter(ret); new (ret) value_type(std::forward(args)...); Time_stamper::restore_timestamp(ret, ts); EraseCounterStrategy::set_erase_counter(*ret, erase_counter); + EraseCounterStrategy::restore_erase_counter(ret, ec); return finalize_insert(ret, fl); } @@ -386,8 +402,10 @@ private: auto ptr = &*x; const auto ts = Time_stamper::time_stamp(ptr); + const auto ec = EraseCounterStrategy::erase_counter(*x); std::allocator_traits::destroy(m_alloc, &*x); Time_stamper::restore_timestamp(ptr, ts); + EraseCounterStrategy::restore_erase_counter(ptr, ec); put_on_free_list(&*x, fl); }