[C++-sig] Re: boost.python: problem exposing static attribute with specific to_python converter

Baptiste Lepilleur gaiacrtn at free.fr
Sat Jan 8 11:33:59 CET 2005


----- Original Message ----- 
From: "David Abrahams" <dave at boost-consulting.com>
To: <c++-sig at python.org>
Sent: Saturday, January 08, 2005 12:18 AM
Subject: [C++-sig] Re: boost.python: problem exposing static attribute with
specific to_python converter


> Baptiste Lepilleur wrote:
>
> > Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
> > win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import localcegui as cegui
> >>>> print "Member:", cegui.TestString().memberFn()
> > Member: member
> >>>> print "StaticVar:", cegui.TestString.staticVar
> > StaticVar:
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > TypeError: No Python class registered for C++ class class CEGUI::String
> >
> >     Changing 'staticVar' type from CEGUI::String to std::string remove
this
> > error message, so something is really going on with the to_python
> > conversion. Why isn't the to_python_converter found ?
> [...]
> reference_existing_object requires a Python wrapper class for the
> returned type to exist, so that it can create an instance of that class
> containing a pointer to the pointee.  If you want it to use your
> converter, you need to get it to use some other policy, like
> default_call_polices:
>
>    .add_static_property("staticVar", make_getter(&TestString::staticVar,
> default_call_policies()));

Thanks, this explains clearly what's going on.

I couldn't get the above solution to work directly. I believe 'CEGUI::String
&' is deduced as a return type instead of 'CEGUI::String'. Here a simplified
compilation error stack (I'm using boost 1.32 & VC++ 7.1):

        include\boost\python\detail\caller.hpp(199) : error C2027: use of
undefined type 'boost::python::detail::specify_a_retur
n_value_policy_to_wrap_functions_returning<T>'
        with
        [
            T=result_t
        ]
//...
        include\boost\python\data_members.hpp(167) : see reference to
function template instantiation 'boost::python::ap
i::object
boost::python::make_function<boost::python::detail::datum<Data>,Policies,boo
st::mpl::vector1<T0>>(F,const Call
Policies &,const KeywordsOrSignature &)' being compiled
        with
        [
            Data=CEGUI::String,
            Policies=boost::python::default_call_policies,
            T0=CEGUI::String &,
            F=boost::python::detail::datum<CEGUI::String>,
            CallPolicies=boost::python::default_call_policies,
            KeywordsOrSignature=boost::mpl::vector1<CEGUI::String &>
        ]
//...
        src\pycegui\CEGUIStringWrapper.h(32) : see reference to function
template instantiation 'boost::python::api::obj
ect
boost::python::make_getter<CEGUI::String*,boost::python::default_call_polici
es>(const D & ,const Policies &)' being
compiled
        with
        [
            D=CEGUI::String *,
            Policies=boost::python::default_call_policies
        ]

    Is this a bug ?

    I got it working using:
      .add_static_property( "staticVar",
         make_getter(&TestString::staticVar,
            return_value_policy<copy_non_const_reference>() ) )

    Is there a way to change the return type used in the function generated
by make_getter to be by value instead of by reference, so that the
default_call_policies could be used ?

    Thanks for your help,
    Baptiste.




More information about the Cplusplus-sig mailing list