[C++-sig] shared_ptr and register_ptr_to_python

Marek Denis marek at octogan.net
Mon Oct 11 19:49:37 CEST 2010


On 11.10.2010 00:42, Jim Bosch wrote:

> Essentially, what you need to do is pass a Python object to call_method
> (boost::python::object or PyObject *) that already contains your C++
> object. In order to get one, you need need to tell Boost.Python to
> construct A and B with what it calls a "back reference". Your C++
> constructors will be given a PyObject* by boost.python, pointing to the
> Python objects the C++ object will be wrapped in, and you can then store
> those as data members and pass the PyObject * to call_method. You can
> find more information in the Boost.Python reference docs on class_,
> especially the "HeldType Semantics" section.

I did checked the docs, but I think I don't get how should it be done in 
my case. What they talk about (as well as in the provided example)
They let the user to create Python classes derived from C++ classes and 
launchind virtual Python function. Would ou mind providing a sample 
piece of code how should it be done to wrap my C++ object into PyObject* 
? Thanks in advance.

> By the way, the call policies on your "gen" function should be
> return_value_policy<manage_new_object>, not return_internal_reference<>;
> the latter is for returning data members of wrapped classes and other
> things that are owned by another existing wrapped object.

Good point, thanks!


-- 
regards

Marek Denis



More information about the Cplusplus-sig mailing list