From 1d12e34b9f616da2ad5665f72818cca0a804f478 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Mar 2021 19:48:17 +0000 Subject: [PATCH] Fix for Mac OS X 10.14 The dllist was able to call delete during a destructor if a template flag was set. This flag is never set in snmalloc, and was included to enable reuse in another project. This was triggering an error on older mac builds. This PR calls a templated function when the DLList is destructed. Hence other projects can specify the `delete` behaviour if required. --- src/ds/dllist.h | 9 ++++----- src/ds/helpers.h | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ds/dllist.h b/src/ds/dllist.h index 915ce1b..ce40102 100644 --- a/src/ds/dllist.h +++ b/src/ds/dllist.h @@ -1,5 +1,7 @@ #pragma once +#include "helpers.h" + #include #include @@ -55,7 +57,7 @@ namespace snmalloc template< class T, class Terminator = std::nullptr_t, - bool delete_on_clear = false> + void on_clear(T*) = ignore> class DLList final { private: @@ -196,10 +198,7 @@ namespace snmalloc { auto c = head; remove(c); - if (delete_on_clear) - { - delete c; - } + on_clear(c); } } diff --git a/src/ds/helpers.h b/src/ds/helpers.h index 159db49..54e2322 100644 --- a/src/ds/helpers.h +++ b/src/ds/helpers.h @@ -142,4 +142,10 @@ namespace snmalloc return (*static_cast>(p))(args...); }; }; + + template + void ignore(T* t) + { + UNUSED(t); + } } // namespace snmalloc