[C++-sig] cannot return boost::python::tuple

David Abrahams david.abrahams at rcn.com
Thu May 30 05:15:10 CEST 2002


Ralf,

The user-friendly explicit conversions and conversions for the builtin type
wrappers are two of the areas where v2 lags behind v1. The documentation
also lags here, since the interface isn't complete yet.

make_ref is currently spelled:

    ref(boost::python::converter::callback_to_python<T>(x).get(),
ref::increment_count)

Though none of those interfaces are guaranteed to be stable. You could
write it thus, for the time being:

    template <class T>
    ref make_ref(T const& x)
    {
        return
ref(boost::python::converter::callback_to_python<T>(x).get(),
ref::increment_count);
    }


As for returing a tuple, for the time being you must return a PyObject*.
Adding the conversions will be relatively easy; it just has to get done.
So, for now:

    return initargs.reference().release();

HTH,
Dave

------

Ralf wrote:

> What is the equivalent of make_ref in V2?
> Here is what I would like to do:
>
> boost::python::module("any")
>   .add("__version__", boost::python::make_ref("1.2.3"));
>
> I tried to find the documentation for boost::python::ref but the link to
> reference_hpp.html is broken.

----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> I am having trouble returning a boost::python::tuple.
> This works (reports None when called from Python):
>
>   void//boost::python::tuple
>   UnitCell_getinitargs(const UnitCell& uc) {
>     boost::python::tuple initargs;
>     //return initargs;
>   }
>
> This is what I really want:
>
>   boost::python::tuple
>   UnitCell_getinitargs(const UnitCell& uc) {
>     boost::python::tuple initargs;
>     return initargs;
>   }
>
> But I get:
>
> Traceback (most recent call last):
>   File "dbg.py", line 6, in ?
>     print u.__getinitargs__()
> TypeError: bad argument type for built-in operation
>
> What am I doing wrong?







More information about the Cplusplus-sig mailing list