From bidihall at gmail.com Sun Jan 3 06:12:03 2010 From: bidihall at gmail.com (Blair Hall) Date: Sun, 3 Jan 2010 18:12:03 +1300 Subject: [C++-sig] boost.build or distutils? Message-ID: <37e118f61001022112t20b1e389x1166817a19c7732c@mail.gmail.com> I have recently built a Python module using Boost.Python that gives me access to a library of C++ classes and functions. It works very nicely :-) Now I would like to be able to distribute it to friends, etc. I am confused about the best way to do this. I am happy to use bjam to build the extension module. I am working on Windows and have the MSVC9 Express compiler. I also have Python 2.5.4 installed. Is there some way to use distutils to build a windows installer that will simply place my binaries in the correct location on a target machine (which we will assume is also Windows and has some version of Python 2.5.x installed)? As far as I can see, distutils is used to build the extension again and I have not had success with this so far (probably need to upgrade to Python 2.6). It seems silly to be struggling with this problem when bjam can do the the build without problems. Can anyone offer advice on how I should proceed? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sipickles at googlemail.com Mon Jan 4 14:53:41 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Mon, 04 Jan 2010 13:53:41 +0000 Subject: [C++-sig] Boost Python Tuple - Find length of tuple? Message-ID: <4B41F2E5.6060002@googlemail.com> Hello, I have a simple question. How do I find out in c++ how many elements are contained within a boost::python::tuple? I tried this: using namespace boost::python; tuple a = make_tuple("hello", 42); object b = a.attr("length"); // exception unsigned int c = extract(b); assert( c==2 ); AttributeError: 'tuple' object has no attribute 'length' Am I missing something? Thanks Si From brokenn at gmail.com Mon Jan 4 15:02:13 2010 From: brokenn at gmail.com (Brian O'Kennedy) Date: Mon, 4 Jan 2010 14:02:13 +0000 Subject: [C++-sig] Boost Python Tuple - Find length of tuple? In-Reply-To: <4B41F2E5.6060002@googlemail.com> References: <4B41F2E5.6060002@googlemail.com> Message-ID: You could try this instead: (untested!) using namespace boost::python; tuple a = make_tuple("hello", 42); std::cout << "Length = " << boost::python::len(a) << std::endl; // explicit namespace not needed hth, Brian 2010/1/4 Simon Pickles > Hello, > > I have a simple question. How do I find out in c++ how many elements are > contained within a boost::python::tuple? > > I tried this: > > using namespace boost::python; > tuple a = make_tuple("hello", 42); > object b = a.attr("length"); // exception > unsigned int c = extract(b); > assert( c==2 ); > > AttributeError: 'tuple' object has no attribute 'length' > > Am I missing something? > > Thanks > > Si > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Mon Jan 4 15:08:39 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 04 Jan 2010 09:08:39 -0500 Subject: [C++-sig] Boost Python Tuple - Find length of tuple? In-Reply-To: <4B41F2E5.6060002@googlemail.com> References: <4B41F2E5.6060002@googlemail.com> Message-ID: <4B41F667.40900@sympatico.ca> On 01/04/2010 08:53 AM, Simon Pickles wrote: > Hello, > > I have a simple question. How do I find out in c++ how many elements > are contained within a boost::python::tuple? > > I tried this: > > using namespace boost::python; > tuple a = make_tuple("hello", 42); > object b = a.attr("length"); // exception > unsigned int c = extract(b); > assert( c==2 ); > > AttributeError: 'tuple' object has no attribute 'length' > > Am I missing something? The attribute is spelled "__len__", not "length", and the pythonic way to call it is "len(a)". Thus: tuple a = ...; unsigned int c = len(a); should work fine. Stefan -- ...ich hab' noch einen Koffer in Berlin... From sipickles at googlemail.com Mon Jan 4 15:24:50 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Mon, 04 Jan 2010 14:24:50 +0000 Subject: [C++-sig] Boost Python Tuple - Find length of tuple? In-Reply-To: References: <4B41F2E5.6060002@googlemail.com> Message-ID: <4B41FA32.8070004@googlemail.com> On 04/01/2010 14:02, Brian O'Kennedy wrote: > You could try this instead: (untested!) > > using namespace boost::python; > tuple a = make_tuple("hello", 42); > std::cout << "Length = " << boost::python::len(a) << std::endl; > // explicit namespace not needed > > Thanks, thats perfect. -------------- next part -------------- An HTML attachment was scrubbed... URL: From blp330 at msn.com Tue Jan 5 07:50:04 2010 From: blp330 at msn.com (blp330) Date: Mon, 4 Jan 2010 22:50:04 -0800 (PST) Subject: [C++-sig] [boost.python] How can I link against certain python version? Message-ID: <26984580.post@talk.nabble.com> Hi, I try to upgrade my boost from 1.36 to 1.41, but it will link against python26.lib. My own python version is 2.5, How can I tell boost to link with python25.lib? Thanks. -- View this message in context: http://old.nabble.com/-boost.python--How-can-I-link-against-certain-python-version--tp26984580p26984580.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From blake at hailmail.net Tue Jan 5 15:09:50 2010 From: blake at hailmail.net (Dane Springmeyer) Date: Tue, 5 Jan 2010 06:09:50 -0800 Subject: [C++-sig] [boost.python] How can I link against certain python version? In-Reply-To: <26984580.post@talk.nabble.com> References: <26984580.post@talk.nabble.com> Message-ID: <567C0133-C413-4713-AF48-CEFB655E62A0@hailmail.net> On Jan 4, 2010, at 10:50 PM, blp330 wrote: > > Hi, > > I try to upgrade my boost from 1.36 to 1.41, but it will link against > python26.lib. > > My own python version is 2.5, > > How can I tell boost to link with python25.lib? > What operating system are you on? Mac OS X? Generally, I on Mac OSX I set up a user-config.jam file and then point to it using the bjam options: bjam --with-python --ignore-site-config --user-config=user-config.jam toolset=darwin -d2 My 'user-config.jam' is based on the template that looks like this: import option ; import feature ; if ! darwin in [ feature.values ] { using darwin ; } project : default-build darwin ; using python : %(num)s # version : %(system)s/Library/Frameworks/Python.framework/Versions/% (num)s/bin/python%(num)s # cmd-or-prefix : %(system)s/Library/Frameworks/Python.framework/Versions/% (num)s/include/python%(num)s # includes : %(system)s/Library/Frameworks/Python.framework/Versions/% (num)s/lib/python%(num)s/config # a lib actually symlink : darwin # condition ; libraries = --with-python ; If it turns out you are on Mac OSX I can explain those variables in the '%()s' syntax a bit more - they are not for bjam but just where you might change info depending on which python version you want to link against. Dane From nico_ml at mgdesign.org Tue Jan 5 18:26:27 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Tue, 05 Jan 2010 18:26:27 +0100 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) Message-ID: <4B437643.5000103@mgdesign.org> An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: boost_python_calling_conventions.patch URL: From renatox at gmail.com Tue Jan 5 18:51:12 2010 From: renatox at gmail.com (Renato Araujo) Date: Tue, 5 Jan 2010 14:51:12 -0300 Subject: [C++-sig] Avoid Implicitly conversion for non direct conversion Message-ID: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> Hi guys, I'm trying use the "implicitly_convertible" to specify to boost.python the possible conversions for every type, but I start get some errors in my functions call because, the boost.python accept conversions in more then one level. Like in this code: The boost.python allow me to call the function "value" passing "int" as argument type. Because "int" is implicitly convertible to "X" and "X" is implicitly convertible to "Y". This make a mess in my functions because boost try converter the values before try other functions and call the wrong functions. I would like to know if is possible to avoid this level of conversion and tell to boost.python only try the direct conversion, because this make the functions call slower then normal calls, and some times cause a lot of problems in my classes. ------------------------------- #include #include #include #include using namespace boost::python; struct X { X(int x) : v(x) {} int v; }; struct Y { Y(const X& w) : v(w.v) {} int v; }; int value(Y const& x) { return x.v; } BOOST_PYTHON_MODULE(implicit_ext) { def("value", value); class_("X", init()) ; class_("Y", init()) ; implicitly_convertible(); implicitly_convertible(); } --------------------------------------- BR Renato Araujo Oliveira Filho From Terry.Rankine at csiro.au Wed Jan 6 07:50:42 2010 From: Terry.Rankine at csiro.au (Terry.Rankine at csiro.au) Date: Wed, 6 Jan 2010 14:50:42 +0800 Subject: [C++-sig] boost 1.41 and autolink (maybe the wrong list) Message-ID: <4E88C091A57493498EEC9F2A21D5BF4321AECF0923@EXWA-MBX01.nexus.csiro.au> I have compiled boost, and now want to use it in my python app but I am having trouble with autolink.hpp in my c++ files. C:\source\esys13>cl /Fo.sconf_temp\conftest_4.obj /c .sconf_temp\conftest_4.cpp /TP /nologo /IC:\python26\include "/IC: \source\boost_1_41_0" conftest_4.cpp C:\source\boost_1_41_0\boost/config/auto_link.hpp(297) : fatal error C1189: #error : "Mixing a dll boost library with a static runtime is a really bad idea..." I haven't done any linking at this point - I am just trying to compile. Here is my test file. .sconf_temp\conftest_4.cpp: #include "boost/python.hpp" Yep - just the include and thats it. VS2008, and python 2.6 Any ideas what I am doing wrong? Terry Rankine -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans_meine at gmx.net Wed Jan 6 08:59:40 2010 From: hans_meine at gmx.net (Hans Meine) Date: Wed, 6 Jan 2010 08:59:40 +0100 Subject: [C++-sig] Avoid Implicitly conversion for non direct conversion In-Reply-To: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> References: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> Message-ID: <201001060859.42133.hans_meine@gmx.net> On Dienstag 05 Januar 2010, Renato Araujo wrote: > I would like to know if is possible to avoid this level of conversion > and tell to boost.python only try the direct conversion, Not as far as I know. > because this > make the functions call slower then normal calls, But only if you pass objects that need to be converted, right? > and some times cause > a lot of problems in my classes. Details? You might have problems with overloaded functions, in which case Troy's recently suggested BPL extension would most likely help. (I am looking forward to its integration). Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From sipickles at googlemail.com Wed Jan 6 12:50:10 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Wed, 06 Jan 2010 11:50:10 +0000 Subject: [C++-sig] boost 1.41 and autolink (maybe the wrong list) In-Reply-To: <4E88C091A57493498EEC9F2A21D5BF4321AECF0923@EXWA-MBX01.nexus.csiro.au> References: <4E88C091A57493498EEC9F2A21D5BF4321AECF0923@EXWA-MBX01.nexus.csiro.au> Message-ID: <4B4478F2.5070508@googlemail.com> Hello Terry, Try this: .sconf_temp\conftest_4.cpp: #define BOOST_PYTHON_DYN_LINK #include "boost/python.hpp" This will make boost look for shared library in the autolink feature Si On 06/01/2010 06:50, Terry.Rankine at csiro.au wrote: > > I have compiled boost, and now want to use it in my python app but I > am having trouble with autolink.hpp in my c++ files. > > C:\source\esys13>cl /Fo.sconf_temp\conftest_4.obj /c > .sconf_temp\conftest_4.cpp /TP /nologo > > /IC:\python26\include "/IC: \source\boost_1_41_0" > > conftest_4.cpp > > C:\source\boost_1_41_0\boost/config/auto_link.hpp(297) : fatal error > C1189: #error : "Mixing a dll boost > > library with a static runtime is a really bad idea..." > > I haven't done any linking at this point -- I am just trying to compile. > > Here is my test file. > > .sconf_temp\conftest_4.cpp: > > #include "boost/python.hpp" > > Yep -- just the include and thats it. > > VS2008, and python 2.6 > > Any ideas what I am doing wrong? > > Terry Rankine > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From renatox at gmail.com Wed Jan 6 14:10:02 2010 From: renatox at gmail.com (Renato Araujo) Date: Wed, 6 Jan 2010 10:10:02 -0300 Subject: [C++-sig] Avoid Implicitly conversion for non direct conversion In-Reply-To: <201001060859.42133.hans_meine@gmx.net> References: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> <201001060859.42133.hans_meine@gmx.net> Message-ID: <95291a81001060510v1ed7c6bdy741e6334eabe8c59@mail.gmail.com> Hi thanks for you help, On Wed, Jan 6, 2010 at 4:59 AM, Hans Meine wrote: > On Dienstag 05 Januar 2010, Renato Araujo wrote: >> I would like to know if is possible to avoid this level of conversion >> and tell to boost.python only try the direct conversion, > > Not as far as I know. > >> because this >> make the functions call slower then normal calls, > > But only if you pass objects that need to be converted, right? Yes but this is the user level I would like to avoid this. > >> and some times cause >> a lot of problems in my classes. > > Details? I'm working on PySide (python bindings for Qt), and I have a lot of classes and a lot of implicitly conversions. Example: I have a class QVariant (Docs: http://doc.trolltech.com/4.6/qvariant.html) with many constructos, adn each type has your implicitly conversion rule. One example is QCorlor (Docs: http://doc.trolltech.com/4.6/qcolor.html) this is implicitly conversible from "int". Then when I create a QVariant(1) (passing int as argument) boost.python call the QVariant(QColor) constructor. I think this happening because boost.python try the implicitly conversion before verify the other basics signatures. This is one of the case I have a lot of others because I have more then 100 classes and more then 200 implicitly conversions rules, it's almost impossible to me, manager this if the conversion can happen in every class level. > > You might have problems with overloaded functions, in which case Troy's > recently suggested BPL extension would most likely help. ?(I am looking > forward to its integration). Where I can get more info about this I searched in ML but I did not find any info related. > > Ciao, / ?/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.o. > ? ? /--/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..o > ? ?/ ?/ ANS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ooo Thanks From troy at resophonic.com Wed Jan 6 16:09:54 2010 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 06 Jan 2010 10:09:54 -0500 Subject: [C++-sig] Avoid Implicitly conversion for non direct conversion In-Reply-To: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> References: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> Message-ID: <4B44A7C2.2060306@resophonic.com> Renato Araujo wrote: > Hi guys, > > I'm trying use the "implicitly_convertible" to specify to boost.python > the possible conversions for every type, but I start get some errors > in my functions call because, the boost.python accept conversions in > more then one level. Like in this code: > > The boost.python allow me to call the function "value" passing "int" > as argument type. Because "int" is implicitly convertible to "X" and > "X" is implicitly convertible to "Y". > This make a mess in my functions because boost try converter the > values before try other functions and call the wrong functions. > > I would like to know if is possible to avoid this level of conversion > and tell to boost.python only try the direct conversion, because this > make the functions call slower then normal calls, and some times cause > a lot of problems in my classes. > > > > ------------------------------- > #include > #include > #include > #include > > using namespace boost::python; > > struct X > { > X(int x) : v(x) {} > int v; > }; > > struct Y > { > Y(const X& w) : v(w.v) {} > int v; > }; > > int value(Y const& x) > { > return x.v; > } > > BOOST_PYTHON_MODULE(implicit_ext) > { > def("value", value); > > class_("X", > init()) > ; > > class_("Y", > init()) > ; > > implicitly_convertible(); > implicitly_convertible(); > } > --------------------------------------- > Hi, I'm in a rather elliptical orbit at the moment but should be coming back around soon. I'll have a look at this: if we're going to attempt to fix overloading, we might as well try to make boost.python obey the c++ rule of 'no more than 1 user-defined conversion in a row'. Renato, the overloading stuff mentioned by Hans is in a thread titled "Implementation of proper overload resolution" on this list. -t From troy at resophonic.com Wed Jan 6 16:10:54 2010 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 06 Jan 2010 10:10:54 -0500 Subject: [C++-sig] function types as user-defined converters In-Reply-To: <200912282143.58716.lists_ravi@lavabit.com> References: <55154.65.220.96.226.1257193994.squirrel@lavabit.com> <4AF47E91.9070503@resophonic.com> <200912282143.58716.lists_ravi@lavabit.com> Message-ID: <4B44A7FE.10408@resophonic.com> Ravi wrote: > On Friday 06 November 2009 14:52:49 troy d. straszheim wrote: >> Currently, the converter type still leaks out to python in the signature: >> >> class S(Boost.Python.instance) >> | add(...) >> | add( (S)arg1, (object)arg2) -> None : >> | >> | C++ signature : >> | void add(S*,to_optional >> (*)(boost::python::api::object)) >> >> >> converters won't nest: >> >> def("foo", as(&somefn)); // nah >> >> I dont have a mechanism for hooking a user defined converter into the >> return type. I'm going to have to think about that one a bit more. > > Did you have any ideas on this, Troy? This is the last bit I think I'd need in > order to replace my code with yours. > Hi Ravi, I haven't looked, I got pulled away. I hope to be back to this soon though. -t From hans_meine at gmx.net Wed Jan 6 16:17:45 2010 From: hans_meine at gmx.net (Hans Meine) Date: Wed, 6 Jan 2010 16:17:45 +0100 Subject: [C++-sig] Avoid Implicitly conversion for non direct conversion In-Reply-To: <95291a81001060510v1ed7c6bdy741e6334eabe8c59@mail.gmail.com> References: <95291a81001050951u62329b80v7f9dd6d994d80426@mail.gmail.com> <201001060859.42133.hans_meine@gmx.net> <95291a81001060510v1ed7c6bdy741e6334eabe8c59@mail.gmail.com> Message-ID: <201001061617.46520.hans_meine@gmx.net> Am Mittwoch, 06. Januar 2010 14:10:02 schrieb Renato Araujo: > On Wed, Jan 6, 2010 at 4:59 AM, Hans Meine wrote: > > But only if you pass objects that need to be converted, right? > > Yes but this is the user level I would like to avoid this. Ah, you fear users saying "PySide is slow" because they're unknowingly using implicit conversions? How slow is this really? IMO BPL method calls are not blazingly fast anyway, since there is a lot of stuff happening at runtime, so one should not try to call millions of methods in the first place. I am not convinced there's a problem, so maybe you could try to ignore it for now. > I have a class QVariant (Docs: > http://doc.trolltech.com/4.6/qvariant.html) with many constructos, adn > each type has your implicitly conversion rule. > One example is QCorlor (Docs: > http://doc.trolltech.com/4.6/qcolor.html) this is implicitly > conversible from "int". > > Then when I create a QVariant(1) (passing int as argument) > boost.python call the QVariant(QColor) constructor. I think this > happening because boost.python try the implicitly conversion before > verify the other basics signatures. Yes, but here the implicit conversion is not the problem IMO, but the fact that BPL tries the overloaded functions one-by-one and uses the first matching, instead of the "best" one. > This is one of the case I have a > lot of others because I have more then 100 classes and more then 200 > implicitly conversions rules, it's almost impossible to me, manager > this if the conversion can happen in every class level. I see, this is exactly the problem that I had in mind when I wrote about the overloading problem. (Without overloading, implicit conversion should not bug you, right?) > > You might have problems with overloaded functions, in which case Troy's > > recently suggested BPL extension would most likely help. (I am looking > > forward to its integration). > > Where I can get more info about this I searched in ML but I did not > find any info related. Cf. recent thread "Implementation of proper overload resolution". HTH, Hans From renatox at gmail.com Wed Jan 6 17:42:59 2010 From: renatox at gmail.com (Renato Araujo) Date: Wed, 6 Jan 2010 13:42:59 -0300 Subject: [C++-sig] Implementation of proper overload resolution In-Reply-To: <874onjd67y.fsf@resophonic.com> References: <87aaxha8ih.fsf@resophonic.com> <0EFC2868-BA76-4E73-8DF2-075C2D73ABD9@hailmail.net> <9D77FF39-BA7A-476F-9CBF-48009A1D7919@hailmail.net> <874onjd67y.fsf@resophonic.com> Message-ID: <95291a81001060842i68c59b00we79150aca3620301@mail.gmail.com> This is great, I will try this, but I'm afraid about the size, because my main problem with boost.python is the library size compared to others c++ python bindings, my current library has 16 MB compared to 5 MB from SIP, and in my bindings I have a lot of overload functions and this solution can produce some new bytes. :( Renato Araujo Oliveira Filho On Tue, Dec 22, 2009 at 12:42 AM, Troy D. Straszheim wrote: > Dane Springmeyer writes: > >> Troy, >> >> Incidentally, do you know the proper way ?(or is there a proper way?) >> to support None type keyword arguments? >> >> Cheers, >> >> Dane >> > > Could you elaborate? ?What're you trying to do? > > -t > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From nico_ml at mgdesign.org Wed Jan 6 18:09:18 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Wed, 06 Jan 2010 18:09:18 +0100 Subject: [C++-sig] boost 1.41 and autolink (maybe the wrong list) In-Reply-To: <4E88C091A57493498EEC9F2A21D5BF4321AECF0923@EXWA-MBX01.nexus.csiro.au> References: <4E88C091A57493498EEC9F2A21D5BF4321AECF0923@EXWA-MBX01.nexus.csiro.au> Message-ID: <4B44C3BE.1090606@mgdesign.org> An HTML attachment was scrubbed... URL: From tim at tizmoi.net Wed Jan 6 23:33:33 2010 From: tim at tizmoi.net (Tim Couper) Date: Wed, 06 Jan 2010 22:33:33 +0000 Subject: [C++-sig] Boost-python wrapping a vector of vectors? Message-ID: <4B450FBD.4040104@tizmoi.net> I'm trying to boost-python a vector-of-vectors, like class A { public A(const std::vector>& my_array); }; and would intuitively write the wrapper: BOOST_PYTHON_MODULE(foo) { using namespace boost::python class_("A") .def(init(std::vector >()) ; but get the error "a call to a constructor cannot appear in a constant expression" Can anyone supply any guidance as to how to wrap this? Thanks Tim Dr Tim Couper -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Thu Jan 7 00:16:26 2010 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 06 Jan 2010 18:16:26 -0500 Subject: [C++-sig] Boost-python wrapping a vector of vectors? In-Reply-To: <4B450FBD.4040104@tizmoi.net> References: <4B450FBD.4040104@tizmoi.net> Message-ID: <4B4519CA.4040502@resophonic.com> Tim Couper wrote: > > I'm trying to boost-python a vector-of-vectors, like > > class A > { > public > A(const std::vector>& my_array); > }; > > and would intuitively write the wrapper: > > BOOST_PYTHON_MODULE(foo) > { > using namespace boost::python > > class_("A") > .def(init(std::vector >()) > ; > > but get the error "a call to a constructor cannot appear in a constant > expression" Syntax error, init takes a type argument: init() -t From tim at tizmoi.net Thu Jan 7 10:21:50 2010 From: tim at tizmoi.net (Tim Couper) Date: Thu, 07 Jan 2010 09:21:50 +0000 Subject: [C++-sig] Boost-python wrapping a vector of vectors? In-Reply-To: <4B4519CA.4040502@resophonic.com> References: <4B450FBD.4040104@tizmoi.net> <4B4519CA.4040502@resophonic.com> Message-ID: <4B45A7AE.3030805@tizmoi.net> Troy Thanks for the prompt reply .. I'm a python expert and a C++ novice ... Apologies for not getting this ... I've seen I can define a python mapping using the vector_indexing suite class_< std::vector< std::vector > >("vector_double2") .def(vector_indexing_suite > > but I can't see how to get that information into the init argument in the C++ class_("A") .def(init( )) as vector_double2 isn't known when the c++ compiles, so this clearly isn't the "type" argument to which you refer. Clearly there's something I'm missing. How do I define a type? Should I be using the named constructors/factories described in http://wiki.python.org/moin/boost.python/HowTo? If so how? Thanks again Tim On 06/01/2010 23:16, troy d. straszheim wrote: > Tim Couper wrote: >> >> I'm trying to boost-python a vector-of-vectors, like >> >> class A >> { >> public >> A(const std::vector>& my_array); >> }; >> >> and would intuitively write the wrapper: >> >> BOOST_PYTHON_MODULE(foo) >> { >> using namespace boost::python >> >> class_("A") >> .def(init(std::vector >()) >> ; >> >> but get the error "a call to a constructor cannot appear in a >> constant expression" > > Syntax error, init takes a type argument: init() > > -t > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.725 / Virus Database: 270.14.127/2603 - Release Date: 01/06/10 07:35:00 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at tizmoi.net Thu Jan 7 11:21:11 2010 From: tim at tizmoi.net (Tim Couper) Date: Thu, 07 Jan 2010 10:21:11 +0000 Subject: [C++-sig] Boost-python wrapping a vector of vectors? In-Reply-To: <4B45A7AE.3030805@tizmoi.net> References: <4B450FBD.4040104@tizmoi.net> <4B4519CA.4040502@resophonic.com> <4B45A7AE.3030805@tizmoi.net> Message-ID: <4B45B597.3050909@tizmoi.net> Ah I understand .. so will reply to my own posting for others new to pb ... C++ constructors with one argument behave differently I understand, so taking a 2 argument case: class A { public A(int i, const std::vector>& my_array); }; In the BOOST_PYTHON_MODULE(foo) .. define a type using typedef: typedef std::vector > double_trouble; and add the python wrappers we're going to need - one for wrapping a vector of doubles, and one for the vector of vectors .. class_ > > ("v2_double") .def(vector_indexing_suite > >()); class_ > ("v_double") .def(vector_indexing_suite >()); now define the constructor like Troy said .. class_("A") .def(init()) ; bjam this lot and we then can write out nosetest tests: def test_v_double(): v = foo.v_double() v[:] = [1.4,2.5] assert_equals(len(v),2) assert_almost_equal(v[0],1.4) def test_v2_double(): v2 = foo.v2_double() v1a = foo.v_double() v2a = foo.v_double() v1a[:] = [1.4, 2.5, 5.6] v2a[:] = [3.4, 2.8, 7.8, 12.5] v2[:] = [v1a,v2a] assert_equals(len(v2),2) assert_almost_equal(v2[0][0],1.4) def test_A(): v2 = foo.v2_double() v1a = foo.v_double() v2a = foo.v_double() v1a[:] = [1.4, 2.5, 5.6] v2a[:] = [3.4, 2.8, 7.8, 12.5] v2[:] = [v1a,v2a] res = foo.A(1, v2) assert isinstance(res, foo.A) and there we have it .. I'll be back ... :-) Tim On 07/01/2010 09:21, Tim Couper wrote: > Troy > > Thanks for the prompt reply .. I'm a python expert and a C++ novice > ... Apologies for not getting this ... > > I've seen I can define a python mapping using the vector_indexing suite > > class_< std::vector< std::vector > >("vector_double2") > .def(vector_indexing_suite > > > > but I can't see how to get that information into the init argument in > the C++ > > class_("A") > .def(init( )) > > as vector_double2 isn't known when the c++ compiles, so this clearly > isn't the "type" argument to which you refer. Clearly there's > something I'm missing. How do I define a type? Should I be using the > named constructors/factories described in > http://wiki.python.org/moin/boost.python/HowTo? If so how? > > Thanks again > > Tim > > > > > > > On 06/01/2010 23:16, troy d. straszheim wrote: >> Tim Couper wrote: >>> >>> I'm trying to boost-python a vector-of-vectors, like >>> >>> class A >>> { >>> public >>> A(const std::vector>& my_array); >>> }; >>> >>> and would intuitively write the wrapper: >>> >>> BOOST_PYTHON_MODULE(foo) >>> { >>> using namespace boost::python >>> >>> class_("A") >>> .def(init(std::vector >()) >>> ; >>> >>> but get the error "a call to a constructor cannot appear in a >>> constant expression" >> >> Syntax error, init takes a type argument: init() >> >> -t >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> >> >> No virus found in this incoming message. >> Checked by AVG -www.avg.com >> Version: 9.0.725 / Virus Database: 270.14.127/2603 - Release Date: 01/06/10 07:35:00 >> >> > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.725 / Virus Database: 270.14.128/2604 - Release Date: 01/06/10 19:35:00 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From blp330 at msn.com Thu Jan 7 13:13:19 2010 From: blp330 at msn.com (blp330) Date: Thu, 7 Jan 2010 04:13:19 -0800 (PST) Subject: [C++-sig] [boost.python] How can I link against certain python version? In-Reply-To: <567C0133-C413-4713-AF48-CEFB655E62A0@hailmail.net> References: <26984580.post@talk.nabble.com> <567C0133-C413-4713-AF48-CEFB655E62A0@hailmail.net> Message-ID: <27059056.post@talk.nabble.com> Thank you. But my operating system is Windows. :p I am sorry I didn't describe my problem clearly. I am using boostpro's compiled binary. I defined BOOST_PYTHON_STATIC_LIB. Visual Studio will try to link python25.lib automatically in 1.36. Now, I don't know how to make it still link against python25.lib after upgrade to 1.41. Thanks. -- View this message in context: http://old.nabble.com/-boost.python--How-can-I-link-against-certain-python-version--tp26984580p27059056.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From dwwkelly at gmail.com Sat Jan 9 19:52:48 2010 From: dwwkelly at gmail.com (devin kelly) Date: Sat, 9 Jan 2010 13:52:48 -0500 Subject: [C++-sig] Exposing C++ data with Boost.Python Message-ID: Hello, I'm trying to expose some data that I develop in C++ to python. Basically, the reverse of this sample code: #include #include #include #include int main(){ Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); ignored = exec("result = 5 ** 2", main_namespace); int five_squared = extract(main_namespace["result"]); std::cout << five_squared << std::endl; return 0; } So this code starts the python interpreter, squares 5 (in python) and then extracts the result to an int called five_squared. This works fine for me, it's basically an example straight out of the boost.python webpage. What I'd really like to do though is have an int that I initialize in C++ and then square in python. So this would require me to pass (or expose) that data to python. I've been trying this for a while and have had no luck whatsoever. The best I can think of is code like this: int main(){ Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); main_namespace["num2square"] = 6; ignored = exec("result = num2square ** 2", main_namespace); int five_squared = extract(main_namespace["result"]); std::cout << five_squared << std::endl; return 0; } This doesn't work. Python throws an error. What am I doing wrong?? Thanks for any help, Devin -- http://users.wpi.edu/~dkelly/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Sat Jan 9 20:55:08 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sat, 09 Jan 2010 14:55:08 -0500 Subject: [C++-sig] Exposing C++ data with Boost.Python In-Reply-To: References: Message-ID: <4B48DF1C.9090900@sympatico.ca> On 01/09/2010 01:52 PM, devin kelly wrote: > Hello, > > I'm trying to expose some data that I develop in C++ to python. > Basically, the reverse of this sample code: > > #include > #include > #include > #include > > int main(){ > > Py_Initialize(); > object main_module = import("__main__"); > object main_namespace = main_module.attr("__dict__"); > ignored = exec("result = 5 ** 2", main_namespace); > int five_squared = extract(main_namespace["result"]); > std::cout << five_squared << std::endl; > > return 0; > } > > > So this code starts the python interpreter, squares 5 (in python) and > then extracts the result to an int called five_squared. This works > fine for me, it's basically an example straight out of the > boost.python webpage. > > What I'd really like to do though is have an int that I initialize in > C++ and then square in python. So this would require me to pass (or > expose) that data to python. I've been trying this for a while and > have had no luck whatsoever. The best I can think of is code like this: > > int main(){ > Py_Initialize(); > object main_module = import("__main__"); > object main_namespace = main_module.attr("__dict__"); > main_namespace["num2square"] = 6; > ignored = exec("result = num2square ** 2", main_namespace); > int five_squared = extract(main_namespace["result"]); > std::cout << five_squared << std::endl; > return 0; > } > > This doesn't work. Python throws an error. What am I doing wrong?? It might help indicating what error Python actually throws. Also, if all you want is to evaluate an expression, I'd suggest you use "eval()", not "exec()". Stefan -- ...ich hab' noch einen Koffer in Berlin... From lists_ravi at lavabit.com Sun Jan 10 17:18:25 2010 From: lists_ravi at lavabit.com (Ravi) Date: Sun, 10 Jan 2010 11:18:25 -0500 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <4B437643.5000103@mgdesign.org> References: <4B437643.5000103@mgdesign.org> Message-ID: <201001101118.25701.lists_ravi@lavabit.com> On Tuesday 05 January 2010 12:26:27 Nicolas Lelong wrote: > Is this mailing list the best route to submit this patch, what more work > should be done to get it accepted into trunk ? Please file a trac ticket at svn.boost.org so that this does not get lost. Ravi From dwwkelly at gmail.com Sun Jan 10 18:36:49 2010 From: dwwkelly at gmail.com (devin kelly) Date: Sun, 10 Jan 2010 12:36:49 -0500 Subject: [C++-sig] Exposing C++ data with Boost.Python In-Reply-To: <4B48DF1C.9090900@sympatico.ca> References: <4B48DF1C.9090900@sympatico.ca> Message-ID: Well what I really to do is turn an STL vector into and python list. I want to do this in a separate script, so I don't think eval is right for me. I just started with an int because that's easier. I've gotten that part too, my code looks like this: int main(){ int five_squared=0; int a =3; try { Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); main_namespace["var"]=a; object ignored = exec("result = 5 ** var", main_namespace); five_squared = extract(main_namespace["result"]); } catch( error_already_set ) { PyErr_Print(); } std::cout << five_squared << std::endl; return 0; } This code works just like you expect it to, it prints 5^3 or 125. However I try to change my code to this int main(){ int five_squared=0; std::vector v(2); v[0]=2; v[1]=3; try { Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); main_namespace["var"]=v; object ignored = exec("result = 5 ** var[1]", main_namespace); five_squared = extract(main_namespace["result"]); } catch( error_already_set ) { PyErr_Print(); } std::cout << five_squared << std::endl; return 0; } I want this to print 5^2 or 25. But instead I get this error: TypeError: No to_python (by-value) converter found for C++ type: std::vector > Which makes sense, python doesn't know how to handle stdd::vector. So I have to make something to do this conversion. This is where I'm stuck now, I think I have to do something like this BOOST_PYTHON_MODULE(vector_indexing_suite_ext){ boost::python::class_ >("PyVec") .def(boost::python::vector_indexing_suite >()); } Is this all I need? Do I need to define __getitem__ ? If this is all I need how do I use it in main()? Also does anyone know of any good resources for embedding in boost.python? Thanks! On Sat, Jan 9, 2010 at 2:55 PM, Stefan Seefeld wrote: > On 01/09/2010 01:52 PM, devin kelly wrote: > >> Hello, >> >> I'm trying to expose some data that I develop in C++ to python. >> Basically, the reverse of this sample code: >> >> #include >> #include >> #include >> #include >> >> int main(){ >> >> Py_Initialize(); >> object main_module = import("__main__"); >> object main_namespace = main_module.attr("__dict__"); >> ignored = exec("result = 5 ** 2", main_namespace); >> int five_squared = extract(main_namespace["result"]); >> std::cout << five_squared << std::endl; >> >> return 0; >> } >> >> >> So this code starts the python interpreter, squares 5 (in python) and then >> extracts the result to an int called five_squared. This works fine for me, >> it's basically an example straight out of the boost.python webpage. >> >> What I'd really like to do though is have an int that I initialize in C++ >> and then square in python. So this would require me to pass (or expose) >> that data to python. I've been trying this for a while and have had no luck >> whatsoever. The best I can think of is code like this: >> >> int main(){ >> Py_Initialize(); >> object main_module = import("__main__"); >> object main_namespace = main_module.attr("__dict__"); >> main_namespace["num2square"] = 6; >> ignored = exec("result = num2square ** 2", main_namespace); >> int five_squared = extract(main_namespace["result"]); >> std::cout << five_squared << std::endl; >> return 0; >> } >> >> This doesn't work. Python throws an error. What am I doing wrong?? >> > > It might help indicating what error Python actually throws. > > Also, if all you want is to evaluate an expression, I'd suggest you use > "eval()", not "exec()". > > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- http://users.wpi.edu/~dkelly/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Sun Jan 10 18:53:25 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 10 Jan 2010 12:53:25 -0500 Subject: [C++-sig] Exposing C++ data with Boost.Python In-Reply-To: References: <4B48DF1C.9090900@sympatico.ca> Message-ID: <4B4A1415.6020604@sympatico.ca> On 01/10/2010 12:36 PM, devin kelly wrote: > So I have to make something to do this conversion. This is where I'm > stuck now, I think I have to do something like this > > BOOST_PYTHON_MODULE(vector_indexing_suite_ext){ > boost::python::class_ >("PyVec") > .def(boost::python::vector_indexing_suite > >()); > } > > Is this all I need? Do I need to define __getitem__ ? If this is all > I need how do I use it in main()? You presumably use it just like any other conversion you have defined. Have you looked at http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/indexing.html, and tried it out ? Reading the docs is typically the best way to get started... > > Also does anyone know of any good resources for embedding in boost.python? This list is a good place to ask questions, for anything not covered by the (online) docs. (We may even improve the docs if it turns out something important isn't covered.) Stefan -- ...ich hab' noch einen Koffer in Berlin... From blp330 at msn.com Mon Jan 11 05:05:05 2010 From: blp330 at msn.com (blp330) Date: Sun, 10 Jan 2010 20:05:05 -0800 (PST) Subject: [C++-sig] [boost.python] How can I wrap operator==? Message-ID: <27105703.post@talk.nabble.com> Hi, I want to wrap operator== for my object, Py++ generates that: Document_exposer.def( bp::self != bp::self); Document_exposer.def( bp::self == bp::self ); But I want to do something more, so I try to wrap it with: Document_exposer.def( bp::self != bp::self , &Document__NotEqualWrap ); Document_exposer.def( bp::self == bp::self , &Document__EqualWrap ); It can't be compiled... How can I do? Thanks. -- View this message in context: http://old.nabble.com/-boost.python--How-can-I-wrap-operator%3D%3D--tp27105703p27105703.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From sipickles at googlemail.com Tue Jan 12 09:16:54 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Tue, 12 Jan 2010 08:16:54 +0000 Subject: [C++-sig] Returning a simple char * Message-ID: <4B4C2FF6.7080307@googlemail.com> Hello, I thought I was trying to do something simple. While wrapping a 3rd party library, I have a c++ class with two member function returning pointers like this: class videoInput { public: static char * getDeviceName(int deviceID); .... }; and a module like this: #include "boost//python.hpp" #include "videoInput.h" using namespace boost::python; BOOST_PYTHON_MODULE(pyVideoInput) { class_("videoInput") .def("getDeviceName", &videoInput::getDeviceName, return_value_policy()) .staticmethod("getDeviceName") ; } Following the guide here (http://wiki.python.org/moin/boost.python/PointersAndSmartPointers) I thought this was the right way but I get errors: pyVideoInput.cpp C:\boost_1_41_0\boost/python/object/make_instance.hpp(24) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE ' with [ x=false ] C:\boost_1_41_0\boost/python/to_python_indirect.hpp(95) : see reference to function template instantiation 'PyObject *boos t::python::objects::make_instance_impl::execute(Arg &)' being compiled with [ T=char, Holder=holder_t, Derived=boost::python::objects::make_ptr_instance, Arg=smart_pointer ] .................. pyVideoInput.cpp(16) : see reference to function template instantiation 'boost::python::class_ &boost::python::class_::def>(const char *,A1,const A2 &)' being comp iled with [ W=videoInput, ResultConverterGenerator=boost::python::manage_new_object, A1=char *(__cdecl *)(int), A2=boost::python::return_value_policy ] ////////////////////////// It seems to be attempting to use a smart_ptr? Can anyone help explain this to me? Many thanks Simon From charlessolar at gmail.com Tue Jan 12 16:08:47 2010 From: charlessolar at gmail.com (Charles Solar) Date: Tue, 12 Jan 2010 09:08:47 -0600 Subject: [C++-sig] Member function bp::optional? Or workaround? Message-ID: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> I have a few default parameters in a couple of my member functions, and these functions do not conform to the format required forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD.. I was wondering how to go about creating those thin wrappers for these functions. For example, my class would be something like struct Foo { int bar( const Y* = NULL ); int bar( const X&, const Y* = NULL ); }; -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans_meine at gmx.net Tue Jan 12 20:21:33 2010 From: hans_meine at gmx.net (Hans Meine) Date: Tue, 12 Jan 2010 20:21:33 +0100 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> Message-ID: <201001122021.39062.hans_meine@gmx.net> On Dienstag 12 Januar 2010, Charles Solar wrote: > I have a few default parameters in a couple of my member functions, and > these functions do not conform to the format required > forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD.. I never use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD anyway. You may freely .def'ine multiple overloads yourself. (Or maybe you want to try pyplusplus, if you have many such functions.) -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From charlessolar at gmail.com Tue Jan 12 20:46:10 2010 From: charlessolar at gmail.com (Charles Solar) Date: Tue, 12 Jan 2010 13:46:10 -0600 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <201001122021.39062.hans_meine@gmx.net> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> Message-ID: <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> Well I want to define the overloads myself anyway, I just do not know how to properly setup the small wrapper that will work. In the doc it tells you how to make flat function wrappers, but nothing on member function wrappers. I am unsure how I am supposed to handle the this pointer, for example. So idealy what I would like to know is what the macro does so I can manually write out the wrappers myself. And I have tried using Py++, it does not handle the default argument, it just puts the call in there and python still requires the param to be there. On Tue, Jan 12, 2010 at 1:21 PM, Hans Meine wrote: > On Dienstag 12 Januar 2010, Charles Solar wrote: > > I have a few default parameters in a couple of my member functions, and > > these functions do not conform to the format required > > forBOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD.. > > I never use BOOST_PYTHON_MEMBER_FUNCTION_OVERLOAD anyway. You may > freely .def'ine multiple overloads yourself. (Or maybe you want to try > pyplusplus, if you have many such functions.) > > -- > Ciao, / / .o. > /--/ ..o > / / ANS ooo > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Jan 12 20:55:16 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 12 Jan 2010 21:55:16 +0200 Subject: [C++-sig] [boost.python] How can I wrap operator==? In-Reply-To: <27105703.post@talk.nabble.com> References: <27105703.post@talk.nabble.com> Message-ID: <7465b6171001121155s25319ffbt724aac143530af2f@mail.gmail.com> On Mon, Jan 11, 2010 at 6:05 AM, blp330 wrote: > > Hi, > > I want to wrap operator== for my object, Py++ generates that: > > ? ? ? ?Document_exposer.def( bp::self != bp::self); > ? ? ? ?Document_exposer.def( bp::self == bp::self ); > > But I want to do something more, so I try to wrap it with: > > ? ? ? ?Document_exposer.def( > ? ? ? ? ? ?bp::self != bp::self > ? ? ? ? ? ?, &Document__NotEqualWrap ); > ? ? ? ?Document_exposer.def( > ? ? ? ? ? ?bp::self == bp::self > ? ? ? ? ? ?, &Document__EqualWrap ); > > It can't be compiled... > > How can I do? It is not clear what you are asking for. If the "Document" class has special function for comparison, than may be you can define few global operators ( == and != ). -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From troy at resophonic.com Tue Jan 12 21:01:53 2010 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 12 Jan 2010 15:01:53 -0500 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> Message-ID: <4B4CD531.3060802@resophonic.com> Charles Solar wrote: > Well I want to define the overloads myself anyway, I just do not know > how to properly setup the small wrapper that will work. In the doc it > tells you how to make flat function wrappers, but nothing on member > function wrappers. I am unsure how I am supposed to handle the this > pointer, for example. > So idealy what I would like to know is what the macro does so I can > manually write out the wrappers myself. > > And I have tried using Py++, it does not handle the default argument, it > just puts the call in there and python still requires the param to be there. > Personally I hate that overload-wrapping macro thing. Here's one way to do it: struct T { void bar(int i) { cout << "bar(" << i << ")\n"; } void bar() { cout << "bar\n"; } }; // // use 'self' for 'this' for the sake of pythonicism // void bar_int (T* self, int i) { self->bar(i); } void bar_void(T* self) { self->bar(); } BOOST_PYTHON_MODULE(foop) { class_("T") .def("bar", bar_int) .def("bar", bar_void) ; } -t From charlessolar at gmail.com Tue Jan 12 21:06:28 2010 From: charlessolar at gmail.com (Charles Solar) Date: Tue, 12 Jan 2010 14:06:28 -0600 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <4B4CD531.3060802@resophonic.com> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> <4B4CD531.3060802@resophonic.com> Message-ID: <708326ee1001121206j46e89b7fyf9db1d8c63f93c13@mail.gmail.com> Looks perfect, thanks much. On Tue, Jan 12, 2010 at 2:01 PM, troy d. straszheim wrote: > Charles Solar wrote: > >> Well I want to define the overloads myself anyway, I just do not know how >> to properly setup the small wrapper that will work. In the doc it tells you >> how to make flat function wrappers, but nothing on member function wrappers. >> I am unsure how I am supposed to handle the this pointer, for example. >> So idealy what I would like to know is what the macro does so I can >> manually write out the wrappers myself. >> >> And I have tried using Py++, it does not handle the default argument, it >> just puts the call in there and python still requires the param to be there. >> >> > Personally I hate that overload-wrapping macro thing. Here's one way to do > it: > > struct T > { > void bar(int i) { cout << "bar(" << i << ")\n"; } > void bar() { cout << "bar\n"; } > }; > > // > // use 'self' for 'this' for the sake of pythonicism > // > void bar_int (T* self, int i) { self->bar(i); } > void bar_void(T* self) { self->bar(); } > > BOOST_PYTHON_MODULE(foop) > { > class_("T") > .def("bar", bar_int) > .def("bar", bar_void) > ; > } > > -t > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Jan 12 21:09:53 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 12 Jan 2010 22:09:53 +0200 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> Message-ID: <7465b6171001121209r4dcd8357ra394226080ee4d3@mail.gmail.com> On Tue, Jan 12, 2010 at 9:46 PM, Charles Solar wrote: > And I have tried using Py++, it does not handle the default argument, it > just puts the call in there and python still requires the param to be there. Can you explain what you mean? The following code was generated by Py++: bp::class_< overloads_macro::Foo >( "Foo") .def( "bar" , (int ( ::overloads_macro::Foo::* )( ::overloads_macro::Y const * ) )( &::overloads_macro::Foo::bar ) , ( bp::arg("arg0")=bp::object() ) ) .def( "bar" , (int ( ::overloads_macro::Foo::* )( ::overloads_macro::X const &,::overloads_macro::Y const * ) )( &::overloads_macro::Foo::bar ) , ( bp::arg("arg0"), bp::arg("arg1")=bp::object() ) ); as you can see ( and try ) the generated code does not "requires" the user to pass default arguments. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From hans_meine at gmx.net Tue Jan 12 21:09:39 2010 From: hans_meine at gmx.net (Hans Meine) Date: Tue, 12 Jan 2010 21:09:39 +0100 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> Message-ID: <201001122109.40705.hans_meine@gmx.net> On Dienstag 12 Januar 2010, Charles Solar wrote: > Well I want to define the overloads myself anyway, I just do not know how > to properly setup the small wrapper that will work. Oh, OK. > In the doc it tells > you how to make flat function wrappers, but nothing on member function > wrappers. I am 100% sure that they're documented, yet I am not very lucky with the docs either. > I am unsure how I am supposed to handle the this pointer, for > example. You can reference the member function pointer like this (untested of course): .def("bar", (void(Foo::*)(const Y*))&T::bar) .def("bar", (void(Foo::*)(const X&,const Y*))&T::bar) > So idealy what I would like to know is what the macro does so I can > manually write out the wrappers myself. > > And I have tried using Py++, it does not handle the default argument, it > just puts the call in there and python still requires the param to be > there. Really? AFAIK, it should work. You should be able to write (arg("some_x"), arg("some_y") = NULL)) as extra .def() argument. Maybe py++ does not output the default args when the arguments are unnamed? (I wouldn't know how, either.) -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From charlessolar at gmail.com Tue Jan 12 21:27:41 2010 From: charlessolar at gmail.com (Charles Solar) Date: Tue, 12 Jan 2010 14:27:41 -0600 Subject: [C++-sig] Member function bp::optional? Or workaround? In-Reply-To: <201001122109.40705.hans_meine@gmx.net> References: <708326ee1001120708h62fbaad8hb43db3c5ec37b5cf@mail.gmail.com> <201001122021.39062.hans_meine@gmx.net> <708326ee1001121146n11a748cdj8bbd32e30cfafa61@mail.gmail.com> <201001122109.40705.hans_meine@gmx.net> Message-ID: <708326ee1001121227g49a60babw28c42aa196a1bc53@mail.gmail.com> Hmm, well if the arg definition matters like you two are suggesting it does, then maybe the python code from Py++ does work. Right now it generates code that I use, but I do not include the bp::object, so my function in boost python looks like int (Foo::*bar1)( const Y*) = &Foo::bar; int (Foo::*bar2)(const X&, const Y*) = &Foo::bar; ... .def( "bar", bar1 ) .def( "bar", bar2 ) That requires python to supply Y* but if I understand what you two are saying .def( "bar", bar1, ( bp::arg("Y") = bp::object() ) ) .def( "bar", bar2, ( bp::arg("X"), bp::arg(Y) = bp::object() ) ) would make python not require that default arg. If that is the case then i guess all is well. When I saw Py++ generate that I figured bp::object() was just some weird thing I did not have to worry about. the documentation page I have been using and could not find an example of member function default params is here http://www.boost.org/doc/libs/1_41_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.default_arguments perhaps it would be nice to note this very handy bp::object somewhere. Thanks On Tue, Jan 12, 2010 at 2:09 PM, Hans Meine wrote: > On Dienstag 12 Januar 2010, Charles Solar wrote: > > Well I want to define the overloads myself anyway, I just do not know how > > to properly setup the small wrapper that will work. > > Oh, OK. > > > In the doc it tells > > you how to make flat function wrappers, but nothing on member function > > wrappers. > > I am 100% sure that they're documented, yet I am not very lucky with the > docs > either. > > > I am unsure how I am supposed to handle the this pointer, for > > example. > > You can reference the member function pointer like this (untested of > course): > > .def("bar", (void(Foo::*)(const Y*))&T::bar) > .def("bar", (void(Foo::*)(const X&,const Y*))&T::bar) > > > So idealy what I would like to know is what the macro does so I can > > manually write out the wrappers myself. > > > > And I have tried using Py++, it does not handle the default argument, it > > just puts the call in there and python still requires the param to be > > there. > > Really? AFAIK, it should work. > > You should be able to write (arg("some_x"), arg("some_y") = NULL)) as > extra .def() argument. > > Maybe py++ does not output the default args when the arguments are unnamed? > (I wouldn't know how, either.) > > -- > Ciao, / / .o. > /--/ ..o > / / ANS ooo > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From blp330 at msn.com Wed Jan 13 07:57:31 2010 From: blp330 at msn.com (blp330) Date: Tue, 12 Jan 2010 22:57:31 -0800 (PST) Subject: [C++-sig] [boost.python] How can I wrap operator==? In-Reply-To: <7465b6171001121155s25319ffbt724aac143530af2f@mail.gmail.com> References: <27105703.post@talk.nabble.com> <7465b6171001121155s25319ffbt724aac143530af2f@mail.gmail.com> Message-ID: <27140350.post@talk.nabble.com> Um... Sorry, I mean I have a class Document, which defined class Document { public: .... bool operator==(const Document& other) const { return Compare(other); } }; It simply call Compare method, I need to something more when I use it in python code but I don't want to change my Document class implementation because it can be used by other language that do not need extra code. Py++ generates: Document_exposer.def( bp::self == bp::self ); For other Document method I can change Py++ generated code to do something more, for example: Py++: { typedef ::StringPtr ( ::Document::*Thumb_function_type )( int,int ) const; Document_exposer.def( "Thumb" //, Thumb_function_type( &::Document::Thumb ) , &Document__ThumbWrap , ( bp::arg("width"), bp::arg("height") ) ); } I can define a Document__ThumbWrap function to write my extra code in it. But operator==, I don't know how to do that. I can't simply change Document_exposer.def( bp::self == bp::self ); to Document_exposer.def( bp::self == bp::self , &Document__EqualWrap ); to write my extra code in Document__EqualWrap. Thank you very much. -- View this message in context: http://old.nabble.com/-boost.python--How-can-I-wrap-operator%3D%3D--tp27105703p27140350.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Wed Jan 13 08:24:33 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 13 Jan 2010 09:24:33 +0200 Subject: [C++-sig] [boost.python] How can I wrap operator==? In-Reply-To: <27140350.post@talk.nabble.com> References: <27105703.post@talk.nabble.com> <7465b6171001121155s25319ffbt724aac143530af2f@mail.gmail.com> <27140350.post@talk.nabble.com> Message-ID: <7465b6171001122324q1a96d81cm54d43d3c613b5cbf@mail.gmail.com> On Wed, Jan 13, 2010 at 8:57 AM, blp330 wrote: > > Um... Sorry, I mean I have a class Document, which defined > > class Document > { > public: > ?.... > > ?bool operator==(const Document& other) const > ?{ > ?return Compare(other); > ?} > }; > > It simply call Compare method, I need to something more when I use it in > python code but I don't want to change my Document class implementation > because it can be used by other language that do not need extra code. > > Py++ generates: > Document_exposer.def( bp::self == bp::self ); > > For other Document method I can change Py++ generated code to do something > more, for example: > Py++: > ? { > ? ? ? ? ? ?typedef ::StringPtr ( ::Document::*Thumb_function_type )( > int,int ) const; > > ? ? ? ? ? ?Document_exposer.def( > ? ? ? ? ? ? ? ?"Thumb" > ? ? ? ? ? ? ? ?//, Thumb_function_type( &::Document::Thumb ) > ? ? ? ? ? ? ? ?, &Document__ThumbWrap > ? ? ? ? ? ? ? ?, ( bp::arg("width"), bp::arg("height") ) ); > > ? ? ? ?} > I can define a Document__ThumbWrap function to write my extra code in it. > > But operator==, I don't know how to do that. > I can't simply change > Document_exposer.def( bp::self == bp::self ); > to > Document_exposer.def( > ? ? bp::self == bp::self > ? ? , &Document__EqualWrap > ?); > to write my extra code in Document__EqualWrap. If I understand you right, you need: 1. define new global function, which takes Document& as the first argument bool Document_EqualWrap( const Document& x, const Document& y ){...} 2. Expose it: ... .def( "__eq__", &Document_EqualWrap ) Is not the working code, but it should give you a direction. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From sipickles at googlemail.com Wed Jan 13 10:00:54 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Wed, 13 Jan 2010 09:00:54 +0000 Subject: [C++-sig] Conversion problem Message-ID: <4B4D8BC6.6050401@googlemail.com> Hello, I wonder if someone could help me with a tricky conversion between c++ and python types (well, tricky for me!) I have a c++ library that I would like to use in python via Boost::Python One function fills a c++ unsigned char* buffer. It has two overloads: unsigned char * getPixels(int deviceID); bool getPixels(int id, unsigned char * pixels); How would I go about getting that data into a python object, a string in particular? I seem to face several problems: ///////////////////////// 1) unsigned char* does not have a to_python converter to Py_String. I tried this: struct uchar_ptr_to_str { static PyObject* convert(unsigned char* p) { return incref( str(p).ptr()); } static PyTypeObject const *get_pytype () {return &PyString_Type; } }; struct uchar_to_str { static PyObject* convert(unsigned char& p) { return incref( str(p).ptr()); } static PyTypeObject const *get_pytype () {return &PyString_Type; } }; BOOST_PYTHON_MODULE(pyVideoInput) { to_python_converter< unsigned char*, uchar_ptr_to_str, true >(); to_python_converter< unsigned char, uchar_to_str, true >(); class_("videoInput") .def("getPixels", &videoInput::getPixels, return_value_policy()) ; } ///////////////////////// 2) How do I allocate memory in a python string and then pass the pointer through boost python, to be filled by the c++ function? In c++, the library would be used like this: videoInput vi; .... unsigned char * buffer = new unsigned char[size]; vi.getPixels(device, buffer); The buffer could be pretty big so I want to pass by pointer, not by value The alternative would be to use the overload which returns the pointer, but I can't get that to compile with bjam. I get the dreaded: make_instance.hpp(24) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE when I try to return a pointer... Thanks for any help freeing me from my confusion! Regards Si From nico_ml at mgdesign.org Wed Jan 13 10:10:29 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Wed, 13 Jan 2010 10:10:29 +0100 Subject: [C++-sig] Returning a simple char * In-Reply-To: <4B4C2FF6.7080307@googlemail.com> References: <4B4C2FF6.7080307@googlemail.com> Message-ID: <4B4D8E05.3020204@mgdesign.org> An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Jan 13 11:44:50 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 13 Jan 2010 12:44:50 +0200 Subject: [C++-sig] Conversion problem In-Reply-To: <4B4D8BC6.6050401@googlemail.com> References: <4B4D8BC6.6050401@googlemail.com> Message-ID: <7465b6171001130244td40a022k103eedb703b2f9f0@mail.gmail.com> On Wed, Jan 13, 2010 at 11:00 AM, Simon Pickles wrote: > Hello, > > I wonder if someone could help me with a tricky conversion between c++ and > python types (well, tricky for me!) > > I have a c++ library that I would like to use in python via Boost::Python > > One function fills a c++ unsigned char* buffer. It has two overloads: > > ? ? ? unsigned char * getPixels(int deviceID); > ? ? ? bool getPixels(int id, unsigned char * pixels); > In both cases the easiest solution would be create small wrappers around the functions: std::string getPixels(int i ){ ... } and expose it. Another solution would be to use ctypes module to call those functions. In both cases Py++ can help you: http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From nico_ml at mgdesign.org Wed Jan 13 12:17:23 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Wed, 13 Jan 2010 12:17:23 +0100 Subject: [C++-sig] Conversion problem In-Reply-To: <4B4D8BC6.6050401@googlemail.com> References: <4B4D8BC6.6050401@googlemail.com> Message-ID: <4B4DABC3.3020002@mgdesign.org> Simon, it seems that I wrapped the same videoinput library you're using. I wrapped the getPixels the following way : python script is responsible of the memory allocation for pixels buffer (in a correctly sized string). The getPixels function is wrapped as follows : namespace { bool videoInput_getPixels(videoInput& input, int device_id, python::object memory_buffer) { PyObject* pyObject = memory_buffer.ptr(); if (PyString_CheckExact(pyObject)) { Py_ssize_t string_size = PyString_Size(pyObject); if (string_size >= Py_ssize_t(input.getWidth(device_id)) * Py_ssize_t(input.getHeight(device_id)) * Py_ssize_t(3)) { unsigned char* pixels = reinterpret_cast(PyString_AsString(pyObject)); return input.getPixels(device_id, pixels, false, false); } } return false; } }; python::class_ klass("VideoInput"); klass.def("getPixels", videoInput_getPixels); This certainly lacks some error checking for the actual 'memory_buffer' parameter type, but can give you a clue. HTH, Nicolas From tim at tizmoi.net Wed Jan 13 19:24:19 2010 From: tim at tizmoi.net (Tim Couper) Date: Wed, 13 Jan 2010 18:24:19 +0000 Subject: [C++-sig] Simple , , I think .. type conversion question C++ -> python In-Reply-To: <4B4DABC3.3020002@mgdesign.org> References: <4B4D8BC6.6050401@googlemail.com> <4B4DABC3.3020002@mgdesign.org> Message-ID: <4B4E0FD3.9040106@tizmoi.net> OK. Here's what I've been stuck with all today .. I have a 3rd party C++ program function which returns a boost::variant (and its inverse) my_variant my_variant_of_string(const std::string& str) This one takes a string & returns a variant, and am trying to wrap this in python, so that there I can have >>> my_variant_of_string('hello') 'hello' >>> my_variant_of_string('1.2') 1.2 >>> my_variant_of_string('10') 10 Simple, eh? .. The reduced code below compiles, creating the python function correctly, but I have not successfully defined to_python_value/to_python_converter statement(s), so the python predictably fails with a ".. no to_python .. converter for .. boost::variant .." when run. I can find lots of helpful references to such converters of classes (eg http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/), but cannot see how I should use the to_python_value functionality to express the "convert the output of this function to a string, int or double as appropriate". Thanks Tim "novice, but learning" Couper -- my_variant.cpp -- #include typedef boost::variant my_variant; template bool from_string(T& t,const std::string& s, std::ios_base& (*f)(std::ios_base&)) { std::istringstream iss(s); return !(iss >> f >> t).fail(); } namespace var { my_variant my_variant_of_string(const std::string& str) // return a float, int or string depending on input parameter content { my_variant param; double dval; int ival; if (str.find(".") != std::string::npos) { if (from_string(dval,str,std::dec)) { param = dval; } } else if (from_string(ival,str,std::dec) ) { param = ival; } else { param= str; } return param; } }// var #include #include BOOST_PYTHON_MODULE(var) { using namespace boost::python; def("my_variant_of_string", &var::my_variant_of_string); } -------------- next part -------------- An HTML attachment was scrubbed... URL: From troy at resophonic.com Wed Jan 13 20:10:26 2010 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 13 Jan 2010 14:10:26 -0500 Subject: [C++-sig] Simple , , I think .. type conversion question C++ -> python In-Reply-To: <4B4E0FD3.9040106@tizmoi.net> References: <4B4D8BC6.6050401@googlemail.com> <4B4DABC3.3020002@mgdesign.org> <4B4E0FD3.9040106@tizmoi.net> Message-ID: <4B4E1AA2.8060805@resophonic.com> Tim Couper wrote: > OK. Here's what I've been stuck with all today .. I have a 3rd party C++ > program function which returns a boost::variant (and its inverse) > > my_variant my_variant_of_string(const std::string& str) > > This one takes a string & returns a variant, and am trying to wrap this > in python, so that there I can have > > >>> my_variant_of_string('hello') > 'hello' > > >>> my_variant_of_string('1.2') > 1.2 > > >>> my_variant_of_string('10') > 10 > > Simple, eh? ... How about something like (not tested): using boost::python::object; typedef variant<...> variant_t; variant_t makes_variant_from(string s); // defined elsewhere // // visitor for converting contents of visitor to object // struct vc : boost::static_visitor { template object operator()(const T& v) const { return v; } }; bp::object thunk(string s) { variant_t v = makes_variant_from(s); return boost::apply_visitor(vc(), v); } BOOST_PYTHON_MODULE(mod) { def("f", &thunk); } You could probably use this to just register a converter from variant to vanilla boost::python::object as well, if this is more convenient... -t From tim at tizmoi.net Wed Jan 13 20:24:50 2010 From: tim at tizmoi.net (Tim Couper) Date: Wed, 13 Jan 2010 19:24:50 +0000 Subject: [C++-sig] Simple , , I think .. type conversion question C++ -> python In-Reply-To: <4B4E1AA2.8060805@resophonic.com> References: <4B4D8BC6.6050401@googlemail.com> <4B4DABC3.3020002@mgdesign.org> <4B4E0FD3.9040106@tizmoi.net> <4B4E1AA2.8060805@resophonic.com> Message-ID: <4B4E1E02.9030400@tizmoi.net> Troy Thanks .. your hints are most helpful .. I'll be back :-) Tim On 13/01/2010 19:10, troy d. straszheim wrote: > Tim Couper wrote: >> OK. Here's what I've been stuck with all today .. I have a 3rd party >> C++ program function which returns a boost::variant (and its inverse) >> >> my_variant my_variant_of_string(const std::string& str) >> >> This one takes a string & returns a variant, and am trying to wrap >> this in python, so that there I can have >> >> >>> my_variant_of_string('hello') >> 'hello' >> >> >>> my_variant_of_string('1.2') >> 1.2 >> >> >>> my_variant_of_string('10') >> 10 >> >> Simple, eh? ... > > How about something like (not tested): > > using boost::python::object; > > typedef variant<...> variant_t; > > variant_t makes_variant_from(string s); // defined elsewhere > > // > // visitor for converting contents of visitor to object > // > struct vc : boost::static_visitor > { > template > object operator()(const T& v) const > { > return v; > } > }; > > bp::object > thunk(string s) > { > variant_t v = makes_variant_from(s); > return boost::apply_visitor(vc(), v); > } > > BOOST_PYTHON_MODULE(mod) > { > def("f", &thunk); > } > > > You could probably use this to just register a converter from variant > to vanilla boost::python::object as well, if this is more convenient... > > -t > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.725 / Virus Database: 270.14.138/2618 - Release Date: 01/13/10 07:35:00 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans_meine at gmx.net Wed Jan 13 13:54:24 2010 From: hans_meine at gmx.net (Hans Meine) Date: Wed, 13 Jan 2010 13:54:24 +0100 Subject: [C++-sig] [boost.python] How can I wrap operator==? In-Reply-To: <7465b6171001122324q1a96d81cm54d43d3c613b5cbf@mail.gmail.com> References: <27105703.post@talk.nabble.com> <27140350.post@talk.nabble.com> <7465b6171001122324q1a96d81cm54d43d3c613b5cbf@mail.gmail.com> Message-ID: <201001131354.25672.hans_meine@gmx.net> On Mittwoch 13 Januar 2010, Roman Yakovenko wrote: > On Wed, Jan 13, 2010 at 8:57 AM, blp330 wrote: > > class Document > > { > > public: > > .... > > > > bool operator==(const Document& other) const > > { > > return Compare(other); > > } > [...] > If I understand you right, you need: > > 1. define new global function, which takes Document& as the first argument > > bool Document_EqualWrap( const Document& x, const Document& y ){...} Not necessary AFAIK, a member function should work, too. (i.e. directly exposing &Document::operator==) > 2. Expose it: > > ... > .def( "__eq__", &Document_EqualWrap ) > > Is not the working code, but it should give you a direction. Yes, I think that's what he was missing. -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From roman.yakovenko at gmail.com Wed Jan 13 21:39:53 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 13 Jan 2010 22:39:53 +0200 Subject: [C++-sig] A nice Boost.Python and Py++ usage example Message-ID: <7465b6171001131239r4fec3efcy6b0b3792baadf92f@mail.gmail.com> http://frontiersin.org/psychology/psychology/paper/10.3389/neuro.11/011.2009/html/ The articles talks about some science fiction ( for me:-) ), but also has few paragraphs related to Boost.Python and Py++. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From jjcarles at jocajica.com Wed Jan 13 22:06:40 2010 From: jjcarles at jocajica.com (Joan Carles Jimenez) Date: Wed, 13 Jan 2010 22:06:40 +0100 Subject: [C++-sig] Boost and wxWidgets Message-ID: <1263416800.3462.71.camel@servidor.jocajica> Hi. I am testing the following source code: -------- Canvas.h -------- #ifndef _CANVAS_H_ #define _CANVAS_H_ #include #include "wx/wx.h" class CanvasFrame { protected: wxFrame* _frame; public: CanvasFrame(const std::string& pTitle); ~CanvasFrame(void); void Plot(void); }; #endif /* _CANVAS_H_ */ ---------- Canvas.cpp ---------- #include #include "canvas.h" CanvasFrame::CanvasFrame(const std::string& pTitle) { _frame = new wxFrame(NULL, wxID_ANY, wxString::FromAscii(pTitle.c_str())); } CanvasFrame::~CanvasFrame(void) { if(_frame) { delete _frame; } } void CanvasFrame::Plot(void) { } ----------- wrapper.cpp ----------- #include #include "canvas.h" using namespace boost::python; BOOST_PYTHON_MODULE(canvas) { class_("CanvasFrame", init()) .def("Plot", &CanvasFrame::Plot) ; } And to generate the module "canvas.so" I execute: g++ -shared -g -I. -I/usr/include/python2.6 -lpython2.6 canvas.cpp wrapper.cpp /usr/lib64/libboost_python.so -fPIC `wx-config --cxxflags` `wx-config --libs` -o canvas.so "canvas.so" is generated without any problems but when I execute in the python console the next code: >>> import canvas >>> a = canvas.CanvasFrame('My Plot Window') I have the next errors: (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function (process:3521): GLib-CRITICAL **: g_once_init_leave: assertion `initialization_value != 0' failed (process:3521): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion `GDK_IS_DISPLAY (display)' failed (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization assertion failed, use IA__g_type_init() prior to this function And more, and more, and more. I have watched the examples of http://wiki.python.org/moin/boost.python/ExportingClasses but I have not seen any problem. They can help me? Thanks! P.D. Sorry for my english! From sipickles at googlemail.com Thu Jan 14 09:23:49 2010 From: sipickles at googlemail.com (Simon Pickles) Date: Thu, 14 Jan 2010 08:23:49 +0000 Subject: [C++-sig] Conversion problem In-Reply-To: <4B4DABC3.3020002@mgdesign.org> References: <4B4D8BC6.6050401@googlemail.com> <4B4DABC3.3020002@mgdesign.org> Message-ID: <4B4ED495.8030505@googlemail.com> Thanks Nicolas, I learnt a lot from your way of doing it! Simon On 13/01/2010 11:17, Nicolas Lelong wrote: > Simon, > > it seems that I wrapped the same videoinput library you're using. > > I wrapped the getPixels the following way : python script is > responsible of the memory allocation for pixels buffer (in a correctly > sized string). > > The getPixels function is wrapped as follows : > > namespace { > > bool videoInput_getPixels(videoInput& input, int device_id, > python::object memory_buffer) > { > PyObject* pyObject = memory_buffer.ptr(); > if (PyString_CheckExact(pyObject)) > { > Py_ssize_t string_size = PyString_Size(pyObject); > if (string_size >= Py_ssize_t(input.getWidth(device_id)) * > Py_ssize_t(input.getHeight(device_id)) * Py_ssize_t(3)) > { > unsigned char* pixels = reinterpret_cast char*>(PyString_AsString(pyObject)); > > return input.getPixels(device_id, pixels, false, false); > } > } > return false; > } > > }; > > python::class_ klass("VideoInput"); > klass.def("getPixels", videoInput_getPixels); > > This certainly lacks some error checking for the actual > 'memory_buffer' parameter type, but can give you a clue. > > HTH, > > Nicolas > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brokenn at gmail.com Thu Jan 14 09:53:06 2010 From: brokenn at gmail.com (Brian O'Kennedy) Date: Thu, 14 Jan 2010 08:53:06 +0000 Subject: [C++-sig] Boost and wxWidgets In-Reply-To: <1263416800.3462.71.camel@servidor.jocajica> References: <1263416800.3462.71.camel@servidor.jocajica> Message-ID: I suspect your problem is unrelated to boost.python. I've never used wxWidgets, but a quick google suggests it should be initialised before being used. *http://docs.wxwidgets.org/stable/wx_appinifunctions.html* int wxEntry(int& * argc*, wxChar ***argv*) hope this helps, Brian 2010/1/13 Joan Carles Jimenez > Hi. > > I am testing the following source code: > > > > -------- > Canvas.h > -------- > > #ifndef _CANVAS_H_ > #define _CANVAS_H_ > > #include > #include "wx/wx.h" > > class CanvasFrame > { > protected: > wxFrame* _frame; > > public: > CanvasFrame(const std::string& pTitle); > ~CanvasFrame(void); > > void Plot(void); > }; > > #endif /* _CANVAS_H_ */ > > ---------- > Canvas.cpp > ---------- > > #include > #include "canvas.h" > > CanvasFrame::CanvasFrame(const std::string& pTitle) > { > _frame = new wxFrame(NULL, wxID_ANY, > wxString::FromAscii(pTitle.c_str())); > } > > CanvasFrame::~CanvasFrame(void) > { > if(_frame) { > delete _frame; > } > } > > void CanvasFrame::Plot(void) > { > } > > ----------- > wrapper.cpp > ----------- > > #include > #include "canvas.h" > > using namespace boost::python; > > BOOST_PYTHON_MODULE(canvas) > { > class_("CanvasFrame", init()) > .def("Plot", &CanvasFrame::Plot) > ; > } > > > > And to generate the module "canvas.so" I execute: > > > > g++ -shared -g -I. -I/usr/include/python2.6 -lpython2.6 canvas.cpp > wrapper.cpp /usr/lib64/libboost_python.so -fPIC `wx-config --cxxflags` > `wx-config --libs` -o canvas.so > > "canvas.so" is generated without any problems but when I execute in the > python console the next code: > > > > >>> import canvas > >>> a = canvas.CanvasFrame('My Plot Window') > > > > I have the next errors: > > > > (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization > assertion failed, use IA__g_type_init() prior to this function > > (process:3521): GLib-CRITICAL **: g_once_init_leave: assertion > `initialization_value != 0' failed > > (process:3521): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion > `GDK_IS_DISPLAY (display)' failed > > (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization > assertion failed, use IA__g_type_init() prior to this function > > > > And more, and more, and more. I have watched the examples of > > http://wiki.python.org/moin/boost.python/ExportingClasses > > but I have not seen any problem. They can help me? Thanks! > > > P.D. Sorry for my english! > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjcarles at jocajica.com Thu Jan 14 11:41:31 2010 From: jjcarles at jocajica.com (Joan Carles Jimenez) Date: Thu, 14 Jan 2010 11:41:31 +0100 Subject: [C++-sig] Boost and wxWidgets In-Reply-To: References: <1263416800.3462.71.camel@servidor.jocajica> Message-ID: <1263465691.3462.87.camel@servidor.jocajica> Thanks Brian, but do not work. The "canvas.so" is a static library not an application. My info is: openSuSE 11.2 64bits boost 1.39 gcc-c++ 4.4 python 2.6.2 On Thu, 2010-01-14 at 08:53 +0000, Brian O'Kennedy wrote: > I suspect your problem is unrelated to boost.python. I've never used > wxWidgets, but a quick google suggests it should be initialised before > being used. > > > http://docs.wxwidgets.org/stable/wx_appinifunctions.html > int wxEntry(int& argc, wxChar **argv) > > > hope this helps, > Brian > > > > 2010/1/13 Joan Carles Jimenez > Hi. > > I am testing the following source code: > > > > -------- > Canvas.h > -------- > > #ifndef _CANVAS_H_ > #define _CANVAS_H_ > > #include > #include "wx/wx.h" > > class CanvasFrame > { > protected: > wxFrame* _frame; > > public: > CanvasFrame(const std::string& pTitle); > ~CanvasFrame(void); > > void Plot(void); > }; > > #endif /* _CANVAS_H_ */ > > ---------- > Canvas.cpp > ---------- > > #include > #include "canvas.h" > > CanvasFrame::CanvasFrame(const std::string& pTitle) > { > _frame = new wxFrame(NULL, wxID_ANY, > wxString::FromAscii(pTitle.c_str())); > } > > CanvasFrame::~CanvasFrame(void) > { > if(_frame) { > delete _frame; > } > } > > void CanvasFrame::Plot(void) > { > } > > ----------- > wrapper.cpp > ----------- > > #include > #include "canvas.h" > > using namespace boost::python; > > BOOST_PYTHON_MODULE(canvas) > { > class_("CanvasFrame", init std::string&>()) > .def("Plot", &CanvasFrame::Plot) > ; > } > > > > And to generate the module "canvas.so" I execute: > > > > g++ -shared -g -I. -I/usr/include/python2.6 -lpython2.6 > canvas.cpp > wrapper.cpp /usr/lib64/libboost_python.so -fPIC `wx-config > --cxxflags` > `wx-config --libs` -o canvas.so > > "canvas.so" is generated without any problems but when I > execute in the > python console the next code: > > > > >>> import canvas > >>> a = canvas.CanvasFrame('My Plot Window') > > > > I have the next errors: > > > > (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: > initialization > assertion failed, use IA__g_type_init() prior to this function > > (process:3521): GLib-CRITICAL **: g_once_init_leave: assertion > `initialization_value != 0' failed > > (process:3521): Gdk-CRITICAL **: gdk_cursor_new_for_display: > assertion > `GDK_IS_DISPLAY (display)' failed > > (process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: > initialization > assertion failed, use IA__g_type_init() prior to this function > > > > And more, and more, and more. I have watched the examples of > > http://wiki.python.org/moin/boost.python/ExportingClasses > > but I have not seen any problem. They can help me? Thanks! > > > P.D. Sorry for my english! > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From hans_meine at gmx.net Thu Jan 14 11:54:08 2010 From: hans_meine at gmx.net (Hans Meine) Date: Thu, 14 Jan 2010 11:54:08 +0100 Subject: [C++-sig] Boost and wxWidgets In-Reply-To: <1263465691.3462.87.camel@servidor.jocajica> References: <1263416800.3462.71.camel@servidor.jocajica> <1263465691.3462.87.camel@servidor.jocajica> Message-ID: <201001141154.08855.hans_meine@gmx.net> Am Donnerstag, 14. Januar 2010 11:41:31 schrieb Joan Carles Jimenez: > On Thu, 2010-01-14 at 08:53 +0000, Brian O'Kennedy wrote: > > I suspect your problem is unrelated to boost.python. I've never used > > wxWidgets, but a quick google suggests it should be initialised before > > being used. > [...] > Thanks Brian, but do not work. The "canvas.so" is a static library not > an application. Yes, but then you should initialize wx/gtk in the actual program using canvas.so, before calling the relevant canvas.so functions. HTH, Hans From rosen.diankov at gmail.com Thu Jan 14 16:55:37 2010 From: rosen.diankov at gmail.com (Rosen Diankov) Date: Thu, 14 Jan 2010 10:55:37 -0500 Subject: [C++-sig] Robotics Project Using Boost Python: OpenRAVE Message-ID: <103101d71001140755k64f1b256l8b3acd5d52e9a018@mail.gmail.com> Dear Boost Python Developers, We've been using boost.python for about a year now for a robotics planning and simulation environment called OpenRAVE (developed by Rosen Diankov): http://openrave.programmingvision.com We are very pleased with boost python and it has opened up many new doors for development. I saw that Boost.Python has a projects page, so if it openrave is deemed worth of getting mentioned on it, a possible project description would be: "OpenRAVE is an open-source, cross-platform, plugin-based robot planning environment for autonomous robotics. Includes many services like collision detection, physics, (inverse) kinematics, sensors, robot controls, complex motion planners, grasping simulation, manipulation planning, and a powerful python scripting environment based on boost.python. Boost.Python allows OpenRAVE to export all its complex C++ functionality into a scripting environment where researchers can easily test new algorithms and dynamically control the flow of execution." thank you, rosen, From nico_ml at mgdesign.org Fri Jan 15 18:09:36 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Fri, 15 Jan 2010 18:09:36 +0100 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <201001101118.25701.lists_ravi@lavabit.com> References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> Message-ID: <4B50A150.1010908@mgdesign.org> My previous mail once again got lost, gotta be more careful... > Changes (by dave): > > This looks terrific! I'll try to get it applied ASAP. Please poke me if > you don't see it in trunk by the end of the week. Thanks ! As I didn't see the batch in trunk today, I poke you :) > Please file a trac ticket at svn.boost.org so that this does not get lost. OK Ravi, thanks for the pointer, I should have known.... I submitted ticket #3833 (https://svn.boost.org/trac/boost/ticket/3833), and will be happy to have feedback about it ! Cheers, Nicolas. From bfitzpatrick at vtiinstruments.com Mon Jan 18 22:48:01 2010 From: bfitzpatrick at vtiinstruments.com (Ben Fitzpatrick) Date: Mon, 18 Jan 2010 15:48:01 -0600 Subject: [C++-sig] Pybindgen and enum types Message-ID: <27AD07BD25612C40AF5C78CB49D09B4967CC0F69EE@34093-MBX-C08.mex07a.mlsrvr.com> Hi everyone, I am trying to wrap a section of C++ code with many enum types in it, of the form: enum Blah { BlahSomething1 = 1000; BlahSomething2 = 1001; } Thanks to this definition - pulled into pybindgen via automagical pygccxml parsing of some header files - code of the form Blah here_is_a_variable; Is recognized just fine and works great. However, code of the form Blah* here_is_a_variable; Is not recognized because pybindgen/pygccxml can't find an explicit definition of a Blah*. I am wondering if there's a simple way to convert these programmatically - that is, not have to write a to_python converter for each one, especially since they're all of the generic form "(enum)*". The code I am wrapping is not guaranteed API-stable, and I'm trying to automate as much parsing as possible. Any suggestions? Thanks, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From gjcarneiro at gmail.com Tue Jan 19 12:04:37 2010 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 19 Jan 2010 11:04:37 +0000 Subject: [C++-sig] Pybindgen and enum types In-Reply-To: <27AD07BD25612C40AF5C78CB49D09B4967CC0F69EE@34093-MBX-C08.mex07a.mlsrvr.com> References: <27AD07BD25612C40AF5C78CB49D09B4967CC0F69EE@34093-MBX-C08.mex07a.mlsrvr.com> Message-ID: On Mon, Jan 18, 2010 at 9:48 PM, Ben Fitzpatrick < bfitzpatrick at vtiinstruments.com> wrote: > Hi everyone, > > > > I am trying to wrap a section of C++ code with many enum types in it, of > the form: > > > > enum Blah > > { > > BlahSomething1 = 1000; > > BlahSomething2 = 1001; > > } > > > > Thanks to this definition - pulled into pybindgen via automagical pygccxml > parsing of some header files - code of the form > > Blah here_is_a_variable; > > > > Is recognized just fine and works great. However, code of the form > > Blah* here_is_a_variable; > > > > Is not recognized because pybindgen/pygccxml can?t find an explicit > definition of a Blah*. I am wondering if there?s a simple way to convert > these programmatically ? that is, not have to write a to_python converter > for each one, especially since they?re all of the generic form ?(enum)*?. > The code I am wrapping is not guaranteed API-stable, and I?m trying to > automate as much parsing as possible. Any suggestions? > If I understand correctly, you are just missing the enum* type handler, which should have been implemented in pybindgen, but I am lazy and often only implement things as they become needed. You can download a patch from here: http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/741 > > > Thanks, > > Ben > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From nico_ml at mgdesign.fr Mon Jan 11 10:06:35 2010 From: nico_ml at mgdesign.fr (Nicolas Lelong) Date: Mon, 11 Jan 2010 10:06:35 +0100 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <201001101118.25701.lists_ravi@lavabit.com> References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> Message-ID: <4B4AEA1B.2080907@mgdesign.fr> > Please file a trac ticket at svn.boost.org so that this does not get lost. OK Ravi, thanks for the pointer, I should have known.... I submitted ticket #3833 (https://svn.boost.org/trac/boost/ticket/3833), and will be happy to have feedback about it ! Cheers, Nicolas. From mtn at xcm.ch Mon Jan 11 17:15:16 2010 From: mtn at xcm.ch (mtn) Date: Mon, 11 Jan 2010 08:15:16 -0800 (PST) Subject: [C++-sig] Py++/boost::python: How to correctly wrap libraries (DLLs) with dependencies on each other. Message-ID: <27112969.post@talk.nabble.com> Hi all, I try to embed a Python interpreter into my project using Py++/boost::python. I have a problem wrapping different libraries for which i own the source and which I compile to DLL/*.so files . The libraries have dependencies on each other but do not necessarily have to be used together. An abstract example: The interpreter is in a library on which all other libraries depend and where they register themselves using init functions generated by py++/boost::python. Let's say I have a base library B. Additionally a library E extending library B. lib B: class __exported_to_python__ Base { void __exported_to_pytthon__ foo(){...} } lib E -> depends B: class __exported_to_python__ Extended : public B { void __exported_to_python__ boo(){...} } It makes sense to also use B alone, therefore I would like to build a Python wrapper for each library directly into the DLL. Now I register my init function generate by Py++/boost::python to the interpreter instance using `PyImport_AppendInittab`. The thing, that I cannot generate a proper inheritance relation between the class `Extended` and `Base` without telling Py++ to wrap both classes. But then I have wrapped `Base` twice. Once in B and once in E. And when boost::python tries to register some transfer functions based on the C++ type (RTTI) it fails, as it has already been registered (because init_B was called). If I simply delete the duplicated classes by hand from the wrapper of library `E` it works. But one has to ensure that first `B` is imported to Python (`import B`) and afterwards `E` (`import E`) otherwise boost::python does not have `Base` registered on which `Extended` depends. I hope I made myself clear enough now :-) So has anybody solved this problem before me? I did not find a source which would explain how to solve this issue with Py++ and boost::python. Thanks for all the fish! solong Martin -- View this message in context: http://old.nabble.com/Py%2B%2B-boost%3A%3Apython%3A-How-to-correctly-wrap-libraries-%28DLLs%29-with-dependencies-on-each-other.-tp27112969p27112969.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From nico_ml at mgdesign.fr Tue Jan 12 15:06:24 2010 From: nico_ml at mgdesign.fr (Nicolas Lelong) Date: Tue, 12 Jan 2010 15:06:24 +0100 Subject: [C++-sig] Returning a simple char * In-Reply-To: <4B4C2FF6.7080307@googlemail.com> References: <4B4C2FF6.7080307@googlemail.com> Message-ID: <4B4C81E0.8070306@mgdesign.fr> IMO, the easiest route would be to wrap the member functions : namespace { std::string video_getDeviceName_wrapped(int deviceID) { char* name = videoInput::getDeviceName(devideID); std::string result(name); // free 'name' memory if needed return result; } } and then :: using namespace boost::python; BOOST_PYTHON_MODULE(pyVideoInput) { class_("videoInput") .def("getDeviceName", &video_getDeviceName_wrapped) .staticmethod("getDeviceName") ; } and you should be done. From roman.yakovenko at gmail.com Wed Jan 20 09:22:30 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 20 Jan 2010 10:22:30 +0200 Subject: [C++-sig] Py++/boost::python: How to correctly wrap libraries (DLLs) with dependencies on each other. In-Reply-To: <27112969.post@talk.nabble.com> References: <27112969.post@talk.nabble.com> Message-ID: <7465b6171001200022m11b2611ft70038cb026e0883c@mail.gmail.com> On Mon, Jan 11, 2010 at 6:15 PM, mtn wrote: > > Hi all, > > I try to embed a Python interpreter into my project using > Py++/boost::python. > > I have a problem wrapping different libraries for which i own the source and > which I compile to DLL/*.so files . The libraries have dependencies on each > other but do not necessarily have to be used together. > > > An abstract example: > > The interpreter is in a library on which all other libraries depend and > where they register themselves using init functions generated by > py++/boost::python. > Let's say I have a base library B. > Additionally a library E extending library B. > > lib B: > class __exported_to_python__ Base { > ?void __exported_to_pytthon__ ?foo(){...} > } > > lib E -> depends B: > class __exported_to_python__ Extended : public B > { > ?void __exported_to_python__ ?boo(){...} > } > > It makes sense to also use B alone, therefore I would like to build a Python > wrapper for each library directly into the DLL. > > Now I register my init function generate by Py++/boost::python to the > interpreter instance using `PyImport_AppendInittab`. > > The thing, that I cannot generate a proper inheritance relation between the > class `Extended` and `Base` without telling Py++ to wrap both classes. But > then I have wrapped `Base` twice. Once in B and once in E. > And when boost::python tries to register some transfer functions based on > the C++ type (RTTI) it fails, as it has already been registered (because > init_B was called). > > If I simply delete the duplicated classes by hand from the wrapper of > library `E` it works. > But one has to ensure that first `B` is imported to Python (`import B`) and > afterwards `E` (`import E`) otherwise boost::python does not have `Base` > registered on which `Extended` depends. You can import "B" from "E". You can do this by building "EImpl" module and the "wrapping" it with package: E/ __init__.py EImpl.[so|pyd|dll] where __init__.py contains the following code: import B from EImpl import * #or something like that > > I hope I made myself clear enough now :-) > So has anybody solved this problem before me? > I did not find a source which would explain how to solve this issue with > Py++ and boost::python. Take a look on http://language-binding.net/pyplusplus/documentation/multi_module_development.html . The document describes the situation you have. If you need a good example take a look on Python-Ogre project. It uses "multi module development" feature all the way. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From mtn at xcm.ch Wed Jan 20 10:51:10 2010 From: mtn at xcm.ch (Martin Seiler) Date: Wed, 20 Jan 2010 10:51:10 +0100 Subject: [C++-sig] Py++/boost::python: How to correctly wrap libraries (DLLs) with dependencies on each other. In-Reply-To: <7465b6171001200022m11b2611ft70038cb026e0883c@mail.gmail.com> References: <27112969.post@talk.nabble.com> <7465b6171001200022m11b2611ft70038cb026e0883c@mail.gmail.com> Message-ID: <7957fb091001200151p25b588afg4429f40860b647f4@mail.gmail.com> Thanks a lot Roman, everything answered.. On Wed, Jan 20, 2010 at 9:22 AM, Roman Yakovenko wrote: > On Mon, Jan 11, 2010 at 6:15 PM, mtn wrote: >> >> Hi all, >> >> I try to embed a Python interpreter into my project using >> Py++/boost::python. >> >> I have a problem wrapping different libraries for which i own the source and >> which I compile to DLL/*.so files . The libraries have dependencies on each >> other but do not necessarily have to be used together. >> >> >> An abstract example: >> >> The interpreter is in a library on which all other libraries depend and >> where they register themselves using init functions generated by >> py++/boost::python. >> Let's say I have a base library B. >> Additionally a library E extending library B. >> >> lib B: >> class __exported_to_python__ Base { >> ?void __exported_to_pytthon__ ?foo(){...} >> } >> >> lib E -> depends B: >> class __exported_to_python__ Extended : public B >> { >> ?void __exported_to_python__ ?boo(){...} >> } >> >> It makes sense to also use B alone, therefore I would like to build a Python >> wrapper for each library directly into the DLL. >> >> Now I register my init function generate by Py++/boost::python to the >> interpreter instance using `PyImport_AppendInittab`. >> >> The thing, that I cannot generate a proper inheritance relation between the >> class `Extended` and `Base` without telling Py++ to wrap both classes. But >> then I have wrapped `Base` twice. Once in B and once in E. >> And when boost::python tries to register some transfer functions based on >> the C++ type (RTTI) it fails, as it has already been registered (because >> init_B was called). >> >> If I simply delete the duplicated classes by hand from the wrapper of >> library `E` it works. >> But one has to ensure that first `B` is imported to Python (`import B`) and >> afterwards `E` (`import E`) otherwise boost::python does not have `Base` >> registered on which `Extended` depends. > > You can import "B" from "E". You can do this by building "EImpl" > module and the "wrapping" it with package: > ?E/ > ? ? __init__.py > ? ? EImpl.[so|pyd|dll] > > where __init__.py contains the following code: > > import B > from EImpl import * #or something like that > > >> >> I hope I made myself clear enough now :-) >> So has anybody solved this problem before me? >> I did not find a source which would explain how to solve this issue with >> Py++ and boost::python. > > Take a look on http://language-binding.net/pyplusplus/documentation/multi_module_development.html > . The document describes the situation you have. > > If you need a good example take a look on Python-Ogre project. It uses > "multi module development" feature all the way. > > HTH > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From bfitzpatrick at vtiinstruments.com Wed Jan 20 18:43:36 2010 From: bfitzpatrick at vtiinstruments.com (Ben Fitzpatrick) Date: Wed, 20 Jan 2010 11:43:36 -0600 Subject: [C++-sig] Boost-python/pybindgen and wrapping member variables Message-ID: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> Hi everyone, I think I'm finally getting the hang of this, I seem to have gotten almost everything in my project working thanks to Gustavo's latest pybindgen patch. One of the remaining things I am having difficulty with is putting annotations on member variables of a class. I have something of the form: class foo{ }; class baz { public: foo* var; } The error I am getting from pybindgen is "WrapperWarning: Return value '::foo *' error (used in baz::var [variable]): TypeConfigurationError('Either caller_owns_return or self.reference_existing_object must be given') I know that the issue is that I need to stick an annotation on there. Since the pointer is allocated and tracked by the underlying C++ code, I'm pretty sure that I need to put reference_existing_object on it. I've tried inserting "{'reference_existing_object' : 'true'}" into the global_annotations table, and also inserting it into the parameter_annotations["return"] dictionary. For kicks, I even tried both at once. No matter what I do I can't get rid of the error, or see it show up in my final build, which leads me to believe there's something I'm missing. I went and looked up the documentation for reference_existing_object, but of course none of their examples show how you could use it on a member variable. What am I missing? Thanks, Ben Fitzpatrick -------------- next part -------------- An HTML attachment was scrubbed... URL: From gjcarneiro at gmail.com Wed Jan 20 19:17:59 2010 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Wed, 20 Jan 2010 18:17:59 +0000 Subject: [C++-sig] Boost-python/pybindgen and wrapping member variables In-Reply-To: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> References: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> Message-ID: On Wed, Jan 20, 2010 at 5:43 PM, Ben Fitzpatrick < bfitzpatrick at vtiinstruments.com> wrote: > Hi everyone, > > > > I think I?m finally getting the hang of this, I seem to have gotten almost > everything in my project working thanks to Gustavo?s latest pybindgen patch. > One of the remaining things I am having difficulty with is putting > annotations on member variables of a class. I have something of the form: > > > > class foo{ > > > > }; > > > > class baz { > > public: > > foo* var; > > } > > > > The error I am getting from pybindgen is ?WrapperWarning: Return value > ?::foo *? error (used in baz::var [variable]): > TypeConfigurationError(?Either caller_owns_return or > self.reference_existing_object must be given?) > > > > I know that the issue is that I need to stick an annotation on there. > Since the pointer is allocated and tracked by the underlying C++ code, I?m > pretty sure that I need to put reference_existing_object on it. I?ve tried > inserting ?{?reference_existing_object? : ?true?}? into the > global_annotations table, and also inserting it into the > parameter_annotations[?return?] dictionary. For kicks, I even tried both at > once. No matter what I do I can?t get rid of the error, or see it show up in > my final build, which leads me to believe there?s something I?m missing. I > went and looked up the documentation for reference_existing_object, but of > course none of their examples show how you could use it on a member > variable. What am I missing? > You are not missing anything. Annotations for member variables (pybindgen calls them "instance attributes") were not implemented. An oversight easily fixed: http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/742 > > > Thanks, > > Ben Fitzpatrick > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From bfitzpatrick at vtiinstruments.com Wed Jan 20 20:26:03 2010 From: bfitzpatrick at vtiinstruments.com (Ben Fitzpatrick) Date: Wed, 20 Jan 2010 13:26:03 -0600 Subject: [C++-sig] Boost-python/pybindgen and wrapping member variables In-Reply-To: References: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> Message-ID: <27AD07BD25612C40AF5C78CB49D09B4967CC0F7063@34093-MBX-C08.mex07a.mlsrvr.com> Gustavo, I think you win some sort of prize for not only fastest mailing list responses, but also fastest implementation of features. I reviewed the diff, and changed what I was adding to the global annotations table for these pointers to ?{?return_internal_reference?:?true?}? ? this seems to be what the new code in foo.h was doing. I am still getting the errors, though ? is this the right way of using it? And just to make sure, I grabbed a new checkout of pybindgen and re-installed it. From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org [mailto:cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org] On Behalf Of Gustavo Carneiro Sent: Wednesday, January 20, 2010 1:18 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost-python/pybindgen and wrapping member variables On Wed, Jan 20, 2010 at 5:43 PM, Ben Fitzpatrick > wrote: Hi everyone, I think I?m finally getting the hang of this, I seem to have gotten almost everything in my project working thanks to Gustavo?s latest pybindgen patch. One of the remaining things I am having difficulty with is putting annotations on member variables of a class. I have something of the form: class foo{ }; class baz { public: foo* var; } The error I am getting from pybindgen is ?WrapperWarning: Return value ?::foo *? error (used in baz::var [variable]): TypeConfigurationError(?Either caller_owns_return or self.reference_existing_object must be given?) I know that the issue is that I need to stick an annotation on there. Since the pointer is allocated and tracked by the underlying C++ code, I?m pretty sure that I need to put reference_existing_object on it. I?ve tried inserting ?{?reference_existing_object? : ?true?}? into the global_annotations table, and also inserting it into the parameter_annotations[?return?] dictionary. For kicks, I even tried both at once. No matter what I do I can?t get rid of the error, or see it show up in my final build, which leads me to believe there?s something I?m missing. I went and looked up the documentation for reference_existing_object, but of course none of their examples show how you could use it on a member variable. What am I missing? You are not missing anything. Annotations for member variables (pybindgen calls them "instance attributes") were not implemented. An oversight easily fixed: http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/742 Thanks, Ben Fitzpatrick _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From enrico.ng at lmco.com Wed Jan 20 23:51:05 2010 From: enrico.ng at lmco.com (Ng, Enrico) Date: Wed, 20 Jan 2010 17:51:05 -0500 Subject: [C++-sig] Arrays to python Message-ID: I have C code similar to the following: float image_data[IMAGE_SIZE]; const float *get_data() get_data returns a pointer to image_data. I'd like to expose get_data to python and have it return a copy of the array in some Python type. (it is actually a 2D array of image data) In the wrapper code, I tried something like: numeric::array py_get_data() { return numeric::array(get_data()); } With .def("get_data", &wrap::py_get_data) But I get this error: TypeError: No to_python (by-value) converter found for C++ type: float I thought I had done this in the past but I must be missing something. Any help would be much appreciated. From gjcarneiro at gmail.com Thu Jan 21 00:28:47 2010 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Wed, 20 Jan 2010 23:28:47 +0000 Subject: [C++-sig] Boost-python/pybindgen and wrapping member variables In-Reply-To: <27AD07BD25612C40AF5C78CB49D09B4967CC0F7063@34093-MBX-C08.mex07a.mlsrvr.com> References: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> <27AD07BD25612C40AF5C78CB49D09B4967CC0F7063@34093-MBX-C08.mex07a.mlsrvr.com> Message-ID: On Wed, Jan 20, 2010 at 7:26 PM, Ben Fitzpatrick < bfitzpatrick at vtiinstruments.com> wrote: > Gustavo, > > > > I think you win some sort of prize for not only fastest mailing list > responses, but also fastest implementation of features. I reviewed the diff, > and changed what I was adding to the global annotations table for these > pointers to ?{?return_internal_reference?:?true?}? ? this seems to be what > the new code in foo.h was doing. I am still getting the errors, though ? is > this the right way of using it? > I am not sure what is wrong. Assuming you are using a "pre_scan_hook", and that you are doing something like global_annotations[?return_internal_reference?] = True, in the proper attribute definition, then it should work. Is it the same error message, or a different error? > > And just to make sure, I grabbed a new checkout of pybindgen and > re-installed it. > > > > *From:* cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org[mailto: > cplusplus-sig-bounces+bfitzpatrick = > vtiinstruments.com at python.org] *On Behalf Of *Gustavo Carneiro > *Sent:* Wednesday, January 20, 2010 1:18 PM > *To:* Development of Python/C++ integration > *Subject:* Re: [C++-sig] Boost-python/pybindgen and wrapping member > variables > > > > > > On Wed, Jan 20, 2010 at 5:43 PM, Ben Fitzpatrick < > bfitzpatrick at vtiinstruments.com> wrote: > > Hi everyone, > > > > I think I?m finally getting the hang of this, I seem to have gotten almost > everything in my project working thanks to Gustavo?s latest pybindgen patch. > One of the remaining things I am having difficulty with is putting > annotations on member variables of a class. I have something of the form: > > > > class foo{ > > > > }; > > > > class baz { > > public: > > foo* var; > > } > > > > The error I am getting from pybindgen is ?WrapperWarning: Return value > ?::foo *? error (used in baz::var [variable]): > TypeConfigurationError(?Either caller_owns_return or > self.reference_existing_object must be given?) > > > > I know that the issue is that I need to stick an annotation on there. > Since the pointer is allocated and tracked by the underlying C++ code, I?m > pretty sure that I need to put reference_existing_object on it. I?ve tried > inserting ?{?reference_existing_object? : ?true?}? into the > global_annotations table, and also inserting it into the > parameter_annotations[?return?] dictionary. For kicks, I even tried both at > once. No matter what I do I can?t get rid of the error, or see it show up in > my final build, which leads me to believe there?s something I?m missing. I > went and looked up the documentation for reference_existing_object, but of > course none of their examples show how you could use it on a member > variable. What am I missing? > > You are not missing anything. Annotations for member variables (pybindgen > calls them "instance attributes") were not implemented. > > > > An oversight easily fixed: > > > > http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/742 > > > > > > Thanks, > > Ben Fitzpatrick > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > -- > Gustavo J. A. M. Carneiro > INESC Porto, Telecommunications and Multimedia Unit > "The universe is always one step beyond logic." -- Frank Herbert > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Thu Jan 21 02:02:45 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Wed, 20 Jan 2010 17:02:45 -0800 Subject: [C++-sig] Arrays to python In-Reply-To: References: Message-ID: <1264035765.10584.67.camel@mu> On Wed, 2010-01-20 at 17:51 -0500, Ng, Enrico wrote: > I have C code similar to the following: > > float image_data[IMAGE_SIZE]; > const float *get_data() > > get_data returns a pointer to image_data. I'd like to expose get_data to python and have it return a copy of the array in some Python type. (it is actually a 2D array of image data) > I have to admit I'm not really familiar with using boost::python::numeric; I don't know how well it works with numeric and numarray's successor, numpy, and I pretty much use numpy exclusively (no one is supporting the other two anymore). But you can do this by using the numpy C API directly: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#from-scratch and you can wrap the PyObject* you get back in a boost::python::object like so: #include boost::python::object py_get_data() { npy_intp shape[1] = { IMAGE_SIZE }; npy_intp strides[1] = { 1 }; boost::python::handle<> array( PyArray_New(&PyArray_Type, 1, shape, NPY_FLOAT, strides, get_data(), sizeof(float), NPY_C_ARRAY_RO, NULL) ); // handle is a C++ smart pointer for PyObject* return boost::python::object(array); } It's not elegant, but it should work. It should even handle exceptions in PyArray_New properly. But you also have to do some work in the module init function (in other words, inside the BOOST_PYTHON_MODULE macro): http://docs.scipy.org/doc/numpy/reference/c-api.array.html#importing-the-api As a bit of self-promotion, I should mention I've written a fairly extensive C++ multidimensional array library that provides automatic boost::python converters to numpy, and might do what you're looking for better: http://code.google.com/p/ndarray/ Documentation for the Python stuff isn't great, but I'd be happy to answer any questions. Jim Bosch From micdestefano at gmail.com Thu Jan 21 09:32:57 2010 From: micdestefano at gmail.com (Michele De Stefano) Date: Thu, 21 Jan 2010 09:32:57 +0100 Subject: [C++-sig] Arrays to python In-Reply-To: References: Message-ID: If you can build a wrapper function which returns a boost::numeric::ublas::vector, you can use the wrappers into the mds-utils library (http://code.google.com/p/mds-utils/ ... it's my library). If you build the doxygen documentation, you'll find a "Python C++ extensions utilities": use the "vector.hpp" and look at the usage examples. Bye. Michele 2010/1/20 Ng, Enrico : > I have C code similar to the following: > > float image_data[IMAGE_SIZE]; > const float *get_data() > > get_data returns a pointer to image_data. ?I'd like to expose get_data to python and have it return a copy of the array in some Python type. ?(it is actually a 2D array of image data) > > > In the wrapper code, I tried something like: > > numeric::array ?py_get_data() > { > ?return numeric::array(get_data()); > } > > With > ?.def("get_data", &wrap::py_get_data) > > > But I get this error: > > TypeError: No to_python (by-value) converter found for C++ type: float > > > I thought I had done this in the past but I must be missing something. ?Any help would be much appreciated. > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://code.google.com/p/mds-utils http://xoomer.virgilio.it/michele_de_stefano From bfitzpatrick at vtiinstruments.com Thu Jan 21 14:43:17 2010 From: bfitzpatrick at vtiinstruments.com (Ben Fitzpatrick) Date: Thu, 21 Jan 2010 07:43:17 -0600 Subject: [C++-sig] Boost-python/pybindgen and wrapping member variables In-Reply-To: References: <27AD07BD25612C40AF5C78CB49D09B4967CC0F6FDE@34093-MBX-C08.mex07a.mlsrvr.com> <27AD07BD25612C40AF5C78CB49D09B4967CC0F7063@34093-MBX-C08.mex07a.mlsrvr.com> Message-ID: <27AD07BD25612C40AF5C78CB49D09B4967CC0F72A9@34093-MBX-C08.mex07a.mlsrvr.com> Interesting, I changed it to the format you suggest and it seems to work. However, I changed it back to this way: global_annotations = {?return_internal_reference?:?true?} and it stopped working. I confirmed there was nothing in there before I added my annotation, so that seems strange to me. On the other hand, your solution works, so I?ll just use that. Thanks again, Ben From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org [mailto:cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org] On Behalf Of Gustavo Carneiro Sent: Wednesday, January 20, 2010 6:29 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost-python/pybindgen and wrapping member variables On Wed, Jan 20, 2010 at 7:26 PM, Ben Fitzpatrick > wrote: Gustavo, I think you win some sort of prize for not only fastest mailing list responses, but also fastest implementation of features. I reviewed the diff, and changed what I was adding to the global annotations table for these pointers to ?{?return_internal_reference?:?true?}? ? this seems to be what the new code in foo.h was doing. I am still getting the errors, though ? is this the right way of using it? I am not sure what is wrong. Assuming you are using a "pre_scan_hook", and that you are doing something like global_annotations[?return_internal_reference?] = True, in the proper attribute definition, then it should work. Is it the same error message, or a different error? And just to make sure, I grabbed a new checkout of pybindgen and re-installed it. From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com@python.org [mailto:cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com@python.org] On Behalf Of Gustavo Carneiro Sent: Wednesday, January 20, 2010 1:18 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost-python/pybindgen and wrapping member variables On Wed, Jan 20, 2010 at 5:43 PM, Ben Fitzpatrick > wrote: Hi everyone, I think I?m finally getting the hang of this, I seem to have gotten almost everything in my project working thanks to Gustavo?s latest pybindgen patch. One of the remaining things I am having difficulty with is putting annotations on member variables of a class. I have something of the form: class foo{ }; class baz { public: foo* var; } The error I am getting from pybindgen is ?WrapperWarning: Return value ?::foo *? error (used in baz::var [variable]): TypeConfigurationError(?Either caller_owns_return or self.reference_existing_object must be given?) I know that the issue is that I need to stick an annotation on there. Since the pointer is allocated and tracked by the underlying C++ code, I?m pretty sure that I need to put reference_existing_object on it. I?ve tried inserting ?{?reference_existing_object? : ?true?}? into the global_annotations table, and also inserting it into the parameter_annotations[?return?] dictionary. For kicks, I even tried both at once. No matter what I do I can?t get rid of the error, or see it show up in my final build, which leads me to believe there?s something I?m missing. I went and looked up the documentation for reference_existing_object, but of course none of their examples show how you could use it on a member variable. What am I missing? You are not missing anything. Annotations for member variables (pybindgen calls them "instance attributes") were not implemented. An oversight easily fixed: http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/742 Thanks, Ben Fitzpatrick _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From enrico.ng at lmco.com Thu Jan 21 15:10:41 2010 From: enrico.ng at lmco.com (Ng, Enrico) Date: Thu, 21 Jan 2010 09:10:41 -0500 Subject: [C++-sig] Arrays to python In-Reply-To: <1264035765.10584.67.camel@mu> References: <1264035765.10584.67.camel@mu> Message-ID: That was just my example, I do not require it to go into a numeric array. It just seemed like the way I was suppose to do it based on the documentation. As long as I can access the data in any form in python, I'll be happy. And I only need to read the data, I do not need to modify the array. I did see your library but I was hoping to be able to do this without incorporating another library. I had hoped that there was something simple after seeing the numeric part in the documentation. -- Enrico Ng -----Original Message----- From: Jim Bosch [mailto:talljimbo at gmail.com] Sent: Wednesday, January 20, 2010 8:03 PM To: cplusplus-sig at python.org Cc: Ng, Enrico Subject: Re: [C++-sig] Arrays to python On Wed, 2010-01-20 at 17:51 -0500, Ng, Enrico wrote: > I have C code similar to the following: > > float image_data[IMAGE_SIZE]; > const float *get_data() > > get_data returns a pointer to image_data. I'd like to expose get_data to python and have it return a copy of the array in some Python type. (it is actually a 2D array of image data) > I have to admit I'm not really familiar with using boost::python::numeric; I don't know how well it works with numeric and numarray's successor, numpy, and I pretty much use numpy exclusively (no one is supporting the other two anymore). But you can do this by using the numpy C API directly: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#from-scratch and you can wrap the PyObject* you get back in a boost::python::object like so: #include boost::python::object py_get_data() { npy_intp shape[1] = { IMAGE_SIZE }; npy_intp strides[1] = { 1 }; boost::python::handle<> array( PyArray_New(&PyArray_Type, 1, shape, NPY_FLOAT, strides, get_data(), sizeof(float), NPY_C_ARRAY_RO, NULL) ); // handle is a C++ smart pointer for PyObject* return boost::python::object(array); } It's not elegant, but it should work. It should even handle exceptions in PyArray_New properly. But you also have to do some work in the module init function (in other words, inside the BOOST_PYTHON_MODULE macro): http://docs.scipy.org/doc/numpy/reference/c-api.array.html#importing-the-api As a bit of self-promotion, I should mention I've written a fairly extensive C++ multidimensional array library that provides automatic boost::python converters to numpy, and might do what you're looking for better: http://code.google.com/p/ndarray/ Documentation for the Python stuff isn't great, but I'd be happy to answer any questions. Jim Bosch From talljimbo at gmail.com Thu Jan 21 22:17:08 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Thu, 21 Jan 2010 13:17:08 -0800 Subject: [C++-sig] Arrays to python In-Reply-To: References: <1264035765.10584.67.camel@mu> Message-ID: <1264108628.13173.71.camel@mu> On Thu, 2010-01-21 at 09:10 -0500, Ng, Enrico wrote: > I had hoped that there was something simple after seeing the numeric part in the documentation. Well, if you're content with a 1-D array and speed isn't a big issue, you can just copy the elements of your array into a Python list like this: boost::python::list py_get_data() { boost::python::list r; for (int n=0; n References: <1264035765.10584.67.camel@mu> <1264108628.13173.71.camel@mu> Message-ID: Thanks, this is pretty much what I ended up doing. Once I got that into python, I converted it to a narray -----Original Message----- From: cplusplus-sig-bounces+enrico.ng=lmco.com at python.org [mailto:cplusplus-sig-bounces+enrico.ng=lmco.com at python.org] On Behalf Of Jim Bosch Sent: Thursday, January 21, 2010 4:17 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Arrays to python On Thu, 2010-01-21 at 09:10 -0500, Ng, Enrico wrote: > I had hoped that there was something simple after seeing the numeric part in the documentation. Well, if you're content with a 1-D array and speed isn't a big issue, you can just copy the elements of your array into a Python list like this: boost::python::list py_get_data() { boost::python::list r; for (int n=0; n Hello, I am very interested in using Boost.Python to test my C++ codebase. However, I would like to have some tips on a typical layout of the files in my project. My codebase today is completely C++-based and I also have tests using cppunit. Here's my file structure of the GFL library (Windows dll): GFL/ include/ GFL <- headers go here src/ <- C++ source goes here (creates GFL.dll) Test/ <- cppunit tests go here (Test.exe links with GFL.dll) Now I need to create the python->C++ bridge using Boost.Python. This has to be separate from the GFL dll as I don't want to link with python in the main dll at this stage. Here's what I am thinking: GFL/ include/ GFL src/ Test/ PyBridge/ <- source files with Boost.Python bridge This would create two libraries, GFL.dll and GFL.PyBridge.dll. I am unsure of the naming convention. Now, I probably would put python test files in PyTest, like so: GFL/ include/ GFL src/ Test/ PyBridge/ PyTest/ <- nose tests here :-) What do you think about this structure? Anybody here doing similar things? I would really appreciate some feedback! :-) Now to another question (sorry if I am too off-topic on this one). We are using TeamCity for continuous integration. My goal is to integrate nose-tests using TeamCity. I can already vision how that would work. But I would also like to make GFL.dll and GFL.PyBridge.dll available to my integration&verification team, so that they can create their own python scripts for verification tests. Is there anyone here who has this kind of solution in place? If so, how do you make the compiled binaries easily available to the I&V team? If this is really too off-topic I'll take my question to the TeamCity forums (might do it anyway). Thanks in advance! Regards, Daniel Lidstr?m Stockholm, Sweden From the.groovy.gregory at googlemail.com Fri Jan 22 19:33:09 2010 From: the.groovy.gregory at googlemail.com (MrF) Date: Fri, 22 Jan 2010 19:33:09 +0100 Subject: [C++-sig] [Boost Python] Extended class loosing attributes when saving as pointer to BaseClass in C++ Message-ID: <4B59EF65.5070009@gmail.com> Hey, My problem is the following: I do have a C++ class, "BaseClass", that I am extending in Python ("SubClass"). Also there is another C++ class, let's call it "BaseClassManager" which has a vector of BaseClass* (well, actually it's holding shared_ptr's). Instances of "SubClass" are created in Python, but ownership has been transferred to C++, as "BaseClassManager" holds all the objects. Here is the code that illustrates this: Wrapped BaseClassManager ------------------------------------ class_("GameBaseX") .def("addObject", &BaseClassManager::addObject) // takes shared_ptr< BaseClass>& .def("getObjectByName", &BaseClassManager::getObjectByName); // takes a string, returns shared_ptr WrapperClass for Base (needed for transferring ownership) ------------------------------------ class BaseClassWrap : public BaseClass{ public: BaseClassWrap( PyObject* self_, const std::string& name) : BaseClass(name),self(self_) { Py_INCREF(self); } BaseClassWrap( PyObject* self_, const BaseClass& copy ) : BaseClass(copy), self(self_) { Py_INCREF(self); } ~BaseClassWrap() { Py_DECREF(self); } PyObject *self; }; Wrapped BaseClass ------------------------------------ class_ >("BaseClass", init()) .add_property("name", make_function(&BaseClass::getName, return_value_policy()) ); // both needed for using shared_ptr's together with the wrapper-class register_ptr_to_python >(); // to_python converter implicitly_convertible, shared_ptr >(); Subclass ------------------------------------ class Subclass(BaseClass): def __init__(self, name): BaseClass.__init__(self, name) self.foo = "bar" ------------------------------------------------------------------------------ Imagine the following Python code: obj = SubClass("superclass") BaseClassManager.addObject(obj) # and somewhere else obj = BaseClassManager.getObjectByName("superclass") print obj.name # prints "superclass" as expected print obj.foo # AttributeError: 'BaseClass' object has no attribute 'foo' Seems all attributes got lost, be it a member-variable or methods I defined in SubClass. Strangely obj is in both cases the same pointer (f. ex. "SubClass object at 0x02343345"). Is there something I can do to preserve the attributes? Otherwise it is kind of senseless to extend a C++ class in Python if it can't have its own attributes. Thanks a lot for the help. Cheers. From talljimbo at gmail.com Fri Jan 22 21:05:32 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Fri, 22 Jan 2010 12:05:32 -0800 Subject: [C++-sig] [Boost Python] Extended class loosing attributes when saving as pointer to BaseClass in C++ In-Reply-To: <4B59EF65.5070009@gmail.com> References: <4B59EF65.5070009@gmail.com> Message-ID: <1264190732.19156.17.camel@mu> I think I can explain what's going on, and I've got an idea for a partial solution. But first, try making BaseClassWrap multiply inherit from BaseClass and boost::python::wrapper. That might fix everything. If not, read on... When boost::python converts a C++ value to Python, it looks up the C++ RTTI type name in a registry and finds a converter for that type. Those converters generally make a new Python object, and put a boost::python::instance_holder in it, containing a C++ object by value or [smart] pointer. But what you want is to extract the PyObject* from the C++ object and just incref and return that. I think you could do this by writing your own Python version of BaseClassManager that checks for this possibility: object PyBaseClassManager_getObjectByName( BaseClassManager & manager, std::string const & name ) { shared_ptr r = manager.getObjectByName(name); shared_ptr w = dynamic_pointer_cast(r); if (w) { handle<> h(w->self); return object(h); } return object(r); } ...unfortunately, you'd have to do that with ANY C++ function that returns a shared_ptr. A better solution would be to write a custom to-python conversion for shared_ptr, or if necessary a custom ResultConverterGenerator to do that work, but that's a little more complicated. This is probably something boost::python should do automatically if BaseClassWrap is a subclass of wrapper. If it doesn't, and you can get me a complete example that demonstrates the problem, I'll see about making a patch to make that happen. Jim Bosch From the.groovy.gregory at googlemail.com Fri Jan 22 22:13:40 2010 From: the.groovy.gregory at googlemail.com (MrF) Date: Fri, 22 Jan 2010 22:13:40 +0100 Subject: [C++-sig] [Boost Python] Extended class loosing attributes when saving as pointer to BaseClass in C++ In-Reply-To: <1264190732.19156.17.camel@mu> References: <4B59EF65.5070009@gmail.com> <1264190732.19156.17.camel@mu> Message-ID: <4B5A1504.9090507@gmail.com> Thanks for help! > A better solution would be to write a > custom to-python conversion for shared_ptr > Tried it and works perfectly. Good hint! > This is probably something boost::python should do automatically if > BaseClassWrap is a subclass of wrapper. If it doesn't, and > you can get me a complete example that demonstrates the problem, I'll > see about making a patch to make that happen I'll have some free days in February so I'll put this into a small project for you to play around with, so the whole procedure can be made a little easier. Thanks a lot for your help! Cheers. From yunlin07 at gmail.com Sat Jan 23 02:29:00 2010 From: yunlin07 at gmail.com (lin yun) Date: Fri, 22 Jan 2010 17:29:00 -0800 Subject: [C++-sig] Please help: boost python 1.41 extension problem Message-ID: Hi, I am trying to install boost 1.41 on Redhat Enterprise Linux 5.3 and I got problem with the extension test. Following the instructions here: http://www.boost.org/doc/libs/1_41_0/libs/python/doc/building.html - I built boost python using bjam. - cd into the libs/python/example/quickstart/ directory - bjam toolset=gcc --verbose-test test Now I see embedding test passes while extension test failed. I got the same problem with boost 1.35, 1.37 on Fedora 7. Below is the error messages: ../../../../boost/type_traits/detail/cv_traits_impl.hpp:37: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:5067 Please submit a full bug report, with preprocessed source if appropriate. See for instructions. Preprocessed source stored into /tmp/ccIhs3ut.out file, please attach this to your bugreport. "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -I"../../../.." -I"/usr/include/python2.4" -c -o "bin/gcc-4.1.2/debug/extending.o" "extending.cpp" ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/extending.o... ...skipped extending.so for lack of extending.o... ...skipped test_ext for lack of extending.so... Does anyone encounter the same issue as me ? Anyone can help ? Thanks a lot, Yun -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerasimov at mlab.cs.msu.su Sat Jan 23 16:59:33 2010 From: gerasimov at mlab.cs.msu.su (sergun) Date: Sat, 23 Jan 2010 15:59:33 +0000 (UTC) Subject: [C++-sig] copy boost::python::object crashes Message-ID: I have a problem with storing reference to Python object inside C++. The following Boost.Python wrapping class: #include using namespace boost; using namespace boost::python; namespace cmodule { object y; void setY(object y1) { y = y1; } } using namespace cmodule; BOOST_PYTHON_MODULE(cmodule) { def("setY",setY); } Crashes with ?Segmentation fault? on so simple python fragment. import cmodule class Foo: pass cmodule.setY(Foo()) When I comment ?y = y1;? assignment everything is fine. What I?m doing wrong? Python version: 2.6 Boost version: 1.41 OS: FreeBSD 8.0 Sergey Gerasimov. From talljimbo at gmail.com Sat Jan 23 22:38:47 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sat, 23 Jan 2010 13:38:47 -0800 Subject: [C++-sig] copy boost::python::object crashes In-Reply-To: References: Message-ID: <1264282727.3199.6.camel@bishop> On Sat, 2010-01-23 at 15:59 +0000, sergun wrote: > I have a problem with storing reference to Python object inside C++. > > The following Boost.Python wrapping class: > > > > #include > > using namespace boost; > using namespace boost::python; > > namespace cmodule > { > > object y; > > void setY(object y1) { y = y1; } > > } > > using namespace cmodule; > > BOOST_PYTHON_MODULE(cmodule) > { > def("setY",setY); > } > > > > > Crashes with ?Segmentation fault? on so simple python fragment. > This might be a static initialization problem: you declare "y", but it's not clear from your code fragment whether it gets initialized. I would have expected that to result in a linker error, but the way Python does its dynamic loading might have suppressed that. It's probably a good idea to avoid global variables in source files anyhow. Wrapping it in a function: object & getY() { static object y; return y; } void setY(object y1) { getY() = y1; } might eliminate your segfault. Jim Bosch From dave at boostpro.com Sun Jan 24 03:10:31 2010 From: dave at boostpro.com (David Abrahams) Date: Sat, 23 Jan 2010 21:10:31 -0500 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <4B50A150.1010908@mgdesign.org> References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> <4B50A150.1010908@mgdesign.org> Message-ID: At Fri, 15 Jan 2010 18:09:36 +0100, Nicolas Lelong wrote: > > My previous mail once again got lost, gotta be more careful... > > > Changes (by dave): > > > > This looks terrific! I'll try to get it applied ASAP. Please poke me if > > you don't see it in trunk by the end of the week. > > Thanks ! As I didn't see the batch in trunk today, I poke you :) Applied; thanks for your patience. -- Dave Abrahams Meet me at BoostCon: http://www.boostcon.com BoostPro Computing http://www.boostpro.com From gerasimov at mlab.cs.msu.su Sun Jan 24 10:30:22 2010 From: gerasimov at mlab.cs.msu.su (sergun) Date: Sun, 24 Jan 2010 09:30:22 +0000 (UTC) Subject: [C++-sig] copy boost::python::object crashes References: <1264282727.3199.6.camel@bishop> Message-ID: Hi Jim, In my opinion ?object y;? is just declaration of global object, not static variable of some class (in this case you are right: explicit declaration needed, something like: ?object MyStaticClass::y;?). I have changed setY function to: void setY(PyObject * y1) { y = object(handle<>(y1)); } and it doesn?t make crash now. I?m not sure that such code has no problems and very interested to know why assignment of one bp::object to another is not correct. I suppose bp:object counteres references correctly and the original object is killed only on Python. Sergey. From talljimbo at gmail.com Mon Jan 25 02:32:12 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sun, 24 Jan 2010 17:32:12 -0800 Subject: [C++-sig] copy boost::python::object crashes In-Reply-To: References: <1264282727.3199.6.camel@bishop> Message-ID: <1264383132.4015.96.camel@bishop> On Sun, 2010-01-24 at 09:30 +0000, sergun wrote: > I have changed setY function to: > void setY(PyObject * y1) { y = object(handle<>(y1)); } > > and it doesn?t make crash now. > I?m not sure that such code has no problems and very interested to know why > assignment of one bp::object to another > is not correct. I suppose bp:object counteres references correctly and the > original object is killed only on Python. > As it turns out, the new code is quite likely worse. Here's what's probably going on: First, I should mention I get the segfault when quitting python after running the python code, not after executing the last statement, so if that's not what you experienced, there may be more going on. Anyhow, with the original version, the global variable holds the only reference to the Foo() object. When Python exits, and the destructor for the global variable executes, it DECREF's a Python object after a lot of Python's machinery has already been shut down. Interestingly, it doesn't fail if you do setY("a string") or setY(5), but that's not much consolation. With the new version, the global variable ends up holding a Foo object with ZERO reference count - I'm not sure, but I think it's already been destroyed by the time the Python setY() call finishes, and the C++ global variable is just a ticking time bomb. But since the reference count is zero, nothing happens when the global's destructor goes off. I think this all means it's probably a very bad idea to have a global or class-static boost::python::object (or handle<>) variable. The best workaround I can think of right now is to have a a global PyObject* instead, and do manual calls to Py_DECREF and Py_INCREF in the C++ setY function. That means the last thing left in the global will never get destroyed, but unless it has a non-trivial Python destruct that shouldn't matter. If you need to make sure it gets destroyed, I think you'll end up having to use Python's atexit. Jim From nico_ml at mgdesign.org Mon Jan 25 10:47:06 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Mon, 25 Jan 2010 10:47:06 +0100 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> <4B50A150.1010908@mgdesign.org> Message-ID: <4B5D689A.40902@mgdesign.org> An HTML attachment was scrubbed... URL: From dave at boostpro.com Mon Jan 25 16:28:55 2010 From: dave at boostpro.com (David Abrahams) Date: Mon, 25 Jan 2010 10:28:55 -0500 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <4B5D689A.40902@mgdesign.org> References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> <4B50A150.1010908@mgdesign.org> <4B5D689A.40902@mgdesign.org> Message-ID: At Mon, 25 Jan 2010 10:47:06 +0100, Nicolas Lelong wrote: > > Thanks Dave, > > not quite sure of it, but it looks like you added the unit tests to > the Jamfile, but you did not add the tests source code to the svn, > did I miss something. Gah, I hate SVN. > Also, the tests i submitted do not consider the compiler > brand/version, so they may fail on compilers that do not have the > Microsoft calling conventions. Did you consider that point ? No! The next question is, should defining the macros to turn on calling convention support cause an error on platforms where they're not supported (which would imply XML markup for those tests and/or #ifdef _MSC_VER in the tests themselves) or should it be benign (implying #ifdef _MSC_VER in the library files)? Your opinion? -- Dave Abrahams Meet me at BoostCon: http://www.boostcon.com BoostPro Computing http://www.boostpro.com From talljimbo at gmail.com Mon Jan 25 21:20:05 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Mon, 25 Jan 2010 12:20:05 -0800 Subject: [C++-sig] Please help: boost python 1.41 extension problem In-Reply-To: References: Message-ID: <1264450805.26787.17.camel@mu> On Fri, 2010-01-22 at 17:29 -0800, lin yun wrote: > Hi, > > I am trying to install boost 1.41 on Redhat Enterprise Linux 5.3 and I > got problem with the extension test. Following the instructions here: > http://www.boost.org/doc/libs/1_41_0/libs/python/doc/building.html > * I built boost python using bjam. > * cd into the libs/python/example/quickstart/ directory > * bjam toolset=gcc --verbose-test test > Now I see embedding test passes while extension test failed. I got the > same problem with boost 1.35, 1.37 on Fedora 7. Below is the error > messages: > > ../../../../boost/type_traits/detail/cv_traits_impl.hpp:37: internal > compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:5067 > > Please submit a full bug report, > > with preprocessed source if appropriate. > > See for instructions. > Your error message indicates a gcc internal error. While it's probably due at least in part to something unusual in your code or boost::python, that kind of stuff should cause gcc to exit more gracefully (and informatively) than this. You might learn something by reporting your error message either to the gcc developers (or Red Hat, since they're more directly responsible for the binary you have). At the very least, I imagine they'd like to hear about it. Jim Bosch From yunlin07 at gmail.com Mon Jan 25 21:38:44 2010 From: yunlin07 at gmail.com (lin yun) Date: Mon, 25 Jan 2010 12:38:44 -0800 Subject: [C++-sig] Please help: boost python 1.41 extension problem In-Reply-To: <1264450805.26787.17.camel@mu> References: <1264450805.26787.17.camel@mu> Message-ID: Hi, Jim: Thank you very much for your reply ! I did not mention that I had no problem with Boost 1.34, on the same system. Also I ever tried Boost 1.34 and 1.37 on Fedora 7, I got exactly the same result: Boost 1.34 worked fine while 1.37 failed on extension test. The test I ran was the example test from boost package: libs/python/example/quickstart/, which was recommended in the boost python installation instruction. There was no any personal code involved. I wonder if you, or anyone else had related experience ? Thanks again, Yun On Mon, Jan 25, 2010 at 12:20 PM, Jim Bosch wrote: > On Fri, 2010-01-22 at 17:29 -0800, lin yun wrote: > > Hi, > > > > I am trying to install boost 1.41 on Redhat Enterprise Linux 5.3 and I > > got problem with the extension test. Following the instructions here: > > http://www.boost.org/doc/libs/1_41_0/libs/python/doc/building.html > > * I built boost python using bjam. > > * cd into the libs/python/example/quickstart/ directory > > * bjam toolset=gcc --verbose-test test > > Now I see embedding test passes while extension test failed. I got the > > same problem with boost 1.35, 1.37 on Fedora 7. Below is the error > > messages: > > > > ../../../../boost/type_traits/detail/cv_traits_impl.hpp:37: internal > > compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:5067 > > > > Please submit a full bug report, > > > > with preprocessed source if appropriate. > > > > See for instructions. > > > > Your error message indicates a gcc internal error. While it's probably > due at least in part to something unusual in your code or boost::python, > that kind of stuff should cause gcc to exit more gracefully (and > informatively) than this. > > You might learn something by reporting your error message either to the > gcc developers (or Red Hat, since they're more directly responsible for > the binary you have). At the very least, I imagine they'd like to hear > about it. > > Jim Bosch > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Mon Jan 25 22:06:13 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Mon, 25 Jan 2010 13:06:13 -0800 Subject: [C++-sig] Please help: boost python 1.41 extension problem In-Reply-To: References: <1264450805.26787.17.camel@mu> Message-ID: <1264453573.27378.20.camel@mu> On Mon, 2010-01-25 at 12:38 -0800, lin yun wrote: > I did not mention that I had no problem with Boost 1.34, on the same > system. Also I ever tried Boost 1.34 and 1.37 on Fedora 7, I got > exactly the same result: Boost 1.34 worked fine while 1.37 failed on > extension test. The test I ran was the example test from boost > package: libs/python/example/quickstart/, which was recommended in > the boost python installation instruction. There was no any personal > code involved. > > I wonder if you, or anyone else had related experience ? > I have not, but I haven't tried boost > 1.34.1 on any Red Hat distros. I can confirm that this example compiles successfully with Boost 1.40 and the latest trunk on Ubuntu 9.10 (gcc 4.4.1). You may have noticed the line gcc aborts on: > > > > ../../../../boost/type_traits/detail/cv_traits_impl.hpp:37: > internal > > compiler error: in make_rtl_for_nonlocal_decl, at > cp/decl.c:5067 > > has not changed between Boost 1.34 and 1.35, but it refers to the macro BOOST_STATIC_CONSTANT, which is defined in boost/config/suffix.hpp, and reflects whether a compiler supports in-class initialization of static integral constant members. Perhaps your compiler does not fully support this feature, but boost thinks it does? Try adding the line #define BOOST_NO_INCLASS_MEMBER_INITIALIZATION to boost/config/user.hpp. Then recompile boost. Jim Bosch From martin.manduch at gmail.com Tue Jan 26 13:36:13 2010 From: martin.manduch at gmail.com (martin manduch) Date: Tue, 26 Jan 2010 13:36:13 +0100 Subject: [C++-sig] wrapping vector of pointers Message-ID: <92560a4e1001260436p3e547f38i3c749aa2ad09c114@mail.gmail.com> Hi, I need to wrap vector of pointers, because it's parameter in one function... I have following code: struct X { X(int nn) {n=nn;} int n; }; BOOST_PYTHON_MODULE(myVector) { class_("X", init()) .def_readwrite("n", &X::n); class_ >("XVec") .def(vector_indexing_suite >()) ; } I want to make XVec responsible for memory, which is addressed through pointers, but I don't know how. >>vec=XVec() >>a=X(7) >>vec.append(a) >>del a >>vec[0].n It prints 1682309121, but I want it to print: 7 Martin From daniel.lidstrom at sbg.se Tue Jan 26 15:47:20 2010 From: daniel.lidstrom at sbg.se (=?iso-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Tue, 26 Jan 2010 15:47:20 +0100 Subject: [C++-sig] Problem running the quickstart Message-ID: Hi, I have troubles compiling and running the quickstart: C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example\quickstart>bjam toolset=msvc-9.0 --verbose-test test --debug -configuration notice: found boost-build.jam at C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example\quickstart\boost-build.jam notice: loading Boost.Build from C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example\quickstart\..\..\..\..\tool s\build\v2 notice: Searching C:\Windows U:\ C:\cygwin\home\daniel C:\Users\Daniel.SBG C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\ python\example\quickstart\../../../../tools/build/v2 C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/kernel C:/Us ers/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/util C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/build C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/tools C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v 2/contrib C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/. for site-config configuration file site-config.jam . notice: Loading site-config configuration file site-config.jam from C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\ example\quickstart\..\..\..\..\tools\build\v2\site-config.jam . notice: Searching U:\ C:\cygwin\home\daniel C:\Users\Daniel.SBG C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\exam ple\quickstart\../../../../tools/build/v2 C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/kernel C:/Users/Daniel. SBG/Programming/boost_1_41_0/tools/build/v2/util C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/build C:/Users/D aniel.SBG/Programming/boost_1_41_0/tools/build/v2/tools C:/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/contrib C :/Users/Daniel.SBG/Programming/boost_1_41_0/tools/build/v2/. for user-config configuration file user-config.jam . notice: Loading user-config configuration file user-config.jam from C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\ example\quickstart\..\..\..\..\tools\build\v2\user-config.jam . notice: Searching ../../../.. for project-config configuration file project-config.jam . notice: Loading project-config configuration file project-config.jam from ..\..\..\..\project-config.jam . notice: [msvc-cfg] msvc-9.0 detected, command: 'c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe' notice: [msvc-cfg] msvc-8.0 detected, command: 'C:\Program Files\Microsoft Visual Studio 8\VC\bin\cl.exe' notice: will use 'c:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe' for msvc, condition msvc-9.0 notice: [msvc-cfg] condition: 'msvc-9.0//', setup: 'call "c:\Program Files\Microsoft Vi sual Studio 9.0\VC\vcvarsall.bat" x86 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0//32', setup: 'call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0/x86/', setup: 'call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0/x86/32', setup: 'call "c:\Program Files\Microso ft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0//64', setup: 'call "c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86_amd64 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0/x86/64', setup: 'call "c:\Program Files\Microso ft Visual Studio 9.0\VC\vcvarsall.bat" x86_amd64 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0/ia64/', setup: 'call "c:\Program Files\Microsof t Visual Studio 9.0\VC\vcvarsall.bat" x86_ia64 >nul ' notice: [msvc-cfg] condition: 'msvc-9.0/ia64/64', setup: 'call "c:\Program Files\Micros oft Visual Studio 9.0\VC\vcvarsall.bat" x86_ia64 >nul ' notice: [cmdline-cfg] Detected command-line request for msvc-9.0: toolset= msvc version= 9.0 notice: [cmdline-cfg] toolset msvc-9.0 already configured notice: iostreams: not using zlib compression notice: iostreams: not using zlib compression notice: iostreams: not using bzip2 compression notice: iostreams: not using bzip2 compression notice: [python-cfg] Configuring python... notice: [python-cfg] Registry indicates Python 3.0 installed at "C:\Python30\" notice: [python-cfg] Checking interpreter command "python"... notice: [python-cfg] running command 'DIR /-C /A:S "C:\Python30\python.exe" 2>&1' notice: [python-cfg] running command 'python -c "from sys import *; print('version=%d.%d\nplatform=%s\nprefix=%s\nexec_prefix =%s\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))" 2>&1' notice: [python-cfg] ...requested configuration matched! notice: [python-cfg] Details of this Python configuration: notice: [python-cfg] interpreter command: "python" notice: [python-cfg] include path: "C:\Python30\Include" notice: [python-cfg] library path: "C:\Python30\libs" notice: [python-cfg] DLL search path: "C:\Python30" error: Unable to find file or target named error: 'test_extending.py' error: referred from project at error: '.' There does not seem to be a script by the name test_extending.py. Did I miss something? Thanks in advance! Regards, Daniel Lidstr?m Stockholm, Sweden From yunlin07 at gmail.com Tue Jan 26 19:29:07 2010 From: yunlin07 at gmail.com (lin yun) Date: Tue, 26 Jan 2010 10:29:07 -0800 Subject: [C++-sig] Please help: boost python 1.41 extension problem In-Reply-To: <1264453573.27378.20.camel@mu> References: <1264450805.26787.17.camel@mu> <1264453573.27378.20.camel@mu> Message-ID: Wow, it worked like a magic!!! Thank you so much, Jim! On Mon, Jan 25, 2010 at 1:06 PM, Jim Bosch wrote: > On Mon, 2010-01-25 at 12:38 -0800, lin yun wrote: > > > I did not mention that I had no problem with Boost 1.34, on the same > > system. Also I ever tried Boost 1.34 and 1.37 on Fedora 7, I got > > exactly the same result: Boost 1.34 worked fine while 1.37 failed on > > extension test. The test I ran was the example test from boost > > package: libs/python/example/quickstart/, which was recommended in > > the boost python installation instruction. There was no any personal > > code involved. > > > > I wonder if you, or anyone else had related experience ? > > > > I have not, but I haven't tried boost > 1.34.1 on any Red Hat distros. > > I can confirm that this example compiles successfully with Boost 1.40 > and the latest trunk on Ubuntu 9.10 (gcc 4.4.1). > > You may have noticed the line gcc aborts on: > > > > > > > ../../../../boost/type_traits/detail/cv_traits_impl.hpp:37: > > internal > > > compiler error: in make_rtl_for_nonlocal_decl, at > > cp/decl.c:5067 > > > > > has not changed between Boost 1.34 and 1.35, but it refers to the macro > BOOST_STATIC_CONSTANT, which is defined in boost/config/suffix.hpp, and > reflects whether a compiler supports in-class initialization of static > integral constant members. Perhaps your compiler does not fully support > this feature, but boost thinks it does? > > Try adding the line > > #define BOOST_NO_INCLASS_MEMBER_INITIALIZATION > > to boost/config/user.hpp. Then recompile boost. > > > > Jim Bosch > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Tue Jan 26 20:44:37 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 26 Jan 2010 11:44:37 -0800 Subject: [C++-sig] Problem running the quickstart In-Reply-To: References: Message-ID: <1264535077.2513.2.camel@bishop> On Tue, 2010-01-26 at 15:47 +0100, Daniel Lidstr?m wrote: > error: Unable to find file or target named > error: 'test_extending.py' > error: referred from project at > error: '.' > > There does not seem to be a script by the name test_extending.py. Did I miss something? > Thanks in advance! > That file is in boost/libs/python/quickstart/. I don't know much about running Python in Windows, but it looks like it was just looking in the default system Python locations. You may have to update your PYTHONPATH. Jim Bosch From talljimbo at gmail.com Tue Jan 26 20:56:30 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 26 Jan 2010 11:56:30 -0800 Subject: [C++-sig] wrapping vector of pointers In-Reply-To: <92560a4e1001260436p3e547f38i3c749aa2ad09c114@mail.gmail.com> References: <92560a4e1001260436p3e547f38i3c749aa2ad09c114@mail.gmail.com> Message-ID: <1264535790.2513.14.camel@bishop> On Tue, 2010-01-26 at 13:36 +0100, martin manduch wrote: > > I want to make XVec responsible for memory, which is addressed through > pointers, but I don't know how. > That would be difficult, especially because you can't really subclass std::vector in a safe way. > > I need to wrap vector of pointers, because it's parameter in one function... > If it's only used in one function, I'd recommend writing a custom wrapper for that function that does a manual conversion from a Python list. Something like this: void py_accept_vector(boost::python::list const & sequence) { int size = boost::python::len(sequence); std::vector vector(size); for (int n = 0; n < size; ++n) { boost::python::extract converter(sequence[n]); if (!converter) { PyErr_SetString( PyExc_TypeError, "Expected sequence of 'X' objects." ); boost::python::throw_error_already_set(); } vector[n] = converter(); } accept_vector(vector); // The passed vector's items are managed // by Python, and cannot be relied upon // to be valid after the function exits. } You can then wrap "py_accept_vector" in the usual way: boost::python::def("accept_vector", py_accept_vector); Hope that helps! Jim Bosch From daniel.lidstrom at sbg.se Wed Jan 27 11:37:51 2010 From: daniel.lidstrom at sbg.se (=?iso-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Wed, 27 Jan 2010 11:37:51 +0100 Subject: [C++-sig] Problem running the quickstart In-Reply-To: <1264535077.2513.2.camel@bishop> References: <1264535077.2513.2.camel@bishop> Message-ID: > From: Jim Bosch [mailto:talljimbo at gmail.com] > > On Tue, 2010-01-26 at 15:47 +0100, Daniel Lidstr?m wrote: > > error: Unable to find file or target named > > error: 'test_extending.py' > > error: referred from project at > > error: '.' > > > > There does not seem to be a script by the name > test_extending.py. Did I miss something? > > Thanks in advance! > > > > That file is in boost/libs/python/quickstart/. > > I don't know much about running Python in Windows, but it > looks like it > was just looking in the default system Python locations. You may have > to update your PYTHONPATH. I don't have boost/libs/python/quickstart: C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python>dir /B build doc example index.html pyste release_notes.txt src test todo.html todo.txt Neither the example nor the quickstart folders contain test_extending.py: C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example>dir /B boost-build.jam getting_started1.cpp getting_started2.cpp Jamroot project.zip quickstart README std_pair.cpp test_getting_started1.py test_getting_started2.py test_std_pair.py tutorial C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example>cd quickstart C:\Users\Daniel.SBG\Programming\boost_1_41_0\libs\python\example\quickstart>dir /B bin boost-build.jam embedding.cpp extending.cpp Jamroot script.py Am I looking in the wrong place? /Daniel From talljimbo at gmail.com Wed Jan 27 12:05:33 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Wed, 27 Jan 2010 03:05:33 -0800 Subject: [C++-sig] Problem running the quickstart In-Reply-To: References: <1264535077.2513.2.camel@bishop> Message-ID: <1264590333.4375.5.camel@bishop> On Wed, 2010-01-27 at 11:37 +0100, Daniel Lidstr?m wrote: > Neither the example nor the quickstart folders contain test_extending.py: ... > > Am I looking in the wrong place? > Nope, that's right. It should be libs/python/examples/quickstart (I forgot the "examples" earlier). I don't know why you didn't get that file, but here's a link to a single-file download for it: https://svn.boost.org/trac/boost/export/59273/tags/release/Boost_1_41_0/libs/python/example/quickstart/test_extending.py Comparing your directory contents to mine, that seems to be all that's missing. Jim From daniel.lidstrom at sbg.se Wed Jan 27 16:27:02 2010 From: daniel.lidstrom at sbg.se (=?iso-8859-1?Q?Daniel_Lidstr=F6m?=) Date: Wed, 27 Jan 2010 16:27:02 +0100 Subject: [C++-sig] Problem running the quickstart In-Reply-To: <1264590333.4375.5.camel@bishop> References: <1264535077.2513.2.camel@bishop> <1264590333.4375.5.camel@bishop> Message-ID: > > > > Am I looking in the wrong place? > > > > Nope, that's right. It should be libs/python/examples/quickstart (I > forgot the "examples" earlier). > > I don't know why you didn't get that file, but here's a link to a > single-file download for it: > > https://svn.boost.org/trac/boost/export/59273/tags/release/Boo > st_1_41_0/libs/python/example/quickstart/test_extending.py > > Comparing your directory contents to mine, that seems to be all that's > missing. Thank you Jim, now I got it to compile! /Daniel From dave at boostpro.com Wed Jan 27 17:34:12 2010 From: dave at boostpro.com (David Abrahams) Date: Wed, 27 Jan 2010 11:34:12 -0500 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: <4B6020B3.6040401@mgdesign.fr> References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> <4B50A150.1010908@mgdesign.org> <4B5D689A.40902@mgdesign.org> <4B6020B3.6040401@mgdesign.fr> Message-ID: At Wed, 27 Jan 2010 12:17:07 +0100, Nicolas Lelong wrote: > > My thought was to leave the library files as-is, and to simply enable > the unit tests on 'toolsets' related to Microsoft compilers, and perhaps > add later other compilers that might support these calling conventions, > based on users needs. > > This way, each user would be free to configure its boost.python > without hassle, and tests would not break on 'uncertified' toolsets. I'm not sure exactly what "enable the unit tests" means in this case. Can you be explicit and/or preferably provide an illustrative patch? -- Dave Abrahams Meet me at BoostCon: http://www.boostcon.com BoostPro Computing http://www.boostpro.com From nico_ml at mgdesign.org Thu Jan 28 10:31:39 2010 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Thu, 28 Jan 2010 10:31:39 +0100 Subject: [C++-sig] boost python calling conventions support patch submission (__stdcall, __cdecl, __fastcall) In-Reply-To: References: <4B437643.5000103@mgdesign.org> <201001101118.25701.lists_ravi@lavabit.com> <4B50A150.1010908@mgdesign.org> <4B5D689A.40902@mgdesign.org> <4B6020B3.6040401@mgdesign.fr> Message-ID: <4B61597B.7010204@mgdesign.org> Le 27/01/2010 17:34, David Abrahams a ?crit : > I'm not sure exactly what "enable the unit tests" means in this case. > Can you be explicit and/or preferably provide an illustrative patch? > As I'm a complete bjam noob, I made an attempt that is certainly clumsy and/or inelegant. The idea would be to conditionally compile/run the test, the condition being the current toolset is in a given set of toolsets (currently only 'msvc' toolset). In the attached patch, I conditionnally define 'BOOST_PYTHON_TEST_ENABLE' on 'msvc' toolset, and I modified the tests to use calling conventions only if 'BOOST_PYTHON_TEST_ENABLE' if defined. I suppose that there's a way to instruct bjam to conditionally compile/run a test, that would be more clear, and would prevent to change the tests. What do you think ? Cheers, Nicolas. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: boost.python.calling_conventions_test_compiler_selection_hack.patch URL: From Matthew.Scouten at tradingtechnologies.com Fri Jan 29 22:53:39 2010 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Fri, 29 Jan 2010 15:53:39 -0600 Subject: [C++-sig] FW: Boost.Python.function bug Message-ID: <32490DFF7774554A85D65D23A9F0F9380C4DE822@chiex01> Hey folks, One of my users spotted this, and I think it is an error in BP. It works the same for any function exported. He states it more completely then I could, So I will just forward what he sent to me: From: Ben Walker (TT) Sent: Friday, January 29, 2010 3:27 PM To: Matthew Scouten (TT) Subject: Boost.Python.function bug >>> boost_func >>> type(boost_func) >>> import types >>> isinstance(boost_func, types.BuiltinFunctionType) True >>> dir(boost_func) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] >>> boost_func.__self__ Traceback (most recent call last): File "", line 1, in AttributeError: 'Boost.Python.function' object has no attribute '__self__' >>> hasattr(boost_func, '__self__') False >>> dir() says Boost.Python.function objects have a __self__ member, but accessing it throws an AttributeError. Furthermore, real builtin functions have a __self__ member and some python libraries assume that if something is an instance of a builtin function, it will have a __self__ member. Testing via hasattr does function appropriately for the actual behavior. This was discovered while trying to use Sphinx's autodoc extension (sphinx.pocoo.org) on a C++ library wrapped via Boost.Python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.lasher at gmail.com Sun Jan 31 17:23:48 2010 From: chris.lasher at gmail.com (Chris Lasher) Date: Sun, 31 Jan 2010 11:23:48 -0500 Subject: [C++-sig] Using code generated by Py++ as a Python extension Message-ID: <128a885f1001310823h7d43ac4dlde26c354e744160f@mail.gmail.com> I asked this question on Stack Overflow, but realized that perhaps few from the Py++ community are there yet. I'm re-posting the question here; I hope you don't mind. http://stackoverflow.com/questions/2169948/using-code-generated-by-py-as-a-python-extension I have a need to wrap an existing C++ library for use in Python. After reading through this answer http://stackoverflow.com/questions/456884/extending-python-to-swig-or-not-to-swig/456949#456949on choosing an appropriate method to wrap C++ for use in Python, I decided to go with Py++. I walked through the tutorial for Py++ http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/module_builder.html, using the tutorial files, and I got the expected output in generated.cpp, but I haven't figured out what to do in order to actually use the generated code as an extension I can import in Python. I'm sure I have to compile the code, now, but with what? Am I supposed to use bjam? Thanks, Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sun Jan 31 19:19:56 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 31 Jan 2010 20:19:56 +0200 Subject: [C++-sig] Using code generated by Py++ as a Python extension In-Reply-To: <128a885f1001310823h7d43ac4dlde26c354e744160f@mail.gmail.com> References: <128a885f1001310823h7d43ac4dlde26c354e744160f@mail.gmail.com> Message-ID: <7465b6171001311019i6a0af051h5f23470cd5ebe124@mail.gmail.com> On Sun, Jan 31, 2010 at 6:23 PM, Chris Lasher wrote: > I asked this question on Stack Overflow, but realized that perhaps few from > the Py++ community are there yet. I'm re-posting the question here; I hope > you don't mind. > > http://stackoverflow.com/questions/2169948/using-code-generated-by-py-as-a-python-extension I will answer here, would you mind to upload the answer to stackoverflow? Thanks. > > I have a need to wrap an existing C++ library for use in Python. > reading through this answer > http://stackoverflow.com/questions/456884/extending-python-to-swig-or-not-to-swig/456949#456949 > on choosing an appropriate method to wrap C++ for use in Python, I decided > to go with Py++. > > I walked through the tutorial for Py++ > http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/module_builder.html > , using the tutorial files, and I got the expected output in generated.cpp, > but I haven't figured out what to do in order to actually use the generated > code as an extension I can import in Python. I'm sure I have to compile the > code, now, but with what? Am I supposed to use bjam? After you generated the code you have to compile it and for this purpose you can use your favorite build system. I use bjam only to compile boost. After this, I prefer to use scons ( on Windows and on Linux ). The following is an example of sconstruct file, which is used to compile one of the Py++ unittests: ( this is a generated code too :-) ) import sys env = Environment() if 'linux' not in sys.platform: env['MSVS'] = {'VERSION': ''} env['MSVS_VERSION'] = '' Tool('msvc')(env) t = env.SharedLibrary( target=r'abstract_classes' , source=[ r'/home/roman/language-binding/sources/pyplusplus_dev/unittests/temp/abstract_classes.cpp' ] , LIBS=[ r"boost_python" ] , LIBPATH=[ r"",r"/home/roman/include/libs" ] , CPPPATH=[ r"/home/roman/boost_svn",r"/usr/include/python2.6",r"/home/roman/language-binding/sources/pyplusplus_dev/unittests/temp",r"/home/roman/language-binding/sources/pyplusplus_dev/unittests/data",r"/home/roman/boost_svn" ] , CCFLAGS=[ ] , SHLIBPREFIX='' , SHLIBSUFFIX='.so' ) Since your code generator written in Python, you can continue where Py++ stops and generate your favorite "make" file. You can go even father. Py++ tests generate the code, compile, load new module and test the functionality. All this is done in a single, stand alone process. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/