[C++-sig] [boost.python] convert swig-wrapped c++-return values to python with boost.python

David Abrahams dave at boostpro.com
Sun Jul 20 20:30:28 CEST 2008


on Sun Jul 20 2008, Maximilian Matthe <Maxi.Matthe-AT-web.de> wrote:

> David Abrahams schrieb:
>> on Sun Jul 20 2008, Maximilian Matthe <Maxi.Matthe-AT-web.de> wrote:
>>
>>> David Abrahams schrieb:
>>>> on Sun Jul 20 2008, Maximilian Matthe <Maxi.Matthe-AT-web.de> wrote:
>>>>
>>>>> Hi!
>>>>>
>>>>> I still have the problem, that I have described below. I found out,
>>>>> that the same problem appears with any class that is not registered
>>>>> with boost.python but only with a custom converter. Returning values
>>>>> of those custom objects works fine, but returning pointers to existing
>>>>> objects gives the conversion error.
>>>> You probably need to register a converter for the pointer type
>>>> (wxWindow*) as well as the class type.  Actually I'd be a little
>>>> surprised if you were actually returning wxWindow by value.
>>>>
>>> I have already tried to add a converter for wxWindow*, but there were
>>> compiler errors that convert needs by value of const reference
>>> parameter.
>>
>>   wxWindow* const&
>>
>> ?
>>
>>> I dont want to return wxWindow by value, but by reference/adress. Thus
>>> the bp::reference_existing_object call policy.

You can't use that policy unless you're returning a Boost.Python-wrapped
class.  Its whole purpose in life is to make an instance of the class
where the C++ object is held by raw pointer.  I suggest you leave it out.

> Well, i checked that, but the problem remains:
> Heres the code:
>
> template <class Ptr>
> struct convert_wxObjectPtr
> {
>   static PyObject* convert(Ptr const& o)
>   {
>     PyObject* arg = wxPyMake_wxObject(const_cast<Ptr>(o), false);

I can't imagine what purpose that const_cast could serve.  Surely
wxPyMake_wxObject doesn't modify its first argument?  I suggest you
leave it out.

>     if(!arg)
>       throw python_error("Object is not convertible to wxPython!");
>     return arg;
>   }
> };
> // code generated by Py++
> struct IApp_wrapper : IApp, bp::wrapper< IApp > {
>   virtual wxWindow * GetWndMain(  ){
>     bp::override func_GetWndMain = this->get_override( "GetWndMain");
>     return func_GetWndMain(  );
>   }
> };

HTH,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the Cplusplus-sig mailing list