@@ -44,6 +44,7 @@ void export_memtools();
4444void export_dyncall ();
4545void export_dynamichooks ();
4646void export_callbacks ();
47+ void export_get_address ();
4748
4849DECLARE_SP_MODULE (memory_c)
4950{
@@ -52,6 +53,7 @@ DECLARE_SP_MODULE(memory_c)
5253 export_dyncall ();
5354 export_dynamichooks ();
5455 export_callbacks ();
56+ export_get_address ();
5557}
5658
5759// -----------------------------------------------------------------------------
@@ -109,7 +111,7 @@ void export_binaryfile()
109111
110112
111113// -----------------------------------------------------------------------------
112- // Exposes CPointer
114+ // Exposes CPointer and CFunction
113115// -----------------------------------------------------------------------------
114116#define OVERLOAD_GET_TYPE (name, type ) \
115117 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (get_##name##_overload, CPointer::Get<type>, 0 , 1 )
@@ -380,8 +382,7 @@ void export_memtools()
380382 def (" alloc" ,
381383 Alloc,
382384 " Allocates a memory block." ,
383- args (" size" ),
384- manage_new_object_policy ()
385+ args (" size" )
385386 );
386387
387388 class_<CFunction, bases<CPointer> >(" Function" , init<unsigned long , Convention_t, char *>())
@@ -481,6 +482,9 @@ void export_dynamichooks()
481482 ;
482483}
483484
485+ // -----------------------------------------------------------------------------
486+ // Exposes CCallback
487+ // -----------------------------------------------------------------------------
484488void export_callbacks ()
485489{
486490 class_< CCallback, bases< CFunction > >(" Callback" , init< object, Convention_t, char * >())
@@ -490,3 +494,43 @@ void export_callbacks()
490494 )
491495 ;
492496}
497+
498+
499+ // -----------------------------------------------------------------------------
500+ // Exposes wrap/get_address functionality
501+ // -----------------------------------------------------------------------------
502+ // Use this macro to add the ability to get the address of an object
503+ #define GET_ADDRESS (type ) \
504+ def (" get_address" , \
505+ &GetAddress<type>, \
506+ " Returns the memory address of the given object." , \
507+ args (" object" ) \
508+ );
509+
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), \
513+ &Wrap::WrapIt<type>, \
514+ "Wraps the given address.", \
515+ args(" pointer" ), \
516+ reference_existing_object_policy() \
517+ ).staticmethod(XSTRINGIFY(pyname))
518+
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)
522+
523+ void export_get_address()
524+ {
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+ ;
536+ }
0 commit comments