From seefeld at sympatico.ca Thu Apr 1 16:02:35 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 01 Apr 2004 09:02:35 -0500 Subject: [C++-sig] missing symbol in boost_python 1.31 Message-ID: <124e50adac47035dc3a7ba312f206c31406c2486@Orthosoft.ca> hi there, I'v switched from boost.python 1.30.2 to 1.31 yesterday, and I'm getting a runtime error concerning a missing symbol boost::python::objects::function_object(boost::function2<_object*, _object*, _object*, std::allocator > const&, unsigned) I'm working with g++ 3.2 on a RH 8 system. Any ideas what could cause this ? I didn't make any changes to my code... Thanks, Stefan From seefeld at sympatico.ca Thu Apr 1 16:09:47 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 01 Apr 2004 09:09:47 -0500 Subject: [C++-sig] missing symbol in boost_python 1.31 References: <124e50adac47035dc3a7ba312f206c31406c2486@Orthosoft.ca> Message-ID: <58506a0a221f939d2390086ed42233d8406c2637@Orthosoft.ca> sorry, that was a false alarm. A bug in my build system caused some object files not to be recompiled after the switch. It's working fine now. Thanks, Stefan From s_sourceforge at nedprod.com Thu Apr 1 12:39:01 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 01 Apr 2004 11:39:01 +0100 Subject: [C++-sig] Pyste and exporting inherited items Message-ID: <406BFF55.10019.12075479@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bruno, are you aware that by adding the exporters.importing mechanism you have totally broken pyste's detection of class inheritance thus causing the class_<...bases > system to stop working? Furthermore nested class definitions get replicated, thus causing Boost.Python to fault on startup complaining about multiple definitions. The solution for others afflicted is to comment out line 55 "if not exporters.importing" in infos.py. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQGvxR8EcvDLFGKbPEQKKxwCfRBndMv7ZIShBeodqkLHz/nToXPEAoK4U VoWQoNIhxixjreYHL6vmkUds =JYuC -----END PGP SIGNATURE----- From drostowsky at radioframenetworks.com Thu Apr 1 22:02:30 2004 From: drostowsky at radioframenetworks.com (David Rostowsky) Date: Thu, 1 Apr 2004 12:02:30 -0800 Subject: [C++-sig] Re: Virtual member functions cause exception in get_derived_class_object References: <001101c41734$5a143af0$64b3fea9@Presario2500> Message-ID: Attached are the files in question. Thanks for the direction. Im a newbie to these lists. In my original post I was trying to post the minimal that failed, so hence I wanted to give everything in the follow-up. Ill try to find a happier middle ground for future posts. "David Abrahams" wrote in message news:uwu4zvpit.fsf at boost-consulting.com... > > Hi David, > > First of all, please bring Boost.Python questions to the C++-sig: > http://www.boost.org/more/mailing_lists.htm#cplussig > > "David Rostowsky" writes: > > > I have a couple of really simple classes: > > > > class MyBase > > { > > public: > > int x; > > virtual int foo(int new_x) { }; // our derived classes may or may > > not override this function. Coders choice. > > }; > > > > class MyDerived: public MyBase > > { > > public: > > int y; > > MyDerived() { y = 0; }; > > int Get(void) { return y; }; > > void Set(int val) { y = val; }; > > }; > > > > My main goal in life is to create an instance of MyDerived class in > > C++: > > MyDerived my_derived = new MyDerived(); > > > > and then pass the pointer to a Python script where the Python script > > can call any of the public member functions. Yes, I am careful to keep > > the pointer around in the C++ code while the Python script uses it. > > So I expose the class (this may or may not be the source of my > > problems, need help): > > > > BOOST_PYTHON_MODULE(test) > > { > > using namespace boost::python; > > > > class_("MyDerived") > > .def("Get", &MyDerived::Get) > > .def("Set", &MyDerived::Set) > > ; > > } /* test*/ > > > > My impasse is that the virtual function seems to really give Boost > > hell when Im trying to pass the pointer to the class over to the > > python script. Heres the code snippet for that. > > Please post a complete, minimal, reproducible example. > > > Its the conversion thats just KILLING me. > > Chill, dude. You're still alive. At least someone's sending email > on your behalf ;-) > > > If I comment out the virtual function, everything works perfectly! I > > can pass the pointer over to my script, it calls the public member > > functions, and Im happy. HOWEVER, if I put the virtual function back > > in, the following line of code > > Well you've posted several lines there; can you be specific about > which one you're having problems with? > > > just EXPLODES! > > What does "EXPLODES" mean? Do you get a compilation error, a runtime > error, or something else? > > > // It crashes and burns in make_ptr_instance.cpp, function > > get_derived_class_object() > > boost::python::object my_arg(boost::ref(my_derived)); > > > > // pass the pointer over to the script now. > > int rval = callPython("myTestFunc", "Test String argument from c++", > > my_arg); > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost > begin 666 test_script.py M=')Y. at T*(" @("!I;7!O71H;VXZ M($EM<&]R="!354-#145$140A(2$B#0IE>&-E<'0Z#0H@(" @('!R:6YT(")0 M>71H;VXZ($EM<&]R="!&04E,140N+BXB#0H-"B -"B,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,-"B, at 5&5S="!M;V1U;&4-"B,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C M(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,-"F1E9B!M M>51E71H;VXZ($ED96YT:71Y(&]F(&5X<&]S960 at 8W!P3V)J.B B M+ T*(" @("!C<'!/8FHN<')I;G10='(H*0T*(" @("!P71H;VXZ.FAA M;F1L93P^(&UY7VUO9'5L93L-"@T*8VQACL-"@E"87-E,2 at I('L@>CT@,3L@?3L-"@EV:7)T=6%L('9O:60@ M3VY+97E5<"AU;G-I9VYE9"!S:&]R="!V:7)T=6%L7VME>2D@>R!].PT*#0I] M.PT*#0IC;&%SPT*<')O=&5C=&5D M. at T*"6EN="!X.PT*#0IP=6)L:6,Z#0H-"@E497-T0R at I('L@>" ](# [('T[ M#0H)=F]I9"!3970H:6YT('9A;"D@>R!X(#T@=F%L.R!].PT*"6EN="!'970H M=F]I9"D@>R!R971U#L@?3L-"B @("!V;VED('!R:6YT4'1R*"D@>R!P MPT*(" @('5S:6YG(&YA;65S<&%C92!B;V]S=#HZ<'ET M:&]N.PT*#0H@("!O8FIE8W0@=&5S=$-L87-S(#T at 8VQA7!E71H;VXH71H;VXZ.F]B:F5C="8@;V)J M*3L-"@T*+R\@0V]N=F5N:65N8V4 at 9G5N8W1I;VYS#0IB;V]S=#HZ<'ET:&]N M.CIH86YD;&4\/B!I;7!OPT*"75S:6YG(&YA;65S<&%C92!B;V]S=#HZ<'ET:&]N.PT*#0H@ M(" @4'E/8FIE8W0@*FUO9'5L95]P='(@/2!0>4EM<&]R=%]);7!OPT*"0E/=71P=71$ M96)U9U-T71H;VXZ.F]B M:F5C="!G971?9G5N8W1I;VXH8V]N4]B:F5C=" J(&1I8W0@/2!0 M>4UO9'5L95]'971$:6-T*&UY7VUO9'5L92YG970H*2D[( T*"0T*(" @(&)O M;W-T.CIP>71H;VXZ.G-T71H;VXZ.F]B:F5C="AB;V]S=#HZ<'ET:&]N.CIH M86YD;&4\/BA0>41I8W1?1V5T271E;2AD:6-T+"!F=6YC3F%M92YP='(H*2DI M*3L-"@T*?2 O*B!G971?9G5N8W1I;VX@*B\-"@T*:6YT(&-A;&Q0>71H;VXH M8V]N71H;VXZ.F]B:F5C="!F=6YC M(#T at 9V5T7V9U;F-T:6]N*&-O;G-T7V-APT*:6YT(')V M86P[#0H-"E1E6]N92!I M2$@#0H)*B\@(" @(" @( T*(" @(" @("!O8FIE8W0 at 87)G,BAT M97-T,7!T51E Sorry if I am asking a question that has already been answered; the number of threads in this forum is formidable, and I can only see so far. This question was asking previously by my teammate Adrian Bentley; now that we know more about the problem, hopefully we can get an answer ;). I am working on a game engine that is attempting to use python for scripting support. And unusual requirement of our engine is the necessity of be able to manipulate types in C++ or Python, pretty much at the same time, e.g. dynamically instantiating an entity in C++ and then being able to manipulate it in python, and then updating its status in C++. I won't go into detail on why this is necessary, suffice to say, it has to deal with managing modules at run-time. I am most of the way to acheiving this goal; however, I am having trouble trying to access said C++ objects from python after I have instantiated them. to give you some idea what I am trying to do, following the boost tutorial I have a class that looks sorta like this --------------------------------------------------- struct PythonManager { dict main_namespace; handle<> main_module; //calls PyInitialize, and grabs the main module and namespace PythonManager(); //calls PyFinalize ~PythonManager(); //runs the interpreter on a single expression, and returns the result object EvaluateExpression(std::string &exp); //runs the interpreter on a multiline script void EvaluateScript(std::string &scr); struct PythonWrapper: public PyObject {}; PythonWrapper * MakeDualObject(int sizebytes, PyTypeObject *pto, std::string &varname) { //Get memory from Python and do necessary Python initialization PythonWrapper * mem = (PythonWrapper*)PyObject_Malloc(sizebytes); object obj( handle<>(PyObject_Init(mem, pto))); //put the variable into Python's variable namespace main_namespace[varname.c_str()] = obj; //set up some of my own tracking here.... return mem; } }; ----------------------------------------------------------- Now, the test that I am subjecting myself to see if all of this works is to have one of my defined types that I have extended into Python and another that I have created behind the scenes (like above) play well together. Unfortunately, I haven't gotten that far; so far, I am having trouble trying to get Python to recognize the types that I have just fed it. I successfully have extended a quaternion class in to python, and so I am using that as my test case, even stealing its typeobj * for use in the making these dual-language-objects. ------------------------------------------------------ struct PyQuat: public PyWrapper, public quat {}; //... _PythonManager.EvaluateScript("import mymath"); _PythonManager.EvaluateScript("x = mymath.quat(1,0,0,0)"); object testquat = _PythonManager.EvaluateExpression("x"); //verify that testquat really is a quat. PyWrapper *test = _PythonManager.MakeDualObject(sizeof(PyQuat), testquat.ptr()->objtype, "y"); //now the interpreter goes "boom!" _PythonManager.EvaluateScript("printquat(y)"); -------------------------------------------------------------- So, obviously what I am doing here is probably sub-optimal; still does anybody know of how to pull this off? Even better, if anybody knows of a more elegant way to pull this off, I am all ears. And again, once I pull that off above, I'll need to be able to make a behind-the-scenes-quat and made-in-python-quat play nicely; any advice on how to make that work would be really appreciated. Thanks for your time and patience, Mike Gonzales From dave at boost-consulting.com Thu Apr 1 22:45:55 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 01 Apr 2004 15:45:55 -0500 Subject: [C++-sig] Re: Virtual member functions cause exception in get_derived_class_object References: <001101c41734$5a143af0$64b3fea9@Presario2500> Message-ID: "David Rostowsky" writes: > Attached are the files in question. Thanks for the direction. Im a newbie to > these lists. In my original post I was trying to post the minimal that > failed, so hence I wanted to give everything in the follow-up. Ill try to > find a happier middle ground for future posts. Also, it'd be good to post instructions for running the test; e.g. where is the test script placed? Incidentally, the slightly modified program I enclosed produces: C++ : Initializing Python and loading script 'import site' failed; use -v for traceback Python: Import SUCCEEDED!!! C++ : Ptr=0x00867958 C++ : test1ptr->Get() in C++ before Python call: 0 Python: msg = Test String argument from c++ Python: Identity of 'local' MyClass object: C++ : Ptr=0x00868B70 Python: Current state: 0 Python: New state : 1234 Python: Identity of exposed cppObj: C++ : Ptr=0x00867958 Python: cppObj.Get() on entry: 0 Python: cppObj.Get() on exit : 9 C++ : callPython() returned: 999 C++ : test1ptr->Get() after Python call: 9 C++ : Press any key to quit -------------- next part -------------- A non-text attachment was scrubbed... Name: test.cpp Type: text/x-cplusplus Size: 6628 bytes Desc: not available URL: -------------- next part -------------- -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 1 22:59:06 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 01 Apr 2004 15:59:06 -0500 Subject: [C++-sig] Re: Accessing instances of C++ objects in Python - Plus more References: <3.0.6.32.20040401122040.009e8458@mail.digipen.edu> Message-ID: Mike Gonzales writes: > Sorry if I am asking a question that has already been answered; the number > of threads in this forum is formidable, and I can only see so far. This > question was asking previously by my teammate Adrian Bentley; now that we > know more about the problem, hopefully we can get an answer ;). > > I am working on a game engine that is attempting to use python for > scripting support. And unusual requirement of our engine is the necessity > of be able to manipulate types in C++ or Python, pretty much at the same > time, e.g. dynamically instantiating an entity in C++ and then being able > to manipulate it in python, and then updating its status in C++. I won't > go into detail on why this is necessary, No problem; that's what Boost.Python is for. > suffice to say, it has to deal with managing modules at run-time. > I am most of the way to acheiving this goal; however, I am having trouble > trying to access said C++ objects from python after I have instantiated them. > > to give you some idea what I am trying to do, following the boost tutorial > I have a class that looks sorta like this > > --------------------------------------------------- > struct PythonManager > { > dict main_namespace; > handle<> main_module; > > //calls PyInitialize, and grabs the main module and namespace > PythonManager(); > > //calls PyFinalize > ~PythonManager(); PyFinalize isn't supported with Boost.Python. See http://www.boost-consulting.com/boost/libs/python/todo.html#pyfinalize-safety > //runs the interpreter on a single expression, and returns the result > object EvaluateExpression(std::string &exp); > //runs the interpreter on a multiline script > void EvaluateScript(std::string &scr); > > struct PythonWrapper: public PyObject > {}; > > PythonWrapper * MakeDualObject(int sizebytes, PyTypeObject *pto, > std::string &varname) > { > //Get memory from Python and do necessary Python initialization > PythonWrapper * mem = (PythonWrapper*)PyObject_Malloc(sizebytes); > object obj( handle<>(PyObject_Init(mem, pto))); If pto refers to a wrapped C++ class, this is the wrong way to go about it. > //put the variable into Python's variable namespace > main_namespace[varname.c_str()] = obj; > > //set up some of my own tracking here.... > > return mem; > } > }; > ----------------------------------------------------------- > > Now, the test that I am subjecting myself to see if all of this works is to > have one of my defined types that I have extended into Python and another > that I have created behind the scenes (like above) play well together. > Unfortunately, I haven't gotten that far; so far, I am having trouble > trying to get Python to recognize the types that I have just fed it. > > I successfully have extended a quaternion class in to python, and so I am > using that as my test case, even stealing its typeobj * for use in the > making these dual-language-objects. > > ------------------------------------------------------ > struct PyQuat: public PyWrapper, public quat > {}; Is this PyQuat thing wrapped with class_ ?? > //... > _PythonManager.EvaluateScript("import mymath"); > _PythonManager.EvaluateScript("x = mymath.quat(1,0,0,0)"); > object testquat = _PythonManager.EvaluateExpression("x"); > > //verify that testquat really is a quat. > > PyWrapper *test = _PythonManager.MakeDualObject(sizeof(PyQuat), > testquat.ptr()->objtype, "y"); > //now the interpreter goes "boom!" > _PythonManager.EvaluateScript("printquat(y)"); > -------------------------------------------------------------- > > So, obviously what I am doing here is probably sub-optimal; still does > anybody know of how to pull this off? It's not even clear what you're trying to pull off. Incomplete code snippets don't leave us with much of a clue as to what the problem might be. The best way to get help is to reduce your problem to a complete, minimal example. I'm not sure if this addresses your problem, but you can capture any Python wrapper for a C++ class this way object T_class = class_("T") // methods, etc... ; and then you can make a wrapped T object this way: object wrapped_T = T_class(/*whatever args you like*/); and you can access the underlying T this way: T& t = extract(wrapped_T); > Even better, if anybody knows of a more elegant way to pull this > off, I am all ears. And again, once I pull that off above, I'll > need to be able to make a behind-the-scenes-quat and > made-in-python-quat play nicely; any advice on how to make that work > would be really appreciated. Sorry, most of your questions are too imprecise to answer with confidence. What does "play nicely" mean? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 1 23:02:26 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 01 Apr 2004 16:02:26 -0500 Subject: [C++-sig] Re: Virtual member functions cause exception in get_derived_class_object References: <001101c41734$5a143af0$64b3fea9@Presario2500> Message-ID: Please see my replies on the C++-sig. Cheers! -- Dave Abrahams Boost Consulting www.boost-consulting.com From halbert at bbn.com Thu Apr 1 23:32:02 2004 From: halbert at bbn.com (Dan Halbert) Date: Thu, 1 Apr 2004 16:32:02 -0500 Subject: [C++-sig] Pyste: Virtual class wrapper doesn't refcount object Message-ID: <200404012132.i31LW2Z12116@rolex.bbn.com> In Pyste from the 1.31.0 release: If Pyste finds any virtual methods in a class it is wrapping (if I understand correctly), it generates a class wrapper for that class that looks something like this: struct VMClass_Wrapper : VMClass_Wrapper { (PyObject* self_): VMClass(), self(self_) {} void f(long int p0) { call_method< void >(self, "f", p0); } PyObject* self; }; Note that the self object is not properly reference-counted. It seems to me it should be, since it's held by the struct, and can disappear from scope in the Python code, and so would go out of existence. I had just such an error when using this class in a callback situation: registerMyCallback(VMClass(), ...) # uses an anonymous VMClass() object I fixed this by modifying the code generated by Pyste to use handle<> and borrowed(): struct VMClass_Wrapper : VMClass_Wrapper { (PyObject* self_): VMClass(), self(borrowed(self_)) {} // was self(self_) void f(long int p0) { call_method< void >(self.get(), "f", p0); // was just self } handle<> self; // was PyObject* self; }; Anything wrong with this? I believe I am using borrowed() properly here, but I'm not 100% sure. If it's OK, it's a fix to make to Pyste. Dan From dave at boost-consulting.com Fri Apr 2 00:20:52 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 01 Apr 2004 17:20:52 -0500 Subject: [C++-sig] Re: Pyste: Virtual class wrapper doesn't refcount object References: <200404012132.i31LW2Z12116@rolex.bbn.com> Message-ID: Dan Halbert writes: > In Pyste from the 1.31.0 release: > > If Pyste finds any virtual methods in a class it is wrapping (if I > understand correctly), it generates a class wrapper for that class > that looks something like this: > > > struct VMClass_Wrapper : VMClass_Wrapper > { > (PyObject* self_): > VMClass(), self(self_) {} > > void f(long int p0) { > call_method< void >(self, "f", p0); > } > > PyObject* self; > }; > > > Note that the self object is not properly reference-counted. It seems > to me it should be No, Pyste generates correct code for this case. See http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html. The Python class already owns the C++ class. That would create an ownership cycle. > since it's held by the struct, and can disappear from scope in the > Python code, and so would go out of existence. > > I had just such an error when using this class in a callback situation: > > registerMyCallback(VMClass(), ...) # uses an anonymous VMClass() object I'm not sure what that's doing, but your problem lies elsewhere. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 1 22:34:20 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 01 Apr 2004 15:34:20 -0500 Subject: [C++-sig] Re: Virtual member functions cause exception in get_derived_class_object References: <001101c41734$5a143af0$64b3fea9@Presario2500> Message-ID: "David Rostowsky" writes: > Attached are the files in question. Thanks for the direction. Im a newbie to > these lists. In my original post I was trying to post the minimal that > failed, so hence I wanted to give everything in the follow-up. Ill try to > find a happier middle ground for future posts. Can you try to answer the other questions I asked in my reply? -- Dave Abrahams Boost Consulting www.boost-consulting.com From aashish at vrac.iastate.edu Fri Apr 2 04:59:56 2004 From: aashish at vrac.iastate.edu (aashish) Date: Thu, 1 Apr 2004 20:59:56 -0600 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs In-Reply-To: <93618711046370@webmail.iastate.edu> Message-ID: <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Hi, I need to pass a dictionary from python to C++ function which is defined as void setVariables(ValueMapPtr variables); where I have typedef ValueMapPtr as //a shared ptr of a value map typedef boost::shared_ptr< ValueMap > ValueMapPtr; // And typedef std::map< std::string, std::vector > ValueMap; Is it possible?? Do I need to use register_ptr_to_python ? Any help is highly appreciated. Thanks, Aashish From halbert at jubilee.bbn.com Fri Apr 2 06:02:06 2004 From: halbert at jubilee.bbn.com (Dan Halbert) Date: Thu, 1 Apr 2004 23:02:06 -0500 Subject: [C++-sig] Re: Pyste: Virtual class wrapper doesn't refcount object In-Reply-To: (message from David Abrahams on Thu, 01 Apr 2004 17:20:52 -0500) References: <200404012132.i31LW2Z12116@rolex.bbn.com> Message-ID: <200404020402.i32426C03669@hbo.bbn.com> >> Note that the self object is not properly reference-counted. It seems >> to me it should be > >No, Pyste generates correct code for this case. See >http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html. OK, I see I am incorrectly blaming Pyste. >The Python class already owns the C++ class. That would create an >ownership cycle. > >> since it's held by the struct, and can disappear from scope in the >> Python code, and so would go out of existence. OK, below is a complete tested small BPL example of the problem I had before I added the borrowed and handle<> in the callback wrapper. I must be misunderstanding something about object ownership. ============================================================================== #include #include using namespace boost::python; // Original C++ class struct Callback { virtual void do_callback() = 0; }; // BPL-tutorial-style wrapper, same as generated by Pyste struct Callback_Wrapper : Callback { Callback_Wrapper(PyObject* self_) : Callback(), self(self_) {} void do_callback() { call_method< void >(self, "do_callback"); } PyObject* self; }; Callback* registered_callback; void register_callback(Callback* cb) { registered_callback = cb; } void call_callback() { registered_callback->do_callback(); } BOOST_PYTHON_MODULE(cb) { class_("Callback", init< >()) .def("do_callback", pure_virtual(&Callback::do_callback)); def("register_callback", register_callback); def("call_callback", call_callback); } ============================================================================== ============================================================================== Now, I'll try it in Python: % python Python 2.3.3 (#1, Mar 1 2004, 12:51:08) [GCC 3.2.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cb >>> class MyCallback(cb.Callback): # subclass the C++ class ... def do_callback(self): ... print "callback called" ... >>> cback = MyCallback() # create an instance & remember it >>> cb.register_callback(cback) # register the callback >>> cb.call_callback() # call the callback callback called # callback works! >>> cb.register_callback(MyCallback()) # anonymous instance, short lifetime >>> cb.call_callback() # call the new callback instance Segmentation fault # BOOM! ============================================================================== If I wrote register_callback(MyCPPCallback()); // BAD IDEA; Callback doesn't live long in C++, I wouldn't expect that to work at all, because the MyCPPCallback() object doesn't live past its use as a parameter. Maybe I shouldn't expect it to work in Python either? I want the C++ code to take ownership of the MyCallback PyObject, or more simply, just increment its reference count. Perhaps I need a policy for the passed-in MyCallback object?? The Call Policies part of the tutorial seems applicable. But all the appropriate-sounding policies seem to apply only to return values. What am I doing wrong? Thanks, Dan From danielhorn at mindspring.com Fri Apr 2 10:40:05 2004 From: danielhorn at mindspring.com (Daniel Horn) Date: 02 Apr 2004 00:40:05 -0800 Subject: [C++-sig] Vega Strike uses boost::python Message-ID: <1080895205.29404.7.camel@mirror> Vega Strike is the 3D Space Simulator that allows you to trade and bounty hunt in a vast universe. Players face dangers, decisions, piracy, and aliens... Instead of going the hackneyed route of using Lua for game scripting, Vega Strike (http://vegastrike.sourceforge.net/) has decided to base its scripting on python, using boost as the layer between the class hierarchy in python and the class hierarchy in C++. The result is a very flexible scripting system that treats units as native python classes when designing missions or writing AI's. A large economic and planetary simulation is currently being run in the background in python and the results are returned back into C++ in the form of various factions' spaceships appearing near worlds that they are simulated to be near in python if the player is in the general neighborhood. From dave at boost-consulting.com Fri Apr 2 15:06:37 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Apr 2004 08:06:37 -0500 Subject: [C++-sig] Re: Pyste: Virtual class wrapper doesn't refcount object References: <200404012132.i31LW2Z12116@rolex.bbn.com> <200404020402.i32426C03669@hbo.bbn.com> Message-ID: Dan Halbert writes: > >> Note that the self object is not properly reference-counted. It seems > >> to me it should be > > > >No, Pyste generates correct code for this case. See > >http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html. > > OK, I see I am incorrectly blaming Pyste. > > >The Python class already owns the C++ class. That would create an > >ownership cycle. > > > >> since it's held by the struct, and can disappear from scope in the > >> Python code, and so would go out of existence. > > > OK, below is a complete tested small BPL example of the problem I had > before I added the borrowed and handle<> in the callback wrapper. I > must be misunderstanding something about object ownership. Yep. The basic principle is: A wrapped C++ object is always owned by the Python object that wraps it. Another principle you can use is: A when a Python object x is converted to a shared_ptr p, p maintains a reference to x, not just to *p. I'm inverting the order of your code snippets: | ============================================================================== | | Now, I'll try it in Python: | | | % python | Python 2.3.3 (#1, Mar 1 2004, 12:51:08) | [GCC 3.2.2] on linux2 | Type "help", "copyright", "credits" or "license" for more information. |>>> import cb |>>> class MyCallback(cb.Callback): # subclass the C++ class | ... def do_callback(self): | ... print "callback called" | ... |>>> cback = MyCallback() # create an instance & remember it |>>> cb.register_callback(cback) # register the callback |>>> cb.call_callback() # call the callback | callback called # callback works! Right; the callback's lifetime is maintained by the the module dict's 'cback' entry. |>>> cb.register_callback(MyCallback()) # anonymous instance, short lifetime |>>> cb.call_callback() # call the new callback instance | Segmentation fault # BOOM! Right; the Python object is gone at this point. | ============================================================================== | If I wrote | | register_callback(MyCPPCallback()); // BAD IDEA; Callback doesn't live long Right. I don't know what MyCPPCallback is, but if it's a class, you've got the same problem as above. | in C++, I wouldn't expect that to work at all, because the MyCPPCallback() | object doesn't live past its use as a parameter. Maybe I shouldn't | expect it to work in Python either? Not unless you do something to manage the lifetime of the Python object. | I want the C++ code to take ownership of the MyCallback PyObject Exactly. | or more simply, just increment its reference count. No, you don't want that. In that case it'll leak. | Perhaps I need a policy for the passed-in MyCallback object?? I don't see how it could help. | The Call Policies part of the tutorial seems applicable. But all the | appropriate-sounding policies seem to apply only to return values. | What am I doing wrong? The solution is to get the C++ code to hang onto the Python object, rather than just the C++ object. Here's one approach: | | ============================================================================== | #include | #include #include | using namespace boost::python; | | // Original C++ class | struct Callback | { | virtual void do_callback() = 0; | }; | | // BPL-tutorial-style wrapper, same as generated by Pyste | struct Callback_Wrapper : Callback | { | Callback_Wrapper(PyObject* self_) : Callback(), self(self_) {} | void do_callback() { call_method< void >(self, "do_callback"); } | PyObject* self; | }; typedef boost::shared_ptr CallbackPtr; | // Callback* registered_callback; CallbackPtr registered_callback; | // void register_callback(Callback* cb) void register_callback(CallbackPtr cb) | { | registered_callback = cb; | } | | void call_callback() | { | registered_callback->do_callback(); | } | | BOOST_PYTHON_MODULE(cb) | { | class_("Callback", init< >()) | .def("do_callback", pure_virtual(&Callback::do_callback)); | | def("register_callback", register_callback); | def("call_callback", call_callback); | } | ============================================================================== HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Apr 2 15:13:28 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Apr 2004 08:13:28 -0500 Subject: [C++-sig] Re: Vega Strike uses boost::python References: <1080895205.29404.7.camel@mirror> Message-ID: Thanks, Daniel! I added this to the projects page. I hope you don't mind, but... Daniel Horn writes: > Vega Strike is the 3D Space Simulator that allows you to trade and > bounty hunt in a vast universe. Players face dangers, decisions, piracy, > and aliens... > > Instead of going the hackneyed route of using Lua for game scripting, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...I left the above phrase out. Publicly bashing Lua would be unseemly for Boost.Python ;-) > Vega Strike (http://vegastrike.sourceforge.net/) > has decided to base its scripting on python, using boost as the layer > between the class hierarchy in python and the class hierarchy in C++. > The result is a very flexible scripting system that treats units as > native python classes when designing missions or writing AI's. > > A large economic and planetary simulation is currently being run in the > background in python and the results are returned back into C++ in the > form of various factions' spaceships appearing near worlds that they are > simulated to be near in python if the player is in the general > neighborhood. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mgonzale at digipen.edu Fri Apr 2 19:34:24 2004 From: mgonzale at digipen.edu (Mike Gonzales) Date: Fri, 02 Apr 2004 09:34:24 -0800 Subject: [C++-sig] Re: Accessing instances of C++ objects in Python - Plus more Message-ID: <3.0.6.32.20040402093424.009e8458@mail.digipen.edu> Thank you for your input - I am incorporating it to make my code neater and more precise. Anyway, I guess my question devolves to this: How do I access a C++ variable from python, and what steps do I need to take? The most obvious hack that I thought of was to try and manually insert the python-wrapped C++ variable into the main module's namespace dictionary; Is there a better way than that? Thanks for your time and patience, Mike From s_sourceforge at nedprod.com Fri Apr 2 18:55:27 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 02 Apr 2004 17:55:27 +0100 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? Message-ID: <406DA90F.23013.18865357@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 With GCC v3.4 from CVS, I finally have build time down to only nine hours now rather than the 20+ it was with GCC v3.3. However, when loading the bindings into python on Linux v2.4 kernel it takes well over six minutes. Is anyone else having this problem? I don't think it's BPL's fault really as on Windows it only takes a second or two so I'm guessing it's the dynamic linker. I'd imagine that that prebinding linkage feature of newer Linuces will fix this problem - in the meantime, any suggestions? (Here's a thought - GCC outputs far too many symbols into the public ELF table - if GCC had a dllexport/dllimport mechanism like on Windows, the amount of symbols needing to be linked could be reduced very significantly indeed. As it so happens, someone submitted a patch to enable per-class symbol visibility specifications using the same syntax as MSVC, it just needs extending to use a command line argument specified default so you can mark everything default hidden. If people here think this a good idea, I may try tackling it). Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG2bA8EcvDLFGKbPEQKACQCffwTwb5rzU0ikzQ3aWATWRKHirmEAoJez fuxMMJ25M6rhVO6No/2o4OKS =CyW3 -----END PGP SIGNATURE----- From seefeld at sympatico.ca Fri Apr 2 20:10:21 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 02 Apr 2004 13:10:21 -0500 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? References: <406DA90F.23013.18865357@localhost> Message-ID: <0a25731b1342271ceab98f36271d7dd8406db042@Orthosoft.ca> Niall Douglas wrote: > Is anyone else having this problem? I don't think it's BPL's fault > really as on Windows it only takes a second or two so I'm guessing > it's the dynamic linker. I'd imagine that that prebinding linkage > feature of newer Linuces will fix this problem - in the meantime, any > suggestions? We experience the same: in our case it's already the linking of the module that takes a long time because we split up the code into multiple translation units. > (Here's a thought - GCC outputs far too many symbols into the public > ELF table - if GCC had a dllexport/dllimport mechanism like on > Windows, the amount of symbols needing to be linked could be reduced > very significantly indeed. As it so happens, someone submitted a The simplest thing to do (in this particular context) is to put everything into an anonymous namespace. Everything but the actual python module init function ('BOOST_PYTHON_MODULE()'). That should restrict the number of the exposed symbols to a strict minimum. Stefan From jdbrandm at unity.ncsu.edu Fri Apr 2 21:06:18 2004 From: jdbrandm at unity.ncsu.edu (Jonathan Brandmeyer) Date: Fri, 02 Apr 2004 14:06:18 -0500 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? In-Reply-To: <406DA90F.23013.18865357@localhost> References: <406DA90F.23013.18865357@localhost> Message-ID: <406DB9AA.7020807@unity.ncsu.edu> Niall Douglas wrote: >With GCC v3.4 from CVS, I finally have build time down to only nine >hours now rather than the 20+ it was with GCC v3.3. However, when >loading the bindings into python on Linux v2.4 kernel it takes well >over six minutes. > >Is anyone else having this problem? I don't think it's BPL's fault >really as on Windows it only takes a second or two so I'm guessing >it's the dynamic linker. I'd imagine that that prebinding linkage >feature of newer Linuces will fix this problem - in the meantime, any >suggestions? > > > You most certainly can minimize the exports. The best way to do this is to segregate all of the classes and functions that you want to share between modules (python or otherwise) into a separate .so, to be placed in one of the standard library locations. Then, place all of your Python export code ( creating class_<>, def, and so on) in the module to be loaded from Python. Next, write a symbol map file. The complete specification for these things is fairly complex, but since you have segregated out all of your shared stuff, what you need is very simple (see the GNU ld manual for more). They are vaguely similar (in functionality) to .def files in Windows. My module defines BOOST_PYTHON_MODULE(cvisual) and the resulting map file looks like this: (file named linux-symbols.map) { global: initcvisual; local: *; }; Now, the only function that is exported is extern "C" initcvisual() and the resulting cvisual.so file size is very significantly reduced. (from about 3MB to 1.5 MB for me). You have to add the option -Wl,--version-script=$(MAPFILE_NAME) to the link command when invoking the linker via G++ to make use of this file. HTH, Jonathan Brandmeyer From s_sourceforge at nedprod.com Fri Apr 2 21:07:57 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 02 Apr 2004 20:07:57 +0100 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? In-Reply-To: <0a25731b1342271ceab98f36271d7dd8406db042@Orthosoft.ca> Message-ID: <406DC81D.19888.18FFA330@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2 Apr 2004 at 13:10, Stefan Seefeld wrote: > > (Here's a thought - GCC outputs far too many symbols into the public > > ELF table - if GCC had a dllexport/dllimport mechanism like on > > Windows, the amount of symbols needing to be linked could be reduced > > very significantly indeed. As it so happens, someone submitted a > > The simplest thing to do (in this particular context) is to put > everything into an anonymous namespace. Everything but the actual > python module init function ('BOOST_PYTHON_MODULE()'). That should > restrict the number of the exposed symbols to a strict minimum. No, most of the symbols come from instantiations of items from the BPL headers and these exist inside the boost::python namespace. The number of symbols generated by the class wrappers (the only thing you can put inside an anonymous namespace as the Export_XXX function must remain linkable) is no more than 5% at most I'd guess. If you take a dump using elfdump (I think), you'll see what I mean. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG26DsEcvDLFGKbPEQJHhACfXmMPexBHp6ZoFWNCti7jlYwAuTUAoPsl r0uwQen+29jbn10GKl+dltc7 =zmWC -----END PGP SIGNATURE----- From dave at boost-consulting.com Fri Apr 2 21:23:27 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Apr 2004 14:23:27 -0500 Subject: [C++-sig] Re: Accessing instances of C++ objects in Python - Plus more References: <3.0.6.32.20040402093424.009e8458@mail.digipen.edu> Message-ID: Mike Gonzales writes: > Thank you for your input - I am incorporating it to make my code neater and > more precise. Anyway, I guess my question devolves to this: How do I > access a C++ variable from python, and what steps do I need to take? You can either expose it as a static member of a class using def_readonly or def_readwrite: class_("X") .def_readwrite("foo", &some_variable) ; and access it as: >>> your_extension_module.X.foo or you can enter it in your module dictionary: scope().attr("foo") = object(boost::ref(some_variable)); and access it as: >>> your_extension_module.foo > The most obvious hack that I thought of was to try and manually > insert the python-wrapped C++ variable into the main module's > namespace dictionary; Is there a better way than that? HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericries at speakeasy.net Fri Apr 2 22:44:25 2004 From: ericries at speakeasy.net (Eric Ries) Date: Fri, 02 Apr 2004 20:44:25 +0000 Subject: [C++-sig] wchar_t bindings for Boost.Python Message-ID: David Abrahams suggested that I post my message below here, which I mistakenly sent directly to him originally. I am happy to provide source code if there is interest; let me know. Thanks! Eric -----Original Message----- From: David Abrahams [mailto:dave at boost-consulting.com] Sent: Friday, April 2, 2004 08:31 PM To: 'Eric Ries' Subject: Re: [C++-sig] Re: Boost.Python problems "Eric Ries" writes: > Hello, > > I am a brand new Boost.Python user, and I am very impressed. So first > off, thanks for the awesome work that has gone into Boost.Python and > Boost generally. Glad you like it! > I have been using Pyste to generate Boost.Python bindings for C++, and > noticed that there is not automatic support for wchar_t -> py unicode > conversions for C++ functions that return that type. > > While searching for a solution, I came across an email of yours > (http://mail.python.org/pipermail/c++-sig/2003-March/003633.html) in > which you wrote: > >>> 4. There are no converters for std::wstring or wchar_t. >> >>Good point. Care to contribute some? > > So I figured I would give it a try. I was pleasantly surprised by how > easy it was. That probably means that either 1) you guys have already > done this on your development branch (I am on a vanilla 1.31.0 intall) > or 2) my solution was easy because it does not generalize to other > compilers. > > But, on the off chance that it might be useful to you, I wanted to > write and see if you would like me to send in a patch. I modified > Pyste as well as several boost.python hpp files. I have only tested on > MSVC6. First, please in the future always post things like this on the C++-sig. There are other people there who ought to see your post too. We already have wstring converters, but you could contribute converters for wchar_t and I'd be happy to have them. I don't know why you'd have to change Pyste, but that's not my department (another reason to post on the C++-sig). Cheers, -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Sat Apr 3 00:22:35 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 02 Apr 2004 23:22:35 +0100 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? In-Reply-To: <406DB9AA.7020807@unity.ncsu.edu> References: <406DA90F.23013.18865357@localhost> Message-ID: <406DF5BB.31402.19B1D114@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2 Apr 2004 at 14:06, Jonathan Brandmeyer wrote: > { > global: > initcvisual; > local: > *; > }; > > Now, the only function that is exported is extern "C" initcvisual() > and the resulting cvisual.so file size is very significantly reduced. > (from about 3MB to 1.5 MB for me). You have to add the option > -Wl,--version-script=$(MAPFILE_NAME) to the link command when invoking > the linker via G++ to make use of this file. Useful trick this - thanks for pointing it out. It took me some time (GNU ld seems very finickity about the grammar being exactly broken in the right places) but I got this: TNFOXP1 { global: extern "C++" { initTnFOX; boost::* }; local: extern "C++" { * }; }; As I patch Boost.Python in various places to enable multithreading support, it makes sense to bundle my patched BPL with the bindings. This is why I needed to work out how to specify C++ identifiers. This method is not perfect on anything more varied eg; a general purpose library. Studying the dynamic symbol table using "nm -C -D " shows symbols which match the wildcards leak out in a chance-like fashion. What we really need is Windows-style specifiers embedded directly into the source. If I get some time this week, I may give a bash at patching GCC. Then we can simply reuse the macros defining Windows DLL support to do the same on POSIX. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG3nrMEcvDLFGKbPEQIClQCgrt1p2c6Z/WoviTyMbW0UcSPXDScAnj59 Ltfgs0FjUey+eNYScSC9HJcQ =ZK8C -----END PGP SIGNATURE----- From grafik.list at redshift-software.com Sat Apr 3 01:17:59 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Fri, 02 Apr 2004 17:17:59 -0600 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? In-Reply-To: <406DF5BB.31402.19B1D114@localhost> References: <406DA90F.23013.18865357@localhost> <406DF5BB.31402.19B1D114@localhost> Message-ID: <406DF4A7.1030900@redshift-software.com> Niall Douglas wrote: > On 2 Apr 2004 at 14:06, Jonathan Brandmeyer wrote: >> >>Now, the only function that is exported is extern "C" initcvisual() >>and the resulting cvisual.so file size is very significantly reduced. >>(from about 3MB to 1.5 MB for me). You have to add the option >>-Wl,--version-script=$(MAPFILE_NAME) to the link command when invoking >>the linker via G++ to make use of this file. > > > Useful trick this - thanks for pointing it out. > If I get some time this week, I may give a bash at patching GCC. Then > we can simply reuse the macros defining Windows DLL support to do the > same on POSIX. I explain how I do the equivalent of dllexport on Linux+GCC on this message... http://sourceforge.net/mailarchive/forum.php?thread_id=2793609&forum_id=34093 Doesn't require changing GCC, but is ELF only, and requires recent enough binutils. One adds something like such.., to each method to export: __attribute__ ((section (".text.dll"))) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From dave at boost-consulting.com Sat Apr 3 01:03:18 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Apr 2004 18:03:18 -0500 Subject: [C++-sig] Re: Virtual member functions cause exception in get_derived_class_object References: <001101c41734$5a143af0$64b3fea9@Presario2500> Message-ID: "David Rostowsky" writes: > Attached are the files in question. Thanks for the direction. Im a newbie to > these lists. In my original post I was trying to post the minimal that > failed, so hence I wanted to give everything in the follow-up. Ill try to > find a happier middle ground for future posts. Can you try to answer the other questions I asked in my reply? -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Sat Apr 3 03:44:43 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 03 Apr 2004 02:44:43 +0100 Subject: [C++-sig] Loading Boost.Python made bindings is horribly slow? In-Reply-To: <406DF4A7.1030900@redshift-software.com> References: <406DF5BB.31402.19B1D114@localhost> Message-ID: <406E251B.11466.1A6AE0C0@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2 Apr 2004 at 17:17, Rene Rivera wrote: > > If I get some time this week, I may give a bash at patching GCC. > > Then we can simply reuse the macros defining Windows DLL support to > > do the same on POSIX. > > I explain how I do the equivalent of dllexport on Linux+GCC on this > message... > > http://sourceforge.net/mailarchive/forum.php?thread_id'93609&forum_i > d4093 > > Doesn't require changing GCC, but is ELF only, and requires recent > enough binutils. One adds something like such.., to each method to > export: Clever hack to solve the problem, but I think it inexcusable that GCC doesn't do this properly already especially as ELF has the functionality and has had it for ages. OTOH you shouldn't moan if you're in a position to fix it yourself, so I won't - I'll just go do it. If the patch were accepted to mainline CVS, you'd simply replace all __declspec(dllexport) with __attribute__ ((visibility("default"))) and compile with the new -fvisibility=hidden command line arg. Hey presto, link times drop substantially, executables become much smaller and faster and no more symbol clashes. ie; life gets much better on POSIX like platforms and we all celebrate! :) Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG4XC8EcvDLFGKbPEQIr6ACgvqhqs8DB5cl5gLp5+omfO4flUiwAn0MA L3+Ay5n+xxnT6jH+WL+EjT9T =jQL6 -----END PGP SIGNATURE----- From dave at boost-consulting.com Sat Apr 3 16:35:47 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 03 Apr 2004 09:35:47 -0500 Subject: [C++-sig] Re: Loading Boost.Python made bindings is horribly slow? References: <406DF5BB.31402.19B1D114@localhost> <406E251B.11466.1A6AE0C0@localhost> Message-ID: "Niall Douglas" writes: > On 2 Apr 2004 at 17:17, Rene Rivera wrote: > >> > If I get some time this week, I may give a bash at patching GCC. >> > Then we can simply reuse the macros defining Windows DLL support to >> > do the same on POSIX. >> >> I explain how I do the equivalent of dllexport on Linux+GCC on this >> message... >> >> http://sourceforge.net/mailarchive/forum.php?thread_id'93609&forum_i >> d4093 >> >> Doesn't require changing GCC, but is ELF only, and requires recent >> enough binutils. One adds something like such.., to each method to >> export: > > Clever hack to solve the problem, but I think it inexcusable that GCC > doesn't do this properly already especially as ELF has the > functionality and has had it for ages. OTOH you shouldn't moan if > you're in a position to fix it yourself, so I won't - I'll just go do > it. > > If the patch were accepted to mainline CVS, you'd simply replace all > __declspec(dllexport) with __attribute__ ((visibility("default"))) > and compile with the new -fvisibility=hidden command line arg. Hey > presto, link times drop substantially, executables become much > smaller and faster and no more symbol clashes. > > ie; life gets much better on POSIX like platforms and we all > celebrate! :) I'm looking forward to that! Something to watch out for if you do this: if __attribute__ ((visibility("default"))) applies to classes, you'll have to decide how to handle member functions that are declared inline. If you don't handle it the same way as Win32 compilers do, you could introduce subtle client portability problems. Of course, if it doesn't apply to classes, your feature won't be nearly so useful ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Sat Apr 3 17:47:44 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sat, 03 Apr 2004 10:47:44 -0500 Subject: [C++-sig] Re: Loading Boost.Python made bindings is horribly slow? In-Reply-To: References: <406DF5BB.31402.19B1D114@localhost> <406E251B.11466.1A6AE0C0@localhost> Message-ID: <406EDCA0.6000603@sympatico.ca> Sorry for the offtopic question, but this thread reminds me of the old question: Has there been any attempt to standardize (read: put into the C and C++ languages) tools to express desired visibility similar to the proprietary dllexport / __attribute__ mechanisms ? Thanks, Stefan From s_sourceforge at nedprod.com Sat Apr 3 20:21:43 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 03 Apr 2004 19:21:43 +0100 Subject: Exception handling as thrown from BPL so (was: Re: [C++-sig] Re: Loading Boost.Python made bindings is horribly slow?) In-Reply-To: Message-ID: <406F0EC7.8064.1DFBA891@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Related to my previous post, I am now finding that if I throw an exception from within my python extension module, the client program won't catch it. This has started happening since I implemented that symbol versioning trick previously suggested. I'm guessing that the type info symbols are getting stripped and so it's unable to match the exception type with the catch type. Am I right in this? It's very hard to prove as it's a 130Mb shared object (this is *without* debug info) and it's horribly mangles my computer when running in gdb. If I am right (please confirm), does anyone know how RTTI symbols are mangled precisely so I can keep them from getting stripped? (Roll on declspec() for GCC!) Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG8AucEcvDLFGKbPEQI83gCg9wdlBKZW6O4lcBOKU8TMHjKNEV0AoO7R DTLo/iWNrZ5uOolZ2czIvc7E =oPYE -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Sat Apr 3 20:30:04 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 03 Apr 2004 19:30:04 +0100 Subject: [C++-sig] Re: Loading Boost.Python made bindings is horribly slow? In-Reply-To: Message-ID: <406F10BC.19337.1E034EE1@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 3 Apr 2004 at 9:35, David Abrahams wrote: > I'm looking forward to that! Something to watch out for if you do > this: if > > __attribute__ ((visibility("default"))) > > applies to classes, you'll have to decide how to handle member > functions that are declared inline. If you don't handle it the same > way as Win32 compilers do, you could introduce subtle client > portability problems. Of course, if it doesn't apply to classes, your > feature won't be nearly so useful ;-) No, it will apply to classes. The patch at http://gcc.gnu.org/bugzilla/show_bug.cgi?id?83 by someone expert at modifying the GCC internals points me the right way. It'll also use identical syntax to MSVC, despite the misgivings of the GCC crew. I was going to always mark inline functions as hidden. Also all templates. This creates code bloat but gives far faster loading & linking times plus less coupling problems between modules. It also follows MSVC. As my previous post pointed out, RTTI is going to be a headache - if you remember Dave some months ago you agreed that some form of being able to filter out the RTTI would be useful in reducing binary size - I figure that if most of the RTTI is not public, it lets the compiler + linker know it can be elided (whether the GNU tools can already do this is unknown). Debugging this 130Mb shared object is a royal PITA. I'm getting tempted to delay release of v0.75 until GCC is patched, but then no one else could make my library without my patch :( Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQG8CrMEcvDLFGKbPEQInWACeNBlO+ea6PQefSkC8Vi/AKmQLVV8An0pQ CP7e8gXgtrYj1WpjoXKf8ZIg =JqJK -----END PGP SIGNATURE----- From dave at boost-consulting.com Sat Apr 3 20:54:59 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 03 Apr 2004 13:54:59 -0500 Subject: [C++-sig] Re: Exception handling as thrown from BPL so References: <406F0EC7.8064.1DFBA891@localhost> Message-ID: "Niall Douglas" writes: > Related to my previous post, I am now finding that if I throw an > exception from within my python extension module, the client program > won't catch it. This has started happening since I implemented that > symbol versioning trick previously suggested. > > I'm guessing that the type info symbols are getting stripped and so > it's unable to match the exception type with the catch type. Am I > right in this? Very probably. > It's very hard to prove as it's a 130Mb shared object > (this is *without* debug info) and it's horribly mangles my computer > when running in gdb. Make a reduced test case then. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Apr 4 04:20:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 03 Apr 2004 21:20:42 -0500 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs References: <93618711046370@webmail.iastate.edu> <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: "aashish" writes: > Hi, > > I need to pass a dictionary from python to C++ function which is defined as > > void setVariables(ValueMapPtr variables); > > where I have typedef ValueMapPtr as > > //a shared ptr of a value map > typedef boost::shared_ptr< ValueMap > ValueMapPtr; > > // And > typedef std::map< std::string, std::vector > ValueMap; > > > Is it possible?? Yes. > Do I need to use register_ptr_to_python ? No; if it's truly a Python dictionary on the Python side, you need to build a custom rvalue from-python converter, per http://www.boost.org/libs/python/doc/v2/faq.html#question2 http://article.gmane.org/gmane.comp.python.c%2B%2B/2161 I wish it were easier; sorry! -- Dave Abrahams Boost Consulting www.boost-consulting.com From RaoulGough at yahoo.co.uk Sun Apr 4 12:31:37 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 04 Apr 2004 11:31:37 +0100 Subject: [C++-sig] Re: Newbie needs advice for decision. References: <4069558C.4060703@freenet.de> Message-ID: Billy Gnosis writes: > Hi I want to extend and more important embed Python in my Programs. > > 1. What is the best (easiest way) to extend Python with C++ ? Swig or > Boost.Python, or is there something easier ? I haven't used Swig, so I can't really compare them. Using Boost.Python is pretty easy once you get into it, but it will probably take a little bit of effort to get there (see the tutorial to get an idea). > > 2. What is the best (easiest way) to embed Python in a C++ Program ? > Boost.Python, the Python/C Api, or is there something easier out there > ? Boost.Python doesn't provide a lot of support for embedding Python. It does basic stuff like managing reference counts for you and so on, but doesn't currently wrap much of the Python/C API. > > > 3. General Question: I played a little bit wit the high level > embedding of the python interpreter in my C++ Program (#include > "Python.h", Py_Initialize()...etc.etc...). Can I somehow compile and > link everything statically ? Meaning, I have one binary in the end, > that already includes all necessary parts of the python interpreter - > when I give this file somebody else, this should be enough to run it > no installation of the python interpreter necessary, etc... > > Is this possible ? I guess anything is possible since you have access to the Python source code and could relink it anyway you want, given enough effort. You'd probably do better to ask about this on the main Python discussion group, since it's not specifically C++ related. I'm not sure about any legal/licensing issues of doing this, and how much of the Python library (i.e. .py or .pyc files) the interpreter needs to have to get going. -- Raoul Gough. export LESS='-X' From RaoulGough at yahoo.co.uk Sun Apr 4 12:56:15 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 04 Apr 2004 11:56:15 +0100 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs References: <93618711046370@webmail.iastate.edu> <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: David Abrahams writes: > "aashish" writes: > >> Hi, >> >> I need to pass a dictionary from python to C++ function which is defined as >> >> void setVariables(ValueMapPtr variables); >> >> where I have typedef ValueMapPtr as >> >> //a shared ptr of a value map >> typedef boost::shared_ptr< ValueMap > ValueMapPtr; >> >> // And >> typedef std::map< std::string, std::vector > ValueMap; >> >> >> Is it possible?? > > Yes. > >> Do I need to use register_ptr_to_python ? > > No; if it's truly a Python dictionary on the Python side, you need to > build a custom rvalue from-python converter, per > > http://www.boost.org/libs/python/doc/v2/faq.html#question2 > http://article.gmane.org/gmane.comp.python.c%2B%2B/2161 > > I wish it were easier; sorry! There is an interesting trade off here, which I've thought about on a few occasions. If you want to share a container between Python and C++ code, I believe you have three choices: 1. Use a Python container and access it from C++ using the Python/C APIs like (e.g.) PyDict_GetItem 2. Use a C++ container and access it from Python using (e.g.) the indexing suite. 3. Use native containers on each side and convert from/to the different types at the interface. In terms of performance, which one is appropriate depends on the application, where most of the processing takes place and probably also on the size of the container. Option 1. means dealing with PyObjects from C++, instead of having the compiler know the static types of the elements. It introduces overheads on the C++ side, so isn't much good if the heavy processing is done here. Option 2. means the C++ code knows the static types of the elements, which gives you the fastest possible code for what you do in C++. It introduces overheads on the Python side, since every operation on the container requires a call through the Boost.Python code. For example, this wouldn't make much sense if you spend all the time filling the container from Python and then do one simple operation on it in C++. Option 3. means converting the whole container for each call (either from a C++ container to Python or vice versa). I guess it also introduces a problem if you want code on the non-native side to modify the container, since you'd then have to convert the container back and replace the original. As for which is the easiest to use, I would say probably option 2 would be, except that I haven't yet documented the new indexing suite properly, and I don't think the original suite has much std::map support. -- Raoul Gough. export LESS='-X' From dave at boost-consulting.com Sun Apr 4 17:44:58 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 04 Apr 2004 11:44:58 -0400 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs References: <93618711046370@webmail.iastate.edu> <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: Raoul Gough writes: > David Abrahams writes: > >> "aashish" writes: >> >>> Hi, >>> >>> I need to pass a dictionary from python to C++ function which is defined as >>> >>> void setVariables(ValueMapPtr variables); >>> >>> where I have typedef ValueMapPtr as >>> >>> //a shared ptr of a value map >>> typedef boost::shared_ptr< ValueMap > ValueMapPtr; >>> >>> // And >>> typedef std::map< std::string, std::vector > ValueMap; >>> >>> >>> Is it possible?? >> >> Yes. >> >>> Do I need to use register_ptr_to_python ? >> >> No; if it's truly a Python dictionary on the Python side, you need to >> build a custom rvalue from-python converter, per >> >> http://www.boost.org/libs/python/doc/v2/faq.html#question2 >> http://article.gmane.org/gmane.comp.python.c%2B%2B/2161 >> >> I wish it were easier; sorry! > > There is an interesting trade off here, which I've thought about on a > few occasions. If you want to share a container between Python and C++ > code, I believe you have three choices: > > 1. Use a Python container and access it from C++ using the Python/C > APIs like (e.g.) PyDict_GetItem > > 2. Use a C++ container and access it from Python using (e.g.) the > indexing suite. > > 3. Use native containers on each side and convert from/to the > different types at the interface. > > In terms of performance, which one is appropriate depends on the > application, where most of the processing takes place and probably > also on the size of the container. > > Option 1. means dealing with PyObjects from C++, instead of having the > compiler know the static types of the elements. It introduces > overheads on the C++ side, so isn't much good if the heavy processing > is done here. > > Option 2. means the C++ code knows the static types of the elements, > which gives you the fastest possible code for what you do in C++. It > introduces overheads on the Python side, since every operation on the > container requires a call through the Boost.Python code. I'm not convinced these overheads you're referring to are real. Accessing a native Python dict or list from Python requires a call through Python's 'C' code that's much like Boost.Python's C++ code. There's probably one extra level of function indirection, but I doubt that counts for much in most cases. > For example, this wouldn't make much sense if you spend all the time > filling the container from Python and then do one simple operation > on it in C++. Probably the reason, though, is the amount of effort you expend writing wrapping code in that case. > Option 3. means converting the whole container for each call (either > from a C++ container to Python or vice versa). I guess it also > introduces a problem if you want code on the non-native side to modify > the container, since you'd then have to convert the container back and > replace the original. Right. > As for which is the easiest to use, I would say probably option 2 > would be, except that I haven't yet documented the new indexing suite > properly, and I don't think the original suite has much std::map > support. Mmm, I'm eagerly awaiting those docs. -- Dave Abrahams Boost Consulting www.boost-consulting.com From RaoulGough at yahoo.co.uk Mon Apr 5 00:36:28 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 04 Apr 2004 23:36:28 +0100 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs References: <93618711046370@webmail.iastate.edu> <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: David Abrahams writes: > Raoul Gough writes: [snip] >> Option 2. means the C++ code knows the static types of the elements, >> which gives you the fastest possible code for what you do in C++. It >> introduces overheads on the Python side, since every operation on the >> container requires a call through the Boost.Python code. > > I'm not convinced these overheads you're referring to are real. > Accessing a native Python dict or list from Python requires a call > through Python's 'C' code that's much like Boost.Python's C++ code. > There's probably one extra level of function indirection, but I doubt > that counts for much in most cases. Hmmm... I'd always assumed there was more to it than just an extra indirection, doesn't it have to search for a matching overload and do type compatibility checking as well? In particular, the purely Python solution doesn't care what kind of object you insert in a container, so it doesn't have to check types or look up a from-Python converter. I must admit I never really looked into in much detail, but I did see a substantial performance difference between filling a Python list from Python and filling a std::vector from Python (about a factor of five). Is this more than you would expect? On the other hand, C++ code searching the vector or sorting it is about fifteen times faster than Python code doing the same on a Python list, so it really does depend on the mix of operations you're doing. > >> For example, this wouldn't make much sense if you spend all the time >> filling the container from Python and then do one simple operation >> on it in C++. > > Probably the reason, though, is the amount of effort you expend > writing wrapping code in that case. > >> Option 3. means converting the whole container for each call (either >> from a C++ container to Python or vice versa). I guess it also >> introduces a problem if you want code on the non-native side to modify >> the container, since you'd then have to convert the container back and >> replace the original. > > Right. > >> As for which is the easiest to use, I would say probably option 2 >> would be, except that I haven't yet documented the new indexing suite >> properly, and I don't think the original suite has much std::map >> support. > > Mmm, I'm eagerly awaiting those docs. I've recently managed to get some paid employment, so I've had to put this work on the back burner for a while. I'm still hoping to get the docco ready by the end of next week (April 16) in time for the Python conference in Oxford. -- Raoul Gough. export LESS='-X' From dave at boost-consulting.com Mon Apr 5 03:36:45 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 04 Apr 2004 21:36:45 -0400 Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs References: <93618711046370@webmail.iastate.edu> <200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: Raoul Gough writes: > David Abrahams writes: > >> Raoul Gough writes: > [snip] >>> Option 2. means the C++ code knows the static types of the elements, >>> which gives you the fastest possible code for what you do in C++. It >>> introduces overheads on the Python side, since every operation on the >>> container requires a call through the Boost.Python code. >> >> I'm not convinced these overheads you're referring to are real. >> Accessing a native Python dict or list from Python requires a call >> through Python's 'C' code that's much like Boost.Python's C++ code. >> There's probably one extra level of function indirection, but I doubt >> that counts for much in most cases. > > Hmmm... I'd always assumed there was more to it than just an extra > indirection, doesn't it have to search for a matching overload Yeah, but if there's only one overload that's free. > and do type compatibility checking as well? Yeah, but Python has to look up a hash function depending on the key type. > In particular, the purely Python solution doesn't care what kind of > object you insert in a container, so it doesn't have to check types > or look up a from-Python converter. from-Python lookups are usually cost-free. > I must admit I never really looked into in much detail, but I did see > a substantial performance difference between filling a Python list > from Python and filling a std::vector from Python (about a factor > of five). Is this more than you would expect? OK, I can't argue with experimental data. You are correct, sir. > On the other hand, C++ code searching the vector or sorting it is > about fifteen times faster than Python code doing the same on a Python > list, so it really does depend on the mix of operations you're doing. OK. >>> As for which is the easiest to use, I would say probably option 2 >>> would be, except that I haven't yet documented the new indexing suite >>> properly, and I don't think the original suite has much std::map >>> support. >> >> Mmm, I'm eagerly awaiting those docs. > > I've recently managed to get some paid employment, so I've had to put > this work on the back burner for a while. I'm still hoping to get the > docco ready by the end of next week (April 16) in time for the Python > conference in Oxford. Great! Sorry I can't be there. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Apr 5 09:19:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 05 Apr 2004 03:19:11 -0400 Subject: [C++-sig] Re: wrapping interfaces and supplied implementations References: <40072187.CBC15DBF@eircom.net> Message-ID: [In response to http://article.gmane.org/gmane.comp.python.c++/5679/] Hi Brian, I know it's been "forever" since you posted this... sorry it took so long! Brian Peters writes: > Hello All, > > I'd like first to thank the Boost.Python team and commend them on their > creation. Dave Abrahams et.al. have implemented code the likes of which > I could not even have conceived, let alone writen. Boost MPL is not > something I could ever have thought up. My hope is simply that someone > some day finds my work as useful and impressive as I find theirs. You're very welcome! I'm very happy that the library helped you! > I am trying to wrap a library that implements a generic programming > approach to computational geometry and topology. To achieve this it > defines a number of interfaces it requires to do its job. For developers > who do not wish to code the details of these interfaces it also supplies > concrete implementations. > > Having observed Dave Abrahams' penchant for a working test case I have > developed a sandbox representing a portion of the library. When I got here I expected to see a you ask a question about how to make the code work... but I'm glad to see you got everything to work on your own. > It has three classes that are abstract base classes: IFacade, > IManager, and IProduct. All their pure virtual methods are defined > using raw pointers to abstract base classes. > > The idea is that an application asks the facade for a manager [ > IManager* IFacade::manager() ] and then uses the manager to create > products [ IProduct* IManager::create(inti i) ]. The products have state > that may be changed by the client or other operations of the facade. The > manager can also store and retrieve products. > > A simple user can use the concrete Manager and Product classes supplied > through these interfaces, but a more advanced user could derive their > own product and manager from the abc's and pass that into the facade [ > void IFacade::setManager(IManager* manager) ]. The old addage applies: > "The simple should be easy, but the complex should be possible." i.e use > the supplied system if you want, but you can always over ride it with > something more complex. Nice! > So now I want to be able to do the same thing in Python. I want to wrap > everything so that a simple user can: > * see the abstract base classes in python; > i.e. the interfaces, their doc strings, etc. > * use the supplied implementation of manager and product > * derive their own products and manager if they want/need to in python > > Well, I got it all working! Not only working, but doing cool python > stuff too. Being new to python I have found it interesting that > arbitrary attributes and methods can be added to any object regardless > of its class. > > I think of a wrapped Product passed out to python from the supplied > Manager class as a python envelope containing the C++ Product. I can > scribble on that envelope. Spill coffee on it. Crumple it up a bit. I > can store it in the manager and throw it away. When I later retrieve > from the manager, not only is it the same C++ Product (i.e same > address), but it is the same PyObject (i.e. same address, or "id" as > they call it in the interpreter), AND it even has the same note > scribbled on it and the coffee stain! Its like decorating C++ classes > dynamically at run time. That's the experience you're supposed to have ;^) > I thought the article about C++/Python integration was cool when I read > it a few months ago, but now I really see it. The line between Python > and C++ is very fluid. ( > http://www.cuj.com/documents/s=8188/cuj0307abrahams ) > > The code is attached below. For reference I am using the following > (admittedly somewhat dated) environment: > * Python 2.2.2 > * Boost 1.30.0 > * Windows NT4 with MSVC6 > * RH linux 2.4.2-2 with g++ 1.96 > > I am offering this example to anyone that finds it useful. It is more > complex than the examples I found in the documentation and code, yet > still simple enough to examine in detail. > > I am hoping that those in the know will tell me if I have done anything > terribly wrong. Well, I don't have time to give it a really in-depth review, but there are a couple of issues that stick out: 1. The use of the undocumented component arg_from_python. Wouldn't extract<> be more appropriate? 2. You could make most of the handling of raw pointers use boost::shared_ptr instead. Then you could probably get rid of all the uses of reference_existing_object, making the object ownership issues both cleaner and safer in general. > I will gladly explain why I have done things the way I have and/or > share the verbose version of this sandbox that contains a lot more > testing functions and cout's. This message is already too long to do > so here. Well, you're right that it's long! Actually, it has the tone and flavor of a short magazine article. CUJ was looking for more Boost.Python articles not long ago; maybe you should develop your example into one? An article written from the perspective of someone getting to know the library could help a lot of people get started smoothly. Cheers, -- Dave Abrahams Boost Consulting www.boost-consulting.com From pierre.barbier at cirad.fr Mon Apr 5 10:13:14 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 05 Apr 2004 10:13:14 +0200 Subject: [C++-sig] Accessing instances of C++ objects in Python - Plus more In-Reply-To: <3.0.6.32.20040401122040.009e8458@mail.digipen.edu> References: <3.0.6.32.20040401122040.009e8458@mail.digipen.edu> Message-ID: <1081152794.715.18.camel@pbarbier> It may be a silly question but why don't you use Boost for that ? I'd try to do this : template boost::python::object MakeDualObject( ExportedType& e, std::string name ) { // Create the boost::python object from the C++ one boost::python::object obj(e); //put the variable into Python's variable namespace main_namespace[varname.c_str()] = obj; return obj; // Return the python object } Then, you could use it with: int main() { // Start interpreter quat q(1,0,0,0); object qpy = _PythonManager.MakeDualObject(q, "y"); _PythonManager.EvaluateScript("printquat(y)"); // Stop interpreter return 0; } I try this and it works quite fine with me ! Pierre On Thu, 2004-04-01 at 22:20, Mike Gonzales wrote: > Sorry if I am asking a question that has already been answered; the number > of threads in this forum is formidable, and I can only see so far. This > question was asking previously by my teammate Adrian Bentley; now that we > know more about the problem, hopefully we can get an answer ;). > > I am working on a game engine that is attempting to use python for > scripting support. And unusual requirement of our engine is the necessity > of be able to manipulate types in C++ or Python, pretty much at the same > time, e.g. dynamically instantiating an entity in C++ and then being able > to manipulate it in python, and then updating its status in C++. I won't > go into detail on why this is necessary, suffice to say, it has to deal > with managing modules at run-time. > > I am most of the way to acheiving this goal; however, I am having trouble > trying to access said C++ objects from python after I have instantiated them. > > to give you some idea what I am trying to do, following the boost tutorial > I have a class that looks sorta like this > > --------------------------------------------------- > struct PythonManager > { > dict main_namespace; > handle<> main_module; > > //calls PyInitialize, and grabs the main module and namespace > PythonManager(); > > //calls PyFinalize > ~PythonManager(); > > //runs the interpreter on a single expression, and returns the result > object EvaluateExpression(std::string &exp); > //runs the interpreter on a multiline script > void EvaluateScript(std::string &scr); > > struct PythonWrapper: public PyObject > {}; > > PythonWrapper * MakeDualObject(int sizebytes, PyTypeObject *pto, > std::string &varname) > { > //Get memory from Python and do necessary Python initialization > PythonWrapper * mem = (PythonWrapper*)PyObject_Malloc(sizebytes); > object obj( handle<>(PyObject_Init(mem, pto))); > > //put the variable into Python's variable namespace > main_namespace[varname.c_str()] = obj; > > //set up some of my own tracking here.... > > return mem; > } > }; > ----------------------------------------------------------- > > Now, the test that I am subjecting myself to see if all of this works is to > have one of my defined types that I have extended into Python and another > that I have created behind the scenes (like above) play well together. > Unfortunately, I haven't gotten that far; so far, I am having trouble > trying to get Python to recognize the types that I have just fed it. > > I successfully have extended a quaternion class in to python, and so I am > using that as my test case, even stealing its typeobj * for use in the > making these dual-language-objects. > > ------------------------------------------------------ > struct PyQuat: public PyWrapper, public quat > {}; > > //... > _PythonManager.EvaluateScript("import mymath"); > _PythonManager.EvaluateScript("x = mymath.quat(1,0,0,0)"); > object testquat = _PythonManager.EvaluateExpression("x"); > > //verify that testquat really is a quat. > > PyWrapper *test = _PythonManager.MakeDualObject(sizeof(PyQuat), > testquat.ptr()->objtype, "y"); > //now the interpreter goes "boom!" > _PythonManager.EvaluateScript("printquat(y)"); > -------------------------------------------------------------- > > So, obviously what I am doing here is probably sub-optimal; still does > anybody know of how to pull this off? Even better, if anybody knows of a > more elegant way to pull this off, I am all ears. And again, once I pull > that off above, I'll need to be able to make a behind-the-scenes-quat and > made-in-python-quat play nicely; any advice on how to make that work would > be really appreciated. > > Thanks for your time and patience, > Mike Gonzales > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From ndbecker2 at verizon.net Mon Apr 5 15:16:52 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Mon, 05 Apr 2004 09:16:52 -0400 Subject: [C++-sig] boost::python::numeric examples? Message-ID: I'm trying to learn about using c++ code with python numarray. I wonder if I can find some good tutorial examples? From s_sourceforge at nedprod.com Mon Apr 5 17:03:50 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 05 Apr 2004 16:03:50 +0100 Subject: [C++-sig] Re: Exception handling as thrown from BPL so In-Reply-To: Message-ID: <40718366.16495.279337BC@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 3 Apr 2004 at 13:54, David Abrahams wrote: > > I'm guessing that the type info symbols are getting stripped and so > > it's unable to match the exception type with the catch type. Am I > > right in this? > > Very probably. Actually, it took some time but I finally figured it out. It would appear that GCC needs the type being thrown to have a virtual function table for it to pass across shared object boundaries. This is odd, because my base exception class never had a virtual function table and I swear it used to work. However, I do do most of my testing on Windows (better debugger). So it's entirely possible I missed it. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQHF1V8EcvDLFGKbPEQL/lgCgh7NDua1EaFpqklUu0mYVYd8DUC4Anidg bTiFrc2qf5nuojbNQpLLn+vD =fQ+N -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Mon Apr 5 19:17:33 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 05 Apr 2004 18:17:33 +0100 Subject: [C++-sig] Symbol visibility patch for GCC v3.4 Message-ID: <4071A2BD.13053.280DA0B6@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 If people could test this patch and let me know, I'd be most grateful. Some might consider this off-topic, so I'll give you a quick run down of the improvements - with my Boost.Python built bindings, my shared object went from >200,000 symbols down to just 19,738 resulting in the six minute load time dropping to a few seconds. If you examine the dynamic table with nm, the output is vastly cleaner with only what is actually required being exported - this will beat any linker version script method hands down. Also, because the compiler now knows what symbols don't need to run through the relocation table, it can substantially optimise code output with better inlining, half the overhead of calling a function, much better ability to totally elide unnecessary code and many other benefits. See Ulrich Drepper's "How to Write Shared Libraries" article. To install, get a GCC v3.4 from CVS. Apply patch. Find the header file boost/boost/python/detail/config.hpp. Modify the dllexport section to: #if defined(BOOST_PYTHON_DYNAMIC_LIB) # if (defined(_WIN32) || defined(__CYGWIN__)) # if defined(BOOST_PYTHON_SOURCE) # define BOOST_PYTHON_DECL __declspec(dllexport) # define BOOST_PYTHON_BUILD_DLL # else # define BOOST_PYTHON_DECL __declspec(dllimport) # endif # elif (defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >=4) # if defined(BOOST_PYTHON_SOURCE) # define BOOST_PYTHON_DECL __attribute__ ((visibility("default"))) # define BOOST_PYTHON_BUILD_DLL # else # define BOOST_PYTHON_DECL # endif # endif #endif Adjust the Jamfile to include a -fvisibility=hidden for the dll boost_python. Recompile everything using -fvisibility=hidden for your binding source files too. You should see a substantial improvement in link times and your shared objects will have reduced in size, sometimes by tens of megabytes. Everything should run just as before. If it doesn't, please let me know - everything on my end runs just as before. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQHGUrcEcvDLFGKbPEQJwfQCeJmlYFO1SaDeq7sO1BBjy2WTlcCcAnAgm TFiYmU2XblgPt7PsLG0DVkkd =Jv/S -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Mon Apr 5 19:17:32 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 05 Apr 2004 18:17:32 +0100 Subject: [C++-sig] Symbol visibility patch for GCC v3.4 Message-ID: <4071A2BC.1397.280D9EC2@localhost> The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: GCC3.4-20040324VisibilityPatch.diff Date: 5 Apr 2004, 18:17 Size: 46294 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: GCC3.4-20040324VisibilityPatch.diff Type: application/octet-stream Size: 46294 bytes Desc: not available URL: -------------- next part -------------- -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUAQHGUrMEcvDLFGKbPEQLErgCdHkY6DniqTLsn3RENWBzdpHAdXq8AoKpn PaVoC2Dg5/R2lIK7OaVQkHp4 =8DFj -----END PGP SIGNATURE----- From zhudjqjcmt at yahoo.com Tue Apr 6 21:07:13 2004 From: zhudjqjcmt at yahoo.com (Carson Mcfarland) Date: Tue, 06 Apr 2004 21:07:13 +0200 Subject: [C++-sig] IT talents for lowest prices Message-ID: An HTML attachment was scrubbed... URL: From aashish at iastate.edu Tue Apr 6 21:43:03 2004 From: aashish at iastate.edu (aashish at iastate.edu) Date: Tue, 6 Apr 2004 14:43:03 -0500 (CDT) Subject: [C++-sig] Re: conversion of python dictionary to shared_ptrs In-Reply-To: References: <93618711046370@webmail.iastate.edu><200404020301.i3231v3N5674255@vracs001.vrac.iastate.edu> Message-ID: <1543.129.186.232.105.1081280583.squirrel@mail.eng.iastate.edu> Hi, I really appreciate e mails from two experts .. thaks a lot..... some questions .... > > 1. Use a Python container and access it from C++ using the Python/C > APIs like (e.g.) PyDict_GetItem > > 2. Use a C++ container and access it from Python using (e.g.) the > indexing suite. I would prefer this option and I tried to use vector for starting. But is it possible same for the STL maps ?? Could you please inform me if there is some example ?? I couldn't find it ..... thanks, aashish From nicodemus at esss.com.br Wed Apr 7 01:04:14 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Tue, 06 Apr 2004 20:04:14 -0300 Subject: [C++-sig] Pyste and exporting inherited items In-Reply-To: <406BFF55.10019.12075479@localhost> References: <406BFF55.10019.12075479@localhost> Message-ID: <4073376E.7050307@esss.com.br> Hi Niall, (sorry for taking so long to respond: I have been out of town) Niall Douglas wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Bruno, are you aware that by adding the exporters.importing mechanism >you have totally broken pyste's detection of class inheritance thus >causing the class_<...bases > system to stop working? >Furthermore nested class definitions get replicated, thus causing >Boost.Python to fault on startup complaining about multiple >definitions. > > Ouch, that's a pretty serious bug. According to the log message, this change was introduce to fix a bug where a class would be exported more than once. >The solution for others afflicted is to comment out line 55 "if not >exporters.importing" in infos.py. > > I will commit this change. I'll have to think something else to deal with the other bug. Thanks a lot for reporting this, and sorry about any trouble this may have caused! 8/ Regards, Nicodemus. From faheem at email.unc.edu Wed Apr 7 02:49:54 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Wed, 7 Apr 2004 00:49:54 +0000 (UTC) Subject: [C++-sig] Re: blitz++ and numarray References: <406904BE.6030808@der.edfgdf.fr> Message-ID: On Tue, 30 Mar 2004 07:25:18 +0200, Xavier WARIN(Compte LOCAL) - I23 wrote: > Hi > > Don't do it by yourself. > You'd better use SWIG to do the wrapping, or better Boost > (www.boost.org). You can find a wrapping for Numeric at this adresse : > http://www.eos.ubc.ca/research/clouds/num_util.html. > (It is done with Boost) > You will be able to export all C++ classes to Python, > and use tuple, dict inside your C++ code etc... Thanks for your reply. The link you reference appears to be broken however. I'm trying to read the Boost Python docs. Would it still be possible using this interface to work with blitz++ arrays in python? Also, how does Boost Python compare with Pycxx (http://cxx.sourceforge.net/)? Thanks. Faheem. From jbrandmeyer at earthlink.net Wed Apr 7 04:00:27 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 06 Apr 2004 22:00:27 -0400 Subject: [C++-sig] Re: blitz++ and numarray In-Reply-To: References: <406904BE.6030808@der.edfgdf.fr> Message-ID: <1081303227.4175.129.camel@illuvatar> On Tue, 2004-04-06 at 20:49, Faheem Mitha wrote: > On Tue, 30 Mar 2004 07:25:18 +0200, Xavier WARIN(Compte LOCAL) - I23 > wrote: > > > Hi > > > > Don't do it by yourself. > > You'd better use SWIG to do the wrapping, or better Boost > > (www.boost.org). You can find a wrapping for Numeric at this adresse : > > http://www.eos.ubc.ca/research/clouds/num_util.html. > > (It is done with Boost) > > You will be able to export all C++ classes to Python, > > and use tuple, dict inside your C++ code etc... > > Thanks for your reply. The link you reference appears to be broken > however. Works for me. > I'm trying to read the Boost Python docs. Would it still be > possible using this interface to work with blitz++ arrays in python? > Also, how does Boost Python compare with Pycxx > (http://cxx.sourceforge.net/)? I recently ported a C++ extension module from Py::CXX to Boost.Python. CXX doesn't do half the things that Boost.Python does. Basically, CXX is a fairly thin wrapper around the C concrete and abstract object APIs. You have to perform all of the argument matching and function overloading yourself, among other things. I'm somewhat familiar with Blitz++, and you should be able to wrap it using Boost.Python. I have (experimentally) wrapped boost::numeric::ublas::matrix classes, which are somewhat similar to blitz::Matrix classes. -Jonathan Brandmeyer From dholth at fastmail.fm Wed Apr 7 05:46:22 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Tue, 06 Apr 2004 23:46:22 -0400 Subject: [C++-sig] boost.python + mingw + msvc python Message-ID: <4073798E.2090806@fastmail.fm> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Have any of you used a mingw compiled Boost.Python to compile an extension for MSVC python (the standard python.org python)? I've had a pretty straightforwards experience using ming to compile Boost.Python (on an XP box, sadly NOT cross compiled from a Linux machine) making gcc libraries for various dlls, and I can compile the extension itself. Unfortunately when I try to import the extension I get a vague sort of 'dll not found' error. I know this is vague, I just would like to know if anyone has succeeded in compiling a working Python+Boost.Python extension this way. I'm trying to wrap ogg, vorbis and theora. (http://dingoskidneys.com/oggpy/) Thanks, Daniel -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFAc3mOVh4W2pVfoMsRAo8UAKCFAmvreyuAe2Tw0kbo/NYY+tqYCgCgj8SH ltTCEyTB4cAhaouFDOMeo/g= =Zilu -----END PGP SIGNATURE----- From prog at msobczak.com Wed Apr 7 10:58:27 2004 From: prog at msobczak.com (Maciej Sobczak) Date: Wed, 07 Apr 2004 10:58:27 +0200 Subject: [C++-sig] Reinitialization of interpreter with Boost.Python Message-ID: <4073C2B3.8040306@msobczak.com> Hi, I use Boost.Python (from 1.30.2 release) for interpreter embedding. The idea is to run short, customized scripts from within the C++ application and have the scripts operate on application's data structures. My use of Python interpreter is tightly scoped and what I need is the possibility to *repeatedly* do the following: 1. initialize the interpreter 2. import module defined in the application's code 3. execute some Python script 4. finalize the interpreter The problem is that the second time (after the interpreter is re-initialized) my module is imported, the code that defines classes cannot go past the registration procedure. This is due to the fact that the slots for conversion functions cannot be reused and the code stumbles either on assertion (in Debug build) or the exception is thrown (in Release build). The "offending" code is in the converter/registry.cpp file (of Boost.Python): void insert(to_python_function_t f, type_info source_t) { # ifdef BOOST_PYTHON_TRACE_REGISTRY std::cout << "inserting to_python " << source_t << "\n"; # endif to_python_function_t& slot = get(source_t)->m_to_python; assert(slot == 0); // we have a problem otherwise if (slot != 0) { throw std::runtime_error( "trying to register to_python_converter for a type which already has a registered to_python_converter"); } slot = f; } Considering the fact that what I need is the possibility to reinitialize the interpreter in exactly the same manner, importing the same module that defines the same classes - the second time the module is imported, the converion function is exactly the same. I have hacked the above function and removed both assertion and if, so that the conversion function pointer is always written into the slot. The second time my module is imported (after the interpreter is finalized and re-initialized), the insert function above will just overwrite the slot with the same value as before. Interestingly, it started to work as expected, at least with simple tests. What bothers me is the claim I found on Boost site, that reinitialization of Python interpreter is *not* supported due to the reference-counting problems affecting some global objects. I do not experience any problems *at the moment*, but I would like to know where the trolls may come from. What is exactly the problem? What should I be aware of? Thank you very much for your time, -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ From python at cityofdreams.com Wed Apr 7 14:38:09 2004 From: python at cityofdreams.com (Your Name) Date: Wed, 07 Apr 2004 08:38:09 -0400 Subject: [C++-sig] VC6 Compile error with boost 1.31.0 Message-ID: Using VC6, Python 2.3 and Boost 1.31.0, I get the following errors inheritance.cpp C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error C2244: 'bidirectional_graph_ move_edge' : unable to resolve function overload C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error C2954: template definitions plus a whole lot more. I know others have had this problem, and the only answer I saw was to get a snapshot direct from CVS. Sadly I can't get direct CVS access from my location. Is there anywhere else I can get an update to the specific files? And can someone list which files I need to get to fix this? Thanks. Peter From python at cityofdreams.com Wed Apr 7 14:38:17 2004 From: python at cityofdreams.com (Your Name) Date: Wed, 07 Apr 2004 08:38:17 -0400 Subject: [C++-sig] VC6 Compile error with boost 1.31.0 Message-ID: Using VC6, Python 2.3 and Boost 1.31.0, I get the following errors inheritance.cpp C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error C2244: 'bidirectional_graph_ move_edge' : unable to resolve function overload C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error C2954: template definitions plus a whole lot more. I know others have had this problem, and the only answer I saw was to get a snapshot direct from CVS. Sadly I can't get direct CVS access from my location. Is there anywhere else I can get an update to the specific files? And can someone list which files I need to get to fix this? Thanks. Peter From dave at boost-consulting.com Wed Apr 7 16:32:56 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 07 Apr 2004 10:32:56 -0400 Subject: [C++-sig] Re: boost.python + mingw + msvc python References: <4073798E.2090806@fastmail.fm> Message-ID: Daniel Holth writes: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Have any of you used a mingw compiled Boost.Python to compile an > extension for MSVC python (the standard python.org python)? Yes, all the time. > I've had a pretty straightforwards experience using ming to compile > Boost.Python (on an XP box, sadly NOT cross compiled from a Linux > machine) making gcc libraries for various dlls, and I can compile the > extension itself. > > Unfortunately when I try to import the extension I get a vague sort of > 'dll not found' error. > > I know this is vague, I just would like to know if anyone has > succeeded in compiling a working Python+Boost.Python extension this > way. I'm trying to wrap ogg, vorbis and theora. > (http://dingoskidneys.com/oggpy/) Just use bjam with -sTOOLS=mingw -d+2 to build any of the examples. Then you can both see it work, and see the commands used to make it work. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Apr 7 16:39:51 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 07 Apr 2004 10:39:51 -0400 Subject: [C++-sig] Re: Reinitialization of interpreter with Boost.Python References: <4073C2B3.8040306@msobczak.com> Message-ID: Maciej Sobczak writes: > I have hacked the above function and removed both assertion and if, so > that the conversion function pointer is always written into the slot. > The second time my module is imported (after the interpreter is > finalized and re-initialized), the insert function above will just > overwrite the slot with the same value as before. > Interestingly, it started to work as expected, at least with simple > tests. I wouldn't expect it to keep working. > > What bothers me is the claim I found on Boost site, that > reinitialization of Python interpreter is *not* supported due to the > reference-counting problems affecting some global objects. > I do not experience any problems *at the moment*, but I would like to > know where the trolls may come from. > > What is exactly the problem? What should I be aware of? I think http://www.boost.org/libs/python/todo.html#pyfinalize-safety explains pretty well: They'll come when your application exits and global objects are destroyed, decrementing reference counts to zero after the interpreter is finalized. Also, objects may leak every time the interpreter is finalized. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Apr 7 16:46:01 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 07 Apr 2004 10:46:01 -0400 Subject: [C++-sig] Re: VC6 Compile error with boost 1.31.0 References: Message-ID: "Your Name" writes: > Using VC6, Python 2.3 and Boost 1.31.0, I get the following errors > > > inheritance.cpp > C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error > C2244: 'bidirectional_graph_ move_edge' : unable to resolve function > overload > C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error > C2954: template definitions > > plus a whole lot more. I know others have had this problem, and the > only answer I saw was to get a snapshot direct from CVS. Sadly I can't > get direct CVS access from my location. Is there anywhere else I can > get an update to the specific files? Hourly snapshot: http://www.boost-consulting.com/boost.tar.bz2 > And can someone list which files I need to get to fix this? I can't. Maybe Jeremy can? -- Dave Abrahams Boost Consulting www.boost-consulting.com From ndbecker2 at verizon.net Wed Apr 7 19:26:05 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Wed, 07 Apr 2004 13:26:05 -0400 Subject: [C++-sig] boost-python + lambda Message-ID: I'd like to wrap a class, but with a modified interface to some member functions. The easy way is write c++ code to wrap the class, inherit from it, and add the new member function, then expose that. I wonder if lambda can be used as a more direct approach? If so, what would the syntax look like? struct A { some_function (sig1); }; BOOST_PYTHON_MODULE (Test2) { class_ ("A") .def(some_function2 ( insert lambda here? ) From seefeld at sympatico.ca Wed Apr 7 19:55:45 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 07 Apr 2004 13:55:45 -0400 Subject: [C++-sig] boost-python + lambda References: Message-ID: <46d3d9ef516585b96870bace25a2137840744509@Orthosoft.ca> Neal D. Becker wrote: > I'd like to wrap a class, but with a modified interface to some member > functions. The easy way is write c++ code to wrap the class, inherit from > it, and add the new member function, then expose that. There is no need to derive a new class just to be able to wrap an individual method. A function with the right signature will do just fine: struct A { void method(int i); }; void method_wrapper(A &a, int i) { std::cout << "before the call" << std::endl; a.method(i); std::cout << "after the call" << std::endl; } ... class_ a("A"); a.def("method", method_wrapper); That's not quite as compact as a lambda but much less overhead than a derived class. I believe the only requirement on the wrapper signature is that the first argument is convertible to an 'A' reference. Regards, Stefan From mike at nospam.com Wed Apr 7 20:08:49 2004 From: mike at nospam.com (Mike Rovner) Date: Wed, 7 Apr 2004 11:08:49 -0700 Subject: [C++-sig] Re: boost-python + lambda References: Message-ID: Neal D. Becker wrote: > I'd like to wrap a class, but with a modified interface to some member > functions. The easy way is write c++ code to wrap the class, inherit > from it, and add the new member function, then expose that. I modify interface all the time to make it more pythonic ;) Usually I write a thin wrapper with desired interface and expose it. > I wonder if lambda can be used as a more direct approach? If so, > what would the syntax look like? You don't need that. You can expose members as functions and vice versa. Please provide some complete example of exxisting class and desired python interface to it. Regards, Mike From ndbecker2 at verizon.net Wed Apr 7 20:09:19 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Wed, 07 Apr 2004 14:09:19 -0400 Subject: [C++-sig] Re: boost-python + lambda References: <46d3d9ef516585b96870bace25a2137840744509@Orthosoft.ca> Message-ID: Stefan Seefeld wrote: > Neal D. Becker wrote: >> I'd like to wrap a class, but with a modified interface to some member >> functions. The easy way is write c++ code to wrap the class, inherit >> from it, and add the new member function, then expose that. > > There is no need to derive a new class just to be able to wrap an > individual method. A function with the right signature will do just fine: > > struct A > { > void method(int i); > }; > > void method_wrapper(A &a, int i) > { > std::cout << "before the call" << std::endl; > a.method(i); > std::cout << "after the call" << std::endl; > } > > ... > > class_ a("A"); > a.def("method", method_wrapper); > > > That's not quite as compact as a lambda but much less overhead than > a derived class. I believe the only requirement on the wrapper signature > is that the first argument is convertible to an 'A' reference. > Thanks! (Now why didn't I think of that? :) From wstwej03 at sneakemail.com Wed Apr 7 21:04:42 2004 From: wstwej03 at sneakemail.com (Eric) Date: Wed, 7 Apr 2004 12:04:42 -0700 Subject: [C++-sig] VC6 Compile error with boost 1.31.0 In-Reply-To: Message-ID: <22946-41960@sneakemail.com> I can't claim this is anything but a hack, but I was able to work around this problem with no ill effects with a handy #if 0: in boost\graph\detail\adjacency_list.hpp:1047 #if 0 // O(E/V) or O(log(E/V)) template inline void bidirectional_graph_helper_with_property::remove_edge(typename Config::edge_descriptor e) { typedef typename Config::graph_type graph_type; graph_type& g = static_cast(*this); boost::remove_edge(source(e, g), target(e, g), *this); } #endif I'm still able to build the boost_python dll with MSVC6 and build various python extension DLLs. Hope that is helpful... Eric -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org]On Behalf Of Your Name python-at-cityofdreams.com |cppsig| Sent: Wednesday, April 07, 2004 5:38 AM To: XXXXXXXXXXXXXXXXXXXXXX Subject: [C++-sig] VC6 Compile error with boost 1.31.0 Using VC6, Python 2.3 and Boost 1.31.0, I get the following errors inheritance.cpp C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1055) : error C2244: 'bidirectional_graph_ move_edge' : unable to resolve function overload C:\Lib\boost_1_31_0\boost/graph/detail/adjacency_list.hpp(1057) : error C2954: template definitions plus a whole lot more. I know others have had this problem, and the only answer I saw was to get a snapshot direct from CVS. Sadly I can't get direct CVS access from my location. Is there anywhere else I can get an update to the specific files? And can someone list which files I need to get to fix this? Thanks. Peter _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From python at cityofdreams.com Thu Apr 8 03:43:01 2004 From: python at cityofdreams.com (Peter) Date: Wed, 07 Apr 2004 21:43:01 -0400 Subject: [C++-sig] VC6 Compile error with boost 1.31.0 Message-ID: Thanks Eric, it builds ok now. Hoepefully that bit of code isn't critical for anything. Peter > I can't claim this is anything but a hack, but I was able to work around > this problem with no ill effects with a handy #if 0: > > in boost\graph\detail\adjacency_list.hpp:1047 > > #if 0 > // O(E/V) or O(log(E/V)) > template > inline void > bidirectional_graph_helper_with_property::remove_edge(typename > Config::edge_descriptor e) > { > typedef typename Config::graph_type graph_type; > graph_type& g = static_cast(*this); > boost::remove_edge(source(e, g), target(e, g), *this); > } > #endif > > I'm still able to build the boost_python dll with MSVC6 and build various > python extension DLLs. > > Hope that is helpful... > > Eric > > > From faheem at email.unc.edu Thu Apr 8 04:57:33 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Thu, 8 Apr 2004 02:57:33 +0000 (UTC) Subject: [C++-sig] problems with compiling and loading C++ extension Message-ID: Dear People, I have been having an odd problem with compiling and loading a simple C++ extension to python (as a .so file in Linux). Unfortunately, I'll need to include my files in here so I apologize in advance for the length of this message. You can download also the files below from http://www.stat.unc.edu/students/faheem/python/python.tar.gz in case that is more convenient. When I try to load arrmod.so into python I get In [1]: import arrmod --------------------------------------------------------------------------- ImportError Traceback (most recent call last) /tmp/wc/corrmodel/ex/ ImportError: ./arrmod.so: undefined symbol: _Z11py_to_blitzIdLi2EEN5blitz5ArrayIT_XT0_EEEP13PyArrayObject If I move the py_to_blitz routine from conv.cc back into arrmod.cc, the error disappears, arrmod loads in python, and everything works correctly. I'm not sure what is going on here. Can someone enlighten me? At first I thought it might have to do with the need for C linkage, but I tried that, and it does not appear to be the case. I also got the following compilation warning, which I don't understand. I don't know if that is relevant. --------------------------------------------------------------------- gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.3 -c conv.cc -o /tmp/temp.linux-i686-2.3/conv.o -Wall /usr/include/python2.3/Numeric/arrayobject.h:286: warning: `void**PyArray_API' defined but not used --------------------------------------------------------------------- Thanks in advance for any enlightenment. Faheem. ********************************************************************** Makefile ********************************************************************** arrmod.so: arrmod.cc common.hh conv.cc python setup.py build --build-base=/tmp --build-lib=. # may not do the right thing for everyone clean: rm arrmod.so rm -r /tmp/temp.linux-i686-2.3 ********************************************************************** ********************************************************************** setup.py ********************************************************************** from distutils.core import setup, Extension module4 = Extension('arrmod', sources = ['arrmod.cc','conv.cc'],libraries=["blitz","m"], extra_compile_args = ['-Wall']) setup (name = 'arrmod', version = '1.0', description = 'This module performs different operations on arrays', ext_modules = [module4] ) ********************************************************************** ********************************************************************** common.hh ********************************************************************** #include "Python.h" #include "Numeric/arrayobject.h" #include using namespace std; using namespace blitz; template static Array py_to_blitz(PyArrayObject* arr_obj); ********************************************************************** ********************************************************************** conv.cc ********************************************************************** #include "common.hh" // Convert a Numpy array to a blitz one, using the original's data (no // copy) template static Array py_to_blitz(PyArrayObject* arr_obj) { int T_size = sizeof(T); TinyVector shape(0); TinyVector strides(0); int *arr_dimensions = arr_obj->dimensions; int *arr_strides = arr_obj->strides; for (int i=0;i((T*) arr_obj->data,shape,strides,neverDeleteData); } ************************************************************************ ************************************************************************ arrmod.cc ************************************************************************ #include "common.hh" template static Array py_to_blitz(PyArrayObject* arr_obj); static PyObject * arrmod_elem(PyObject *self, PyObject *args); static PyMethodDef arrmod_methods[] = { {"elem", (PyCFunction)arrmod_elem, METH_VARARGS, "Returns the trace of a two-dimensional array.\n"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initarrmod(void) { (void) Py_InitModule3("arrmod", arrmod_methods, "Returns the Trace of a two-dimensional array.\n"); import_array(); } static PyObject * arrmod_elem(PyObject *self, PyObject *args) { PyObject *input, *result; PyArrayObject *array; double el; int i, j; if (!PyArg_ParseTuple(args, "Oii", &input, &i, &j)) return NULL; array = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 2, 2); if (array == NULL) return NULL; Array arr = py_to_blitz(array); el = arr(i,j); result = Py_BuildValue("d",el); return result; } ******************************************************************************** From iceryeah2000 at 163.com Thu Apr 8 05:13:01 2004 From: iceryeah2000 at 163.com (iceryeah) Date: Thu, 8 Apr 2004 11:13:01 +0800 Subject: [C++-sig] how to get python expection infomation in c++? Message-ID: hello, if python script has error when c++ prog is running, i can get the expection with error_already_set, now i want to get the expection infomation, but python interpreter output info to std_err, i can't get it! tell me your method how to get expection info. thanks From pierre.barbier at cirad.fr Thu Apr 8 09:59:05 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Thu, 08 Apr 2004 09:59:05 +0200 Subject: [C++-sig] how to get python expection infomation in c++? In-Reply-To: References: Message-ID: <1081411145.20965.7.camel@pbarbier> Hi ! I had the same problem ... so I redirected sys.stderr to a pipe I opened before ... Here's the few lines that do that : int nb_err[2]; FILE* err, *rd_err; pipe( nb_err ); // Initialise the pipe err = fdopen( nb_err[ 1 ], "w" ); setlinebuf( err ); rd_err = fdopen( nb_err[ 0 ], "r" ); // Install stderr boost::python::handle<> herr( PyFile_FromFile(err, "embedded_err", "w", fclose ) ); object obj_err( herr ); main_namespace[ "__embedded_stderr__" ] = obj_err; PyRun_String( "sys.stderr = __embedded_stderr__", Py_file_input, main_namespace.ptr(), main_namespace.ptr() ); After that, you can read the errors in rd_err. The assumption is made that the sys module is already imported ! Also, main_namespace is a boost::python::dict wrapping the __main__ module dictionnary. As I don't need to interpret what's written but just to forward it to the user, this interface is ok for me (I just have a thread dedicated to listen the error output). Pierre On Thu, 2004-04-08 at 05:13, iceryeah wrote: > hello, > if python script has error when c++ prog is running, i can get the > expection with error_already_set, now i want to get the expection > infomation, but python interpreter output info to std_err, i can't get it! > tell me your method how to get expection info. thanks > > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From dave at boost-consulting.com Thu Apr 8 13:28:09 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Apr 2004 07:28:09 -0400 Subject: [C++-sig] Re: how to get python expection infomation in c++? References: <1081411145.20965.7.camel@pbarbier> Message-ID: Pierre Barbier de Reuille writes: > Hi ! > > I had the same problem ... so I redirected sys.stderr to a pipe I opened > before ... > > Here's the few lines that do that : > > int nb_err[2]; > FILE* err, *rd_err; > pipe( nb_err ); > // Initialise the pipe > err = fdopen( nb_err[ 1 ], "w" ); > setlinebuf( err ); > rd_err = fdopen( nb_err[ 0 ], "r" ); > // Install stderr > boost::python::handle<> herr( PyFile_FromFile(err, "embedded_err", > "w", fclose ) ); > object obj_err( herr ); > main_namespace[ "__embedded_stderr__" ] = obj_err; > PyRun_String( "sys.stderr = __embedded_stderr__", Py_file_input, > main_namespace.ptr(), main_namespace.ptr() ); > > After that, you can read the errors in rd_err. The assumption is made > that the sys module is already imported ! Also, main_namespace is a > boost::python::dict wrapping the __main__ module dictionnary. As I don't > need to interpret what's written but just to forward it to the user, > this interface is ok for me (I just have a thread dedicated to listen > the error output). Easier approaches are detailed here: http://tinyurl.com/uiis and in: http://tinyurl.com/uiiu FWIW, -- Dave Abrahams Boost Consulting www.boost-consulting.com From paul at paulgrenyer.co.uk Thu Apr 8 13:35:41 2004 From: paul at paulgrenyer.co.uk (Paul Grenyer) Date: Thu, 8 Apr 2004 12:35:41 +0100 Subject: [C++-sig] Re: how to get python expection infomation in c++? Message-ID: <200404081135.i38BZff01006@ns.cricketthosting.co.uk> Hi > Easier approaches are detailed here: > > http://tinyurl.com/uiis > > and in: > > http://tinyurl.com/uiiu Which is great if you have a console for std::err to display the error on. If, like us, you've embedded python in a GUI based app, this doesn't work. Correct me if I'm wrong??? Regards Paul Paul Grenyer Email: paul at paulgrenyer.co.uk Web: http://www.paulgrenyer.co.uk Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/? Version 0.3.0 beta now available for download. From ndbecker2 at verizon.net Thu Apr 8 13:35:29 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Thu, 08 Apr 2004 07:35:29 -0400 Subject: [C++-sig] wrapping constructor Message-ID: Using boost-python I have a class with non-default constructor. I don't want to expose this constructor to python, but want to wrap it in a new interface. Is this OK? (No ownership issues...) I'm assuming copying the object is not terribly expensive, or won't happen that often. class X { X (something something) }; X MakeX (some args more suitable for python) { return X (use above constructor); } BOOST_PYTHON_MODULE(X_wrap) { class_ ("X", no_init); def ("MakeX", MakeX); } From pierre.barbier at cirad.fr Thu Apr 8 13:41:31 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Thu, 08 Apr 2004 13:41:31 +0200 Subject: [C++-sig] Re: how to get python expection infomation in c++? In-Reply-To: References: <1081411145.20965.7.camel@pbarbier> Message-ID: <1081424490.20446.13.camel@pbarbier> My point was about getting the error message not printed in stderr (because I have a GUI and reporting the error must be done in it). As PyErr_Print() writes its message to sys.stderr, the only way I found to get the message is to redirect sys.stderr to a pipe and to read this pipe. I event looked into Python code to see if there were a function to write the error where I want it to, but I didn't find any ! Pierre On Thu, 2004-04-08 at 13:28, David Abrahams wrote: > Pierre Barbier de Reuille writes: > > > Hi ! > > > > I had the same problem ... so I redirected sys.stderr to a pipe I opened > > before ... > > > > Here's the few lines that do that : > > > > int nb_err[2]; > > FILE* err, *rd_err; > > pipe( nb_err ); > > // Initialise the pipe > > err = fdopen( nb_err[ 1 ], "w" ); > > setlinebuf( err ); > > rd_err = fdopen( nb_err[ 0 ], "r" ); > > // Install stderr > > boost::python::handle<> herr( PyFile_FromFile(err, "embedded_err", > > "w", fclose ) ); > > object obj_err( herr ); > > main_namespace[ "__embedded_stderr__" ] = obj_err; > > PyRun_String( "sys.stderr = __embedded_stderr__", Py_file_input, > > main_namespace.ptr(), main_namespace.ptr() ); > > > > After that, you can read the errors in rd_err. The assumption is made > > that the sys module is already imported ! Also, main_namespace is a > > boost::python::dict wrapping the __main__ module dictionnary. As I don't > > need to interpret what's written but just to forward it to the user, > > this interface is ok for me (I just have a thread dedicated to listen > > the error output). > > Easier approaches are detailed here: > > http://tinyurl.com/uiis > > and in: > > http://tinyurl.com/uiiu > > FWIW, -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From ingo at fargonauten.de Thu Apr 8 13:57:02 2004 From: ingo at fargonauten.de (Ingo Luetkebohle) Date: Thu, 08 Apr 2004 13:57:02 +0200 Subject: [C++-sig] Re: how to get python expection infomation in c++? In-Reply-To: <1081424490.20446.13.camel@pbarbier> References: <1081411145.20965.7.camel@pbarbier> <1081424490.20446.13.camel@pbarbier> Message-ID: <1081425421.32167.1.camel@localhost> Am Do, den 08.04.2004 schrieb Pierre Barbier de Reuille um 13:41: > My point was about getting the error message not printed in stderr > (because I have a GUI and reporting the error must be done in it). As > PyErr_Print() writes its message to sys.stderr, the only way I found to > get the message is to redirect sys.stderr to a pipe and to read this > pipe. I event looked into Python code to see if there were a function to > write the error where I want it to, but I didn't find any ! Check out the source code for PyErr_Print (from Python). Its simply a convenience function to inspect the python traceback object. All the information is available with other Python/C calls and you can print it directly. Its slightly more effort, but might come in handy if you want to have just part of the trace or somesuch. regards -- Ingo Soll doch jeder bleiben, wie er gerne w?re. From rwgk at yahoo.com Thu Apr 8 14:11:43 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 8 Apr 2004 05:11:43 -0700 (PDT) Subject: [C++-sig] wrapping constructor In-Reply-To: Message-ID: <20040408121143.73543.qmail@web20206.mail.yahoo.com> --- "Neal D. Becker" wrote: > Using boost-python I have a class with non-default constructor. I don't > want to expose this constructor to python, but want to wrap it in a new > interface. Is this OK? (No ownership issues...) I'm assuming copying the > object is not terribly expensive, or won't happen that often. > > class X { > X (something something) > }; > > X MakeX (some args more suitable for python) { > return X (use above constructor); > } X* MakeX(...) { return new X(...); } > BOOST_PYTHON_MODULE(X_wrap) { > class_ ("X", no_init); > > def ("MakeX", MakeX); def("__init__", boost::python::make_constructor(MakeX)) ; > } boost::python::make_constructor is a fairly recent addition to the library. For this to work you'll need the 1.31 release or the current CVS. See also: http://www.boost.org/libs/python/doc/v2/make_function.html#make_constructor-spec boost/libs/python/test/injected.cpp Ralf __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ From ndbecker2 at verizon.net Thu Apr 8 14:56:21 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Thu, 08 Apr 2004 08:56:21 -0400 Subject: [C++-sig] Re: wrapping constructor References: <20040408121143.73543.qmail@web20206.mail.yahoo.com> Message-ID: Thanks, this is very helpful. Now a related question. I'm trying to wrap lots of C++ code, which is all written for STL-sytle iterators. So, a class X would look like: class X { template X (it_t beg, it_t end) {...} template void Compute (in_t in, in_t inend, out_t out) {...} }; I can write a non-member wrapper function to convert from a python container to the iterator interface needed by the constructor, as you described. How do I handle the member function? Can I make a non-member C++ wrapper, and then inject this into the class? How? template inline X* MakeX (CONT v) { return new X (v.begin(), v.end()); } template inline void Compute_wrap (X& c, CONT v) { c.Compute (v.begin(), v.end()); } BOOST_PYTHON_MODULE(Corr4_wrap) { typedef std::vector::const_iterator vc_cit; class_ ("X", no_init) .def("__init__", boost::python::make_constructor(MakeX& >)) .def("Compute", ) ; } From bert at isiosf.isi.it Thu Apr 8 16:45:05 2004 From: bert at isiosf.isi.it (bert at isiosf.isi.it) Date: Thu, 8 Apr 2004 16:45:05 +0200 Subject: [C++-sig] should (how) I use Python to run my c++ classes Message-ID: <20040408144505.GA25835@apus.isi.it> Hi all, I'm not a Python user, but I've read something and it seems very interesting. I'm expecially interested in it's interplatform nature also reguarding GUI (though Tkinter.) I've already written a lot of classes for medical image processing, and now I'm using qt as GUI to put all together. But, first of all, qt isn't free under windows, plus I'm encountering several troubles in putting together some libraries. So I though to Python as a possible language by which to write the GUI (Tkinter) and call my c++ classes. I've read quickly several parts of "learning Python" (oreilly) and I got my idea is feasible and even suggested in the introduction. But I don't know at all how to realize it... Of corse I now I'll have to read a lot, but it would be nice to have a simple example of a minimal python program calling a c++ class, maybe after clicking on a tk button. In this way I would understand if at least it can be useful for me before to start a timekeeping study. Any suggestion will be appreciated, thank you very much, Alberto From rwgk at yahoo.com Thu Apr 8 18:13:09 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 8 Apr 2004 09:13:09 -0700 (PDT) Subject: [C++-sig] Re: wrapping constructor In-Reply-To: Message-ID: <20040408161309.28511.qmail@web20210.mail.yahoo.com> --- "Neal D. Becker" wrote: > template > inline X* MakeX (CONT v) { > return new X (v.begin(), v.end()); > } > > template > inline void Compute_wrap (X& c, CONT v) { > c.Compute (v.begin(), v.end()); > } > > BOOST_PYTHON_MODULE(Corr4_wrap) { > typedef std::vector::const_iterator vc_cit; > > class_ ("X", no_init) > .def("__init__", boost::python::make_constructor(MakeX std::vector& >)) > .def("Compute", ) .def("Compute", Compute_wrap const&>) > ; > > } This will not work with older compilers such as gcc 2.96. If you need to support non-conforming compilers use a cast or write non-template thin wrappers, e.g. Compute_wrap_vector_complex. Ralf __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ From ndbecker2 at verizon.net Thu Apr 8 18:57:50 2004 From: ndbecker2 at verizon.net (Neal D. Becker) Date: Thu, 08 Apr 2004 12:57:50 -0400 Subject: [C++-sig] [boost-python] overloading problem Message-ID: I'm having trouble with overloading. It seems to work for default args, but not for a family of fncs with common prefix. This is on gcc-3.3.3. #include #include #include #include #include using namespace boost::python; struct george { void wack_em(int a) {} void wack_em(int a, int b) {} }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(george_overloads, wack_em, 1, 2) BOOST_PYTHON_MODULE (GEORGE) { class_ ("george") .def("wack_em", &george::wack_em, george_overloads()) ; } g++ -c Test3.cc -I/usr/include/python2.3 Test3.cc: In function `void init_module_GEORGE()': Test3.cc:19: error: no matching function for call to ` boost::python::class_ ::def(const char[8], , george_overloads)' From dave at boost-consulting.com Fri Apr 9 01:02:36 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Apr 2004 19:02:36 -0400 Subject: [C++-sig] Re: should (how) I use Python to run my c++ classes References: <20040408144505.GA25835@apus.isi.it> Message-ID: bert at isiosf.isi.it writes: > Hi all, > > I'm not a Python user, but I've read something and it seems very > interesting. I'm expecially interested in it's interplatform nature also > reguarding GUI (though Tkinter.) > > I've already written a lot of classes for medical image processing, and > now I'm using qt as GUI to put all together. But, first of all, qt > isn't free under windows, plus I'm encountering several troubles in > putting together some libraries. > So I though to Python as a possible language by which to write the GUI > (Tkinter) and call my c++ classes. I've read quickly several parts of > "learning Python" (oreilly) and I got my idea is feasible and even > suggested in the introduction. > But I don't know at all how to realize it... > Of corse I now I'll have to read a lot, but it would be nice to have a > simple example of a minimal python program calling a c++ class, maybe > after clicking on a tk button. In this way I would understand if at > least it can be useful for me before to start a timekeeping study. I suggest, especially if you already have Qt interfaces, that you go with http://tnfox.sourceforge.net/TnFOX/html/, which also has a Python interface. I know it's not the simple intro you wanted; maybe someone else can contribute that? -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Fri Apr 9 01:40:22 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 09 Apr 2004 00:40:22 +0100 Subject: [C++-sig] Python differences on Windows and Linux Message-ID: <4075F0F6.16766.822BE9@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 When creating a new interpreter using Py_NewInterpreter, on Windows I need to reimport my BPL based bindings in the new environment but if I try this on Linux I get BPL failing its "I don't like being imported twice" assertion test. Is this behaviour known and does anyone know why it's happening? Could it be related to my BPL based bindings being linked against a static library python on linux versus a dynamic library python on Windows? (I have wondered what the effects of having copies of python disjointed across different ELF binaries might be, especially if they're passing python structures being each other). Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQHXi5sEcvDLFGKbPEQLOLgCg9PO5wWeucGtXFN9+WLMYwkmJbGUAoNFL fcjxFM/ifNM4S+tOMTeqOy6e =FNhv -----END PGP SIGNATURE----- From dave at boost-consulting.com Fri Apr 9 01:51:16 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Apr 2004 19:51:16 -0400 Subject: [C++-sig] Re: [boost-python] overloading problem References: Message-ID: "Neal D. Becker" writes: > I'm having trouble with overloading. It seems to work for default args, but > not for a family of fncs with common prefix. Yes, it seems we have another instance of untested code in the tutorial here. Joel, can you fix that, please? > This is on gcc-3.3.3. > > #include > #include > #include > #include > #include > > using namespace boost::python; > > struct george > { > void wack_em(int a) {} > void wack_em(int a, int b) {} > }; > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(george_overloads, wack_em, 1, 2) I'd probably call it "wack_em_overloads" instead, but that's an aesthetic issue. > BOOST_PYTHON_MODULE (GEORGE) { > class_ ("george") > .def("wack_em", &george::wack_em, george_overloads()) Should be: .def("wack_em", (void(george::*)(int,int))0, george_overloads()) Actually, it occurs to me that since we know the maximum number of arguments, there's might be a way to make your code work as-is using template argument deduction... but I think it would be a giant mess 'o' metaprogramming for only a tiny gain. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Fri Apr 9 01:51:32 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 09 Apr 2004 00:51:32 +0100 Subject: [C++-sig] Re: should (how) I use Python to run my c++ classes In-Reply-To: Message-ID: <4075F394.25644.8C65F4@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 8 Apr 2004 at 19:02, David Abrahams wrote: > > I've already written a lot of classes for medical image processing, > > and now I'm using qt as GUI to put all together. But, first of all, > > qt isn't free under windows, plus I'm encountering several troubles > > in putting together some libraries. Qt is free for non-commercial use on Windows until v2.? - it's good enough for what you want. > > So I though to Python as a > > possible language by which to write the GUI (Tkinter) and call my > > c++ classes. I've read quickly several parts of "learning Python" > > (oreilly) and I got my idea is feasible and even suggested in the > > introduction. But I don't know at all how to realize it... Of corse > > I now I'll have to read a lot, but it would be nice to have a simple > > example of a minimal python program calling a c++ class, maybe after > > clicking on a tk button. In this way I would understand if at least > > it can be useful for me before to start a timekeeping study. There seem to be a lot of people wrapping medical software recently. If you have plenty of time in which to do this, moving as much of your project to being written in python as possible is a good idea. However in real world terms, if there's time constraints, best not stray too far from what you know already. > I suggest, especially if you already have Qt interfaces, that you go > with http://tnfox.sourceforge.net/TnFOX/html/, which also has a Python > interface. TnFOX only replicates the non-GUI part of Qt's API. FOX's API is used for the GUI bit! > I know it's not the simple intro you wanted; maybe someone else can > contribute that? I attach TestPython from TnFOX below. I hope it helps. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQHXlhMEcvDLFGKbPEQJIawCfSkBjAYoB9f1tbyelrhL+kQLaqXEAn2ev 4ua7RH1HmBHvIsxQaeVO3MXn =2xzU -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Fri Apr 9 01:51:32 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 09 Apr 2004 00:51:32 +0100 Subject: [C++-sig] Re: should (how) I use Python to run my c++ classes In-Reply-To: Message-ID: <4075F394.1750.8C64AC@localhost> The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: mainwindow.py Date: 9 Apr 2004, 0:51 Size: 2275 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: mainwindow.py Type: application/octet-stream Size: 2275 bytes Desc: not available URL: -------------- next part -------------- -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUAQHXlhMEcvDLFGKbPEQIbPgCfaqLlHQGfikJk9iCkg1ag8xtBe+QAoN5n YmMsa5cQQ9stuYifwXnSMKmS =wLo5 -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Fri Apr 9 01:51:31 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 09 Apr 2004 00:51:31 +0100 Subject: [C++-sig] Re: should (how) I use Python to run my c++ classes In-Reply-To: Message-ID: <4075F393.1406.8C6354@localhost> The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: main.py Date: 9 Apr 2004, 0:51 Size: 2468 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: main.py Type: application/octet-stream Size: 2468 bytes Desc: not available URL: -------------- next part -------------- -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUAQHXlg8EcvDLFGKbPEQJEUwCeO4oRIbWSFaYXsT4oPKiul+d/iUwAn2jK Batskm02Wy4Mr4rrJET2h4C/ =AF9X -----END PGP SIGNATURE----- From jmastro at rochester.rr.com Fri Apr 9 02:34:37 2004 From: jmastro at rochester.rr.com (James Mastro) Date: Thu, 8 Apr 2004 20:34:37 -0400 Subject: [C++-sig] wrap_python.hpp errors on Mac OS X Message-ID: I'm trying to use Boost.Python on Mac OS X 10.3.3, with boost 1.31.0. I finally got module building working right, and my Python objects can call into some wrapped C++ libraries of mine. But, I want to be able to go the other way, too. Have my C++ code call methods on the Python objects I create. But when I try to include , I get errors in the wrap_python.hpp file. The errors are: patchlevel.h: No such file or directory Python.h: No such file or directory The Python.h error I can easily fix. For the other, just commenting out the include of patchlevel.h seemed like a grand idea. But then I start getting compile errors in convertible.hpp (which might be happening even with my hacking in patchlevel.h) The boost.python site says it's known to work on 10.3, but it's not for me. Any ideas? I can use the Python/C API, of course, but Boost.Python looks much easier. -jim From ndbecker2 at verizon.net Fri Apr 9 02:51:18 2004 From: ndbecker2 at verizon.net (Neal Becker) Date: Thu, 08 Apr 2004 20:51:18 -0400 Subject: [C++-sig] python copying of boost-python objects Message-ID: I'm having a hard time figuring out how python handles copying of boost-python objects. In particularly, I want to wrap stl vector objects. What happens when I do x1 = x2[:] or use python copy()? Can/should I do something to control it to ensure large vector copies are efficient? From dave at boost-consulting.com Fri Apr 9 02:59:12 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Apr 2004 20:59:12 -0400 Subject: [C++-sig] Re: Python differences on Windows and Linux References: <4075F0F6.16766.822BE9@localhost> Message-ID: "Niall Douglas" writes: > When creating a new interpreter using Py_NewInterpreter, on Windows I > need to reimport my BPL based bindings in the new environment but if > I try this on Linux I get BPL failing its "I don't like being > imported twice" assertion test. > > Is this behaviour known and does anyone know why it's happening? > Could it be related to my BPL based bindings being linked against a > static library python on linux versus a dynamic library python on > Windows? Yes it could. I-know-it's-not-much,-but-HTH-ly y'rs, dave -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Fri Apr 9 05:49:29 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 8 Apr 2004 20:49:29 -0700 (PDT) Subject: [C++-sig] wrap_python.hpp errors on Mac OS X In-Reply-To: Message-ID: <20040409034929.73586.qmail@web20204.mail.yahoo.com> --- James Mastro wrote: > I'm trying to use Boost.Python on Mac OS X 10.3.3, with boost 1.31.0. I > finally got module building working right, and my Python objects can > call into some wrapped C++ libraries of mine. > > But, I want to be able to go the other way, too. Have my C++ code call > methods on the Python objects I create. But when I try to include > , I get errors in the wrap_python.hpp file. The > errors are: > > patchlevel.h: No such file or directory > Python.h: No such file or directory > > The Python.h error I can easily fix. For the other, just commenting out > the include of patchlevel.h seemed like a grand idea. But then I start > getting compile errors in convertible.hpp (which might be happening > even with my hacking in patchlevel.h) The boost.python site says it's > known to work on 10.3, but it's not for me. Any ideas? I can use the > Python/C API, of course, but Boost.Python looks much easier. I am using Boost.Python under OS 10.3.2 with Xcode v1.1 all the time, but I don't do embedding and I use a SCons-based build system. I'd guess that your problems are related to differences in the build system, or more specifically the compilation commands that are issued by the build system. Even more specifically, it looks like "-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3" is missing. Which build system are you using? Could you post the command line that leads to the "no such file" errors? If you are using bjam, add "-d2" to the bjam command line to see the commands that are issued. Ralf __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ From faheem at email.unc.edu Fri Apr 9 06:49:28 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Fri, 9 Apr 2004 04:49:28 +0000 (UTC) Subject: [C++-sig] help building hello world example on Debian Message-ID: Dear People, I have spent the last couple of hours trying to understand how to use bjam so as to build the `hello world' tutorial example for boost-python. I have not succeeded. I'm running Debian sarge. Debian seems me to want to use boost-python 1.30.2, though I also have 1.31 installed. I have also installed bjam. The Jamfile from the hello world example appears below. How should I modify this to work on my system? Alternatively, I'd be happy with a regular Makefile. I would prefer not to have to do extensive configuration of other files, and I'd also prefer not to have to modify the jamfile if I moved it to a different location in the directory hierarchy. Can these preferences be satisfied? When running bjam on the script below I get the following. bjam Unable to load Boost.Build: could not find build system. --------------------------------------------------------- /home/faheem/wc/boost/example/boost-build.jam attempted to load the build system by invoking 'boost-build ../../../tools/build/v1 ;' but we were unable to find "bootstrap.jam" in the specified directory or in BOOST_BUILD_PATH (searching /home/faheem/wc/boost/example/../../../tools/build/v1, /usr/share/boost-build). I have tried reading the documentation but it seems very complicated and I just get more confused. Some guidance would be appreciated. Faheem. ***************************************************************** # Hello World Example from the tutorial # [Joel de Guzman 10/9/2002] # Specify our location in the boost project hierarchy subproject libs/python/example/tutorial ; # Include definitions needed for Python modules import python ; extension hello # Declare a Python extension called hello : hello.cpp # source ../../build/boost_python # dependencies ; From dholth at fastmail.fm Fri Apr 9 07:24:28 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Fri, 09 Apr 2004 01:24:28 -0400 Subject: [C++-sig] help building hello world example on Debian In-Reply-To: References: Message-ID: <1081488268.3166.25.camel@bluefish> On Fri, 2004-04-09 at 00:49, Faheem Mitha wrote: > I have spent the last couple of hours trying to understand how to use > bjam so as to build the `hello world' tutorial example for > boost-python. I have not succeeded. > > I'm running Debian sarge. Debian seems me to want to use boost-python > 1.30.2, though I also have 1.31 installed. I have also installed bjam. One side effect of using the debian or gentoo boost package is that it's not laid out the same as the boost distribution. There will be no BOOST_ROOT laid out similarly to the way boost jam expects. Do you have the boost sources or just the debian package? Your chances for success are greater if you download the boost distribution. p.s. can somebody point me to a downloadable third-party extension that uses bjam? - Daniel H. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: From jmastro at rochester.rr.com Fri Apr 9 07:41:10 2004 From: jmastro at rochester.rr.com (James Mastro) Date: Fri, 9 Apr 2004 01:41:10 -0400 Subject: [C++-sig] wrap_python.hpp errors on Mac OS X In-Reply-To: <20040409034929.73586.qmail@web20204.mail.yahoo.com> References: <20040409034929.73586.qmail@web20204.mail.yahoo.com> Message-ID: <8145ECD4-89E8-11D8-A8B9-00306599C846@rochester.rr.com> On Apr 8, 2004, at 11:49 PM, Ralf W. Grosse-Kunstleve wrote: > it looks like > "-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/ > python2.3" > is missing. Which build system are you using? Could you post the > command line > that leads to the "no such file" errors? If you are using bjam, add > "-d2" to > the bjam command line to see the commands that are issued. When I add the include path above, there's no problems finding the files, thanks. But I get the errors in convertible.hpp relating to these lines: static inline no_convertible check(...) { return 0; } static inline yes_convertible check(Target) { return 0; } "error: storage class specified for typename" is what I get on the first line above. Then a bunch of other files have problems,because of this I assume. I'm building an app right in Xcode, and trying to include . Should I not be attempting this? -jim From faheem at email.unc.edu Fri Apr 9 07:55:48 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Fri, 9 Apr 2004 05:55:48 +0000 (UTC) Subject: [C++-sig] Re: help building hello world example on Debian References: <1081488268.3166.25.camel@bluefish> Message-ID: On Fri, 09 Apr 2004 01:24:28 -0400, Daniel Holth wrote: > One side effect of using the debian or gentoo boost package is that > it's not laid out the same as the boost distribution. There will be > no BOOST_ROOT laid out similarly to the way boost jam expects. > Do > you have the boost sources or just the debian package? Your chances > for success are greater if you download the boost distribution. I have the debian package installed. I also downloaded the debian sources for boost, which are the boost sources patched for debian. I was hoping that someone who uses Debian could tell me the correct compilation arguments to pass to g++, which I can then use to write a simple Makefile for hello.cpp. Surely it cannot be so difficult. Thanks. Faheem. From rwgk at yahoo.com Fri Apr 9 09:27:41 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 9 Apr 2004 00:27:41 -0700 (PDT) Subject: [C++-sig] Re: help building hello world example on Debian In-Reply-To: Message-ID: <20040409072741.25020.qmail@web20202.mail.yahoo.com> --- Faheem Mitha wrote: > On Fri, 09 Apr 2004 01:24:28 -0400, Daniel Holth wrote: > > > One side effect of using the debian or gentoo boost package is that > > it's not laid out the same as the boost distribution. There will be > > no BOOST_ROOT laid out similarly to the way boost jam expects. > Do > > you have the boost sources or just the debian package? Your chances > > for success are greater if you download the boost distribution. > > I have the debian package installed. I also downloaded the debian > sources for boost, which are the boost sources patched for debian. > > I was hoping that someone who uses Debian could tell me the correct > compilation arguments to pass to g++, which I can then use to write a > simple Makefile for hello.cpp. Surely it cannot be so difficult. If you have a fast network connection you could go to this site: http://cci.lbl.gov/cctbx_build/ Download "cctbx_bundle.selfx" (or one of the other source code bundles that include the Python sources if necessary; the complete Boost tree from about two days ago is included in all source code bundles). Issue perl cctbx_bundle.selfx If you are lucky you will see the compilation commands fly by. Copy and paste into your Makefile. Warnings: 1. You will get a lot more than you actually want. Ctrl-C after you've seen a few link commands producing *_ext.so. 2. We don't have a Debian system. I cannot guarantee that it works. If you don't see compilation commands within one minute after downloading the selfx file send me the error message or discard this idea :) Ralf P.S.: If you have the patience to wait for the entire compilation to finish and it works all the way to the end, please let me know. __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ From rwgk at yahoo.com Fri Apr 9 09:34:53 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 9 Apr 2004 00:34:53 -0700 (PDT) Subject: [C++-sig] wrap_python.hpp errors on Mac OS X In-Reply-To: <8145ECD4-89E8-11D8-A8B9-00306599C846@rochester.rr.com> Message-ID: <20040409073453.60132.qmail@web20210.mail.yahoo.com> --- James Mastro wrote: > When I add the include path above, there's no problems finding the > files, thanks. But I get the errors in convertible.hpp relating to > these lines: > > static inline no_convertible check(...) { return 0; } > static inline yes_convertible check(Target) { return 0; } > > "error: storage class specified for typename" is what I get on the > first line above. Then a bunch of other files have problems,because of > this I assume. Doesn't look familiar. I think we need to know exactly what you are trying to compile. > I'm building an app right in Xcode, and trying to include > . Should I not be attempting this? Is this from within some GUI? I'm compiling exclusively from the command line. But I suspect that compilation should also work from within the GUI *if* you get all the setting right. See also my posting from a few minutes ago. You can do the same under OS 10.3 and in this case I know it works (but look at the Mac OS X notes!). I.e. you can copy the compilation commands from the output that you see. Ralf __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ From dave at boost-consulting.com Fri Apr 9 14:02:07 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Apr 2004 08:02:07 -0400 Subject: [C++-sig] Re: wrap_python.hpp errors on Mac OS X References: <20040409034929.73586.qmail@web20204.mail.yahoo.com> <8145ECD4-89E8-11D8-A8B9-00306599C846@rochester.rr.com> Message-ID: James Mastro writes: > On Apr 8, 2004, at 11:49 PM, Ralf W. Grosse-Kunstleve wrote: > >> it looks like >> "-I/System/Library/Frameworks/Python.framework/Versions/2.3/include/ >> python2.3" >> is missing. Which build system are you using? Could you post the >> command line >> that leads to the "no such file" errors? If you are using bjam, add >> "-d2" to >> the bjam command line to see the commands that are issued. > > When I add the include path above, there's no problems finding the > files, thanks. But I get the errors in convertible.hpp relating to > these lines: > > static inline no_convertible check(...) { return 0; } > static inline yes_convertible check(Target) { return 0; } > > "error: storage class specified for typename" is what I get on the > first line above. Then a bunch of other files have problems,because of > this I assume. This is almost certainly an Apple-specific compiler bug. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Apr 9 14:16:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Apr 2004 08:16:11 -0400 Subject: [C++-sig] Re: help building hello world example on Debian References: Message-ID: Faheem Mitha writes: > Dear People, > > I have spent the last couple of hours trying to understand how to use > bjam so as to build the `hello world' tutorial example for > boost-python. I have not succeeded. > > I'm running Debian sarge. Debian seems me to want to use boost-python > 1.30.2 What does that mean, specifically? > , though I also have 1.31 installed. I have also installed bjam. > > The Jamfile from the hello world example appears below. How should I > modify this to work on my system? Alternatively, I'd be happy with a > regular Makefile. Take a clue from the libs/python/example subdirectory of your Boost installation (I suggest you use 1.31). [Joel, the tutorial example is not a very good one in general; people would like to be able to build extensions outside of their Boost tree. I think you ought to base the "building" example on the one in libs/python/example, and use project ids (e.g. @boost) as in that Jamfile] > I would prefer not to have to do extensive configuration of other > files, and I'd also prefer not to have to modify the jamfile if I > moved it to a different location in the directory hierarchy. Can these > preferences be satisfied? Yes; just use your boost-build file to indicate the location of the Boost project. > When running bjam on the script below I get the following. > > bjam > Unable to load Boost.Build: could not find build system. > --------------------------------------------------------- > /home/faheem/wc/boost/example/boost-build.jam attempted to load the > build system by invoking > > 'boost-build ../../../tools/build/v1 ;' It's very probable from looking at the paths above that the boost-build.jam file in your example directory ought to say: boost-build ../../tools/build/v1 ; ...or you can rewrite it to use an absolute path. You only need one boost-build.jam file somewhere in the directory tree above all the places from which you'll invoke bjam, pointing at your Boost installation's tools/build/v1 directory; for example, you could put one at the root of your filesystem and never set it again (not recommended). > but we were unable to find "bootstrap.jam" in the specified directory > or in BOOST_BUILD_PATH (searching > /home/faheem/wc/boost/example/../../../tools/build/v1, > /usr/share/boost-build). > > I have tried reading the documentation but it seems very complicated > and I just get more confused. Some guidance would be appreciated. Please, which docs seem complicated and were confusing you? We'd like to improve them. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dholth at fastmail.fm Fri Apr 9 17:34:24 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Fri, 09 Apr 2004 11:34:24 -0400 Subject: [C++-sig] Re: help building hello world example on Debian In-Reply-To: References: <1081488268.3166.25.camel@bluefish> Message-ID: <4076C280.8090700@fastmail.fm> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Faheem Mitha wrote: | I have the debian package installed. I also downloaded the debian | sources for boost, which are the boost sources patched for debian. | | I was hoping that someone who uses Debian could tell me the correct | compilation arguments to pass to g++, which I can then use to | write a simple Makefile for hello.cpp. Surely it cannot be so | difficult. Under Linux (I can't do this in Windows yet) I have had no difficulty using distutils to build boost.python extensions. Just put boost_python in the list of library dependencies and it works; my shoutpy (http://dingoskidneys.com/shoutpy/) would be a reasonable example. It is especially easy with boost packages since the standard include and library paths are all that's necessary. - - Daniel Holth -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFAdsKAVh4W2pVfoMsRAhmgAKCi+rWsklXFRWIbcUviTvGvXQ5LRwCdE8xF CSsKuCoq1zlgdKdgIXeZAlM= =wX/T -----END PGP SIGNATURE----- From s_sourceforge at nedprod.com Fri Apr 9 18:35:29 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Fri, 09 Apr 2004 17:35:29 +0100 Subject: [C++-sig] BPL and multiple interpreters Message-ID: <4076DEE1.404.4238926@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Having just recompiled everything to use the dynamic object python, it now turns out that on Linux at least, python v2.3 recalls the init() function for any python extension modules imported into a new interpreter. This is despite the documentation for Py_NewInterpreter saying that this is not the case. Surely though people on this list have noticed this before? If someone has used multiple interpreters with BPL and not found this, please do say. Otherwise, I suppose I should submit a bug report. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQHbQ08EcvDLFGKbPEQIUyQCbB69HCkWCdONaUkRKhkS2oVFivMsAnR0o cw9HY5yhODNa9nWENtqqKWzn =fkbS -----END PGP SIGNATURE----- From jmastro at rochester.rr.com Sat Apr 10 08:32:25 2004 From: jmastro at rochester.rr.com (James Mastro) Date: Sat, 10 Apr 2004 02:32:25 -0400 Subject: [C++-sig] Re: wrap_python.hpp errors on Mac OS X In-Reply-To: References: <20040409034929.73586.qmail@web20204.mail.yahoo.com> <8145ECD4-89E8-11D8-A8B9-00306599C846@rochester.rr.com> Message-ID: On Apr 9, 2004, at 8:02 AM, David Abrahams wrote: > This is almost certainly an Apple-specific compiler bug. It looks that way. So I'm basically out of luck...eh. -jim From python at cityofdreams.com Sat Apr 10 13:35:25 2004 From: python at cityofdreams.com (Peter) Date: Sat, 10 Apr 2004 07:35:25 -0400 Subject: [C++-sig] How to access a custom module from embedded Python? Message-ID: I've just started using boost.python and have embedded a Python interpretor in a test app. But how do I access a Python extension I have created in the same app that embeds Python? e.g. I define a hello module BOOST_PYTHON_MODULE(hello) { def("greet", greet); } and in the same code I embed Python: Py_Initialize(); handle<> main_module(borrowed( PyImport_AddModule("__main__") )); dict main_namespace(handle<>(borrowed( PyModule_GetDict(main_module.get()) ))); And am stuck at the next step... how do I call hello.greet() from this embedded Python instance? Thanks, Peter From rwgk at yahoo.com Sat Apr 10 17:44:52 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 10 Apr 2004 08:44:52 -0700 (PDT) Subject: [C++-sig] Re: wrap_python.hpp errors on Mac OS X In-Reply-To: Message-ID: <20040410154452.57662.qmail@web20201.mail.yahoo.com> --- James Mastro wrote: > On Apr 9, 2004, at 8:02 AM, David Abrahams wrote: > > > This is almost certainly an Apple-specific compiler bug. > > It looks that way. So I'm basically out of luck...eh. It got a lot of stuff to work under Mac OS X. I had to do only a few strange things, like adding dummy member data, but eventually everything worked. I don't think there is a reason to give up that quickly. Why don't you tell us exactly what you are trying to do. More often than not there is an alternative route that gets you around compiler-specific problems. Ralf __________________________________ Do you Yahoo!? Yahoo! Tax Center - File online by April 15th http://taxes.yahoo.com/filing.html From faheem at email.unc.edu Sun Apr 11 00:05:30 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Sat, 10 Apr 2004 22:05:30 +0000 (UTC) Subject: [C++-sig] Re: help building hello world example on Debian References: <1081488268.3166.25.camel@bluefish> <4076C280.8090700@fastmail.fm> Message-ID: On Fri, 09 Apr 2004 11:34:24 -0400, Daniel Holth wrote: > > Faheem Mitha wrote: > >| I have the debian package installed. I also downloaded the debian >| sources for boost, which are the boost sources patched for debian. >| >| I was hoping that someone who uses Debian could tell me the correct >| compilation arguments to pass to g++, which I can then use to >| write a simple Makefile for hello.cpp. Surely it cannot be so >| difficult. > > Under Linux (I can't do this in Windows yet) I have had no difficulty > using distutils to build boost.python extensions. Just put > boost_python in the list of library dependencies and it works; my > shoutpy (http://dingoskidneys.com/shoutpy/) would be a reasonable example. > > It is especially easy with boost packages since the standard include > and library paths are all that's necessary. Your package built without problems on Debian (once I had installed libshout3 and libshout3-dev). Thanks. This is very encouraging. I shall try using your setup.py and config.py as a template for my efforts. I didn't think distutils would work with boost python and there is no mention of it on the web page. I was about to ask why boost-python did not support distutils officially. I suppose the reasons are lack of portability. Faheem. From python at cityofdreams.com Sun Apr 11 01:18:55 2004 From: python at cityofdreams.com (Peter) Date: Sat, 10 Apr 2004 19:18:55 -0400 Subject: [C++-sig] How to access a custom module from embedded Python? Message-ID: Problem solved. My ignorance of how to use boost.python was to blame. I realized there is a fn named "inithello" that must be imported: PyImport_AppendInittab("hello", inithello); before Py_Initialize(); and later: object strRes(handle<>(PyRun_String( "from hello import *\n" "result = greet()\n", Py_file_input, main_namespace.ptr(), main_namespace.ptr()) )); const char* res = extract(main_namespace["result"]); So simple! - Peter > I've just started using boost.python and have embedded a Python > interpretor in a test app. But how do I access a Python extension I > have created in the same app that embeds Python? > > e.g. I define a hello module > > BOOST_PYTHON_MODULE(hello) > { > def("greet", greet); > } > > and in the same code I embed Python: > > Py_Initialize(); > > handle<> main_module(borrowed( > PyImport_AddModule("__main__") )); > dict main_namespace(handle<>(borrowed( > PyModule_GetDict(main_module.get()) ))); > > And am stuck at the next step... how do I call hello.greet() from this > embedded Python instance? > > Thanks, > Peter > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From faheem at email.unc.edu Sun Apr 11 01:18:43 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Sat, 10 Apr 2004 23:18:43 +0000 (UTC) Subject: [C++-sig] Re: help building hello world example on Debian References: <20040409072741.25020.qmail@web20202.mail.yahoo.com> Message-ID: On Fri, 9 Apr 2004 00:27:41 -0700 (PDT), Ralf W. Grosse-Kunstleve wrote: > If you have a fast network connection you could go to this site: > > http://cci.lbl.gov/cctbx_build/ > > Download "cctbx_bundle.selfx" (or one of the other source code bundles that > include the Python sources if necessary; the complete Boost tree from about two > days ago is included in all source code bundles). Issue > > perl cctbx_bundle.selfx > > If you are lucky you will see the compilation commands fly by. Copy and paste > into your Makefile. > > Warnings: > > 1. You will get a lot more than you actually want. Ctrl-C after you've seen a > few link commands producing *_ext.so. > > 2. We don't have a Debian system. I cannot guarantee that it works. If you > don't see compilation commands within one minute after downloading the selfx > file send me the error message or discard this idea :) > > Ralf > > P.S.: If you have the patience to wait for the entire compilation to finish and > it works all the way to the end, please let me know. Daniel Holth (see elsewhere in this thread) just informed me that distutils should work for me on Linux, and referred me to a extension package of his called shoutpy, using boost.python and built using distutils. This built for me on Debian with no problem, so it looks very hopeful. Therefore. I'll try using distutils (which I am somewhat familiar with already) before trying anything else. Thanks for the suggestion. Faheem. From faheem at email.unc.edu Sun Apr 11 02:08:14 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Sun, 11 Apr 2004 00:08:14 +0000 (UTC) Subject: [C++-sig] Re: help building hello world example on Debian References: Message-ID: Hi, Thanks for the quick and helpful reply. Replies follow. On Fri, 09 Apr 2004 08:16:11 -0400, David Abrahams wrote: > Faheem Mitha writes: > >> Dear People, >> >> I have spent the last couple of hours trying to understand how to use >> bjam so as to build the `hello world' tutorial example for >> boost-python. I have not succeeded. >> >> I'm running Debian sarge. Debian seems me to want to use boost-python >> 1.30.2 > > What does that mean, specifically? Never mind. I was talking nonsense. >> , though I also have 1.31 installed. I have also installed bjam. >> >> The Jamfile from the hello world example appears below. How should I >> modify this to work on my system? Alternatively, I'd be happy with a >> regular Makefile. > > Take a clue from the libs/python/example subdirectory of your Boost > installation (I suggest you use 1.31). I'd already downloaded the sources (patched for Debian), and looked at this directory. OK, I'm now looking at this more carefully. In what follows I'm going to try the obvious things and report what happens. 1) The first thing I am doing is copying the directory example to /tmp. I then tried faheem /tmp/example>bjam -sTOOLS=gcc test Unable to load Boost.Build: could not find build system. --------------------------------------------------------- /tmp/example/boost-build.jam attempted to load the build system by invoking 'boost-build ../../../tools/build/v1 ;' but we were unable to find "bootstrap.jam" in the specified directory or in BOOST_BUILD_PATH (searching /tmp/example/../../../tools/build/v1, /usr/share/boost-build). Ok. This obviously wants files elsewhere in the source directory eg (tools/build/vi). This is undesirable, as I don't want to have to always build my extensions inside the source directory. Looking at tools/build/vi, I see a lot of files ending with the words jam. I have all the relevant binary Debian packages installed, and the only place I see it is in /usr/share/doc/libboost-doc/HTML/tools/build/v1 which includes a few random files like python.jam, which do appear to correspond to the files in tools/build in the boost sources. Wonder if some of these files did not get copied by mistake. Regardless, these files should be part of a dev package, not a doc package if they are required for building. What is the difference between v1 and v2? Why should I be using one as opposed to the other? Does this correspond to the v1 and v2 of Boost Build? Should I be using v1? If so, why? 2) I then tried this command in the source directory. This gave me ******************************************************************* skipping Boost.Python library build due to missing or incorrect configuration couldn't find Python.h in "/usr/local/include/python2.2" You can configure the location of your python installation by setting: PYTHON_ROOT - currently "/usr/local" PYTHON_VERSION - The 2-part python Major.Minor version number (e.g. "2.2", NOT "2.2.1") - currently "2.2" The following are automatically configured from PYTHON_ROOT if not otherwise set: PYTHON_LIB_PATH - path to Python library object; currently "/usr/local/lib/python2.2/config" PYTHON_INCLUDES - path to Python #include directories; currently "/usr/local/include/python2.2" ******************************************************************* Ok. So I need to set some environmental variables. However, I don't want to have to set these environmental variables globally. http://www.boost.org/tools/build/v1/build_system.htm#setting_variables says I can set it in my Jamrules file. I have a Jamrules file in libs/python/example which says *************************************************************** ... # Edit this path to point at the root directory of your Boost # installation. Absolute paths work, too. path-global BOOST_ROOT : ../../.. ; project boost : $(BOOST_ROOT) ; ****************************************************************** Ok, putting path-global PYTHON_ROOT : /usr ; path-global PYTHON_VERSION : 2.3 ; in the Jamrules files seems to do the trick after a long compilation, and I get getting_started1.so getting_started2.so in bin/example. Suggestion. Add these lines above (or something similar) commented out to the Jamrules, since these will frequently need to be changed/adjusted depending on the system. > [Joel, the tutorial example is not a very good one in general; people > would like to be able to build extensions outside of their Boost tree. > I think you ought to base the "building" example on the one in > libs/python/example, and use project ids (e.g. @boost) as in that > Jamfile] Yes, I think it would be nice to have a tutorial where the configuration files are as detailed as possible. Preferably self-documenting. >> I would prefer not to have to do extensive configuration of other >> files, and I'd also prefer not to have to modify the jamfile if I >> moved it to a different location in the directory hierarchy. Can these >> preferences be satisfied? > > Yes; just use your boost-build file to indicate the location of the Boost > project. If this refers to the files in tools/build/v1, I must again repeat that they are not installed on my system. If this is an error on the part of the Debian maintainer(s), I'd be happy to file a suitable bug report. Let me know. >> When running bjam on the script below I get the following. >> >> bjam >> Unable to load Boost.Build: could not find build system. >> --------------------------------------------------------- >> /home/faheem/wc/boost/example/boost-build.jam attempted to load the >> build system by invoking >> >> 'boost-build ../../../tools/build/v1 ;' > > It's very probable from looking at the paths above that the > boost-build.jam file in your example directory ought to say: > > boost-build ../../tools/build/v1 ; > > ...or you can rewrite it to use an absolute path. You only need one > boost-build.jam file somewhere in the directory tree above all the > places from which you'll invoke bjam, pointing at your Boost > installation's tools/build/v1 directory; for example, you could put > one at the root of your filesystem and never set it again (not > recommended). > >> but we were unable to find "bootstrap.jam" in the specified directory >> or in BOOST_BUILD_PATH (searching >> /home/faheem/wc/boost/example/../../../tools/build/v1, >> /usr/share/boost-build). >> >> I have tried reading the documentation but it seems very complicated >> and I just get more confused. Some guidance would be appreciated. > > Please, which docs seem complicated and were confusing you? We'd > like to improve them. Ok, here are some suggestions. 1) Please clarify which files correspond to the boost build system. If these tools/build/v1 should be part of a binary installation, plese say so. It is is not reasonable to expect people to build against a complete copy of the boost sources. 2) Also, all this v1/v2 stuff is unclear. My impression is that v1 is the "stable" version of the build system, and v2 is the unstable one, but it would be useful to say something about this explicitly. 3) Make the tutorial example config files (eg. Jamfile, Jamrules, boost-build.jam) as self-contained and as detailed as possible, so a new user only needs to look at other documentation if he has special needs. Basically, include all configuration variable settings that might reasonably need to be changed, possibly commented out, and with enough explanation that the user could figure out what he needed to change it to, Daniel Holth just wrote that distutils works for him on Linux (apparently he uses Gentoo). He mentioned a Python extension package of his called shoutpy which uses boost.python and distutils, and it builds on Debian with no problem. Therefore, I might give this a try. I was wondering why boost.python does not officially support distutils. If it is for reasons of portability, I think it would do no harm to suggest it on the web page as a possible alternative, at least for Linux, possibly with a link to shoutpy or some other example of use. Sorry about the long message. Faheem. From dholth at fastmail.fm Sun Apr 11 06:19:57 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Sun, 11 Apr 2004 00:19:57 -0400 Subject: [C++-sig] Re: help building hello world example on Debian In-Reply-To: References: Message-ID: <4078C76D.2050507@fastmail.fm> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Faheem Mitha wrote: | Daniel Holth just wrote that distutils works for him on Linux | (apparently he uses Gentoo). He mentioned a Python extension | package of his called shoutpy which uses boost.python and | distutils, and it builds on Debian with no problem. Therefore, I | might give this a try. I'm very glad you've enjoyed my "exemplary" module. And I've also figured out boost.build v1. Definitely not harder to figure out than automake or even make. It's a very edifying way to build my little C++ example, too. Version 0.5.2 now includes a Jamfile that builds the module. http://dingoskidneys.com/shoutpy/ shoutpy is a wrapper that lets you use Python to send compressed audio to an icecast server for internet radio broadcast. The wrapper uses three files: a header and C++ file to wrap libshout2 in a C++ class, and the boost.python declarations in the third. http://www.xiph.org/~brendan/shout-python/ wraps the same library using the Python C api directly; my boost.python binary is 29 times larger than that when compiled by distutils and the boost-jam debug build is 165 times larger. When you run 'strip' on shoutpy.so the extension is only 18 times larger than the C version of almost the same thing. But as we know the boost.python wrapper gets written much more quickly and in a less dodgy way than often ad-hoc direct-to-Python-API code, and if we didn't care about programmer efficiency we wouldn't be using Python in the first place. - - Daniel Holth -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFAeMdsVh4W2pVfoMsRAtC+AJ0WRzoowFRNKUX6TYr6NtdB2qG/kwCgzWIf pUO8JgWIZVh6nn4qyO179AU= =ggN1 -----END PGP SIGNATURE----- From dave at boost-consulting.com Sun Apr 11 13:56:43 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 11 Apr 2004 07:56:43 -0400 Subject: [C++-sig] Re: help building hello world example on Debian References: Message-ID: [Volodya/Rene -- Faheem makes some important points about our documentation below] Faheem Mitha writes: > Hi, Thanks for the quick and helpful reply. Replies follow. > > In what follows I'm going to try the obvious things and report what > happens. > > 1) The first thing I am doing is copying the directory example to > /tmp. I then tried > > faheem /tmp/example>bjam -sTOOLS=gcc test > Unable to load Boost.Build: could not find build system. > --------------------------------------------------------- > /tmp/example/boost-build.jam attempted to load the build system by > invoking > > 'boost-build ../../../tools/build/v1 ;' > > but we were unable to find "bootstrap.jam" in the specified directory > or in BOOST_BUILD_PATH (searching > /tmp/example/../../../tools/build/v1, /usr/share/boost-build). > > Ok. This obviously wants files elsewhere in the source directory I don't know what you mean. Just read http://www.boost.org/libs/python/doc/building.html#building_ext and follow the directions there. You just have to make a couple of small edits to indicate where the Boost build system lives. > eg (tools/build/vi). This is undesirable, as I don't want to have to > always build my extensions inside the source directory. > > Looking at tools/build/vi, I see a lot of files ending with the words > jam. I have all the relevant binary Debian packages installed, and the > only place I see it is in > /usr/share/doc/libboost-doc/HTML/tools/build/v1 which includes a few > random files like python.jam, which do appear to correspond to the > files in tools/build in the boost sources. Wonder if some of these > files did not get copied by mistake. > > Regardless, these files should be part of a dev package, not a doc > package if they are required for building. I don't know anything about packages; I don't make the debian distros. You should talk to whoever is responsible for that. > What is the difference between v1 and v2? Why should I be using one as > opposed to the other? v1 is supported. v2 is prerelease. > > Does this correspond to the v1 and v2 of Boost Build? Yes. > Should I be using v1? If so, why? See above. > 2) I then tried this command in the source directory. > > This gave me > > ******************************************************************* > skipping Boost.Python library build due to missing or incorrect > configuration > > couldn't find Python.h in "/usr/local/include/python2.2" > > You can configure the location of your python installation by setting: > PYTHON_ROOT - currently "/usr/local" > PYTHON_VERSION - The 2-part python Major.Minor version number (e.g. > "2.2", NOT "2.2.1") - currently "2.2" > > The following are automatically configured from PYTHON_ROOT if not > otherwise set: > > PYTHON_LIB_PATH - path to Python library object; currently > "/usr/local/lib/python2.2/config" > PYTHON_INCLUDES - path to Python #include directories; > currently "/usr/local/include/python2.2" > ******************************************************************* > > Ok. So I need to set some environmental variables. However, I don't > want to have to set these environmental variables globally. > > http://www.boost.org/tools/build/v1/build_system.htm#setting_variables > says I can set it in my Jamrules file. I have a Jamrules file in > libs/python/example which says > > *************************************************************** > ... > # Edit this path to point at the root directory of your Boost > # installation. Absolute paths work, too. > path-global BOOST_ROOT : ../../.. ; > project boost : $(BOOST_ROOT) ; > ****************************************************************** > > Ok, putting > > path-global PYTHON_ROOT : /usr ; > path-global PYTHON_VERSION : 2.3 ; > > in the Jamrules files seems to do the trick after a long compilation, > and I get getting_started1.so getting_started2.so in bin/example. Whoo hoo! > Suggestion. Add these lines above (or something similar) commented out > to the Jamrules, since these will frequently need to be > changed/adjusted depending on the system. > >> [Joel, the tutorial example is not a very good one in general; people >> would like to be able to build extensions outside of their Boost tree. >> I think you ought to base the "building" example on the one in >> libs/python/example, and use project ids (e.g. @boost) as in that >> Jamfile] > > Yes, I think it would be nice to have a tutorial where the > configuration files are as detailed as possible. Preferably > self-documenting. That's a good idea. >>> I would prefer not to have to do extensive configuration of other >>> files, and I'd also prefer not to have to modify the jamfile if I >>> moved it to a different location in the directory hierarchy. Can these >>> preferences be satisfied? >> >> Yes; just use your boost-build file to indicate the location of the Boost >> project. > > If this refers to the files in tools/build/v1, I must again repeat > that they are not installed on my system. If this is an error on the > part of the Debian maintainer(s), I'd be happy to file a suitable bug > report. Let me know. If you want to build the Boost libraries or use Boost.Build for building your own extensions, they're required. I'm not qualified to say whether the fact that they're missing is an error. >> Please, which docs seem complicated and were confusing you? We'd >> like to improve them. > > Ok, here are some suggestions. Thanks, these are much appreciated. > 1) Please clarify which files correspond to the boost build system. Where should that be clarified? > If these tools/build/v1 should be part of a binary installation, > plese say so. It depends on your expectations of a binary installation, I guess. If you want to do all your building with other build systems, you probably don't need them. That said, we recommend Boost.Build, at least in order to see the proper command-lines. > It is is not reasonable to expect people to build against a complete > copy of the boost sources. Actually, that is the expectation. > 2) Also, all this v1/v2 stuff is unclear. My impression is that v1 is > the "stable" version of the build system, and v2 is the unstable one, > but it would be useful to say something about this explicitly. Where should that be stated? > 3) Make the tutorial example config files (eg. Jamfile, Jamrules, > boost-build.jam) as self-contained and as detailed as possible, so a > new user only needs to look at other documentation if he has special > needs. Great; I can handle that part. > Basically, include all configuration variable settings that might > reasonably need to be changed I don't think we can quite do that, since individual compilers may need config info, however we can make reference to the toolsets web pages that document it. > possibly commented out, and with enough explanation that the user > could figure out what he needed to change it to, > > Daniel Holth just wrote that distutils works for him on Linux > (apparently he uses Gentoo). He mentioned a Python extension package > of his called shoutpy which uses boost.python and distutils, and it > builds on Debian with no problem. Therefore, I might give this a try. > > I was wondering why boost.python does not officially support > distutils. Several reasons: 1. When I was investigating distutils, its ability to deal with the particular issues of building C++ code was highly/deeply lacking, even according to the distutils people. 2. I don't have time to support a great many different build tools. Getting portable builds that will work on all the different compilers with Boost.Build is hard enough. If I support bjam and distutils, why not make? Why not scons? > If it is for reasons of portability, I think it would do no harm to > suggest it on the web page as a possible alternative, at least for > Linux, possibly with a link to shoutpy or some other example of use. I have no guarantee that it's going to work, and "seems to work for me" isn't good enough; the build code to support Boost.Python extensions in all of the different configurations is nontrivial, and I'd bet you dollars to donuts that a naive build of all the Boost.Python regression test extensions with distutils will turn up problems. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Apr 11 15:13:00 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 11 Apr 2004 09:13:00 -0400 Subject: [C++-sig] Re: help building hello world example on Debian References: <4078C76D.2050507@fastmail.fm> Message-ID: Daniel Holth writes: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Faheem Mitha wrote: > > | Daniel Holth just wrote that distutils works for him on Linux > | (apparently he uses Gentoo). He mentioned a Python extension > | package of his called shoutpy which uses boost.python and > | distutils, and it builds on Debian with no problem. Therefore, I > | might give this a try. > > I'm very glad you've enjoyed my "exemplary" module. And I've also > figured out boost.build v1. Definitely not harder to figure out than > automake or even make. It's a very edifying way to build my little C++ > example, too. I just updated the CVS with a better-commented example directory; see http://boost-consulting.com/boost/libs/python/example/README, which should be updated within the hour. Daniel, it'd be a great idea for you to make sure that your shoutpy example uses the same techniques, if you're going to be passing it around as an example. Why did you do this? You don't need it: # Include definitions needed for Python modules SEARCH on python.jam = $(BOOST_BUILD_PATH) ; > Version 0.5.2 now includes a Jamfile that builds the module. > http://dingoskidneys.com/shoutpy/ > > shoutpy is a wrapper that lets you use Python to send compressed audio > to an icecast server for internet radio broadcast. The wrapper uses > three files: a header and C++ file to wrap libshout2 in a C++ class, > and the boost.python declarations in the third. Nice! What can one do with this library, in lay terms? > http://www.xiph.org/~brendan/shout-python/ wraps the same library > using the Python C api directly; my boost.python binary is 29 times > larger than that when compiled by distutils and the boost-jam debug > build is 165 times larger. When you run 'strip' on shoutpy.so the > extension is only 18 times larger than the C version of almost the > same thing. But as we know the boost.python wrapper gets written much > more quickly and in a less dodgy way than often ad-hoc > direct-to-Python-API code, and if we didn't care about programmer > efficiency we wouldn't be using Python in the first place. Well, yeah, and did you try a release build? -- Dave Abrahams Boost Consulting www.boost-consulting.com From faheem at email.unc.edu Sun Apr 11 17:20:28 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Sun, 11 Apr 2004 15:20:28 +0000 (UTC) Subject: [C++-sig] Re: help building hello world example on Debian References: Message-ID: Hi, Thanks very much for the followup. On Sun, 11 Apr 2004 07:56:43 -0400, David Abrahams wrote: > [Volodya/Rene -- Faheem makes some important points about our > documentation below] > > Faheem Mitha writes: > >> Hi, Thanks for the quick and helpful reply. Replies follow. >> >> In what follows I'm going to try the obvious things and report what >> happens. >> >> 1) The first thing I am doing is copying the directory example to >> /tmp. I then tried >> >> faheem /tmp/example>bjam -sTOOLS=gcc test >> Unable to load Boost.Build: could not find build system. >> --------------------------------------------------------- >> /tmp/example/boost-build.jam attempted to load the build system by >> invoking >> >> 'boost-build ../../../tools/build/v1 ;' >> >> but we were unable to find "bootstrap.jam" in the specified directory >> or in BOOST_BUILD_PATH (searching >> /tmp/example/../../../tools/build/v1, /usr/share/boost-build). >> >> Ok. This obviously wants files elsewhere in the source directory > > I don't know what you mean. Just read > http://www.boost.org/libs/python/doc/building.html#building_ext and > follow the directions there. You just have to make a couple of small > edits to indicate where the Boost build system lives. What I meant is that an installation of the Boost build system is required. Therefore the bjam executable requires more than just itself and the local config files referring specifically to that extension (eg. Jamfile, boost-build.jam) in order to build. >> eg (tools/build/vi). This is undesirable, as I don't want to have to >> always build my extensions inside the source directory. >> >> Looking at tools/build/vi, I see a lot of files ending with the words >> jam. I have all the relevant binary Debian packages installed, and the >> only place I see it is in >> /usr/share/doc/libboost-doc/HTML/tools/build/v1 which includes a few >> random files like python.jam, which do appear to correspond to the >> files in tools/build in the boost sources. Wonder if some of these >> files did not get copied by mistake. >> >> Regardless, these files should be part of a dev package, not a doc >> package if they are required for building. > > I don't know anything about packages; I don't make the debian > distros. You should talk to whoever is responsible for that. Ok. Looks like I will be filing a bug report. libboost-dev looks like a reasonable starting point. Any comments from other Debian users here? Is all this already supplied in Debian and I am not aware of it somehow? >> What is the difference between v1 and v2? Why should I be using one as >> opposed to the other? > > v1 is supported. v2 is prerelease. Ok. >> Does this correspond to the v1 and v2 of Boost Build? > > Yes. Ok >> Should I be using v1? If so, why? > > See above. > >> 2) I then tried this command in the source directory. >> >> This gave me >> >> ******************************************************************* >> skipping Boost.Python library build due to missing or incorrect >> configuration >> >> couldn't find Python.h in "/usr/local/include/python2.2" >> >> You can configure the location of your python installation by setting: >> PYTHON_ROOT - currently "/usr/local" >> PYTHON_VERSION - The 2-part python Major.Minor version number (e.g. >> "2.2", NOT "2.2.1") - currently "2.2" >> >> The following are automatically configured from PYTHON_ROOT if not >> otherwise set: >> >> PYTHON_LIB_PATH - path to Python library object; currently >> "/usr/local/lib/python2.2/config" >> PYTHON_INCLUDES - path to Python #include directories; >> currently "/usr/local/include/python2.2" >> ******************************************************************* >> >> Ok. So I need to set some environmental variables. However, I don't >> want to have to set these environmental variables globally. >> >> http://www.boost.org/tools/build/v1/build_system.htm#setting_variables >> says I can set it in my Jamrules file. I have a Jamrules file in >> libs/python/example which says >> >> *************************************************************** >> ... >> # Edit this path to point at the root directory of your Boost >> # installation. Absolute paths work, too. >> path-global BOOST_ROOT : ../../.. ; >> project boost : $(BOOST_ROOT) ; >> ****************************************************************** >> >> Ok, putting >> >> path-global PYTHON_ROOT : /usr ; >> path-global PYTHON_VERSION : 2.3 ; >> >> in the Jamrules files seems to do the trick after a long compilation, >> and I get getting_started1.so getting_started2.so in bin/example. > > Whoo hoo! > >> Suggestion. Add these lines above (or something similar) commented out >> to the Jamrules, since these will frequently need to be >> changed/adjusted depending on the system. >> >>> [Joel, the tutorial example is not a very good one in general; people >>> would like to be able to build extensions outside of their Boost tree. >>> I think you ought to base the "building" example on the one in >>> libs/python/example, and use project ids (e.g. @boost) as in that >>> Jamfile] >> >> Yes, I think it would be nice to have a tutorial where the >> configuration files are as detailed as possible. Preferably >> self-documenting. > > That's a good idea. > >>>> I would prefer not to have to do extensive configuration of other >>>> files, and I'd also prefer not to have to modify the jamfile if I >>>> moved it to a different location in the directory hierarchy. Can these >>>> preferences be satisfied? >>> >>> Yes; just use your boost-build file to indicate the location of the Boost >>> project. >> >> If this refers to the files in tools/build/v1, I must again repeat >> that they are not installed on my system. If this is an error on the >> part of the Debian maintainer(s), I'd be happy to file a suitable bug >> report. Let me know. > > If you want to build the Boost libraries or use Boost.Build for > building your own extensions, they're required. I'm not qualified to > say whether the fact that they're missing is an error. Well, perhaps error is the wrong word. However, before I can file a bug report, I do need to know whether these are the *only* files required for an extension build. See below. >>> Please, which docs seem complicated and were confusing you? We'd >>> like to improve them. >> >> Ok, here are some suggestions. > > Thanks, these are much appreciated. > >> 1) Please clarify which files correspond to the boost build system. > > Where should that be clarified? I think the tutorial would be a good place to say something about this. Bear in mind that most people will pass that way at least at the beginning, and at least some of them will not be familiar with the boost build system. >> If these tools/build/v1 should be part of a binary installation, >> please say so. > > It depends on your expectations of a binary installation, I guess. > If you want to do all your building with other build systems, you > probably don't need them. That said, we recommend Boost.Build, at > least in order to see the proper command-lines. Well, to clarify, I mean you should be able (at least for a modern Linux distribution) to install packages (using rpm, apt, emerge whatever) all necessary files into the system to enable such extensions to build. The word binary may be misleading in this context. Is it correct to say that the files in build/v1 would be enough by themselves for the extension to build against? That is my impression, since boost-build.jam in the libs/python/example directory is pointing to it, and nothing else is the build process is looking for other files in the Boost installation. However, it seems possible, since compilation took so long, that the build also compiled files elsewhere in the sources as part of the extension build. If so, this would make things more difficult. I'd appreciate information about this. >> It is is not reasonable to expect people to build against a complete >> copy of the boost sources. > > Actually, that is the expectation. Surely a complete source copy is not necessary if only certain files are required. >> 2) Also, all this v1/v2 stuff is unclear. My impression is that v1 is >> the "stable" version of the build system, and v2 is the unstable one, >> but it would be useful to say something about this explicitly. > > Where should that be stated? Again, the tutorial would be a good place. >> 3) Make the tutorial example config files (eg. Jamfile, Jamrules, >> boost-build.jam) as self-contained and as detailed as possible, so a >> new user only needs to look at other documentation if he has special >> needs. > > Great; I can handle that part. > >> Basically, include all configuration variable settings that might >> reasonably need to be changed > > I don't think we can quite do that, since individual compilers may > need config info, however we can make reference to the toolsets web > pages that document it. In Jamrules, mention path-global PYTHON_ROOT : /usr ; path-global PYTHON_VERSION : 2.3 ; at least, these will frequently need to be changed. Possibly also add a line for $(ALL_LOCATE_TARGET) since people often want to control where their built binaries will end up. I know I do. None of these are compiler/tool-chain dependent config options, as far as I can see. You already mention python config stuff in Jamrules (in libs/python/example/Jamrules), but put in the actual lines to be used so people don't have figure out the exact syntax. >> possibly commented out, and with enough explanation that the user >> could figure out what he needed to change it to, >> >> Daniel Holth just wrote that distutils works for him on Linux >> (apparently he uses Gentoo). He mentioned a Python extension package >> of his called shoutpy which uses boost.python and distutils, and it >> builds on Debian with no problem. Therefore, I might give this a try. >> >> I was wondering why boost.python does not officially support >> distutils. > > Several reasons: > > 1. When I was investigating distutils, its ability to deal with the > particular issues of building C++ code was highly/deeply lacking, > even according to the distutils people. > > 2. I don't have time to support a great many different build tools. > Getting portable builds that will work on all the different compilers > with Boost.Build is hard enough. If I support bjam and distutils, > why not make? Why not scons? Well, distutils is the official build tool for Python extensions, as I understand it. So it is not quite the same as make or scons etc. A few questions. * Is work underway to add the necessary C++ support to distutils? * Once there is sufficient support, would you consider officially supporting distutils? * Is there anything you can point me to which discusses distutil's deficiencies wrt to C++? I think I will continue using distutils for the moment, at least till such time as I run into problems. I suspect for the rather simple C++c code I am likely to write, I will be Ok. >> If it is for reasons of portability, I think it would do no harm to >> suggest it on the web page as a possible alternative, at least for >> Linux, possibly with a link to shoutpy or some other example of use. > > I have no guarantee that it's going to work, and "seems to work for > me" isn't good enough; the build code to support Boost.Python > extensions in all of the different configurations is nontrivial, and > I'd bet you dollars to donuts that a naive build of all the > Boost.Python regression test extensions with distutils will turn up > problems. Ok. Fair enough. Thanks for the detailed replies. Faheem. From dholth at fastmail.fm Sun Apr 11 18:28:00 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Sun, 11 Apr 2004 12:28:00 -0400 Subject: [C++-sig] Re: help building hello world example on Debian In-Reply-To: References: <4078C76D.2050507@fastmail.fm> Message-ID: <40797210.7030903@fastmail.fm> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Abrahams wrote: | I just updated the CVS with a better-commented example directory; | see http://boost-consulting.com/boost/libs/python/example/README, | which should be updated within the hour. Daniel, it'd be a great | idea for you to make sure that your shoutpy example uses the same | techniques, if you're going to be passing it around as an example. Good, I'll check mine. Thanks for the improved example. It is better, I've just incorporated your Jamrules into shoutpy. shoutpy is an instance of a simple external Boost.Python extension, optionally using boost-build or distutils-, and it depends on a non-boost library. I would like to hear about more libraries that meet this criteria. warning: shoutpy's boost-jam setup may not work right now for you. Must I distribute the boost license along with my program because I've used your example? | Why did you do this? You don't need it: | | # Include definitions needed for Python modules SEARCH on | python.jam = $(BOOST_BUILD_PATH) ; It's there because it was in project.zip , no other reason. |> http://dingoskidneys.com/shoutpy/ |> |> shoutpy is a wrapper that lets you use Python to send compressed |> audio | Nice! What can one do with this library, in lay terms? You can use shoutpy to send Ogg/Vorbis or mp3 music to an Internet radio station. | Well, yeah, and did you try a release build? Just did... the module's binary is 135 kilobytes. That's about half the size of the distutils build, very good! What are the advantages to using this: ~