1.1 --- a/sourcehook/generate/sourcehook.h Fri Nov 09 21:14:37 2007 +0000
1.2 +++ b/sourcehook/generate/sourcehook.h Sat Nov 10 16:10:55 2007 +0000
1.3 @@ -35,6 +35,11 @@
1.4 // 1 - standard
1.5 #define SH_HOOKMAN_VERSION 1
1.6
1.7 +// Hookmanautogen versions
1.8 +// 1 - initial
1.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
1.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
1.11 +
1.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
1.13 // It's used in various macros
1.14 #ifndef SH_GLOB_SHPTR
1.15 @@ -472,6 +477,17 @@
1.16 virtual void EndContext(IHookContext *pCtx) = 0;
1.17 };
1.18
1.19 +
1.20 + class IHookManagerAutoGen
1.21 + {
1.22 + public:
1.23 + virtual int GetIfaceVersion() = 0;
1.24 + virtual int GetImplVersion() = 0;
1.25 +
1.26 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
1.27 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
1.28 + };
1.29 +
1.30 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
1.31 // These have to be able to return references. If T is a reference, the pointers returned
1.32 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
2.1 --- a/sourcehook/generate/sourcehook.hxx Fri Nov 09 21:14:37 2007 +0000
2.2 +++ b/sourcehook/generate/sourcehook.hxx Sat Nov 10 16:10:55 2007 +0000
2.3 @@ -35,6 +35,11 @@
2.4 // 1 - standard
2.5 #define SH_HOOKMAN_VERSION 1
2.6
2.7 +// Hookmanautogen versions
2.8 +// 1 - initial
2.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
2.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
2.11 +
2.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
2.13 // It's used in various macros
2.14 #ifndef SH_GLOB_SHPTR
2.15 @@ -472,6 +477,17 @@
2.16 virtual void EndContext(IHookContext *pCtx) = 0;
2.17 };
2.18
2.19 +
2.20 + class IHookManagerAutoGen
2.21 + {
2.22 + public:
2.23 + virtual int GetIfaceVersion() = 0;
2.24 + virtual int GetImplVersion() = 0;
2.25 +
2.26 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
2.27 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
2.28 + };
2.29 +
2.30 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
2.31 // These have to be able to return references. If T is a reference, the pointers returned
2.32 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
3.1 --- a/sourcehook/sourcehook.cpp Fri Nov 09 21:14:37 2007 +0000
3.2 +++ b/sourcehook/sourcehook.cpp Sat Nov 10 16:10:55 2007 +0000
3.3 @@ -151,6 +151,25 @@
3.4
3.5 return true;
3.6 }
3.7 +
3.8 + bool CProto::ExactlyEqual(const CProto &other) const
3.9 + {
3.10 + if (m_Version != other.m_Version ||
3.11 + m_NumOfParams != other.m_NumOfParams ||
3.12 + m_Convention != other.m_Convention ||
3.13 + GetRet() != other.GetRet())
3.14 + {
3.15 + return false;
3.16 + }
3.17 +
3.18 + for (int i = 0; i < m_NumOfParams; ++i)
3.19 + {
3.20 + if(GetParam(i) != other.GetParam(i))
3.21 + return false;
3.22 + }
3.23 +
3.24 + return true;
3.25 + }
3.26
3.27 //////////////////////////////////////////////////////////////////////////
3.28 // CHookManager
4.1 --- a/sourcehook/sourcehook.h Fri Nov 09 21:14:37 2007 +0000
4.2 +++ b/sourcehook/sourcehook.h Sat Nov 10 16:10:55 2007 +0000
4.3 @@ -35,6 +35,11 @@
4.4 // 1 - standard
4.5 #define SH_HOOKMAN_VERSION 1
4.6
4.7 +// Hookmanautogen versions
4.8 +// 1 - initial
4.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
4.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
4.11 +
4.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
4.13 // It's used in various macros
4.14 #ifndef SH_GLOB_SHPTR
4.15 @@ -472,6 +477,17 @@
4.16 virtual void EndContext(IHookContext *pCtx) = 0;
4.17 };
4.18
4.19 +
4.20 + class IHookManagerAutoGen
4.21 + {
4.22 + public:
4.23 + virtual int GetIfaceVersion() = 0;
4.24 + virtual int GetImplVersion() = 0;
4.25 +
4.26 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
4.27 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
4.28 + };
4.29 +
4.30 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
4.31 // These have to be able to return references. If T is a reference, the pointers returned
4.32 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
5.1 --- a/sourcehook/sourcehook_hookmangen.cpp Fri Nov 09 21:14:37 2007 +0000
5.2 +++ b/sourcehook/sourcehook_hookmangen.cpp Sat Nov 10 16:10:55 2007 +0000
5.3 @@ -15,6 +15,7 @@
5.4 // http://www.angelcode.com/dev/callconv/callconv.html
5.5 // http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-1.html
5.6
5.7 +#include "sourcehook_impl.h"
5.8 #include "sourcehook_hookmangen.h"
5.9 #include "sourcehook_hookmangen_x86.h"
5.10 #include "sh_memory.h"
5.11 @@ -47,7 +48,7 @@
5.12 }
5.13
5.14 GenContext::GenContext(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx, ISourceHook *pSHPtr)
5.15 - : m_Proto(proto), m_VtblOffs(vtbl_offs), m_VtblIdx(vtbl_idx), m_SHPtr(pSHPtr),
5.16 + : m_GeneratedPubFunc(NULL), m_Proto(proto), m_VtblOffs(vtbl_offs), m_VtblIdx(vtbl_idx), m_SHPtr(pSHPtr),
5.17 m_pHI(NULL), m_HookfuncVfnptr(NULL), m_RegCounter(0)
5.18 {
5.19 m_pHI = new void*;
5.20 @@ -1652,5 +1653,91 @@
5.21 GenerateHookFunc();
5.22 return fastdelegate::detail::horrible_cast<HookManagerPubFunc>(GeneratePubFunc());
5.23 }
5.24 +
5.25 + HookManagerPubFunc GenContext::GetPubFunc()
5.26 + {
5.27 + if (m_GeneratedPubFunc == 0)
5.28 + m_GeneratedPubFunc = Generate();
5.29 +
5.30 + return m_GeneratedPubFunc;
5.31 + }
5.32 +
5.33 + bool GenContext::Equal(const CProto &proto, int vtbl_offs, int vtbl_idx)
5.34 + {
5.35 + return (m_Proto.ExactlyEqual(proto) && m_VtblOffs == vtbl_offs && m_VtblIdx == vtbl_idx);
5.36 + }
5.37 +
5.38 + bool GenContext::Equal(HookManagerPubFunc other)
5.39 + {
5.40 + return m_GeneratedPubFunc == other;
5.41 + }
5.42 +
5.43 + // *********************************** class GenContextContainer
5.44 + CHookManagerAutoGen::CHookManagerAutoGen(ISourceHook *pSHPtr) : m_pSHPtr(pSHPtr)
5.45 + {
5.46 + }
5.47 +
5.48 + CHookManagerAutoGen::~CHookManagerAutoGen()
5.49 + {
5.50 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
5.51 + {
5.52 + delete iter->m_GenContext;
5.53 + }
5.54 + }
5.55 +
5.56 + int CHookManagerAutoGen::GetIfaceVersion()
5.57 + {
5.58 + return SH_HOOKMANAUTOGEN_IFACE_VERSION;
5.59 + }
5.60 +
5.61 + int CHookManagerAutoGen::GetImplVersion()
5.62 + {
5.63 + return SH_HOOKMANAUTOGEN_IMPL_VERSION;
5.64 + }
5.65 +
5.66 + HookManagerPubFunc CHookManagerAutoGen::MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx)
5.67 + {
5.68 + CProto mproto(proto);
5.69 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
5.70 + {
5.71 + if (iter->m_GenContext->Equal(mproto, vtbl_offs, vtbl_idx))
5.72 + {
5.73 + iter->m_RefCnt++;
5.74 + return iter->m_GenContext->GetPubFunc();
5.75 + }
5.76 + }
5.77 +
5.78 + // Not found yet -> new one
5.79 + StoredContext sctx;
5.80 + sctx.m_RefCnt = 1;
5.81 + sctx.m_GenContext = new GenContext(proto, vtbl_offs, vtbl_idx, m_pSHPtr);
5.82 +
5.83 + if (sctx.m_GenContext->GetPubFunc() == NULL)
5.84 + {
5.85 + return NULL;
5.86 + }
5.87 + else
5.88 + {
5.89 + m_Contexts.push_back(sctx);
5.90 + return sctx.m_GenContext->GetPubFunc();
5.91 + }
5.92 + }
5.93 +
5.94 + void CHookManagerAutoGen::ReleaseHookMan(HookManagerPubFunc pubFunc)
5.95 + {
5.96 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
5.97 + {
5.98 + if (iter->m_GenContext->Equal(pubFunc))
5.99 + {
5.100 + iter->m_RefCnt--;
5.101 + if (iter->m_RefCnt == 0)
5.102 + {
5.103 + delete iter->m_GenContext;
5.104 + m_Contexts.erase(iter);
5.105 + }
5.106 + break;
5.107 + }
5.108 + }
5.109 + }
5.110 }
5.111 }
6.1 --- a/sourcehook/sourcehook_hookmangen.h Fri Nov 09 21:14:37 2007 +0000
6.2 +++ b/sourcehook/sourcehook_hookmangen.h Sat Nov 10 16:10:55 2007 +0000
6.3 @@ -11,7 +11,6 @@
6.4 #ifndef __SOURCEHOOK_HOOKMANGEN_H__
6.5 #define __SOURCEHOOK_HOOKMANGEN_H__
6.6
6.7 -#include "sourcehook_impl.h"
6.8 #include "sh_pagealloc.h"
6.9
6.10 namespace SourceHook
6.11 @@ -158,6 +157,8 @@
6.12 const static int SIZE_PTR = sizeof(void*);
6.13 const static int PassFlag_ForcedByRef = (1<<30); // ByVal in source, but actually passed by reference (GCC) -> private pass, destruct
6.14
6.15 + HookManagerPubFunc m_GeneratedPubFunc;
6.16 +
6.17 CProto m_Proto;
6.18 int m_VtblOffs;
6.19 int m_VtblIdx;
6.20 @@ -231,13 +232,40 @@
6.21 void BuildProtoInfo();
6.22 void *GenerateHookFunc();
6.23 void *GeneratePubFunc();
6.24 +
6.25 + HookManagerPubFunc Generate();
6.26 public:
6.27 // Level 1 -> Public interface
6.28 GenContext(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx, ISourceHook *pSHPtr);
6.29 ~GenContext();
6.30
6.31 - HookManagerPubFunc Generate();
6.32 + bool Equal(const CProto &proto, int vtbl_offs, int vtbl_idx);
6.33 + bool Equal(HookManagerPubFunc other);
6.34 +
6.35 + HookManagerPubFunc GetPubFunc();
6.36 };
6.37 +
6.38 + class CHookManagerAutoGen : public IHookManagerAutoGen
6.39 + {
6.40 + struct StoredContext
6.41 + {
6.42 + int m_RefCnt;
6.43 + GenContext *m_GenContext;
6.44 + };
6.45 + List<StoredContext> m_Contexts;
6.46 + ISourceHook *m_pSHPtr;
6.47 +
6.48 + public:
6.49 + CHookManagerAutoGen(ISourceHook *pSHPtr);
6.50 + ~CHookManagerAutoGen();
6.51 +
6.52 + int GetIfaceVersion();
6.53 + int GetImplVersion();
6.54 +
6.55 + HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx);
6.56 + void ReleaseHookMan(HookManagerPubFunc pubFunc);
6.57 + };
6.58 +
6.59 }
6.60 }
6.61
7.1 --- a/sourcehook/sourcehook_impl_cproto.h Fri Nov 09 21:14:37 2007 +0000
7.2 +++ b/sourcehook/sourcehook_impl_cproto.h Sat Nov 10 16:10:55 2007 +0000
7.3 @@ -26,6 +26,21 @@
7.4 void *pCopyCtor;
7.5 void *pDtor;
7.6 void *pAssignOperator;
7.7 +
7.8 + bool operator == (const IntPassInfo &other) const
7.9 + {
7.10 + return size == other.size
7.11 + && type == other.type
7.12 + && flags == other.flags
7.13 + && pNormalCtor == other.pNormalCtor
7.14 + && pDtor == other.pDtor
7.15 + && pAssignOperator == other.pAssignOperator;
7.16 + }
7.17 +
7.18 + bool operator != (const IntPassInfo &other) const
7.19 + {
7.20 + return !(*this == other);
7.21 + }
7.22 };
7.23
7.24 class CProto
7.25 @@ -72,6 +87,8 @@
7.26
7.27 bool operator == (const CProto &other) const;
7.28
7.29 + bool ExactlyEqual(const CProto &other) const;
7.30 +
7.31 int GetVersion() const
7.32 {
7.33 return m_Version;
8.1 --- a/sourcehook/test/main.cpp Fri Nov 09 21:14:37 2007 +0000
8.2 +++ b/sourcehook/test/main.cpp Sat Nov 10 16:10:55 2007 +0000
8.3 @@ -13,6 +13,7 @@
8.4
8.5 #include "sourcehook_impl.h"
8.6 #include "sourcehook.h"
8.7 +#include "sourcehook_hookmangen.h"
8.8
8.9 using namespace std;
8.10 bool g_Verbose;
8.11 @@ -111,3 +112,14 @@
8.12 {
8.13 static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
8.14 }
8.15 +
8.16 +SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
8.17 +{
8.18 + return new SourceHook::Impl::CHookManagerAutoGen(shptr);
8.19 +}
8.20 +
8.21 +void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
8.22 +{
8.23 + delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
8.24 +}
8.25 +
9.1 --- a/sourcehook/test/sourcehook_test.h Fri Nov 09 21:14:37 2007 +0000
9.2 +++ b/sourcehook/test/sourcehook_test.h Sat Nov 10 16:10:55 2007 +0000
9.3 @@ -34,3 +34,16 @@
9.4 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
9.5 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
9.6 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
9.7 +
9.8 +SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *pSHPtr);
9.9 +void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr);
9.10 +
9.11 +struct CHMAGAutoDestruction
9.12 +{
9.13 + SourceHook::IHookManagerAutoGen *m_Ptr;
9.14 + CHMAGAutoDestruction(SourceHook::IHookManagerAutoGen *ptr) : m_Ptr(ptr) {}
9.15 + ~CHMAGAutoDestruction() { Test_HMAG_Delete(m_Ptr); }
9.16 +};
9.17 +
9.18 +
9.19 +#define GET_HMAG(var, shptr) var = Test_HMAG_Factory(shptr); CHMAGAutoDestruction __hmagautodestruction(var);
10.1 --- a/sourcehook/test/testhookmangen.cpp Fri Nov 09 21:14:37 2007 +0000
10.2 +++ b/sourcehook/test/testhookmangen.cpp Sat Nov 10 16:10:55 2007 +0000
10.3 @@ -2,7 +2,6 @@
10.4 #include "sourcehook.h"
10.5 #include "sourcehook_test.h"
10.6 #include "testevents.h"
10.7 -#include "sourcehook_hookmangen.h"
10.8 #include "sh_memory.h"
10.9 #include "sh_pagealloc.h"
10.10
10.11 @@ -23,6 +22,8 @@
10.12 SourceHook::ISourceHook *g_SHPtr;
10.13 SourceHook::Plugin g_PLID;
10.14
10.15 + SourceHook::IHookManagerAutoGen *g_HMAGPtr;
10.16 +
10.17 // PtrBuf(ptr) gives ptrs unique numbers
10.18 // in the order they appear
10.19 SourceHook::List<const void*> g_PtrHash;
10.20 @@ -254,7 +255,6 @@
10.21 }
10.22 }
10.23
10.24 -
10.25 // MyDelegate base class for other delegates
10.26 class MyDelegate : public SourceHook::ISHDelegate
10.27 {
10.28 @@ -415,6 +415,7 @@
10.29 bool TestHookManGen(std::string &error)
10.30 {
10.31 GET_SHPTR(g_SHPtr);
10.32 + GET_HMAG(g_HMAGPtr, g_SHPtr);
10.33 g_PLID = 1337;
10.34
10.35 // 5 Global constructors (g_O111_*)
10.36 @@ -463,9 +464,8 @@
10.37 NULL), "Test11 Part0");
10.38
10.39 setuppi_11();
10.40 - g_Genc11 = new SourceHook::Impl::GenContext(&protoinfo_11, 0, 0, g_SHPtr);
10.41 - g_Genc_ad11.set(g_Genc11);
10.42 - SourceHook::HookManagerPubFunc myhookman11 = g_Genc11->Generate();
10.43 + SourceHook::HookManagerPubFunc myhookman11 = g_HMAGPtr->MakeHookMan(&protoinfo_11, 0, 0); \
10.44 + CAutoReleaseHookMan arhm_11(myhookman11); \
10.45 int hook1_11, hook2_11, hook3_11, hook4_11;
10.46
10.47 TestClass11 *pTest11 = new TestClass11;
10.48 @@ -630,9 +630,8 @@
10.49 setuppi_110();
10.50 setupri_110();
10.51
10.52 - g_Genc110 = new SourceHook::Impl::GenContext(&protoinfo_110, 0, 0, g_SHPtr);
10.53 - g_Genc_ad110.set(g_Genc110);
10.54 - SourceHook::HookManagerPubFunc myhookman110 = g_Genc110->Generate();
10.55 + SourceHook::HookManagerPubFunc myhookman110 = g_HMAGPtr->MakeHookMan(&protoinfo_110, 0, 0); \
10.56 + CAutoReleaseHookMan arhm_110(myhookman110); \
10.57 int hook1_110, hook2_110, hook3_110, hook4_110;
10.58
10.59 TestClass110 *pTest110 = new TestClass110;
11.1 --- a/sourcehook/test/testhookmangen.h Fri Nov 09 21:14:37 2007 +0000
11.2 +++ b/sourcehook/test/testhookmangen.h Sat Nov 10 16:10:55 2007 +0000
11.3 @@ -1,3 +1,15 @@
11.4 +struct CAutoReleaseHookMan
11.5 +{
11.6 + SourceHook::HookManagerPubFunc m_Ptr;
11.7 + CAutoReleaseHookMan(SourceHook::HookManagerPubFunc ptr) : m_Ptr(ptr)
11.8 + {
11.9 + }
11.10 + ~CAutoReleaseHookMan()
11.11 + {
11.12 + g_HMAGPtr->ReleaseHookMan(m_Ptr);
11.13 + }
11.14 +};
11.15 +
11.16 // Strip &
11.17 template <class T> struct StripRef
11.18 {
11.19 @@ -520,9 +532,6 @@
11.20 SourceHook::PassInfo::V2Info paraminfos2_##id[0+1]; \
11.21 SourceHook::ProtoInfo protoinfo_##id = { 0, {0, 0, 0}, paraminfos_##id, \
11.22 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.23 - \
11.24 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.25 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.26
11.27
11.28 #define THGM_MAKE_TEST0(id, ret_type) \
11.29 @@ -621,8 +630,7 @@
11.30 SourceHook::ProtoInfo protoinfo_##id = { 0, {0, 0, 0}, paraminfos_##id, \
11.31 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.32 \
11.33 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.34 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.35 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.36
11.37 #define THGM_SETUP_PI0(id) \
11.38 void setuppi_##id() \
11.39 @@ -731,9 +739,6 @@
11.40 SourceHook::PassInfo::V2Info paraminfos2_##id[1+1]; \
11.41 SourceHook::ProtoInfo protoinfo_##id = { 1, {0, 0, 0}, paraminfos_##id, \
11.42 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.43 - \
11.44 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.45 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.46
11.47
11.48 #define THGM_MAKE_TEST1(id, ret_type, param1) \
11.49 @@ -832,8 +837,7 @@
11.50 SourceHook::ProtoInfo protoinfo_##id = { 1, {0, 0, 0}, paraminfos_##id, \
11.51 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.52 \
11.53 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.54 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.55 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.56
11.57 #define THGM_SETUP_PI1(id, p1_type, p1_passtype, p1_flags) \
11.58 void setuppi_##id() \
11.59 @@ -942,9 +946,6 @@
11.60 SourceHook::PassInfo::V2Info paraminfos2_##id[2+1]; \
11.61 SourceHook::ProtoInfo protoinfo_##id = { 2, {0, 0, 0}, paraminfos_##id, \
11.62 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.63 - \
11.64 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.65 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.66
11.67
11.68 #define THGM_MAKE_TEST2(id, ret_type, param1, param2) \
11.69 @@ -1043,8 +1044,7 @@
11.70 SourceHook::ProtoInfo protoinfo_##id = { 2, {0, 0, 0}, paraminfos_##id, \
11.71 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.72 \
11.73 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.74 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.75 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.76
11.77 #define THGM_SETUP_PI2(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags) \
11.78 void setuppi_##id() \
11.79 @@ -1153,9 +1153,6 @@
11.80 SourceHook::PassInfo::V2Info paraminfos2_##id[3+1]; \
11.81 SourceHook::ProtoInfo protoinfo_##id = { 3, {0, 0, 0}, paraminfos_##id, \
11.82 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.83 - \
11.84 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.85 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.86
11.87
11.88 #define THGM_MAKE_TEST3(id, ret_type, param1, param2, param3) \
11.89 @@ -1254,8 +1251,7 @@
11.90 SourceHook::ProtoInfo protoinfo_##id = { 3, {0, 0, 0}, paraminfos_##id, \
11.91 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.92 \
11.93 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.94 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.95 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.96
11.97 #define THGM_SETUP_PI3(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags) \
11.98 void setuppi_##id() \
11.99 @@ -1364,9 +1360,6 @@
11.100 SourceHook::PassInfo::V2Info paraminfos2_##id[4+1]; \
11.101 SourceHook::ProtoInfo protoinfo_##id = { 4, {0, 0, 0}, paraminfos_##id, \
11.102 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.103 - \
11.104 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.105 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.106
11.107
11.108 #define THGM_MAKE_TEST4(id, ret_type, param1, param2, param3, param4) \
11.109 @@ -1465,8 +1458,7 @@
11.110 SourceHook::ProtoInfo protoinfo_##id = { 4, {0, 0, 0}, paraminfos_##id, \
11.111 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.112 \
11.113 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.114 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.115 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.116
11.117 #define THGM_SETUP_PI4(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags) \
11.118 void setuppi_##id() \
11.119 @@ -1575,9 +1567,6 @@
11.120 SourceHook::PassInfo::V2Info paraminfos2_##id[5+1]; \
11.121 SourceHook::ProtoInfo protoinfo_##id = { 5, {0, 0, 0}, paraminfos_##id, \
11.122 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.123 - \
11.124 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.125 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.126
11.127
11.128 #define THGM_MAKE_TEST5(id, ret_type, param1, param2, param3, param4, param5) \
11.129 @@ -1676,8 +1665,7 @@
11.130 SourceHook::ProtoInfo protoinfo_##id = { 5, {0, 0, 0}, paraminfos_##id, \
11.131 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.132 \
11.133 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.134 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.135 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.136
11.137 #define THGM_SETUP_PI5(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags) \
11.138 void setuppi_##id() \
11.139 @@ -1786,9 +1774,6 @@
11.140 SourceHook::PassInfo::V2Info paraminfos2_##id[6+1]; \
11.141 SourceHook::ProtoInfo protoinfo_##id = { 6, {0, 0, 0}, paraminfos_##id, \
11.142 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.143 - \
11.144 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.145 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.146
11.147
11.148 #define THGM_MAKE_TEST6(id, ret_type, param1, param2, param3, param4, param5, param6) \
11.149 @@ -1887,8 +1872,7 @@
11.150 SourceHook::ProtoInfo protoinfo_##id = { 6, {0, 0, 0}, paraminfos_##id, \
11.151 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
11.152 \
11.153 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
11.154 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
11.155 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
11.156
11.157 #define THGM_SETUP_PI6(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags, p6_type, p6_passtype, p6_flags) \
11.158 void setuppi_##id() \
11.159 @@ -1931,9 +1915,8 @@
11.160
11.161 #define THGM_DO_TEST_void(id, call_params) \
11.162 setuppi_##id(); \
11.163 - g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
11.164 - g_Genc_ad##id.set(g_Genc##id); \
11.165 - SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
11.166 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(&protoinfo_##id, 0, 0); \
11.167 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
11.168 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
11.169 \
11.170 TestClass##id::ms_DoRecall = false; \
11.171 @@ -2050,9 +2033,8 @@
11.172 #define THGM_DO_TEST(id, call_params) \
11.173 setuppi_##id(); \
11.174 setupri_##id(); \
11.175 - g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
11.176 - g_Genc_ad##id.set(g_Genc##id); \
11.177 - SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
11.178 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(&protoinfo_##id, 0, 0); \
11.179 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
11.180 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
11.181 \
11.182 TestClass##id::ms_DoRecall = false; \
12.1 --- a/sourcehook/test/testhookmangen.hxx Fri Nov 09 21:14:37 2007 +0000
12.2 +++ b/sourcehook/test/testhookmangen.hxx Sat Nov 10 16:10:55 2007 +0000
12.3 @@ -1,3 +1,15 @@
12.4 +struct CAutoReleaseHookMan
12.5 +{
12.6 + SourceHook::HookManagerPubFunc m_Ptr;
12.7 + CAutoReleaseHookMan(SourceHook::HookManagerPubFunc ptr) : m_Ptr(ptr)
12.8 + {
12.9 + }
12.10 + ~CAutoReleaseHookMan()
12.11 + {
12.12 + g_HMAGPtr->ReleaseHookMan(m_Ptr);
12.13 + }
12.14 +};
12.15 +
12.16 // Strip &
12.17 template <class T> struct StripRef
12.18 {
12.19 @@ -262,9 +274,6 @@
12.20 SourceHook::PassInfo::V2Info paraminfos2_##id[$1+1]; \
12.21 SourceHook::ProtoInfo protoinfo_##id = { $1, {0, 0, 0}, paraminfos_##id, \
12.22 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
12.23 - \
12.24 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
12.25 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
12.26
12.27
12.28 #define THGM_MAKE_TEST$1(id, ret_type@[$2,1,$1:, param$2@]) \
12.29 @@ -363,8 +372,7 @@
12.30 SourceHook::ProtoInfo protoinfo_##id = { $1, {0, 0, 0}, paraminfos_##id, \
12.31 SourceHook::ProtoInfo::CallConv_ThisCall, __SH_EPI, paraminfos2_##id }; \
12.32 \
12.33 - SourceHook::Impl::GenContext *g_Genc##id = NULL; \
12.34 - CAutoPtrDestruction<SourceHook::Impl::GenContext> g_Genc_ad##id(NULL);
12.35 + CAutoReleaseHookMan g_Genc_ad##id(NULL);
12.36
12.37 #define THGM_SETUP_PI$1(id@[$2,1,$1:, p$2_type, p$2_passtype, p$2_flags@]) \
12.38 void setuppi_##id() \
12.39 @@ -407,9 +415,8 @@
12.40
12.41 #define THGM_DO_TEST_void(id, call_params) \
12.42 setuppi_##id(); \
12.43 - g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
12.44 - g_Genc_ad##id.set(g_Genc##id); \
12.45 - SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
12.46 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(&protoinfo_##id, 0, 0); \
12.47 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
12.48 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
12.49 \
12.50 TestClass##id::ms_DoRecall = false; \
12.51 @@ -526,9 +533,8 @@
12.52 #define THGM_DO_TEST(id, call_params) \
12.53 setuppi_##id(); \
12.54 setupri_##id(); \
12.55 - g_Genc##id = new SourceHook::Impl::GenContext(&protoinfo_##id, 0, 0, g_SHPtr); \
12.56 - g_Genc_ad##id.set(g_Genc##id); \
12.57 - SourceHook::HookManagerPubFunc myhookman##id = g_Genc##id->Generate(); \
12.58 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(&protoinfo_##id, 0, 0); \
12.59 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
12.60 int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
12.61 \
12.62 TestClass##id::ms_DoRecall = false; \