From s_sourceforge at nedprod.com Sun Oct 1 20:21:06 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 01 Oct 2006 19:21:06 +0100 Subject: [C++-sig] TnFOX with the latest py++ from SVN Message-ID: <45201522.1846.205A0B@s_sourceforge.nedprod.com> Sorry it's taken so long to get onto this - but I have some conclusions. WARNING: void FX::FXGLViewer::eyeToScreen(FX::FXint & sx, FX::FXint & sy, FX::FXVec3f e) [member_function] > The function takes as argument (name=sx, pos=0 ) non-const reference > to C++ fundamental type - function could not be called from Python. Surely BPL can rebind the value of sx on output back to the input? I remember something in the tutorial about this just working out of the box. In vector_less_fx_scope_fxwindow_ptr__comma_std_scope_allocator_less_fx_s cope_fxwindow_ptr__grate___grate_.pypp.cpp, it doesn't automatically include boost/python/suite/indexing/vector_indexing_suite.hpp which it should as it uses it. I've added the insertion of a preprocessor define to indicate the file being compiled so a general include 'patches.h' can insert custom code: Index: multiple_files.py =================================================================== --- multiple_files.py (revision 609) +++ multiple_files.py (working copy) @@ -198,6 +198,7 @@ if self.extmodule.license: answer.append( self.extmodule.license.create() ) + answer.append( '#define PYPP_BUILDING_'+file_name.replace('.', '_').upper() ) head_headers = [ file_name + self.HEADER_EXT ] answer.append( self.create_include_code( creators, head_headers ) ) py++ still tries to subclass unions with wrappers, or expose them as read only data. This of course fails. I have a class called SysRandomness inheriting off FRandomness ie; class SysRandomness : protected QMutex, protected FRandomness. This causes py++ to specify FRandomness as the base class but this causes BPL to give an error as a pointer to SysRandomness cannot be converted to FRandomness. How do I disable py++ using bases<> for this class? The old problem of badly ordered declarations still occurs. After linking and on running I get: exceptions.TypeError,No to_python (by-value) converter found for C++ type: enum FX::FXACL::EntityType at line ? in ? This is due to: { //::FX::FXACL typedef bp::class_< FXACL_wrapper > FXACL_exposer_t; FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL", bp::init< bp::optional< FX::FXACL::EntityType, FX::FXACLEntity const & > >(( bp::arg("type")=::FX::FXACL::Unknown, bp::arg("owner")=FX::FXACLEntity::currentUser( ) )) ); bp::scope FXACL_scope( FXACL_exposer ); bp::enum_< FX::FXACL::EntityType>("EntityType") .value("Unknown", FX::FXACL::Unknown) .value("File", FX::FXACL::File) .value("Directory", FX::FXACL::Directory) .value("Pipe", FX::FXACL::Pipe) .value("MemMap", FX::FXACL::MemMap) .export_values() ; py++ specifies FXACL::EntityType as an optional construction parameter, but BPL needs it declared before usage. Not sure how this can be done sadly other than fixing BPL. Otherwise, things have improved greatly! I especially like the new bitfield support. Cheers, Niall From roman.yakovenko at gmail.com Sun Oct 1 21:51:15 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 1 Oct 2006 21:51:15 +0200 Subject: [C++-sig] TnFOX with the latest py++ from SVN In-Reply-To: <45201522.1846.205A0B@s_sourceforge.nedprod.com> References: <45201522.1846.205A0B@s_sourceforge.nedprod.com> Message-ID: <7465b6170610011251r495e1d31v12792ced7092f7c1@mail.gmail.com> On 10/1/06, Niall Douglas wrote: > Sorry it's taken so long to get onto this - but I have some > conclusions. > > WARNING: void FX::FXGLViewer::eyeToScreen(FX::FXint & sx, FX::FXint & > sy, FX::FXVec3f e) [member_function] > > The function takes as argument (name=sx, pos=0 ) non-const reference > > to C++ fundamental type - function could not be called from Python. > > Surely BPL can rebind the value of sx on output back to the input? I > remember something in the tutorial about this just working out of the > box. No it can not. In near future it will be very easy to instruct Py++ to create wrapper for such functions. > > In > vector_less_fx_scope_fxwindow_ptr__comma_std_scope_allocator_less_fx_s > cope_fxwindow_ptr__grate___grate_.pypp.cpp, it doesn't automatically > include boost/python/suite/indexing/vector_indexing_suite.hpp which > it should as it uses it. I am not sure about this one. I just checked this use case and it works as expected. I think I need more information here. May be this is an old file or something like this? > I've added the insertion of a preprocessor define to indicate the > file being compiled so a general include 'patches.h' can insert > custom code: > > Index: multiple_files.py > =================================================================== > --- multiple_files.py (revision 609) > +++ multiple_files.py (working copy) > @@ -198,6 +198,7 @@ > if self.extmodule.license: > answer.append( self.extmodule.license.create() ) > > + answer.append( '#define > PYPP_BUILDING_'+file_name.replace('.', '_').upper() ) > head_headers = [ file_name + self.HEADER_EXT ] > answer.append( self.create_include_code( creators, > head_headers ) ) You don't need this trick any more. It is possible to insert custom code to a file: http://language-binding.net/pyplusplus/documentation/inserting_code.html > py++ still tries to subclass unions with wrappers, or expose them as > read only data. This of course fails. Bug! I will fix it. The way I will fix it is by excluding them. For a time being you will have to wrap them manually. > I have a class called SysRandomness inheriting off FRandomness ie; > class SysRandomness : protected QMutex, protected FRandomness. This > causes py++ to specify FRandomness as the base class but this causes > BPL to give an error as a pointer to SysRandomness cannot be > converted to FRandomness. How do I disable py++ using bases<> for > this class? You can't. I think this is a bug in Py++. I fixed it and the fix in svn. > exceptions.TypeError,No to_python (by-value) converter found for C++ > type: enum FX::FXACL::EntityType at line ? in ? >... > py++ specifies FXACL::EntityType as an optional construction > parameter, but BPL needs it declared before usage. Not sure how this > can be done sadly other than fixing BPL. Fixed. The fix in svn. From now every constructor that has default argument of type "enum" that is declared in the class, the default value will be replaced with long( %default_values ) string. This does not fix the general case, but until now this is the only case the users asked to fix. I remember you had other problems with registration order. Take a look on this feature: http://sourceforge.net/mailarchive/message.php?msg_id=36710872 In short Py++ supports Boost.Python Auto-Overloading functionality ( http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.auto_overloading ) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dave at boost-consulting.com Mon Oct 2 15:15:28 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 02 Oct 2006 09:15:28 -0400 Subject: [C++-sig] TnFOX with the latest py++ from SVN References: <45201522.1846.205A0B@s_sourceforge.nedprod.com> <7465b6170610011251r495e1d31v12792ced7092f7c1@mail.gmail.com> Message-ID: <87wt7isvtb.fsf@pereiro.luannocracy.com> "Roman Yakovenko" writes: > On 10/1/06, Niall Douglas wrote: >> Sorry it's taken so long to get onto this - but I have some >> conclusions. >> >> WARNING: void FX::FXGLViewer::eyeToScreen(FX::FXint & sx, FX::FXint & >> sy, FX::FXVec3f e) [member_function] >> > The function takes as argument (name=sx, pos=0 ) non-const reference >> > to C++ fundamental type - function could not be called from Python. >> >> Surely BPL can rebind the value of sx on output back to the input? I >> remember something in the tutorial about this just working out of the >> box. > > No it can not. In near future it will be very easy to instruct Py++ to > create wrapper > for such functions. But even with a wrapper it's never going to automagically rebind anything, FWIW. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Mon Oct 2 16:42:18 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 02 Oct 2006 15:42:18 +0100 Subject: [C++-sig] TnFOX with the latest py++ from SVN In-Reply-To: <87wt7isvtb.fsf@pereiro.luannocracy.com> References: <45201522.1846.205A0B@s_sourceforge.nedprod.com>, <87wt7isvtb.fsf@pereiro.luannocracy.com> Message-ID: <4521335A.9056.1883565@s_sourceforge.nedprod.com> On 2 Oct 2006 at 9:15, David Abrahams wrote: > >> Surely BPL can rebind the value of sx on output back to the input? I > >> remember something in the tutorial about this just working out of the > >> box. > > > > No it can not. In near future it will be very easy to instruct Py++ to > > create wrapper > > for such functions. > > But even with a wrapper it's never going to automagically rebind > anything, FWIW. I'm probably being stupid, but surely if you pass by non-const reference then you *expect* it to change? Of course, modified in C++ is not modified in Python where basic types are immutable. But it does seem a reasonable approximation that as a default, the python parameter is rebound to the output value for integral types. Cheers, Niall From roman.yakovenko at gmail.com Mon Oct 2 21:06:00 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 2 Oct 2006 21:06:00 +0200 Subject: [C++-sig] TnFOX with the latest py++ from SVN In-Reply-To: <4521335A.9056.1883565@s_sourceforge.nedprod.com> References: <45201522.1846.205A0B@s_sourceforge.nedprod.com> <87wt7isvtb.fsf@pereiro.luannocracy.com> <4521335A.9056.1883565@s_sourceforge.nedprod.com> Message-ID: <7465b6170610021206x18198928p582bfc0fbdbc556d@mail.gmail.com> On 10/2/06, Niall Douglas wrote: > On 2 Oct 2006 at 9:15, David Abrahams wrote: > > > >> Surely BPL can rebind the value of sx on output back to the input? I > > >> remember something in the tutorial about this just working out of the > > >> box. > > > > > > No it can not. In near future it will be very easy to instruct Py++ to > > > create wrapper > > > for such functions. > > > > But even with a wrapper it's never going to automagically rebind > > anything, FWIW. > > I'm probably being stupid, but surely if you pass by non-const > reference then you *expect* it to change? > > Of course, modified in C++ is not modified in Python where basic > types are immutable. But it does seem a reasonable approximation that > as a default, the python parameter is rebound to the output value for > integral types. I am not sure whether it reasonable. In my opinion the behaviour, you propose, will surprise any Python developer and I am sure will break few invariants in Python. Solutions: "Out of the box" Boost.Python has a weaknesses if you work with C-like code. Consider next function: void do_smth( int& arg ); It is not possible to expose this function as-is to Python, a wrapper should be created: int do_smth_wrapper( int arg ){ int tmp( arg ); do_smth( tmp ); return tmp; } In my opinion Boost.Python could introduce interface similar to CTypes module: http://docs.python.org/dev/lib/node452.html . It will allow users to expose such functions without additional work. Users who want to call this function from Python will have to create special object - c_int: import my_module from boost_python_core import c_int arg = c_int( 23 ) my_module.do_smth( arg ) This approach has few advantages over the wrapper creation one: smaller compilation time, customization\\convenience wrappers could be created from Python. I am not sure whether it is possible to implement this in BPL or not. Meanwhile Matthias Baas introduced new feature to Py++ - "function transformation". It allows user to instruct Py++ what wrapper to create. The approach is semi-automated: ( The API of "function transformation" feature is not closed yet. ) mb = module_builder_t( ... ) do_smth = mb.free_function( 'do_smth' ) do_smth.function_transformations.append( inout( 0 ) ) Py++ will generate do_smth_wrapper function. Also in this case Py++ can( and some day it will ) generate a wrapper version without user intervention. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Tue Oct 3 00:56:18 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Mon, 2 Oct 2006 18:56:18 -0400 Subject: [C++-sig] Confusion about inheritance with boost.python Message-ID: <200610021856.18475.noah.schwartz1@gmail.com> Hi, I am a bit confused about how to properly handle inheritance when exposing my C++ classes to python. Here's my simple example: #include using namespace boost::python; class A { virtual ~A() = 0; virtual int f() = 0; }; struct AWrap : A, wrapper { int f() { return 0; } }; BOOST_PYTHON_MODULE(libnn) { class_("A") .def("f", pure_virtual(&A::f)) ; } However when I load my module in python I get a complaint about the undefined symbol A. I think I might be a bit generally confused about this. Thanks, Noah From mharidev at qualcomm.com Tue Oct 3 01:26:00 2006 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Mon, 2 Oct 2006 16:26:00 -0700 Subject: [C++-sig] Exposing c++ classes with static arrays using Boost.Python and py++ In-Reply-To: <7465b6170605032225i3ea790a3g5a86383dbebef4e3@mail.gmail.com> Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA8801B2BFB5@NAEX11.na.qualcomm.com> Hi Roman, A similar question was posted sometime ago: ------------------------------------------------------------------------ ---- While running Py++ on a class which contains a static array inside it, Py++ generates Boost.Python bindings using a derived class for the original C++ class. Let me illustrate with the help of the following example: ------------------------------------------------------------------------ ---- class AttributesTest { public: int staticIntArray[10]; }; Notice this class has an array inside it Running Py++ generates the following code, with a wrapper class that derives from the AttributesTest class. struct AttributesTest_wrapper : AttributesTest, bp::wrapper< AttributesTest> { AttributesTest_wrapper(AttributesTest const & arg ) : AttributesTest( arg ) , bp::wrapper< AttributesTest >() {} AttributesTest_wrapper( ) : AttributesTest( ) , bp::wrapper< AttributesTest >() {} pyplusplus::containers::static_sized::array_1_t< int, 10 > pyplusplus_staticIntArray_wrapper(){ return pyplusplus::containers::static_sized::array_1_t< int, 10 >( staticIntArray ); } }; and BOOST_PYTHON_MODULE(PYPP_Test){ if( true ){ typedef bp::class_< AttributesTest_wrapper > AttributesTest_exposer_t; AttributesTest_exposer_t AttributesTest_exposer = AttributesTest_exposer_t( "AttributesTest" ); bp::scope AttributesTest_scope( AttributesTest_exposer ); AttributesTest_exposer.def( bp::init< >()[bp::default_call_policies()] ); pyplusplus::containers::static_sized::register_array_1< int, 10, bp::default_call_policies >( "__array_1_int_10" ); AttributesTest_exposer.add_property( "staticIntArray", bp::make_function((pyplusplus::containers::static_sized::array_1_t< int, 10>(AttributesTest_wrapper::* )( )) &AttributesTest_wrapper::pyplusplus_staticIntArray_wrapper), bp::with_custodian_and_ward_postcall< 0, 1, bp::default_call_policies >() ) );; ------------------------------------------------------------------------ -- Note that it maps the python name "AttributesTest" to the derived class AttributesTest_wrapper. Also, let's say we have another class that looks like this and it is exposed to Python using Py++ as well: class NestedAttributesTest{ public: AttributesTest data[10]; } In Python we want to be able to do this: >> import PYPP_Test >> nested = PYPP_Test.NestedAttributesTest() >> nested.data.staticIntArray[0] = 1 This gives the following error: ArgumentError: Python argument types in None(AttributesTest) did not match C++ signature: None(AttributesTest_wrapper {lvalue}) Why not just keep it simple and rather than creating a derived class just create a namespace(for extra uniqueness) instead and map the variable "staticIntArray" via some method defined in that namespace, such as: .add_property( "staticIntArray", bp::make_function( (&AttributesTest_NSwrapper::pyplusplus_staticIntArray_wrapper), bp::with_custodian_and_ward_postcall< 0, 1, bp::default_call_policies >() ) );; and define the pyplusplus_staticIntArray_wrapper method in the namespace: namespace AttributesTest_NSwrapper{ pyplusplus::containers::static_sized::array_1_t< int, 10 > pyplusplus_staticIntArray_wrapper(){ return pyplusplus::containers::static_sized::array_1_t< int, 10 >( staticIntArray ); } } This solves the above mentioned problem that occurs when you use derived classes as wrappers instead. Any comments? Thanks, -Meghana. -----Original Message----- From: c++-sig-bounces+mharidev=qualcomm.com at python.org [mailto:c++-sig-bounces+mharidev=qualcomm.com at python.org] On Behalf Of Roman Yakovenko Sent: Wednesday, May 03, 2006 10:25 PM To: Abhi; Development of Python/C++ integration Subject: Re: [C++-sig] Exposing c++ classes with static arrays usingBoost.Python and py++ On 5/4/06, Abhi wrote: > While running py++ on a class with a static array inside it, py++ generates > Boost.Python bindings using a derived class for the original C++ class. > > pyplusplus::containers::static_sized::array_1_t< int, 10 > > pyplusplus_staticIntArray_wrapper(){ > return pyplusplus::containers::static_sized::array_1_t< int, 10 >( > staticIntArray ); > } I should make this function static and to take an instance as the first argument. Then generated code will work for derived classes too. I will fix it in few days > > Is there any drawback with just mapping the array variable to a global > method rather than mapping the whole class. Obviously, the generated code represents my understanding, preferences and personal taste of how it should be done. In this specific case py++ should mangle into function name: namespace name, class name, variable name. Or it should create some scope/namespace where IntArray will be unique name. Such scope already exists - class wrapper, so I reused it. Also the approach I choose, simplifies py++ code ( == less bugs ). I will re-think my approach, if you will give 3 good reasons, why it should be changed. :-) > thanks > - Abhi -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From dave at boost-consulting.com Tue Oct 3 05:06:35 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 02 Oct 2006 23:06:35 -0400 Subject: [C++-sig] TnFOX with the latest py++ from SVN References: <45201522.1846.205A0B@s_sourceforge.nedprod.com> <87wt7isvtb.fsf@pereiro.luannocracy.com> <4521335A.9056.1883565@s_sourceforge.nedprod.com> Message-ID: <87bqoukshw.fsf@pereiro.luannocracy.com> "Niall Douglas" writes: > On 2 Oct 2006 at 9:15, David Abrahams wrote: > >> >> Surely BPL can rebind the value of sx on output back to the input? I >> >> remember something in the tutorial about this just working out of the >> >> box. >> > >> > No it can not. In near future it will be very easy to instruct Py++ to >> > create wrapper >> > for such functions. >> >> But even with a wrapper it's never going to automagically rebind >> anything, FWIW. > > I'm probably being stupid, but surely if you pass by non-const > reference then you *expect* it to change? > > Of course, modified in C++ is not modified in Python where basic > types are immutable. But it does seem a reasonable approximation that > as a default, the python parameter is rebound to the output value for > integral types. There is absolutely no way for the function to detect which variable (if any) the original value was bound to. f(x + y) is an example where it wasn't bound to anything. You could try to do something unspeakable, like looking back up the python traceback and decompiling the code of the caller to figure it out, but even if that could work sometimes, it wouldn't work all the time. Anyway, if you want to try to implement such an abomination, more power to you, but it will never go into Boost.Python. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Oct 3 17:37:23 2006 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 03 Oct 2006 11:37:23 -0400 Subject: [C++-sig] Confusion about inheritance with boost.python References: <200610021856.18475.noah.schwartz1@gmail.com> Message-ID: <87lknxjtqk.fsf@pereiro.luannocracy.com> Noah Schwartz writes: > struct AWrap : A, wrapper { > int f() { > return 0; > } > }; > > BOOST_PYTHON_MODULE(libnn) > { > class_("A") > .def("f", pure_virtual(&A::f)) > ; > } This doesn't look right. If A::f is supposed to be exposed as pure virtual, you shouldn't be overriding it in AWrap. > However when I load my module in python I get a complaint about the > undefined symbol A. Please post the complete text of the complaint. In fact, please also post a reproducible example containing one C++ file and one Python file. -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Tue Oct 3 22:09:35 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 3 Oct 2006 22:09:35 +0200 Subject: [C++-sig] Exposing c++ classes with static arrays using Boost.Python and py++ In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA8801B2BFB5@NAEX11.na.qualcomm.com> References: <7465b6170605032225i3ea790a3g5a86383dbebef4e3@mail.gmail.com> <5383A81D5EB8F14FBDB487D9B5FBEA8801B2BFB5@NAEX11.na.qualcomm.com> Message-ID: <7465b6170610031309g131c8fd2l4f32eaff6ab5bb1@mail.gmail.com> On 10/3/06, Haridev, Meghana wrote: > Hi Roman, > Why not just keep it simple and rather than creating a derived class > just create a namespace(for extra uniqueness) instead and map the > variable "staticIntArray" via some method defined in that namespace, > such as: > .add_property( "staticIntArray", > bp::make_function( > > (&AttributesTest_NSwrapper::pyplusplus_staticIntArray_wrapper), > bp::with_custodian_and_ward_postcall< 0, 1, > bp::default_call_policies >() ) );; > > and define the pyplusplus_staticIntArray_wrapper method in the > namespace: > > namespace AttributesTest_NSwrapper{ > pyplusplus::containers::static_sized::array_1_t< int, 10 > > pyplusplus_staticIntArray_wrapper(){ > return pyplusplus::containers::static_sized::array_1_t< int, > 10 >( > staticIntArray ); > } > } > > This solves the above mentioned problem that occurs when you use derived > classes as wrappers instead. It smells like a problem in Boost.Python, also I can not say this for sure without creating small test case that reproduce the problem. > Any comments? I think Py++ should use "range" functionality to expose static arrays. I will try to find how to implement this. It will take some time so. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mharidev at qualcomm.com Wed Oct 4 00:06:45 2006 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Tue, 3 Oct 2006 15:06:45 -0700 Subject: [C++-sig] Exposing c++ classes with static arrays usingBoost.Python and py++ In-Reply-To: <7465b6170610031309g131c8fd2l4f32eaff6ab5bb1@mail.gmail.com> Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA8801B2C1B2@NAEX11.na.qualcomm.com> Hi Roman, I don't think it is a Boost.Python problem because I am able to expose the arrays successfully using namespaces. I think it is more to do with how Py++ exposes arrays (using derived classes). I have attached code to illustrate this by exposing arrays (of both simple and complex types) using namespaces instead of derived classes and how they can be successfully accessed in python. Please let me know what you think about this solution and if something similar can be incorporated into Py++ Thanks, -Meghana. -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, October 03, 2006 1:10 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Exposing c++ classes with static arrays usingBoost.Python and py++ On 10/3/06, Haridev, Meghana wrote: > Hi Roman, > Why not just keep it simple and rather than creating a derived class > just create a namespace(for extra uniqueness) instead and map the > variable "staticIntArray" via some method defined in that namespace, > such as: > .add_property( "staticIntArray", > bp::make_function( > > (&AttributesTest_NSwrapper::pyplusplus_staticIntArray_wrapper), > bp::with_custodian_and_ward_postcall< 0, 1, > bp::default_call_policies >() ) );; > > and define the pyplusplus_staticIntArray_wrapper method in the > namespace: > > namespace AttributesTest_NSwrapper{ > pyplusplus::containers::static_sized::array_1_t< int, 10 > > pyplusplus_staticIntArray_wrapper(){ > return pyplusplus::containers::static_sized::array_1_t< int, > 10 >( > staticIntArray ); > } > } > > This solves the above mentioned problem that occurs when you use derived > classes as wrappers instead. It smells like a problem in Boost.Python, also I can not say this for sure without creating small test case that reproduce the problem. > Any comments? I think Py++ should use "range" functionality to expose static arrays. I will try to find how to implement this. It will take some time so. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- A non-text attachment was scrubbed... Name: arrayTest.h Type: application/octet-stream Size: 148 bytes Desc: arrayTest.h URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: boost_arrayTest.cpp Type: application/octet-stream Size: 2576 bytes Desc: boost_arrayTest.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: __array_1.pypp.hpp Type: application/octet-stream Size: 3149 bytes Desc: __array_1.pypp.hpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: arrayTest.py Type: application/octet-stream Size: 267 bytes Desc: arrayTest.py URL: From roman.yakovenko at gmail.com Wed Oct 4 00:16:28 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 4 Oct 2006 00:16:28 +0200 Subject: [C++-sig] Exposing c++ classes with static arrays usingBoost.Python and py++ In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA8801B2C1B2@NAEX11.na.qualcomm.com> References: <7465b6170610031309g131c8fd2l4f32eaff6ab5bb1@mail.gmail.com> <5383A81D5EB8F14FBDB487D9B5FBEA8801B2C1B2@NAEX11.na.qualcomm.com> Message-ID: <7465b6170610031516y5fe4b1q6d9b162e2c597c96@mail.gmail.com> On 10/4/06, Haridev, Meghana wrote: > Hi Roman, > > I don't think it is a Boost.Python problem because I am able to expose > the arrays successfully using namespaces. I think it is more to do with > how Py++ exposes arrays (using derived classes). I was wrong. Py++ generated wrong code. > I have attached code to illustrate this by exposing arrays (of both > simple and complex types) using namespaces instead of derived classes > and how they can be successfully accessed in python. Please let me know > what you think about this solution and if something similar can be > incorporated into Py++ There is nothing wrong with your solution. For few reasons I prefer to user wrapper for such things. I just comitted a fix to your problem to SVN. Please try it and let me know what do you think and whether it fix your bug. I created a unit tests based on your input and now it passes. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From s_sourceforge at nedprod.com Wed Oct 4 10:16:31 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Wed, 04 Oct 2006 09:16:31 +0100 Subject: [C++-sig] TnFOX with the latest py++ from SVN In-Reply-To: <87bqoukshw.fsf@pereiro.luannocracy.com> References: <45201522.1846.205A0B@s_sourceforge.nedprod.com>, <87bqoukshw.fsf@pereiro.luannocracy.com> Message-ID: <45237BEF.21209.A73B9F6@s_sourceforge.nedprod.com> On 2 Oct 2006 at 23:06, David Abrahams wrote: > There is absolutely no way for the function to detect which variable (if any) > the original value was bound to. > > f(x + y) > > is an example where it wasn't bound to anything. > > You could try to do something unspeakable, like looking back up the python > traceback and decompiling the code of the caller to figure it out, but > even if that could work sometimes, it wouldn't work all the time. > Anyway, if you want to try to implement such an abomination, more > power to you, but it will never go into Boost.Python. Almost for the coding challenge that looks like fun, but well I'm nowhere near fifteen years old any more! More sensible would be if Python supplied this information to BPL. Then BPL can rightly throw an exception if you effectively bind to an rvalue. In other words, would you support adding this functionality to Python and afterwards BPL? Cheers, Niall From shiqinfeng at gmail.com Wed Oct 4 11:39:53 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Wed, 4 Oct 2006 19:39:53 +1000 Subject: [C++-sig] pass function pointer to c extension function in python Message-ID: Dear All, I used a global function pointer op, so that when op = add, it operates as add, when op = minus, it operates as minus. I used a function choose_op() to set op = add or minus. It works if I call choose_op() inside other function exposed in python. It reported a error when I used bjam to compile it if I exposed it into python. Any suggestion will be appreciated. Thanks in advance. ---------------------------c extension--------------------- float add(float a, float b){ return a+b; } float minus(float a, float b){ return a-b; } float (*op)(float a, float b) = add; void choose_op(float (* method)(float a, float b)){ op = method; } int funcPtrTest() { float a,b,c; a = 1; b = 2; c = -10; choose_op(minus); c = op(a,b); printf("%f\n",c); return 0; } BOOST_PYTHON_MODULE(hello){ def("funcPtrTest", &funcPtrTest); def("choose_op",&choose_op);// this line makes bjam report an error. Without it is ok. But without it also means we can't call it directly in python. } ------------------------result------------- (1)if without def("choose_op",&choose_op), >>> import hello >>> c = hello.funcPtrTest() -1.000000 so it works. (2)if with def("choose_op",&choose_op), It can't be compiled successfully by bjam. /boost_1_33_1/boost/type_traits/add_cv.hpp:34: error: `const volatile' qualifiers cannot be applied to `float ()(float, float)' -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ERANH at il.ibm.com Wed Oct 4 09:24:13 2006 From: ERANH at il.ibm.com (Haggai Eran) Date: Wed, 4 Oct 2006 09:24:13 +0200 Subject: [C++-sig] Exposing smart pointers to constants using boost.python Message-ID: Hi I'm having problems exposing functions that return a smart pointer that points to a constant variable using boost.python. The problem has been reported to this list in this message: http://mail.python.org/pipermail/c++-sig/2006-April/010503.html but I couldn't find any answer to this question. Haggai Eran From dave at boost-consulting.com Wed Oct 4 12:49:31 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 04 Oct 2006 06:49:31 -0400 Subject: [C++-sig] Confusion about inheritance with boost.python References: <200610021856.18475.noah.schwartz1@gmail.com> <87lknxjtqk.fsf@pereiro.luannocracy.com> Message-ID: <87odssfj9g.fsf@pereiro.luannocracy.com> David Abrahams writes: > Noah Schwartz writes: > >> struct AWrap : A, wrapper { >> int f() { >> return 0; >> } >> }; >> >> BOOST_PYTHON_MODULE(libnn) >> { >> class_("A") >> .def("f", pure_virtual(&A::f)) >> ; >> } > > This doesn't look right. If A::f is supposed to be exposed as pure > virtual, you shouldn't be overriding it in AWrap. Sorry, I don't know what I'm saying. AWrap should say: int f() { return get_override("f")(); } but of course that has nothing to do with your problem. >> However when I load my module in python I get a complaint about the >> undefined symbol A. > > Please post the complete text of the complaint. In fact, please also > post a reproducible example containing one C++ file and one Python > file. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Oct 4 12:53:56 2006 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 04 Oct 2006 06:53:56 -0400 Subject: [C++-sig] TnFOX with the latest py++ from SVN References: <45201522.1846.205A0B@s_sourceforge.nedprod.com> <87bqoukshw.fsf@pereiro.luannocracy.com> <45237BEF.21209.A73B9F6@s_sourceforge.nedprod.com> Message-ID: <87irj0fj23.fsf@pereiro.luannocracy.com> "Niall Douglas" writes: >> You could try to do something unspeakable, like looking back up the python >> traceback and decompiling the code of the caller to figure it out, but >> even if that could work sometimes, it wouldn't work all the time. >> Anyway, if you want to try to implement such an abomination, more >> power to you, but it will never go into Boost.Python. > > Almost for the coding challenge that looks like fun, but well I'm > nowhere near fifteen years old any more! > > More sensible would be if Python supplied this information to BPL. > Then BPL can rightly throw an exception if you effectively bind to an > rvalue. In other words, would you support adding this functionality > to Python and afterwards BPL? If you can get it past Guido, then I'd support adding it to the BPL, but IMO your chances are 0% because it would incur overheads on every function call that are needed on a tiny fraction, but more importantly it totally violates the Python programming model. The right way to wrap functions with such out parameters to transform the interface on the Python side so that tuples are returned. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ngoodspeed at solidworks.com Wed Oct 4 16:11:32 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Wed, 4 Oct 2006 10:11:32 -0400 Subject: [C++-sig] pass function pointer to c extension function in python Message-ID: <31E9B8A4BEFAA242B047A736B344578B237C03@corp-mail8.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi Sent: Wednesday, October 04, 2006 5:40 AM To: c++-sig at python.org Subject: [C++-sig] pass function pointer to c extension function in python I used a global function pointer op, so that when op = add, it operates as add, when op = minus, it operates as minus. I used a function choose_op() to set op = add or minus. It works if I call choose_op() inside other function exposed in python. It reported a error when I used bjam to compile it if I exposed it into python. Any suggestion will be appreciated. Thanks in advance. [Nat] How were you planning to have the client Python code pass to choose_op() a parameter of type 'float (* method)(float a, float b)'? Maybe you could publish to Python a wrapper function that accepts a string or something. On receiving "+", it would call choose_op(add), and so forth. From seefeld at sympatico.ca Wed Oct 4 16:37:40 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 04 Oct 2006 10:37:40 -0400 Subject: [C++-sig] pass function pointer to c extension function in python In-Reply-To: References: Message-ID: <4523C734.9040304@sympatico.ca> Qinfeng(Javen) Shi wrote: > Dear All, > > I used a global function pointer op, so that when op = add, it operates as > add, when op = minus, it operates as minus. I used a function > choose_op() to > set op = add or minus. It works if I call choose_op() inside other function > exposed in python. It reported a error when I used bjam to compile it if I > exposed it into python. > > Any suggestion will be appreciated. Thanks in advance. In python 'callables' are first-class objects; you can pass them around much as you can pass around C++ function pointers. There is no reason to export a 'choose_op' function from C++, as you can 'choose' (assign) a function directly inside python: > ---------------------------c extension--------------------- > float add(float a, float b){ > return a+b; > } > float minus(float a, float b){ > return a-b; > } > float (*op)(float a, float b) = add; > void choose_op(float (* method)(float a, float b)){ > op = method; > } > int funcPtrTest() > { > float a,b,c; > a = 1; > b = 2; > c = -10; > > choose_op(minus); > c = op(a,b); > printf("%f\n",c); > return 0; > } > > BOOST_PYTHON_MODULE(hello){ > def("funcPtrTest", &funcPtrTest); > def("choose_op",&choose_op);// this line makes bjam report an error. > Without > it is ok. But without it also means we can't call it directly in python. > } Make that: def("plus", plus); def("minus", minus); > ------------------------result------------- > (1)if without def("choose_op",&choose_op), >>>> import hello >>>> c = hello.funcPtrTest() > -1.000000 > so it works. > > (2)if with def("choose_op",&choose_op), > It can't be compiled successfully by bjam. > /boost_1_33_1/boost/type_traits/add_cv.hpp:34: error: `const > volatile' qualifiers cannot be applied to `float ()(float, float)' > ...and this: import hello op = hello.plus op(1, 2) op = hello.minus op(1, 2) Or did I misunderstand what you are trying to do ? HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From noah.schwartz1 at gmail.com Wed Oct 4 18:47:55 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 4 Oct 2006 12:47:55 -0400 Subject: [C++-sig] Confusion about inheritance with boost.python In-Reply-To: <87odssfj9g.fsf@pereiro.luannocracy.com> References: <200610021856.18475.noah.schwartz1@gmail.com> <87lknxjtqk.fsf@pereiro.luannocracy.com> <87odssfj9g.fsf@pereiro.luannocracy.com> Message-ID: <200610041247.55355.noah.schwartz1@gmail.com> On Wednesday 04 October 2006 06:49, David Abrahams wrote: > Sorry, I don't know what I'm saying. AWrap should say: > > int f() > { > return get_override("f")(); > } > > but of course that has nothing to do with your problem. Yeah, I just dropped a return 0 in there for the sake of keeping things more simple. Noah From noah.schwartz1 at gmail.com Wed Oct 4 18:53:35 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 4 Oct 2006 12:53:35 -0400 Subject: [C++-sig] Confusion about inheritance with boost.python In-Reply-To: <87lknxjtqk.fsf@pereiro.luannocracy.com> References: <200610021856.18475.noah.schwartz1@gmail.com> <87lknxjtqk.fsf@pereiro.luannocracy.com> Message-ID: <200610041253.35908.noah.schwartz1@gmail.com> On Tuesday 03 October 2006 11:37, David Abrahams wrote: > Noah Schwartz writes: > > struct AWrap : A, wrapper { > > int f() { > > return 0; > > } > > }; > > > > BOOST_PYTHON_MODULE(libnn) > > { > > class_("A") > > .def("f", pure_virtual(&A::f)) > > ; > > } > > This doesn't look right. If A::f is supposed to be exposed as pure > virtual, you shouldn't be overriding it in AWrap. From the documentation I got the impression that if you have some class A with a pure virtual function and will have classes inherit from A that will implement the virtual function, you need to wrap A so that the polymorphic relationship will work correctly. > > > However when I load my module in python I get a complaint about the > > undefined symbol A. > > Please post the complete text of the complaint. In fact, please also > post a reproducible example containing one C++ file and one Python > file. I don't have the exact error message anymore. Basically, it seemed like python didn't understand what A was and so couldn't understand AWrap. When I specified that AWrap had no init and so could not be created, the undefined symbol stopped occuring. I think this makes sense. I think some of my confusion with this simple example stemmed from a more general confusion about how to properly expose my classes to Python. I have things working correctly now, though. Thanks, Noah From agross at irobot.com Wed Oct 4 18:43:45 2006 From: agross at irobot.com (Gross, Ashley) Date: Wed, 4 Oct 2006 12:43:45 -0400 Subject: [C++-sig] intrusive pointer comparison in python Message-ID: <712A2DEC228C7448978CBD7A7AD5B09007D77B8E@fever.wardrobe.irobot.com> I've got a problem when comparing intrusive pointers in python. I've got a class wrapped in python that does not support the equality operator. In C++ intrusive pointers support equality comparisons by comparing the pointers that they hold. However in python, this does not appear to work. For example: intrusive_ptr1=foo() intrusive_ptr2=intrusive_ptr1 intrusive_ptr1==intrusive_ptr2 This gives me false. The only comparison that seems to work is comparing an object to itself: intrusive_ptr1==intrusive_ptr1 Is there a way to get this to work? Thanks, Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: From brdavs at yahoo.com Wed Oct 4 20:30:22 2006 From: brdavs at yahoo.com (Marko Skace) Date: Wed, 4 Oct 2006 11:30:22 -0700 (PDT) Subject: [C++-sig] wrapping 2D arrays with boost::python Message-ID: <20061004183022.93480.qmail@web30701.mail.mud.yahoo.com> I would like to wrap a a fixed 2-dimensional array with boost::python. Example: class Array2 { public: float* operator[]( int i ) { return data[i]; } private: float data[4][4]; }; I want to wrap this code such that __getitem__ and __setitem__ will work: array[2][3] = 1.0; Any suggestions and pointers are appreciated. Marko __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From agross at irobot.com Wed Oct 4 21:42:14 2006 From: agross at irobot.com (Gross, Ashley) Date: Wed, 4 Oct 2006 15:42:14 -0400 Subject: [C++-sig] intrusive pointer comparison in python Message-ID: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> Here's a better example: class foo; typedef boost::intrusive_ptr fooHandle; // personal refcounting implementation class foo: public reference_counted {}; }; class foocontainer { public: foocontainer():fooobj(foo::getfoo()) {} fooHandle getfoo() {return fooobj;} private: fooHandle fooobj; }; BOOST_PYTHON_MODULE(test_intrusive) { class_("foo"); class_("foocontainer") .def("getfoo",&foocontainer::getfoo); } Now if I go into python shell: >> x=foocontainer() >> test1=x.getfoo() >> test2=x.getfoo() >> test1==test2 False > -----Original Message----- > From: Hans Meine [mailto:meine at informatik.uni-hamburg.de] > Sent: Wednesday, October 04, 2006 1:03 PM > To: Gross, Ashley > Subject: Re: [C++-sig] intrusive pointer comparison in python > > On Wednesday, 04. October 2006 18:43, Gross, Ashley wrote: > > intrusive_ptr1=foo() > > > > intrusive_ptr2=intrusive_ptr1 > > > > intrusive_ptr1==intrusive_ptr2 > > AFAIK, this should work (it does out-of-the-box with BPL for me). > > -- > Ciao, / / > /--/ > / / ANS From amohr at pixar.com Wed Oct 4 22:10:28 2006 From: amohr at pixar.com (Alex Mohr) Date: Wed, 04 Oct 2006 13:10:28 -0700 Subject: [C++-sig] intrusive pointer comparison in python In-Reply-To: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> Message-ID: <45241534.8030904@pixar.com> > Here's a better example: > > class foo; > typedef boost::intrusive_ptr fooHandle; > > // personal refcounting implementation > class foo: public reference_counted {}; > }; > > class foocontainer { > public: > foocontainer():fooobj(foo::getfoo()) {} > fooHandle getfoo() {return fooobj;} > private: > fooHandle fooobj; > }; > > BOOST_PYTHON_MODULE(test_intrusive) { > class_("foo"); > class_("foocontainer") > .def("getfoo",&foocontainer::getfoo); > } > > Now if I go into python shell: >>> x=foocontainer() >>> test1=x.getfoo() >>> test2=x.getfoo() >>> test1==test2 > False This is due to the fact that boost::python doesn't really handle what I call the "object identity" problem. In this case, you expect test1 and test2 to be the same python object because they "represent" the same C++ object. They're not the same python object though -- boost python creates a new python wrapper each time a fooHandle is converted to-python. There's no simple way to solve this problem in boost::python as-is. It would be great if boost::python could have some support for doing this, because it's obviously an important thing. BTW: I should mention that boost::python does handle this correctly for objects that are exposed to python polymorphically (deriving from wrapper). But then only for polymorphic wrapper objects (boost::python holds the python object in wrapper). Incidentally, you can make your 'test1 == test2' line work by adding the equality operator to your wrapper, and have it compare the pointers. But you can't make 'test1 is test2' work. Alex From hans_meine at gmx.net Thu Oct 5 00:19:30 2006 From: hans_meine at gmx.net (Hans Meine) Date: Thu, 5 Oct 2006 00:19:30 +0200 Subject: [C++-sig] wrapping 2D arrays with boost::python In-Reply-To: <20061004183022.93480.qmail@web30701.mail.mud.yahoo.com> References: <20061004183022.93480.qmail@web30701.mail.mud.yahoo.com> Message-ID: <200610050019.31756.hans_meine@gmx.net> On Wednesday 04 October 2006 20:30, Marko Skace wrote: > I want to wrap this code such that __getitem__ and > __setitem__ will work: > > array[2][3] = 1.0; /me finds "array[2,3] = 1.0;" much more natural... (easy to do with __getitem__(tuple) ) Have fun, Hans From agross at irobot.com Thu Oct 5 00:20:56 2006 From: agross at irobot.com (Gross, Ashley) Date: Wed, 4 Oct 2006 18:20:56 -0400 Subject: [C++-sig] intrusive pointer comparison in python References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> <45241534.8030904@pixar.com> Message-ID: <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> Unfortunately, the class that I'm using isn't comparable, I'm bassically looking for a direct comparison of the held pointers. I'm not sure what you mean by "objects that are exposed to python polymorphically", can you please elaborate? Thanks, Ashley -----Original Message----- From: c++-sig-bounces at python.org on behalf of Alex Mohr Sent: Wed 10/4/2006 4:10 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] intrusive pointer comparison in python > Here's a better example: > > class foo; > typedef boost::intrusive_ptr fooHandle; > > // personal refcounting implementation > class foo: public reference_counted {}; > }; > > class foocontainer { > public: > foocontainer():fooobj(foo::getfoo()) {} > fooHandle getfoo() {return fooobj;} > private: > fooHandle fooobj; > }; > > BOOST_PYTHON_MODULE(test_intrusive) { > class_("foo"); > class_("foocontainer") > .def("getfoo",&foocontainer::getfoo); > } > > Now if I go into python shell: >>> x=foocontainer() >>> test1=x.getfoo() >>> test2=x.getfoo() >>> test1==test2 > False This is due to the fact that boost::python doesn't really handle what I call the "object identity" problem. In this case, you expect test1 and test2 to be the same python object because they "represent" the same C++ object. They're not the same python object though -- boost python creates a new python wrapper each time a fooHandle is converted to-python. There's no simple way to solve this problem in boost::python as-is. It would be great if boost::python could have some support for doing this, because it's obviously an important thing. BTW: I should mention that boost::python does handle this correctly for objects that are exposed to python polymorphically (deriving from wrapper). But then only for polymorphic wrapper objects (boost::python holds the python object in wrapper). Incidentally, you can make your 'test1 == test2' line work by adding the equality operator to your wrapper, and have it compare the pointers. But you can't make 'test1 is test2' work. Alex _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 3785 bytes Desc: not available URL: From amohr at pixar.com Thu Oct 5 00:32:30 2006 From: amohr at pixar.com (Alex Mohr) Date: Wed, 04 Oct 2006 15:32:30 -0700 Subject: [C++-sig] intrusive pointer comparison in python In-Reply-To: <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> <45241534.8030904@pixar.com> <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> Message-ID: <4524367E.6060602@pixar.com> > Unfortunately, the class that I'm using isn't comparable, I'm bassically looking for a direct comparison of the held pointers. That's what I said. Have it compare the pointers. template static bool are_ptrs_equal(Ptr const &self, Ptr const &other) { return self == other; } class_("foo") .def("__eq__", are_ptrs_equal); > I'm not sure what you mean by "objects that are exposed to python polymorphically", can you please elaborate? http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions Alex From shiqinfeng at gmail.com Thu Oct 5 03:11:32 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Thu, 5 Oct 2006 11:11:32 +1000 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointer to c extension function in python Message-ID: Hi Stefan and Nat, The problem is that "op" is not visible in python. How to make the function pointer visible and callable in python? And my real need is that I have a very complex function as following void process(arg1,...,arg_op){ ... op = arg_op; ... } so that it runs like >>process(arg1,..., minus) >>process(arg1,..., plus) So according to your replys, there are two possible solutions: (1)expose process() (which has a function pointer argument) to python. (2)expose the function pointer "op" to python, then assign minus or plus to "op" before we call process(). But how to make it? -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Thu Oct 5 05:03:40 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 04 Oct 2006 23:03:40 -0400 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointer to c extension function in python In-Reply-To: References: Message-ID: <4524760C.1010809@sympatico.ca> Qinfeng(Javen) Shi wrote: > Hi Stefan and Nat, > > The problem is that "op" is not visible in python. How to make the function > pointer visible and callable in python? Do you really mean 'callable' ? Or 'assignable', as your last mail suggested ? > And my real need is that I have a very complex function as following > > void process(arg1,...,arg_op){ > ... > op = arg_op; > ... > } > > so that it runs like >>> process(arg1,..., minus) >>> process(arg1,..., plus) I'm still not sure I fully understand your needs. How often is 'process' called ? How critical is good performance for it ? The best solution depends on the answer to those questions. For example, 'minus' as well as 'plus' could be python callables (which may actually be wrappers around your C++ functions), and your 'op' then may be a boost::python::object. However, whether that is viable performance-wise only you know. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From shiqinfeng at gmail.com Thu Oct 5 16:30:32 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Fri, 6 Oct 2006 00:30:32 +1000 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointer to Re: (Stefan Seefeld)(Nat Goodspeed) pass function pointer to c extension function in python Message-ID: Hi Stefan and Nat, 'process()' is implemented in c. It didn't lose much speed when I wrapped it into python. Speed is very important for it. The problem turns out to be: (1)I know how to wrap a function pointer op, but I don't know how to wrap it callable in python. (2)And I know how to wrap a normal function callalbe in python, but I don't know how to wrap a function which has a function pointer argument. I tried it in the same way with what I did for normal function, but failed. Does it make sense now? -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Thu Oct 5 16:49:19 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 05 Oct 2006 10:49:19 -0400 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointer to Re: (Stefan Seefeld)(Nat Goodspeed) pass function pointer to c extension function in python In-Reply-To: References: Message-ID: <45251B6F.40305@sympatico.ca> Qinfeng(Javen) Shi wrote: > Hi Stefan and Nat, > > 'process()' is implemented in c. It didn't lose much speed when I > wrapped it into python. Speed is very important for it. > > The problem turns out to be: > (1)I know how to wrap a function pointer op, but I don't know how to > wrap it callable in python. > (2)And I know how to wrap a normal function callalbe in python, but I > don't know how to wrap a function which has a function pointer argument. > I tried it in the same way with what I did for normal function, but failed. If both the 'process' function as well as the functions it should optionally call are provided by C++, why don't you just use some other parameter (a string, say), and then assign to your C++ function pointers, based on that discriminator ? I.e., you'd simply have some mapping from strings to function pointers, and then let the python side only care about the strings ? I think that's about what the other poster suggested initially... Regards, Stefan From dave at boost-consulting.com Thu Oct 5 16:38:09 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 05 Oct 2006 10:38:09 -0400 Subject: [C++-sig] intrusive pointer comparison in python References: <712A2DEC228C7448978CBD7A7AD5B09007D77B8E@fever.wardrobe.irobot.com> Message-ID: <87vemyakvi.fsf@pereiro.luannocracy.com> "Gross, Ashley" writes: > I?ve got a problem when comparing intrusive pointers in python. > I?ve got a class wrapped in python that does not support the > equality operator. In C++ intrusive pointers support equality > comparisons by comparing the pointers that they hold. However in > python, this does not appear to work. For example: > > intrusive_ptr1=foo() > > intrusive_ptr2=intrusive_ptr1 > > intrusive_ptr1==intrusive_ptr2 > > This gives me false. The only comparison that seems to work is comparing an object to itself: > > intrusive_ptr1==intrusive_ptr1 Both of your examples compare an object to itself. In the first example the names intrusive_ptr1 and intrusive_ptr2 are bound to the same object. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Oct 5 16:41:15 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 05 Oct 2006 10:41:15 -0400 Subject: [C++-sig] intrusive pointer comparison in python References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> <45241534.8030904@pixar.com> <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> <4524367E.6060602@pixar.com> Message-ID: <87psd6akqc.fsf@pereiro.luannocracy.com> Alex Mohr writes: >> Unfortunately, the class that I'm using isn't comparable, I'm bassically looking for a direct comparison of the held pointers. > > That's what I said. Have it compare the pointers. > > template > static bool are_ptrs_equal(Ptr const &self, > Ptr const &other) > { > return self == other; > } > > class_("foo") > .def("__eq__", are_ptrs_equal); isn't this the same as class_("foo") .def(self == self) ; ? -- Dave Abrahams Boost Consulting www.boost-consulting.com From agross at irobot.com Thu Oct 5 17:01:42 2006 From: agross at irobot.com (Gross, Ashley) Date: Thu, 5 Oct 2006 11:01:42 -0400 Subject: [C++-sig] intrusive pointer comparison in python Message-ID: <712A2DEC228C7448978CBD7A7AD5B09007DD66A4@fever.wardrobe.irobot.com> foo has no equality operator defined. Ashley > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of David Abrahams > Sent: Thursday, October 05, 2006 10:41 AM > To: c++-sig at python.org > Subject: Re: [C++-sig] intrusive pointer comparison in python > > Alex Mohr writes: > > >> Unfortunately, the class that I'm using isn't comparable, I'm > bassically looking for a direct comparison of the held pointers. > > > > That's what I said. Have it compare the pointers. > > > > template > > static bool are_ptrs_equal(Ptr const &self, > > Ptr const &other) > > { > > return self == other; > > } > > > > class_("foo") > > .def("__eq__", are_ptrs_equal); > > isn't this the same as > > class_("foo") > .def(self == self) > ; > ? > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From ngoodspeed at solidworks.com Thu Oct 5 17:15:29 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Thu, 5 Oct 2006 11:15:29 -0400 Subject: [C++-sig] pass function pointerto c extension function in python Message-ID: <31E9B8A4BEFAA242B047A736B344578B237E34@corp-mail8.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi Sent: Thursday, October 05, 2006 10:31 AM To: c++-sig at python.org Subject: Re: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointerto Re: (Stefan Seefeld)(Nat Goodspeed) pass function pointerto c extension function in python [Nat] Stephan is trying to determine your functional requirements. I blithely assumed some and tried to answer on that basis. Since you're still asking, evidently we do not yet know what you need to be able to do with this C++ function pointer in Python. I assumed that you don't actually need to /call/ the function pointer from Python: you only need Python code to /assign/ it, and the call will happen later in C++ code. That's why I suggested that perhaps you could represent the set of possible C++ target functions using symbolic values in Python. You could populate a C++ map whose keys are those symbolic values and whose values are the actual C++ function pointers. A Python request to set the function pointer would pass a symbolic Python value. The C++ function would look up that value and assign the corresponding function pointer. Stephan assumed that you might need to call the function in Python as well as in C++. Therefore you'd use a Python callable, a first-class Python object. Publish the whole set of possible target C++ functions (add, minus, etc.) to Python. Don't even bother trying to represent a C++ function pointer in Python. The Python call that sets the function pointer will receive a boost::python::object, perhaps named something like 'function'. Store it as a boost::python::object. When your C++ code needs to call it, simply call function(args...). There are several big advantages to Stephan's approach, among them: - You can call the selected function from Python as well as from C++. - You could later write a new Python function and select that rather than any one of the original C++ target functions, thus extending the functionality of process(). > 'process()' is implemented in c. It didn't lose much speed when I > wrapped it into python. Speed is very important for it. [Nat] I *think* you're saying here that you don't want process() to use Python callables. You want it to directly call the C++ target function via a C++ function pointer. > The problem turns out to be: > (1) I know how to wrap a function pointer op, but I don't know how > to wrap it callable in python. [Nat] But on the other hand, now you seem to be saying that you DO need to be able to call the target function from Python as well as from C++. > (2) And I know how to wrap a normal function callable in python, > but I don't know how to wrap a function which has a function > pointer argument. [Nat] Other Boosters will correct me if I'm wrong, but I do not believe that it's possible to directly represent a C++ function pointer as a Python data object. And I believe that's what would be necessary in order for Boost.Python to be able to wrap a C++ function that accepts a C++ function pointer as an argument. Therefore I do not believe it's possible to directly wrap such a function. I still think Stephan has the right idea. You should probably implement it his way and do some performance testing. "Premature optimization is the root of all evil..." Put differently, getting the algorithm right has a much bigger performance impact than tweaking implementation details. But if making function calls indirectly through Python's calling machinery turns out to slow down process() unacceptably, then here's another thought. - Keep the C++ function pointer and call it directly from within process(). - Set it indirectly from Python as I described in my second paragraph above. - If you need to call it from Python, publish a new C++ function whose only purpose is to call through the C++ function pointer. In this alternative, Python never directly sees the C++ function pointer. From amohr at pixar.com Thu Oct 5 18:42:21 2006 From: amohr at pixar.com (Alex Mohr) Date: Thu, 05 Oct 2006 09:42:21 -0700 Subject: [C++-sig] intrusive pointer comparison in python In-Reply-To: <87psd6akqc.fsf@pereiro.luannocracy.com> References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> <45241534.8030904@pixar.com> <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> <4524367E.6060602@pixar.com> <87psd6akqc.fsf@pereiro.luannocracy.com> Message-ID: <452535ED.5010400@pixar.com> >> class_("foo") >> .def("__eq__", are_ptrs_equal); > > isn't this the same as > > class_("foo") > .def(self == self) > ; > ? Unless I'm mistaken, no I don't think so. I think that 'self == self' will generate an overload expecting 'foo' arguments, and will compare the 'foo' objects directly, rather than comparing 'fooHandle's. Ashley said that 'foo' is not comparable. Let me know if I'm misreading operators.hpp though. Alex From shiqinfeng at gmail.com Sat Oct 7 10:06:40 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Sat, 7 Oct 2006 18:06:40 +1000 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointer to c Message-ID: Stefan and Nat, Thanks for your suggestion. Maybe I don't explain my requirement clearly. The reason why I don't pass a string parameter then assgin a funtion pointer inside the process() is that, I want to provide a extendable interface.The goal is that user can provide any new operation function without rewriting process(). For instance, if a user write a new operation function called "multiply"(any name but I could't know what name he would like to give), he can still call process(arg1,..., multiply). One day another user write another operation function called "vectorproduct", he can also call process(arg1,...,vectorproduct). If I do it in Stefan's way, every time when user provide a new operation function, the process() has to be rewriten. User may not want to rewrite process() code every time, and furthermore the source code of process() is not always provided for users. Thanks. Do you get me now? -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Sat Oct 7 14:47:33 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 07 Oct 2006 08:47:33 -0400 Subject: [C++-sig] intrusive pointer comparison in python References: <712A2DEC228C7448978CBD7A7AD5B09007D77FB0@fever.wardrobe.irobot.com> <45241534.8030904@pixar.com> <712A2DEC228C7448978CBD7A7AD5B090045690D6@fever.wardrobe.irobot.com> <4524367E.6060602@pixar.com> <87psd6akqc.fsf@pereiro.luannocracy.com> <452535ED.5010400@pixar.com> Message-ID: <878xjswavu.fsf@pereiro.luannocracy.com> Alex Mohr writes: >>> class_("foo") >>> .def("__eq__", are_ptrs_equal); >> >> isn't this the same as >> >> class_("foo") >> .def(self == self) >> ; >> ? > > Unless I'm mistaken, no I don't think so. I think that 'self == self' > will generate an overload expecting 'foo' arguments, and will compare > the 'foo' objects directly, rather than comparing 'fooHandle's. Ashley > said that 'foo' is not comparable. > > Let me know if I'm misreading operators.hpp though. You're not. Thanks for pointing out what I should have seen. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ngoodspeed at solidworks.com Sat Oct 7 15:53:24 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Sat, 7 Oct 2006 09:53:24 -0400 Subject: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointerto c Message-ID: <31E9B8A4BEFAA242B047A736B344578B2381BD@corp-mail8.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi Sent: Saturday, October 07, 2006 4:07 AM To: c++-sig at python.org Subject: Re: [C++-sig] (Stefan Seefeld)(Nat Goodspeed) pass function pointerto c The reason why I don't pass a string parameter then assign a function pointer inside the process() is that, I want to provide a extendable interface. The goal is that user can provide any new operation function without rewriting process(). For instance, if a user write a new operation function called "multiply"(any name but I could't know what name he would like to give), he can still call process(arg1,..., multiply). One day another user write another operation function called "vectorproduct", he can also call process(arg1,...,vectorproduct). [Nat] Okay, that's a good reason not to do it the way I originally suggested. If I do it in Stefan's way, every time when user provide a new operation function, the process() has to be rewriten. User may not want to rewrite process() code every time, and furthermore the source code of process() is not always provided for users. [Nat] Here's where the disconnect lies. I must respectfully disagree with your statement that process() must be rewritten to extend the set of operation functions. I think it would go something like this (not compiled, silly syntax errors likely): ----- C++ code defining ProcessModule ----- // Candidate functions for 'op' float add(float a, float b){ return a+b; } float minus(float a, float b){ return a-b; } // op boost::python::object op; // Was choose_op just for your test program, if process accepts // arg_op? void choose_op(boost::python::object method) { op = method; } // process void process(arg1,..., boost::python::object arg_op){ ... op = arg_op; ... float a = 5; float b = 3; float result = op(a, b); ... } // ... publish add, minus, choose_op, process as usual ... ----- Python code ----- import ProcessModule process(..., ProcessModule.add) process(..., ProcessModule.minus) // You can define new operation functions in ProcessModule or elsewhere. // You can even define them in Python: def multiply(a, b): return a * b process(..., multiply) From agross at irobot.com Sat Oct 7 19:49:26 2006 From: agross at irobot.com (Gross, Ashley) Date: Sat, 7 Oct 2006 13:49:26 -0400 Subject: [C++-sig] intrusive pointer comparison in python Message-ID: <712A2DEC228C7448978CBD7A7AD5B09007E6EAED@fever.wardrobe.irobot.com> I think I've got something worked out, thanks for all your help :) Ashley > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On > Behalf Of David Abrahams > Sent: Saturday, October 07, 2006 8:48 AM > To: c++-sig at python.org > Subject: Re: [C++-sig] intrusive pointer comparison in python > > Alex Mohr writes: > > >>> class_("foo") > >>> .def("__eq__", are_ptrs_equal); > >> > >> isn't this the same as > >> > >> class_("foo") > >> .def(self == self) > >> ; > >> ? > > > > Unless I'm mistaken, no I don't think so. I think that 'self == self' > > will generate an overload expecting 'foo' arguments, and will compare > > the 'foo' objects directly, rather than comparing 'fooHandle's. Ashley > > said that 'foo' is not comparable. > > > > Let me know if I'm misreading operators.hpp though. > > You're not. Thanks for pointing out what I should have seen. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From shiqinfeng at gmail.com Mon Oct 9 02:18:35 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Mon, 9 Oct 2006 10:18:35 +1000 Subject: [C++-sig] (Nat Goodspeed) pass function pointerto c Message-ID: Hi Nat, Thank you very much. I tried what you said, but it seems boost::python::object can't be converted to float by (float) (op(a,b)). So I converted the pointer of op's result into float*, but got a unexpected result. Something wrong with my code? -------------------------c extension--------------- boost::python::object op; void process(arg1,..., boost::python::object arg_op){ ... op = arg_op; ... float a = 1; float b = 2; boost::python::object rlt = op(a,b); float * f = (float *) (rlt.ptr()); printf("%f \n",*f); ... } ---------------------result----------------------------- >>> import hello >>> hello.funcPtrTest(hello.add) 0.000000 >>> hello.funcPtrTest(hello.minus) 0.000000 >>> -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Mon Oct 9 02:32:53 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 08 Oct 2006 20:32:53 -0400 Subject: [C++-sig] (Nat Goodspeed) pass function pointerto c In-Reply-To: References: Message-ID: <452998B5.5090401@sympatico.ca> Qinfeng(Javen) Shi wrote: > Hi Nat, > > Thank you very much. > I tried what you said, but it seems boost::python::object can't be > converted to float by (float) (op(a,b)). So I converted the pointer of > op's result into float*, but got a unexpected result. Something wrong > with my code? > > -------------------------c extension--------------- > boost::python::object op; > > void process(arg1,..., boost::python::object arg_op){ > ... > op = arg_op; > ... > float a = 1; > float b = 2; > > boost::python::object rlt = op(a,b); > float * f = (float *) (rlt.ptr()); make that float f = boost::python::extract(rlt); Would that work ? On a stylistic note: There is almost never a reason to use C-style casts in a C++ program. At least use one of const_cast, static_cast, or reinterpret_cast instead. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From thilinasepala at gmail.com Mon Oct 9 11:59:36 2006 From: thilinasepala at gmail.com (thilina sepala dahanayake) Date: Mon, 9 Oct 2006 11:59:36 +0200 (CEST) Subject: [C++-sig] thilina sepala dahanayake has invited you to use Google Talk Message-ID: <16619871.17353181160386489222.chat@gmail.com> I've been using Google Talk and thought you might like to try it out. We can use it to call each other for free over the internet. Here's an invitation to download Google Talk. Give it a try! ------------------------------------------------------------------------ thilina sepala dahanayake has invited you to sign up for Google Talk so you can talk to each other for free over your computers. To sign-up, go to: http://www.google.com/accounts/NewAccount?service=talk&sendvemail=true&skipvpage=true&reqemail=c%2B%2B-sig%40python.org&continue=http%3A%2F%2Fwww.google.com%2Ftalk%2Fservice%2Fhandleinvite%3Fp%3DhQPp-w8BAAA.shjwgNYxwNoYebhbkAxBQqCLxUtC7g3FfzMCGYlm7KTO2613I2vJrl-IKVv5NJOL.cRAgKZKDyKEheueE4oCpHQ&followup=http%3A%2F%2Fwww.google.com%2Ftalk%2Fservice%2FHandleEmailVerified%3Fee%3DhQPp-w8BAAA._xTV1HxGe4wLucmqGIn2RMWQnl15aN5B-UJaDbEyXU4.AmT9owsfHJ9-tO_jjLv3ew Google Talk is a downloadable Windows* application that offers: - Free calls over your computer anytime, from anywhere, and for as long as you want - A simple and intuitive user interface for sending instant messages or making calls--no clutter, pop-ups or ads - Superior voice quality through just a microphone and computer speaker - Fast file transfers with no restrictions on file type After signing-up, download Google Talk and sign in with your new Google Account username and password. You can then begin inviting anyone you want to talk to for free. Google Talk works with any computer speaker and microphone, such as the ones built-in to many PC laptops today, as well as with wired and wireless headsets and USB phones. Google Talk also works across all firewalls. Google Talk is still in beta. Just like with Gmail, we're working hard to add features and make improvements, so we might also ask for your comments and suggestions periodically. We appreciate your help in making it even better! Thanks, The Google Talk Team To learn more about Google Talk before signing up, visit: http://www.google.com/talk/about.html (If clicking the URLs in this message does not work, copy and paste them into the address bar of your browser). * Not a Windows user? No problem. You can also connect to the Google Talk service from any platform using third-party clients (http://www.google.com/talk/otherclients.html). From shiqinfeng at gmail.com Mon Oct 9 17:54:29 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Tue, 10 Oct 2006 01:54:29 +1000 Subject: [C++-sig] (Stefan Seefeld) pass function pointerto c Message-ID: Hi Stefan, Thanks very much. > make that >float f = boost::python::extract(rlt); >Would that work ? It works if arg_op = plus or minus. ( here process(boost::python::object arg_op)). But it didn't work if arg_op = vectorPlus. It seems that arg_op can't accept a c++ float pointer. Acctually the real vectorPlus() used in my code has been optimized for speed and kindof unfriendly readable. I listed the simple version of vectorPlus() which had the same idea and problem. For speed reason, I can't use plus(p1[i],p2[i]) instead of vectorPlus(p1,p2,length).So I hope vectorPlus can work. ---------------------c extension----------------- vectorPlus(float* p1, float* p2,int point_len)// plus for two vectors. { float sum = 0; for (int i=0;i (rlt); printf("%f \n",*f); ... } ----------------------result -------------------- >>> import hello >>> hello.process(hello.vectorPlus) Traceback (most recent call last): File "", line 1, in ? TypeError: No to_python (by-value) converter found for C++ type: float* >>> -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From abierbaum at gmail.com Mon Oct 9 17:55:55 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Mon, 9 Oct 2006 10:55:55 -0500 Subject: [C++-sig] A little "Pure virtual function called" help... Message-ID: I have a rather frustrating problem in a binding I am trying to extend. It is inside a rather complex binding that is partially described here: http://thread.gmane.org/gmane.comp.python.c++/10125/focus=10125 It is complex because I am using custom smart pointers and it is wrapping a very large library so coming up with a small test case has been difficult. In fact the small from scratch test case I created worked which was surprising. I have a Geometry class that has a set of methods that return access to geometry properties. For example it may return an object that holds a list of positions in space. These positions could be in any number of formats (float, double, int, etc) so the library returns a base class that acts as an adapter and provides uniform access to all the various possible formats. All of these classes are in C++ so although I do have the wrapper types generated by Py++, I don't think they are relevant to this discussion. The format hierarchy has classes like this: class GeoVectorProperty { .... void setValue( variant_type, 0); virtual unsigned getSize() = 0; }; class GeoVectorPropertyVec3f : public GeoVectorProperty { .... virtual unsigned getSize(); } I have successfully wrapped GeoVectorProperty but I would like to avoid wrapping all of the numerous implementations of the "real" types. Instead I want to just keep using the base adapter interface and calling those methods to access the data. I thought things were good until I tried the code in python: >>> g >>> pos = g.getPositions() >>> pos >>> pos.size() Traceback (most recent call last): File "", line 1, in ? RuntimeError: Pure virtual function called >>> pos.setValue(osg2.Vec3f(0,0,0), 1) The problem seems to be that for some reason the pure virtual method "size" is not being called correctly. I know that the class behind the scenes for "pos" is a derived type because the "setValue" method uses the virtual methods internally in the C++ code. At first I thought that maybe Py++ was not wrapping this correctly but I created a simple test cases with 2 classes and a factory function that when wrapped worked correctly when calling a pure virtual of a base class. To make matters a little stranger, I found that if I edit the pure virtual method GeoVectorProperty::getSize() and make it none pure by returning 0, then everything works as expected. So I am left wondering where to turn next? I am suspicious that possibly the python object "pos" doesn't have a pointer type that is able to handle this correctly. It should, but that code is deep inside the smart_pointer wrappers and boost.python conversion code and I don't have any way to verify what the type is. So my question is, what should I look for next? Any hints as to how to try to debug this problem? Thanks, Allen From seefeld at sympatico.ca Mon Oct 9 18:06:14 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 09 Oct 2006 12:06:14 -0400 Subject: [C++-sig] (Stefan Seefeld) pass function pointerto c In-Reply-To: References: Message-ID: <452A7376.2090904@sympatico.ca> Qinfeng(Javen) Shi wrote: > Hi Stefan, > > Thanks very much. > >> make that >> float f = boost::python::extract(rlt); >> Would that work ? > It works if arg_op = plus or minus. ( here process(boost::python::object > arg_op)). > But it didn't work if arg_op = vectorPlus. It seems that arg_op can't > accept > a c++ float pointer. Python has no notion of pointer. So, the float * is accepted, but that's because for convenience the boost.python side accepts it as a pointer to a single item. You can't pass arrays like that. (You may want to look at http://boost.org/libs/python/doc/v2/indexing.html to see how you can export containers.) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From dave at boost-consulting.com Mon Oct 9 21:23:23 2006 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 Oct 2006 15:23:23 -0400 Subject: [C++-sig] A little "Pure virtual function called" help... References: Message-ID: <87fydxpa38.fsf@pereiro.luannocracy.com> "Allen Bierbaum" writes: > I have a rather frustrating problem in a binding I am trying to > extend. It is inside a rather complex binding that is partially > described here: > http://thread.gmane.org/gmane.comp.python.c++/10125/focus=10125 > > It is complex because I am using custom smart pointers and it is > wrapping a very large library so coming up with a small test case has > been difficult. In fact the small from scratch test case I created > worked which was surprising. Just progressively reduce the case that fails until it stops failing or you find the problem. If you do the reduction using a binary search you'll be there in no time. -- Dave Abrahams Boost Consulting www.boost-consulting.com From monty at inaugust.com Tue Oct 10 21:54:38 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 12:54:38 -0700 Subject: [C++-sig] mapping object pointers with boost Message-ID: Hey all, So all the examples in the docs just deal with standard arguments, as far as I can tell, and I'm stuck trying to figure this out. I'm guessing I could write a wrapper, but I'm hoping there is some simple way I'm just not seeing... Oh, and I'm interfacing code that can't change, so I'll have to wrap it rather than fix it. :) I've got a class with a constructor that looks like this: Ndb::Ndb(Ndb_cluster_connection*, const char*, const char*); I have an Ndb_cluster_connection already defined: class_("Ndb_cluster_connection") .def("connect",&Ndb_cluster_connection::connect) .def("wait_until_ready",&Ndb_cluster_connection::wait_until_ready) ; and it works. So I tried doing this: class_("Ndb") .def(init()); Which did not work. As you might expect, I get this error: boost/python/object/value_holder.hpp:134: error: no matching function for call to 'Ndb::Ndb()' Ndb.hpp:1084: note: candidates are: Ndb::Ndb(Ndb_cluster_connection*, const char*, const char*) Ndb.hpp:1047: note: Ndb::Ndb(const Ndb&) I'm not even trying to deal with the overloads at the moment, although maybe I have to. Any thoughts on a sensible way to deal with this? Am I looking at wrapping this in some way? The usage from the python side should sort of look like: conn=Ndb_cluster_connection() n=Ndb(conn,"foo","bar") I suppose I could make an Ndb_cluster_connection::getNdb() which would be easier to wrap in this case - but I would love to understand general mechanism better so I can deal with things the 'right' way. This will not be the only time I need to do something like that. Pointers to the right place in the docs are appreciated, too. Thanks! Monty From amohr at pixar.com Tue Oct 10 22:26:12 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 13:26:12 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: Message-ID: <452C01E4.80306@pixar.com> > class_("Ndb") > .def(init()); Try this: class_("Ndb") .def(init()); Alex From grant.tang at gmail.com Tue Oct 10 22:33:43 2006 From: grant.tang at gmail.com (Grant Tang) Date: Tue, 10 Oct 2006 15:33:43 -0500 Subject: [C++-sig] How to compile boost.python with '-fPIC' option Message-ID: I am trying to compile boost.python for a static libboost_python.a library, I need compile it with -fPIC option, but in the Jamfile I can not figure out a way to add this option? Can somebody help me? Thx -- Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From monty at inaugust.com Tue Oct 10 22:52:44 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 13:52:44 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C01E4.80306@pixar.com> References: <452C01E4.80306@pixar.com> Message-ID: Ha. But that actually makes sense. :) But unfortunately, I'm still getting: error: no matching function for call to 'Ndb::Ndb()' thanks, Monty On 10/10/06, Alex Mohr wrote: > > class_("Ndb") > > .def(init()); > > Try this: > > class_("Ndb") > .def(init()); > > Alex > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From amohr at pixar.com Tue Oct 10 22:56:47 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 13:56:47 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> Message-ID: <452C090F.10600@pixar.com> > Ha. But that actually makes sense. :) > > But unfortunately, I'm still getting: > error: no matching function for call to 'Ndb::Ndb()' That's because by not saying "no_init" in the class_<> constructor, boost python has assumed that you have a default constructor. Try this: class_("Ndb", no_init) .def(init()); Alex From monty at inaugust.com Tue Oct 10 23:28:06 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 14:28:06 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C090F.10600@pixar.com> References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> Message-ID: Well. That seems to have done it. And it even makes sense. Thanks! On 10/10/06, Alex Mohr wrote: > > Ha. But that actually makes sense. :) > > > > But unfortunately, I'm still getting: > > error: no matching function for call to 'Ndb::Ndb()' > > That's because by not saying "no_init" in the class_<> constructor, > boost python has assumed that you have a default constructor. Try this: > > class_("Ndb", no_init) > .def(init()); > > Alex > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From monty at inaugust.com Wed Oct 11 00:53:49 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 15:53:49 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> Message-ID: On to more problems... So there's another method, Ndb::getDictionary that's wrapped as follows .def("getDictionary",&Ndb::getDictionary, return_value_policy()) as you might assume from the name, it returns an NdbDictionary: class_("NdbDictionary",no_init); Problem is, Dictionary's constructor and destructor are protected, which boost doesn't seem to like. Any ideas? Thanks, Monty On 10/10/06, Monty Taylor wrote: > Well. That seems to have done it. And it even makes sense. Thanks! > > > > On 10/10/06, Alex Mohr wrote: > > > Ha. But that actually makes sense. :) > > > > > > But unfortunately, I'm still getting: > > > error: no matching function for call to 'Ndb::Ndb()' > > > > That's because by not saying "no_init" in the class_<> constructor, > > boost python has assumed that you have a default constructor. Try this: > > > > class_("Ndb", no_init) > > .def(init()); > > > > Alex > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > From amohr at pixar.com Wed Oct 11 00:59:33 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 15:59:33 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> Message-ID: <452C25D5.2090609@pixar.com> > class_("NdbDictionary",no_init); > > Problem is, Dictionary's constructor and destructor are protected, > which boost doesn't seem to like. Try: class_(...) But if the copy ctor's protected/private, I don't think copy_const_ref can work. Alex From monty at inaugust.com Wed Oct 11 02:05:52 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:05:52 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C25D5.2090609@pixar.com> References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> Message-ID: Once again, that did the trick. The copy_const_ref was me trying to do the opposite of the right thing. One more question... (probably more of just a basic C++ question - it's a little rusty) The code has a nested class Dictionary inside NdbDictionary. The Dictionary class has a method, getTable. So I tried this: class_("Dictionary",no_init) .def("getTable", &NdbDictionary::Dictionary::getTable, return_value_policy() ) ; But it doesn't see getTable as a method - it sees NdbDictionary as a method that it can't find. How do I tell it how to find the original method? Thanks! Monty On 10/10/06, Alex Mohr wrote: > > class_("NdbDictionary",no_init); > > > > Problem is, Dictionary's constructor and destructor are protected, > > which boost doesn't seem to like. > > Try: > > class_(...) > > But if the copy ctor's protected/private, I don't think copy_const_ref > can work. > > Alex > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From seefeld at sympatico.ca Wed Oct 11 02:12:23 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 10 Oct 2006 20:12:23 -0400 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> Message-ID: <452C36E7.7090901@sympatico.ca> Monty Taylor wrote: > The code has a nested class Dictionary inside NdbDictionary. The > Dictionary class has a method, getTable. So I tried this: > > class_("Dictionary",no_init) > .def("getTable", &NdbDictionary::Dictionary::getTable, > return_value_policy() ) > ; > > But it doesn't see getTable as a method - it sees NdbDictionary as a > method that it can't find. How do I tell it how to find the original > method? Please post the actual error message you get with the above code. Thanks, Stefan From amohr at pixar.com Wed Oct 11 02:16:40 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 17:16:40 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> Message-ID: <452C37E8.4040202@pixar.com> > One more question... (probably more of just a basic C++ question - > it's a little rusty) > > The code has a nested class Dictionary inside NdbDictionary. The > Dictionary class has a method, getTable. So I tried this: > > class_("Dictionary",no_init) > .def("getTable", &NdbDictionary::Dictionary::getTable, > return_value_policy() ) > ; > > But it doesn't see getTable as a method - it sees NdbDictionary as a > method that it can't find. How do I tell it how to find the original > method? On the surface this looks correct to me. I've wrapped stuff like this: class Foo { class Bar { void method() {} }; }; Similarly before, using &Foo::Bar::method to get a pointer to the method. Are you using a peculiar compiler or are any of these private/protected? Or -- if your wrapping code is in a template, you might have to say something like: typedef typename NdbDictionary::Dictionary Dictionary; and then: &Dictionary::getTable But as Stefan says, more details would help. Alex From monty at inaugust.com Wed Oct 11 02:17:15 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:17:15 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C36E7.7090901@sympatico.ca> References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> Message-ID: _ndb.cpp:50: error: no matching function for call to 'boost::python::class_::def(const char [9], , boost::python::return_value_policy)' On 10/10/06, Stefan Seefeld wrote: > Monty Taylor wrote: > > > The code has a nested class Dictionary inside NdbDictionary. The > > Dictionary class has a method, getTable. So I tried this: > > > > class_("Dictionary",no_init) > > .def("getTable", &NdbDictionary::Dictionary::getTable, > > return_value_policy() ) > > ; > > > > But it doesn't see getTable as a method - it sees NdbDictionary as a > > method that it can't find. How do I tell it how to find the original > > method? > > Please post the actual error message you get with the above code. > > Thanks, > Stefan > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From monty at inaugust.com Wed Oct 11 02:18:35 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:18:35 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> Message-ID: getTable looks like this: class NdbDictionary { class Dictionary { const Table * getTable(const char * name) const; } } On 10/10/06, Monty Taylor wrote: > _ndb.cpp:50: error: no matching function for call to > 'boost::python::class_ boost::noncopyable_::noncopyable, > boost::python::detail::not_specified, > boost::python::detail::not_specified>::def(const char [9], overloaded function type>, > boost::python::return_value_policy boost::python::default_call_policies>)' > > > On 10/10/06, Stefan Seefeld wrote: > > Monty Taylor wrote: > > > > > The code has a nested class Dictionary inside NdbDictionary. The > > > Dictionary class has a method, getTable. So I tried this: > > > > > > class_("Dictionary",no_init) > > > .def("getTable", &NdbDictionary::Dictionary::getTable, > > > return_value_policy() ) > > > ; > > > > > > But it doesn't see getTable as a method - it sees NdbDictionary as a > > > method that it can't find. How do I tell it how to find the original > > > method? > > > > Please post the actual error message you get with the above code. > > > > Thanks, > > Stefan > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > From amohr at pixar.com Wed Oct 11 02:23:12 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 17:23:12 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C01E4.80306@pixar.com> <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> Message-ID: <452C3970.6010800@pixar.com> Monty Taylor wrote: > _ndb.cpp:50: error: no matching function for call to > 'boost::python::class_ boost::noncopyable_::noncopyable, > boost::python::detail::not_specified, > boost::python::detail::not_specified>::def(const char [9], overloaded function type>, > boost::python::return_value_policy boost::python::default_call_policies>)' Is getTable overloaded, by any chance? Alex From monty at inaugust.com Wed Oct 11 02:38:13 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:38:13 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C3970.6010800@pixar.com> References: <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> <452C3970.6010800@pixar.com> Message-ID: well... it didn't look that way, but NdbDictionary does have one as well, so the nested scoping may be doing it? So the whole picture is more like: class NdbDictionary { class Dictionary { const Table * getTable(const char * name) const; } const Table * getTable(const char * name, void **data) const; } On 10/10/06, Alex Mohr wrote: > Monty Taylor wrote: > > _ndb.cpp:50: error: no matching function for call to > > 'boost::python::class_ > boost::noncopyable_::noncopyable, > > boost::python::detail::not_specified, > > boost::python::detail::not_specified>::def(const char [9], > overloaded function type>, > > boost::python::return_value_policy > boost::python::default_call_policies>)' > > Is getTable overloaded, by any chance? > > Alex > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From amohr at pixar.com Wed Oct 11 02:42:17 2006 From: amohr at pixar.com (Alex Mohr) Date: Tue, 10 Oct 2006 17:42:17 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C090F.10600@pixar.com> <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> <452C3970.6010800@pixar.com> Message-ID: <452C3DE9.6010406@pixar.com> > well... it didn't look that way, but NdbDictionary does have one as > well, so the nested scoping may be doing it? > > So the whole picture is more like: > class NdbDictionary { > class Dictionary { > const Table * getTable(const char * name) const; > } > const Table * getTable(const char * name, void **data) const; > } Hmm. Well, your compiler is claiming that the argument passed to def() is an "unresolved overloaded function type". Is your compiler broken? Can you write code that takes the address of NdbDictionary::Dictionary::getTable outside the context of boost.python? Alex From monty at inaugust.com Wed Oct 11 02:47:18 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:47:18 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: <452C3DE9.6010406@pixar.com> References: <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> <452C3970.6010800@pixar.com> <452C3DE9.6010406@pixar.com> Message-ID: I'll try real quick. On 10/10/06, Alex Mohr wrote: > > well... it didn't look that way, but NdbDictionary does have one as > > well, so the nested scoping may be doing it? > > > > So the whole picture is more like: > > class NdbDictionary { > > class Dictionary { > > const Table * getTable(const char * name) const; > > } > > const Table * getTable(const char * name, void **data) const; > > } > > Hmm. Well, your compiler is claiming that the argument passed to def() > is an "unresolved overloaded function type". Is your compiler broken? > > Can you write code that takes the address of > NdbDictionary::Dictionary::getTable outside the context of boost.python? > > Alex > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From monty at inaugust.com Wed Oct 11 02:59:10 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 17:59:10 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> <452C3970.6010800@pixar.com> <452C3DE9.6010406@pixar.com> Message-ID: The compiler (g++ 4.1) seems to see both methods, at least based on seeing the output of what it considers candidates. I'll try treating the method as overloaded and see where I can get. error: no matches converting function 'getTable' to type 'struct Table* (*)(const char*)' /usr/include/mysql/ndb/ndbapi/NdbDictionary.hpp:1174: error: candidates are: const NdbDictionary::Table* NdbDictionary::Dictionary::getTable(const char*) const /usr/include/mysql/ndb/ndbapi/NdbDictionary.hpp:1331: error: const NdbDictionary::Table* NdbDictionary::Dictionary::getTable(const char*, void**) const On 10/10/06, Monty Taylor wrote: > I'll try real quick. > > On 10/10/06, Alex Mohr wrote: > > > well... it didn't look that way, but NdbDictionary does have one as > > > well, so the nested scoping may be doing it? > > > > > > So the whole picture is more like: > > > class NdbDictionary { > > > class Dictionary { > > > const Table * getTable(const char * name) const; > > > } > > > const Table * getTable(const char * name, void **data) const; > > > } > > > > Hmm. Well, your compiler is claiming that the argument passed to def() > > is an "unresolved overloaded function type". Is your compiler broken? > > > > Can you write code that takes the address of > > NdbDictionary::Dictionary::getTable outside the context of boost.python? > > > > Alex > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > From monty at inaugust.com Wed Oct 11 03:09:21 2006 From: monty at inaugust.com (Monty Taylor) Date: Tue, 10 Oct 2006 18:09:21 -0700 Subject: [C++-sig] mapping object pointers with boost In-Reply-To: References: <452C25D5.2090609@pixar.com> <452C36E7.7090901@sympatico.ca> <452C3970.6010800@pixar.com> <452C3DE9.6010406@pixar.com> Message-ID: No luck. I tried this: BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(dict_overloads, getTable, 1, 2) and class_("Dictionary",no_init) .def("getTable", &NdbDictionary::Dictionary::getTable, dict_overloads("name")[reference_existing_object<>()] ) ; based on the example code: http://www.boost.org/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec And still get: _ndb.cpp: In function 'void init_module__ndb()': _ndb.cpp:53: error: 'boost::python::reference_existing_object' is not a template _ndb.cpp:53: error: no matching function for call to 'boost::python::class_::def(const char [9], , boost::python::detail::overloads_proxy)' On 10/10/06, Monty Taylor wrote: > The compiler (g++ 4.1) seems to see both methods, at least based on > seeing the output of what it considers candidates. I'll try treating > the method as overloaded and see where I can get. > > error: no matches converting function 'getTable' to type 'struct > Table* (*)(const char*)' > /usr/include/mysql/ndb/ndbapi/NdbDictionary.hpp:1174: error: > candidates are: const NdbDictionary::Table* > NdbDictionary::Dictionary::getTable(const char*) const > /usr/include/mysql/ndb/ndbapi/NdbDictionary.hpp:1331: error: > const NdbDictionary::Table* > NdbDictionary::Dictionary::getTable(const char*, void**) const > > > On 10/10/06, Monty Taylor wrote: > > I'll try real quick. > > > > On 10/10/06, Alex Mohr wrote: > > > > well... it didn't look that way, but NdbDictionary does have one as > > > > well, so the nested scoping may be doing it? > > > > > > > > So the whole picture is more like: > > > > class NdbDictionary { > > > > class Dictionary { > > > > const Table * getTable(const char * name) const; > > > > } > > > > const Table * getTable(const char * name, void **data) const; > > > > } > > > > > > Hmm. Well, your compiler is claiming that the argument passed to def() > > > is an "unresolved overloaded function type". Is your compiler broken? > > > > > > Can you write code that takes the address of > > > NdbDictionary::Dictionary::getTable outside the context of boost.python? > > > > > > Alex > > > _______________________________________________ > > > C++-sig mailing list > > > C++-sig at python.org > > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > From monty at inaugust.com Wed Oct 11 22:11:56 2006 From: monty at inaugust.com (Monty Taylor) Date: Wed, 11 Oct 2006 13:11:56 -0700 Subject: [C++-sig] private destructor In-Reply-To: References: Message-ID: Hi all, I've got a class with a private destructor. So I marked it no_init: class_("NdbTransaction",no_init); based on a thread about what pyste should do in a similar situation. But I'm still getting: /usr/include/mysql/ndb/ndbapi/NdbTransaction.hpp:586: error: 'NdbTransaction::~NdbTransaction()' is private /home/mtaylor/src/boost/cctbx_sources/boost/boost/python/object/value_holder.hpp:134: error: within this context /usr/include/mysql/ndb/ndbapi/NdbTransaction.hpp: In destructor 'virtual boost::python::objects::value_holder::~value_holder()': /usr/include/mysql/ndb/ndbapi/NdbTransaction.hpp:586: error: 'NdbTransaction::~NdbTransaction()' is private Is there something else special I should do? Thanks, Monty From nindi73 at yahoo.co.uk Sat Oct 14 23:38:45 2006 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Sat, 14 Oct 2006 21:38:45 +0000 (GMT) Subject: [C++-sig] python bool not C++ bool Message-ID: <20061014213845.98204.qmail@web27908.mail.ukl.yahoo.com> I would very much like to pass bools from python to C++ and have them accepted as bools. However I cannot seem to do this. My code class MyTestClass { public: MyTestClass ():theType("Empty"){} MyTestClass(bool theBool):theType("Bool"){} MyTestClass(int theInt):theType("Int"){} object GetType(){return object(theType);} std::string theType; }; void exportTestClass() { class_ theClass_("TestClass"); theClass_.def(init()); theClass_.def(init()); theClass_.def("GetType",&MyTestClass::GetType); } then the output in python is >>> a = TestClass(True) >>> a.GetType() 'Int' >>> a = TestClass(10) >>> a.GetType() 'Int' >>> a = TestClass(bool(True)) >>> a.GetType() 'Int' >>> I cannot see what I am doing wrong, as I understand from http://mail.python.org/pipermail/c++-sig/2005-September/009503.html that it should work. I am using boost 1.33 ___________________________________________________________ Try the all-new Yahoo! Mail. "The New Version is radically easier to use" ? The Wall Street Journal http://uk.docs.yahoo.com/nowyoucan.html ___________________________________________________________ All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine http://uk.docs.yahoo.com/nowyoucan.html From roman.yakovenko at gmail.com Sun Oct 15 08:34:48 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 15 Oct 2006 08:34:48 +0200 Subject: [C++-sig] private destructor In-Reply-To: References: Message-ID: <7465b6170610142334i2d069426xd964d1be8fbedf0a@mail.gmail.com> On 10/11/06, Monty Taylor wrote: > Hi all, > > I've got a class with a private destructor. So I marked it no_init: > > class_("NdbTransaction",no_init); > > based on a thread about what pyste should do in a similar situation. > But I'm still getting: Try Py++. It handles such situation well :-) For the next class struct X{ int i; private: ~X(){} }; Py++ generates next code: bp::class_< X, boost::noncopyable >( "X", bp::no_init ) .def_readwrite( "i", &X::i ); Take a look on Py++ GUI - you don't have to learn any API. http://language-binding.net/pyplusplus/documentation/tutorials/tutorials.html#graphical-interface -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From nindi73 at yahoo.co.uk Sun Oct 15 21:59:40 2006 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Sun, 15 Oct 2006 19:59:40 +0000 (GMT) Subject: [C++-sig] (no subject) Message-ID: <20061015195940.6467.qmail@web27912.mail.ukl.yahoo.com> In the Boost.Python dict class there are methods 'iteritems', 'iterkeys' and 'itervalues' all returning objects. How exactly are you supposed to use these objects (iterators) ? Send instant messages to your online friends http://uk.messenger.yahoo.com From nindi73 at yahoo.co.uk Sun Oct 15 22:02:23 2006 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Sun, 15 Oct 2006 20:02:23 +0000 (GMT) Subject: [C++-sig] 'iteritems', 'iterkeys' and 'itervalues' in dict Message-ID: <20061015200223.21926.qmail@web27907.mail.ukl.yahoo.com> Apolgies for not putting the subject line in my last email. In the Boost.Python dict class there are methods 'iteritems', 'iterkeys' and 'itervalues' all returning objects. How exactly are you supposed to use these objects (iterators) ? ___________________________________________________________ Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html From nindi73 at yahoo.co.uk Sun Oct 15 22:36:46 2006 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Sun, 15 Oct 2006 20:36:46 +0000 (GMT) Subject: [C++-sig] 'iteritems', 'iterkeys' and 'itervalues' in dict Message-ID: <20061015203646.181.qmail@web27915.mail.ukl.yahoo.com> SOLVED I just hit it with PyIter_Next .. so I have to step a but outside Boost. ----- Original Message ---- From: Nindi Singh To: c++-sig at python.org Sent: Sunday, 15 October, 2006 9:02:23 PM Subject: [C++-sig] 'iteritems', 'iterkeys' and 'itervalues' in dict Apolgies for not putting the subject line in my last email. In the Boost.Python dict class there are methods 'iteritems', 'iterkeys' and 'itervalues' all returning objects. How exactly are you supposed to use these objects (iterators) ? ___________________________________________________________ Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig Send instant messages to your online friends http://uk.messenger.yahoo.com From michael.drumheller at boeing.com Mon Oct 16 06:54:45 2006 From: michael.drumheller at boeing.com (Drumheller, Michael) Date: Sun, 15 Oct 2006 21:54:45 -0700 Subject: [C++-sig] Boost.Python and Threads Message-ID: <716621DCB4468F46BBCC1BCFBED45C120281C6FE@XCH-NW-2V2.nw.nos.boeing.com> I am interested in whatever workarounds/patches might exist for releasing/acquiring the GIL from Boost.Python-based C++ extensions. The FAQ http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport says this is basically not supported, but mentions a patch on C++-sig. Is the following http://mail.python.org/pipermail/c++-sig/2003-July/004791.html the patch being referred to? It would be great if I could find out whether the author of that patch (Vladimir Vukicevic), or anyone else, is still using it and still believes that it works, or, if not, are there any other similar patches out there that one should try? Thank you. Michael Drumheller Boeing Phantom Works Mathematics and Engineering Analysis 425.373.2703 michael.drumheller at boeing.com This email may contain proprietary information. If you are not the intended recipient please delete it and notify the sender that you received it in error. From shiqinfeng at gmail.com Mon Oct 16 10:25:08 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Mon, 16 Oct 2006 18:25:08 +1000 Subject: [C++-sig] Assign a value to its non-existing attribue, why it did not report a error? Message-ID: Dear All, I wrapped a class, and get a instance of it, then assign a value to its non-existing attribue. It should report a error. But it doesn't, and it adds the non-existing attribue to it. I want it reports a error when user assign value to a non-existing attribue mistakely. Anyone can help me? Thanks in advance. ---------------------c extension--------------- class cover_tree { public: cover_tree() { } }; BOOST_PYTHON_MODULE(hello) { class_("cover_tree",init<>()); } >>> c = hello.cover_tree() >>> c.adf //c doesn't have adf attribute, but still can assign. Traceback (most recent call last): File "", line 1, in ? AttributeError: 'cover_tree' object has no attribute 'adf' >>> c.adf = 1 >>> dir(c) [ ... 'adf'] >>> -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_sourceforge at nedprod.com Mon Oct 16 10:50:59 2006 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 16 Oct 2006 09:50:59 +0100 Subject: [C++-sig] Boost.Python and Threads In-Reply-To: <716621DCB4468F46BBCC1BCFBED45C120281C6FE@XCH-NW-2V2.nw.nos.boeing.com> References: <716621DCB4468F46BBCC1BCFBED45C120281C6FE@XCH-NW-2V2.nw.nos.boeing.com> Message-ID: <45335603.4437.76F42@s_sourceforge.nedprod.com> On 15 Oct 2006 at 21:54, Drumheller, Michael wrote: > I am interested in whatever workarounds/patches might exist for > releasing/acquiring > the GIL from Boost.Python-based C++ extensions. The FAQ > http://www.boost.org/libs/python/doc/v2/faq.html#threadsupport > says this is basically not supported, but mentions a patch on C++-sig. > Is the following > http://mail.python.org/pipermail/c++-sig/2003-July/004791.html > the patch being referred to? > > It would be great if I could find out whether the author of that patch > (Vladimir > Vukicevic), or anyone else, is still using it and still believes that it > works, or, if > not, are there any other similar patches out there that one should try? I believe that my GIL patch to BPL is the standard one off which most people base their own for the last few years. You can find it inside BoostPatches.zip inside the TnFOX SVN (at http://www.nedprod.com/TnFOX/). You'll need to tailor it around your own threading system, but it does have all the changes in the right places. Cheers, Niall From ngoodspeed at solidworks.com Mon Oct 16 14:26:56 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 16 Oct 2006 08:26:56 -0400 Subject: [C++-sig] Assign a value to its non-existing attribue, why it did not report a error? Message-ID: <31E9B8A4BEFAA242B047A736B344578B26D981@corp-mail8.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi Sent: Monday, October 16, 2006 4:25 AM To: c++-sig at python.org Subject: [C++-sig] Assign a value to its non-existing attribue,why it did not report a error? I wrapped a class, and get a instance of it, then assign a value to its non-existing attribue. It should report a error. But it doesn't, and it adds the non-existing attribue to it. [Nat] In Python, it should not report an error, it should add the new attribute. Try defining a small class in Python, creating an instance and assigning to a previously-undefined attribute - without involving your C++ code at all. This is the expected behavior in Python. class Foo(object): pass foo = Foo() foo.itWorks = True I want it reports a error when user assign value to a non-existing attribue mistakely. [Nat] Are you sure you want it to behave differently than a native Python object? In a pure-Python class, you could define your own __setattr__() method: http://docs.python.org/ref/attribute-access.html Your method could examine self.__dict__ and, if the specified attribute isn't already there, raise an exception. But I should add that I've never tried using the __setattr__() mechanism with a C++ object published to Python. From ngoodspeed at solidworks.com Mon Oct 16 14:33:12 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 16 Oct 2006 08:33:12 -0400 Subject: [C++-sig] Assign a value to its non-existing attribue, why it did not report a error? Message-ID: <31E9B8A4BEFAA242B047A736B344578B26D984@corp-mail8.solidworks.swk> > -----Original Message----- > From: c++-sig-bounces+ngoodspeed=solidworks.com at python.org [mailto:c++- > sig-bounces+ngoodspeed=solidworks.com at python.org] On Behalf Of Nat > Goodspeed > Sent: Monday, October 16, 2006 8:27 AM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] Assign a value to its non-existing attribue,why it > did not report a error? > > Your method could examine self.__dict__ and, if the specified attribute > isn't already there, raise an exception. [Nat] One obvious gotcha is that you'll have to suppress the exception long enough to allow each new instance to acquire the attributes you expect! From shiqinfeng at gmail.com Mon Oct 16 14:40:34 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Mon, 16 Oct 2006 22:40:34 +1000 Subject: [C++-sig] Problem with using boost::python::object and PyArrayObject* and PyObject* Message-ID: Dear All, I used python object to implement something like function pointer in C. So for my funcPtrTest3(boost::python::object), given a function object, funcPtrTest3 will call object(a,b) inside. It works perfect when a, b are simple python compatabile type(such as int, float). It does't work when a, b are c array type, because python has no pointer. So I use numpy.ndarray( PyArrayObject* in c) to wrap the c array. But python reports a error that it seems python can't recognize PyArrayObject as numpy.ndarray. If I use PyObject* instead of PyArrayObject*,it can't even be compiled successfully. Any help will be appreciated! /-------------------------using PyArrayObject* result------------------------------/ >>> import hello as H >>> H.funcPtrTest3(H.norm2_distPyObject) 0.000000 1.000000 2.000000 3.000000 4.000000 Traceback (most recent call last): File "", line 1, in ? TypeError: No to_python (by-value) converter found for C++ type: PyArrayObject >>> /--------------------------c extension-----------------------/ void funcPtrTest3(boost::python::object arg_op) { op = arg_op; float fArray[5] = {0,1,2,3,4}; intp m = 5; PyArrayObject* c = convertPtrToPyArray(fArray,5); op(c,c,1000); } PyArrayObject* convertPtrToPyArray(float * p1,int point_len) { for (int i = 0; i upper_bound) return sqrt(sum); } return sqrt(sum); } BOOST_PYTHON_MODULE(hello) { import_array(); ar::array::set_module_and_type("numpy", "ndarray"); def("funcPtrTest3", &funcPtrTest3); def("norm2_distPyArrayObject",&norm2_distPyArrayObject); } /---------------------using PyObject* result--------------------------------/ /home/users/qshi/boost_1_33_1/boost/python/converter/arg_to_python.hpp: In static member function `static void boost::python::converter::detail::reject_raw_object_helper::error(Convertibility) [with T = PyObject, Convertibility = char*]' /home/users/qshi/boost_1_33_1/boost/python/converter/arg_to_python.hpp:181: error: incomplete type ' boost::python::converter::detail::cannot_convert_raw_PyObject' cannot be used to name a scope /--------------------------------- c extension-----------------------------------/ void funcPtrTest3(boost::python::object arg_op) { op = arg_op; float fArray[5] = {0,1,2,3,4}; intp m = 5; PyArrayObject* c = convertPtrToPyArray(fArray,5); op(c,c,1000); } PyObject* convertPtrToPyObject(float * p1, int point_len) { for (int i = 0; i From Narinder.CLAIRE at rbos.com Tue Oct 17 16:21:38 2006 From: Narinder.CLAIRE at rbos.com (CLAIRE, Narinder, Group Risk Mgmt) Date: Tue, 17 Oct 2006 15:21:38 +0100 Subject: [C++-sig] (no subject) Message-ID: <3AFBCEBFD689FC459151885D7C9980D602309ADE@lonms01008.fm.rbsgrp.net> *********************************************************************************** The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB. Authorised and regulated by the Financial Services Authority This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer. Internet e-mails are not necessarily secure. The Royal Bank of Scotland plc does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that the onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is accepted by The Royal Bank of Scotland plc in this regard and the recipient should carry out such virus and other checks as it considers appropriate. Visit our websites at: http://www.rbos.com http://www.rbsmarkets.com *********************************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Tue Oct 17 17:01:59 2006 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 17 Oct 2006 11:01:59 -0400 Subject: [C++-sig] int vs. char Message-ID: In wrapping ublas::vector class, I enountered the following tiny problem. Here is one constructor: template inline vector* vector_with_init (int size, object const& init) { T ival = extract (init); return new vector (size, ival); } In the case of vector (T==char), then this python code fails: u = vector_char (K, 0) TypeError: No registered converter was able to produce a C++ rvalue of type char from this Python object of type int Of course, this will work: u = vector_char (K, char(0)) But I wonder if there is a better solution? From shiqinfeng at gmail.com Wed Oct 18 02:03:00 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Wed, 18 Oct 2006 10:03:00 +1000 Subject: [C++-sig] (Stefan Seefeld) pass function pointerto c Message-ID: Hi Stefan, >Python has no notion of pointer. So, the float * is accepted, but >that's because for convenience the boost.python side accepts it as a >pointer to a single item. You can't pass arrays like that. >(You may want to look at http://boost.org/libs/python/doc/v2/indexing.html >to see how you can export containers.) I saw this indexing method. I want to expose float* to python, so that boost::python::object(float*,float*) is callable in c extension. But here float* is not a class. If even I "typedef float* vector;", then expose vector as following, class_("Vec") .def(vector_indexing_suite()) ; it will report a error."error: `float*' is not a class, struct, or union type" Could you tell me how to expose it? Thanks. -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Oct 18 02:20:43 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 17 Oct 2006 20:20:43 -0400 Subject: [C++-sig] (Stefan Seefeld) pass function pointerto c In-Reply-To: References: Message-ID: <4535735B.40905@sympatico.ca> Qinfeng(Javen) Shi wrote: > Hi Stefan, > >> Python has no notion of pointer. So, the float * is accepted, but >> that's because for convenience the boost.python side accepts it as a >> pointer to a single item. You can't pass arrays like that. >> (You may want to look at >> http://boost.org/libs/python/doc/v2/indexing.html >> to see how you can export containers.) > > I saw this indexing method. I want to expose float* to python, so that > boost::python::object(float*,float*) is callable in c extension. > > But here float* is not a class. If even I "typedef float* vector;", then > expose vector as following, > class_("Vec") > .def(vector_indexing_suite()) > ; > > it will report a error."error: `float*' is not a class, struct, or union > type" Right. Typedefs don't create new types, only aliases, and so the above fails. > Could you tell me how to expose it? I'd wrap the array pointed to by your float pointer into an actual class. That has the side-effect of allowing you to make element-access a little safer, and to allow introspection (report the array's size, for example). Then you can expose that class using the index_suite I pointed you at in the other mail. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From noah.schwartz1 at gmail.com Wed Oct 18 22:04:07 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 18 Oct 2006 16:04:07 -0400 Subject: [C++-sig] C++ object pointers contained in a vector Message-ID: <200610181604.07329.noah.schwartz1@gmail.com> Hi, I've used the vector_indexing_suite to expose vectors containing pointers to some class. I see that I can't iterate over this vector in Python like I can with say, a vector of floats. I get the following error: TypeError: No to_python (by-value) converter found for C++ type: MyClass* MyClass is already exposed properly. I can even use a MyClass* fine in Python when other C++ functions return a pointer to one. I am guessing that I need to define a to_python converter either in MyClass or in a new class, MyClass*. Not really sure how that works though. Noah From roman.yakovenko at gmail.com Wed Oct 18 22:09:41 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 18 Oct 2006 22:09:41 +0200 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <200610181604.07329.noah.schwartz1@gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> Message-ID: <7465b6170610181309j1ce46952qf017a4839626f6d4@mail.gmail.com> On 10/18/06, Noah Schwartz wrote: > Hi, > > I've used the vector_indexing_suite to expose vectors containing pointers to > some class. I see that I can't iterate over this vector in Python like I can > with say, a vector of floats. I get the following error: > TypeError: No to_python (by-value) converter found for C++ type: MyClass* > > MyClass is already exposed properly. I can even use a MyClass* fine in Python > when other C++ functions return a pointer to one. > > I am guessing that I need to define a to_python converter either in MyClass or > in a new class, MyClass*. Not really sure how that works though. Try to set NoProxy to true http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite Does it help? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Wed Oct 18 22:15:49 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 18 Oct 2006 16:15:49 -0400 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <7465b6170610181309j1ce46952qf017a4839626f6d4@mail.gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <7465b6170610181309j1ce46952qf017a4839626f6d4@mail.gmail.com> Message-ID: <200610181615.49655.noah.schwartz1@gmail.com> On Wednesday 18 October 2006 16:09, Roman Yakovenko wrote: > On 10/18/06, Noah Schwartz wrote: > > Hi, > > > > I've used the vector_indexing_suite to expose vectors containing pointers > > to some class. I see that I can't iterate over this vector in Python like > > I can with say, a vector of floats. I get the following error: > > TypeError: No to_python (by-value) converter found for C++ type: MyClass* > > > > MyClass is already exposed properly. I can even use a MyClass* fine in > > Python when other C++ functions return a pointer to one. > > > > I am guessing that I need to define a to_python converter either in > > MyClass or in a new class, MyClass*. Not really sure how that works > > though. > > Try to set NoProxy to true > > http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite > > Does it help? So, something like this? class_ >("VectorMyClassP") .def(vector_indexing_suite, true >()) ; Same problem... From roman.yakovenko at gmail.com Wed Oct 18 22:28:17 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 18 Oct 2006 22:28:17 +0200 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <200610181615.49655.noah.schwartz1@gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <7465b6170610181309j1ce46952qf017a4839626f6d4@mail.gmail.com> <200610181615.49655.noah.schwartz1@gmail.com> Message-ID: <7465b6170610181328i4f8bccfak8f42b497e0df4bdb@mail.gmail.com> On 10/18/06, Noah Schwartz wrote: > On Wednesday 18 October 2006 16:09, Roman Yakovenko wrote: > > On 10/18/06, Noah Schwartz wrote: > > > Hi, > > > > > > I've used the vector_indexing_suite to expose vectors containing pointers > > > to some class. I see that I can't iterate over this vector in Python like > > > I can with say, a vector of floats. I get the following error: > > > TypeError: No to_python (by-value) converter found for C++ type: MyClass* > > > > > > MyClass is already exposed properly. I can even use a MyClass* fine in > > > Python when other C++ functions return a pointer to one. > > > > > > I am guessing that I need to define a to_python converter either in > > > MyClass or in a new class, MyClass*. Not really sure how that works > > > though. > > > > Try to set NoProxy to true > > > > http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite > > > > Does it help? > > So, something like this? > class_ >("VectorMyClassP") > .def(vector_indexing_suite, true >()) > ; > > Same problem... :-(, for some reason I thought this would work: Take a look on this post: http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2261029 I am not sure about indexing suite v2, because you can change call policies: return_internal_reference. You can find documentation for indexing suite v2 here: http://tinyurl.com/yndgbw -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Wed Oct 18 22:35:30 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 18 Oct 2006 16:35:30 -0400 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <7465b6170610181328i4f8bccfak8f42b497e0df4bdb@mail.gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <200610181615.49655.noah.schwartz1@gmail.com> <7465b6170610181328i4f8bccfak8f42b497e0df4bdb@mail.gmail.com> Message-ID: <200610181635.30975.noah.schwartz1@gmail.com> On Wednesday 18 October 2006 16:28, Roman Yakovenko wrote: > On 10/18/06, Noah Schwartz wrote: > > On Wednesday 18 October 2006 16:09, Roman Yakovenko wrote: > > > On 10/18/06, Noah Schwartz wrote: > > > > Hi, > > > > > > > > I've used the vector_indexing_suite to expose vectors containing > > > > pointers to some class. I see that I can't iterate over this vector > > > > in Python like I can with say, a vector of floats. I get the > > > > following error: TypeError: No to_python (by-value) converter found > > > > for C++ type: MyClass* > > > > > > > > MyClass is already exposed properly. I can even use a MyClass* fine > > > > in Python when other C++ functions return a pointer to one. > > > > > > > > I am guessing that I need to define a to_python converter either in > > > > MyClass or in a new class, MyClass*. Not really sure how that works > > > > though. > > > > > > Try to set NoProxy to true > > > > > > http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite > > > > > > Does it help? > > > > So, something like this? > > class_ >("VectorMyClassP") > > .def(vector_indexing_suite, true > > >()) ; > > > > Same problem... > > > :-(, for some reason I thought this would work: > > Take a look on this post: > http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2261029 > > I am not sure about indexing suite v2, because you can change call > policies: return_internal_reference. > > You can find documentation for indexing suite v2 here: > http://tinyurl.com/yndgbw Seems to indicate that I need to use shared_ptr's instead of regular pointers... Unfortunately I have thousands and thousands of line of C++ code all written -- none of which use shared_ptrs. I have never used a shared_ptr but, I get the feeling that I am going to have to change a lot of code and retest everything :( From roman.yakovenko at gmail.com Wed Oct 18 22:37:47 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 18 Oct 2006 22:37:47 +0200 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <200610181635.30975.noah.schwartz1@gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <200610181615.49655.noah.schwartz1@gmail.com> <7465b6170610181328i4f8bccfak8f42b497e0df4bdb@mail.gmail.com> <200610181635.30975.noah.schwartz1@gmail.com> Message-ID: <7465b6170610181337h7bc1b8edi84352b0b10bb9097@mail.gmail.com> On 10/18/06, Noah Schwartz wrote: > On Wednesday 18 October 2006 16:28, Roman Yakovenko wrote: > > On 10/18/06, Noah Schwartz wrote: > > > On Wednesday 18 October 2006 16:09, Roman Yakovenko wrote: > > > > On 10/18/06, Noah Schwartz wrote: > > > > > Hi, > > > > > > > > > > I've used the vector_indexing_suite to expose vectors containing > > > > > pointers to some class. I see that I can't iterate over this vector > > > > > in Python like I can with say, a vector of floats. I get the > > > > > following error: TypeError: No to_python (by-value) converter found > > > > > for C++ type: MyClass* > > > > > > > > > > MyClass is already exposed properly. I can even use a MyClass* fine > > > > > in Python when other C++ functions return a pointer to one. > > > > > > > > > > I am guessing that I need to define a to_python converter either in > > > > > MyClass or in a new class, MyClass*. Not really sure how that works > > > > > though. > > > > > > > > Try to set NoProxy to true > > > > > > > > http://boost.org/libs/python/doc/v2/indexing.html#indexing_suite > > > > > > > > Does it help? > > > > > > So, something like this? > > > class_ >("VectorMyClassP") > > > .def(vector_indexing_suite, true > > > >()) ; > > > > > > Same problem... > > > > > :-(, for some reason I thought this would work: > > > > Take a look on this post: > > http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2261029 > > > > I am not sure about indexing suite v2, because you can change call > > policies: return_internal_reference. > > > > You can find documentation for indexing suite v2 here: > > http://tinyurl.com/yndgbw > > Seems to indicate that I need to use shared_ptr's instead of regular > pointers... > > Unfortunately I have thousands and thousands of line of C++ code all > written -- none of which use shared_ptrs. I have never used a shared_ptr but, > I get the feeling that I am going to have to change a lot of code and retest > everything :( Wait a little, I will try indexing suite v2 for you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Wed Oct 18 22:55:06 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 18 Oct 2006 22:55:06 +0200 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <7465b6170610181337h7bc1b8edi84352b0b10bb9097@mail.gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <200610181615.49655.noah.schwartz1@gmail.com> <7465b6170610181328i4f8bccfak8f42b497e0df4bdb@mail.gmail.com> <200610181635.30975.noah.schwartz1@gmail.com> <7465b6170610181337h7bc1b8edi84352b0b10bb9097@mail.gmail.com> Message-ID: <7465b6170610181355x91dd78dk5ffecc7623877048@mail.gmail.com> On 10/18/06, Roman Yakovenko wrote: > > > Take a look on this post: > > > http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2261029 > > > > > > I am not sure about indexing suite v2, because you can change call > > > policies: return_internal_reference. > > > > > > You can find documentation for indexing suite v2 here: > > > http://tinyurl.com/yndgbw > > > > Seems to indicate that I need to use shared_ptr's instead of regular > > pointers... > > > > Unfortunately I have thousands and thousands of line of C++ code all > > written -- none of which use shared_ptrs. I have never used a shared_ptr but, > > I get the feeling that I am going to have to change a lot of code and retest > > everything :( > > Wait a little, I will try indexing suite v2 for you. Okay, I tested your use case with indexing suite v2. If you set container call policy to return_internal_reference all works as expected. Here you will find all setup information and source code for v2 suite: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ It should not take too much time to install it. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Thu Oct 19 00:43:34 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Wed, 18 Oct 2006 18:43:34 -0400 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <7465b6170610181355x91dd78dk5ffecc7623877048@mail.gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <7465b6170610181337h7bc1b8edi84352b0b10bb9097@mail.gmail.com> <7465b6170610181355x91dd78dk5ffecc7623877048@mail.gmail.com> Message-ID: <200610181843.34943.noah.schwartz1@gmail.com> On Wednesday 18 October 2006 16:55, Roman Yakovenko wrote: > On 10/18/06, Roman Yakovenko wrote: > > > > Take a look on this post: > > > > http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2261029 > > > > > > > > I am not sure about indexing suite v2, because you can change call > > > > policies: return_internal_reference. > > > > > > > > You can find documentation for indexing suite v2 here: > > > > http://tinyurl.com/yndgbw > > > > > > Seems to indicate that I need to use shared_ptr's instead of regular > > > pointers... > > > > > > Unfortunately I have thousands and thousands of line of C++ code all > > > written -- none of which use shared_ptrs. I have never used a > > > shared_ptr but, I get the feeling that I am going to have to change a > > > lot of code and retest everything :( > > > > Wait a little, I will try indexing suite v2 for you. > > Okay, I tested your use case with indexing suite v2. If you set container > call policy to return_internal_reference all works as expected. > > Here you will find all setup information and source code for v2 suite: > http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2 >/ > > It should not take too much time to install it. Ok...I will definitely look into this later tonight. I have read in several places that using return_internal_reference is a bad idea. I am already using it in several places. I don't expect to have any issues with invalid references to objects in a container. Is there anything else I should watch out when using return_internal_reference? Would you recommend that I use shared_ptr's instead? Noah From roman.yakovenko at gmail.com Thu Oct 19 07:58:31 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 19 Oct 2006 07:58:31 +0200 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <200610181843.34943.noah.schwartz1@gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <7465b6170610181337h7bc1b8edi84352b0b10bb9097@mail.gmail.com> <7465b6170610181355x91dd78dk5ffecc7623877048@mail.gmail.com> <200610181843.34943.noah.schwartz1@gmail.com> Message-ID: <7465b6170610182258wfb7be9s16df6539bba5103a@mail.gmail.com> On 10/19/06, Noah Schwartz wrote: > I have read in several places that using return_internal_reference is a bad > idea. I am already using it in several places. It is not bad, you just should understand what you are doing. > I don't expect to have any > issues with invalid references to objects in a container. > > Is there anything else I should watch out when using > return_internal_reference? In this case you will have to manage lifetime of objects ( keep alive ) created from Python and added to your containers. > Would you recommend that I use shared_ptr's > instead? The answer is obvious: yes. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Thu Oct 19 18:55:54 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Thu, 19 Oct 2006 12:55:54 -0400 Subject: [C++-sig] C++ object pointers contained in a vector In-Reply-To: <7465b6170610182258wfb7be9s16df6539bba5103a@mail.gmail.com> References: <200610181604.07329.noah.schwartz1@gmail.com> <200610181843.34943.noah.schwartz1@gmail.com> <7465b6170610182258wfb7be9s16df6539bba5103a@mail.gmail.com> Message-ID: <200610191255.54577.noah.schwartz1@gmail.com> On Thursday 19 October 2006 01:58, Roman Yakovenko wrote: > On 10/19/06, Noah Schwartz wrote: > > I have read in several places that using return_internal_reference is a > > bad idea. I am already using it in several places. > > It is not bad, you just should understand what you are doing. > > > I don't expect to have any > > issues with invalid references to objects in a container. > > > > Is there anything else I should watch out when using > > return_internal_reference? > > In this case you will have to manage lifetime of objects ( keep alive > ) created from > Python and added to your containers. > > > Would you recommend that I use shared_ptr's > > instead? > > The answer is obvious: yes. Ok -- I spent last night changing my C++ library to use shared pointers instead of raw pointers. Seems to still be working and the cleanup code is much prettier now (this is a neural networks library, messy cleanup). I am still using the first version of the indexing suite and everything works as expected with no_proxy set to true. Thanks for the help! Noah From noah.schwartz1 at gmail.com Thu Oct 19 19:52:11 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Thu, 19 Oct 2006 13:52:11 -0400 Subject: [C++-sig] NoProxy and the data in an std::map Message-ID: <200610191352.11882.noah.schwartz1@gmail.com> Hi, I am having another issue with the indexing suite. I have an std::map from int to boost::shared_ptr. However, in python, I can't seem to look at the data element of an iterator into that map. I get a TypeError complaining that there is no class registered for C++ class boost::shared_ptr. However, I did tell python about shared_ptrs of MyClass and no_proxy is set to true. Binding code: #include #include #include using namespace boost::python; #include class MyClass { public: int e; }; class MyClassMaker { public: std::map > & func() {return myMap;}; void add(int x, int y) {boost::shared_ptr instance(new MyClass); instance->e = y; myMap[x] = instance;}; std::map > myMap; }; BOOST_PYTHON_MODULE(testlib) { class_ >("MyClass") ; class_("MyClassMaker") .def("func", &MyClassMaker::func, return_value_policy()) .def("add", &MyClassMaker::add) ; class_ > >("MapIntMyClass") .def(map_indexing_suite >, true>()) ; } Python code: >>> import testlib >>> >>> a = testlib.MyClassMaker() >>> >>> a.add(1, 2) >>> a.add(3, 4) >>> a.add(5, 6) >>> >>> map = a.func() >>> >>> for i in map: ... print i.key() ... print i.data() ... 1 Traceback (most recent call last): File "", line 3, in ? TypeError: No Python class registered for C++ class boost::shared_ptr If you look at the binding code I have specified shared_ptr as a held type. I should mention that if I use a simpler container such as a vector container of shared_ptr's and do not specify no_proxy to true then I get the same error. Maybe the no_proxy code isnt being properly applied to the second template type in the map container. Noah From roman.yakovenko at gmail.com Thu Oct 19 21:00:48 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 19 Oct 2006 21:00:48 +0200 Subject: [C++-sig] NoProxy and the data in an std::map In-Reply-To: <200610191352.11882.noah.schwartz1@gmail.com> References: <200610191352.11882.noah.schwartz1@gmail.com> Message-ID: <7465b6170610191200i5c343df6v14e21d5211d38a90@mail.gmail.com> On 10/19/06, Noah Schwartz wrote: > Hi, > > I am having another issue with the indexing suite. I have an std::map from > int to boost::shared_ptr. However, in python, I can't seem to look > at the data element of an iterator into that map. I get a TypeError > complaining that there is no class registered for C++ class > boost::shared_ptr. However, I did tell python about shared_ptrs of > MyClass and no_proxy is set to true. > > Binding code: > #include > #include > #include > using namespace boost::python; > > #include > > class MyClass { > public: > int e; > }; > > class MyClassMaker { > public: > std::map > & func() {return myMap;}; > void add(int x, int y) {boost::shared_ptr instance(new MyClass); > instance->e = y; myMap[x] = instance;}; > > std::map > myMap; > }; > > BOOST_PYTHON_MODULE(testlib) > { > class_ >("MyClass") > ; > class_("MyClassMaker") > .def("func", &MyClassMaker::func, > return_value_policy()) > .def("add", &MyClassMaker::add) > ; > > class_ > >("MapIntMyClass") > .def(map_indexing_suite >, true>()) > ; > } > > > Python code: > >>> import testlib > >>> > >>> a = testlib.MyClassMaker() > >>> > >>> a.add(1, 2) > >>> a.add(3, 4) > >>> a.add(5, 6) > >>> > >>> map = a.func() > >>> > >>> for i in map: > ... print i.key() > ... print i.data() > ... > 1 > Traceback (most recent call last): > File "", line 3, in ? > TypeError: No Python class registered for C++ class boost::shared_ptr > > If you look at the binding code I have specified shared_ptr as a held type. > > I should mention that if I use a simpler container such as a vector container > of shared_ptr's and do not specify no_proxy to true then I get the same > error. Maybe the no_proxy code isnt being properly applied to the second > template type in the map container. Google is your friend: http://mail.python.org/pipermail/c++-sig/2005-November/009849.html http://mail.python.org/pipermail/c++-sig/2005-November/009854.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From noah.schwartz1 at gmail.com Thu Oct 19 21:08:50 2006 From: noah.schwartz1 at gmail.com (Noah Schwartz) Date: Thu, 19 Oct 2006 15:08:50 -0400 Subject: [C++-sig] NoProxy and the data in an std::map In-Reply-To: <7465b6170610191200i5c343df6v14e21d5211d38a90@mail.gmail.com> References: <200610191352.11882.noah.schwartz1@gmail.com> <7465b6170610191200i5c343df6v14e21d5211d38a90@mail.gmail.com> Message-ID: <200610191508.51121.noah.schwartz1@gmail.com> On Thursday 19 October 2006 15:00, Roman Yakovenko wrote: > On 10/19/06, Noah Schwartz wrote: > > Hi, > > > > I am having another issue with the indexing suite. I have an > > std::map from int to boost::shared_ptr. However, in python, I > > can't seem to look at the data element of an iterator into that map. I > > get a TypeError complaining that there is no class registered for C++ > > class > > boost::shared_ptr. However, I did tell python about shared_ptrs > > of MyClass and no_proxy is set to true. > > > > Binding code: > > #include > > #include > > #include > > using namespace boost::python; > > > > #include > > > > class MyClass { > > public: > > int e; > > }; > > > > class MyClassMaker { > > public: > > std::map > & func() {return > > myMap;}; void add(int x, int y) {boost::shared_ptr instance(new > > MyClass); instance->e = y; myMap[x] = instance;}; > > > > std::map > myMap; > > }; > > > > BOOST_PYTHON_MODULE(testlib) > > { > > class_ >("MyClass") > > ; > > class_("MyClassMaker") > > .def("func", &MyClassMaker::func, > > return_value_policy()) > > .def("add", &MyClassMaker::add) > > ; > > > > class_ > > > >("MapIntMyClass") .def(map_indexing_suite > boost::shared_ptr >, true>()) ; > > } > > > > Python code: > > >>> import testlib > > >>> > > >>> a = testlib.MyClassMaker() > > >>> > > >>> a.add(1, 2) > > >>> a.add(3, 4) > > >>> a.add(5, 6) > > >>> > > >>> map = a.func() > > >>> > > >>> for i in map: > > > > ... print i.key() > > ... print i.data() > > ... > > 1 > > Traceback (most recent call last): > > File "", line 3, in ? > > TypeError: No Python class registered for C++ class > > boost::shared_ptr > > > > If you look at the binding code I have specified shared_ptr as a held > > type. > > > > I should mention that if I use a simpler container such as a vector > > container of shared_ptr's and do not specify no_proxy to true then I get > > the same error. Maybe the no_proxy code isnt being properly applied to > > the second template type in the map container. > > Google is your friend: > > http://mail.python.org/pipermail/c++-sig/2005-November/009849.html > http://mail.python.org/pipermail/c++-sig/2005-November/009854.html I did see this before sending the e-mail. That thread is almost a year old and the original sender was using boost 1.33.0. Are you telling me the fix made last year is still in CVS and isn't part of 1.33.1? Noah From shandong.han at mizuho-sc.com Fri Oct 20 02:02:06 2006 From: shandong.han at mizuho-sc.com (Shandong Han) Date: Fri, 20 Oct 2006 09:02:06 +0900 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions Message-ID: <000001c6f3da$fb5d1780$ca34680a@ad.mizuhosc.com> Sorry if this is too naive, but I searched the internet and digged out the previous mails here without any luck... I am new to this, and my question is pretty simple: how to call functions which use a pointer to return value? Sample code is as follows: =================================== #include "boost/python.hpp" #include "boost/python/suite/indexing/vector_indexing_suite.hpp" namespace bp = boost::python; int add(int a, int b, int* s) { *s = a + b; return 0; } BOOST_PYTHON_MODULE(hello){ // bp::def("add", &::add); { //::add -- generated using py++ typedef int ( *function_ptr_t )( int,int,int * ); bp::def( "add" , function_ptr_t( &::add ) , ( bp::arg("a"), bp::arg("b"), bp::arg("s") ) , bp::default_call_policies() ); } } =================================== It builds fine. So test it in python: >>> from ctypes import * >>> from hello import * >>> a=c_int() >>> add(1,1,byref(a)) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in hello.add(int, int, CArgObject) did not match C++ signature: add(int a, int b, int * s) >>> >>> add(1,1,pointer(a)) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in hello.add(int, int, LP_c_long) did not match C++ signature: add(int a, int b, int * s) Maybe the use of ctypes is not the correct way, but I don't know how I can make a pointer without using that... Could you let me know how to do this? And another question about arrays: int arrayTest(int n, const int a[], int b[]) { for(int i = 0; i < n; i++) b[i] = a[i] * 2; return 0; } py++ treats the arrays as pointers: typedef ::std::string ( *function_ptr_t )( ::std::string const & ); bp::def( "myFunc" , function_ptr_t( &::myFunc ) , ( bp::arg("arg0") ) , bp::default_call_policies() ); So this becomes the same question as the above one... Thanks a lot in advance! S. Han Note: This e-mail contains privileged and confidential information and is for the sole use of the intended recipient(s). If you are not an intended recipient, you are hereby kindly requested to refrain from printing, copying, or distributing the information contained herein. Furthermore, any other use of the information contained herein is strictly prohibited. If you have received this transmission in error, please kindly notify the sender immediately and destroy all copies of the original message. From mark at image-engine.com Fri Oct 20 02:18:38 2006 From: mark at image-engine.com (Mark Williams) Date: Thu, 19 Oct 2006 19:18:38 -0500 Subject: [C++-sig] Calling func that takes intrusive_ptr with intrusive_ptr... Message-ID: <1098.1161303518@image-engine.com> I found the query below in the December 2005 archive which would appear to be describing the exact same problem as my own. A follow-up by the original author suggested they'd made their own version of converter/shared_ptr_from_python.hpp in order to support their own SmartPtr type, but they were questioning whether this was indeed the correct path to take. I've not been able to find replies to either of these original queries so would be grateful for any pertinent information regarding intrusive_ptr usage. Does Boost.Python support intrusive_ptr to the same level as shared_ptr? The documentation for register_ptr_to_python doesn't seen to suggest any particular dependency on any one shared pointer type. Thanks in advance, Mark > > Hmm.. I was expecting this to work. Any ideas as to why it doesn't? > >Thanks, > >Alex > > >#include >#include >#include > >using namespace boost::python; >using boost::intrusive_ptr; >using std::string; > >class Base { public: virtual ~Base() {} }; >class Derived : public Base { public: virtual ~Derived() {} }; > >void intrusive_ptr_add_ref(Base *base) {} >void intrusive_ptr_add_ref(Base *base) {} > >intrusive_ptr makeDerived() { > return intrusive_ptr(new Derived()); >} > >string takesBasePtr(intrusive_ptr const &base) { > return "takesBasePtr"; >} > >BOOST_PYTHON_MODULE(foo) { > class_ >("Base", no_init); > class_, bases > > ("Derived", no_init) > .def("__init__", make_constructor(makeDerived)) > .def("takesBasePtr", takesBasePtr) > ; >} > >================================================== > > >>> from foo import * > >>> d = Derived() > >>> d.takesBasePtr() >Traceback (most recent call last): > File "", line 1, in ? >Boost.Python.ArgumentError: Python argument types in > Derived.takesBasePtr(Derived) >did not match C++ signature: > takesBasePtr(boost::intrusive_ptr) From dave at boost-consulting.com Fri Oct 20 03:49:25 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 Oct 2006 21:49:25 -0400 Subject: [C++-sig] 'iteritems', 'iterkeys' and 'itervalues' in dict References: <20061015203646.181.qmail@web27915.mail.ukl.yahoo.com> Message-ID: <87u01z69ju.fsf@pereiro.luannocracy.com> Nindi Singh writes: > SOLVED > > I just hit it with PyIter_Next .. so I have to step a but outside Boost. No need: d.iterkeys().attr("next")() -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 20 03:54:25 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 Oct 2006 21:54:25 -0400 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions References: <000001c6f3da$fb5d1780$ca34680a@ad.mizuhosc.com> Message-ID: <87ods769bi.fsf@pereiro.luannocracy.com> "Shandong Han" writes: > Sorry if this is too naive, but I searched the internet and digged out the > previous mails here without any luck... > > I am new to this, and my question is pretty simple: how to call functions > which use a pointer to return value? Sample code is as follows: > > =================================== > > #include "boost/python.hpp" > #include "boost/python/suite/indexing/vector_indexing_suite.hpp" > > namespace bp = boost::python; > > int add(int a, int b, int* s) > { > *s = a + b; > return 0; > } Just put a thin wrapper around the function: boost::python::tuple add(int a, int b) { return boost::python::make_tuple(0, a+b); } Then wrap that -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 20 03:48:11 2006 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 Oct 2006 21:48:11 -0400 Subject: [C++-sig] python bool not C++ bool References: <20061014213845.98204.qmail@web27908.mail.ukl.yahoo.com> Message-ID: <87zmbr69lw.fsf@pereiro.luannocracy.com> Nindi Singh writes: > I would very much like to pass bools from python to C++ and have them accepted as bools. However I cannot seem to do this. > My code > > class MyTestClass { > public: > MyTestClass ():theType("Empty"){} > MyTestClass(bool theBool):theType("Bool"){} > MyTestClass(int theInt):theType("Int"){} > object GetType(){return object(theType);} > std::string theType; > }; > > void exportTestClass() { > class_ theClass_("TestClass"); > theClass_.def(init()); > theClass_.def(init()); Just exchange the two lines above and it will work. However, you may not be able to overload between int and Bool. Boost.Python tries overloads in reverse order of definition. -- Dave Abrahams Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Fri Oct 20 11:05:35 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 20 Oct 2006 11:05:35 +0200 Subject: [C++-sig] Calling func that takes intrusive_ptr with intrusive_ptr... In-Reply-To: <1098.1161303518@image-engine.com> References: <1098.1161303518@image-engine.com> Message-ID: <7465b6170610200205p58e49d94wa1938335de9c641d@mail.gmail.com> On 10/20/06, Mark Williams wrote: > > I found the query below in the December 2005 archive which would appear to be describing the exact same problem as my own. > > A follow-up by the original author suggested they'd made their own version of converter/shared_ptr_from_python.hpp in order > to support their own SmartPtr type, but they were questioning whether this was indeed the correct path to take. > > I've not been able to find replies to either of these original queries so would be grateful for any pertinent information regarding > intrusive_ptr usage. Does Boost.Python support intrusive_ptr to the same level as shared_ptr? The documentation for > register_ptr_to_python doesn't seen to suggest any particular dependency on any one shared pointer type. Recently, I had a problem with custom smart pointer. David Abrahams helped me to solve it. The solution with unittests and explanation could be found here: http://tinyurl.com/y9jzop I think you can replace smart_ptr_t with intrusive_ptr and all should work. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Oct 20 11:14:23 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 20 Oct 2006 11:14:23 +0200 Subject: [C++-sig] [ANN]Py++-0.8.2 Message-ID: <7465b6170610200214i653c2128g45a15f0b303734d7@mail.gmail.com> I'm glad to announce the new version of Py++. Download page: http://language-binding.net/pyplusplus/download.html What is it? Py++ is an object-oriented framework for creating a code generator for Boost.Python library. Project home page: http://language-binding.net/pyplusplus/pyplusplus.html The new version introduces quite few improvements: * performance, in some case x10 * fully automatic algorithm for exposing C++ get\set functions as Python properties. * treatment for previously generated, but no more in use, source files * convenience API for translating user defined exception to Python one * generated code - improved formatting * better understanding of call policies: - default_call_policies should not be generated any more - return_value_policy< return_opaque_pointer >, Py++ will create specialization for type_id function, as required by the library * documentation, new chapters were written, all source code in documentation is highlighted using pykleur package. Dependencies: Py++-0.8.2 depends on pygccxml-0.8.2 Thanks to every one who contributed to this release. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Oct 20 11:31:01 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 20 Oct 2006 11:31:01 +0200 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions In-Reply-To: <000001c6f3da$fb5d1780$ca34680a@ad.mizuhosc.com> References: <000001c6f3da$fb5d1780$ca34680a@ad.mizuhosc.com> Message-ID: <7465b6170610200231v6559d82fx938b91150a21fa3f@mail.gmail.com> On 10/20/06, Shandong Han wrote: > Sorry if this is too naive, but I searched the internet and digged out the > previous mails here without any luck... > > I am new to this, and my question is pretty simple: how to call functions > which use a pointer to return value? Sample code is as follows: > > =================================== > > #include "boost/python.hpp" > #include "boost/python/suite/indexing/vector_indexing_suite.hpp" > > namespace bp = boost::python; > > int add(int a, int b, int* s) > { > *s = a + b; > return 0; > } > > BOOST_PYTHON_MODULE(hello){ > // bp::def("add", &::add); > > { //::add -- generated using py++ > typedef int ( *function_ptr_t )( int,int,int * ); > > bp::def( > "add" > , function_ptr_t( &::add ) > , ( bp::arg("a"), bp::arg("b"), bp::arg("s") ) > , bp::default_call_policies() ); > } > } > > =================================== > > It builds fine. So test it in python: > > >>> from ctypes import * > >>> from hello import * > >>> a=c_int() > >>> add(1,1,byref(a)) > Traceback (most recent call last): > File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > hello.add(int, int, CArgObject) > did not match C++ signature: > add(int a, int b, int * s) > >>> > >>> add(1,1,pointer(a)) > Traceback (most recent call last): > File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > hello.add(int, int, LP_c_long) > did not match C++ signature: > add(int a, int b, int * s) > > Maybe the use of ctypes is not the correct way, but I don't know how I can > make a pointer without using that... Could you let me know how to do this? > > And another question about arrays: > > int arrayTest(int n, const int a[], int b[]) > { > for(int i = 0; i < n; i++) > b[i] = a[i] * 2; > return 0; > } > > py++ treats the arrays as pointers: > > typedef ::std::string ( *function_ptr_t )( ::std::string const & ); > > bp::def( > "myFunc" > , function_ptr_t( &::myFunc ) > , ( bp::arg("arg0") ) > , bp::default_call_policies() ); > > So this becomes the same question as the above one... C++ treats arrays as pointers, not Py++. Any way you have a problem, which should be solved. David Abrahams already provided you with solution, I will point you to experimental code in Py++ that will allow you to implement the solution with it. We call the functionality you are looking for - "Function Transformation". It wil allow you to instruct Py++ to create right function wrapper. Start here: https://realityforge.vrsource.org/view/PyppApi/CodeInserter Take a look on Py++ unit tests: http://tinyurl.com/uo5kh - usage example http://tinyurl.com/vv9j6 - C++ source code to expose This feature presents in Py++-0.8.2 release. The feature is highly experimental, nevertheless very useful. The API will change. Can you try it and provide some feedback? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From wz_ at gmx.net Sun Oct 22 16:36:47 2006 From: wz_ at gmx.net (Nicolas Tessore) Date: Sun, 22 Oct 2006 16:36:47 +0200 Subject: [C++-sig] Template Functions Message-ID: <453B81FF.6010405@gmx.net> Hello, I got along fairly well with Py++ and my project. My build chain worked out quite nice, first I generate a header file that has the typedef-s, sizeof()-s and template function calls: /* long list of #includes */ /* This namespace is not going to be exported */ namespace NoExport { /* Auxiliary function for template export */ inline void export_obj_templates() { Niflib::NiObjectRef CastObj; /* Object NiVisController */ sizeof(Niflib::Ref); Niflib::DynamicCast(CastObj); Niflib::StaticCast (CastObj); /* more objects ... */ } } (This is one random example object, the CastObj is one generic ancestor that is cast into all the children classes.) Now this behaves as expected. I then use a code generator script that catches all the Ref and DynamicCast and StaticCast and renames them to: NiVisControllerRef DynamicCastToNiVisController() StaticCastToNiVisController() Now the problem is: From my perception, pyplusplus should know what type the template T should be of. At least for the Refs (ok, they are classes) it does. Still the resulting .def looks like this (NVC = NiVisController): bp::def( "DynamicCastToNVC" , DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) , ( bp::arg("object") ) ); This is of course an error, it should be: DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) --- Long story short: Why does Py++ not recognize that my functions contain templates, and does not put it to the right place? Thanks, N. From roman.yakovenko at gmail.com Sun Oct 22 16:54:19 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 22 Oct 2006 16:54:19 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <453B81FF.6010405@gmx.net> References: <453B81FF.6010405@gmx.net> Message-ID: <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> On 10/22/06, Nicolas Tessore wrote: > bp::def( > "DynamicCastToNVC" > , DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) > , ( bp::arg("object") ) ); > > This is of course an error, it should be: > > DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) > > --- > > Long story short: Why does Py++ not recognize that my functions contain > templates, and does not put it to the right place? > I think you should read next document: http://tinyurl.com/y2rfqp Does it help? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From wz_ at gmx.net Sun Oct 22 17:12:24 2006 From: wz_ at gmx.net (Nicolas Tessore) Date: Sun, 22 Oct 2006 17:12:24 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> References: <453B81FF.6010405@gmx.net> <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> Message-ID: <453B8A58.3080205@gmx.net> Roman Yakovenko schrieb: > On 10/22/06, Nicolas Tessore wrote: >> bp::def( >> "DynamicCastToNVC" >> , DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) >> , ( bp::arg("object") ) ); >> >> This is of course an error, it should be: >> >> DynamicCastToNVC_function_type( &::Niflib::DynamicCast ) >> >> --- >> >> Long story short: Why does Py++ not recognize that my functions contain >> templates, and does not put it to the right place? >> > > I think you should read next document: http://tinyurl.com/y2rfqp > Does it help? > Yes, indeed! Thanks for the help, I read the whole doc but completely misunderstood the intention of it :D Py++ is quite hard to get into (for a newbie like me =)) but once you get the hang of it, it's a real beauty. Thanks again, N. From roman.yakovenko at gmail.com Sun Oct 22 17:24:25 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 22 Oct 2006 17:24:25 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <453B8A58.3080205@gmx.net> References: <453B81FF.6010405@gmx.net> <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> <453B8A58.3080205@gmx.net> Message-ID: <7465b6170610220824w3e0e3363s1207ba72df7a9c2@mail.gmail.com> On 10/22/06, Nicolas Tessore wrote: > > I think you should read next document: http://tinyurl.com/y2rfqp > > Does it help? > > > > Yes, indeed! Thanks for the help, I read the whole doc but completely > misunderstood the intention of it :D In your opinion how this FAQ should be written? > Py++ is quite hard to get into (for a newbie like me =)) This is a bug. I would like to know your opinion: what do you consider to be hard and how you propose to fix it, really. > but once you get the hang of it, it's a real beauty. :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From wz_ at gmx.net Sun Oct 22 17:55:35 2006 From: wz_ at gmx.net (Nicolas Tessore) Date: Sun, 22 Oct 2006 17:55:35 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <7465b6170610220824w3e0e3363s1207ba72df7a9c2@mail.gmail.com> References: <453B81FF.6010405@gmx.net> <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> <453B8A58.3080205@gmx.net> <7465b6170610220824w3e0e3363s1207ba72df7a9c2@mail.gmail.com> Message-ID: <453B9477.2030601@gmx.net> Roman Yakovenko wrote: > In your opinion how this FAQ should be written? I would add a little abstract describing the problem in normal speech, so that it gets immediately clear what the answer adresses. Sometimes you overlook the solution simply because you fail to see the similarities (at least I do this :/). "How to deal with template on return type functions?" "There are situations in which Py++ cannot ..." This makes it easier for beginners to find their problems in the FAQ :) > This is a bug. I would like to know your opinion: what do you consider > to be hard and how > you propose to fix it, really. The whole setup process is quite underexplained. Not a Py++ issue really, but you have to do a lot of additional research to get it to run. As I said - this is not a Py++ issue. But I imagine it keeps a lot of "I just started" users from using it. And it makes it harder for me when I want to share my bindings, since I will need to write a whole lot of documentation just to enable others to rebuild the Python module: Documentation on how to get Boost (easy) and on how to get GCC XML (hard: CVS needed, CMake needed, build manually) It's not your fault, and I am really happy you have created such a nice language wrapper. I guess it's just to early to expect a fully featured solution :) N. From roman.yakovenko at gmail.com Sun Oct 22 18:14:30 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 22 Oct 2006 18:14:30 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <453B9477.2030601@gmx.net> References: <453B81FF.6010405@gmx.net> <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> <453B8A58.3080205@gmx.net> <7465b6170610220824w3e0e3363s1207ba72df7a9c2@mail.gmail.com> <453B9477.2030601@gmx.net> Message-ID: <7465b6170610220914r4cebd110j6beea54aeae27776@mail.gmail.com> On 10/22/06, Nicolas Tessore wrote: > Roman Yakovenko wrote: > > In your opinion how this FAQ should be written? > I would add a little abstract describing the problem in normal speech, > so that it gets immediately clear what the answer adresses. Sometimes > you overlook the solution simply because you fail to see the > similarities (at least I do this :/). > > "How to deal with template on return type functions?" > "There are situations in which Py++ cannot ..." > > This makes it easier for beginners to find their problems in the FAQ :) Can you contribute such description to the problem? I will integrate it. The problem is that I think too "low level" and English is not my native language. > > This is a bug. I would like to know your opinion: what do you consider > > to be hard and how > > you propose to fix it, really. > The whole setup process is quite underexplained. Not a Py++ issue > really, but you have to do a lot of additional research to get it to > run. As I said - this is not a Py++ issue. But I imagine it keeps a lot > of "I just started" users from using it. > > And it makes it harder for me when I want to share my bindings, since I > will need to write a whole lot of documentation just to enable others to > rebuild the Python module: > Documentation on how to get Boost (easy) and on how to get GCC XML > (hard: CVS needed, CMake needed, build manually) You can cut gccxml and CMake by providing GCC-XML generated xml file: http://tinyurl.com/y8usuv http://tinyurl.com/y5rosb http://tinyurl.com/y7pj57 > It's not your fault, and I am really happy you have created such a nice > language wrapper. I guess it's just to early to expect a fully featured > solution :) Not at all. I found a nice installer for boost libraries here http://boost-consulting.com/download.html I started to work on "single click" installer for gccxml, pygccxml and Py++. It could be nice if I will be able to add to it Boost.Python + its dependencies libraries. This installer will create a real "solution" for C++ Python bindings. I am aware of the nightmare user should pass. I am looking for cross platform installer with simple syntax. Any help or recommendation is welcome. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Tessore at stud.uni-heidelberg.de Sun Oct 22 18:25:14 2006 From: Tessore at stud.uni-heidelberg.de (Nicolas Tessore) Date: Sun, 22 Oct 2006 18:25:14 +0200 Subject: [C++-sig] Template Functions In-Reply-To: <7465b6170610220914r4cebd110j6beea54aeae27776@mail.gmail.com> References: <453B81FF.6010405@gmx.net> <7465b6170610220754r228300e0vee0f789a78e146ea@mail.gmail.com> <453B8A58.3080205@gmx.net> <7465b6170610220824w3e0e3363s1207ba72df7a9c2@mail.gmail.com> <453B9477.2030601@gmx.net> <7465b6170610220914r4cebd110j6beea54aeae27776@mail.gmail.com> Message-ID: <453B9B6A.6080906@stud.uni-heidelberg.de> Roman Yakovenko wrote: > Can you contribute such description to the problem? I will integrate it. > The problem is that I think too "low level" and English is not my > native language. I will try to come up with those, I cannot promise anything though, I am really loaded with work. > Not at all. I found a nice installer for boost libraries here > http://boost-consulting.com/download.html > > I started to work on "single click" installer for gccxml, pygccxml and Py++. > It could be nice if I will be able to add to it Boost.Python + its dependencies > libraries. This installer will create a real "solution" for C++ Python bindings. > > I am aware of the nightmare user should pass. I am looking for cross platform > installer with simple syntax. Any help or recommendation is welcome. I'm afraid I have no solution either. The only installer I worked with is NSIS - but it is Win32. I think I heard of a port, but I am not sure. It's amazing how much Py++ improved already, I'm sure you can overcome all those small obstacles as well. N. From shandong.han at mizuho-sc.com Mon Oct 23 03:30:02 2006 From: shandong.han at mizuho-sc.com (Shandong Han) Date: Mon, 23 Oct 2006 10:30:02 +0900 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions In-Reply-To: <7465b6170610200231v6559d82fx938b91150a21fa3f@mail.gmail.com> Message-ID: <000801c6f642$c30ef690$4034680a@ad.mizuhosc.com> Thank you guys very much for the prompt replies. Dave: It's really a great idea to put those things in a tuple. But there are two problems with that: 1. I have to write wrappers for all the functions (since all the functions are like that) without the help of automatic tools... 2. There is still the problem with arrays or pointers to arrays. Roman: Thank you for providing the great tool and supports on it. BTW, I cannot access the first link, maybe it needs logging in? But I read the following two, and found following comment: // Made the method 'virtual' for now because func transformers // are currently only taken into account on virtual functions. Unfortunately the functions I need to wrap are all independent functions... > This feature presents in Py++-0.8.2 release. The feature is highly experimental, nevertheless very useful. The API will change. Can you try it and provide some feedback? Yes, I will try it. But this time I was required to write something serious... :-P Just wonder if there is a solution in Boost.Python on pointers to or arrays of primitive types? If not, just wonder how people manage to live with working on the big C/C++ projects :-) Note:The 'Note' appended to my emails except this one are added by system, I am sorry that I cannot remove them... -----Original Message----- From: Roman Yakovenko [mailto:roman.yakovenko at gmail.com] Sent: Friday, October 20, 2006 6:31 PM To: shandong.han at mizuho-sc.com; Development of Python/C++ integration Subject: Re: [C++-sig] Question about passing ordinary pointers (like int*) to functions C++ treats arrays as pointers, not Py++. Any way you have a problem, C++ which should be solved. David Abrahams already provided you with solution, I will point you to experimental code in Py++ that will allow you to implement the solution with it. We call the functionality you are looking for - "Function Transformation". It wil allow you to instruct Py++ to create right function wrapper. Start here: https://realityforge.vrsource.org/view/PyppApi/CodeInserter Take a look on Py++ unit tests: http://tinyurl.com/uo5kh - usage example http://tinyurl.com/vv9j6 - C++ source code to expose This feature presents in Py++-0.8.2 release. The feature is highly experimental, nevertheless very useful. The API will change. Can you try it and provide some feedback? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Oct 23 09:24:37 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 23 Oct 2006 09:24:37 +0200 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions In-Reply-To: <000801c6f642$c30ef690$4034680a@ad.mizuhosc.com> References: <7465b6170610200231v6559d82fx938b91150a21fa3f@mail.gmail.com> <000801c6f642$c30ef690$4034680a@ad.mizuhosc.com> Message-ID: <7465b6170610230024x76b9a8abx2207c3c359bf4739@mail.gmail.com> On 10/23/06, Shandong Han wrote: > Roman: Thank you for providing the great tool and supports on it. BTW, I > cannot access the first link, maybe it needs logging in? But I read the > following two, and found following comment: > > // Made the method 'virtual' for now because func transformers > // are currently only taken into account on virtual functions. > > Unfortunately the functions I need to wrap are all independent functions... You mean free functions, right? If so , than you are right this is a missing functionality. Also it is not much work to generate wrappers for your functions. Take a look on Py++ code_repository package: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/ It provides few functions to work with sequence. > > This feature presents in Py++-0.8.2 release. The feature is highly > experimental, nevertheless very useful. The API will change. Can you try it > and provide some feedback? > > Yes, I will try it. But this time I was required to write something > serious... :-P > > Just wonder if there is a solution in Boost.Python on pointers to or arrays > of primitive types? I don't think so. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From shandong.han at mizuho-sc.com Mon Oct 23 10:53:06 2006 From: shandong.han at mizuho-sc.com (Shandong Han) Date: Mon, 23 Oct 2006 17:53:06 +0900 Subject: [C++-sig] Question about passing ordinary pointers (like int*) to functions In-Reply-To: <7465b6170610230024x76b9a8abx2207c3c359bf4739@mail.gmail.com> Message-ID: <000001c6f680$a81bf890$4034680a@ad.mizuhosc.com> Roman, Thank you for the information. I got the idea, to wrap up the primitive arrays using classes. I have been playing with SWIG, and found that it's kind of handy. So maybe I will switch to that for this project. But I will definitely try Boost and py++ later. thanks a lot! Shandong Han -----Original Message----- From: Roman Yakovenko [mailto:roman.yakovenko at gmail.com] Sent: Monday, October 23, 2006 4:25 PM To: shandong.han at mizuho-sc.com Cc: Development of Python/C++ integration Subject: Re: [C++-sig] Question about passing ordinary pointers (like int*) to functions On 10/23/06, Shandong Han wrote: > Roman: Thank you for providing the great tool and supports on it. BTW, > I cannot access the first link, maybe it needs logging in? But I read > the following two, and found following comment: > > // Made the method 'virtual' for now because func transformers > // are currently only taken into account on virtual functions. > > Unfortunately the functions I need to wrap are all independent > functions... You mean free functions, right? If so , than you are right this is a missing functionality. Also it is not much work to generate wrappers for your functions. Take a look on Py++ code_repository package: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_re pository/ It provides few functions to work with sequence. > > This feature presents in Py++-0.8.2 release. The feature is highly > experimental, nevertheless very useful. The API will change. Can you > try it and provide some feedback? > > Yes, I will try it. But this time I was required to write something > serious... :-P > > Just wonder if there is a solution in Boost.Python on pointers to or > arrays of primitive types? I don't think so. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From beau.sapach at ualberta.ca Mon Oct 23 20:07:11 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Mon, 23 Oct 2006 12:07:11 -0600 Subject: [C++-sig] Embedding... Message-ID: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> Hello Everyone, I'm looking to embed Python in an application I'm working on in C++. I've been trying out Boost.Python and it seems pretty straight forward but doesn't have (that I've found yet anyway) any complete examples to follow for embedding Python. What I want to be able to do is give users access to objects created in C++ land inside a Python window within my .exe. I'm assuming I'll have to create instances of my classes in C++, for example when my application is starting up. Then I would have to create a Python interpreter and have it call Python functions to give it references to my previously created C++ objects. Lastly, show the Python window to the user. Please correct me if I'm wrong in how I'm imagining this... The problem I'm having right now is that Boost.Python seems very good for creating DLLs to give Python access to classes and functions, but how do I make classes/functions that are compiled as part of my exe available to python WITHIN the same exe??? Beau -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Mon Oct 23 21:35:29 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 23 Oct 2006 15:35:29 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> Message-ID: <453D1981.1050203@sympatico.ca> Beau Sapach wrote: > Hello Everyone, > > > I'm looking to embed Python in an application I'm working on in C++. I've > been trying out Boost.Python and it seems pretty straight forward but > doesn't have (that I've found yet anyway) any complete examples to follow > for embedding Python. What I want to be able to do is give users access to > objects created in C++ land inside a Python window within my .exe. Have you looked at the code from CVS ? I added some support for embedding sometime in 2005 (after the 1.33 release branch was created), containing 'exec', 'exec_string', and 'import' functions: http://cci.lbl.gov/~rwgk/shortcuts/boost//libs/python/doc/v2/exec.html (The docs at boost.org don't include these bits yet as they only document the last release.) > I'm assuming I'll have to create instances of my classes in C++, for example > when my application is starting up. Then I would have to create a Python > interpreter and have it call Python functions to give it references to my > previously created C++ objects. Lastly, show the Python window to the user. Right. One way is to have preexisting (C++) objects be bound to python objects that get exposed to user scripts that are run from within the main (C++) application by means of an embedded python interpreter. > Please correct me if I'm wrong in how I'm imagining this... The problem I'm > having right now is that Boost.Python seems very good for creating DLLs to > give Python access to classes and functions, but how do I make > classes/functions that are compiled as part of my exe available to python > WITHIN the same exe??? See above. The bits to actually provide the missing link are straight forward, so you may put it into your own code, if you can't use the latest not-quite-released-yet version of boost: // Execute python source code from file filename. // global and local are the global and local scopes respectively, // used during execution. object exec_file(str filename, object global, object local) { // should be 'char const *' but older python versions don't use 'const' yet. char *f = python::extract(filename); // Let python open the file to avoid potential binary incompatibilities. PyObject *pyfile = PyFile_FromString(f, "r"); if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file"); python::handle<> file(pyfile); PyObject* result = PyRun_File(PyFile_AsFile(file.get()), f, Py_file_input, global.ptr(), local.ptr()); if (!result) throw_error_already_set(); return object(detail::new_reference(result)); } Good luck, Stefan -- ...ich hab' noch einen Koffer in Berlin... From mark at image-engine.com Mon Oct 23 22:58:10 2006 From: mark at image-engine.com (Mark Williams) Date: Mon, 23 Oct 2006 15:58:10 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <2593.1161637090@image-engine.com> I'm having a few problems passing objects in and out of Python/C++ via boost.python, which are probably explained best by the example and test cases below. I have a trivial class "Base", and some functions which allows reference-counted instances of this class to be stored/retrieved to/from a static variable. Firstly, I derive class "Derived" from "Base" within Python, and "store" an instance of Derived in the C++ static. When I then "retrieve" this object in Python I find that it's no longer of type "Derived", but of type "Base": c = Derived() store(c) d = retrieve() self.assertEqual( type(c), type(d) ) # FAILS Secondly, I store and then immediately retrieve an instance of "Base". I find that boost returns me a different Python object. I'm not surprised that this happens, but cannot find a CallPolicy which works: c = Base() store(c) d = retrieve() self.assert_( c is d ) # FAILS Is it possible to fix either of these problems by modifiying my boost.python bindings alone? Thanks in advance, Mark //////////////////////////////////////////////// class Base : public RefCounted /* RefCounted is my own implementation of a simple reference counting class */ { public: Base() {}; }; typedef boost::intrusive_ptr BasePtr; template struct GlobalsTest { static boost::intrusive_ptr g_object ; static boost::intrusive_ptr retrieve() { return g_object; } static void store( const boost::intrusive_ptr &o) { g_object = o; } }; BOOST_PYTHON_MODULE(myModule) { class_< Base, BasePtr>("Base"); def("store", & GlobalsTest::store ); def("retrieve", & GlobalsTest::retrieve ); } ////////////////////////////////////////////////////////////////////////////////////////////////// import unittest from myModule import * class Derived(Base): def methodInDerived(self): return 12 class TestBoostPython(unittest.TestCase): def test1(self): c = Derived() self.assertEqual( c.methodInDerived(), 12 ) store(c) d = retrieve() self.assertEqual( type(c), type(d) ) self.assert_( c is d ) def test2(self): c = Base() store(c) d = retrieve() self.assertEqual( type(c), type(d) ) self.assert_( c is d ) if __name__ == "__main__": unittest.main() ///////////////////////////////////////////////////////////////////////////////// test1 (__main__.TestBoostPython) ... FAIL test2 (__main__.TestBoostPython) ... FAIL ====================================================================== FAIL: test1 (__main__.TestBoostPython) ---------------------------------------------------------------------- Traceback (most recent call last): File "test/boostPython.py", line 19, in test1 self.assertEqual( type(c), type(d) ) AssertionError: != ====================================================================== FAIL: test2 (__main__.TestBoostPython) ---------------------------------------------------------------------- Traceback (most recent call last): File "test/boostPython.py", line 30, in test2 self.assert_( c is d ) AssertionError ---------------------------------------------------------------------- From roman.yakovenko at gmail.com Tue Oct 24 08:27:22 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Oct 2006 08:27:22 +0200 Subject: [C++-sig] Passing objects between python / c++ In-Reply-To: <2593.1161637090@image-engine.com> References: <2593.1161637090@image-engine.com> Message-ID: <7465b6170610232327x36db8b3jec52411c6d3a317f@mail.gmail.com> On 10/23/06, Mark Williams wrote: > class Derived(Base): __init__ method is missing. > def methodInDerived(self): > return 12 You can take a look on custom smart pointer example here: http://language-binding.net/pyplusplus/bpl_lessons_learned/smart_ptrs/smart_ptrs.html If you will start with it, I am sure you will save your time. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mark at image-engine.com Tue Oct 24 21:26:59 2006 From: mark at image-engine.com (Mark Williams) Date: Tue, 24 Oct 2006 14:26:59 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <1949.1161718019@image-engine.com> On Mon Oct 23 23:27 , 'Roman Yakovenko' sent: >You can take a look on custom smart pointer example here: >http://language-binding.net/pyplusplus/bpl_lessons_learned/smart_ptrs/smart_ptrs.html > >If you will start with it, I am sure you will save your time. I've had a good look at that example, but am concerned at the apparent need to create a derived_ptr_t type and the implication that I'd effectively need to implement one of these for every class type which my shared pointers can hold. I could be wrong about this but the only comment associated with derived_ptr_t is "Small convenience class. Actually it is defined here, because this is a pattern Ogre project uses.", which isn't too descriptive. Also, are the base_wrapper_t and derived_wrapper_t classes absolutely necessary? Basically I have an existing class hierarchy that I'm attempting to wrap without having to modify it in any way, or resort to using shared_ptrs - but it would appear that this may not be possible without substantial code bloat to support intrusive_ptr. :( Thanks, Mark From mark at image-engine.com Tue Oct 24 21:36:30 2006 From: mark at image-engine.com (Mark Williams) Date: Tue, 24 Oct 2006 14:36:30 -0500 Subject: [C++-sig] Overloaded pure virtual method Message-ID: <2649.1161718590@image-engine.com> Hi, I'm having some difficulty understanding the syntax for binding pure virtual member functions with default arguments. Here is a simple class definition: class TestOverloads { public: virtual ~TestOverloads() {} virtual void overloaded(float f = 0) =0; }; I have also defined: BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MyOverloads, overloaded, 0, 1); Now, I find that the following does not compile: class_("TestOverloads", no_init) .def("overloaded", pure_virtual( &TestOverloads::overloaded), MyOverloads() ); But the following does compile: class_("TestOverloads", no_init) .def("overloaded", pure_virtual( &TestOverloads::overloaded) ); If I remove the =0 pure virtual specification from the class definition then I can at least compile: class_("TestOverloads", no_init) .def("overloaded", &TestOverloads::overloaded, MyOverloads() ); So it would appear to be some combination of pure_virtual with BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS What am I doing wrong here, please? Thanks, Mark From info at tobias-kraentzer.de Tue Oct 24 21:24:44 2006 From: info at tobias-kraentzer.de (Tobias =?iso-8859-1?q?Kr=E4ntzer?=) Date: Tue, 24 Oct 2006 21:24:44 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance Message-ID: <200610242124.44621.info@tobias-kraentzer.de> hello altogether, i have a problem using boost::python and boost::shared_ptr with abstract classes and inheritance. i am using a structure of abstract classes as interface. the implementation is in derived classes of the base classes. class Base { /* ..pure virtual methods.. */ }; class Derived : Base { /* ..pure virtual methods.. */ }; class Base_impl : Base { /* ..implementation gose here.. */ }; class Derived_impl : Derived { /* ..implementation gose here.. */ }; the object creation is handled with a factory which always returns a shared_ptr< Base >. shared_ptr< Base > factory( bool use_derived); if the factory creates a derived class i want have access to that interface. >>> base = factory( False ) # object of type Base >>> derived = factory( True ) # object of type Derived how can i handle this? greetings, . . . tobias the complete code looks like this: #include #include // Interface /////////////////////////////// class Base { public: typedef boost::shared_ptr< Base > Ptr; virtual std::string foo() const = 0; }; class Derived : public Base { public: typedef boost::shared_ptr< Derived > Ptr; virtual std::string bar() const = 0; }; Base::Ptr factory( bool use_derived ); // Implementation ////////////////////////// class Base_impl : public Base { friend Base::Ptr factory( bool use_derived ); public: std::string foo() const { return( "Base foo" ); }; }; class Derived_impl : public Derived { friend Base::Ptr factory( bool use_derived ); public: std::string foo() const { return( "Derived foo" ); }; std::string bar() const { return( "Derived bar" ); }; }; // Factory ///////////////////////////////// Base::Ptr factory( bool use_derived ) { if ( !use_derived ) { Base::Ptr pt( new Base_impl() ); return( pt ); } else { Derived::Ptr pt( new Derived_impl() ); return( pt ); }; }; // Python ////////////////////////////////// #include using namespace boost::python; BOOST_PYTHON_MODULE( test ) { class_< Base, Base::Ptr, boost::noncopyable >( "Base", no_init ) .def( "foo", &Base::foo ) ; class_< Derived, Derived::Ptr, bases< Base >, boost::noncopyable >( "Derived", no_init ) .def( "foo", &Derived::foo ) .def( "bar", &Derived::bar ) ; def( "factory", &factory ); }; From roman.yakovenko at gmail.com Tue Oct 24 21:58:36 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Oct 2006 21:58:36 +0200 Subject: [C++-sig] Overloaded pure virtual method In-Reply-To: <2649.1161718590@image-engine.com> References: <2649.1161718590@image-engine.com> Message-ID: <7465b6170610241258q6d1ad2d9j87a1f10d9e64916d@mail.gmail.com> On 10/24/06, Mark Williams wrote: > > Hi, I'm having some difficulty understanding the syntax for binding pure virtual member functions with default arguments. Here > is a simple class definition: > > class TestOverloads > { > public: > virtual ~TestOverloads() {} > virtual void overloaded(float f = 0) =0; > > }; > > I have also defined: > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(MyOverloads, overloaded, 0, 1); This macro should not be used for pure virtual functions. > What am I doing wrong here, please? You should use boost::python::arg to add default value. http://boost.org/libs/python/doc/v2/args.html Next code was generated by Py++: struct TestOverloads_wrapper : TestOverloads, bp::wrapper< TestOverloads > { TestOverloads_wrapper() : TestOverloads() , bp::wrapper< TestOverloads >(){ // null constructor } virtual void overloaded( float f=0 ){ bp::override func_overloaded = this->get_override( "overloaded" ); func_overloaded( f ); } }; BOOST_PYTHON_MODULE(pyplusplus){ bp::class_< TestOverloads_wrapper, boost::noncopyable >( "TestOverloads" ) .def( "overloaded" , bp::pure_virtual( &::TestOverloads::overloaded ) , ( bp::arg("f")=0 ) ); } This code allows you to create new classes in Python that derives from TestOverloads class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Oct 24 22:15:58 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Oct 2006 22:15:58 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance In-Reply-To: <200610242124.44621.info@tobias-kraentzer.de> References: <200610242124.44621.info@tobias-kraentzer.de> Message-ID: <7465b6170610241315m54458b0alb9f5177a2544e5e6@mail.gmail.com> On 10/24/06, Tobias Kr?ntzer wrote: > hello altogether, > > i have a problem using boost::python and boost::shared_ptr with abstract > classes and inheritance. > > i am using a structure of abstract classes as interface. the implementation is > in derived classes of the base classes. > > class Base { /* ..pure virtual methods.. */ }; > class Derived : Base { /* ..pure virtual methods.. */ }; > > class Base_impl : Base { /* ..implementation gose here.. */ }; > class Derived_impl : Derived { /* ..implementation gose here.. */ }; > > the object creation is handled with a factory which always returns a > shared_ptr< Base >. > > shared_ptr< Base > factory( bool use_derived); > > if the factory creates a derived class i want have access to that interface. > > >>> base = factory( False ) # object of type Base > >>> derived = factory( True ) # object of type Derived > > how can i handle this? You did not describe the problem you actually have. derived.bar() should work It seems that you exported the classes "by the book". -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From info at tobias-kraentzer.de Tue Oct 24 22:40:11 2006 From: info at tobias-kraentzer.de (Tobias =?iso-8859-1?q?Kr=E4ntzer?=) Date: Tue, 24 Oct 2006 22:40:11 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance In-Reply-To: <7465b6170610241315m54458b0alb9f5177a2544e5e6@mail.gmail.com> References: <200610242124.44621.info@tobias-kraentzer.de> <7465b6170610241315m54458b0alb9f5177a2544e5e6@mail.gmail.com> Message-ID: <200610242240.11680.info@tobias-kraentzer.de> Am Dienstag, 24. Oktober 2006 22:15 schrieb Roman Yakovenko: > You did not describe the problem you actually have. sorry ;-) if i call the factory i only get the base interface not the derived. >>> import test >>> test.Base.create( False ) >>> test.Base.create( True ) >>> >>> d = test.Base.create( True ) >>> d.bar() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Base' object has no attribute 'bar' >>> d.__class__ = test.Derived >>> d >>> d.bar() 'Derived bar' . . . tobias From roman.yakovenko at gmail.com Tue Oct 24 22:51:04 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 24 Oct 2006 22:51:04 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance In-Reply-To: <200610242240.11680.info@tobias-kraentzer.de> References: <200610242124.44621.info@tobias-kraentzer.de> <7465b6170610241315m54458b0alb9f5177a2544e5e6@mail.gmail.com> <200610242240.11680.info@tobias-kraentzer.de> Message-ID: <7465b6170610241351t3cffc060n5c264e33cd3f42d2@mail.gmail.com> On 10/24/06, Tobias Kr?ntzer wrote: > Am Dienstag, 24. Oktober 2006 22:15 schrieb Roman Yakovenko: > > You did not describe the problem you actually have. > > sorry ;-) > > if i call the factory i only get the base interface not the derived. > > >>> import test > >>> test.Base.create( False ) > > >>> test.Base.create( True ) > > >>> > >>> d = test.Base.create( True ) > >>> d.bar() > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'Base' object has no attribute 'bar' > >>> d.__class__ = test.Derived > >>> d > > >>> d.bar() > 'Derived bar' Try to add implicitly_convertible< Derived::Ptr, Base::Ptr >(); Does it help? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From info at tobias-kraentzer.de Tue Oct 24 23:28:47 2006 From: info at tobias-kraentzer.de (Tobias =?iso-8859-1?q?Kr=E4ntzer?=) Date: Tue, 24 Oct 2006 23:28:47 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance In-Reply-To: <7465b6170610241351t3cffc060n5c264e33cd3f42d2@mail.gmail.com> References: <200610242124.44621.info@tobias-kraentzer.de> <200610242240.11680.info@tobias-kraentzer.de> <7465b6170610241351t3cffc060n5c264e33cd3f42d2@mail.gmail.com> Message-ID: <200610242328.47852.info@tobias-kraentzer.de> Am Dienstag, 24. Oktober 2006 22:51 schrieb Roman Yakovenko: > On 10/24/06, Tobias Kr?ntzer wrote: > > Am Dienstag, 24. Oktober 2006 22:15 schrieb Roman Yakovenko: > > > You did not describe the problem you actually have. > > > > sorry ;-) > > > > if i call the factory i only get the base interface not the derived. > > > > >>> import test > > >>> test.Base.create( False ) > > > > > > > > >>> test.Base.create( True ) > > > > > > > > >>> d = test.Base.create( True ) > > >>> d.bar() > > > > Traceback (most recent call last): > > File "", line 1, in ? > > AttributeError: 'Base' object has no attribute 'bar' > > > > >>> d.__class__ = test.Derived > > >>> d > > > > > > > > >>> d.bar() > > > > 'Derived bar' > > Try to add > implicitly_convertible< Derived::Ptr, Base::Ptr >(); > > Does it help? unfortunately not. the same behavior as before. if it helps, i'm using: * Python 2.4.3 * g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5) and * boost 1.33.1 ... tobias PS: i saw i've written an example with an other api. actually it has to be: test.factory( ... ) not test.Base.create( ... ) but the behavior is the same. From mark at image-engine.com Wed Oct 25 01:37:26 2006 From: mark at image-engine.com (Mark Williams) Date: Tue, 24 Oct 2006 18:37:26 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <2331.1161733046@image-engine.com> >I think you are wrong. Remove from example derived class, make base class to >be constructable( no pure virtual function ) and replace smart_ptr_t with >intrusive_ptr. I think this will work. > Below is what I've tried, following your suggestion. The original tests pass, but the one I added to test passing an instance of the class through C++ fails : File "test.py", line 44, in test_object_passing self.assert_( c is d ) This assert definitely passes if shared_ptr is used in place of intrusive_ptr. Thanks again, Mark ---------------------- SConstruct ----------------------------------------- #scons build script SharedLibrary( target=r'custom_sptr' , source=[ r'bindings.cpp' ] , LIBS=[ r"boost_python" ] , CPPPATH=[ r"/usr/include/python2.4" ] , SHLIBPREFIX='' , SHLIBSUFFIX='.so' ) -------------------- bindings.cpp ------------------------------------- #include "boost/intrusive_ptr.hpp" #include "boost/python.hpp" class ref_counted_t { public: typedef unsigned long RefCount; ref_counted_t() : m_numRefs(0) {} void addRef() {m_numRefs ++;} void removeRef() {m_numRefs--; if (!m_numRefs) delete this;} protected: virtual ~ref_counted_t() {} RefCount m_numRefs; }; inline void intrusive_ptr_add_ref( ref_counted_t *r ){ r->addRef(); } inline void intrusive_ptr_release( ref_counted_t *r ){ r->removeRef(); } struct base_t : public ref_counted_t { public: virtual ~base_t() {} virtual int get_value() { return 0xDD; } }; typedef boost::intrusive_ptr base_ptr_t; base_ptr_t create_base(){ return boost::intrusive_ptr< base_t >( new base_t() ); } inline int ref_get_value( base_ptr_t& a ){ return a->get_value(); } inline int val_get_value( base_ptr_t a ){ return a->get_value(); } inline int const_ref_get_value( const base_ptr_t& a ){ return a->get_value(); } namespace bp = boost::python; struct globals_t { static base_ptr_t g_object; static base_ptr_t retrieve() { return g_object; } static void store( const base_ptr_t &o) { g_object = o; } }; base_ptr_t globals_t::g_object; BOOST_PYTHON_MODULE( custom_sptr ){ bp::class_< base_t, boost::noncopyable, base_ptr_t >( "base_t" ) .def( "get_value", &base_t::get_value ); bp::def( "const_ref_get_value", &::const_ref_get_value ); bp::def( "ref_get_value", &::ref_get_value ); bp::def( "val_get_value", &::val_get_value ); bp::def( "create_base", &::create_base ); bp::def("store", & globals_t::store ); bp::def("retrieve", & globals_t::retrieve ); } ------------------------ test.py ------------------------------- import unittest import custom_sptr class tester_t( unittest.TestCase ): def __init__( self, *args ): unittest.TestCase.__init__( self, *args ) def __test_ref( self, inst ): try: custom_sptr.ref_get_value( inst ) self.fail( 'ArgumentError was not raised.' ) except Exception, error: self.failUnless( error.__class__.__name__ == 'ArgumentError' ) def __test_ref_fine( self, inst, val ): self.assertEqual( custom_sptr.ref_get_value( inst ), val ) def __test_val( self, inst, val ): self.assertEqual( custom_sptr.val_get_value( inst ), val ) def __test_const_ref( self, inst, val ): self.assertEqual( custom_sptr.const_ref_get_value( inst ), val ) def __test_impl( self, inst, val ): self.__test_ref( inst ) self.__test_val( inst, val ) self.__test_const_ref( inst, val ) def test_created_base( self ): inst = custom_sptr.create_base() val = 0xDD self.__test_ref_fine( inst, val ) self.__test_val( inst, val ) self.__test_const_ref( inst, val ) def test_object_passing(self): c = custom_sptr.create_base() custom_sptr.store(c) d = custom_sptr.retrieve() self.assertEqual( type(c), type(d) ) self.assert_( c is d ) def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) return suite def run_suite(): unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": run_suite() From shiqinfeng at gmail.com Wed Oct 25 07:40:52 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Wed, 25 Oct 2006 15:40:52 +1000 Subject: [C++-sig] How to make *.so file callable in different platforms(unix, windows, mac) Message-ID: Dear All, I have wrapped something c++ code and build it into *.so file under Unix. The problem is that user can only import it under Unix now. How can I let it work under different platforms(windows,mac)? Any suggestion? Thanks in advance! -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Oct 25 08:11:21 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 25 Oct 2006 08:11:21 +0200 Subject: [C++-sig] Passing objects between python / c++ In-Reply-To: <2331.1161733046@image-engine.com> References: <2331.1161733046@image-engine.com> Message-ID: <7465b6170610242311k28d6bdceid3f49df64addb65a@mail.gmail.com> On 10/25/06, Mark Williams wrote: > > >I think you are wrong. Remove from example derived class, make base class to > >be constructable( no pure virtual function ) and replace smart_ptr_t with > >intrusive_ptr. I think this will work. > > > > Below is what I've tried, following your suggestion. The original tests pass, but the one I added to test passing an instance of the class through C++ fails : > > File "test.py", line 44, in test_object_passing > self.assert_( c is d ) > > This assert definitely passes if shared_ptr is used in place of intrusive_ptr. I think this is "an identity problem". Search for it in the mailing list. Also c and expose same object they are different Python objects. Am I right? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achim-bpl at mol-net.com Wed Oct 25 09:29:24 2006 From: achim-bpl at mol-net.com (Achim H.) Date: Wed, 25 Oct 2006 09:29:24 +0200 Subject: [C++-sig] How to make *.so file callable in different platforms(unix, windows, mac) In-Reply-To: References: Message-ID: <200610250929.24702.achim-bpl@mol-net.com> Am Mittwoch, 25. Oktober 2006 07:40 schrieb Qinfeng(Javen) Shi: > I have wrapped something c++ code and build it into *.so file under Unix. > The problem is that user can only import it under Unix now. > How can I let it work under different platforms(windows,mac)? You have to compile it on those platforms as well, in case of Windows to a .dll file. ( If you want the same filename extension on all platforms then you are allowed to rename the dll/so files to .pyd after creation, but still each platform needs its file natively compiled.) Achim. -- Dr. Achim Herwig, Dipl.-Chem. Molecular Networks GmbH, N?gelsbachstra?e 25, 91052 Erlangen, Germany Tel. (+49 9131) 97 90 624, (+49 9131) 81 56 68, Fax. (+49 9131) 81 56 69 achim.herwig at molecular-networks.com - http://www.molecular-networks.com From shiqinfeng at gmail.com Wed Oct 25 14:14:14 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Wed, 25 Oct 2006 22:14:14 +1000 Subject: [C++-sig] How to make *.so file callable in different Re: How to make *.so file callable in different platforms Message-ID: >You have to compile it on those platforms as well, in case of Windows to a .dll file. Is there any easy way without compiling it in every platforms? -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngoodspeed at solidworks.com Wed Oct 25 14:31:47 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Wed, 25 Oct 2006 08:31:47 -0400 Subject: [C++-sig] How to make *.so file callable in different platforms Message-ID: <31E9B8A4BEFAA242B047A736B344578B2BAD99@corp-mail8.solidworks.swk> ________________________________________ From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi Sent: Wednesday, October 25, 2006 8:14 AM To: c++-sig at python.org Subject: Re: [C++-sig] How to make *.so file callable in different Re: Howto make *.so file callable in different platforms >You have to compile it on those platforms as well, in case of Windows to a >.dll file. Is there any easy way without compiling it in every platforms? [Nat] Code written in Python should run on every platform. A Python extension module written in C++ (or any code written in C++) can only run on a given platform if it has specifically been compiled for that platform family. That's one of the driving motivations behind languages such as Python and Java. From beau.sapach at ualberta.ca Wed Oct 25 18:05:52 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Wed, 25 Oct 2006 10:05:52 -0600 Subject: [C++-sig] MFC and Python Message-ID: <000101c6f84f$7735d7c0$65a18740$@sapach@ualberta.ca> Hello everyone, I apologize if this isn't the best place to be asking this, but does anyone know if MFC can work with python? That is, can I write an MFC DLL and use it as a python module? I've tried a couple of quick tests, writing a couple of plane functions that printf some output, but what about creating a dialog class and displaying it to the user? Beau -------------- next part -------------- An HTML attachment was scrubbed... URL: From geekU at mac.com Wed Oct 25 18:22:49 2006 From: geekU at mac.com (geekU) Date: Wed, 25 Oct 2006 18:22:49 +0200 Subject: [C++-sig] MFC and Python In-Reply-To: <000101c6f84f$7735d7c0$65a18740$%sapach@ualberta.ca> References: <000101c6f84f$7735d7c0$65a18740$%sapach@ualberta.ca> Message-ID: <453F8F59.6040401@mac.com> Beau Sapach schrieb: > > Hello everyone, > > I apologize if this isn?t the best place to be asking this, but does > anyone know if MFC can work with python? That is, can I write an MFC > DLL and use it as a python module? I?ve tried a couple of quick tests, > writing a couple of plane functions that printf some output, but what > about creating a dialog class and displaying it to the user? > > Beau > > ------------------------------------------------------------------------ > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > you can even do only the resource in the dll and use the python mfc wrappers :) from pywin.mfc import dialog import win32ui self.dll= *win32ui.LoadLibrary(/"mylib.dll"/*) self.dlg= dialog.Dialog(ID_MyDIALOG,self.dll) self.dlg.CreateWindow() self.dlg.SetFocus() self.dlg.ShowWindow(1) text=self.dlg.GetDlgItem(1000) text.SetWindowText("hallo from Python") From mjmille2 at uiuc.edu Wed Oct 25 18:48:57 2006 From: mjmille2 at uiuc.edu (Matt Miller) Date: Wed, 25 Oct 2006 11:48:57 -0500 Subject: [C++-sig] Getting Boost.Python Examples Working with Debian Packages Message-ID: <33d506e50610250948h489b265g79e7432ce8a21467@mail.gmail.com> Based on some questions to this list, it seems that some people were unable to get the Boost.Python examples to work when they used Debian packages (e.g., boost-build, bjam, libboost-doc, libboost.*-dev packages). I finally got it to work on my system and, since I couldn't find any documentation on this list or elsewhere, thought I'd share the steps I took: * The getting_started{1,2} examples that I tested are found at: /usr/share/doc/libboost-doc/examples/libs/python/example (I copied these files elsewhere to make the modifications) * The packages use Bjam v2, so remove the v1 Jamfile and rename the v2 Jamfile: rm Jamfile mv Jamfile.v2 Jamfile * For some reason an empty project-root.jam file needs to be created: touch project-root.jam * In boost-build.jam, modify the boost-build path to the following: boost-build /usr/share/boost-build/kernel ; * In Jamrules, modify the BOOST_ROOT path to be: path-global BOOST_ROOT : /usr/include/ ; * In Jamfile (which is now the v2 Jamfile), the project requirements should be modified as follows (assuming the python-dev package was installed and that it is for Python version 2.4): project : requirements /usr/lib/libboost_python.so /usr/include/python2.4; * Now, you should be able to run bjam and get the following output: ...found 18 targets... ...updating 7 targets... MkDir1 bin MkDir1 bin/gcc MkDir1 bin/gcc/debug gcc.compile.c++ bin/gcc/debug/getting_started1.o gcc.link.dll bin/gcc/debug/getting_started1.so gcc.compile.c++ bin/gcc/debug/getting_started2.o gcc.link.dll bin/gcc/debug/getting_started2.so ...updated 7 targets... * Copy the the *.{o,so} files to the example directory and they should be usable in Python now: cp bin/gcc/debug/*.{o,so} . python >>> import getting_started1 >>> print getting_started1.greet() hello, world -Matt From beau.sapach at ualberta.ca Wed Oct 25 19:22:05 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Wed, 25 Oct 2006 11:22:05 -0600 Subject: [C++-sig] Embedding... In-Reply-To: <453D1981.1050203@sympatico.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> Message-ID: <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> Hello everyone, Thanks Stefan for your help! I know I'm posting a lot to this list, but I must admit I'm having a hard time wrapping my head around boost.python. If I want to make an instance of an object in C++ available to a python interpreter within the same .exe I must first expose the class correct? Using the same method described in the tutorial? Once that's done could I expose a global function (again within the same exe) that would return a pointer to an instance of the previously exposed class? Or is there an easier way of simply passing this to python? For example if I have a window called a workspace that the user interacts with, could I expose the workspace class and have a global function called GetWorkspace() that returns a pointer to the C++ instance of workspace, thus allowing the user to manipulate the window in python? Beau -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Monday, October 23, 2006 1:35 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedding... Beau Sapach wrote: > Hello Everyone, > > > I'm looking to embed Python in an application I'm working on in C++. I've > been trying out Boost.Python and it seems pretty straight forward but > doesn't have (that I've found yet anyway) any complete examples to follow > for embedding Python. What I want to be able to do is give users access to > objects created in C++ land inside a Python window within my .exe. Have you looked at the code from CVS ? I added some support for embedding sometime in 2005 (after the 1.33 release branch was created), containing 'exec', 'exec_string', and 'import' functions: http://cci.lbl.gov/~rwgk/shortcuts/boost//libs/python/doc/v2/exec.html (The docs at boost.org don't include these bits yet as they only document the last release.) > I'm assuming I'll have to create instances of my classes in C++, for example > when my application is starting up. Then I would have to create a Python > interpreter and have it call Python functions to give it references to my > previously created C++ objects. Lastly, show the Python window to the user. Right. One way is to have preexisting (C++) objects be bound to python objects that get exposed to user scripts that are run from within the main (C++) application by means of an embedded python interpreter. > Please correct me if I'm wrong in how I'm imagining this... The problem I'm > having right now is that Boost.Python seems very good for creating DLLs to > give Python access to classes and functions, but how do I make > classes/functions that are compiled as part of my exe available to python > WITHIN the same exe??? See above. The bits to actually provide the missing link are straight forward, so you may put it into your own code, if you can't use the latest not-quite-released-yet version of boost: // Execute python source code from file filename. // global and local are the global and local scopes respectively, // used during execution. object exec_file(str filename, object global, object local) { // should be 'char const *' but older python versions don't use 'const' yet. char *f = python::extract(filename); // Let python open the file to avoid potential binary incompatibilities. PyObject *pyfile = PyFile_FromString(f, "r"); if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file"); python::handle<> file(pyfile); PyObject* result = PyRun_File(PyFile_AsFile(file.get()), f, Py_file_input, global.ptr(), local.ptr()); if (!result) throw_error_already_set(); return object(detail::new_reference(result)); } Good luck, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From mark at image-engine.com Wed Oct 25 19:36:33 2006 From: mark at image-engine.com (Mark Williams) Date: Wed, 25 Oct 2006 12:36:33 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <1426.1161797793@image-engine.com> On Tue Oct 24 23:11 , "Roman Yakovenko" sent: >On 10/25/06, Mark Williams mark at image-engine.com> wrote: >> >> >I think you are wrong. Remove from example derived class, make base class to >> >be constructable( no pure virtual function ) and replace smart_ptr_t with >> >intrusive_ptr. I think this will work. >> > >> >> Below is what I've tried, following your suggestion. The original tests pass, but the one I added to test passing an instance of the class through C++ fails : >> >> File "test.py", line 44, in test_object_passing >> self.assert_( c is d ) >> >> This assert definitely passes if shared_ptr is used in place of intrusive_ptr. > >I think this is "an identity problem". Search for it in the mailing >list. Also c and expose >same object they are different Python objects. > >Am I right? > You are right - it is an identity problem. However, before posting my original question I had already been through the lists to see if there was an existing solution. The threads I've found on the subject - the most notable of which appears to be http://mail.python.org/pipermail/c++-sig/2006-March/010458.html - seem to tail off without a conclusion being made. I see that internally boost.python contains many references to shared_ptr, and I have confirmed through a number of tests that the identity problem appears to be solved if shared_ptrs are employed, unfortunately I'm in a position where I cannot change the C++ I'm binding to use a different smart pointer type. Is there anything else I might try, or is this unfixable? Thanks again, Mark From seefeld at sympatico.ca Wed Oct 25 19:46:01 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 25 Oct 2006 13:46:01 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> Message-ID: <453FA2D9.9040802@sympatico.ca> Beau Sapach wrote: > Hello everyone, > > Thanks Stefan for your help! I know I'm posting a lot to this list, but I > must admit I'm having a hard time wrapping my head around boost.python. > > If I want to make an instance of an object in C++ available to a python > interpreter within the same .exe I must first expose the class correct? > Using the same method described in the tutorial? Right. > Once that's done could I expose a global function (again within the same > exe) that would return a pointer to an instance of the previously exposed > class? Or is there an easier way of simply passing this to python? Assuming you have set up a module 'world', containing a class 'hello' (exported via the aforementioned class_<> harness), you can instantiate an object of that type as: ----C++ code---- namespace bpl = boost::python; bpl::object main = python::import("__main__"); bpl::object global(main.attr("__dict__")); // Load the 'hello' module. bpl::object result = bpl::exec("import hello\n", global, global); // Get hold of the hello.world class. bpl::object hello_class = global["hello.world"]; // Instantiate it. bpl::object hello_instance = hello_class(); // Inject it into environment. global['hello_instance'] = hello_instance; // And run a script with it. result = bpl::exec_file(script_name, global, global); // Recover things from environment. bpl::object greeting = global["greeting"]; ---------------- The script itself can now assume the existence of 'hello_instance', which was placed into the environment just before the script was invoked with it (see above): ----python code---- # let's assume the 'hello.world' class exposes a 'greet' method. greeting = hello_instance.greet() ------------------- 'greeting' becomes a new variable in the environment, which can be extracted after the script's execution has finished. (See above.) As you can see, the main device to exchange data between the C++ runtime and the environment seen by the script is the 'global' dictionary that gets passed to the exec / exec_file calls. It works two-ways. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From beau.sapach at ualberta.ca Wed Oct 25 21:38:58 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Wed, 25 Oct 2006 13:38:58 -0600 Subject: [C++-sig] Embedding... In-Reply-To: <453FA2D9.9040802@sympatico.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> Message-ID: <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> Thanks again for your help Stefan! I'm trying to compile a simple example based on your code but I'm getting link errors, unresolved externals for both exec and import functions. Does this mean that they are not built into my boost_python.lib? I've downloaded and built the CVS version using the visual studio .dsw file. Now I'm guessing it's not up to date? Beau -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Wednesday, October 25, 2006 11:46 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedding... Beau Sapach wrote: > Hello everyone, > > Thanks Stefan for your help! I know I'm posting a lot to this list, > but I must admit I'm having a hard time wrapping my head around boost.python. > > If I want to make an instance of an object in C++ available to a > python interpreter within the same .exe I must first expose the class correct? > Using the same method described in the tutorial? Right. > Once that's done could I expose a global function (again within the > same > exe) that would return a pointer to an instance of the previously > exposed class? Or is there an easier way of simply passing this to python? Assuming you have set up a module 'world', containing a class 'hello' (exported via the aforementioned class_<> harness), you can instantiate an object of that type as: ----C++ code---- namespace bpl = boost::python; bpl::object main = python::import("__main__"); bpl::object global(main.attr("__dict__")); // Load the 'hello' module. bpl::object result = bpl::exec("import hello\n", global, global); // Get hold of the hello.world class. bpl::object hello_class = global["hello.world"]; // Instantiate it. bpl::object hello_instance = hello_class(); // Inject it into environment. global['hello_instance'] = hello_instance; // And run a script with it. result = bpl::exec_file(script_name, global, global); // Recover things from environment. bpl::object greeting = global["greeting"]; ---------------- The script itself can now assume the existence of 'hello_instance', which was placed into the environment just before the script was invoked with it (see above): ----python code---- # let's assume the 'hello.world' class exposes a 'greet' method. greeting = hello_instance.greet() ------------------- 'greeting' becomes a new variable in the environment, which can be extracted after the script's execution has finished. (See above.) As you can see, the main device to exchange data between the C++ runtime and the environment seen by the script is the 'global' dictionary that gets passed to the exec / exec_file calls. It works two-ways. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From seefeld at sympatico.ca Wed Oct 25 21:54:05 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 25 Oct 2006 15:54:05 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> Message-ID: <453FC0DD.1050707@sympatico.ca> Beau Sapach wrote: > Thanks again for your help Stefan! > > I'm trying to compile a simple example based on your code but I'm getting > link errors, unresolved externals for both exec and import functions. Does > this mean that they are not built into my boost_python.lib? I've downloaded > and built the CVS version using the visual studio .dsw file. Now I'm > guessing it's not up to date? I have no idea about what the dsw file contains; I have never touched it. The canonical way to build boost is using bjam. :-) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From info at tobias-kraentzer.de Wed Oct 25 22:35:56 2006 From: info at tobias-kraentzer.de (Tobias =?iso-8859-1?q?Kr=E4ntzer?=) Date: Wed, 25 Oct 2006 22:35:56 +0200 Subject: [C++-sig] shared_ptr, abstract classes and inheritance In-Reply-To: <200610242328.47852.info@tobias-kraentzer.de> References: <200610242124.44621.info@tobias-kraentzer.de> <7465b6170610241351t3cffc060n5c264e33cd3f42d2@mail.gmail.com> <200610242328.47852.info@tobias-kraentzer.de> Message-ID: <200610252235.56602.info@tobias-kraentzer.de> Am Dienstag, 24. Oktober 2006 23:28 schrieb Tobias Kr?ntzer: > > Does it help? > > unfortunately not. > the same behavior as before. Temporally I've made a workaround: I changed the factory to: list factory( bool use_derived ) { list result; if ( !use_derived ) { Base::Ptr pt( new Base_impl() ); result.append( pt ); } else { Derived::Ptr pt( new Derived_impl() ); result.append( pt ); }; return( result ); }; an write an new factory in Python: >>> import test >>> _old_factory = test.factory >>> >>> def _new_factory( derived ): ... return _old_factory( derived )[0] >>> test.factory = _new_factory >>> >>> test.factory( True ) >>> test.factory( False ) >>> test.factory( True ).bar() 'Derived bar' I will focus on a solution to the problem later. But at the moment, thanks for help. From beau.sapach at ualberta.ca Wed Oct 25 23:31:41 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Wed, 25 Oct 2006 15:31:41 -0600 Subject: [C++-sig] Embedding... In-Reply-To: <453FC0DD.1050707@sympatico.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> Message-ID: <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> Hi everyone, I've downloaded the CVS version of boost(following instructions from http://www.boost.org/more/getting_started.html#CVS) and built using bjam. I built with the following command: C:\boost\libs\python\build>bjam -sPYTHON_VERSION=2.5 -sPYTHON_ROOT=c:\python25 -sPYTHON_LIB_PATH=c:\python25\libs -sTOOLS=vc-7_1 -sBUILD=debug I then copied all the resulting lib and dll files (from bin-stage) to c:\boost\dll which is on my system's PATH and is also listed in visual studio under "library files". I've also explicitly added boost_python_debug.lib and python25.lib to my linker command line. My test program compiles fine but when it comes to linking it says: boostapp error LNK2019: unresolved external symbol "class boost::python::api::object __cdecl boost::python::exec(class boost::python::str,class boost::python::api::object,class boost::python::api::object)" (?exec at python@boost@@YA?AVobject at api@12 at Vstr@12 at V3412@1 at Z) referenced in function "public: void __thiscall CboostappDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1 at CboostappDlg@@QAEXXZ) boostapp error LNK2019: unresolved external symbol "class boost::python::api::object __cdecl boost::python::import(class boost::python::str)" (?import at python@boost@@YA?AVobject at api@12 at Vstr@12@@Z) referenced in function "public: void __thiscall CboostappDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1 at CboostappDlg@@QAEXXZ) And the offending C++ code: void CboostappDlg::OnBnClickedButton1() { namespace bpl = boost::python; bpl::object main = bpl::import("__main__"); bpl::object global(main.attr("__dict__")); //load the module bpl::object result = bpl::exec("import hello\n", global, global); //get a hold of the class bpl::object hello_class = global["hello.world"]; //instantiate the class bpl::object hello_instance = hello_class(); // Inject it into environment. global["hello_instance"] = hello_instance; // And run a script with it. result = bpl::exec("hello.greet()\n", global, global); } Does this mean that exec and import are not in my library or that I'm somehow calling them in such a way that the compiler doesn't complain but the linker does? Beau -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Wednesday, October 25, 2006 1:54 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedding... Beau Sapach wrote: > Thanks again for your help Stefan! > > I'm trying to compile a simple example based on your code but I'm getting > link errors, unresolved externals for both exec and import functions. Does > this mean that they are not built into my boost_python.lib? I've downloaded > and built the CVS version using the visual studio .dsw file. Now I'm > guessing it's not up to date? I have no idea about what the dsw file contains; I have never touched it. The canonical way to build boost is using bjam. :-) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From seefeld at sympatico.ca Wed Oct 25 23:47:17 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 25 Oct 2006 17:47:17 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> Message-ID: <453FDB65.9030006@sympatico.ca> Beau Sapach wrote: > Hi everyone, > > I've downloaded the CVS version of boost(following instructions from > http://www.boost.org/more/getting_started.html#CVS) and built using bjam. > > I built with the following command: > > C:\boost\libs\python\build>bjam -sPYTHON_VERSION=2.5 > -sPYTHON_ROOT=c:\python25 -sPYTHON_LIB_PATH=c:\python25\libs -sTOOLS=vc-7_1 > -sBUILD=debug > > I then copied all the resulting lib and dll files (from bin-stage) to > c:\boost\dll which is on my system's PATH and is also listed in visual > studio under "library files". I've also explicitly added > boost_python_debug.lib and python25.lib to my linker command line. My test > program compiles fine but when it comes to linking it says: > > boostapp error LNK2019: unresolved external symbol "class > boost::python::api::object __cdecl boost::python::exec(class > boost::python::str,class boost::python::api::object,class > boost::python::api::object)" 1) Can you confirm (by simply visually checking bjam's output) that exec.cpp and import.cpp get compiled and linked into the library ? 2) Are you sure the library you are linking with is indeed the one you just compiled, as opposed to one you have compiled / installed previously from an older version of the code ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From roman.yakovenko at gmail.com Wed Oct 25 23:54:18 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 25 Oct 2006 23:54:18 +0200 Subject: [C++-sig] Passing objects between python / c++ In-Reply-To: <1426.1161797793@image-engine.com> References: <1426.1161797793@image-engine.com> Message-ID: <7465b6170610251454p4dce756dvf38b9580b853845d@mail.gmail.com> On 10/25/06, Mark Williams wrote: > > > > On Tue Oct 24 23:11 , "Roman Yakovenko" sent: > > >On 10/25/06, Mark Williams mark at image-engine.com> wrote: > >> > >> >I think you are wrong. Remove from example derived class, make base class to > >> >be constructable( no pure virtual function ) and replace smart_ptr_t with > >> >intrusive_ptr. I think this will work. > >> > > >> > >> Below is what I've tried, following your suggestion. The original tests pass, but the one I added to test passing an instance of the class through C++ fails : > >> > >> File "test.py", line 44, in test_object_passing > >> self.assert_( c is d ) > >> > >> This assert definitely passes if shared_ptr is used in place of intrusive_ptr. > > > >I think this is "an identity problem". Search for it in the mailing > >list. Also c and expose > >same object they are different Python objects. > > > >Am I right? > > > > You are right - it is an identity problem. However, before posting my original question I had already been through the lists to see if there was an existing solution. The threads I've found on the subject - the most notable of which appears to be http://mail.python.org/pipermail/c++-sig/2006-March/010458.html - seem > to tail off without a conclusion being made. I see that internally boost.python contains many references to shared_ptr, and I have confirmed through a number of tests that the identity problem appears to be solved if shared_ptrs are employed, unfortunately I'm in a position where I cannot change the C++ I'm > binding to use a different smart pointer type. > > Is there anything else I might try, or is this unfixable? I don't have enough knowledge to answer the question. It seems to me that you can create small work around: redefine store and retrieve function in Python, save the reference to the python object somewhere, next time user will ask to retrieve the object, you can return the object you stored earlier in Python. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From beau.sapach at ualberta.ca Thu Oct 26 00:40:42 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Wed, 25 Oct 2006 16:40:42 -0600 Subject: [C++-sig] Embedding... In-Reply-To: <453FDB65.9030006@sympatico.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> Message-ID: <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> Exec and import show up in the output: vc-C++ ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\exec.obj exec.cpp vc-C++ ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\import.obj import.cpp vc-Link ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\boost_python.dll ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\boost_python.lib Creating library ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\boost_python.lib and object ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\release\threadi ng-multi\boost_python.exp FileClone bin-stage\boost_python.dll FileClone bin-stage\boost_python.lib AND vc-C++ ..\..\..\bin\boost\libs\python\build\libboost_python.lib\vc-7_1\release\thre ading-multi\exec.obj exec.cpp vc-C++ ..\..\..\bin\boost\libs\python\build\libboost_python.lib\vc-7_1\release\thre ading-multi\import.obj import.cpp vc-Archive ..\..\..\bin\boost\libs\python\build\libboost_python.lib\vc-7_1\release\thre ading-multi\libboost_python.lib Microsoft (R) Library Manager Version 7.10.3077 Copyright (C) Microsoft Corporation. All rights reserved. ... ... ... "..\..\..\bin\boost\libs\python\build\libboost_python.lib\vc-7_1\release\thr eading-multi\exec.obj" "..\..\..\bin\boost\libs\python\build\libboost_python.lib\vc-7_1\release\thr eading-multi\import.obj" FileClone bin-stage\libboost_python.lib ...updated 78 targets... I'm not sure if this means that it compiled and linked properly but I certainly don't see any errors... What is libboost_python.lib for? Beau -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Wednesday, October 25, 2006 3:47 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedding... Beau Sapach wrote: > Hi everyone, > > I've downloaded the CVS version of boost(following instructions from > http://www.boost.org/more/getting_started.html#CVS) and built using bjam. > > I built with the following command: > > C:\boost\libs\python\build>bjam -sPYTHON_VERSION=2.5 > -sPYTHON_ROOT=c:\python25 -sPYTHON_LIB_PATH=c:\python25\libs > -sTOOLS=vc-7_1 -sBUILD=debug > > I then copied all the resulting lib and dll files (from bin-stage) to > c:\boost\dll which is on my system's PATH and is also listed in visual > studio under "library files". I've also explicitly added > boost_python_debug.lib and python25.lib to my linker command line. My > test program compiles fine but when it comes to linking it says: > > boostapp error LNK2019: unresolved external symbol "class > boost::python::api::object __cdecl boost::python::exec(class > boost::python::str,class boost::python::api::object,class > boost::python::api::object)" 1) Can you confirm (by simply visually checking bjam's output) that exec.cpp and import.cpp get compiled and linked into the library ? 2) Are you sure the library you are linking with is indeed the one you just compiled, as opposed to one you have compiled / installed previously from an older version of the code ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From seefeld at sympatico.ca Thu Oct 26 01:40:59 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 25 Oct 2006 19:40:59 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> Message-ID: <453FF60B.6000805@sympatico.ca> Beau Sapach wrote: [...] > I'm not sure if this means that it compiled and linked properly but I > certainly don't see any errors... > What is libboost_python.lib for? OK, so it gets compiled into the library. However, I just realize that these symbols don't get exported by a dll (by default) on windows, so a declspec decorator is missing. (I'm rarely using windows, so I haven't noticed this omission yet.) Could you please try the attached patch to see whether it solves the missing symbols issue ? (If you don't know how to apply a patch: please try injecting the BOOST_PYTHON_DECL macro at the four different places as shown in the applied patch file.) Many thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch URL: From richardb at avisynth.org Thu Oct 26 07:28:01 2006 From: richardb at avisynth.org (Richard Berg) Date: Thu, 26 Oct 2006 01:28:01 -0400 Subject: [C++-sig] Boost::Python patch for decorated class method Message-ID: <025b01c6f8bf$810e0720$6401a8c0@yakko> Surprised there was no response from Boost. Is this the right place to submit boost::python bugs & patches? -----Original Message----- From: Richard Berg [mailto:richardb at avisynth.org] Sent: Sunday, October 15, 2006 21:40 To: boost at lists.boost.org Subject: Boost::Python patch for decorated class method I found that I could not compile any code that tried to export a class method to Python if the method was "decorated" with a calling convention like __cdecl (MSVC8 style).? Standalone functions work ok because the compiler matches them against RT(*) while class methods were trying to match against RT(ClassT::*). ? I'm sure there's a concise way to make signature.hpp work with decorative keywords generally, so I am *not* proposing you accept my patch.? I know virtually nothing about template metaprogramming; my code is neither concise nor general.? However, the patch does demonstrate the problem and solution. ? Best, -Richard -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.hpp.patch Type: application/octet-stream Size: 2404 bytes Desc: not available URL: From meine at informatik.uni-hamburg.de Thu Oct 26 17:18:27 2006 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 26 Oct 2006 17:18:27 +0200 Subject: [C++-sig] Embedding... In-Reply-To: <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> Message-ID: <200610261718.28057.meine@informatik.uni-hamburg.de> On Wednesday, 25. October 2006 19:22, Beau Sapach wrote: > If I want to make an instance of an object in C++ available to a python > interpreter within the same .exe I must first expose the class correct? > Using the same method described in the tutorial? > > Once that's done could I expose a global function (again within the same > exe) that would return a pointer to an instance of the previously exposed > class? Yes, that works fine, if you cannot instantiate the class from python, or if the object is something which is already initialized from C++, e.g. a program window or sth. like that. I wrote the following in one of my .cxx files: BOOST_PYTHON_MODULE_INIT(segmenterInternal) { def("viewer", &getViewer); ... } and then in main.cxx: int main(int argc, char **argv) { Py_Initialize(); initsegmenterInternal(); // init internal python module HTH, too. -- Ciao, / / /--/ / / ANS From beau.sapach at ualberta.ca Thu Oct 26 18:27:09 2006 From: beau.sapach at ualberta.ca (Beau Sapach) Date: Thu, 26 Oct 2006 10:27:09 -0600 Subject: [C++-sig] Embedding... In-Reply-To: <453FF60B.6000805@sympatico.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> <453FF60B.6000805@sympatico.ca> Message-ID: <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> That seems to have worked, I manually added the BOOST_PYTHON_DECL macro to the 4 files and now it links just fine. Thanks! Strangely though, my app can't link into the DLL at runtime unless it's in the same folder, even though the DLL is on the PATH and the LD_LIBRARY_PATH. And finally, the program is breaking within the first call to import: boost::python::object main = boost::python::import("__main__"); it breaks on: python::handle<> module(python::borrowed(PyImport_AddModule(n))); saying: Unhandled exception at 0x1e079547 in boostapp.exe: 0xC0000005: Access violation reading location 0x00000004. Beau -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Wednesday, October 25, 2006 5:41 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedding... Beau Sapach wrote: [...] > I'm not sure if this means that it compiled and linked properly but I > certainly don't see any errors... > What is libboost_python.lib for? OK, so it gets compiled into the library. However, I just realize that these symbols don't get exported by a dll (by default) on windows, so a declspec decorator is missing. (I'm rarely using windows, so I haven't noticed this omission yet.) Could you please try the attached patch to see whether it solves the missing symbols issue ? (If you don't know how to apply a patch: please try injecting the BOOST_PYTHON_DECL macro at the four different places as shown in the applied patch file.) Many thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From seefeld at sympatico.ca Thu Oct 26 18:40:30 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 26 Oct 2006 12:40:30 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> <453FF60B.6000805@sympatico.ca> <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> Message-ID: <4540E4FE.4060203@sympatico.ca> Beau Sapach wrote: > That seems to have worked, I manually added the BOOST_PYTHON_DECL macro to > the 4 files and now it links just fine. Thanks! Strangely though, my app Great ! David, is it OK for this patch (see previous mail) to be applied to both, HEAD, as well as the 1_34 branch ? > can't link into the DLL at runtime unless it's in the same folder, even > though the DLL is on the PATH and the LD_LIBRARY_PATH. And finally, the > program is breaking within the first call to import: > > boost::python::object main = boost::python::import("__main__"); > > it breaks on: > > python::handle<> module(python::borrowed(PyImport_AddModule(n))); > > saying: > > Unhandled exception at 0x1e079547 in boostapp.exe: 0xC0000005: Access > violation reading location 0x00000004. That's very strange. Can you run the boost.python test suite ? I'd strongly suspect your build system / code to be the culprit, unless you can prove the contrary. :-) (And yes: in order for anybody to be able to help you further a test case is needed, making the failure reproducible, at least to those who run boost on the same platform as you.) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From shiqinfeng at gmail.com Fri Oct 27 08:24:53 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Fri, 27 Oct 2006 16:24:53 +1000 Subject: [C++-sig] ERROR:illegal hardware instruction on MAC OS when using import_array() Message-ID: Dear All, I wrapped a c++ code which can receive numpy.array data in python on linux. For that I used import_array() in c extension. It works well on linux. Then I bjam it in MAC OS without any error. But when I import it in python on MAC OS, it reports a error. It seems that import_array() evoked the error. Does anyone know how to solve it? Thanks! -------------------error------------------ >> test.py zsh: illegal hardware instruction -----------------c extension------------ namespace ar=boost::python::numeric; BOOST_PYTHON_MODULE(coverTree) { import_array(); //ar::array::set_module_and_type("numpy", "ndarray"); } -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From yardbird at nerdshack.com Fri Oct 27 17:48:50 2006 From: yardbird at nerdshack.com (yardbird) Date: Fri, 27 Oct 2006 17:48:50 +0200 Subject: [C++-sig] [boost::python] Unresolved overloaded function - methods with same name Message-ID: <200610271748.50943.yardbird@nerdshack.com> Hello, I have a problem with getters/setters methods with the same name which both return cont/non-const reference to a class' data member. For instance: struct Foo { Foo(int x) { b = x; } int const& get_b() const { return b; } int & get_b() { return b; } private: int b; }; // Wrapper code BOOST_PYTHON_MODULE(my_module) { class_("Foo", init()) .def("get_b", &Foo::get_b); } When I try to build this it seems like it cannot decide whether it should use the const or non-const method to access the member. The error I get is something like: [...]no matching function for call to [...] ::def(const char [6], ,[...] I know I could just make "b" public and then use .defreadonly/.defreadwrite to access it, but I would like to keep unaltered the original layout of the class. Sorry if this is a stupid question, I looked at the documentation and tried to use "return_internal_reference<>()" and the likes but I really could not figure it out. Thanks very much, Francesco From roman.yakovenko at gmail.com Fri Oct 27 19:49:40 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 27 Oct 2006 19:49:40 +0200 Subject: [C++-sig] [boost::python] Unresolved overloaded function - methods with same name In-Reply-To: <200610271748.50943.yardbird@nerdshack.com> References: <200610271748.50943.yardbird@nerdshack.com> Message-ID: <7465b6170610271049m7874f94cqf7f8fc648f3a861c@mail.gmail.com> On 10/27/06, yardbird wrote: > Hello, > > I have a problem with getters/setters methods with the same name which both > return cont/non-const reference to a class' data member. For instance: > > struct Foo { > Foo(int x) { b = x; } > int const& get_b() const { return b; } > int & get_b() { return b; } > private: > int b; > }; > > // Wrapper code > > BOOST_PYTHON_MODULE(my_module) > { > class_("Foo", init()) > .def("get_b", &Foo::get_b); -----------------------^^^^^^^^^^^ typedef int const& (Foo::*get_b_const_type) const; .def( "get_b", get_b_const_type( &Foo::get_b ) ); The idea is to use function type to specify to compiler what function you want to export. I think you also will have to specify call policies: return_value_policy< copy_const_reference > -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mark at image-engine.com Fri Oct 27 21:36:30 2006 From: mark at image-engine.com (Mark Williams) Date: Fri, 27 Oct 2006 14:36:30 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <2217.1161977790@image-engine.com> >> You are right - it is an identity problem. However, before posting my original question I had already been through the lists to see if there was an existing solution. The threads I've found on the subject - the most notable of which appears to be http://mail.python.org/pipermail/c++-sig/2006-March/010458.html - seem >> to tail off without a conclusion being made. I see that internally boost.python contains many references to shared_ptr, and I have confirmed through a number of tests that the identity problem appears to be solved if shared_ptrs are employed, unfortunately I'm in a position where I cannot change the C++ I'm >> binding to use a different smart pointer type. >> >> Is there anything else I might try, or is this unfixable? > >I don't have enough knowledge to answer the question. >It seems to me that you can create small work around: >redefine store and retrieve function in Python, save the reference to the python >object somewhere, next time user will ask to retrieve the object, you can return >the object you stored earlier in Python. > Thanks for your help. Mark From roman.yakovenko at gmail.com Fri Oct 27 21:42:53 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 27 Oct 2006 21:42:53 +0200 Subject: [C++-sig] Passing objects between python / c++ In-Reply-To: <2217.1161977790@image-engine.com> References: <2217.1161977790@image-engine.com> Message-ID: <7465b6170610271242m1a007caq3e96500b4a4570e6@mail.gmail.com> On 10/27/06, Mark Williams wrote: > > > >> You are right - it is an identity problem. However, before posting my original question I had already been through the lists to see if there was an existing solution. The threads I've found on the subject - the most notable of which appears to be http://mail.python.org/pipermail/c++-sig/2006-March/010458.html - seem > >> to tail off without a conclusion being made. I see that internally boost.python contains many references to shared_ptr, and I have confirmed through a number of tests that the identity problem appears to be solved if shared_ptrs are employed, unfortunately I'm in a position where I cannot change the C++ I'm > >> binding to use a different smart pointer type. > >> > >> Is there anything else I might try, or is this unfixable? > > > >I don't have enough knowledge to answer the question. > >It seems to me that you can create small work around: > >redefine store and retrieve function in Python, save the reference to the python > >object somewhere, next time user will ask to retrieve the object, you can return > >the object you stored earlier in Python. > > > > Thanks for your help. My pleasure. Do you mind if I will add the code you have posted in this thread to the web pages: http://language-binding.net/pyplusplus/bpl_lessons_learned/smart_ptrs/smart_ptrs.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mark at image-engine.com Fri Oct 27 21:49:00 2006 From: mark at image-engine.com (Mark Williams) Date: Fri, 27 Oct 2006 14:49:00 -0500 Subject: [C++-sig] Passing objects between python / c++ Message-ID: <2340.1161978540@image-engine.com> >> Thanks for your help. > >My pleasure. >Do you mind if I will add the code you have posted in this thread to the web >pages: >http://language-binding.net/pyplusplus/bpl_lessons_learned/smart_ptrs/smart_ptrs.html > That's fine - I've still yet to establish a workaround for his particular problem, though. Mark From seefeld at sympatico.ca Fri Oct 27 22:09:53 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 27 Oct 2006 16:09:53 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <871wotwn7r.fsf@pereiro.luannocracy.com> References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> <453FF60B.6000805@sympatico.ca> <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> <4540E4FE.4060203@sympatico.ca> <871wotwn7r.fsf@pereiro.luannocracy.com> Message-ID: <45426791.2080802@sympatico.ca> David Abrahams wrote: > Stefan Seefeld writes: > >> Beau Sapach wrote: >>> That seems to have worked, I manually added the BOOST_PYTHON_DECL macro to >>> the 4 files and now it links just fine. Thanks! Strangely though, my app >> Great ! David, is it OK for this patch (see previous mail) to be applied to >> both, HEAD, as well as the 1_34 branch ? >> > > I didn't see the previous email, but it seems inappropriate to think > about applying patches before so many mysteries (below) are cleared up. Well..., I don't think these mysteries are in any way related to the patch in question. (For your convenience, I've attached it again, given how small it is.) Rather, the patch looks like an oversight on my part, as I hadn't thought of Windows and DLL creation when I originally applied it. So, can you see any potential problem in the patch ? Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch URL: From dave at boost-consulting.com Fri Oct 27 21:57:34 2006 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 27 Oct 2006 15:57:34 -0400 Subject: [C++-sig] How to compile boost.python with '-fPIC' option References: Message-ID: <87wt6lv8ep.fsf@pereiro.luannocracy.com> "Grant Tang" writes: > I am trying to compile boost.python for a static libboost_python.a library, I need compile it > with -fPIC option, but in the Jamfile I can not figure out a way to add this option? > > Can somebody help me? Thx On the command-line with Boost.Build v1: bjam -sBUILD=-fPIC ...whatever.. or if you're using the CVS head, with Boost.Build v2: bjam --v2 cxxflags=-fPIC ...whatever... -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 27 21:52:24 2006 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 27 Oct 2006 15:52:24 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <4540E4FE.4060203@sympatico.ca> (Stefan Seefeld's message of "Thu, 26 Oct 2006 12:40:30 -0400") References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> <453FF60B.6000805@sympatico.ca> <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> <4540E4FE.4060203@sympatico.ca> Message-ID: <871wotwn7r.fsf@pereiro.luannocracy.com> Stefan Seefeld writes: > Beau Sapach wrote: >> That seems to have worked, I manually added the BOOST_PYTHON_DECL macro to >> the 4 files and now it links just fine. Thanks! Strangely though, my app > > Great ! David, is it OK for this patch (see previous mail) to be applied to > both, HEAD, as well as the 1_34 branch ? > I didn't see the previous email, but it seems inappropriate to think about applying patches before so many mysteries (below) are cleared up. >> can't link into the DLL at runtime unless it's in the same folder, even >> though the DLL is on the PATH and the LD_LIBRARY_PATH. And finally, the >> program is breaking within the first call to import: >> >> boost::python::object main = boost::python::import("__main__"); >> >> it breaks on: >> >> python::handle<> module(python::borrowed(PyImport_AddModule(n))); >> >> saying: >> >> Unhandled exception at 0x1e079547 in boostapp.exe: 0xC0000005: Access >> violation reading location 0x00000004. > > That's very strange. Can you run the boost.python test suite ? > I'd strongly suspect your build system / code to be the culprit, unless > you can prove the contrary. :-) > > (And yes: in order for anybody to be able to help you further a > test case is needed, making the failure reproducible, at least to > those who run boost on the same platform as you.) > > Regards, > Stefan > > > -- > > ...ich hab' noch einen Koffer in Berlin... > -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Oct 27 23:05:20 2006 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 27 Oct 2006 17:05:20 -0400 Subject: [C++-sig] Embedding... In-Reply-To: <45426791.2080802@sympatico.ca> (Stefan Seefeld's message of "Fri, 27 Oct 2006 16:09:53 -0400") References: <000201c6f6ce$0ff7c5f0$2fe751d0$@sapach@ualberta.ca> <453D1981.1050203@sympatico.ca> <000601c6f85a$181b3860$4851a920$@sapach@ualberta.ca> <453FA2D9.9040802@sympatico.ca> <000a01c6f86d$377201e0$a65605a0$@sapach@ualberta.ca> <453FC0DD.1050707@sympatico.ca> <000b01c6f87c$f6712080$e3536180$@sapach@ualberta.ca> <453FDB65.9030006@sympatico.ca> <000001c6f886$9ad42ba0$d07c82e0$@sapach@ualberta.ca> <453FF60B.6000805@sympatico.ca> <000001c6f91b$95cf93c0$c16ebb40$@sapach@ualberta.ca> <4540E4FE.4060203@sympatico.ca> <871wotwn7r.fsf@pereiro.luannocracy.com> <45426791.2080802@sympatico.ca> Message-ID: <87r6wtv59r.fsf@pereiro.luannocracy.com> Stefan Seefeld writes: > So, can you see any potential problem in the patch ? No; looks great; please go ahead. -- Dave Abrahams Boost Consulting www.boost-consulting.com From abierbaum at gmail.com Sat Oct 28 00:57:55 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Fri, 27 Oct 2006 17:57:55 -0500 Subject: [C++-sig] pointer_holder and pure virtual base classes In-Reply-To: <7465b6170609191041v52afa38fqba99519cbdc880af@mail.gmail.com> References: <7465b6170609191041v52afa38fqba99519cbdc880af@mail.gmail.com> Message-ID: Sorry to reply to an old e-mail, but I just got time to revisit this issue. See below... On 9/19/06, Roman Yakovenko wrote: > On 9/19/06, Allen Bierbaum wrote: > > This is a followup to my efforts in the thread here: > > http://thread.gmane.org/gmane.comp.python.c++/10125/focus=10125 > > > > I seemed to have everything working but I just ran into a new problem. > > A simplified summary is: > > > > class Base > > { > > public: > > int getSomething() = 0; > > }; > > > > class DerivedA : public Base > > { > > public: > > int getSomething() { return 1; } > > } > > > > class DerivedB : public DerivedA > > { > > public: > > int getSomething() { return 1; } > > } > > > > I am wrapping these classes with a held_type of RefPtr > > except for the Base class because it is pure virtual. (this is a > > custom ref counting pointer; see thread above for details) > > > > I thought everything was good until I tried to wrap a factory class. > > The class can return any class type but it returns it through a > > pointer to the Base class like this: > > > > class Store > > { > > public: > > RefPtr getObject(int id); > > }; > > > > The problem wrapping this is that since I do not have a held_type > > registered for the base type as RefPtr, there is no to_python > > (by-value) converter found for C++ type: RefPtr. > > > > As an attempt to fix this I set the held type for Base to > > RefPtr, but this fails because pointer_holder.hpp line 179 needs > > to be able to alloate an object of the pointee type. Since it is pure > > virtual the compiler fails here. > > > > So my question is, when dealing with a polymorphic hierarchy like this > > is is possible to use a smart pointer as a held type for the most > > basic types? (ie. the pure virtual base). If not, does anyone have > > suggested workarounds for me to try? > > David Abrahams solved this problem for my case. See "custom smart pointer" > thread. > > Basically you will have to set as HeldType RefPtr, where > BaseWrapper is a wrapper class, that defines "override" for pure > virtual functions. Unfortunately I can't do this. The smart pointers I am using are not quite standard, so I can't apply them easily to the wrapper. I did find another way to do it though that almost works... > Your smart pointer shoud support construction of RefPtr from > RefPtr. What I did was register a ptr_to_python for my base class RefPtr type. I also already had a to_python_converter registered for the type returned from the store (an FCPtr). So now with the ptr_to_python registered the path boost.python should be taking is: - I call the getObject method of the store which returns a FCPtr - A custom to_python converter gets called with returns a RefPtr >: "return bp::incref(bp::object(RefPtrType(fcPtr)).ptr());" - boost.python recognizes this type as a ptr because of a call I make to bp::register_ptr_to_python > >(); This all seems to work but I get a very strange error when trying to use an object returned through this path. Here is a sample run: >>> n = osg2.Node.create() >>> osg2.FieldContainerFactory.the().getContainer(osg2.getContainerId(n)) >>> n2 = osg2.FieldContainerFactory.the().getContainer(191) >>> n >>> n2 >>> n.getType() >>> n2.getType() Traceback (most recent call last): File "", line 1, in ? ArgumentError: Python argument types in Node.getType(Node) did not match C++ signature: getType(OSG::Node {lvalue}) getType(OSG::Node {lvalue}) As you can see, the n2 variable type looks like it converted to the correct type but it doesn't work. Does anyone have any ideas what I should be looking for here? Any ideas how I can trace it down? Thanks, Allen From shiqinfeng at gmail.com Sat Oct 28 13:27:53 2006 From: shiqinfeng at gmail.com (Qinfeng(Javen) Shi ) Date: Sat, 28 Oct 2006 21:27:53 +1000 Subject: [C++-sig] import_array() evokes illegal hardware instruction on MAC OS Message-ID: Dear All, I used import_array() in c extension of python wrapped by boost. It works well on linux. Then I recompiled it in MAC OS (by bjam) without any error. But when I imported it in python on MAC OS, it reported a error. It seems that import_array() evoked the error. If I delete import_array(), then import it, it won't report the error. But I need import_array() to handle numpy.array. Does anybody can help me? -------------------error------------------ >> import coverTree zsh: illegal hardware instruction -----------------c extension------------ namespace ar=boost::python::numeric; BOOST_PYTHON_MODULE(coverTree) { import_array(); //ar::array::set_module_and_type("numpy", "ndarray"); } -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -- Qinfeng(Javen) Shi Research School of Information Sciences and Engineering Australian National University Locked Bag 8001 Canberra ACT 2601 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Sun Oct 29 14:32:09 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 29 Oct 2006 08:32:09 -0500 Subject: [C++-sig] pointer_holder and pure virtual base classes References: <7465b6170609191041v52afa38fqba99519cbdc880af@mail.gmail.com> Message-ID: <87hcxncko6.fsf@pereiro.luannocracy.com> "Allen Bierbaum" writes: > Unfortunately I can't do this. The smart pointers I am using are not > quite standard In most cases that shouldn't make a difference; you can always overload get_pointer and specialize pointee<>. -- Dave Abrahams Boost Consulting www.boost-consulting.com From abierbaum at gmail.com Sun Oct 29 17:10:42 2006 From: abierbaum at gmail.com (Allen Bierbaum) Date: Sun, 29 Oct 2006 10:10:42 -0600 Subject: [C++-sig] pointer_holder and pure virtual base classes In-Reply-To: <87hcxncko6.fsf@pereiro.luannocracy.com> References: <7465b6170609191041v52afa38fqba99519cbdc880af@mail.gmail.com> <87hcxncko6.fsf@pereiro.luannocracy.com> Message-ID: On 10/29/06, David Abrahams wrote: > "Allen Bierbaum" writes: > > > Unfortunately I can't do this. The smart pointers I am using are not > > quite standard > > In most cases that shouldn't make a difference; you can always > overload get_pointer and specialize pointee<>. I will look into this some more, but the issue wasn't telling boost.python about the pointers it was the the class library I am wrapping expects certain things to be true about the classes that you use it's smart pointers with and what can be done with them. Because of this it doesn't end up as easy as just making the held type be a smart ptr to the wrapper class. Like I said though I will give it some more thought and see if there is anything that can be done here. In the meantime, can you help point me in the right direction to figure out what is happening here that makes it look like I am wrapping an object of the right type but instead end up with an object that can't call it's methods? I just haven't run into this before so I am more then a bit confused about what could cause it. Thanks, Allen From yardbird at nerdshack.com Mon Oct 30 12:49:18 2006 From: yardbird at nerdshack.com (yardbird) Date: Mon, 30 Oct 2006 12:49:18 +0100 Subject: [C++-sig] [boost::python] Unresolved overloaded function - methods with same name In-Reply-To: <7465b6170610271049m7874f94cqf7f8fc648f3a861c@mail.gmail.com> References: <200610271748.50943.yardbird@nerdshack.com> <7465b6170610271049m7874f94cqf7f8fc648f3a861c@mail.gmail.com> Message-ID: <200610301249.18636.yardbird@nerdshack.com> On Friday 27 October 2006 19:49, Roman Yakovenko wrote: > typedef int const& (Foo::*get_b_const_type) const; > > .def( "get_b", get_b_const_type( &Foo::get_b ) ); > > The idea is to use function type to specify to compiler what function > you want to export. > > I think you also will have to specify call policies: > return_value_policy< copy_const_reference > Yes, thank you very much, that worked ok :) Now I have to look a bit into those return value policies... Best regards and thanks again, Francesco From ngoodspeed at solidworks.com Mon Oct 30 15:18:32 2006 From: ngoodspeed at solidworks.com (Nat Goodspeed) Date: Mon, 30 Oct 2006 09:18:32 -0500 Subject: [C++-sig] ERROR:illegal hardware instruction on MAC OS when using import_array() Message-ID: <31E9B8A4BEFAA242B047A736B344578B303C54@corp-mail8.solidworks.swk> ________________________________________ > From: c++-sig-bounces at python.org > [mailto:c++-sig-bounces at python.org] On Behalf Of Qinfeng(Javen) Shi > Sent: Friday, October 27, 2006 2:25 AM > To: c++-sig at python.org > Cc: Kishor Gawande > Subject: [C++-sig] ERROR:illegal hardware instruction on MAC OS > when using import_array() > > I wrapped a c++ code which can receive numpy.array data in python > on linux. For that I used import_array() in c extension. It works > well on linux. Then I bjam it in MAC OS without any error. But > when I import it in python on MAC OS, it reports a error. It > seems that import_array() evoked the error. [Nat] I haven't used numpy, and this is not a problem with which I'm familiar. Just contributing a thought. Have you tried using py2app to build your extension on OS X? http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html I've used py2app, though I've never used its compilation feature: we've always built our extensions using Xcode. But it does claim to build C++ Python extensions using the right set of build options to allow Mac Python to import them. From david.toneian at gmail.com Tue Oct 31 19:28:50 2006 From: david.toneian at gmail.com (David Toneian) Date: Tue, 31 Oct 2006 19:28:50 +0100 Subject: [C++-sig] a question about embedding python in c++ Message-ID: hi, i would like to embed a scripting language in my (planned) c++ apps. i've found boost.python now, and it seems to be what i need. nevertheless, i'm still unsure whether i can do the follwoing with boost.python: (note that the python-related part is just pseudo-code, of course :> ) class someNumber { public: float x; someNumber() : x(0) {} }; class myClass { public: int a; someNumber* number; myClass() : a(0) {number=new someNumber();} ~myClass(){delete number;} void add(const int x) {a+=x;} }; void printHelloPython() { std::cout<<"hello python"; } int main() { myClass foobar(); revealFunctionToPython(&printHelloPython); revealClassToPython("someNumber"); revealClassToPython("myClass"); revealInstanceToPython(&foobar); runThatPythonScrip(); return foobar.a+foobar.number.x; } Where the python code sets a to 5 directly (something like foobar.a=5), calls printHelloPython(), sets the someNumber instance inside foobar to 1330 and then calls foobar.add(2). I'd expect an output of "hello python" and the returned result from main to be 1337. so, can i manipulate the c++ instance from within a python script? if i can't, is there a scripting language that i can embed in my application that is able to do the job? thank you, david From seefeld at sympatico.ca Tue Oct 31 19:32:50 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 31 Oct 2006 13:32:50 -0500 Subject: [C++-sig] a question about embedding python in c++ In-Reply-To: References: Message-ID: <454796D2.4010107@sympatico.ca> David Toneian wrote: > hi, > i would like to embed a scripting language in my (planned) c++ apps. > i've found boost.python now, and it seems to be what i need. > nevertheless, i'm still unsure whether i can do the follwoing with > boost.python: [...] > Where the python code sets a to 5 directly (something like > foobar.a=5), calls printHelloPython(), sets the someNumber instance > inside foobar to 1330 and then calls foobar.add(2). > I'd expect an output of "hello python" and the returned result from > main to be 1337. > > so, can i manipulate the c++ instance from within a python script? if Definitely ! Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From david.toneian at gmail.com Tue Oct 31 19:47:39 2006 From: david.toneian at gmail.com (David Toneian) Date: Tue, 31 Oct 2006 19:47:39 +0100 Subject: [C++-sig] a question about embedding python in c++ In-Reply-To: <454796D2.4010107@sympatico.ca> References: <454796D2.4010107@sympatico.ca> Message-ID: do i have to pass the instance to python and retrieve it again after script execution to make the changes take effect? for example, is it going to be like: givePythonThatInstancePlease(&someInstance); executeARandomScript(); someInstance=getTheInstanceBackAgain(); or is the last line not needed because python will have direct access to the instance? apropos direct access: is the python script manipulating the original instance or is there some copying needed? That would be kind of "bad" since one could not use classes with a lot of data in them or a lot of encapsulation for applications where time is crucial (like games).... oh, and sorry that i'm writing only pseudo-code, which may be quite far from what the real approach with boost.python will look like. i just didn't want to study the library functions and classes before i was sure it would be useful to me :) thanks for you fast answer (mailing lists seem to be quite cool, i'm new to this) From seefeld at sympatico.ca Tue Oct 31 20:01:12 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 31 Oct 2006 14:01:12 -0500 Subject: [C++-sig] a question about embedding python in c++ In-Reply-To: References: <454796D2.4010107@sympatico.ca> Message-ID: <45479D78.306@sympatico.ca> David Toneian wrote: > do i have to pass the instance to python and retrieve it again after > script execution to make the changes take effect? Yes, you can pass the instance by injecting it into the environment (the global dictionary with which you then call the script). Any calls on that from within the script will directly manipulate the wrapped C++ instance. But details depend on how to export the class' API via boost::python::class_<>. > for example, is it going to be like: > givePythonThatInstancePlease(&someInstance); > executeARandomScript(); > someInstance=getTheInstanceBackAgain(); > > or is the last line not needed because python will have direct access > to the instance? Yes, precisely. The instance will be manipulated in-situ. There is no copying involved. > oh, and sorry that i'm writing only pseudo-code, which may be quite > far from what the real approach with boost.python will look like. i > just didn't want to study the library functions and classes before i > was sure it would be useful to me :) Understood. Good luck ! Stefan -- ...ich hab' noch einen Koffer in Berlin... From david.toneian at gmail.com Tue Oct 31 20:07:13 2006 From: david.toneian at gmail.com (David Toneian) Date: Tue, 31 Oct 2006 20:07:13 +0100 Subject: [C++-sig] a question about embedding python in c++ In-Reply-To: <45479D78.306@sympatico.ca> References: <454796D2.4010107@sympatico.ca> <45479D78.306@sympatico.ca> Message-ID: Thank you very much :) On 10/31/06, Stefan Seefeld wrote: > David Toneian wrote: > > do i have to pass the instance to python and retrieve it again after > > script execution to make the changes take effect? > > Yes, you can pass the instance by injecting it into the environment > (the global dictionary with which you then call the script). Any > calls on that from within the script will directly manipulate the > wrapped C++ instance. But details depend on how to export the class' > API via boost::python::class_<>. > > > for example, is it going to be like: > > givePythonThatInstancePlease(&someInstance); > > executeARandomScript(); > > someInstance=getTheInstanceBackAgain(); > > > > or is the last line not needed because python will have direct access > > to the instance? > > Yes, precisely. The instance will be manipulated in-situ. There is no > copying involved. > > > oh, and sorry that i'm writing only pseudo-code, which may be quite > > far from what the real approach with boost.python will look like. i > > just didn't want to study the library functions and classes before i > > was sure it would be useful to me :) > > Understood. > > Good luck ! > > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig >