Re: [C++-sig] Py++ module for code with protected operator=
On Fri, Mar 19, 2010 at 6:42 PM, Maciej Sitarz wrote: > > Hi all, > > I want to create python module for class that has protected operator=. > That class placed in std::vector and code generated by Py++ uses that > operator. I could be wring, but if I remember right, you can not use such classes with Boost.Python indexing suite. I suggest you to switch to the indexing suite that comes with Py++: http://language-binding.net/pyplusplus/documentation/containers.html . I am pretty sure it will work out of the box. You will not have to specify "noncopyable=True". HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ - one header file including all project header files
On Fri, Mar 19, 2010 at 1:27 AM, Maciej Sitarz wrote: > On 17.03.2010 08:52, Roman Yakovenko wrote: >> >> Nothing, really. >> >> Please take a look on the following document: >> >> http://language-binding.net/pyplusplus/documentation/tutorials/module_builder/module_builder.html#declarations-customization >> and let me know whether is makes sense to you. >> >> If not come back and we will resolve the issue > > Thanks, I added this two loops for ex/including some classes and now it > works as it should. > > # Include Cream CE classes > for class_name in environment.include_classes: > print "Including class '%s'" % class_name > mb.class_( name=class_name ).include() > > # Exclude Cream CE classes > for class_name in environment.exclude_classes: > print "Excluding class '%s'" % class_name > mb.class_( name=class_name ).exclude() You can write it shorter: mb._classes( lambda cls: cls.name in environment.exclude_classes ).exclude() :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On 20.03.2010 19:12, Roman Yakovenko wrote: On Fri, Mar 19, 2010 at 6:42 PM, Maciej Sitarz wrote: Hi all, I want to create python module for class that has protected operator=. That class placed in std::vector and code generated by Py++ uses that operator. I could be wring, but if I remember right, you can not use such classes with Boost.Python indexing suite. I suggest you to switch to the indexing suite that comes with Py++: http://language-binding.net/pyplusplus/documentation/containers.html . I am pretty sure it will work out of the box. You will not have to specify "noncopyable=True". I tried indexing_suite_version=2 but the problem is still the same. Difference in generated code with noncopyable set and not set: --- generated_idx2.cpp 2010-03-20 19:58:42.611632788 +0100 +++ generated_idx2_noncopyable.cpp 2010-03-20 20:00:39.494986097 +0100 @@ -40,7 +40,7 @@ BOOST_PYTHON_MODULE(test){ vector_less__JobPropertyWrapper__greater__exposer.def( bp::indexing::vector_suite< std::vector< JobPropertyWrapper > >() ); } -bp::class_< JobPropertyWrapper >( "JobPropertyWrapper" ); +bp::class_< JobPropertyWrapper, boost::noncopyable >( "JobPropertyWrapper" ); The compile errors are still the same: generated.cpp:40: instantiated from here test.h:6: error: 'JobPropertyWrapper& JobPropertyWrapper::operator=(const JobPropertyWrapper&)' is protected I attached the generated file with this mail. -- Maciek Sitarz // This file has been generated by Py++. #include "boost/python.hpp" #include "indexing_suite/value_traits.hpp" #include "indexing_suite/container_suite.hpp" #include "indexing_suite/vector.hpp" #include "test.h" namespace bp = boost::python; namespace boost { namespace python { namespace indexing { template<> struct value_traits< JobPropertyWrapper >{ static bool const equality_comparable = false; static bool const less_than_comparable = false; template static void visit_container_class(PythonClass &, Policy const &){ } }; }/*indexing*/ } /*python*/ } /*boost*/ BOOST_PYTHON_MODULE(test){ { //::std::vector< JobPropertyWrapper > typedef bp::class_< std::vector< JobPropertyWrapper > > vector_less__JobPropertyWrapper__greater__exposer_t; vector_less__JobPropertyWrapper__greater__exposer_t vector_less__JobPropertyWrapper__greater__exposer = vector_less__JobPropertyWrapper__greater__exposer_t( "vector_less__JobPropertyWrapper__greater_" ); bp::scope vector_less__JobPropertyWrapper__greater__scope( vector_less__JobPropertyWrapper__greater__exposer ); vector_less__JobPropertyWrapper__greater__exposer.def( bp::indexing::vector_suite< std::vector< JobPropertyWrapper > >() ); } bp::class_< JobPropertyWrapper, boost::noncopyable >( "JobPropertyWrapper" ); bp::class_< classA >( "classA" ) .def( "fun" , (void ( ::classA::* )( ::std::vector< JobPropertyWrapper > const & ) )( &::classA::fun ) , ( bp::arg("v") ) ); { //::main typedef int ( *main_function_type )( ); bp::def( "main" , main_function_type( &::main ) ); } } ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On Sat, Mar 20, 2010 at 9:15 PM, Maciej Sitarz wrote: > On 20.03.2010 19:12, Roman Yakovenko wrote: >> >> On Fri, Mar 19, 2010 at 6:42 PM, Maciej Sitarz wrote: > The compile errors are still the same: > generated.cpp:40: instantiated from here > test.h:6: error: 'JobPropertyWrapper& JobPropertyWrapper::operator=(const > JobPropertyWrapper&)' is protected > Sorry, I missed the point in the initial post. The error has nothing to do with generated code. You can define class with protected operator=, but you will not be able to insert it into std::vector, because it requires public operator= . I think, you will have to change your code. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On 20.03.2010 20:47, Roman Yakovenko wrote: On Sat, Mar 20, 2010 at 9:15 PM, Maciej Sitarz wrote: On 20.03.2010 19:12, Roman Yakovenko wrote: On Fri, Mar 19, 2010 at 6:42 PM, Maciej Sitarzwrote: The compile errors are still the same: generated.cpp:40: instantiated from here test.h:6: error: 'JobPropertyWrapper& JobPropertyWrapper::operator=(const JobPropertyWrapper&)' is protected Sorry, I missed the point in the initial post. The error has nothing to do with generated code. You can define class with protected operator=, but you will not be able to insert it into std::vector, because it requires public operator= . Em... but the example main() compiles and works... unless I want to 'push_back' object to the vector. I think, you will have to change your code. I could change it in the example, but I can't change the code for which I'm making the python module. I think I should investigate how the vector is created and put into the function in the original project. Or maybe you have other suggestions? -- Maciek Sitarz ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On Sat, Mar 20, 2010 at 10:12 PM, Maciej Sitarz wrote: > On 20.03.2010 20:47, Roman Yakovenko wrote: > Em... but the example main() compiles and works... unless I want to > 'push_back' object to the vector. This is exactly my point >> I think, you will have to change your code. > > I could change it in the example, but I can't change the code for which I'm > making the python module. > I think I should investigate how the vector is created and put into the > function in the original project. > Or maybe you have other suggestions? Yes. Can you show/point me to the original code you are trying to expose. ( not the whole library but the concrete class ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] [Py++] boost::shared_ptr casting
Hello, I'm having some issues with shared_ptr's in a Python environment: it looks like once a shared_ptr enters Python, it cannot be upcasted nor downcasted. Here's a brief C++ source code to explain better the issue: #include class Base { }; class Derived : public Base { }; boost::shared_ptr base1( ) { return boost::shared_ptr( new Base ); } boost::shared_ptr base2( ) { return boost::shared_ptr( new Derived ); } boost::shared_ptr base3( boost::shared_ptr derived ) { return boost::shared_ptr( derived ); } boost::shared_ptr derived1( ) { return boost::shared_ptr( new Derived ); } boost::shared_ptr derived2( boost::shared_ptr base ) { return boost::static_pointer_cast( base ); } then, after building the library and importing it into Python, I would expect something like this: from shared_ptr_inheritance import * type( base1() ) -> Base type( base2() ) -> Base type( derived1() ) -> Derived type( base3( derived1() ) ) -> Base type( derived2( base2() ) ) -> Derived but instead, this is the actual behaviour: from shared_ptr_inheritance import * type( base1() ) -> Base type( base2() ) -> Base type( derived1() ) -> Derived type( base3( derived1() ) ) -> Derived (!!!) type( derived2( base2() ) ) -> Base (!!!) am I doing something wrong? why does this happen, and, mostly, how can I cast a shared_ptr containing a Derived pointer, to shared_ptr ? ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On 20.03.2010 21:24, Roman Yakovenko wrote: On Sat, Mar 20, 2010 at 10:12 PM, Maciej Sitarz wrote: On 20.03.2010 20:47, Roman Yakovenko wrote: I think, you will have to change your code. I could change it in the example, but I can't change the code for which I'm making the python module. I think I should investigate how the vector is created and put into the function in the original project. Or maybe you have other suggestions? Yes. Can you show/point me to the original code you are trying to expose. ( not the whole library but the concrete class ). Class constructor in line *72* accepts vector : http://freya.dsv.agh.edu.pl/~macieks/pycream/cream-client-api-c/JobIdWrapper.h And the JobPropertyWrapper is here: http://freya.dsv.agh.edu.pl/~macieks/pycream//cream-client-api-c/JobPropertyWrapper.h -- Maciek Sitarz ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Py++] boost::shared_ptr casting
On Sat, 2010-03-20 at 21:31 +0100, peoro wrote: > Hello, > > I'm having some issues with shared_ptr's in a Python environment: it > looks like once a shared_ptr enters Python, it cannot be upcasted nor > downcasted. > > Here's a brief C++ source code to explain better the issue: > > > #include > > class Base { }; > class Derived : public Base { }; > > boost::shared_ptr base1( ) { > return boost::shared_ptr( new Base ); > } > boost::shared_ptr base2( ) { > return boost::shared_ptr( new Derived ); > } > boost::shared_ptr base3( boost::shared_ptr derived ) { > return boost::shared_ptr( derived ); > } > boost::shared_ptr derived1( ) { > return boost::shared_ptr( new Derived ); > } > boost::shared_ptr derived2( boost::shared_ptr base ) { > return boost::static_pointer_cast( base ); > } > > > then, after building the library and importing it into Python, I would > expect something like this: > > > from shared_ptr_inheritance import * > type( base1() ) -> Base > type( base2() ) -> Base > type( derived1() ) -> Derived > type( base3( derived1() ) ) -> Base > type( derived2( base2() ) ) -> Derived > > > but instead, this is the actual behaviour: > > > from shared_ptr_inheritance import * > type( base1() ) -> Base > type( base2() ) -> Base > type( derived1() ) -> Derived > type( base3( derived1() ) ) -> Derived (!!!) > type( derived2( base2() ) ) -> Base (!!!) > > > am I doing something wrong? > why does this happen, and, mostly, how can I cast a shared_ptr > containing a Derived pointer, to shared_ptr ? > __ If you've wrapped all classes with shared_ptr storage, to-python converts should always produce the most-derived type in Python, and I think that's what you want on the Python side. This may not work if you can't use shared_ptr storage for some reason, or if you return an intermediate class you haven't wrapped. Are you using shared_ptr storage? Jim Bosch ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
Just one more comment... The constructor takes reference to vector, so I suspect that maybe it will be filled there by some other code I don't have? So I don't need to fill the vector, just to create it (I will ask the developers) Additional source + documentation (but no details ): http://grid.pd.infn.it/cream/CppApiDoc/JobIdWrapper_8h-source.html http://grid.pd.infn.it/cream/CppApiDoc/JobPropertyWrapper_8h-source.html -- Maciek Sitarz ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] Boost.Python and PEP 384
Do Boost.Python-generated extension modules conform to PEP 384's constraints for ABI compatibility? Thx, Skip Montanaro ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Py++] boost::shared_ptr casting
Yes, having all of the objects at their most-derived type would be what I need, but it's not what happens. I posted a piece of C++ code that shows what I do (I exported it using py++ without any further modification): all of the pointers my functions return are wrapped in boost::shared_ptr's, but from Python I see them at the "derivation level" they were when I passed them to python the first time (look at the summarized output in my previous message)... On Sat, Mar 20, 2010 at 10:06 PM, Jim Bosch wrote: > On Sat, 2010-03-20 at 21:31 +0100, peoro wrote: >> Hello, >> >> I'm having some issues with shared_ptr's in a Python environment: it >> looks like once a shared_ptr enters Python, it cannot be upcasted nor >> downcasted. >> >> Here's a brief C++ source code to explain better the issue: >> >> >> #include >> >> class Base { }; >> class Derived : public Base { }; >> >> boost::shared_ptr base1( ) { >> return boost::shared_ptr( new Base ); >> } >> boost::shared_ptr base2( ) { >> return boost::shared_ptr( new Derived ); >> } >> boost::shared_ptr base3( boost::shared_ptr derived ) { >> return boost::shared_ptr( derived ); >> } >> boost::shared_ptr derived1( ) { >> return boost::shared_ptr( new Derived ); >> } >> boost::shared_ptr derived2( boost::shared_ptr base ) { >> return boost::static_pointer_cast( base ); >> } >> >> >> then, after building the library and importing it into Python, I would >> expect something like this: >> >> >> from shared_ptr_inheritance import * >> type( base1() ) -> Base >> type( base2() ) -> Base >> type( derived1() ) -> Derived >> type( base3( derived1() ) ) -> Base >> type( derived2( base2() ) ) -> Derived >> >> >> but instead, this is the actual behaviour: >> >> >> from shared_ptr_inheritance import * >> type( base1() ) -> Base >> type( base2() ) -> Base >> type( derived1() ) -> Derived >> type( base3( derived1() ) ) -> Derived (!!!) >> type( derived2( base2() ) ) -> Base (!!!) >> >> >> am I doing something wrong? >> why does this happen, and, mostly, how can I cast a shared_ptr >> containing a Derived pointer, to shared_ptr ? >> __ > > If you've wrapped all classes with shared_ptr storage, to-python > converts should always produce the most-derived type in Python, and I > think that's what you want on the Python side. This may not work if you > can't use shared_ptr storage for some reason, or if you return an > intermediate class you haven't wrapped. > > Are you using shared_ptr storage? > > > Jim Bosch > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Py++ module for code with protected operator=
On Sat, Mar 20, 2010 at 11:10 PM, Maciej Sitarz wrote: > Just one more comment... > > The constructor takes reference to vector, so I suspect > that maybe it will be filled there by some other code I don't have? So I > don't need to fill the vector, just to create it (I will ask the developers) Right, you'd better talk with them. Boost.Python allows to export libraries without touching them, but sometimes a small library change could make you task easier. The following code works: #include struct item_t{ explicit item_t( int v) : value( v ) {} int value; protected: item_t& operator=( const item_t& other ); }; int main( int argc, const char** argv ){ std::vector< item_t > values( 10, item_t( 12 )); for( size_t i = 0; i < values.size(); ++i ){ values[ i ].value = i; } } -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Py++] boost::shared_ptr casting
On Sun, 2010-03-21 at 03:07 +0100, peoro wrote: > Yes, having all of the objects at their most-derived type would be > what I need, but it's not what happens. > > I posted a piece of C++ code that shows what I do (I exported it using > py++ without any further modification): all of the pointers my > functions return are wrapped in boost::shared_ptr's, but from Python I > see them at the "derivation level" they were when I passed them to > python the first time (look at the summarized output in my previous > message)... > Ok, maybe I'm not familiar with Py++ enough to help - I tend to just use Boost.Python directly. What I meant by "shared_ptr storage" is whether your class wrapper declarations look like this: boost::python::class_< wrapped, boost::shared_ptr > or this: boost::python::class_< wrapped > If it's the former, the downcasting will happen automatically. I would guess Py++ has a switch that turns this on, but I don't know what it is. Jim ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Py++] boost::shared_ptr casting
On Sun, Mar 21, 2010 at 4:07 AM, peoro wrote: > Yes, having all of the objects at their most-derived type would be > what I need, but it's not what happens. > > I posted a piece of C++ code that shows what I do (I exported it using > py++ without any further modification): all of the pointers my > functions return are wrapped in boost::shared_ptr's, but from Python I > see them at the "derivation level" they were when I passed them to > python the first time (look at the summarized output in my previous > message)... Can you check your code, but with the following class definition class Base { public: virtual ~Base(){} }; class Derived : public Base { }; -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig