[C++-sig] Re: How to expose virtual function with defaultarguments in boost.python ?
Baptiste Lepilleur
gaiacrtn at free.fr
Mon Dec 6 23:35:36 CET 2004
----- Original Message -----
From: "David Abrahams" <dave at boost-consulting.com>
To: <c++-sig at python.org>
Sent: Monday, December 06, 2004 3:11 PM
Subject: [C++-sig] Re: How to expose virtual function with defaultarguments
in boost.python ?
> Baptiste Lepilleur wrote:
> > ----- Original Message -----
> > From: "David Abrahams" <dave at boost-consulting.com>
>
>
> >>1. Use new-style polymorphism.
> [...]
> > Is there a performance hit if I always use the VC6/7 work-around in the
> > overridden virtual method ? (=> should I used the #if BOOST_WORKAROUND
all
> > over the place ?)
>
> No performance hit; it's just uglier. But if you need portable code,
> just use the vc6/7 method.
This solution passes all my simple test cases. I'm now tackling a full
generation of the pyogre binding to "polish" the generator. When compiling
the full binding, I stumbled on the following warning (I'm compiling with
VC++ 7.1):
build\pyogre_\BillboardSet.cpp(303) : warning C4172: returning address of
local variable or temporary
Ogre::String is just a typedef on std::string. This code is the
implementation of the overriden virtual method in the wrapper class. The
code generation the warning follow:
---
const Ogre::String& getMaterialName() const {
if (override f = this->get_override("getMaterialName"))
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) // Workaround for vc6/vc7
return call< const Ogre::String& >( f.ptr());
#else
return f( ); /// <<< *** warning on this line ***
#endif
return Ogre::BillboardSet::getMaterialName();
}
---
Do you have any idea on how to "remove" this warning ? The old-style way:
return call_method< const Ogre::String& >(py_self, "getMaterialName");
does not generate that warning.
By the way, what is the "right" way to retrieve the PyObject* associated to
the wrapper ? The only thing I found is:
boost::python::detail::wrapper_base_::get_owner(). Seems to be hidden too
deeply to be of legal use. Anyway, would replacing the line causing the
warning by:
PyObject *py_self = boost::python::detail::wrapper_base_::get_owner(
*this );
return call_method< const Ogre::String& >(py_self, "getMaterialName");
works correctly ?
> >>and...
[...]
> >>2. qualify your calls to set:
> >>
> >>return self.VirtualReturnValuePolicy::set(p0);
> >
> >
> > I don't see how this would change anything. self is already of type
> > 'VirtualReturnValuePolicy &'.
>
> It prevents VirtualReturnValuePolicy_Wrapper::set from being called
instead.
Somehow, I managed to forget that 'set' is a virtual function (nothing short
of amazing!). Will try this later.
Baptiste.
More information about the Cplusplus-sig
mailing list