[C++-sig] void* (void pointer) function arguments
Holger.Joukl at LBBW.de
Tue Aug 16 11:31:03 CEST 2011
> > I am a bit unsure about how to work the void-pointers. A viable way
> > to wrap the original
> > API functions with thin wrappers that take a boost::python::object and
> > the "raw" PyObject*
> > into the original function:
> I don't see anything wrong with this approach, aside from the fact that
> you have to make an explicit wrapper for all of your functions that take
> void pointers. It might be a little less safe, but you should be able
> to make things more automatic by casting function pointers that accept a
> void* to a signature with void* replaced by PyObject*; Boost.Python does
> know how to wrap functions that take PyObject*. For example, in the
> wrapper for your "Worker" class, you'd have:
Just tested, it works:
.def("destroy", &Worker::destroy, &WorkerWrap::default_destroy)
.def("destroy2", (int (Worker::*)(DestructionCallback*,
So I could save the thin wrappers that get called from the Python side.
> I think this should do the same thing, though you may want to check that
> default arguments work as expected. Of course this could lead to big
> problems if you pass around things that aren't in fact PyObject* as void
> pointers in the same places, though I think your solution suffers from
> this too.
The default args seem to work fine with your proposal, though.
> Good luck!
Thanks a lot and all the best
Anstalt des oeffentlichen Rechts
Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz
More information about the Cplusplus-sig