From 5a2fd1e25e1636a882991120e276ff4d5b3435be Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 18 Feb 2016 19:16:50 +0100 Subject: [PATCH] Adapt safe_ptr to build in this project --- include/kakoune/ref_ptr.hh | 8 ++++++++ include/kakoune/safe_ptr.hh | 25 ++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/kakoune/ref_ptr.hh b/include/kakoune/ref_ptr.hh index a061cff..692aa63 100644 --- a/include/kakoune/ref_ptr.hh +++ b/include/kakoune/ref_ptr.hh @@ -3,6 +3,10 @@ #include +#if !defined(NDEBUG) && !defined(KAK_DEBUG) +# define KAK_DEBUG +#endif + namespace Kakoune { @@ -122,4 +126,8 @@ struct RefCountable } +#if defined(KAK_DEBUG) +# undef KAK_DEBUG +#endif + #endif // ref_ptr_hh_INCLUDED diff --git a/include/kakoune/safe_ptr.hh b/include/kakoune/safe_ptr.hh index 12a9b4a..3ba71b3 100644 --- a/include/kakoune/safe_ptr.hh +++ b/include/kakoune/safe_ptr.hh @@ -3,9 +3,7 @@ // #define SAFE_PTR_TRACK_CALLSTACKS -#include "assert.hh" #include "ref_ptr.hh" -#include "backtrace.hh" #include #include @@ -15,6 +13,14 @@ #include #endif +#include + +#define kak_assert assert + +#if !defined(NDEBUG) && !defined(KAK_DEBUG) +# define KAK_DEBUG +#endif + namespace Kakoune { @@ -33,7 +39,7 @@ public: #endif } - friend void inc_ref_count(const SafeCountable* sc, void* ptr) + friend void inc_ref_count(const SafeCountable* sc, void* /*ptr*/) { ++sc->m_count; #ifdef SAFE_PTR_TRACK_CALLSTACKS @@ -41,7 +47,7 @@ public: #endif } - friend void dec_ref_count(const SafeCountable* sc, void* ptr) + friend void dec_ref_count(const SafeCountable* sc, void* /*ptr*/) { --sc->m_count; kak_assert(sc->m_count >= 0); @@ -53,7 +59,7 @@ public: #endif } - friend void ref_ptr_moved(const SafeCountable* sc, void* from, void* to) + friend void ref_ptr_moved(const SafeCountable* /*sc*/, void* /*from*/, void* /*to*/) { #ifdef SAFE_PTR_TRACK_CALLSTACKS auto it = std::find_if(sc->m_callstacks.begin(), sc->m_callstacks.end(), @@ -77,10 +83,10 @@ private: mutable int m_count; #else [[gnu::always_inline]] - friend void inc_ref_count(const SafeCountable* sc, void* ptr) {} + friend void inc_ref_count(const SafeCountable* /*sc*/, void* /*ptr*/) {} [[gnu::always_inline]] - friend void dec_ref_count(const SafeCountable* sc, void* ptr) {} + friend void dec_ref_count(const SafeCountable* /*sc*/, void* /*ptr*/) {} #endif }; @@ -92,4 +98,9 @@ using SafePtr = RefPtr>; } +#if defined(KAK_DEBUG) +# undef KAK_DEBUG +#endif +#undef kak_assert + #endif // safe_ptr_hh_INCLUDED