[C++-sig] pyste and return reference problem
John Hunter
jdhunter at ace.bsd.uchicago.edu
Tue Nov 9 00:40:46 CET 2004
I have found what looks like pyste bug. pyste wraps the following
struct
struct C {
const C& func(double val) {return *this;}
double func() {return 0.0;}
};
as
class_< C >("C", init< >())
.def(init< const C& >())
.def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >())
.def("func", (double (C::*)() )&C::func, return_value_policy< copy_const_reference >())
;
Note that (double (C::*)() )&C::func has a call policy of
return_value_policy< copy_const_reference >()).
If you reverse the order of the method definitions in C, ie
struct C {
double func() {return 0.0;}
const C& func(double val) {return *this;}
};
pyste gets it right
class_< C >("C", init< >())
.def(init< const C& >())
.def("func", (double (C::*)() )&C::func)
.def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >())
;
This leads me to a question related to one of my earlier questions:
when wrapping overloaded functions as above, is there a way to
differentially set the call policies in pyste for the different
signatures. I know one can use as described in the docs
set_policy(f, return_internal_reference())
set_policy(C.foo, return_value_policy(manage_new_object))
How does one do this for overloaded functions?
Sorry for the deluge of mail! I'm going home now :-)
JDH
boost_python 1.31.0 with pyste and gccxml-0.6.0
More information about the Cplusplus-sig
mailing list