Fix SafeCountable and RefCountable copy/move logic

The safe and ref counts should not get copied around.
This commit is contained in:
Maxime Coste 2017-08-04 11:38:04 +07:00
parent 420c6aca23
commit 45a7496f54
4 changed files with 18 additions and 5 deletions

View File

@ -11,7 +11,7 @@ namespace Kakoune
class AliasRegistry : public SafeCountable
{
public:
AliasRegistry(AliasRegistry& parent) : m_parent(&parent) {}
AliasRegistry(AliasRegistry& parent) : SafeCountable{}, m_parent(&parent) {}
void add_alias(String alias, String command);
void remove_alias(StringView alias);
StringView operator[](StringView alias) const;

View File

@ -14,7 +14,7 @@ class Context;
class HookManager : public SafeCountable
{
public:
HookManager(HookManager& parent) : m_parent(&parent) {}
HookManager(HookManager& parent) : SafeCountable{}, m_parent(&parent) {}
void add_hook(StringView hook_name, String group, Regex filter, String commands);
void remove_hooks(StringView group);

View File

@ -8,8 +8,15 @@ namespace Kakoune
struct RefCountable
{
int refcount = 0;
RefCountable() = default;
RefCountable(const RefCountable&) {}
RefCountable(RefCountable&&) {}
virtual ~RefCountable() = default;
RefCountable& operator=(const RefCountable&) { return *this; }
RefCountable& operator=(RefCountable&&) { return *this; }
int refcount = 0;
};
struct RefCountablePolicy

View File

@ -24,7 +24,7 @@ class SafeCountable
{
public:
#ifdef KAK_DEBUG
SafeCountable() : m_count(0) {}
SafeCountable() {}
~SafeCountable()
{
kak_assert(m_count == 0);
@ -33,6 +33,12 @@ public:
#endif
}
SafeCountable(const SafeCountable&) {}
SafeCountable(SafeCountable&&) {}
SafeCountable& operator=(const SafeCountable& other) { return *this; }
SafeCountable& operator=(SafeCountable&& other) { return *this; }
private:
friend struct SafeCountablePolicy;
#ifdef SAFE_PTR_TRACK_CALLSTACKS
@ -45,7 +51,7 @@ private:
mutable Vector<Callstack> m_callstacks;
#endif
mutable int m_count;
mutable int m_count = 0;
#endif
};