Thread: [pygccxml-development] Removing copy constructor
Brought to you by:
mbaas,
roman_yakovenko
From: Benoit L. <ben...@mo...> - 2010-04-13 11:40:49
|
Hi, I have a problem with a class I try to bind (how original!). It has a boost::mutex member (which is non-copyable). My class itself has no explicitely defined copy-constructor. ==> py++ tries to access this copy-constructor in the wrapper class copy-constructor. class MyClass { public: MyClass(){....} // .... protected: // .... boost::mutex m_mutex; // .... }; struct MyClassWrapper : MyClass, bp::wrapper<MyClass> { MyClassWrapper(MyClass const & arg ) : MyClass( arg ), bp::wrapper< MyClass >() { // copy constructor } // other stuff.... // ... }; I tried to set the class.copyable to False, but py++ still generates the same code... Any clue? Thanks! Benoit |
From: Roman Y. <rom...@gm...> - 2010-04-13 12:01:23
|
On Tue, Apr 13, 2010 at 2:40 PM, Benoit Leveau <ben...@mo...> wrote: > Hi, > > I have a problem with a class I try to bind (how original!). I hope py++ is part of the solution. If you have comments how it could be improved - I'll be glad to get them. Some time ago I wrote "easy extending guide"( http://language-binding.net/pyplusplus/troubleshooting_guide/easy_extending_guide/easy_extending_guide.html ). Only pretty simple code could be wrapped without problems. > It has a boost::mutex member (which is non-copyable). > My class itself has no explicitely defined copy-constructor. > ==> py++ tries to access this copy-constructor in the wrapper class > copy-constructor. > > class MyClass > { > public: > MyClass(){....} > // .... > protected: > // .... > boost::mutex m_mutex; > // .... > }; > > struct MyClassWrapper : MyClass, bp::wrapper<MyClass> { > MyClassWrapper(MyClass const & arg ) : MyClass( arg ), bp::wrapper< > MyClass >() > { > // copy constructor > } > > // other stuff.... > // ... > }; > > I tried to set the class.copyable to False, but py++ still generates the > same code... > > Any clue? No. I have the following test: ( see noncopyable_to_be_exported.hpp file ) C++ code: class c_t : public boost::noncopyable{ public: static char get_c(){ return 'c'; } }; struct e_t{ virtual void do_smth() = 0; private: c_t c; }; The generated code (without tweaking) is the following: namespace bp = boost::python; struct e_t_wrapper : noncopyables::e_t, bp::wrapper< noncopyables::e_t > { virtual void do_smth( ){ bp::override func_do_smth = this->get_override( "do_smth" ); func_do_smth( ); } }; Can you provide more details? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Benoit L. <ben...@mo...> - 2010-04-13 12:11:20
|
Roman Yakovenko wrote: > On Tue, Apr 13, 2010 at 2:40 PM, Benoit Leveau > <ben...@mo...> wrote: >> Hi, >> >> I have a problem with a class I try to bind (how original!). > > I hope py++ is part of the solution. If you have comments how it could > be improved - I'll be glad to get them. So far, everything is going well ;) >> It has a boost::mutex member (which is non-copyable). >> My class itself has no explicitely defined copy-constructor. >> ==> py++ tries to access this copy-constructor in the wrapper class >> copy-constructor. >> >> class MyClass >> { >> public: >> MyClass(){....} >> // .... >> protected: >> // .... >> boost::mutex m_mutex; >> // .... >> }; >> >> struct MyClassWrapper : MyClass, bp::wrapper<MyClass> { >> MyClassWrapper(MyClass const & arg ) : MyClass( arg ), bp::wrapper< >> MyClass >() >> { >> // copy constructor >> } >> >> // other stuff.... >> // ... >> }; >> >> I tried to set the class.copyable to False, but py++ still generates the >> same code... >> >> Any clue? > > > No. I have the following test: ( see noncopyable_to_be_exported.hpp file ) > > > C++ code: > > > > class c_t : public boost::noncopyable{ > > public: > > static char get_c(){ return 'c'; } > > > > }; > > struct e_t{ > > virtual void do_smth() = 0; > > private: > > c_t c; > > }; > > > The generated code (without tweaking) is the following: > > namespace bp = boost::python; > > struct e_t_wrapper : noncopyables::e_t, bp::wrapper< noncopyables::e_t > { > > virtual void do_smth( ){ > bp::override func_do_smth = this->get_override( "do_smth" ); > func_do_smth( ); > } > > }; > Can you provide more details? That's really interesting...I didn't know py++ was supposed to detect this case (when a class has a non-copyable member). I'm going to try to reproduce your example, then i'll introduce my types...hopefully at some point I'll see what's causing the problem. I'll let you know what I can find. |
From: Roman Y. <rom...@gm...> - 2010-04-13 12:33:29
Attachments:
noncopyable.cpp
|
On Tue, Apr 13, 2010 at 3:11 PM, Benoit Leveau <ben...@mo...> wrote: > That's really interesting...I didn't know py++ was supposed to detect this > case (when a class has a non-copyable member). :-) Take a look on: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/noncopyable_to_be_exported.hpp?view=markup http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/noncopyable_tester.py?view=markup and the attached generated file > I'm going to try to reproduce > your example, then i'll introduce my types...hopefully at some point I'll > see what's causing the problem. > I'll let you know what I can find. Cool. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Benoit L. <ben...@mo...> - 2010-04-13 12:38:01
|
Roman Yakovenko wrote: > On Tue, Apr 13, 2010 at 3:11 PM, Benoit Leveau > <ben...@mo...> wrote: >> That's really interesting...I didn't know py++ was supposed to detect this >> case (when a class has a non-copyable member). > > :-) > > Take a look on: > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/noncopyable_to_be_exported.hpp?view=markup > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/noncopyable_tester.py?view=markup > > and the attached generated file > >> I'm going to try to reproduce >> your example, then i'll introduce my types...hopefully at some point I'll >> see what's causing the problem. >> I'll let you know what I can find. > > Cool. Thanks a lot! I'll try this in a few minutes.. I should have looked in the unit tests, I didn't think about it... |
From: Benoit L. <ben...@mo...> - 2010-04-13 14:58:50
|
Benoit Leveau wrote: > Roman Yakovenko wrote: >> On Tue, Apr 13, 2010 at 3:11 PM, Benoit Leveau >> <ben...@mo...> wrote: >>> That's really interesting...I didn't know py++ was supposed to detect this >>> case (when a class has a non-copyable member). >> :-) >> >> Take a look on: >> >> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/noncopyable_to_be_exported.hpp?view=markup >> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/noncopyable_tester.py?view=markup >> >> and the attached generated file >> >>> I'm going to try to reproduce >>> your example, then i'll introduce my types...hopefully at some point I'll >>> see what's causing the problem. >>> I'll let you know what I can find. >> Cool. > > Thanks a lot! I'll try this in a few minutes.. > I should have looked in the unit tests, I didn't think about it... using your example, I indeed don't get a copy-constructor, even after "complexifying" the class so it looks more like mine... this is probably something tricky! I'm not sure I really have to bind that class, but I'll let you know if I find where the problem was I was thinking about something. I had a few troubles now and then using the call_policies. I explain: If you want to use "copy_non_const_reference" you use: function.call_policies = call_policies.return_value_policy(call_policies.copy_non_const_reference) but if you want to use return_internal_reference you use: function.call_policies = call_policies.return_internal_reference() I had to look into call_policies.py and from time to time I forget and get some errors (even sometimes py++ doesn't complain but the errors appear at compilation). All these policies are listed in the same section, without any mention that one is a function, the others are string and need to be passed to return_value_policy(). It might be useful to add that to the documentation, if it's not already somewhere I missed. Benoit |
From: Roman Y. <rom...@gm...> - 2010-04-14 05:14:14
|
On Tue, Apr 13, 2010 at 5:58 PM, Benoit Leveau <ben...@mo...> wrote: > using your example, I indeed don't get a copy-constructor, even after > "complexifying" the class so it looks more like mine... this is probably > something tricky! I'm not sure I really have to bind that class, but I'll > let you know if I find where the problem was Thanks. "copyable" is the most "fragile" part of the project. That's why I has so many tests for it. > I was thinking about something. I had a few troubles now and then using the > call_policies. I explain: > If you want to use "copy_non_const_reference" you use: > function.call_policies = > call_policies.return_value_policy(call_policies.copy_non_const_reference) > > but if you want to use return_internal_reference you use: > function.call_policies = call_policies.return_internal_reference() > > I had to look into call_policies.py and from time to time I forget and get > some errors (even sometimes py++ doesn't complain but the errors appear at > compilation). > All these policies are listed in the same section, without any mention that > one is a function, the others are string and need to be passed to > return_value_policy(). > It might be useful to add that to the documentation, if it's not already > somewhere I missed. I tried to implement the interface similar to Boost.Python library: http://www.boost.org/doc/libs/1_42_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies * with_custodian_and_ward: Ties lifetimes of the arguments * with_custodian_and_ward_postcall: Ties lifetimes of the arguments and results * return_internal_reference: Ties lifetime of one argument to that of result * return_value_policy<T> with T one of: o reference_existing_object: naive (dangerous) approach o copy_const_reference: Boost.Python v1 approach o copy_non_const_reference: o manage_new_object: Adopt a pointer and hold the instance where you replace "< T >" with "( T )", I hoped it will be enough to look at Boost.Python documentation and understand how the code (py++) should be written. Will few comments in the source file fix this or we need to introduce some validation checks? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Benoit L. <ben...@mo...> - 2010-04-14 08:32:54
|
Roman Yakovenko wrote: > On Tue, Apr 13, 2010 at 5:58 PM, Benoit Leveau > <ben...@mo...> wrote: > >> using your example, I indeed don't get a copy-constructor, even after >> "complexifying" the class so it looks more like mine... this is probably >> something tricky! I'm not sure I really have to bind that class, but I'll >> let you know if I find where the problem was > > Thanks. "copyable" is the most "fragile" part of the project. That's > why I has so many tests for it. >> I was thinking about something. I had a few troubles now and then using the >> call_policies. I explain: >> If you want to use "copy_non_const_reference" you use: >> function.call_policies = >> call_policies.return_value_policy(call_policies.copy_non_const_reference) >> >> but if you want to use return_internal_reference you use: >> function.call_policies = call_policies.return_internal_reference() >> >> I had to look into call_policies.py and from time to time I forget and get >> some errors (even sometimes py++ doesn't complain but the errors appear at >> compilation). >> All these policies are listed in the same section, without any mention that >> one is a function, the others are string and need to be passed to >> return_value_policy(). >> It might be useful to add that to the documentation, if it's not already >> somewhere I missed. > > I tried to implement the interface similar to Boost.Python library: > > http://www.boost.org/doc/libs/1_42_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.call_policies > > * with_custodian_and_ward: Ties lifetimes of the arguments > * with_custodian_and_ward_postcall: Ties lifetimes of the > arguments and results > * return_internal_reference: Ties lifetime of one argument to that of result > * return_value_policy<T> with T one of: > o reference_existing_object: naive (dangerous) approach > o copy_const_reference: Boost.Python v1 approach > o copy_non_const_reference: > o manage_new_object: Adopt a pointer and hold the instance > > where you replace "< T >" with "( T )", I hoped it will be enough to > look at Boost.Python documentation and understand how the code (py++) > should be written. > > Will few comments in the source file fix this or we need to introduce > some validation checks? I don't think introducing some validation checks is necessary. The confusing thing is that the online doc shows a different indentation than what you just said: * default_call_policies * return_value_policy - return_opaque_pointer - copy_const_reference - return_by_value - copy_non_const_reference - return_internal_reference <= should be at the same level as return_value_policy, else we think we must use return_value_policy( return_internal_reference ) * return self so this would just be a matter of changing the indentation in docs/documentation/functions/call_policies/call_policies.rest |
From: Roman Y. <rom...@gm...> - 2010-04-14 08:50:41
|
On Wed, Apr 14, 2010 at 11:32 AM, Benoit Leveau <ben...@mo...> wrote: > * default_call_policies > * return_value_policy > - return_opaque_pointer > - copy_const_reference > - return_by_value > - copy_non_const_reference > - return_internal_reference <= should be at the same level as > return_value_policy, else we think we must use return_value_policy( > return_internal_reference ) > * return self > > so this would just be a matter of changing the indentation in > docs/documentation/functions/call_policies/call_policies.rest Done: http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1836&view=rev Thank you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |