|
Boost : |
From: Trevor Perrin (tperrin_at_[hidden])
Date: 2001-07-08 18:31:06
I included the variants; below (and attached, if that works) is my test
file. Probably vc just sucks. Since splicing the converters directly into
python_extension_class_converters works for me that's what I'm going to do.
Thanks for your help.
Error:
-----------------------
c:\boost\boost_1_22_0\boost\python\caller.hpp(1071) : error C2665:
'from_python' : none of the 61 overloads can convert parameter 2 from type
'struct boost::python::type<class boostold::shared_ptr<class hello> >'
c:\boost\boost_1_22_0\boost\python\detail\functions.hpp(69) : see
reference to function template instantiation 'struct _object *__cdecl
boost::python::caller<void>::call(void (__cdecl *)(class
boostold::shared_ptr<class hello>),struct _objec
t *,struct _object *)' being compiled
Test case
-----------------------
#include <boost/python/class_builder.hpp>
namespace python = boost::python;
#include "boostold/smart_ptr.hpp"
//Below I attempt to define from_python() and to_python() converters for
boostold::shared_ptr
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
template <class T>
PyObject* to_python(boostold::shared_ptr<T> p)
{
return
boost::python::python_extension_class_converters<T>::smart_ptr_to_python(p);
}
template <class T>
boostold::shared_ptr<T>& from_python(PyObject* p, boostold::shared_ptr<T>&)
{ return
boost::python::python_extension_class_converters<T>::smart_ptr_reference(p,
boost::python::type<boostold::shared_ptr<T> >()); }
template <class T>
const boostold::shared_ptr<T>& from_python(PyObject* p,
boostold::shared_ptr<T>)
{ return
boost::python::python_extension_class_converters<T>::smart_ptr_value(p,
boost::python::type<boostold::shared_ptr<T> >()); }
template <class T>
const boostold::shared_ptr<T>& from_python(PyObject* p, const
boostold::shared_ptr<T>&)
{ return
boost::python::python_extension_class_converters<T>::smart_ptr_value(p,
boost::python::type<boostold::shared_ptr<T> >()); }
BOOST_PYTHON_END_CONVERSION_NAMESPACE
class hello{};
void func(boostold::shared_ptr<hello>){}
BOOST_PYTHON_MODULE_INIT(testbp)
{
try
{
python::module_builder this_module("testbp");
python::class_builder<hello> hello_class(this_module, "hello");
this_module.def(func, "func");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}
-----Original Message-----
From: David Abrahams [mailto:david.abrahams_at_[hidden]]
Sent: Sunday, July 08, 2001 3:36 PM
To: boost_at_[hidden]
Subject: Re: [boost] Python & smart pointers
You probably didn't define enough variants. You need:
friend boost::shared_ptr<T>& from_python(PyObject* p,
boost::python::type<boost::shared_ptr<T>&>)
{ return smart_ptr_reference(p,
boost::python::type<boost::shared_ptr<T> >()); }
friend const boost::shared_ptr<T>& from_python(PyObject* p,
boost::python::type<boost::shared_ptr<T> >)
{ return smart_ptr_value(p, boost::python::type<boost::shared_ptr<T>
>()); }
friend const boost::shared_ptr<T>& from_python(PyObject* p,
boost::python::type<const boost::shared_ptr<T>&>)
{ return smart_ptr_value(p, boost::python::type<boost::shared_ptr<T>
>()); }
The type inside boost::python::type<...> is the type of parameter you are
converting to, so unless the function you're wrapping takes a reference to a
boostold::shared_ptr, no variation on what you have below will work.
-Dave
----- Original Message -----
From: "Trevor Perrin" <tperrin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, July 08, 2001 4:04 PM
Subject: RE: [boost] Python & smart pointers
>
> Sorry, that mail was incomplete, I sent it by accident. Anyways, I
> tried the below and tweaking it in various ways (ie
> wrapping/unwrapping the boostold::shared_ptr in boost::python::type<>)
> to make from_python() work
in
> a similar stand-alone way to to_python() but couldn't; I'm using
> vc6sp4;
is
> there a simple way to do this? I kind of get the impression from
> conversions.hpp I'm out of luck..
>
> Trevor
>
> -----Original Message-----
> From: Trevor Perrin [mailto:tperrin_at_[hidden]]
> Sent: Sunday, July 08, 2001 12:58 PM
> To: 'boost_at_[hidden]'
> Subject: RE: [boost] Python & smart pointers
>
>
>
> Thanks. What about from_python()? By analogy with
> python_extension_class_converters I tried:
>
> template <class T>
> boostold::shared_ptr<T>& from_python(PyObject* p,
boostold::shared_ptr<T>&)
>
> return
>
boost::python::python_extension_class_converters<T>::smart_ptr_reference(p,
> boost::python::type<boostold::shared_ptr<T> >());
> }
>
>
>
>
> -----Original Message-----
> From: David Abrahams [mailto:david.abrahams_at_[hidden]]
> Sent: Sunday, July 08, 2001 5:39 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Python & smart pointers
>
>
> The formula is simple: just use this technique:
> BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug
> workaround
> template <class T>
> PyObject* to_python(my_smart_ptr<T> p)
> {
> return
> boost::python::python_extension_class_converters<T>::ptr_to_python(p);
> }
> BOOST_PYTHON_END_CONVERSION_NAMESPACE
>
> -Dave
> ----- Original Message -----
> From: "Trevor Perrin" <tperrin_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Saturday, July 07, 2001 11:22 PM
> Subject: [boost] Python & smart pointers
>
>
> >
> > An uninformed question by a Boost.Python newbie:
> >
> > I've previously created a modified boost::smart_ptr for myself, and
> > moved
> it
> > into a 'boostold' namespace. Now I'd like to use at least
> > boostold::shared_ptr with Boost.Python. As a first stab I
> > duplicated the bottom 4 converter member functions in
> > extension_class.hpp/python_extension_class_converters, which refer
> > to 'boost::shared_ptr', and changed 'boost::shared_ptr' to
> > 'boostold::shared_ptr'.
> >
> > Which seems to work (I'm using vc6sp4; also I don't care about
> > cross-extension-module dependencies right now), but I'm wondering if
> there's
> > a cleaner way to insert these converters into boost.python than
> > modifying its code. I'm also quite confused by the shared_ptr
> > converter code within conversions.hpp; what is "wrapped_pointer",
> > for example? Is the "MUST_SUPPORT_MSVC" code in the comments an
> > idiom I should be using?
> >
> > Trevor
> >
> >
> > Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
> >
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/
> >
> >
>
>
> Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
> Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk