(I am not yet subscribed to the list... it seems mailman is having trouble sending me the authorization. Please CC me on replies.. Thanks.) Hi all, I just started using Boost.Python to embed Python in a project of mine. I spent a couple days evaluating, testing, and studying, but it seems to have paid off! Great job on making such a time-saving library! I am wrapping an internally refcounted class called CutScene. CutScene objects are referenced by RefPtr<CutScene> smart pointers, typedef'd as CutScenePtr. I export the class with: class_<CutScene, CutScenePtr>("CutScene").def /*etc*/; So far, so good. The problem comes about when I want to pass a CutScenePtr into object::operator() to call a function. If I pass a CutScenePtr object in, it says something about reject_raw_object_ptr: d:\Projects\empyrean\empyrean\third-party-vc7\include\boost\python\converter\arg_to_python.hpp(244) : error C2784: 'void boost::python::converter::detail::reject_raw_object_ptr(T *)' : could not deduce template argument for 'T1 *' from 'pyr::RefPtr<T>' with [ T=pyr::CutScene ] If I pass the result of CutScenePtr::get() into operator() I get a runtime error about Boost.Python not knowing how to convert RefDerivedSafe<T>* to a Python object. This makes sense, because RefPtr's implicit conversion operator, operator->, and get() all return RefDerivedSafe<T>*. (RefDerivedSafe<T> is a special class derived from T that prevents C++ clients from accidentally calling delete, ref(), or unref() on a smart pointer. This techique is used in both ATL and nsCOMPtr in Mozilla). Here's my question: Is there a way to tell Boost.Python that ptr(someCutScenePtr) is valid and should be equivalent to ptr(someCutScenePtr.get()) and/or that RefDerivedSafe<T>* can be implicitly converted to T*? I've tried several different things, and nothing seems to work... I'm currently using Boost 1.31 with both gcc 3.3.1 and VS.NET 2003. Many thanks, Chad
Chad Austin <caustin@gmail.com> writes:
(I am not yet subscribed to the list... it seems mailman is having trouble sending me the authorization. Please CC me on replies.. Thanks.)
Hi all,
I just started using Boost.Python to embed Python in a project of mine. I spent a couple days evaluating, testing, and studying, but it seems to have paid off! Great job on making such a time-saving library!
I am wrapping an internally refcounted class called CutScene. CutScene objects are referenced by RefPtr<CutScene> smart pointers, typedef'd as CutScenePtr. I export the class with:
class_<CutScene, CutScenePtr>("CutScene").def /*etc*/;
So far, so good. The problem comes about when I want to pass a CutScenePtr into object::operator() to call a function. If I pass a CutScenePtr object in, it says something about reject_raw_object_ptr:
d:\Projects\empyrean\empyrean\third-party-vc7\include\boost\python\converter\arg_to_python.hpp(244) : error C2784: 'void boost::python::converter::detail::reject_raw_object_ptr(T *)' : could not deduce template argument for 'T1 *' from 'pyr::RefPtr<T>' with [ T=pyr::CutScene ]
1. Show us more detail: more of the error messages, some sample code, etc. 2. As far as I can tell you have used boost::ptr around one of your RefPtr<CutScene>s, call it 'x': ptr(x) boost::ptr is reserved for real pointers.
If I pass the result of CutScenePtr::get() into operator() I get a runtime error about Boost.Python not knowing how to convert RefDerivedSafe<T>* to a Python object. This makes sense, because RefPtr's implicit conversion operator, operator->, and get() all return RefDerivedSafe<T>*. (RefDerivedSafe<T> is a special class derived from T that prevents C++ clients from accidentally calling delete, ref(), or unref() on a smart pointer
Bah! T* p = x.get(); delete p;
. This techique is used in both ATL and nsCOMPtr in Mozilla).
That doesn't make it safe ;->
Here's my question: Is there a way to tell Boost.Python that ptr(someCutScenePtr) is valid
No! Why do you want to use ptr?
and should be equivalent to ptr(someCutScenePtr.get()) and/or that RefDerivedSafe<T>* can be implicitly converted to T*? I've tried several different things, and nothing seems to work...
Maybe this helps? http://www.boost.org/libs/python/doc/v2/register_ptr_to_python.html -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
On Sat, 19 Jun 2004 07:00:41 -0400, David Abrahams <dave@boost-consulting.com> wrote:
2. As far as I can tell you have used boost::ptr around one of your RefPtr<CutScene>s, call it 'x':
ptr(x)
boost::ptr is reserved for real pointers.
Ah, I didn't know that. Taking out the ptr call seems to work. Now I understand how HeldType works. (Thanks Nikolay.)
If I pass the result of CutScenePtr::get() into operator() I get a runtime error about Boost.Python not knowing how to convert RefDerivedSafe<T>* to a Python object. This makes sense, because RefPtr's implicit conversion operator, operator->, and get() all return RefDerivedSafe<T>*. (RefDerivedSafe<T> is a special class derived from T that prevents C++ clients from accidentally calling delete, ref(), or unref() on a smart pointer
Bah!
T* p = x.get(); delete p;
Of course you can work around it. :P The point is, it does help catch unintentional bugs, especially in code written by someone new to refcounting/smart pointers or when refactoring.
. This techique is used in both ATL and nsCOMPtr in Mozilla).
That doesn't make it safe ;->
We can go back and forth for eternity arguing about C++ style, but that doesn't get anywhere. I really just wanted some help in getting this existing codebase connected nicely to Python.
Here's my question: Is there a way to tell Boost.Python that ptr(someCutScenePtr) is valid
No! Why do you want to use ptr?
I was under the impression that if you don't use ptr, a copy of the object is given to Python. From the discussion at: http://www.boost.org/libs/python/doc/v2/callbacks.html I guess it just wasn't exactly clear how I should pass my own refcounting pointer into Boost.Python and how that fit in with HeldType. Chad
Chad Austin <caustin@gmail.com> writes:
Bah!
T* p = x.get(); delete p;
Of course you can work around it. :P The point is, it does help catch unintentional bugs, especially in code written by someone new to refcounting/smart pointers or when refactoring.
Just to be clear, I have no problem with that part; it's having the implicit conversion at all that I take issue with... but I see below you don't really care what I think about this ;-> (I can't blame you).
. This techique is used in both ATL and nsCOMPtr in Mozilla).
That doesn't make it safe ;->
We can go back and forth for eternity arguing about C++ style, but that doesn't get anywhere. I really just wanted some help in getting this existing codebase connected nicely to Python.
I hope you got the help you needed. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Try to satisfy the detailed requirements for the "HeldType" (http://www.boost.org/libs/python/doc/v2/class.html#class_-spec). I think you'll have to define get_pointer(CutScenePtr). And maybe specialize python::pointee. HTH, Nikolay Chad Austin wrote:
(I am not yet subscribed to the list... it seems mailman is having trouble sending me the authorization. Please CC me on replies.. Thanks.)
Hi all,
I just started using Boost.Python to embed Python in a project of mine. I spent a couple days evaluating, testing, and studying, but it seems to have paid off! Great job on making such a time-saving library!
I am wrapping an internally refcounted class called CutScene. CutScene objects are referenced by RefPtr<CutScene> smart pointers, typedef'd as CutScenePtr. I export the class with:
class_<CutScene, CutScenePtr>("CutScene").def /*etc*/;
So far, so good. The problem comes about when I want to pass a CutScenePtr into object::operator() to call a function. If I pass a CutScenePtr object in, it says something about reject_raw_object_ptr:
d:\Projects\empyrean\empyrean\third-party-vc7\include\boost\python\converter\arg_to_python.hpp(244) : error C2784: 'void boost::python::converter::detail::reject_raw_object_ptr(T *)' : could not deduce template argument for 'T1 *' from 'pyr::RefPtr<T>' with [ T=pyr::CutScene ]
If I pass the result of CutScenePtr::get() into operator() I get a runtime error about Boost.Python not knowing how to convert RefDerivedSafe<T>* to a Python object. This makes sense, because RefPtr's implicit conversion operator, operator->, and get() all return RefDerivedSafe<T>*. (RefDerivedSafe<T> is a special class derived from T that prevents C++ clients from accidentally calling delete, ref(), or unref() on a smart pointer. This techique is used in both ATL and nsCOMPtr in Mozilla).
Here's my question: Is there a way to tell Boost.Python that ptr(someCutScenePtr) is valid and should be equivalent to ptr(someCutScenePtr.get()) and/or that RefDerivedSafe<T>* can be implicitly converted to T*? I've tried several different things, and nothing seems to work...
I'm currently using Boost 1.31 with both gcc 3.3.1 and VS.NET 2003.
Many thanks, Chad
-- Nikolay Mladenov Sitius Automation Inc. www.sitius.com
participants (3)
-
Chad Austin -
David Abrahams -
Nikolay Mladenov