On 9/6/06, Alex Mohr <amohr@pixar.com> wrote:
The problem for me was that the rvalue converter when passed a non-None could not do the placement new created of the ptr<Base> because the constructor is protected. The library I am wrapping requires all objects to be created using static factory methods:
ref_ptr<Base> obj = Class.create()
But the converter's not trying to create a new *object* -- just a new smart pointer. If you can write code that obtains a correct new smart pointer from a raw object pointer, then just fill in that code in the right place in the converter and it should work.
This is the part I can't do. I can make a ref_ptr<> from a ptr<> as vice versa, but I can't build either of them from a raw pointer. I may take a look at this later and see if I can make it work better so I just have the one converter.
The only other thing that's required is that the smart pointer objects be copy-constructible, which I would think they ought to be. Otherwise they're very strange.
So there is something going on in the implicit conversion for the smart pointers that just handles things better.
I ended up getting the code to work though by making it so the rvalue convertible method return NULL if p != NonType. This ends up meaning that the rvalue converter is only used in the case of passing None, but it works for me now.
Sure -- that sounds like it will be okay given your situation.
I agree. NoneType --> ptr<> was always a special case for me since I want everything held by ref_ptrs all the time anyway. Thanks again. -Allen
Thanks for your help. I will let you know if anything else crops up but I think I am starting to understand this part of boost.python much better now so hopefully I will be able to fix it myself. :)
No problem.
Alex _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig