Boost logo

Boost :

From: rwgk_at_[hidden]
Date: 2001-08-24 02:34:44

You could try something like this:

PyObject* MyObjectB::mem_function(params) {
        MyObjectA retVal;
        if (ok)
                return BOOST_PYTHON_CONVERSION::to_python(retVal);
                return boost::python::detail::none();

The instationation of class_builder<MyObjectA> must appear
*before* you use the to_python converter.

Related examples: do_it_yourself_cvts.cpp, pickle3.cpp.
do_it_yourself_cvts.cpp shows how you can fill a Python
list with your objects.

Another detail: I believe it would be best if your member
function returns a boost::python::ref. Only to_python
converters should return a bar PyObject*.
If you have a reason to stick with PyObject* as the
return value anyway, test your code for memory leaks.
Under Unix this is very easy: call the method a millon
times and monitor the memory allocation with the
"top" command.


--- In boost_at_y..., "Achim Domma" <achim.domma_at_s...> wrote:
> Hi,
> is there a possibility to convert instances of objects, which are
> in my module, to PyObjects*. The following works fine :
> MyObjectA MyObjectB::mem_function(params) {
> MyObjectA retVal;
> ...
> return retVal;
> }
> but this way I can't return 'None'. So I tried the following:
> PyObject* MyObjectB::mem_function(params) {
> MyObjectA retVal;
> if (ok)
> return retVal; // <- how to convert ???
> else
> return boost::details::none();
> }
> How can I get a PyObject out of my C++ Instance ? The same problem
> if I try to fill a python list with my own objects.
> I tried to find a solution in the sources and via
> could not find anything. If there is a solution I would be
absolutly happy
> with as point I can start searching.
> greetings
> Achim

Boost list run by bdawes at, gregod at, cpdaniel at, john at