Fixing Fake.h to use an interface in the list and compile Fake.h to check syntax.

This commit is contained in:
sergiotarxz 2022-08-02 07:21:57 +02:00
parent fba5287da2
commit 5e0d6e43fc
2 changed files with 9 additions and 19 deletions

View File

@ -1,4 +1,5 @@
#include "elfspy/Call.h"
#include "elfspy/Fake.h"
namespace spy
{

View File

@ -16,18 +16,12 @@ namespace spy
* The constructor installs the new function in place of the function, the
* destructor uninstalls it
*/
class Fake;
class FakeI {
};
extern std::vector<std::shared_ptr<FakeI>> fake_list;
template <typename H, typename ReturnType, typename... ArgTypes>
extern std::vector<std::shared_ptr<Fake>> 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[index]);
delete element;
}
}
class Fake
class Fake : FakeI
{
public:
Fake(H& hook, ReturnType (*func)(ArgTypes...));
@ -52,18 +46,13 @@ inline Fake<H, ReturnType, ArgTypes...>::~Fake()
hook_.patch(func_);
}
template <typename H, typename ReturnType, typename... ArgTypes>
void fake(H& hook, ReturnType (*patch)(ArgTypes...)) {
auto shared_ptr = std::make_shared<Fake<H, ReturnType, ArgTypes...>> (hook, patch);
fake_list.push_back (shared_ptr);
}
template <typename H, typename ReturnType, typename... ArgTypes>
inline auto new_fake(H& hook, ReturnType (*patch)(ArgTypes...))
-> Fake<H, ReturnType, ArgTypes...>*
{
return new Fake<H, ReturnType, ArgTypes...>(hook, patch);
auto instance = std::make_shared<Fake<H, ReturnType, ArgTypes...>>(hook, patch);
fake_list.push_back (instance);
return instance;
}
} // namespace elfspy