[C++-sig] Re: Methods returning & taking pointers to functions

Niall Douglas s_sourceforge at nedprod.com
Sat Oct 4 01:19:19 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3 Oct 2003 at 17:53, David Abrahams wrote:

> > I see a two pronged approach: (i) make a pointer to a function an
> > opaque type and (ii) write a thunk which invokes an arbitrary python
> > function. The latter, through some small alterations to the base
> > library, could be entirely driven by parameters (all I need is a
> > pointer to the thing calling the sort function).
> >
> > Has anyone else tried this? Is it even possible? 
> 
> I think what you're asking for is an automatic conversion from a
> Python callable object to a C++ function pointer.
> 
> Well, no, it isn't possible, at least not in a reliable way.  That's
> because a C++ function pointer can't have any associated data, and
> you'd need some way to bind the callable Python object to it.

I was going to take a more traditional approach and have the sorting 
function caller pass "this" with the objects to be compared. Then a 
routine can look up the instance and call the correct piece of 
python.

I luckily can have the sources altered, though not significantly as 
it would break the ABI. Next major release probably.

> If you can change your interface to use, say, 
> 
>         boost::function2<bool, T, T>
> 
> I think we can come up with a solution.

Can't have any boost in the main C++ library, at least not yet. Not 
even the STL is permitted in FOX!

> > If BP can't wrap methods taking or receiving pointers to functions,
> > then it's a non- starter.
> 
> It may be that.  This isn't a Boost.Python issue.  Search back in the
> archives for posts about FLTK if you want more details.

It certainly seems to barf here, but I don't know if that's my CVS of 
BP yet.

It was merely whether it's possible to wrap function pointers or not. 
My solution above would require the function pointer accepting 
methods to be excluded and replaced with some python anyway.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBP34D+cEcvDLFGKbPEQKFagCfWedH/TRDpM/WFEKVOd77Gay9H9QAn3Nc
URC2S8b7Gk2nzddZeXWd0f6V
=2I2j
-----END PGP SIGNATURE-----




More information about the Cplusplus-sig mailing list