Skip to content

Commit 558ead9

Browse files
committed
Removed platform check for Pointer.get_virtual_func
- Added Pointer.make_virtual_function
1 parent 4e766d2 commit 558ead9

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/core/modules/memory/memory_callback.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ using namespace DynamicHooks;
3939

4040

4141
// ============================================================================
42-
// >> CLASSES
42+
// >> MACROS
4343
// ============================================================================
4444
#define GET_CALLBACK_CALLER(type) \
4545
GET_FUNCTION(type, CallbackCaller<type>, CCallback*, unsigned long, unsigned long)
4646

47+
48+
// ============================================================================
49+
// >> CLASSES
50+
// ============================================================================
4751
CCallback::CCallback(object oCallback, Convention_t eConv, char* szParams)
4852
: CFunction(NULL, eConv, szParams)
4953
{

src/core/modules/memory/memory_tools.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,11 @@ void CPointer::Move(object oDest, unsigned long ulNumBytes)
165165
memmove((void *) ulDest, (void *) m_ulAddr, ulNumBytes);
166166
}
167167

168-
CPointer* CPointer::GetVirtualFunc(int iIndex, bool bPlatformCheck /* = true */)
168+
CPointer* CPointer::GetVirtualFunc(int iIndex)
169169
{
170170
if (!IsValid())
171171
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Pointer is NULL.")
172172

173-
#ifdef __linux__
174-
if (bPlatformCheck)
175-
iIndex++;
176-
#endif
177-
178173
void** vtable = *(void ***) m_ulAddr;
179174
if (!vtable)
180175
return new CPointer();
@@ -190,6 +185,11 @@ CFunction* CPointer::MakeFunction(Convention_t eConv, char* szParams)
190185
return new CFunction(m_ulAddr, eConv, szParams);
191186
}
192187

188+
CFunction* CPointer::MakeVirtualFunction(int iIndex, Convention_t eConv, char* szParams)
189+
{
190+
return GetVirtualFunc(iIndex)->MakeFunction(eConv, szParams);
191+
}
192+
193193
//-----------------------------------------------------------------------------
194194
// CFunction class
195195
//-----------------------------------------------------------------------------

src/core/modules/memory/memory_tools.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ class CPointer
187187

188188
bool IsValid() { return m_ulAddr != 0; }
189189

190-
CPointer* GetVirtualFunc(int iIndex, bool bPlatformCheck = true);
190+
CPointer* GetVirtualFunc(int iIndex);
191191

192192
void Realloc(int iSize) { m_ulAddr = (unsigned long) UTIL_Realloc((void *) m_ulAddr, iSize); }
193193
void Dealloc() { UTIL_Dealloc((void *) m_ulAddr); m_ulAddr = 0; }
194194

195195
CFunction* MakeFunction(Convention_t eConv, char* szParams);
196+
CFunction* MakeVirtualFunction(int iIndex, Convention_t eConv, char* szParams);
197+
196198

197199
public:
198200
unsigned long m_ulAddr;

src/core/modules/memory/memory_wrap_python.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_ptr_overload, SetPtr, 1, 2)
175175
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_ptr_overload, SetStringPtr, 1, 2)
176176
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_array_overload, SetStringArray, 1, 2)
177177

178-
// Other overloads
179-
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(get_virtual_func_overload, GetVirtualFunc, 1, 2)
180-
181178
void export_memtools()
182179
{
183180
class_<CPointer>("Pointer", init< optional<unsigned long> >())
@@ -255,10 +252,23 @@ void export_memtools()
255252
// Other methods
256253
.def("get_virtual_func",
257254
&CPointer::GetVirtualFunc,
258-
get_virtual_func_overload(
259-
"Returns the address (as a CPointer instance) of a virtual function at the given index.",
260-
args("index", "platform_check")
261-
)[manage_new_object_policy()]
255+
"Returns the address (as a CPointer instance) of a virtual function at the given index.",
256+
args("index"),
257+
manage_new_object_policy()
258+
)
259+
260+
.def("make_function",
261+
&CPointer::MakeFunction,
262+
"Creates a new Function instance.",
263+
args("convention", "parameters"),
264+
manage_new_object_policy()
265+
)
266+
267+
.def("make_virtual_function",
268+
&CPointer::MakeVirtualFunction,
269+
"Creates a new Function instance.",
270+
args("index", "convention", "parameters"),
271+
manage_new_object_policy()
262272
)
263273

264274
.def("realloc",
@@ -272,13 +282,6 @@ void export_memtools()
272282
"Deallocates a memory block."
273283
)
274284

275-
.def("make_function",
276-
&CPointer::MakeFunction,
277-
"Creates a new Function instance.",
278-
args("convention", "parameters"),
279-
manage_new_object_policy()
280-
)
281-
282285
.def("get_size",
283286
&CPointer::GetSize,
284287
"Returns the size of the memory block."

0 commit comments

Comments
 (0)