From 09ca4e4515fad3db887919be4b345fb41af36ee8 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Thu, 31 Dec 2020 10:10:00 +0100 Subject: [PATCH] swig: add helper get_PySwigObject --- include/eigenpy/swig.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/eigenpy/swig.hpp b/include/eigenpy/swig.hpp index 56f81cbf..0913ce66 100644 --- a/include/eigenpy/swig.hpp +++ b/include/eigenpy/swig.hpp @@ -5,6 +5,8 @@ #ifndef __eigenpy_swig_hpp__ #define __eigenpy_swig_hpp__ +#include "eigenpy/fwd.hpp" + namespace eigenpy { struct PySwigObject @@ -13,6 +15,19 @@ namespace eigenpy void * ptr; const char * desc; }; + + inline PySwigObject * get_PySwigObject(PyObject * pyObj) + { + if(!PyObject_HasAttrString(pyObj,"this")) + return NULL; + + PyObject * this_ptr = PyObject_GetAttrString(pyObj,"this"); + if(this_ptr == NULL) + return NULL; + PySwigObject * swig_obj = reinterpret_cast<PySwigObject*>(this_ptr); + + return swig_obj; + } } #endif // ifndef __eigenpy_swig_hpp__ -- GitLab