diff --git a/Fake.cpp b/Fake.cpp deleted file mode 100644 index 84d6e2a..0000000 --- a/Fake.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "elfspy/Fake.h" - -std::vector spy::fake_list; diff --git a/Hook.cpp b/Hook.cpp new file mode 100644 index 0000000..af4c128 --- /dev/null +++ b/Hook.cpp @@ -0,0 +1,13 @@ +#include + +std::vector spy::hook_list; + +void spy::delete_mocks (void) { + while (spy::hook_list.size () != 0) { + auto index = spy::hook_list.size () - 1; + auto element = spy::hook_list[index]; + + spy::hook_list.erase (spy::hook_list.begin() + index); + delete element; + } +} diff --git a/elfspy/Fake.h b/elfspy/Fake.h index d98ed8a..f748cf0 100644 --- a/elfspy/Fake.h +++ b/elfspy/Fake.h @@ -5,6 +5,7 @@ #include #include +#include namespace spy { @@ -18,20 +19,9 @@ namespace spy * destructor uninstalls it */ -class FakeI { -}; -extern std::vector fake_list; -void delete_mocks (void) { - while (fake_list.size () != 0) { - auto index = fake_list.size () - 1; - auto element = fake_list[index]; - fake_list.erase (fake_list.begin() + index); - delete element; - } -} template -class Fake : FakeI +class Fake { public: Fake(H& hook, ReturnType (*func)(ArgTypes...)); @@ -43,27 +33,30 @@ private: }; template -inline Fake:: +Fake:: Fake(H& hook, ReturnType (*func)(ArgTypes...)) :hook_(hook) { func_ = hook_.patch(func); } +/* template -inline Fake::~Fake() +Fake::~Fake() { + std::cout << "Fake" << std::endl; hook_.patch(func_); } template -inline auto new_fake(H& hook, ReturnType (*patch)(ArgTypes...)) - -> Fake* +Fake* new_fake(H& hook, ReturnType (*patch)(ArgTypes...)) { - auto instance = std::make_shared>(hook, patch); + std::cout << "hola" << std::endl; + auto instance = new Fake(hook, patch); fake_list.push_back (instance); return instance; } +*/ } // namespace elfspy diff --git a/elfspy/Hook.h b/elfspy/Hook.h index 368383d..8f4b3de 100644 --- a/elfspy/Hook.h +++ b/elfspy/Hook.h @@ -7,6 +7,9 @@ #include "elfspy/MethodInfo.h" #include "elfspy/Thunk.h" +#include +#include + namespace spy { @@ -20,6 +23,19 @@ namespace spy * are functions where the first type in Args... is the class type. */ + +class IHook { +public: + virtual ~IHook() { + std::cout << "HookI" << std::endl; + } + +}; + +extern std::vector hook_list; + +void delete_mocks (void); + template class Hook : public HookImpl { diff --git a/elfspy/Lambda.h b/elfspy/Lambda.h index 4299da4..fdd3b41 100644 --- a/elfspy/Lambda.h +++ b/elfspy/Lambda.h @@ -1,10 +1,12 @@ #ifndef ELFSPY_LAMBDA_H #define ELFSPY_LAMBDA_H +#include #include namespace spy { +extern std::vector hook_list; /** * @namespace spy @@ -16,7 +18,7 @@ namespace spy */ template -class Lambda +class Lambda : public IHook { public: Lambda(H& hook, L& lambda); @@ -56,20 +58,15 @@ ReturnType Lambda::function(ArgTypes... argtypes) return instance_->lambda_(std::forward(argtypes)...); } -template -inline auto fake(H& hook, L& lambda) - -> typename H::template Export::Type -{ - return { hook, lambda }; -} - template inline auto new_fake(H& hook, L& lambda) -> typename H::template Export::Type* { using Install = typename H::template Export::Type; - return new Install(hook, lambda); + auto instance = new Install(hook, lambda); + hook_list.push_back (instance); + return instance; } } // namespace elfspy diff --git a/meson.build b/meson.build index afe1c52..9211150 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,7 @@ pkg = import('pkgconfig') sources = [ 'Call.cpp', + 'Hook.cpp', 'Report.cpp', 'ELFInfo.cpp', 'SPY.cpp', @@ -11,7 +12,6 @@ sources = [ 'GOTEntry.cpp', 'Fail.cpp', 'MFile.cpp', - 'Fake.cpp', ] headers = [