[C++-sig] Return value policies for objects with custom to-python converters

Ravi lists_ravi at lavabit.com
Thu Oct 2 16:09:17 CEST 2008


On Thursday 02 October 2008 04:38:02 Roman Yakovenko wrote:
> On Thu, Oct 2, 2008 at 12:33 AM, Ravi <lists_ravi at lavabit.com> wrote:
> > On Monday 29 September 2008 14:17:25 Ravi wrote:
> >>   The return value policies from boost.python do not seem to handle
> >> objects with custom converters; they seem to handle only those types
> >> exposed via boost.python. Attached is some code that handles
> >> reference_existing_object for objects with custom converters.
> >
> > Searching the web, I found that Roman Yakovenko has a similar converter
> > in his Py++ code repository, but for some reason, his version is called
> > return_ref_value rather than reference_existing_object_[some_suffix] and
> > that his version does not handle references (only pointers). If Roman
> > could not plug in his converter into the already-existing boost.python
> > framework, I probably should not bother trying to do so.
>
> Too many assumptions :-). Really.
> * I am not that good in Boost.Python internals.
> * I didn't need such functionality.

Well, I'm pretty sure I understand boost.python internals less than you do :-)

> >> 2. So far, I have used only reference_existing_object. Do the other
> >> return value policies need similar special handling for objects with
> >> custom to-python converters? How do I figure out which ones do and which
> >> ones don't?
> >
> > The other return value policies seem to be fine though I would like some
> > assurance (from someone knowledgeable about boost.python internals) that
> > only reference_existing_object needs to be rewritten to handle custom
> > to-python converters.
>
> You didn't presented small test case that reproduce the problem.

Attached; hope you don't mind me using your code in my example. You will also 
need tuples.hpp from here:
http://www.language-
binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/tuples.hpp.html

Python code:
import tuples
x = tuples.get2() # works
x = tuples.get1() # fails with conversion error

> I suggest you to take a look on the following FAQ:
> http://www.boost.org/doc/libs/1_36_0/libs/python/doc/v2/faq.html#topythonco
>nversionfailed

As far I can tell, add_property cannot be used to declare stand-alone 
functions though I am happy to be corrected.

Regards,
Ravi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tuples_tester.cpp
Type: text/x-c++src
Size: 628 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081002/164516a8/attachment.cpp>


More information about the Cplusplus-sig mailing list