[C++-sig] call_method trouble?

Dirk Ulbricht fxdirk at insanesoftware.de
Mon Mar 10 20:00:32 CET 2003


Hi Dave,

I tested with the latest cvs, still the same results. I could narrow down
the problem a bit, though. Only methods that are defined in the
class-to-wrap can be called in the message handler, methods that are defined
in the Wrapper (but not in the base class, like python_handle) are visible
(print(dir(sender)) shows them) but they do not work. Do you have any ideas
on how to work around that?


- Dirk Ulbricht

-----Original Message-----
From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org] On Behalf
Of Dirk Ulbricht
Sent: Monday, March 10, 2003 6:24 PM
To: c++-sig at python.org
Subject: RE: [C++-sig] call_method trouble?

Hi Dave,

ok I'll be posting plain text.

I use the 1.29.00 (download from the website). As I started working with
boost.python, I tried the cvs version but at that time it didn't compile so
I just sticked with the website download. I'll try again.

The problem with the "virtual functions with default implementations"
approach is that the virtual wrapper and the forwarder need to have the same
method signature. However I couldn't find a way to wrap a method that takes
a void* parameter, that doesn't make much sense anyway. Since this parameter
is not needed in python I just omitted it. Also, FXObject::handle is not
meant to be overridden in python, it is just a bit different for objects
available to python. The infinite recursion could only happen if there are
cycles in the "message sending chain", which should never happen.

I'll try again with the latest cvs and let you know if that works better.
Thank you for your time.

- Dirk Ulbricht

-----Original Message-----
From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org] On Behalf
Of David Abrahams
Sent: Monday, March 10, 2003 5:47 PM
To: c++-sig at python.org; dave at boost-consulting.com
Subject: Re: [C++-sig] call_method trouble?


Dirk,

I think the fact that you are posting in HTML (I'm guessing) is
causing your code to be formatted badly in the mail messages.  Please
try posting in Plaintext.

It looks to me like FXObjectWrap::python_handle should be calling
FXObject::handle rather than the unqualified handle, because it will
cause an infinite recursion otherwise when invoked via the Python
onMessage callback.  Also, you should probably be using the "virtual
function with default implementation" wrapping formula described at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/p
ython/doc/tutorial/doc/virtual_functions_with_default_implementations.html.

One possible explanation for the problem is that type information is
lost when converting your FXObject* to a Python object in this line:

   long res = call_method<long>(o, method_name, boost::python::ptr(sender),
sel);

Are you using the latest CVS state or the 1.30.0 beta?  These are way
ahead of the 1.29.0 release in handling polymorphic classes.


"Dirk Ulbricht" <fxdirk at insanesoftware.de> writes:

> Hello,
>
>  
>
> first a big thank you to everone working on boost.python, this library
> rocks! However, I have come across a problem I just can not solve. I
> apologize for the length of the post, but in order to demonstrate the
> problem I had to include this code. This is the class I try to wrap:
>
>  
>
> class FXObject
>
>       {
>
> public:
>
>       virtual long handle(FXObject* sender, FXSelector sel, void* ptr)
>
>             {
>
>             }
>
> };

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig



_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig






More information about the Cplusplus-sig mailing list