[python] Passing pointers as arguments without copying.

Hello. The question is simple, but reading the documentation I cannot understand how to do this: class MyClass : boost::noncopyable { void f(MyClass2 * c2); }; MyClass2 is not copyable either. So I want to be able to wrap that function, but avoid the copying of MyClass2 when called from python. I want to pass the c++ object directly, not a copy of it. I'm not sure if this can be done with ptr() or some kind of call policy, but I don't understand the documentation 100%. Any help will be appreciated. Thanks.

I don't know about the whole boost::noncopyable, but if you dont want
to pass a copy of the class, doesn't a reference/pointer do th trick?
On Sat, Sep 26, 2009 at 7:36 AM, Germán Diago
Hello. The question is simple, but reading the documentation I cannot understand how to do this:
class MyClass : boost::noncopyable { void f(MyClass2 * c2); };
MyClass2 is not copyable either. So I want to be able to wrap that function, but avoid the copying of MyClass2 when called from python. I want to pass the c++ object directly, not a copy of it.
I'm not sure if this can be done with ptr() or some kind of call policy, but I don't understand the documentation 100%. Any help will be appreciated. Thanks. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I don't know about the whole boost::noncopyable, but if you dont want to pass a copy of the class, doesn't a reference/pointer do th trick?
I don't know how to do it.
I mean, I try to expose the class
class_

On Sat, Sep 26, 2009 at 2:38 AM, Germán Diago
I don't know about the whole boost::noncopyable, but if you dont want to pass a copy of the class, doesn't a reference/pointer do th trick?
I don't know how to do it.
I mean, I try to expose the class
class_
...; class_
("MyClass", ...). def(&MyClass::f, "f"); The problem is that "f", exposed to python, takes an argument of type MyClass2 *.
But MyClass2 * is noncopyable. So I cannot expose f that way because python will try to copy *myclass2 and it's noncopyable.
How can I avoid that copying? I don't know how. I saw something with ptr(), but it was to take a function with parameters from python to c++, not the other way, which is what I'm trying.
If it takes MyClass2*, then it will pass the memory address to it, it should not copy it...
participants (3)
-
Diederick C. Niehorster
-
Germán Diago
-
OvermindDL1