Skip to content

Commit c4c61ca

Browse files
committed
Added memory_c.TYPE_SIZES
- Removed DynCall functions
1 parent 779e11d commit c4c61ca

File tree

3 files changed

+28
-109
lines changed

3 files changed

+28
-109
lines changed

src/core/modules/memory/memory_callback.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// ============================================================================
3030
#include "memory_callback.h"
3131
#include "utility/wrap_macros.h"
32+
#include "utility/call_python.h"
3233

3334
#include "AsmJit.h"
3435
using namespace AsmJit;
@@ -207,6 +208,8 @@ object CallCallback(CCallback* pCallback, unsigned long ulEBP, unsigned long ulE
207208

208209
END_BOOST_PY_NORET()
209210

211+
PythonLog(0, "An exception occured while calling the Python callback. The server will now crash!");
212+
210213
// Throw an exception. We will crash now :(
211214
throw;
212215
}

src/core/modules/memory/memory_tools.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -199,51 +199,6 @@ class CPointer
199199
CFunction* MakeFunction(Convention_t eConv, char* szParams);
200200
CFunction* MakeVirtualFunction(int iIndex, Convention_t eConv, char* szParams);
201201

202-
// DynCall
203-
inline void ResetVM()
204-
{ dcReset(g_pCallVM); }
205-
206-
inline void SetMode(int iMode)
207-
{ dcMode(g_pCallVM, iMode); }
208-
209-
// A macro to shorten the implementation
210-
#define IMPLEMENT_DC(type, fname, dcname) \
211-
inline void SetArg##fname(type value) \
212-
{ dcArg##dcname(g_pCallVM, value); } \
213-
\
214-
inline type Call##fname() \
215-
{ return dcCall##dcname(g_pCallVM, m_ulAddr); }
216-
217-
IMPLEMENT_DC(bool, Bool, Bool)
218-
IMPLEMENT_DC(char, Char, Char)
219-
IMPLEMENT_DC(unsigned char, UChar, Char)
220-
IMPLEMENT_DC(short, Short, Short)
221-
IMPLEMENT_DC(unsigned short, UShort, Short)
222-
IMPLEMENT_DC(int, Int, Int)
223-
IMPLEMENT_DC(unsigned int, UInt, Int)
224-
IMPLEMENT_DC(long, Long, Long)
225-
IMPLEMENT_DC(unsigned long, ULong, Long)
226-
IMPLEMENT_DC(float, Float, Float)
227-
IMPLEMENT_DC(double, Double, Double)
228-
229-
inline void CallVoid()
230-
{ dcCallVoid(g_pCallVM, m_ulAddr); }
231-
232-
inline void SetArgPointer(object value)
233-
{
234-
unsigned long ptr = ExtractPyPtr(value);
235-
dcArgPointer(g_pCallVM, ptr);
236-
}
237-
238-
inline CPointer CallPointer()
239-
{ return CPointer(dcCallPointer(g_pCallVM, m_ulAddr)); }
240-
241-
inline void SetArgString(const char* value)
242-
{ dcArgPointer(g_pCallVM, (unsigned long) value); }
243-
244-
const char* CallString()
245-
{ return (const char *) dcCallPointer(g_pCallVM, m_ulAddr); }
246-
247202
public:
248203
unsigned long m_ulAddr;
249204
};

src/core/modules/memory/memory_wrap_python.cpp

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,6 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_ptr_overload, SetPtr, 1, 2)
171171
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_ptr_overload, SetStringPtr, 1, 2)
172172
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_string_array_overload, SetStringArray, 1, 2)
173173

174-
// These three macros ease the exposing part of DynCall
175-
#define EXPOSE_DC_SET(pyname, cppname) \
176-
.def("set_arg_" XSTRINGIFY(pyname), \
177-
&CPointer::SetArg##cppname, \
178-
args("value"), \
179-
"Adds a new parameter to the virtual machine." \
180-
)
181-
182-
#define EXPOSE_DC_CALL(pyname, cppname) \
183-
.def("call_" XSTRINGIFY(pyname), \
184-
&CPointer::Call##cppname, \
185-
"Calls the virtual machine." \
186-
)
187-
188-
#define EXPOSE_DC(pyname, cppname) \
189-
EXPOSE_DC_SET(pyname, cppname) \
190-
EXPOSE_DC_CALL(pyname, cppname)
191-
192174
void export_memtools()
193175
{
194176
class_<CPointer>("Pointer", init< optional<unsigned long> >())
@@ -251,33 +233,6 @@ void export_memtools()
251233
)
252234
)
253235

254-
// DynCall methods
255-
.def("reset_vm",
256-
&CPointer::ResetVM,
257-
"Resets the virtual machine."
258-
)
259-
260-
.def("set_mode",
261-
&CPointer::SetMode,
262-
"Sets the calling convention.",
263-
args("convention")
264-
)
265-
266-
EXPOSE_DC_CALL(void, Void)
267-
EXPOSE_DC(bool, Bool)
268-
EXPOSE_DC(char, Char)
269-
EXPOSE_DC(uchar, UChar)
270-
EXPOSE_DC(short, Short)
271-
EXPOSE_DC(ushort, UShort)
272-
EXPOSE_DC(int, Int)
273-
EXPOSE_DC(uint, UInt)
274-
EXPOSE_DC(long, Long)
275-
EXPOSE_DC(ulong, ULong)
276-
EXPOSE_DC(float, Float)
277-
EXPOSE_DC(double, Double)
278-
EXPOSE_DC(pointer, Pointer)
279-
EXPOSE_DC(string, String)
280-
281236
// Other methods
282237
.def("get_virtual_func",
283238
&CPointer::GetVirtualFunc,
@@ -497,7 +452,7 @@ void export_callbacks()
497452

498453

499454
//-----------------------------------------------------------------------------
500-
// Exposes wrap/get_address functionality
455+
// Exposes wrap/get_address/TYPE_SIZES functionality
501456
//-----------------------------------------------------------------------------
502457
// Use this macro to add the ability to get the address of an object
503458
#define GET_ADDRESS(type) \
@@ -507,30 +462,36 @@ void export_callbacks()
507462
args("object") \
508463
);
509464

510-
// Use this macro if the Python name of the type is different to the C++ name
511-
#define WRAP_ADDRESS0(type, pyname) \
512-
.def(XSTRINGIFY(pyname), \
465+
// Use this macro to add the ability to get the size of an object
466+
#define ADD_SIZE(type) \
467+
scope().attr("TYPE_SIZES")[XSTRINGIFY(type)] = sizeof(type);
468+
469+
// Use this macro to add the ability to wrap a pointer using an exposed class
470+
#define WRAP_POINTER(type) \
471+
cls.def(XSTRINGIFY(type), \
513472
&Wrap::WrapIt<type>, \
514473
"Wraps the given address.", \
515474
args("pointer"), \
516475
reference_existing_object_policy() \
517-
).staticmethod(XSTRINGIFY(pyname))
476+
).staticmethod(XSTRINGIFY(type));
518477

519-
// Use this macro if the Python and C++ name of the type are the same
520-
#define WRAP_ADDRESS1(type) \
521-
WRAP_ADDRESS0(type, type)
478+
// Use this macro to call the three macros all at once
479+
#define ADD_ALL(type) \
480+
GET_ADDRESS(type) \
481+
WRAP_POINTER(type) \
482+
ADD_SIZE(type)
522483

523484
void export_get_address()
524485
{
525-
// get_address()
526-
GET_ADDRESS(Vector)
527-
GET_ADDRESS(QAngle)
528-
529-
// wrap.<type>()
530-
class_<Wrap>("wrap", no_init)
531-
532-
WRAP_ADDRESS1(Vector)
533-
WRAP_ADDRESS1(QAngle)
534-
535-
;
486+
// Don't remove this! It's required for the WRAP_POINTER and ADD_SIZE macro.
487+
scope().attr("TYPE_SIZES") = dict();
488+
class_<Wrap> cls = class_<Wrap>("wrap", no_init);
489+
490+
// Add all classes here...
491+
// mathlib_c
492+
ADD_ALL(Vector)
493+
ADD_ALL(QAngle)
494+
ADD_ALL(Quaternion)
495+
ADD_ALL(cplane_t)
496+
ADD_ALL(RadianEuler)
536497
}

0 commit comments

Comments
 (0)