I'm using Boost.Python to wrap a C++ library.
How do I ensure that the same Python instance (by object identity) is always returned for a particular C++ instance (by pointer identity)? I can't extend the C++ classes, but I can add a member variable (such as a PyObject * or a boost::python::handle<>) if that helps. I'm thinking that I should be able to cache the Python instance in the C++ instance, and return the cached instance instead of creating a new one. However, I can't figure out what wrapping code is required.
Example class to be wrapped:
class C {
public:
boost::python::handle<> wrapper_;
private:
C();
C(const C &);
~C();
};
Can anyone offer advice?