From markus at relix.de Tue Aug 1 02:23:09 2006 From: markus at relix.de (Markus Heller) Date: Tue, 1 Aug 2006 02:23:09 +0200 Subject: [C++-sig] Working with python unicode strings without wstring In-Reply-To: <7465b6170607311127y1d5f6962l4c2dd662146b8eb7@mail.gmail.com> References: <200607311933.51670.markus@relix.de> <7465b6170607311127y1d5f6962l4c2dd662146b8eb7@mail.gmail.com> Message-ID: <200608010223.09974.markus@relix.de> Dear Roman, > May be you should use another set of API? > http://docs.python.org/api/unicodeObjects.html Thanks for your advice. I'm just reading the documentation :-) > It is also possible that your locale is wrong. So what is the influence of the locale setting (here: de_DE at euro) on the interpretation of a German umlaut character? Python gets it right, only the handover to the C++ std::string variable crashes. Regards Markus From mharidev at qualcomm.com Tue Aug 1 03:01:36 2006 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Mon, 31 Jul 2006 18:01:36 -0700 Subject: [C++-sig] Pyplusplus: Removing generation of bp::implicitly_convertible code? Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA880167CDFF@NAEX11.na.qualcomm.com> I'm using pyplusplus to generate boost.python wrappers for the following piece of code: //test.h class Y { }; class X { public: X(const Y *yptr = 0){ } }; Pyplusplus generates the corresponding boost.python code for it: // This file has been generated by pyplusplus. #include "boost/python.hpp" #include "test.h" namespace bp = boost::python; BOOST_PYTHON_MODULE(TEST){ bp::class_< Y >( "Y" ); bp::class_< X >( "X", bp::init< bp::optional< Y const * > >(( bp::arg("yptr")=bp::object() )) ); bp::implicitly_convertible< Y const *, X >(); } Two Questions: ---------------------- Question 1: How can I make pyplusplus to NOT generate the implicitly convertible boost code? I do not want to take advantage of the conversion facility. Basically, I want the pyplusplus generated code to look like this: BOOST_PYTHON_MODULE(TEST){ bp::class_< Y >( "Y" ); bp::class_< X >( "X", bp::init< bp::optional< Y const * > >(( bp::arg("yptr")=bp::object() )) ); //bp::implicitly_convertible< Y const *, X >(); - Do not want to generate } ----- OR ------ Question 2: Is there any way I can expose only the default no-arg constructor for class X i.e X( ) and not expose the constructor X(const Y *yptr = 0)? That is, expose class X as: bp::class_< X >( "X", bp::init< >( ) ). That would automatically take care of not generating the bp::implicitly_convertible code also. Generated code should look like this: BOOST_PYTHON_MODULE(TEST){ bp::class_< Y >( "Y" ); bp::class_< X >( "X", bp::init< >( ) ); //Expose just default constructor //bp::implicitly_convertible< Y const *, X >(); - Will not be generated } I also tried excluding constructors for class X, but it excludes all the constructors. I want to be able to select and just exclude the X(const Y *yptr = 0) constructor. Is it possible to selectively exclude constructors from being exposed to C++ using pyplusplus? Thanks, -Meghana. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Aug 1 08:17:39 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Aug 2006 09:17:39 +0300 Subject: [C++-sig] Working with python unicode strings without wstring In-Reply-To: <200608010223.09974.markus@relix.de> References: <200607311933.51670.markus@relix.de> <7465b6170607311127y1d5f6962l4c2dd662146b8eb7@mail.gmail.com> <200608010223.09974.markus@relix.de> Message-ID: <7465b6170607312317y7be98c4fh87d650a74e0589ce@mail.gmail.com> On 8/1/06, Markus Heller wrote: > Dear Roman, > > > May be you should use another set of API? > > http://docs.python.org/api/unicodeObjects.html > Thanks for your advice. I'm just reading the documentation :-) > > > It is also possible that your locale is wrong. > So what is the influence of the locale setting (here: de_DE at euro) on the > interpretation of a German umlaut character? Python gets it right, only the > handover to the C++ std::string variable crashes. I could be wrong, but it seems to me that default C++ locale is C locale, and it treats only ASCII characters. So, may be you need to set global locale to the right one? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Aug 1 08:37:02 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Aug 2006 09:37:02 +0300 Subject: [C++-sig] Pyplusplus: Removing generation of bp::implicitly_convertible code? In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA880167CDFF@NAEX11.na.qualcomm.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA880167CDFF@NAEX11.na.qualcomm.com> Message-ID: <7465b6170607312337j86a4bdfi9e767165c2a4186b@mail.gmail.com> On 8/1/06, Haridev, Meghana wrote: > I'm using pyplusplus to generate boost.python wrappers for the following > piece of code: > > //test.h > class Y > { }; > class X > { > public: > X(const Y *yptr = 0){ } > }; > Pyplusplus generates the corresponding boost.python code for it: > > // This file has been generated by pyplusplus. > #include "boost/python.hpp" > #include "test.h" > namespace bp = boost::python; > BOOST_PYTHON_MODULE(TEST){ > bp::class_< Y >( "Y" ); > bp::class_< X >( "X", bp::init< bp::optional< Y const * > >(( > bp::arg("yptr")=bp::object() )) ); > bp::implicitly_convertible< Y const *, X >(); > } > Two Questions: > > ---------------------- > > Question 1: How can I make pyplusplus to NOT generate the implicitly > convertible boost code? I do not want to take advantage of the conversion > facility. Basically, I want the pyplusplus generated code to look like this: mb = module_builder_t( ... ) mb.build_code_creator( ..., create_castinig_constructor=False, ... ) > > Question 2: Is there any way I can expose only the default no-arg > constructor for class X i.e X( ) and not expose the constructor X(const Y > *yptr = 0)? That is, expose class X as: bp::class_< X >( "X", bp::init< >( ) > ). That would automatically take care of not generating the > bp::implicitly_convertible code also. Generated code should look like this: > > BOOST_PYTHON_MODULE(TEST){ > > bp::class_< Y >( "Y" ); > > bp::class_< X >( "X", bp::init< >( ) ); //Expose just default > constructor > > //bp::implicitly_convertible< Y const *, X >(); - Will not be generated > > } > > I also tried excluding constructors for class X, but it excludes all the > constructors. I want to be able to select and just exclude the X(const Y > *yptr = 0) constructor. Is it possible to selectively exclude constructors > from being exposed to C++ using pyplusplus? Class X does not have empty constructor. I assume that it has. Before you read my explanation, please read this tutorials: http://language-binding.net/pygccxml/query_interface.html from pygccxml import declarations mb = module_builder_t( ... ) def criteria( constructor ): if len( constructor.arguments ) != 1: return False arg0_type = constructor.arguments[0].type if not declarations.is_pointer( arg0_type ): return tmp = declarations.remove_pointer( arg0_type ): if not declarations.is_const( tmp ): return False return declarations.is_same( declarations.remove_const( tmp ), mb.class_( "Y" ) ) X = mb.class_( "X" ) constructor_from_Y = X.constructor( criteria ) Ther is another approach. constructor_from_Y = X.constructor( args_type=[ "Y const *" ] ) -----------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This query will return constructor, that takes 1 argument "Y const *". The problem with this approach is that this string should be equal to arg0.type.decl_string. And third approach it to select all constructors that take 1 argument: cs = X.constructors( [None] ) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From j.reid at mail.cryst.bbk.ac.uk Tue Aug 1 10:49:59 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 01 Aug 2006 09:49:59 +0100 Subject: [C++-sig] Boost.Python shared_ptr container gotchas Message-ID: Hi, I use boost::shared_ptr to manage lifetimes of objects. I've run into a couple of problems using these inside containers with Boost.Python. I thought I could share my experiences and perhaps get some useful feedback or help others avoid these problems. 1) Exposing a vector< shared_ptr< T > > through the indexing suite was giving me headaches. I couldn't work out why I couldn't access the elements from python. I kept getting a runtime error about no python class for boost::shared_ptr< T > even after I was registering the pointer type. It turns out that my problem was the vector indexing suite was trying to wrap a reference to the boost::shared_ptr< T > in a python object. I needed to set the NoProxy template parameter on vector_indexing_suite to true and that solved all those issues. Once I understood what was happening the answer was clear. Until that moment there was a lot of head-scratching. The documentation is factually comprehensive but I wonder whether it couldn't have more use cases that explain why certain things are necessary. 2) This was a slightly more insidious problem. I also use the shared_ptrs as keys in associative containers. I ensure that equal objects are always identical (i.e. share the same address) so that I can just compare addresses rather than contents. The trouble was that operator< for shared_ptrs seemed to be comparing more than just the address of the pointee. If a shared_ptr made a round trip through python and back again it would not be equal (not greater nor less than) to the original shared_ptr under the operator< relationship. I fixed this by changing the ordering on my map to: struct smart_ptr_less_than { template< typename T > bool operator()( T p1, T p2 ) const { return p1.get() < p2.get(); } }; AFAIK this is defines a valid weak ordering. I'm not sure why operator< on shared_ptrs is not defined like this. Something to do with the deleter stored for shared_ptrs perhaps? I hope this proves useful to someone or that I can be corrected and learn something in the process. Regards, John. From roman.yakovenko at gmail.com Tue Aug 1 11:16:08 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Aug 2006 12:16:08 +0300 Subject: [C++-sig] Boost.Python shared_ptr container gotchas In-Reply-To: References: Message-ID: <7465b6170608010216h794cc164re96a6ceaef6e1e60@mail.gmail.com> On 8/1/06, John Reid wrote: > Hi, > > I use boost::shared_ptr to manage lifetimes of objects. I've run into a > couple of problems using these inside containers with Boost.Python. I > thought I could share my experiences and perhaps get some useful > feedback or help others avoid these problems. > > 1) Exposing a vector< shared_ptr< T > > through the indexing suite was > giving me headaches. I couldn't work out why I couldn't access the > elements from python. I kept getting a runtime error about no python > class for boost::shared_ptr< T > even after I was registering the > pointer type. It turns out that my problem was the vector indexing suite > was trying to wrap a reference to the boost::shared_ptr< T > in a python > object. I needed to set the NoProxy template parameter on > vector_indexing_suite to true and that solved all those issues. Once I > understood what was happening the answer was clear. Until that moment > there was a lot of head-scratching. The documentation is factually > comprehensive but I wonder whether it couldn't have more use cases that > explain why certain things are necessary. For next code: struct item{}; std::vector< boost::shared_ptr< item > > get_items(){ return std::vector< boost::shared_ptr< item > >(); } pyplusplus will generate next registration code for the vector: bp::vector_indexing_suite< ::std::vector, std::allocator > >, true >() Do you see "true" at the end? :-) pyplusplus tries to help a user as much as it can. It can serve as a user guide and as an inspector: http://tinyurl.com/mbd4r ( development version ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From j.reid at mail.cryst.bbk.ac.uk Tue Aug 1 11:59:48 2006 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 01 Aug 2006 10:59:48 +0100 Subject: [C++-sig] Boost.Python shared_ptr container gotchas In-Reply-To: <7465b6170608010216h794cc164re96a6ceaef6e1e60@mail.gmail.com> References: <7465b6170608010216h794cc164re96a6ceaef6e1e60@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > pyplusplus will generate next registration code for the vector: > > bp::vector_indexing_suite< ::std::vector, > std::allocator > >, true >() > > Do you see "true" at the end? :-) > > pyplusplus tries to help a user as much as it can. It can serve as a > user guide and > as an inspector: http://tinyurl.com/mbd4r ( development version ). > That sounds good to me. I did try to use pyplusplus but setting up gccxml on my windows box proved to be such a headache I gave up and went back to Boost.Python. I will probably try in the future when I have more time. It wasn't clear from the pyplusplus documentation which version of gccxml was required. Also I forgot to mention in my first post that I think Boost.Python is a fantastic library overall. I don't just want to mention the problems I've had. :-) John. From roman.yakovenko at gmail.com Tue Aug 1 12:22:11 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Aug 2006 13:22:11 +0300 Subject: [C++-sig] Boost.Python shared_ptr container gotchas In-Reply-To: References: <7465b6170608010216h794cc164re96a6ceaef6e1e60@mail.gmail.com> Message-ID: <7465b6170608010322r6b8bf4bcu8bb0e87817368b28@mail.gmail.com> On 8/1/06, John Reid wrote: > Roman Yakovenko wrote: > > pyplusplus will generate next registration code for the vector: > > > > bp::vector_indexing_suite< ::std::vector, > > std::allocator > >, true >() > > > > Do you see "true" at the end? :-) > > > > pyplusplus tries to help a user as much as it can. It can serve as a > > user guide and > > as an inspector: http://tinyurl.com/mbd4r ( development version ). > > > > That sounds good to me. I did try to use pyplusplus but setting up > gccxml on my windows box proved to be such a headache I gave up and went > back to Boost.Python. I will probably try in the future when I have more > time. It wasn't clear from the pyplusplus documentation which version of > gccxml was required. I can help you with that. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From sbalasub at qualcomm.com Wed Aug 2 05:27:24 2006 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Tue, 1 Aug 2006 20:27:24 -0700 Subject: [C++-sig] Problem exposing templates Message-ID: Hi, I have installed the latest cvs version of gccxml, pyplusplus, pygccxml I am attaching the code to this mail that has the problem. Files: Stack.h: Has the class template BP_Stack.cpp Contains the boost.python code generated by py++ Sconstruct-lib: Builds the stack library Sconstruct: Builds the boost-python-stack library <> <> <> <> <> The compilation fails at line number 29 and 40. The problem the functional definition generated with "_GLOBAL__I_Stack.h****** { //::_GLOBAL__D_Stack.hLZJ4nd typedef void ( *function_ptr_t )( ); bp::def( "_GLOBAL__D_Stack.hLZJ4nd" , function_ptr_t( &::_GLOBAL__D_Stack.hLZJ4nd ) , bp::default_call_policies() ); } { //::_GLOBAL__I_Stack.hLZJ4nd typedef void ( *function_ptr_t )( ); bp::def( "_GLOBAL__I_Stack.hLZJ4nd" , function_ptr_t( &::_GLOBAL__I_Stack.hLZJ4nd ) , bp::default_call_policies() ); } Is there any ways else to explicitly instantiate the template? The class compiles and runs fine if I remove those two declarations. Thanks, Shiva -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: genCode.py Type: application/octet-stream Size: 808 bytes Desc: genCode.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: sconstruct Type: application/octet-stream Size: 318 bytes Desc: sconstruct URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: sconstruct-lib Type: application/octet-stream Size: 149 bytes Desc: sconstruct-lib URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Stack.h Type: application/octet-stream Size: 656 bytes Desc: Stack.h URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: BP_Stack.cpp Type: application/octet-stream Size: 1241 bytes Desc: BP_Stack.cpp URL: From roman.yakovenko at gmail.com Wed Aug 2 07:02:04 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 2 Aug 2006 08:02:04 +0300 Subject: [C++-sig] Problem exposing templates In-Reply-To: References: Message-ID: <7465b6170608012202ne6bf42bhc6f80832ef368cdb@mail.gmail.com> On 8/2/06, Balasubramanyam, Shivakumar wrote: > Hi, Good morning. > Is there any ways else to explicitly instantiate the template? Yes, you can write C++ code that uses that functions and feed it to gccxml. P.S. Also gccxml is involved in the process it has nothing to do with the problem: http://gccxml.org/HTML/FAQ.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jan at langernetz.de Wed Aug 2 15:28:56 2006 From: jan at langernetz.de (Jan Langer) Date: Wed, 02 Aug 2006 15:28:56 +0200 Subject: [C++-sig] [boost.python] conversion between string and unsigned char * Message-ID: Hello, I have a library I want to expose to python by using boost.python and pyplusplus. This library works completely with unsigned char * for strings. My current approach is // library typedef unsigned char * StringT; StringT F_ApiGetString (F_ObjHandleT docId, F_ObjHandleT objId, IntT propNum); // boost.python code struct StringT_converter { static PyObject *convert (StringT s) { return bp::incref (bp::str (reinterpret_cast (s)).ptr ()); } }; BOOST_PYTHON_MODULE(pyfdk){ bp::to_python_converter (); bp::def("F_ApiGetString" , &::F_ApiGetString , ( bp::arg("arg0"), bp::arg("arg1"), bp::arg("arg2") ) , bp::return_value_policy< bp::return_by_value, bp::default_call_policies >() ); } But somehow it does not work: TypeError: No to_python (by-value) converter found for C++ type: char Actually, I must free the memory of the returned StringT, but I am not sure if I can savely change the converter like this: struct StringT_converter { static PyObject *convert (StringT s) { PyObject *p = bp::incref (bp::str (reinterpret_cast (s)).ptr ()); F_ApiDeallocate(s); return p; } }; I hope someone can help me. Thanks, Jan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: From jan at langernetz.de Wed Aug 2 15:42:11 2006 From: jan at langernetz.de (Jan Langer) Date: Wed, 02 Aug 2006 15:42:11 +0200 Subject: [C++-sig] Pyplusplus - anonymous union In-Reply-To: <7465b6170607201021j2ff8e92cy154d70e95c565455@mail.gmail.com> References: <7465b6170607201021j2ff8e92cy154d70e95c565455@mail.gmail.com> Message-ID: Roman Yakovenko wrote: >>I'm using pyplusplus to generate python-bindings for a C API. > > mb = module_builder_t( ... ) > #The code in subversion does it for you > mb.classes( name='' ).exclude() > > Next code is copied from Python-OGRE bindings: > > [...] > > This should work. > > P.S. You project is 3rd project that need this feature, may be this is a time > to implement it :-) Thank you. Actually this behavior does not work like I want, but gave me more insight into the workings of pyplusplus. I now use a different strategy. First, I generate a union wrapper to give the anonymous union a name. Then, I provide getter and setter functions for each union member and getter/setter for the union itself. The access to the union members and the union is then accomplished by the .add_property calls. I paste the relevant boost.python code below. However, I omit the pyplusplus code, but in case someone is interested I can send it, too. Jan //------------------------------------------------- // library code typedef struct { IntT offset; IntT dataType; union { StringT sdata; IntT idata; } u; } F_TextItemT; // boost.python code union F_TextItemT_union { StringT sdata; IntT idata; }; StringT get_F_TextItemT_union_sdata (union_wrapper const &t) { return t.u.sdata; } void set_F_TextItemT_union_sdata (union_wrapper &t, StringT const &v) { t.u.sdata = v; } IntT get_F_TextItemT_union_idata (union_wrapper const &t) { return t.u.idata; } void set_F_TextItemT_union_idata (union_wrapper &t, IntT const &v) { t.u.idata = v; } union_wrapper get_F_TextItemT_u (F_TextItemT const &t) { union_wrapper uw; assert(sizeof(uw.u) == sizeof(uw.u)); std::memcpy(&uw.u,&t.u,sizeof(uw.u)); return uw; } void set_F_TextItemT_u (F_TextItemT &t, union_wrapper const &uw) { assert(sizeof(uw.u) == sizeof(t.u)); std::memcpy(&t.u,&uw.u,sizeof(uw.u)); } BOOST_PYTHON_MODULE(pyfdk){ if( true ){ typedef bp::class_< F_TextItemT > F_TextItemT_exposer_t; F_TextItemT_exposer_t F_TextItemT_exposer = F_TextItemT_exposer_t( "F_TextItemT" ); bp::scope F_TextItemT_scope( F_TextItemT_exposer ); bp::class_ > ("F_TextItemT_union") .add_property ("sdata", bp::make_function (&get_F_TextItemT_union_sdata,bp::return_value_policy ()), &set_F_TextItemT_union_sdata) .add_property ("idata", bp::make_function (&get_F_TextItemT_union_idata,bp::return_value_policy ()), &set_F_TextItemT_union_idata) ; F_TextItemT_exposer.def_readwrite( "offset", &F_TextItemT::offset ); F_TextItemT_exposer.def_readwrite( "dataType", &F_TextItemT::dataType ); F_TextItemT_exposer.add_property("u", &get_F_TextItemT_u, &set_F_TextItemT_u); } } -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: From mkirk at pdi.com Wed Aug 2 18:32:35 2006 From: mkirk at pdi.com (Mark Kirk) Date: Wed, 2 Aug 2006 16:32:35 +0000 (UTC) Subject: [C++-sig] wrapping abstract bases whose virtual functions should *not* be overridden in Python Message-ID: Hi... I'm using using boost::python for the first time to wrap a C++ lib. I'm extremely impressed with it, and I offer a warm thank-you to Dave and others on the boost::python team for creating it. I've been working with it for a couple of days, and I've read the tutorial and other bits of the Boost docs; I think most of it has sunk in. However, I'm having trouble with something: I have an abstract base class (one+ pure virtuals). I do *not* want any of these virtual functions overridden from within Python; I'm quite happy with the implementations in the C++ derived classes. This is an in-house lib, and the C++ implementation is and should remain the canonical implementation. In the docs, there are a couple of sections which address abstract bases ("Class Virtual Functions" subsection in the tutorial and the wrapper.hpp docs). Both state the procedure outlined is for wrapping bases for which you wish the ability to override the virtuals from *within* Python. Again, I explicitly do *not* want this ability. So, how do I correctly wrap my abstract base? I get errors complaining about the the virtual functions being abstract. Must I still use the wrapper<> procedure in my situation? If so, how do I prevent overriding of my virtuals in Python? Or, is there another way entirely? Thanks for your help, and let me know if you need clarification. mark From roman.yakovenko at gmail.com Wed Aug 2 19:26:55 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 2 Aug 2006 20:26:55 +0300 Subject: [C++-sig] Pyplusplus - anonymous union In-Reply-To: References: <7465b6170607201021j2ff8e92cy154d70e95c565455@mail.gmail.com> Message-ID: <7465b6170608021026i7fa376a7lcf2d99e984cb4ecd@mail.gmail.com> On 8/2/06, Jan Langer wrote: > Roman Yakovenko wrote: > >>I'm using pyplusplus to generate python-bindings for a C API. > > > > mb = module_builder_t( ... ) > > #The code in subversion does it for you > > mb.classes( name='' ).exclude() > > > > Next code is copied from Python-OGRE bindings: > > > > [...] > > > > This should work. > > > > P.S. You project is 3rd project that need this feature, may be this is a time > > to implement it :-) > > Thank you. Actually this behavior does not work like I want, but gave me > more insight into the workings of pyplusplus. I now use a different > strategy. First, I generate a union wrapper to give the anonymous union > a name. Then, I provide getter and setter functions for each union > member and getter/setter for the union itself. The access to the union > members and the union is then accomplished by the .add_property calls. I > paste the relevant boost.python code below. However, I omit the > pyplusplus code, but in case someone is interested I can send it, too. > > Jan > > //------------------------------------------------- > // library code > > typedef struct > { > IntT offset; > IntT dataType; > union { > StringT sdata; > IntT idata; > } u; > } F_TextItemT; > > // boost.python code > > union F_TextItemT_union > { > StringT sdata; > IntT idata; > }; > > StringT get_F_TextItemT_union_sdata (union_wrapper > const &t) > { > return t.u.sdata; > } > void set_F_TextItemT_union_sdata (union_wrapper &t, > StringT const &v) > { > t.u.sdata = v; > } > > IntT get_F_TextItemT_union_idata (union_wrapper > const &t) > { > return t.u.idata; > } > void set_F_TextItemT_union_idata (union_wrapper &t, > IntT const &v) > { > t.u.idata = v; > } > > union_wrapper get_F_TextItemT_u (F_TextItemT const &t) > { > union_wrapper uw; > assert(sizeof(uw.u) == sizeof(uw.u)); > std::memcpy(&uw.u,&t.u,sizeof(uw.u)); > return uw; > } > void set_F_TextItemT_u (F_TextItemT &t, union_wrapper > const &uw) > { > assert(sizeof(uw.u) == sizeof(t.u)); > std::memcpy(&t.u,&uw.u,sizeof(uw.u)); > } > > BOOST_PYTHON_MODULE(pyfdk){ > if( true ){ > typedef bp::class_< F_TextItemT > F_TextItemT_exposer_t; > F_TextItemT_exposer_t F_TextItemT_exposer = > F_TextItemT_exposer_t( "F_TextItemT" ); > bp::scope F_TextItemT_scope( F_TextItemT_exposer ); > bp::class_ > > ("F_TextItemT_union") > .add_property ("sdata", > bp::make_function > (&get_F_TextItemT_union_sdata,bp::return_value_policy > ()), > &set_F_TextItemT_union_sdata) > .add_property ("idata", > bp::make_function > (&get_F_TextItemT_union_idata,bp::return_value_policy > ()), > &set_F_TextItemT_union_idata) > ; > F_TextItemT_exposer.def_readwrite( "offset", &F_TextItemT::offset ); > F_TextItemT_exposer.def_readwrite( "dataType", > &F_TextItemT::dataType ); > F_TextItemT_exposer.add_property("u", > &get_F_TextItemT_u, > &set_F_TextItemT_u); > } > } > Cool! Can you post pyplusplus code? I will create a FAQ entry. Thank you -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Wed Aug 2 19:35:20 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 2 Aug 2006 20:35:20 +0300 Subject: [C++-sig] wrapping abstract bases whose virtual functions should *not* be overridden in Python In-Reply-To: References: Message-ID: <7465b6170608021035s3b582d53h88472908776ac993@mail.gmail.com> On 8/2/06, Mark Kirk wrote: > Hi... > > I have an abstract base class (one+ pure virtuals). I do *not* want any of > these virtual functions overridden from within Python; I'm quite happy with the > implementations in the C++ derived classes. This is an in-house lib, and the > C++ implementation is and should remain the canonical implementation. In the > docs, there are a couple of sections which address abstract bases ("Class > Virtual Functions" subsection in the tutorial and the wrapper.hpp docs). Both > state the procedure outlined is for wrapping bases for which you wish the > ability to override the virtuals from *within* Python. Again, I explicitly do > *not* want this ability. > So, how do I correctly wrap my abstract base? I get errors complaining about > the the virtual functions being abstract. Must I still use the wrapper<> > procedure in my situation? If No. I think you can just say that class could not be created( no_init ) http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jan at langernetz.de Wed Aug 2 20:06:08 2006 From: jan at langernetz.de (Jan Langer) Date: Wed, 02 Aug 2006 20:06:08 +0200 Subject: [C++-sig] Pyplusplus - anonymous union In-Reply-To: <7465b6170608021026i7fa376a7lcf2d99e984cb4ecd@mail.gmail.com> References: <7465b6170607201021j2ff8e92cy154d70e95c565455@mail.gmail.com> <7465b6170608021026i7fa376a7lcf2d99e984cb4ecd@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On 8/2/06, Jan Langer wrote: >>Roman Yakovenko wrote: >>>>I'm using pyplusplus to generate python-bindings for a C API. >>> >>>mb = module_builder_t( ... ) >>>#The code in subversion does it for you >>>mb.classes( name='' ).exclude() >>> >>>Next code is copied from Python-OGRE bindings: >>> >>>[...] >>> >>>This should work. >>> >>>P.S. You project is 3rd project that need this feature, may be this is a time >>>to implement it :-) >> >>Thank you. Actually this behavior does not work like I want, but gave me >>more insight into the workings of pyplusplus. I now use a different >>strategy. First, I generate a union wrapper to give the anonymous union >>a name. Then, I provide getter and setter functions for each union >>member and getter/setter for the union itself. The access to the union >>members and the union is then accomplished by the .add_property calls. I >>paste the relevant boost.python code below. However, I omit the >>pyplusplus code, but in case someone is interested I can send it, too. > > [...] > > Cool! Can you post pyplusplus code? I will create a FAQ entry. Hello Roman, actually, I am not very happy with my code, because I probably do many things not the right pyplusplus way and not even the right (safe) c++ way (see my other post today). Anyway, I attached the script and I think I don't need to explain in further detail :-[. The std::memcpy part of it works for this library, but it probably does not for other more advanced libraries. In case it is relevant, I am trying to wrap the FrameMaker FDK library. The union_wrapper.hpp file basically just contains the following code: template struct union_wrapper { typedef Union union_type; Union u; }; -------------- next part -------------- A non-text attachment was scrubbed... Name: build.py Type: application/x-python Size: 9583 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: From sbalasub at qualcomm.com Thu Aug 3 02:43:56 2006 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Wed, 2 Aug 2006 17:43:56 -0700 Subject: [C++-sig] [GCC-XML] (__GLOBAL function was Problem exposing templates) In-Reply-To: <7465b6170608012202ne6bf42bhc6f80832ef368cdb@mail.gmail.com> Message-ID: >-----Original Message----- >From: gccxml-bounces+sbalasub=qualcomm.com at gccxml.org [mailto:gccxml- >bounces+sbalasub=qualcomm.com at gccxml.org] On Behalf Of Roman Yakovenko >Sent: Tuesday, August 01, 2006 10:02 PM >To: Development of Python/C++ integration >Cc: gccxml at gccxml.org >Subject: [GCC-XML] Re: [C++-sig] Problem exposing templates > >On 8/2/06, Balasubramanyam, Shivakumar wrote: >> Hi, > >Good morning. > >> Is there any ways else to explicitly instantiate the template? > >Yes, you can write C++ code that uses that functions and feed it to gccxml. > >P.S. Also gccxml is involved in the process it has nothing to do with >the problem: >http://gccxml.org/HTML/FAQ.html [shiva] Roman, I understood the second part of my question, which was using typedef for explicit instantiation. Now I declared using "typedef Stack::Stack Stack_Int;" I still see pyplusplus generate the _GLOBAL function (see below) which results in compilation error? { //::_GLOBAL__D_Stack.hLZJ4nd typedef void ( *function_ptr_t )( ); bp::def( "_GLOBAL__D_Stack.hLZJ4nd" , function_ptr_t( &::_GLOBAL__D_Stack.hLZJ4nd ) , bp::default_call_policies() ); } { //::_GLOBAL__I_Stack.hLZJ4nd typedef void ( *function_ptr_t )( ); bp::def( "_GLOBAL__I_Stack.hLZJ4nd" , function_ptr_t( &::_GLOBAL__I_Stack.hLZJ4nd ) , bp::default_call_policies() ); } Thanks, Shiva From roman.yakovenko at gmail.com Thu Aug 3 06:51:02 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 3 Aug 2006 07:51:02 +0300 Subject: [C++-sig] [GCC-XML] (__GLOBAL function was Problem exposing templates) In-Reply-To: References: <7465b6170608012202ne6bf42bhc6f80832ef368cdb@mail.gmail.com> Message-ID: <7465b6170608022151o704a3cabna565cc798b2ff74a@mail.gmail.com> On 8/3/06, Balasubramanyam, Shivakumar wrote: > [shiva] Roman, I understood the second part of my question, which was > using typedef for explicit instantiation. > > Now I declared using "typedef Stack::Stack Stack_Int;" This does not couse to template instantiation. Please write: Stack_Int s; Also I will fix py++ to skip those declarations -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From bjorn at 4roald.org Thu Aug 3 07:34:55 2006 From: bjorn at 4roald.org (=?ISO-8859-1?Q?Bj=F8rn_Roald?=) Date: Thu, 03 Aug 2006 07:34:55 +0200 Subject: [C++-sig] [GCC-XML] (__GLOBAL function was Problem exposing templates) In-Reply-To: <7465b6170608022151o704a3cabna565cc798b2ff74a@mail.gmail.com> References: <7465b6170608012202ne6bf42bhc6f80832ef368cdb@mail.gmail.com> <7465b6170608022151o704a3cabna565cc798b2ff74a@mail.gmail.com> Message-ID: <44D18AFF.7060903@4roald.org> Roman Yakovenko wrote: > On 8/3/06, Balasubramanyam, Shivakumar wrote: >> [shiva] Roman, I understood the second part of my question, which was >> using typedef for explicit instantiation. >> >> Now I declared using "typedef Stack::Stack Stack_Int;" > > This does not couse to template instantiation. > > Please write: > > Stack_Int s; Why do you need the typdef? Stack::Stack Stack_Int; Should do it! Or am I missing some other purpose of the typedef? Bjorn From roman.yakovenko at gmail.com Thu Aug 3 13:20:12 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 3 Aug 2006 14:20:12 +0300 Subject: [C++-sig] [boost.python] conversion between string and unsigned char * In-Reply-To: References: Message-ID: <7465b6170608030420p36156610n4c525ec931f100f0@mail.gmail.com> On 8/2/06, Jan Langer wrote: > Hello, > I have a library I want to expose to python by using boost.python and > pyplusplus. This library works completely with unsigned char * for > strings. My current approach is > > // library > > typedef unsigned char * StringT; > StringT F_ApiGetString (F_ObjHandleT docId, F_ObjHandleT objId, IntT > propNum); > > // boost.python code > > struct StringT_converter > { > static PyObject *convert (StringT s) > { > return bp::incref (bp::str (reinterpret_cast (s)).ptr ()); > } > }; > > BOOST_PYTHON_MODULE(pyfdk){ > bp::to_python_converter (); I think this line does not do what you expect. You are trying to register custom converter for C++ fundamental type. I could be wrong, but it seems to me that boost.python uses different approach ( type conversion ) when it comes to fundamental C++ types. If I right, than pyplusplus can help you. 1. For every function, that uses StringT generate small wrapper, replacing StringT with std::string or custom string class( http://boost.org/libs/python/doc/v2/faq.html#custom_string ) 2. Export those wrappers. Consider to run pyplusplus on generated files, instead of adding code to the module builder. > I hope someone can help me. Does it help? > Thanks, > Jan -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jan at langernetz.de Thu Aug 3 17:21:33 2006 From: jan at langernetz.de (Jan Langer) Date: Thu, 03 Aug 2006 17:21:33 +0200 Subject: [C++-sig] [boost.python] conversion between string and unsigned char * In-Reply-To: <7465b6170608030420p36156610n4c525ec931f100f0@mail.gmail.com> References: <7465b6170608030420p36156610n4c525ec931f100f0@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On 8/2/06, Jan Langer wrote: >>I have a library I want to expose to python by using boost.python and >>pyplusplus. This library works completely with unsigned char * for >>strings. My current approach is >> >>// library >> >>typedef unsigned char * StringT; >>StringT F_ApiGetString (F_ObjHandleT docId, F_ObjHandleT objId, IntT >>propNum); >> >>// boost.python code >> >>struct StringT_converter >>{ >> static PyObject *convert (StringT s) >> { >> return bp::incref (bp::str (reinterpret_cast (s)).ptr ()); >> } >>}; >> >>BOOST_PYTHON_MODULE(pyfdk){ >> bp::to_python_converter (); > > I think this line does not do what you expect. You are trying to > register custom > converter for C++ fundamental type. I could be wrong, but it seems to > me that boost.python > uses different approach ( type conversion ) when it comes to > fundamental C++ types. Actually, that was my intention, and I wanted to achieve it with the to_python_converter. But I probably did not understand the concept correctly. > If I right, than pyplusplus can help you. > 1. For every function, that uses StringT generate small wrapper, > replacing StringT with > std::string or custom string class( > http://boost.org/libs/python/doc/v2/faq.html#custom_string ) Okay, thank you, I will try to do that. > 2. Export those wrappers. Consider to run pyplusplus on generated > files, instead of > adding code to the module builder. Can you please explain in more detail. Do you mean a two-stage generation process with pyplusplus? Regards, Jan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: From roman.yakovenko at gmail.com Thu Aug 3 19:34:09 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 3 Aug 2006 20:34:09 +0300 Subject: [C++-sig] [boost.python] conversion between string and unsigned char * In-Reply-To: References: <7465b6170608030420p36156610n4c525ec931f100f0@mail.gmail.com> Message-ID: <7465b6170608031034n69ae9ab7r8b02000587151aae@mail.gmail.com> On 8/3/06, Jan Langer wrote: > >>BOOST_PYTHON_MODULE(pyfdk){ > >> bp::to_python_converter (); > > > > I think this line does not do what you expect. You are trying to > > register custom > > converter for C++ fundamental type. I could be wrong, but it seems to > > me that boost.python > > uses different approach ( type conversion ) when it comes to > > fundamental C++ types. > > Actually, that was my intention, and I wanted to achieve it with the > to_python_converter. But I probably did not understand the concept > correctly. No, I think that you understand it right, boost.python treats fundamental type in special way and you can not change this. > > If I right, than pyplusplus can help you. > > 1. For every function, that uses StringT generate small wrapper, > > replacing StringT with > > std::string or custom string class( > > http://boost.org/libs/python/doc/v2/faq.html#custom_string ) > > Okay, thank you, I will try to do that. > > > 2. Export those wrappers. Consider to run pyplusplus on generated > > files, instead of > > adding code to the module builder. > > Can you please explain in more detail. Do you mean a two-stage > generation process with pyplusplus? Yes. First run you generate wrappers, second run you expose those wrappers. > Regards, > Jan -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roberto.c.aguilar at gmail.com Thu Aug 3 21:25:32 2006 From: roberto.c.aguilar at gmail.com (Roberto Aguilar) Date: Thu, 3 Aug 2006 12:25:32 -0700 Subject: [C++-sig] [Boost.Python] Using bbv2 to build simple extension Message-ID: Hello, I'm trying to setup my build environment to properly build a python extension outside of the boost tree using Boost.Build v2. So far I have this tree setup: top/ | +-- Jamroot | +-- lib/ | | | +-- pytest | | | `-- Jamfile | `-- python.cpp My Jamroot file looks like: ---- .boost-root = /Users/berto/apps/opt/boost_1_33_1 ; use-project /boost : $(.boost-root) ; using python : 2.4 : /sw ; project myproj : requirements static ; ---- My Jamfile: ---- project : usage-requirements . ; [...] python-extension fileformats_py : python.cpp : /boost/python//boost_python ; ---- In the jamfile I also have some library declarations, but they're irrelevant to this. When I run bjam, I get this: [berto at drjekyll][1108]$ bjam Building Boost.Regex with the optional Unicode/ICU support disabled. Please refer to the Boost.Regex documentation for more information (and if you don't know what ICU is then you probably don't need it). error: Unable to find file or target named error: '/python//python_for_extensions error: referred from project aterror: '.' My guess is that I'm missing some sort of declaration in my Jamroot file. Any help is much appreciated! Thanks! -Roberto. From investtcartier at yahoo.com Thu Aug 3 21:52:01 2006 From: investtcartier at yahoo.com (Kevin Jones) Date: Thu, 3 Aug 2006 12:52:01 -0700 (PDT) Subject: [C++-sig] Converter with return_value_policy semantics... Message-ID: <20060803195202.92517.qmail@web55501.mail.re4.yahoo.com> Hi all, I have a function T foo(). The problem is that T is a variant type and by default is being converted to a python object using my supplied converter. I would like to rewrite the converter to use return_value_policy semantics on a case by case basis for each variant type. Any suggestions? Best regards, Kevin __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From roman.yakovenko at gmail.com Thu Aug 3 22:04:33 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 3 Aug 2006 23:04:33 +0300 Subject: [C++-sig] Converter with return_value_policy semantics... In-Reply-To: <20060803195202.92517.qmail@web55501.mail.re4.yahoo.com> References: <20060803195202.92517.qmail@web55501.mail.re4.yahoo.com> Message-ID: <7465b6170608031304g53da4120t3535692f2edf0127@mail.gmail.com> On 8/3/06, Kevin Jones wrote: > Hi all, > > I have a function T foo(). The problem is that T is a > variant type and by default is being converted to a > python object using my supplied converter. > > I would like to rewrite the converter to use > return_value_policy semantics on a > case by case basis for each variant type. > > Any suggestions? You can create custom call policies. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mharidev at qualcomm.com Fri Aug 4 03:14:05 2006 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Thu, 3 Aug 2006 18:14:05 -0700 Subject: [C++-sig] Pyplusplus: Exporting arrays of non-copyable type? Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA880167D603@NAEX11.na.qualcomm.com> Hi Folks, I'm using pyplusplus to generate boost.python wrappers for the following piece of C++ code: ------------------------------------------------------------------------ ----------- //test.cpp class Base { protected: Base() { } private: // Copy constructor and assignment operator should not // be used. Base(const Base&); const Base& operator=(const Base&); }; class Derv: public Base { public: int x; }; class Test: public Base { public: Derv dataArray[20]; }; ------------------------------------------------------------------------ ------------- In class Test, the dataArray if of type Derv which is a non-copyable type (because of private copy constructor and assignment operator of Base class). In other words, this is not allowed: >> obj = Test() >> obj.dataArray[0] = Derv() #Not allowed But the pyplusplus generated code (register_array_1() in __array_1.pypp.hpp) exposes a set_item method for the data array though it's type is non-copyable and hence the code does not compile with the following error message: ------------------------------------------------------------------------ ------------- test.cpp:8: error: 'const Base& Base::operator=(const Base&)' is private test.cpp:11: error: within this context __array_1.pypp.hpp: In member function 'void pyplusplus::containers::static_sized::array_1_t::set_item(long unsigned int, typename boost::call_traits::param_type) [with TItemType = Derv, long unsigned int size = 20ul]': __array_1.pypp.hpp:73: warning: synthesized method 'Derv& Derv::operator=(const Derv&)' first required here ------------------------------------------------------------------------ ------------- Please see attached source/generated files. Is there any way I can make pyplusplus to NOT generate the set_item method for arrays of non-copyable type? (maybe by setting some flag?) Thanks, -Meghana. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.cpp Type: application/octet-stream Size: 300 bytes Desc: test.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: generate_code.py Type: application/octet-stream Size: 1066 bytes Desc: generate_code.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: PYPP_YMI.cpp Type: application/octet-stream Size: 1591 bytes Desc: PYPP_YMI.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: From roman.yakovenko at gmail.com Fri Aug 4 14:48:19 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 4 Aug 2006 14:48:19 +0200 Subject: [C++-sig] Pyplusplus: Exporting arrays of non-copyable type? In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA880167D603@NAEX11.na.qualcomm.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA880167D603@NAEX11.na.qualcomm.com> Message-ID: <7465b6170608040548q65f0eb99u56f19dad10e6474@mail.gmail.com> On 8/4/06, Haridev, Meghana wrote: > I'm using pyplusplus to generate boost.python wrappers for the following > piece of C++ code: > ... > > In class Test, the dataArray if of type Derv which is a non-copyable type > (because of private copy constructor and assignment operator of Base class). > In other words, this is not allowed: > But the pyplusplus generated code (register_array_1() in __array_1.pypp.hpp) > exposes a set_item method for the data array though it's type is > non-copyable and hence the code does not compile with the following error > message: > > > Is there any way I can make pyplusplus to NOT generate the set_item method > for arrays of non-copyable type? (maybe by setting some flag?) Unfortunately no. I did not thought about this. You have 2 choices: 1. To add this functionality to pyplusplus 2. To exclude the variable from generation and to add hand written code. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From lee.will at gmail.com Fri Aug 4 16:30:03 2006 From: lee.will at gmail.com (Will Lee) Date: Fri, 4 Aug 2006 09:30:03 -0500 Subject: [C++-sig] Overriding operator= in boost python Message-ID: <7f03db650608040730ga70b414ieb0e265ea2db2bf@mail.gmail.com> Hi, Is there any way to wrap the operator= for a C++ assignment operator in boost python? The documentation on operators doesn't seem to allow that ( http://www.boost.org/libs/python/doc/v2/operators.html). Essentially, I would like to do the python equalivalent of: class A; class B : public A; I then have: B& operator=(const A& a) { // assign A to B } So that I can do (say bHolder is a class that contains a B instance): a = A(); bHolder.b = a; Thanks, Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Aug 4 16:46:31 2006 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 04 Aug 2006 10:46:31 -0400 Subject: [C++-sig] Overriding operator= in boost python In-Reply-To: <7f03db650608040730ga70b414ieb0e265ea2db2bf@mail.gmail.com> References: <7f03db650608040730ga70b414ieb0e265ea2db2bf@mail.gmail.com> Message-ID: <44D35DC7.7050001@sympatico.ca> Will Lee wrote: > Hi, > > Is there any way to wrap the operator= for a C++ assignment operator in > boost python? The documentation on operators doesn't seem to allow that ( > http://www.boost.org/libs/python/doc/v2/operators.html). Essentially, I > would like to do the python equalivalent of: > > class A; > > class B : public A; > > I then have: > > B& operator=(const A& a) > { > // assign A to B > } > > So that I can do (say bHolder is a class that contains a B instance): > > a = A(); > bHolder.b = a; The statement c.b = a in python will call c's '__setattr__' method, not, as in C++, c.b's assignment operator. This is because the above changes the binding of 'c.b', not the state of the object 'c.b' refers to. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From gsculpt at googlemail.com Sat Aug 5 11:57:05 2006 From: gsculpt at googlemail.com (Geoffrey French) Date: Sat, 5 Aug 2006 10:57:05 +0100 Subject: [C++-sig] Calling list.__len__() from C++ causes crash with >= 100 elements Message-ID: <562c63b10608050257v64ada668u82e3d359c8054ecf@mail.gmail.com> Hi, I am currently running Python 2.4.3 and Boost 1.33.1-5 on Fedora Core 5. I have prepared some test code which seems to cause a seg fault when C++ code attempts to get the length of a list which has 100 or more elements. Valgrind seems to report it as an attempt to dereference a NULL pointer. An application that I have written (http://gsculpt.sf.net) displays the same behavior when compiled for Fedora Core 5, and Windows. Here is the code for a C++ module to demonstrate this: ======================== boostpythonbug.cpp ======================== #include #include using namespace boost::python; void printListLength(boost::python::object elements) { boost::python::extract lenExtract( elements.attr( "__len__" )() ); if ( lenExtract.check() ) { int numElements = lenExtract; std::cout << numElements << " elements" << std::endl; } } void printValue(boost::python::object obj) { boost::python::extract vExtract( obj.attr( "value" )() ); if ( vExtract.check() ) { int v = vExtract; std::cout << "value = " << v << std::endl; } } BOOST_PYTHON_MODULE(ListLength) { def( "printListLength", &printListLength ); def( "printValue", &printValue ); } ======================== boostpythonbug.cpp ======================== To compile: $ c++ boostpythonbug.cpp --shared -o ListLength.so -lpython2.4-lboost_python -I/usr/include/python2.4 The python module below tests this module: ======================== boostpythonbug.py ======================== from ListLength import * class Test (object): def __init__(self, x): self.x = x def value(self): return self.x def __len__(self): return self.x printValue( Test( 5 ) ) printValue( Test( 99 ) ) printValue( Test( 100 ) ) printValue( Test( 101 ) ) printListLength( Test( 5 ) ) printListLength( Test( 99 ) ) printListLength( Test( 100 ) ) printListLength( Test( 101 ) ) printListLength( [] ) printListLength( [ 0 ] ) printListLength( range( 0, 5 ) ) printListLength( range( 0, 99 ) ) printListLength( range( 0, 100 ) ) ======================== boostpythonbug.py ======================== Here is the output: $ python boostpythonbug.py value = 5 value = 99 value = 100 value = 101 5 elements 99 elements 100 elements 101 elements 0 elements 1 elements 5 elements 99 elements Segmentation fault (core dumped) Getting integer values from a generic function call works fine, as demonstrated by printValue(), and printListLength() invoked on a 'Test' object. It only seems to affect lists. Defining printListLength as: void printListLength(boost::python::object elements) OR void printListLength(boost::python::list elements) does not prevent the seg-faulting. The second definition means you can only pass lists though, i.e. the cases where a 'Test' object is passed will not work. Is this a boost::python bug, or have I screwed up some how? Thank you for your time. Regards Geoffrey French -------------- next part -------------- An HTML attachment was scrubbed... URL: From jorge.vargas at gmail.com Sat Aug 5 18:57:34 2006 From: jorge.vargas at gmail.com (Jorge Vargas) Date: Sat, 5 Aug 2006 12:57:34 -0400 Subject: [C++-sig] boost.org broken link to this list Message-ID: <32822fe60608050957u58768f8fodef47526a58744db@mail.gmail.com> Hello I'm new here and I was looking for boost support when I find out their link is broken. http://www.boost.org/more/mailing_lists.htm#projects broken link - http://www.python.org/community/sigs/c++-sig/ new link - http://www.python.org/community/sigs/current/c++-sig/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jorge.vargas at gmail.com Sat Aug 5 19:32:41 2006 From: jorge.vargas at gmail.com (Jorge Vargas) Date: Sat, 5 Aug 2006 13:32:41 -0400 Subject: [C++-sig] can't build boost.python under msys/windows Message-ID: <32822fe60608051032o4993e584r864d5cb1d75a0807@mail.gmail.com> hi Could someone stop what I'm doing wrong? $ echo $PATH .:/usr/local/bin:/mingw/bin:/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/Program Files/Subversion/bin:/c/Python24:/c/Python24/Scripts $ bjam "-sTOOLS=mgw" stage $ bjam "-sTOOLS=mingw" stage both commands fail doing a lot of lookups for vc-7_1 and the .Net framework (I have those install) CALL "C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\bin\VCVARS32.BAT" >nul ...skipped <@boost!libs!python!build\libboost_python.lib\vc-7_1\debug\threading-multi>libboost_python.CMD for lack of <@boost!libs!python!build\libboost_python.lib\vc-7_1\debug\threading-multi> numeric.obj... ------ so I take them out of the path $ echo $PATH .:/usr/local/bin:/mingw/bin:/bin:/c/Python24:/c/Python24/Scripts $ bjam "-sTOOLS=mgw" stage and it fails to do anything $ bjam "-sTOOLS=mgw" stage ...found 944 targets... ...updating 121 targets... vc-C++ ..\..\..\bin\boost\libs\python\build\boost_python.dll\vc-7_1\debug\threading-multi\numeric.obj spawn: No such file or directory so basically bjam is ignoring the TOOLS flag I have to say I downloaded the binary for windows ( boost-jam-3.1.13-1-ntx86.zip) and all boostJam related links seems to be broken http://www.boost.org/doc/html/jam/building.html http://www.boost.org/tools/jam/index.html what I'm actually trying to do is porting this https://develop.participatoryculture.org/projects/democracy/wiki/WindowsBuildDocs to compile with free tools so at the moment what I need is a replacement for boost_python-vc71-mt-1_33.dll that works with mingw does anyone distributes this as binary? thanks for the help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From markus at relix.de Sun Aug 6 01:58:12 2006 From: markus at relix.de (Markus Heller) Date: Sun, 6 Aug 2006 01:58:12 +0200 Subject: [C++-sig] Working with python unicode strings without wstring In-Reply-To: <7465b6170607312317y7be98c4fh87d650a74e0589ce@mail.gmail.com> References: <200608010223.09974.markus@relix.de> <7465b6170607312317y7be98c4fh87d650a74e0589ce@mail.gmail.com> Message-ID: <200608060158.12985.markus@relix.de> Dear Roman, > > > May be you should use another set of API? > > > http://docs.python.org/api/unicodeObjects.html well, I have done some experiments with the API you're suggesting. Though, I have a number of problems here: I see that Py_UNICODE refers to one single character / symbol which may be any symbol whatsoever in its numeric representation. I see that when I retrieve my unicoded Python string with PyContainer = PyList_GetItem(Tuple, 1); and when I convert the PyObject "PyContainer" into a PyUnicodeObject, I do it with a simple cast, which works fine. Then, I'd like to get hold of the individual symbols, also in their numeric (not encoded) representation. But how can I do this? Initially, I wanted to get everything into the form of a stl string, but a stl vector will also do fine. Thanks very much for your help! Markus From rwgk at yahoo.com Sun Aug 6 08:08:52 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 5 Aug 2006 23:08:52 -0700 (PDT) Subject: [C++-sig] boost.org broken link to this list In-Reply-To: <32822fe60608050957u58768f8fodef47526a58744db@mail.gmail.com> Message-ID: <20060806060852.51367.qmail@web31505.mail.mud.yahoo.com> --- Jorge Vargas wrote: > Hello I'm new here and I was looking for boost support when I find out their > link is broken. > > > http://www.boost.org/more/mailing_lists.htm#projects > > broken link - http://www.python.org/community/sigs/c++-sig/ > new link - http://www.python.org/community/sigs/current/c++-sig/ Thanks for pointing this out! However, the broken link was fixed a while ago in the boost CVS. Unfortunately we have to wait for the next Boost release before the fix is visible in the main page. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From rwgk at yahoo.com Sun Aug 6 08:48:47 2006 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 5 Aug 2006 23:48:47 -0700 (PDT) Subject: [C++-sig] Calling list.__len__() from C++ causes crash with >= 100 elements In-Reply-To: <562c63b10608050257v64ada668u82e3d359c8054ecf@mail.gmail.com> Message-ID: <20060806064847.33668.qmail@web31512.mail.mud.yahoo.com> --- Geoffrey French wrote: > void printListLength(boost::python::object elements) > { > boost::python::extract lenExtract( elements.attr( "__len__" )() ); > if ( lenExtract.check() ) > { > int numElements = lenExtract; > std::cout << numElements << " elements" << std::endl; > } > } I can reproduce your problem under FC3 and FC5 (both x86_64). I am not sure if this is a bug or a feature. In any case, this workaround does the trick for me: void printListLength(boost::python::object elements) { boost::python::object len_result = elements.attr( "__len__" )(); boost::python::extract lenExtract( len_result ); if ( lenExtract.check() ) { int numElements = lenExtract; std::cout << numElements << " elements" << std::endl; } } BTW: With the latest boost CVS you can simply write std::cout << len(elements) << " elements" << std::endl; __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From roman.yakovenko at gmail.com Sun Aug 6 11:45:56 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 6 Aug 2006 12:45:56 +0300 Subject: [C++-sig] Working with python unicode strings without wstring In-Reply-To: <200608060158.12985.markus@relix.de> References: <200608010223.09974.markus@relix.de> <7465b6170607312317y7be98c4fh87d650a74e0589ce@mail.gmail.com> <200608060158.12985.markus@relix.de> Message-ID: <7465b6170608060245x2c5b2f52w9e443ad5dabe3226@mail.gmail.com> On 8/6/06, Markus Heller wrote: > Dear Roman, > > > > > May be you should use another set of API? > > > > http://docs.python.org/api/unicodeObjects.html > > well, I have done some experiments with the API you're suggesting. Though, I > have a number of problems here: > > I see that Py_UNICODE refers to one single character / symbol which may be any > symbol whatsoever in its numeric representation. > > I see that when I retrieve my unicoded Python string with > > PyContainer = PyList_GetItem(Tuple, 1); > > and when I convert the PyObject "PyContainer" into a PyUnicodeObject, I do it > with a simple cast, which works fine. Then, I'd like to get hold of the > individual symbols, also in their numeric (not encoded) representation. But > how can I do this? Initially, I wanted to get everything into the form of a > stl string, but a stl vector will also do fine. > > Thanks very much for your help! I did not help you. I think you will be more productive if you will ask this question on Python user group. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jorge.vargas at gmail.com Sun Aug 6 15:42:52 2006 From: jorge.vargas at gmail.com (Jorge Vargas) Date: Sun, 6 Aug 2006 09:42:52 -0400 Subject: [C++-sig] boost.org broken link to this list In-Reply-To: <20060806060852.51367.qmail@web31505.mail.mud.yahoo.com> References: <32822fe60608050957u58768f8fodef47526a58744db@mail.gmail.com> <20060806060852.51367.qmail@web31505.mail.mud.yahoo.com> Message-ID: <32822fe60608060642g39ff4648qf86462c17b858059@mail.gmail.com> On 8/6/06, Ralf W. Grosse-Kunstleve wrote: > > --- Jorge Vargas wrote: > > > Hello I'm new here and I was looking for boost support when I find out > their > > link is broken. > > > > > > http://www.boost.org/more/mailing_lists.htm#projects > > > > broken link - http://www.python.org/community/sigs/c++-sig/ > > new link - http://www.python.org/community/sigs/current/c++-sig/ > > Thanks for pointing this out! However, the broken link was fixed a while > ago in > the boost CVS. Unfortunately we have to wait for the next Boost release > before > the fix is visible in the main page. ohhh i see autogenerated docs :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Sun Aug 6 19:54:08 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 06 Aug 2006 13:54:08 -0400 Subject: [C++-sig] Calling list.__len__() from C++ causes crash with >= 100 elements References: <562c63b10608050257v64ada668u82e3d359c8054ecf@mail.gmail.com> Message-ID: "Geoffrey French" writes: > Here is the code for a C++ module to demonstrate this: > > Is this a boost::python bug, or have I screwed up some how? > Thank you for your time. What is the *smallest* code that demonstrates it? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Aug 6 19:55:14 2006 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 06 Aug 2006 13:55:14 -0400 Subject: [C++-sig] boost.org broken link to this list References: <32822fe60608050957u58768f8fodef47526a58744db@mail.gmail.com> <20060806060852.51367.qmail@web31505.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > --- Jorge Vargas wrote: > >> Hello I'm new here and I was looking for boost support when I find out their >> link is broken. >> >> >> http://www.boost.org/more/mailing_lists.htm#projects >> >> broken link - http://www.python.org/community/sigs/c++-sig/ >> new link - http://www.python.org/community/sigs/current/c++-sig/ > > Thanks for pointing this out! However, the broken link was fixed a while ago in > the boost CVS. Unfortunately we have to wait for the next Boost release before > the fix is visible in the main page. Ralf, you _can_ update the site directly: http://boost.org/more/updating_the_website.html -- Dave Abrahams Boost Consulting www.boost-consulting.com From cablepuff at gmail.com Sun Aug 6 21:03:24 2006 From: cablepuff at gmail.com (chun ping wang) Date: Sun, 6 Aug 2006 12:03:24 -0700 Subject: [C++-sig] boost python compiling question. Message-ID: <7253f6b30608061203v135e867ex3db9e7e2dad0d565@mail.gmail.com> Hmm k i have a simple question, how would I build boost.python given this following information. I am using dev-cpp and its install in "c:\dev-cpp" folder. IN it contains the mingw32 sub directory My project folder is "c:\cs classes\cs386\c++". In it contains FiniteAutomta.cpp which maps to python module... my boost folder is "C:\boost_1_33_1" in it contains the bjam.exe file. PYTHON_ROOT = "C:\python24" Thanks for the help. I look at the tutorial but is confused on how I can build my project. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael_gruner at arcor.de Mon Aug 7 13:58:55 2006 From: michael_gruner at arcor.de (michael_gruner at arcor.de) Date: Mon, 7 Aug 2006 13:58:55 +0200 (CEST) Subject: [C++-sig] [boost.python] void ptr problem Message-ID: <20872957.1154951935894.JavaMail.ngmail@webmail14> Hello, I'm trying to use boost.python to wrap a C function that takes a pointer on a void pointer as an argument. But I'm going wrong to use the example from the FAQ. Could anyone help me on this? my code looks like this: struct void_; BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_); int myfunc(char * mychar, void ** mypointer); int myfunc_wrp(char * mychar, void_ ** mypointer){ return myfunc(mychar,(void ** ) mypointer); } ... BOOST_PYTHON_MODULE(mymodule){ def("myfunc", &myfunc_wrp); } later in python I do: import mymodule mystring = " " mypointerobject = 0 mymodule.myfunc(mystring,mypointerobject) and get: Boost.Python.ArgumentError: Python argument types in mymodule.myfunc(str, int) did not match C++ signature: myfunc(char *, struct void_ * *) Are there any advices to solve this problem? thank you for your answers. Kind regards, Michael From richjohnson905 at msn.com Mon Aug 7 15:07:17 2006 From: richjohnson905 at msn.com (RICH JOHNSON) Date: Mon, 07 Aug 2006 08:07:17 -0500 Subject: [C++-sig] ImportError: timemodule.so Message-ID: I am new to boost python and am having difficulty importing python modules into a little C++ program. Any insight into the problem would be appreciated. OS: Linux Redhat gcc: 3.2.3 python 2.2 boost 1.33.1 >From the command line I can do: [rjohnson at pitwar7 rjohnson]$ python Python 2.2.3 (#1, Feb 15 2005, 02:41:06) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>from time import time,ctime >>>print 'Today is', ctime(time()) Today is Fri Aug 4 10:47:20 2006 >>> But the C++ program below outputs: 25 20 Traceback (most recent call last): File "", line 1, in ? ImportError: /usr/lib/python2.2/lib-dynload/timemodule.so: undefined symbol: PyDict_SetItemString #include #include int main(int, char **) { using namespace boost::python; Py_Initialize(); try { PyRun_SimpleString("result = 5 ** 2"); object module((handle<>(borrowed(PyImport_AddModule("__main__"))))); object dictionary = module.attr("__dict__"); object result = dictionary["result"]; int result_value = extract(result); std::cout << result_value << std::endl; dictionary["result"] = 20; PyRun_SimpleString("print result"); // Here is the same command that ran successfully at the command line above but fails from C++ PyRun_SimpleString("from time import time,ctime\n" "print 'Today is',ctime(time())\n"); } catch (error_already_set) { PyErr_Print(); } Py_Finalize(); return 0; } My LD_LIBRARY_PATH is /usr/local/lib:/usr/lib/python2.2/config PYTHONPATH is /usr/lib/python2.2/config From richjohnson905 at msn.com Mon Aug 7 16:17:03 2006 From: richjohnson905 at msn.com (RICH JOHNSON) Date: Mon, 07 Aug 2006 09:17:03 -0500 Subject: [C++-sig] ImportError: timemodule.so In-Reply-To: Message-ID: More info on my import error: In my Jamfile, my import statement when I build boost_python-gcc was: import python ; I am currently trying to rebuild my boost_python.so with: import python time ; ... thinking this may be the problem. ----Original Message Follows---- From: "RICH JOHNSON" Reply-To: Development of Python/C++ integration To: c++-sig at python.org Subject: [C++-sig] ImportError: timemodule.so Date: Mon, 07 Aug 2006 08:07:17 -0500 I am new to boost python and am having difficulty importing python modules into a little C++ program. Any insight into the problem would be appreciated. OS: Linux Redhat gcc: 3.2.3 python 2.2 boost 1.33.1 >From the command line I can do: [rjohnson at pitwar7 rjohnson]$ python Python 2.2.3 (#1, Feb 15 2005, 02:41:06) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>from time import time,ctime >>>print 'Today is', ctime(time()) Today is Fri Aug 4 10:47:20 2006 >>> But the C++ program below outputs: 25 20 Traceback (most recent call last): File "", line 1, in ? ImportError: /usr/lib/python2.2/lib-dynload/timemodule.so: undefined symbol: PyDict_SetItemString #include #include int main(int, char **) { using namespace boost::python; Py_Initialize(); try { PyRun_SimpleString("result = 5 ** 2"); object module((handle<>(borrowed(PyImport_AddModule("__main__"))))); object dictionary = module.attr("__dict__"); object result = dictionary["result"]; int result_value = extract(result); std::cout << result_value << std::endl; dictionary["result"] = 20; PyRun_SimpleString("print result"); // Here is the same command that ran successfully at the command line above but fails from C++ PyRun_SimpleString("from time import time,ctime\n" "print 'Today is',ctime(time())\n"); } catch (error_already_set) { PyErr_Print(); } Py_Finalize(); return 0; } My LD_LIBRARY_PATH is /usr/local/lib:/usr/lib/python2.2/config PYTHONPATH is /usr/lib/python2.2/config _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From dgregor at cs.indiana.edu Mon Aug 7 15:59:03 2006 From: dgregor at cs.indiana.edu (Doug Gregor) Date: Mon, 7 Aug 2006 09:59:03 -0400 Subject: [C++-sig] Boost.Python: Caching Python object instances Message-ID: <13F95FA6-11E4-4937-B80A-A51DF3080A36@cs.indiana.edu> Hello, I am using Boost.Python to expose the Boost Graph Library in Python. The vertices in the graph types are small structures that are always passed by value. A vertex looks something like this: struct Vertex { int index; Graph* graph; }; This class is exposed to python in the normal way: class_(); Now, each time that we convert a Vertex from C++ to Python, Boost.Python will create a new PyObject for it. This behavior has surprised us a few times, and contributes to some performance problems. So, I would like to cache the PyObject instances in the Graph object itself: class Graph { public: std::vector py_vertices; }; When I add a new vertex, I want to create a Python object for it and store that object in the py_vertices vector. Then, when Boost.Python needs to convert a vertex_descriptor value "v" to a Python object, I'd like to return "py_vertices[v.index]" instead of creating a new object. With lots of hackery, I've attained some limited success in this area. My approach is to register a to_python_vertex for the vertex type with this function object: struct cached_vertex_object { static PyObject* convert(const Vertex& v) { PyObject* result = v.graph->py_vertices[v.index].ptr(); Py_INCREF(result); return result; } }; to_python_converter(); Of course, now I have the problem of creating the boost::python::object values to put in the cache! Digging around in the source a bit, I came up with this: typedef class_cref_wrapper > > Converter; Vertex result(this->py_vertices.size(), this); boost::python::object vertex_object(handle<>(Converter::convert (result))); this->py_vertices.push_back(result); This actually does work, but I get a sharp rebuke from Boost.Python whenever my extension module gets loaded: /u/dgregor/lib/python/boost/graph/__init__.py:10: RuntimeWarning: to- Python converter for boost::graph::python::basic_descriptor already registered; second conversion method ignored. from _graph import * I have two questions: 1) Is there a better way to cache Python object instances with Boost.Python? 2) I've filtered out those Boost.Python warnings: will they come back to bite me eventually? Cheers, Doug From amohr at pixar.com Mon Aug 7 18:46:18 2006 From: amohr at pixar.com (Alex Mohr) Date: Mon, 07 Aug 2006 09:46:18 -0700 Subject: [C++-sig] Calling list.__len__() from C++ causes crash with >= 100 elements In-Reply-To: <20060806064847.33668.qmail@web31512.mail.mud.yahoo.com> References: <20060806064847.33668.qmail@web31512.mail.mud.yahoo.com> Message-ID: <44D76E5A.5010905@pixar.com> >> void printListLength(boost::python::object elements) >> { >> boost::python::extract lenExtract( elements.attr( "__len__" )() ); >> if ( lenExtract.check() ) >> { >> int numElements = lenExtract; >> std::cout << numElements << " elements" << std::endl; >> } >> } > > I can reproduce your problem under FC3 and FC5 (both x86_64). I am not sure if > this is a bug or a feature. In any case, this workaround does the trick for me: It is apparently a feature. We've had a similar bug before as well. You're creating a c++ temporary holding a new python object when you do "elements.attr("__len__")()" and passing it off to the extractor, and then you attempt to invoke the extractor later after the c++ temporary has died. The problem is that the extractor does not keep a reference to the python object it was constructed with (and is documented accordingly). So, by the time you invoke the extractor, the python object it's got is long since dead, and you get a crash. The fix posted in the parent message is the correct one. You need to make sure the object you pass to the extractor lives at least as long as the last invocation of the extractor. Here's the documentation: http://www.boost.org/libs/python/doc/v2/extract.html#extract-spec Note this sentence: "Stores a pointer to the Python object managed by its constructor argument. In particular, the reference count of the object is not incremented. The onus is on the user to be sure it is not destroyed before the extractor's conversion function is called." When we came across this, we wondered why it would be bad for the extractor to take a reference to its argument. David -- can you shed some light on this? Alex From tcickovs at nd.edu Tue Aug 8 02:45:07 2006 From: tcickovs at nd.edu (tcickovs at nd.edu) Date: Mon, 7 Aug 2006 20:45:07 -0400 Subject: [C++-sig] C++ and Python variables referencing the same location Message-ID: <1154997907.44d7de939c3de@webmail.nd.edu> Hello, I have been working on something for the past few days and have not been able to find much online help on it. Conceptually, what I want to do is very simple: I would like to declare a C++ variable, then use the Python/C API (or some other available utility) to define a Python variable, and then somehow get the two to reference the same memory location so that when I modify one, the other changes. So, for example, in my C++ file if I have this: object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); int y = 2; // y = 2 main_module.attr("x") = y; // x = 2, y = 2 main_module.attr("x") = 3; // x = 3, y = 2 (does not change) y = 4; // x = 3 (does not change), y = 4 Modifications to x and y happen independently because one is on the C++ runtime stack and the other is on the Python interpreter's heap. I'd like it to be if I modify x, then y changes; and vice-versa. Now, I saw in the Python/C API there was a way to modify information in the Python interpreter heap from C++: int* y = PyMem_New(int, 1); *y = 4; // Changes data in the heap However, I need to somehow get x to reference the location in the heap that I just allocated. Is there a way? Or is there a completely alternative solution that I can use? I feel like someone must have done this before, but cannot find much documentation. Appreciate any help at all. -Trevor From sbalasub at qualcomm.com Tue Aug 8 06:10:31 2006 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Mon, 7 Aug 2006 21:10:31 -0700 Subject: [C++-sig] boost.python version that contains indexing suite. Message-ID: Hi, Can someone provide a tar file for the boost.python code that contains the indexing_suite_v2. The last time I tried, I had the compilation failures and could go no further. I followed the steps listed in http://home.clara.net/raoulgough/boost/index.html, but with the latest version of boost. cvs -z3 -d:pserver:anonymous at boost.cvs.sourceforge.net:/cvsroot/boost co -P boost cvs update -d -r indexing_v2 boost/python/suite/indexing cvs update -d -r indexing_v2 libs/python Any ideas? Thanks, Shiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From sbalasub at qualcomm.com Tue Aug 8 06:40:25 2006 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Mon, 7 Aug 2006 21:40:25 -0700 Subject: [C++-sig] STL list data member. Message-ID: Hi, I have some classes which has std::list as public data members that need to be exposed. What is the good way to do it? The short term solution I can think of is to add a wrapper getter/setter method to convert to/from boost::python::list. I could probably use the decl_string from py++ to check if the member_data is "::std::list" and automate the wrapper generation. Does anyone else have other solutions? Thanks, Shiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From sbalasub at qualcomm.com Tue Aug 8 06:57:16 2006 From: sbalasub at qualcomm.com (Balasubramanyam, Shivakumar) Date: Mon, 7 Aug 2006 21:57:16 -0700 Subject: [C++-sig] [GCC-XML] (__GLOBAL function was Problem exposing templates) In-Reply-To: <44D18AFF.7060903@4roald.org> Message-ID: Roman, Bjorn, The template instantiations happens in both declarations below. 1. typedef Stack::Stack Stack_int; This would result in a template instantiation with user defined class name "Stack_int" 2. template class Stack as instructed in http://www.gccxml.org/HTML/FAQ.html This would result in a template instantiation with class name picked by gcc "Stack_less_int_grate_" Though I used step 1, I think it makes sense to use step 2 and probably rename the class name in py++ or pyapp to Stack_Int or StackOfInt. This would be generic way for naming the template instantiations, BTW, I used the following code to get rid of _GLOBAL functions, *** for decl in mb.free_functions(): if(decl.name.startswith('_GLOBAL')): mb.free_functions(decl.name).exclude() *** HTH, Shiva >-----Original Message----- >From: Bj?rn Roald [mailto:bjorn at 4roald.org] >Sent: Wednesday, August 02, 2006 10:35 PM >To: Roman Yakovenko >Cc: Balasubramanyam, Shivakumar; gccxml at gccxml.org; Development of >Python/C++ integration >Subject: Re: [GCC-XML] (__GLOBAL function was Problem exposing templates) > >Roman Yakovenko wrote: >> On 8/3/06, Balasubramanyam, Shivakumar wrote: >>> [shiva] Roman, I understood the second part of my question, which was >>> using typedef for explicit instantiation. >>> >>> Now I declared using "typedef Stack::Stack Stack_Int;" >> >> This does not couse to template instantiation. >> >> Please write: >> >> Stack_Int s; >Why do you need the typdef? > >Stack::Stack Stack_Int; > >Should do it! Or am I missing some other purpose of the typedef? > > Bjorn From roman.yakovenko at gmail.com Tue Aug 8 07:17:12 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 8 Aug 2006 08:17:12 +0300 Subject: [C++-sig] [GCC-XML] (__GLOBAL function was Problem exposing templates) In-Reply-To: References: <44D18AFF.7060903@4roald.org> Message-ID: <7465b6170608072217g2def47c2ld47f8965423a4cbe@mail.gmail.com> On 8/8/06, Balasubramanyam, Shivakumar wrote: > Roman, Bjorn, > > The template instantiations happens in both declarations below. > > 1. typedef Stack::Stack Stack_int; > > This would result in a template instantiation with user defined class name "Stack_int" > > 2. template class Stack as instructed in http://www.gccxml.org/HTML/FAQ.html > > This would result in a template instantiation with class name picked by gcc "Stack_less_int_grate_" > Please, read this document, you will understand why there is a difference in class aliases: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/docs/documentation/hints.rest?view=markup -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Tue Aug 8 07:24:43 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 8 Aug 2006 08:24:43 +0300 Subject: [C++-sig] boost.python version that contains indexing suite. In-Reply-To: References: Message-ID: <7465b6170608072224p6f9eb935r2744bf071db53c1@mail.gmail.com> On 8/8/06, Balasubramanyam, Shivakumar wrote: > Hi, > > Can someone provide a tar file for the boost.python code that contains the > indexing_suite_v2. The last time I tried, I had the compilation failures and > could go no further. > pyplusplus documentation for indexing suite v2: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/docs/documentation/containers.rest?view=markup source code and instructions for indexing suite v2: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From quncao at gmail.com Tue Aug 8 11:22:29 2006 From: quncao at gmail.com (Qun Cao) Date: Tue, 8 Aug 2006 02:22:29 -0700 Subject: [C++-sig] Can Boost.Python help me? Message-ID: <1f527df80608080222r61821e97u8b0dddb66a560d53@mail.gmail.com> Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location) To configure the game environment. I am trying to figure out how to make this happen. I only have the vague idea that this concerns embedding/extending python with C++, but after reading Python Doc, SWIG, BOOST.Python, I am still not sure how to architecture it. Since the main program is still going to be the C++ application, I guess we need to embedding the python scripts in the C++ code. So at initialization stage, the python script needs to be loaded into the C++ code. And this code can be simple, like player = Player() game.loadPlayer(player) But for this to work, the python code needs to know the Player class, is it right? Does that mean I need to build a python wrapper class for Player and "import Player" in the python code? But because this application is built on top of a game engine, Player class inherits many classes from there, I cannot possibly wrapping them all, right? Also, some global objects are probably needed in this code of adding players, how can the python code access them? I know I probably don't have a grasp of basics here, please kindly enlighten me! Btw, if you can point me to any source code of non-trivial projects utilizing Boost.Python, that would be very helpful. I found the examples on the tutorials are far too simple. Thank you very much, Qun Cao From roman.yakovenko at gmail.com Tue Aug 8 11:35:09 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 8 Aug 2006 12:35:09 +0300 Subject: [C++-sig] Can Boost.Python help me? In-Reply-To: <1f527df80608080222r61821e97u8b0dddb66a560d53@mail.gmail.com> References: <1f527df80608080222r61821e97u8b0dddb66a560d53@mail.gmail.com> Message-ID: <7465b6170608080235k47be9af5n20306dccda1e91da@mail.gmail.com> On 8/8/06, Qun Cao wrote: > Hi Everyone, > > I am a beginner on cross language development. My problem at hand is > to build a python interface for a C++ application built on top of a 3D > game engine. The purpose of this python interface is providing a > convenient scripting toolkit for the application. Fortunately you are not the first one, and I hope not the last: http://language-binding.net/pyplusplus/quotes.html#who-is-using-pyplusplus 1. Python OGRE * http://lakin.weckers.net/index_ogre_python.html * http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=1478&sid=df5ad0fff81d1f746f527ebcdd4aa1db 2. http://cgkit.sourceforge.net/ - contains Python bindings for Maya C++ SDK 3. PyOpenSG - https://realityforge.vrsource.org/view/PyOpenSG/WebHome The goal of PyOpenSG is to provide python bindings for the OpenSG scene graph. > Since the main program is still going to be the C++ application, I > guess we need to embedding the python scripts in the C++ code. I think cgkit project is dealing with this problem too. > > But for this to work, the python code needs to know the Player class, > is it right? Right > Does that mean I need to build a python wrapper class for > Player and "import Player" in the python code? But because this > application is built on top of a game engine, Player class inherits > many classes from there, I cannot possibly wrapping them all, right? It depends on how much functionality you want to export. > Also, some global objects are probably needed in this code of adding > players, how can the python code access them? Boost.Python provides the functionality. > I know I probably don't have a grasp of basics here, please kindly > enlighten me! > > Btw, if you can point me to any source code of non-trivial projects > utilizing Boost.Python, that would be very helpful. I found the > examples on the tutorials are far too simple. Those are tutorials, they should be simple, right :-) ? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From gsculpt at googlemail.com Tue Aug 8 22:42:02 2006 From: gsculpt at googlemail.com (Geoffrey French) Date: Tue, 8 Aug 2006 21:42:02 +0100 Subject: [C++-sig] Calling list.__len__() from C++ causes crash with >= 100 elements Message-ID: <562c63b10608081342p690d2472y82f38ed504526b9d@mail.gmail.com> I tried to code the smallest module to demonstrate the problem. I presented it as a module so that people could get it working and running easily, to aid any debugging that might have been done. Sorry if I got the balance between too much code and too little, somewhat off. Regards Geoffrey French "Geoffrey French" > > writes: > > >* Here is the code for a C++ module to demonstrate this:* > > > ** > > > >* Is this a boost::python bug, or have I screwed up some how?* > >* Thank you for your time.* > > What is the *smallest* code that demonstrates it? > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lee.will at gmail.com Tue Aug 8 23:48:38 2006 From: lee.will at gmail.com (Will Lee) Date: Tue, 8 Aug 2006 16:48:38 -0500 Subject: [C++-sig] Wrapping shared_ptr of virtual classes Message-ID: <7f03db650608081448w44d9d332hae6cca39efd9cfe3@mail.gmail.com> I have seen this post ( http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2262721) a while a go but I couldn't find the response that solves this problem. Essentially, I couldn't find a way to wrap an abstract class that is being returned as a shared_ptr. For the following scenario: class A has virtual method f class B inherits from A that implements f class F that has a static method: shared_ptr getInstance() Essentially I want to call F.getInstance().f() in python, which will call B::f All the documentation points to creating a wrapper class, so I have done so: struct AWrapper : A, wrapper (would wrap function "f" that uses this->get_override() call to call the overridden function) My question is, like what is in the post, how do I declare class A? I don't think I can declare the AWrapper, since F.getInstance() returns shared_ptr and not shared_ptr: class_, boost::noncopyable>... I don't think I can declare with A either, since how can I tie the wrapper function calls? class_, boost::noncopyable> Then this just gets me confused in what it would do (I got a convert error saying that there is no to_python converter found): class_, boost::noncopyable> ... Your help is greatly appreciated. Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From jorge.vargas at gmail.com Wed Aug 9 00:55:48 2006 From: jorge.vargas at gmail.com (Jorge Vargas) Date: Tue, 8 Aug 2006 18:55:48 -0400 Subject: [C++-sig] can't build boost.python under msys/windows In-Reply-To: <32822fe60608051032o4993e584r864d5cb1d75a0807@mail.gmail.com> References: <32822fe60608051032o4993e584r864d5cb1d75a0807@mail.gmail.com> Message-ID: <32822fe60608081555l6032f232n91c55689f3d3c362@mail.gmail.com> anyone? On 8/5/06, Jorge Vargas wrote: > > hi > > Could someone stop what I'm doing wrong? > > $ echo $PATH > .:/usr/local/bin:/mingw/bin:/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/Program > Files/Subversion/bin:/c/Python24:/c/Python24/Scripts > > $ bjam "-sTOOLS=mgw" stage > $ bjam "-sTOOLS=mingw" stage > > both commands fail doing a lot of lookups for vc-7_1 and the .Net > framework (I have those install) > CALL "C:\Program Files\Microsoft Visual Studio .NET > 2003\VC7\bin\VCVARS32.BAT" >nul > ...skipped <@boost!libs!python!build\libboost_python.lib\vc-7_1\debug\threading-multi>libboost_python.CMD > for lack of <@boost > !libs!python!build\libboost_python.lib\vc-7_1\debug\threading-multi> > numeric.obj.. . > > ------ > > so I take them out of the path > > $ echo $PATH > .:/usr/local/bin:/mingw/bin:/bin:/c/Python24:/c/Python24/Scripts > > $ bjam "-sTOOLS=mgw" stage > > > and it fails to do anything > $ bjam "-sTOOLS=mgw" stage > ...found 944 targets... > ...updating 121 targets... > vc-C++ ..\..\..\bin\boost > \libs\python\build\boost_python.dll\vc-7_1\debug\threading-multi\numeric.obj > spawn: No such file or directory > > so basically bjam is ignoring the TOOLS flag > > I have to say I downloaded the binary for windows (boost- > jam-3.1.13-1-ntx86.zip) > and all boostJam related links seems to be broken > http://www.boost.org/doc/html/jam/building.html > http://www.boost.org/tools/jam/index.html > > what I'm actually trying to do is porting this > > https://develop.participatoryculture.org/projects/democracy/wiki/WindowsBuildDocs > to compile with free tools so at the moment what I need is a replacement > for boost_python-vc71-mt-1_33.dll > that works with mingw does anyone distributes this as binary? > > thanks for the help. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Aug 9 08:11:23 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 9 Aug 2006 09:11:23 +0300 Subject: [C++-sig] Wrapping shared_ptr of virtual classes In-Reply-To: <7f03db650608081448w44d9d332hae6cca39efd9cfe3@mail.gmail.com> References: <7f03db650608081448w44d9d332hae6cca39efd9cfe3@mail.gmail.com> Message-ID: <7465b6170608082311r6482e291k30c50e50b9a080a7@mail.gmail.com> On 8/9/06, Will Lee wrote: > I have seen this post > (http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2262721) > a while a go but I couldn't find the response that solves this problem. > Essentially, I couldn't find a way to wrap an abstract class that is being > returned as a shared_ptr. I hope next links will help you: Python code: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/smart_pointers_tester.py?view=markup C++ code: http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.hpp?view=markup http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/smart_pointers_to_be_exported.cpp?view=markup Generated code attached. Also, it could be nice to get the answer, why user can not specify HeldType for abstract class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- // This file has been generated by pyplusplus. // Copyright 2004 Roman Yakovenko. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include "boost/python.hpp" #include "smart_pointers_to_be_exported.hpp" namespace bp = boost::python; struct base_wrapper : smart_pointers::base, bp::wrapper< smart_pointers::base > { base_wrapper( ) : smart_pointers::base( ) , bp::wrapper< smart_pointers::base >() { // Normal constructor } virtual int get_base_value( ) { if( bp::override func_get_base_value = this->get_override( "get_base_value" ) ) return func_get_base_value( ); else return smart_pointers::base::get_base_value( ); } int default_get_base_value( ) { return smart_pointers::base::get_base_value( ); } virtual int get_some_value( ){ bp::override func_get_some_value = this->get_override( "get_some_value" ); return func_get_some_value( ); } }; struct data_wrapper : smart_pointers::data, bp::wrapper< smart_pointers::data > { data_wrapper(smart_pointers::data const & arg ) : smart_pointers::data( arg ) , bp::wrapper< smart_pointers::data >(){ // copy constructor } data_wrapper( ) : smart_pointers::data( ) , bp::wrapper< smart_pointers::data >() { // Normal constructor } virtual int get_some_value( ) { if( bp::override func_get_some_value = this->get_override( "get_some_value" ) ) return func_get_some_value( ); else return smart_pointers::data::get_some_value( ); } int default_get_some_value( ) { return smart_pointers::data::get_some_value( ); } virtual int get_value( ) { if( bp::override func_get_value = this->get_override( "get_value" ) ) return func_get_value( ); else return smart_pointers::data::get_value( ); } int default_get_value( ) { return smart_pointers::data::get_value( ); } }; BOOST_PYTHON_MODULE(smart_pointers){ { //::smart_pointers::base typedef bp::class_< base_wrapper, boost::noncopyable > base_exposer_t; base_exposer_t base_exposer = base_exposer_t( "base", "documentation" ); bp::scope base_scope( base_exposer ); base_exposer.def( bp::init< >("documentation")[bp::default_call_policies()] ); { //::smart_pointers::base::get_base_value typedef int ( ::smart_pointers::base::*function_ptr_t )( ) ; typedef int ( base_wrapper::*default_function_ptr_t )( ) ; base_exposer.def( "get_base_value" , function_ptr_t(&::smart_pointers::base::get_base_value) , default_function_ptr_t(&base_wrapper::default_get_base_value) , bp::default_call_policies() ); } { //::smart_pointers::base::get_some_value typedef int ( ::smart_pointers::base::*function_ptr_t )( ) ; base_exposer.def( "get_some_value" , bp::pure_virtual( function_ptr_t(&::smart_pointers::base::get_some_value) ) , bp::default_call_policies() , "documentation" ); } base_exposer.def_readwrite( "base_value", &smart_pointers::base::base_value, "documentation" ); bp::register_ptr_to_python< std::auto_ptr< smart_pointers::base > >(); bp::register_ptr_to_python< boost::shared_ptr< smart_pointers::base > >(); } { //::smart_pointers::data typedef bp::class_< data_wrapper, bp::bases< smart_pointers::base >, boost::shared_ptr< smart_pointers::data > > data_exposer_t; data_exposer_t data_exposer = data_exposer_t( "data", "documentation" ); bp::scope data_scope( data_exposer ); data_exposer.def( bp::init< >("documentation")[bp::default_call_policies()] ); { //::smart_pointers::data::get_some_value typedef int ( ::smart_pointers::data::*function_ptr_t )( ) ; typedef int ( data_wrapper::*default_function_ptr_t )( ) ; data_exposer.def( "get_some_value" , function_ptr_t(&::smart_pointers::data::get_some_value) , default_function_ptr_t(&data_wrapper::default_get_some_value) , bp::default_call_policies() ); } { //::smart_pointers::data::get_value typedef int ( ::smart_pointers::data::*function_ptr_t )( ) ; typedef int ( data_wrapper::*default_function_ptr_t )( ) ; data_exposer.def( "get_value" , function_ptr_t(&::smart_pointers::data::get_value) , default_function_ptr_t(&data_wrapper::default_get_value) , bp::default_call_policies() ); } data_exposer.def_readwrite( "value", &smart_pointers::data::value, "documentation" ); bp::register_ptr_to_python< std::auto_ptr< smart_pointers::data > >(); bp::implicitly_convertible< std::auto_ptr< smart_pointers::data >, std::auto_ptr< smart_pointers::base > >(); bp::implicitly_convertible< boost::shared_ptr< smart_pointers::data >, boost::shared_ptr< smart_pointers::base > >(); } { //::smart_pointers::const_ref_auto typedef int ( *function_ptr_t )( ::smart_pointers::data_a_ptr const & ); bp::def( "const_ref_auto" , function_ptr_t( &::smart_pointers::const_ref_auto ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::const_ref_auto_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr const & ); bp::def( "const_ref_auto_base_value" , function_ptr_t( &::smart_pointers::const_ref_auto_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::const_ref_auto_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr const & ); bp::def( "const_ref_auto_some_value" , function_ptr_t( &::smart_pointers::const_ref_auto_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::const_ref_shared typedef int ( *function_ptr_t )( ::smart_pointers::data_s_ptr const & ); bp::def( "const_ref_shared" , function_ptr_t( &::smart_pointers::const_ref_shared ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::const_ref_shared_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr const & ); bp::def( "const_ref_shared_base_value" , function_ptr_t( &::smart_pointers::const_ref_shared_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::const_ref_shared_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr const & ); bp::def( "const_ref_shared_some_value" , function_ptr_t( &::smart_pointers::const_ref_shared_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::create_auto typedef ::smart_pointers::data_a_ptr ( *function_ptr_t )( ); bp::def( "create_auto" , function_ptr_t( &::smart_pointers::create_auto ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::create_shared typedef ::smart_pointers::data_s_ptr ( *function_ptr_t )( ); bp::def( "create_shared" , function_ptr_t( &::smart_pointers::create_shared ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_auto typedef int ( *function_ptr_t )( ::smart_pointers::data_a_ptr & ); bp::def( "ref_auto" , function_ptr_t( &::smart_pointers::ref_auto ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_auto_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr & ); bp::def( "ref_auto_base_value" , function_ptr_t( &::smart_pointers::ref_auto_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_auto_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr & ); bp::def( "ref_auto_some_value" , function_ptr_t( &::smart_pointers::ref_auto_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_shared typedef int ( *function_ptr_t )( ::smart_pointers::data_s_ptr & ); bp::def( "ref_shared" , function_ptr_t( &::smart_pointers::ref_shared ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_shared_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr & ); bp::def( "ref_shared_base_value" , function_ptr_t( &::smart_pointers::ref_shared_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::ref_shared_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr & ); bp::def( "ref_shared_some_value" , function_ptr_t( &::smart_pointers::ref_shared_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_auto typedef int ( *function_ptr_t )( ::smart_pointers::data_a_ptr ); bp::def( "val_auto" , function_ptr_t( &::smart_pointers::val_auto ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_auto_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr ); bp::def( "val_auto_base_value" , function_ptr_t( &::smart_pointers::val_auto_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_auto_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_a_ptr ); bp::def( "val_auto_some_value" , function_ptr_t( &::smart_pointers::val_auto_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_shared typedef int ( *function_ptr_t )( ::smart_pointers::data_s_ptr ); bp::def( "val_shared" , function_ptr_t( &::smart_pointers::val_shared ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_shared_base_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr ); bp::def( "val_shared_base_value" , function_ptr_t( &::smart_pointers::val_shared_base_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } { //::smart_pointers::val_shared_some_value typedef int ( *function_ptr_t )( ::smart_pointers::base_s_ptr ); bp::def( "val_shared_some_value" , function_ptr_t( &::smart_pointers::val_shared_some_value ) , ( bp::arg("a") ) , bp::default_call_policies() , "documentation" ); } } From roman.yakovenko at gmail.com Wed Aug 9 08:16:56 2006 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 9 Aug 2006 09:16:56 +0300 Subject: [C++-sig] can't build boost.python under msys/windows In-Reply-To: <32822fe60608081555l6032f232n91c55689f3d3c362@mail.gmail.com> References: <32822fe60608051032o4993e584r864d5cb1d75a0807@mail.gmail.com> <32822fe60608081555l6032f232n91c55689f3d3c362@mail.gmail.com> Message-ID: <7465b6170608082316s520d3dof3bab1eead77ce02@mail.gmail.com> I suggest you to ask the question to bjam mailing list. I am sure they will be able to help you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From eduardo.picado at gmail.com Wed Aug 9 14:15:28 2006 From: eduardo.picado at gmail.com (Eduardo Picado) Date: Wed, 9 Aug 2006 14:15:28 +0200 Subject: [C++-sig] boost python liking problems In-Reply-To: References: <6c75ff8f0607280627t1e86f90bicefbfd1344567fe3@mail.gmail.com> Message-ID: <6c75ff8f0608090515r296fd051w4a0ea08bb300020a@mail.gmail.com> On 7/28/06, David Abrahams wrote: > "Eduardo Picado" writes: > > > I'm trying to use Boost Python to wrap a 3rd party library. I have the > > headers, DLLs and a .lib file. > > When I try to compile my .cpp files I receive linkage errors: > > Surely this is when you try to link your shared objects... > > > ------------- > > Creating library > > bin\telismaPyste\TASRNlSmlResult.pyd\msvc\debug\threading-multi\TASRNlSmlResult.lib > > and object bin\telismaPyste\TASRNlSmlResult.pyd\msvc\debug\threading-multi\TASRNlSmlResult.exp > > TASRNlSmlResult.obj : error LNK2001: unresolved external symbol > > "public: char const * __thiscall TASRNlSmlResult::str(void)const " > > (?str at TASRNlSmlResult@@QBEPBDXZ) > > Are you sure you didn't just forget to define the member function > > TASRNlSmlResult::str() const > > as denoted in the error message? The message gives the impression > that it's supposed to be part of your code. If not, > > extension TASRNlSmlResult > : # sources > whatever.cpp > > # requirements and dependencies for Boost.Python extensions >