From srossross at gmail.com Fri Jun 1 03:01:24 2007 From: srossross at gmail.com (Sean Ross-Ross) Date: Thu, 31 May 2007 19:01:24 -0600 Subject: [C++-sig] smart ptr In-Reply-To: <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> References: <20070521131405.GA12892@dogbert.sdsl.sun.ac.za> <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> Message-ID: <410D3A8B-F88B-4B39-89AD-6607BDC69A4A@gmail.com> I have a class that is similar to a smart_ptr, called RefCountPtr and I have a c++ class constructor X::X( RefCountPtr< foo >& f ) : thisfoo(f) ; When I pass a Python 'foo' object into this constructor, I want to wrap it in a c++ RefCountPtr class before passing it to the c++ constructor. I have written an from_python extration method to do this static void* extract_rcp(PyObject* o) { object boostobj = object(handle<>(borrowed( o )) ); foo *counted = extract( boostobj ); RefCountPtr< foo > *counter = new RefCountPtr< foo > ( counted , true ); return counter; } When I extract the 'foo' object, I create a new RefCountPtr to pass to the constructor, once the constructor finishes, I am left with a reference count of 2: One for the new'd object and one for the data member of the X class. My question is, how can I get rid of the extra reference count? Is there a call policy that will do this for me? ~Sean From fred.jen at web.de Fri Jun 1 14:55:08 2007 From: fred.jen at web.de (Fred Jendrzejewski) Date: Fri, 01 Jun 2007 14:55:08 +0200 Subject: [C++-sig] using boost.python with boost-build v2 Message-ID: <1180702508.6724.13.camel@muli> Hello, if i want to built the hello.cpp example from the tutorial i get the warning, that it is impossible to find a Jamfile or a project-jam.root. Because all the problems seems to be a lil bit strange, i will describe my configuration as good as possible: the boost-built directory is: /usr/share/boost-build and in the tools/ directory there is no build sub-directory the bjam is in : /usr/bin i have python2.5 bjam --version gives me: Boost.Build V2 (Milestone 11) Boost.Jam 03.1.13 the directory where i copied the hello.cpp, Jamrules, the Jamfile and the boost-build.jam is ~/Boost the hello.cpp is like before. the Jamfile is that: project hello : requirements /boost/python//boost_python : build_dir ~/Boost/ ; python-extension hello: hello.cpp ; the jamrules: path-global BOOST_ROOT : /usr/include/ ; project boost : $(BOOST_ROOT) ; the boost-build.jam: boost-build /usr/share/boost-build/tools ; the user-config.jam are copied in the ~/ and there you can find: import toolset : using ; using gcc ; using python : 2.5 ; Properbly i am overlooking something, but i found no solution until now. Knid Regards, Fred Jendrzejewski From srossross at gmail.com Fri Jun 1 22:34:24 2007 From: srossross at gmail.com (Sean Ross-Ross) Date: Fri, 1 Jun 2007 14:34:24 -0600 Subject: [C++-sig] extract Message-ID: hi, How do I write multiple to_python conversions? Say I have an boost::python::object and I call extract, where the object could be a "c++ somthing class" or a Python dictionary Thanks From sipickles at hotmail.com Fri Jun 1 22:48:32 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Fri, 01 Jun 2007 21:48:32 +0100 Subject: [C++-sig] Exception using boost::python and PyRun_file Message-ID: Hi, [newbie alert] I am trying to embed python in c++ with boost::python. I'm using MSVC++ 2005 Express Boost 1.34 Python 2.52 Unfortunately, I've come unstuck already. Here's my code object main_module( ( handle<>( borrowed( PyImport_AddModule( "__main__" ) ) ) ) ); object main_namespace = main_module.attr("__dict__"); FILE* myPython = fopen( "myPython.py", "r" ); handle<> ignored( ( PyRun_File( myPython, "myPython.py", Py_file_input, main_namespace.ptr(), main_namespace.ptr() ) ) ); fclose( myPython ); and heres the exception: First-chance exception at 0x7c918fea in Server 20070601.exe: 0xC0000005: Access violation writing location 0x00000010. Unhandled exception at 0x7c918fea in Server 20070601.exe: 0xC0000005: Access violation writing location 0x00000010. What am I doing wrong? must be something simple :) Thanks! Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ Play your part in making history - Email Britain! http://www.emailbritain.co.uk/ From seefeld at sympatico.ca Fri Jun 1 23:06:49 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 01 Jun 2007 17:06:49 -0400 Subject: [C++-sig] Exception using boost::python and PyRun_file In-Reply-To: References: Message-ID: <46608A69.7030200@sympatico.ca> Simon Pickles wrote: > Here's my code > > object main_module( ( handle<>( borrowed( PyImport_AddModule( "__main__" > ) ) ) ) ); > > object main_namespace = main_module.attr("__dict__"); > > FILE* myPython = fopen( "myPython.py", "r" ); > > handle<> ignored( ( PyRun_File( myPython, "myPython.py", > Py_file_input, > main_namespace.ptr(), > main_namespace.ptr() ) ) ); > > fclose( myPython ); Please try this instead: python::object main = python::import("__main__"); python::object global(main.attr("__dict__")); python::object result = python::exec_file("myPython.py", global, global); (This API is new in Boost.Python 1.34.) I'm not sure what may have caused the error. One likely cause is that boost and your own application have not been compiled with the same compiler (version), leading to ABI incompatibilities such as different FILE definitions. But that's just a guess, of course. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From nickm at sitius.com Fri Jun 1 23:55:27 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Fri, 01 Jun 2007 17:55:27 -0400 Subject: [C++-sig] Documentation patch Message-ID: <466095CF.37ECCAD7@sitius.com> Hello, I have a docstring related patch which I would like to submit. It outputs nice python signatures with every function, condensing the overloads and displaying the default parameter values. This is how the output of help looks >>> help(ugui.AngleField.value) Help on method value: value(...) unbound sitius.ugui.AngleField method value( (AngleField)self) -> Angle : returns the field's value value( (AngleField)self, (Angle)angle [, (bool)invoke_callback=False]) -> AngleField : Sets the value of the field and optionally invokes the activate callback Here is the summary of changes that I have. 1. added "PyTypeObject* converter::registration::expected_from_python_class_object() const" method used to find a python class that is convertible to a given parameter type 2 added type_info member to the signature_element to allow using the method of 1 3. added member template struct extract_return_type{ typename type; }; to every call policy class. for the default_call_policies class for example it is: template struct extract_return_type { typedef BOOST_DEDUCED_TYPENAME mpl::front::type type; }; but for return_arg it is: template struct extract_return_type{ typedef BOOST_DEDUCED_TYPENAME mpl::at_c::type type; }; 4. added to py_function: virtual python::detail::signature_element const& get_return_type() const {return signature()[0];} and overloaded it for the policy based py_functions 5. *HACK* made the lvalue_from_python_chain::convert(0) and rvalue_from_python_chain::convertible(0) to return PyTypeObject *( the python type they expect or 0) and used it in the implementation of 1 5 is dangerous because it will crash if someone registers lvalue_from_python_chain::convert and rvalue_from_python_chain::convertible directly with the expectation that the parameter is non zero a cleaner way would be to add another member to rvalue_from_python_chain and lvalue_from_python_chain to return their PyTypeObject expectation. 6. added a new class function_doc_signature_generator which uses 1-5 to generate python style signatures. Is there interest for this patch, and What is the best cvs diff format for submiting patch? Regards, Nikolay Mladenov Sitius Automation From roman.yakovenko at gmail.com Sat Jun 2 11:37:47 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 2 Jun 2007 11:37:47 +0200 Subject: [C++-sig] smart ptr In-Reply-To: <410D3A8B-F88B-4B39-89AD-6607BDC69A4A@gmail.com> References: <20070521131405.GA12892@dogbert.sdsl.sun.ac.za> <20070521140207.GC12892@dogbert.sdsl.sun.ac.za> <410D3A8B-F88B-4B39-89AD-6607BDC69A4A@gmail.com> Message-ID: <7465b6170706020237r2d33cb36ma0a316c676d8142c@mail.gmail.com> On 6/1/07, Sean Ross-Ross wrote: > I have a class that is similar to a smart_ptr, called RefCountPtr > and I have a c++ class constructor > > X::X( RefCountPtr< foo >& f ) : thisfoo(f) ; > > When I pass a Python 'foo' object into this constructor, I want to > wrap it in a c++ RefCountPtr class before passing it to the c++ > constructor. What if the instance of foo object is already managed by other RefCountPtr? > I have written an from_python extration method to do this > > > static void* extract_rcp(PyObject* o) > { > object boostobj = object(handle<>(borrowed( o )) ); > foo *counted = extract( boostobj ); > RefCountPtr< foo > *counter = new RefCountPtr< foo > > ( counted , true ); > return counter; > } > > When I extract the 'foo' object, I create a new RefCountPtr to pass > to the constructor, once the constructor finishes, I am left with a > reference count of 2: One for the new'd object and one for the data > member of the X class. > > > My question is, how can I get rid of the extra reference count? Is > there a call policy that will do this for me? I think the whole approach you are taking is erroneous. It is much better to let Boost.Python to manage such things. Take a look on "custom smart pointers" guide I wrote few month ago http://www.language-binding.net/pyplusplus/troubleshooting_guide/smart_ptrs/smart_ptrs.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 2 11:41:36 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 2 Jun 2007 11:41:36 +0200 Subject: [C++-sig] extract In-Reply-To: References: Message-ID: <7465b6170706020241h70248ef5yd4f009100cbb1565@mail.gmail.com> On 6/1/07, Sean Ross-Ross wrote: > hi, > How do I write multiple to_python conversions? > Say I have an boost::python::object and I call extract, > where the object could be a "c++ somthing class" or a Python dictionary I guess you should read "extract" documentation: http://boost.org/libs/python/doc/v2/extract.html boost::python::extract< something > ex( obj ); if( ex.check() ){ .... } else{ .... } I didn't try this for boost::python::dict class. If this will not work, you can always use "isinstance" functionality. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From sipickles at hotmail.com Sun Jun 3 20:35:23 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Sun, 03 Jun 2007 19:35:23 +0100 Subject: [C++-sig] using extract with embedded boost::python Message-ID: Hi, I am getting an error when I run example code like this: // Retrieve the main module. /* object main = import("__main__"); // Retrieve the main module's namespace object global(main.attr("__dict__")); // Define greet function in Python. object result = exec( "def greet(self): \n" " return 'Hello from Python!' \n", global, global); // Create a reference to it. object greet = global["greet"]; // Call it. std::string message = extract(greet()); It gives error_already_set, which I catch, but then it crashes on shutdown during garbage collection. The extract line is causing the crash. Strangely this works: object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); handle<> ignored((PyRun_String( "import myPython" ))); int five_squared = extract(main_namespace["result"]); g_log->Log( "%d\n", five_squared ); Can anyone demystify the difference to a boost:python newbie? Thanks Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ Could you be the guest MSN Movies presenter? Click Here to Audition http://www.lightscameraaudition.co.uk From sipickles at hotmail.com Sun Jun 3 20:52:48 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Sun, 03 Jun 2007 19:52:48 +0100 Subject: [C++-sig] using extract with embedded boost::python In-Reply-To: Message-ID: Sorry, A cut-n-paste error, the code which works is the boost example: object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); handle<> ignored((PyRun_String( "result = 5 ** 2" , Py_file_input , main_namespace.ptr() , main_namespace.ptr()) )); int five_squared = extract(main_namespace["result"]); ---------------------------------------------------------------- http://www.simonpickles.com --- http://www.squirtualreality.com >From: "Simon Pickles" >Reply-To: Development of Python/C++ integration >To: c++-sig at python.org >Subject: [C++-sig] using extract with embedded boost::python >Date: Sun, 03 Jun 2007 19:35:23 +0100 > > >Hi, > >I am getting an error when I run example code like this: > > // Retrieve the main module. >/* object main = import("__main__"); > > // Retrieve the main module's namespace > object global(main.attr("__dict__")); > > // Define greet function in Python. > object result = exec( > "def greet(self): \n" > " return 'Hello from Python!' \n", > global, global); > > // Create a reference to it. > object greet = global["greet"]; > > // Call it. > std::string message = extract(greet()); > >It gives error_already_set, which I catch, but then it crashes on shutdown >during garbage collection. The extract line is causing the crash. > >Strangely this works: > > object main_module(( > handle<>(borrowed(PyImport_AddModule("__main__"))))); > >object main_namespace = main_module.attr("__dict__"); > >handle<> ignored((PyRun_String( "import myPython" ))); > >int five_squared = extract(main_namespace["result"]); > >g_log->Log( "%d\n", five_squared ); > >Can anyone demystify the difference to a boost:python newbie? > >Thanks > >Simon > > >http://www.simonpickles.com --- http://www.squirtualreality.com > >_________________________________________________________________ >Could you be the guest MSN Movies presenter? Click Here to Audition >http://www.lightscameraaudition.co.uk > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Txt a lot? Get Messenger FREE on your mobile. https://livemessenger.mobile.uk.msn.com/ From gazihan at cse.wustl.edu Sun Jun 3 21:03:23 2007 From: gazihan at cse.wustl.edu (Gazihan Alankus) Date: Sun, 03 Jun 2007 14:03:23 -0500 Subject: [C++-sig] Boost.Python std::cerr segfault when built with -lGL References: <465771E7.2060104@sympatico.ca> <465DBED2.2040302@sympatico.ca> <465DC87A.6080604@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Gazihan Alankus wrote: > >> Thank you for your interest. If you don't get the same error, I can run >> any test programs, give you traces or if you prefer I can open up a user >> account for you in my laptop so that you can ssh in. > > I followed your suggested procedure, and everything seems to run fine. No > segfault. I would expect the problem to be somewhere deep down in system > libraries and the compiler (toolchain), not directly related to boost or > mesa. (Mesa, as a C library, doesn't even know about std::cerr...) I'm happy to inform everybody that I've solved this, *and* it was related to Mesa. Here is a short overview of what went down: When I dived into gcc's libstdc++-v3 code, I saw that operator<<() was using std::uncaught_exception() to see whether there is an uncought exception around, which was dereferencing what __cxxabiv1::__cxa_get_globals() returns, which was NULL when the library was linked against libGL.so. __cxxabiv1::__cxa_get_globals() had three cases depending on #define's which were all about threading. I didn't know which ones were active, but I pursued all and couldn't end up with anything better than a global variable's pointer being NULL, which didn't make much sense. Maybe it was an extern'ed global variable, but I'm not sure. This was where I stopped a couple of days ago. This morning I wanted to go deep in Mesa, and before I did luckily I saw that Mesa can be compiled with or without Native POSIX Thread Library (NPTL) support and my settings in Gentoo (use flags) included +nptl. I compiled Mesa without nptl support, and voila! cerr works perfectly fine in my Boost.Python library! I'm not sure who to blame:), but I suggest this should be looked into by Boost.Python and Mesa developers. For anyone currently experiencing this strange bug, the solution for the time being is to compile Mesa without NPTL support. -Gazi From seefeld at sympatico.ca Sun Jun 3 21:16:37 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 03 Jun 2007 15:16:37 -0400 Subject: [C++-sig] Boost.Python std::cerr segfault when built with -lGL In-Reply-To: References: <465771E7.2060104@sympatico.ca> <465DBED2.2040302@sympatico.ca> <465DC87A.6080604@sympatico.ca> Message-ID: <46631395.9040309@sympatico.ca> Gazihan Alankus wrote: > I'm not sure who to blame:), but I suggest this should be looked into by > Boost.Python and Mesa developers. For anyone currently experiencing this > strange bug, the solution for the time being is to compile Mesa without > NPTL support. Your description makes it sound as if the error should persist even if you take out all references to boost.python. This seems to be about compatibility between the different runtimes used by Mesa and libstdc++, i.e. in particular whether or not to compile with -pthread. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From seefeld at sympatico.ca Sun Jun 3 21:21:23 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 03 Jun 2007 15:21:23 -0400 Subject: [C++-sig] using extract with embedded boost::python In-Reply-To: References: Message-ID: <466314B3.2040300@sympatico.ca> Simon Pickles wrote: > Sorry, A cut-n-paste error, the code which works is the boost example: > > object main_module(( > handle<>(borrowed(PyImport_AddModule("__main__"))))); > > object main_namespace = main_module.attr("__dict__"); > > handle<> ignored((PyRun_String( > > "result = 5 ** 2" > > , Py_file_input > , main_namespace.ptr() > , main_namespace.ptr()) > )); > > int five_squared = extract(main_namespace["result"]); Please have a look at the tests that are part of the boost source distribution. Notably, libs/python/tests/exec.cpp contains functionality similar to the above, and is shown to work correctly on all tested platforms. Also, it would be good to figure out what (python) exception is raised (indicated by the exception_already_set in C++). You can query this using PyErr_Fetch(). (I'm hoping I will get around to wrap that and related functions in boost.python in time for boost 1.35.) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From gazihan at cse.wustl.edu Sun Jun 3 21:54:49 2007 From: gazihan at cse.wustl.edu (Gazihan Alankus) Date: Sun, 03 Jun 2007 14:54:49 -0500 Subject: [C++-sig] Boost.Python std::cerr segfault when built with -lGL References: <465771E7.2060104@sympatico.ca> <465DBED2.2040302@sympatico.ca> <465DC87A.6080604@sympatico.ca> <46631395.9040309@sympatico.ca> Message-ID: Stefan Seefeld wrote: > > Your description makes it sound as if the error should persist even if you > take out all references to boost.python. This seems to be about > compatibility between the different runtimes used by Mesa and libstdc++, > i.e. in particular whether or not to compile with -pthread. > You are right, I just proved that it's Python, not Boost.Python. Attached is a simple source extending Python without Boost.Python and that has the same problem with cerr. I guess since all C++ users use Boost.Python to extend, the other two people that saw this error were also using Boost.Python. Thanks for your help. -Gazi -------------- next part -------------- A non-text attachment was scrubbed... Name: ex.c Type: text/x-csrc Size: 572 bytes Desc: not available URL: From aljaz.fajmut at siol.net Mon Jun 4 01:43:13 2007 From: aljaz.fajmut at siol.net (Aljaz) Date: Mon, 4 Jun 2007 01:43:13 +0200 Subject: [C++-sig] question about timer Message-ID: Hello I have one boost::asio::deadline_timer object in my application.. Lets say I call/set it two times at once (the first time it expires after 6 seconds, and the second time after 10 seconds).. Now it will only expire after 10 seconds (because I have 'overwriten' the settings). In case that scenario happens, should I cancel the timer before setting it to new expire time or I can just set new timer values without calling cancel? Thanks for help Best regards A From seefeld at sympatico.ca Mon Jun 4 02:41:53 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 03 Jun 2007 20:41:53 -0400 Subject: [C++-sig] question about timer In-Reply-To: References: Message-ID: <46635FD1.2060601@sympatico.ca> Aljaz wrote: > Hello > > I have one boost::asio::deadline_timer object in my application.. Aljaz, I believe you are on the wrong mailing list for that question. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From littlesweetmelon at gmail.com Mon Jun 4 08:45:09 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Mon, 4 Jun 2007 14:45:09 +0800 Subject: [C++-sig] [c++-sig] How does C++ cooperate with python array? Message-ID: I'm sure it is a newbie question. ^_^ In my python program, it will generate a very big array stored in array.array. The data processing is time consuming. So I want to move it into C++, and return the result array back to python. Could you give me a related example by using Boost.Python library? It may like this: ============ # python code ar = array(...) ret = func(ar) # call a Boost.Python exported funtion which accepts a array.array parameter. ... # C++ code array func(array& ar) // just simple array.array, not numpy.array { ... //return array } BOOST_PYTHON_MODULE() {...} ============ Another concern is about the memory management. If I create a new array in C++ part, who will take charge of memory release? And, is there any implicit data-copying on the way that the array is passed between C++ and python? Due to the size of the array is very large, any unnecessary copy will lead to poor performance. Is there anything I should pay attention to when using Boost.Python? Thank you. -- ShenLei From sipickles at hotmail.com Mon Jun 4 15:27:28 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Mon, 04 Jun 2007 14:27:28 +0100 Subject: [C++-sig] using extract with embedded boost::python In-Reply-To: <466314B3.2040300@sympatico.ca> References: <466314B3.2040300@sympatico.ca> Message-ID: <46641340.70007@hotmail.com> Thanks Stefan. On consulting libs/python/tests/exec.cpp I got the extract to work, with simple data types, like int and std::string. How can I do the same for a function. I tried: // C++ python::dict global; python::object result = python::exec_file("myPython.py", global, global)l python::object greet = global["greet"]; std::string message = python::extract(greet()); // MYPYTHON.PY def greet(self): return "hello, world!" This gives an error. Its the example from the documentation. Then, can I also pass parameters? As for PyErr_Fetch, since I am not using a console application (win32), I don't know what to do with PyErr_Fetch or PyErr_Print! Sorry, not big on console apps! Keep up the good work! I'm loving what I see! Regards Simon Stefan Seefeld wrote: > Simon Pickles wrote: > >> Sorry, A cut-n-paste error, the code which works is the boost example: >> >> object main_module(( >> handle<>(borrowed(PyImport_AddModule("__main__"))))); >> >> object main_namespace = main_module.attr("__dict__"); >> >> handle<> ignored((PyRun_String( >> >> "result = 5 ** 2" >> >> , Py_file_input >> , main_namespace.ptr() >> , main_namespace.ptr()) >> )); >> >> int five_squared = extract(main_namespace["result"]); >> > > Please have a look at the tests that are part of the boost source distribution. > Notably, libs/python/tests/exec.cpp contains functionality similar to the above, > and is shown to work correctly on all tested platforms. > > Also, it would be good to figure out what (python) exception is raised (indicated > by the exception_already_set in C++). You can query this using PyErr_Fetch(). > (I'm hoping I will get around to wrap that and related functions in boost.python > in time for boost 1.35.) > > Regards, > Stefan > > -- http://www.simonpickles.com --- http://www.squirtualreality.com From seefeld at sympatico.ca Mon Jun 4 15:44:39 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 04 Jun 2007 09:44:39 -0400 Subject: [C++-sig] using extract with embedded boost::python In-Reply-To: <46641340.70007@hotmail.com> References: <466314B3.2040300@sympatico.ca> <46641340.70007@hotmail.com> Message-ID: <46641747.8070000@sympatico.ca> Simon Pickles wrote: > Thanks Stefan. > > On consulting libs/python/tests/exec.cpp I got the extract to work, with > simple data types, like int and std::string. > > How can I do the same for a function. I tried: > > // C++ > python::dict global; > python::object result = python::exec_file("myPython.py", global, global)l > > python::object greet = global["greet"]; > std::string message = python::extract(greet()); > > > // MYPYTHON.PY > def greet(self): > return "hello, world!" > > > This gives an error. Its the example from the documentation. What error ? I'm not exactly sure about the above: greet() returns a new object, and extract returns something (a proxy ?) which is implicitly convertible to a std::string. Is it possible that the lifetime of the object to be extracted from is slightly shorter than that of the proxy ? David ? Does it make a difference if you store the result of greet() in a local object and extract from that ? > Then, can I also pass parameters? pass to what ? The function call ? That's all covered in the tutorial / manual. > As for PyErr_Fetch, since I am not using a console application (win32), > I don't know what to do with PyErr_Fetch or PyErr_Print! Sorry, not big > on console apps! I don't quite understand the relation to "console app". If your platform doesn't have support for stdout / stderr, you surely have other means to display text. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From roman.yakovenko at gmail.com Mon Jun 4 20:12:53 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 4 Jun 2007 21:12:53 +0300 Subject: [C++-sig] [c++-sig] How does C++ cooperate with python array? In-Reply-To: References: Message-ID: <7465b6170706041112j65f338aancfb6400dd318cc5a@mail.gmail.com> On 6/4/07, ?? wrote: > I'm sure it is a newbie question. ^_^ > In my python program, it will generate a very big array stored in > array.array. It seems that this module doesn't provide C API. Is it possible to get access from C++ to the underlying array? > The data processing is time consuming. So I want to move > it into C++, and return the result array back to python. A new array or you want to reuse the array instance you pass as argument. > Could you give me a related example by using Boost.Python library? It > may like this: > ============ > # python code > ar = array(...) > ret = func(ar) # call a Boost.Python exported funtion which accepts a > array.array parameter. You will not find example that does exactly what you want. Boost.Python tutorials is a good place to start. You can always right something like this: boost::python::object func( boost::python::object ){ ... } def( "func", &::func ); > ... > > # C++ code > array func(array& ar) // just simple array.array, not numpy.array What do you mean simple array "int*" or instance of array.array type? > { > ... > //return array > } > > BOOST_PYTHON_MODULE() {...} > > ============ > Another concern is about the memory management. If I create a new > array in C++ part, who will take charge of memory release? It depends. If you will write the right code than Boost.Python, otherwise you( your users ) > And, is > there any implicit data-copying on the way that the array is passed > between C++ and python? You don't have to copy the whole array, but you should understand that you do construct new Python object every time you access an item within the array >Due to the size of the array is very large, > any unnecessary copy will lead to poor performance. > Is there anything I should pay attention to when using Boost.Python? Well it is possible to create clean solution, that will not force you copy arrays. May be you should consider to expose std::vector< your type > ( http://boost.org/libs/python/doc/v2/indexing.html#vector_indexing_suite ) and implement all interface using it. Thus you will have good performance and memory management. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From aljaz.fajmut at siol.net Mon Jun 4 20:14:35 2007 From: aljaz.fajmut at siol.net (Aljaz) Date: Mon, 4 Jun 2007 20:14:35 +0200 Subject: [C++-sig] question about timer References: <46635FD1.2060601@sympatico.ca> Message-ID: Thats right.. Sorry again, I posted on wrong list. "Stefan Seefeld" wrote in message news:46635FD1.2060601 at sympatico.ca... > Aljaz wrote: >> Hello >> >> I have one boost::asio::deadline_timer object in my application.. > > Aljaz, > > I believe you are on the wrong mailing list for that question. > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... From dave at boost-consulting.com Tue Jun 5 21:45:02 2007 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 05 Jun 2007 15:45:02 -0400 Subject: [C++-sig] Boost Python: Howto wrap "out" arguments of a methode References: Message-ID: <87k5uinq2p.fsf@grogan.peloton> on Mon Jun 04 2007, Alexander Eisenhuth wrote: > How to wrap methode Get with Boost.Python? First, I suggest you take your question to the C++-sig (http://www.boost.org/more/mailing_lists.htm#cplussig). > > class MyClass { > public: > MyClass(); > > void GetX(double &pos_x); > [...] > > > I'v tried it with: > > .def( > "GetX" > , &::MyClass::GetX > , bp::arg("") > , bp::return_value_policy() >() > > But when I try it in python: > > Boost.Python.ArgumentError: Python argument types in > MyClass.GetX(MyClass, int) > did not match C++ signature: > GetX(class MyClass::LedPosition_C {lvalue}, int {lvalue} ) > > Any ideas? return_value_policy is only good for telling Boost.Python how to handle the actual (non-void) return value of your C++ function. In your case, create a thin wrapper function: double GetX2(MyClass& self, double pos_x) { self.GetX(pos_x); return pos_x; } and wrap that instead of GetX: .def("GetX", GetX2) -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From gabriel.becedillas at corest.com Tue Jun 5 22:02:23 2007 From: gabriel.becedillas at corest.com (Gabriel Becedillas) Date: Tue, 05 Jun 2007 17:02:23 -0300 Subject: [C++-sig] boost::shared_ptr getting back from Python with a PyObject inside Message-ID: <4665C14F.3020208@corest.com> I have the following problem: 1_) A boost::shared_ptr is converted to python. 2_) The PyObject holding the boost::shared_ptr is converted back from python, (apparently) yielding the same boost::shared_ptr. 3_) The boost::shared_ptr hits refcount 0 somewhere else in C++Land without holding the Python GIL. 4_) Python's API gets called without holding the GIL because a sp_counted_impl_pd with a shared_ptr_deleter modifies the PyObject's refcount and Py_Dealloc gets called (check shared_ptr_deleter::operator()). This is wrong because you shouldn't use Python's API without holding the GIL. In my particular case I don't know when or where a boost::shared_ptr will hit refcount 0 (thats the funny part of using smart pointers). I took a look around and found that: 1_) shared_ptr_from_python is putting the shared_ptr_deleter. 2_) shared_ptr_to_python is checking if the boost::shared_ptr holds a shared_ptr_deleter to get the PyObject inside. Is there a way to make shared_ptr_from_python return the original boost::shared_ptr without changing the sp_counted_impl_pd/shared_ptr_deleter ? Thanks. From rwgk at yahoo.com Wed Jun 6 02:09:14 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 5 Jun 2007 17:09:14 -0700 (PDT) Subject: [C++-sig] Better introspection/apidoc extraction support? Message-ID: <682292.92957.qm@web31101.mail.mud.yahoo.com> > Would it make sense to just add two \n instead of one in > libs/python/src/object/function.cpp:510? I've just checked in a modified version of your patch (and the many required changes to the unit tests...). The changes are in the cvs head only. If you lobby the release manager for backporting to 1.34 I could easily do that, too. (But I'm not sure if this makes sense or not; I'm out of touch with the release plans.) Ralf ____________________________________________________________________________________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 -------------- next part -------------- An HTML attachment was scrubbed... URL: From newsuser at stacom-software.de Wed Jun 6 08:02:27 2007 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Wed, 06 Jun 2007 08:02:27 +0200 Subject: [C++-sig] Boost Python: Howto wrap "out" arguments of a methode In-Reply-To: <87k5uinq2p.fsf@grogan.peloton> References: <87k5uinq2p.fsf@grogan.peloton> Message-ID: David Abrahams schrieb: > on Mon Jun 04 2007, Alexander Eisenhuth wrote: > >> How to wrap methode Get with Boost.Python? > > First, I suggest you take your question to the C++-sig > (http://www.boost.org/more/mailing_lists.htm#cplussig). > > >> class MyClass { >> public: >> MyClass(); >> >> void GetX(double &pos_x); >> [...] >> >> >> I'v tried it with: >> >> .def( >> "GetX" >> , &::MyClass::GetX >> , bp::arg("") >> , bp::return_value_policy() >() >> >> But when I try it in python: >> >> Boost.Python.ArgumentError: Python argument types in >> MyClass.GetX(MyClass, int) >> did not match C++ signature: >> GetX(class MyClass::LedPosition_C {lvalue}, int {lvalue} ) >> >> Any ideas? > > return_value_policy is only good for telling Boost.Python how to > handle the actual (non-void) return value of your C++ function. In > your case, create a thin wrapper function: Ok, thanks for that hint. > > double GetX2(MyClass& self, double pos_x) > { self.GetX(pos_x); return pos_x; } > > and wrap that instead of GetX: > > .def("GetX", GetX2) > So boost.python doesn't have a mechanism to transform in the wrapper code a call by reference into return value? From meine at informatik.uni-hamburg.de Wed Jun 6 12:48:37 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Wed, 6 Jun 2007 12:48:37 +0200 Subject: [C++-sig] Better introspection/apidoc extraction support? In-Reply-To: <682292.92957.qm@web31101.mail.mud.yahoo.com> References: <682292.92957.qm@web31101.mail.mud.yahoo.com> Message-ID: <200706061248.37554.meine@informatik.uni-hamburg.de> Hi Ralf! Am Mittwoch, 06. Juni 2007 02:09:14 schrieb Ralf W. Grosse-Kunstleve: > > Would it make sense to just add two \n instead of one in > > libs/python/src/object/function.cpp:510? > > I've just checked in a modified version of your patch (and the many > required changes to the unit tests...). Thanks, nice. > The changes are in the cvs head > only. If you lobby the release manager for backporting to 1.34 I could > easily do that, too. (But I'm not sure if this makes sense or not; I'm out > of touch with the release plans.) AFAICS, the changes are quite trivial and should not be able to break anything, right? I would really like to see them in 1.34.0 then. Ciao, / / /--/ / / ANS From seefeld at sympatico.ca Wed Jun 6 13:37:19 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 06 Jun 2007 07:37:19 -0400 Subject: [C++-sig] Better introspection/apidoc extraction support? In-Reply-To: <200706061248.37554.meine@informatik.uni-hamburg.de> References: <682292.92957.qm@web31101.mail.mud.yahoo.com> <200706061248.37554.meine@informatik.uni-hamburg.de> Message-ID: <46669C6F.3050902@sympatico.ca> Hans Meine wrote: > AFAICS, the changes are quite trivial and should not be able to break > anything, right? I would really like to see them in 1.34.0 then. Then make sure Thomas is reading this. And point him at the patch so he can judge by himself. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From littlesweetmelon at gmail.com Wed Jun 6 14:17:34 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Wed, 6 Jun 2007 20:17:34 +0800 Subject: [C++-sig] [c++-sig] How does C++ cooperate with python array? In-Reply-To: <7465b6170706041112j65f338aancfb6400dd318cc5a@mail.gmail.com> References: <7465b6170706041112j65f338aancfb6400dd318cc5a@mail.gmail.com> Message-ID: Thank you very much. I went through the intro and manual document of boost.python. Now I can emerge C++ and python smoothly. -- ShenLei From littlesweetmelon at gmail.com Wed Jun 6 14:38:34 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Wed, 6 Jun 2007 20:38:34 +0800 Subject: [C++-sig] [c++-sig] How to raise a python exception in boost.python? Message-ID: I have read the python C API manual for exception handling. It seems that if the function below is called, python interpreter will get a ValueError exception, PyObject* RaiseValueError(PyObject*) { PyErr_SetString(PyExc_ValueError, "for some reason..."); return 0; } just like the statement in python: >>> raise ValueError("for some reason...") Is that right?? Ok, but if I move this function into boost.python, the exception disappeared. object RaiseValueError(object) { PyErr_SetString(PyExc_ValueError, "for some reason..."); return object(); } If I throw a C++ exception, later on the boundary of boost.python, it will be translated into a python exception: (in boost file errors.cpp) BOOST_PYTHON_DECL bool handle_exception_impl(function0 f) { try { if (detail::exception_handler::chain) return detail::exception_handler::chain->handle(f); f(); return false; } catch(const boost::python::error_already_set&) { // The python error reporting has already been handled. } catch(const std::bad_alloc&) { PyErr_NoMemory(); } catch(const bad_numeric_cast& x) { PyErr_SetString(PyExc_OverflowError, x.what()); } catch(const std::out_of_range& x) { PyErr_SetString(PyExc_IndexError, x.what()); } catch(const std::exception& x) { PyErr_SetString(PyExc_RuntimeError, x.what()); } catch(...) { PyErr_SetString(PyExc_RuntimeError, "unidentifiable C++ exception"); } return true; } So, I'm really confused. Why does NOT my calling to PyErr_SetString work, while boost.python similar calling works? Does boost.python eats my error flags? Anyway, my goal is the raise a python exception (eg: ValueError) from boost.python based code. How to do that? (Do not tell me to write a custom exception translator and plug it into boost.python... -_-!! The only thing I need is just to raise a python exception directly.) Thank you. --- ShenLei From littlesweetmelon at gmail.com Wed Jun 6 15:16:13 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Wed, 6 Jun 2007 21:16:13 +0800 Subject: [C++-sig] [c++-sig] How to raise a python exception in boost.python? In-Reply-To: References: Message-ID: 2007/6/6, ?? : > I have read the python C API manual for exception handling. It seems > that if the function below is called, python interpreter will get a > ValueError exception, > PyObject* RaiseValueError(PyObject*) > { > PyErr_SetString(PyExc_ValueError, "for some reason..."); > return 0; > } > just like the statement in python: > >>> raise ValueError("for some reason...") > Is that right?? > > Ok, but if I move this function into boost.python, the exception disappeared. > object RaiseValueError(object) > { > PyErr_SetString(PyExc_ValueError, "for some reason..."); > return object(); > } > > If I throw a C++ exception, later on the boundary of boost.python, it > will be translated into a python exception: (in boost file errors.cpp) > > BOOST_PYTHON_DECL bool handle_exception_impl(function0 f) > { > try > { > if (detail::exception_handler::chain) > return detail::exception_handler::chain->handle(f); > f(); > return false; > } > catch(const boost::python::error_already_set&) > { > // The python error reporting has already been handled. > } > catch(const std::bad_alloc&) > { > PyErr_NoMemory(); > } > catch(const bad_numeric_cast& x) > { > PyErr_SetString(PyExc_OverflowError, x.what()); > } > catch(const std::out_of_range& x) > { > PyErr_SetString(PyExc_IndexError, x.what()); > } > catch(const std::exception& x) > { > PyErr_SetString(PyExc_RuntimeError, x.what()); > } > catch(...) > { > PyErr_SetString(PyExc_RuntimeError, "unidentifiable C++ exception"); > } > return true; > } > > So, I'm really confused. Why does NOT my calling to PyErr_SetString > work, while boost.python similar calling works? Does boost.python eats > my error flags? > > Anyway, my goal is the raise a python exception (eg: ValueError) from > boost.python based code. How to do that? (Do not tell me to write a > custom exception translator and plug it into boost.python... -_-!! The > only thing I need is just to raise a python exception directly.) > > Thank you. > --- > ShenLei > Oh~~ I solved this problem by myself. I forgot to call throw_error_already_set() to tell boost.python that python error has occurred. Sorry for such newbie mistake. ^_^ --- ShenLei From mark at image-engine.com Wed Jun 6 22:35:26 2007 From: mark at image-engine.com (Mark Williams) Date: Wed, 06 Jun 2007 13:35:26 -0700 Subject: [C++-sig] Copying objects derived in python from C++? Message-ID: <46671A8E.4090301@image-engine.com> I have a short example below which demonstrates and issue I'm having. I have a base class, "Base", written in C++ and exposed via boost.python. I have class, "Derived", which is written in Python and derives from the C++ base. In addition, there is a simple C++ function "func" which takes a Base* as an argument. What I'd like to be able to do is take a copy of an instance of the derived class, within Python, and pass it into the C++ function. However, this yields an ArgumentError exception: Boost.Python.ArgumentError: Python argument types in MyModule.func(Derived) did not match C++ signature: func(boost::shared_ptr) So it would appear that in taking a copy of the instance using Python's "copy.copy", I'm losing the C++ portion of the object. What is the correct way to go about doing this, please? Here's the test case I'm using: ================ C++ ============ struct Base { Base(){} }; typedef boost::shared_ptr BasePtr; void func( BasePtr b ) { std::cerr << "func(" << b.get() << ")" << std::endl; } BOOST_PYTHON_MODULE(MyModule) { class_("Base", no_init) .def(init<>()) ; def("func", func); } ================ Python ============ import copy from MyModule import * class Derived(Base): pass b = Base() func(b) d = Derived() func(d) d_copy = copy.copy(d) func(d_copy) ============ Example output ============== func(0x9db3500) func(0x9d76b20) Traceback (most recent call last): File "test.py", line 15, in func(d_copy) Boost.Python.ArgumentError: Python argument types in MyModule.func(Derived) did not match C++ signature: func(boost::shared_ptr) Thanks in advance, Mark From rwgk at yahoo.com Thu Jun 7 01:57:37 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 6 Jun 2007 16:57:37 -0700 (PDT) Subject: [C++-sig] Copying objects derived in python from C++? Message-ID: <925166.39290.qm@web31104.mail.mud.yahoo.com> This could be connected to missing pickle support. I think copy.copy() essentially pickles/unpickles to make the copy. I'd think if you add pickle support to your class it will work. I'm not sure about the details. See the "pickle suite" docs (link on main Boost.Python page). Ralf ----- Original Message ---- From: Mark Williams To: c++-sig at python.org Sent: Wednesday, June 6, 2007 1:35:26 PM Subject: [C++-sig] Copying objects derived in python from C++? d_copy = copy.copy(d) func(d_copy) ____________________________________________________________________________________ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at image-engine.com Thu Jun 7 02:48:34 2007 From: mark at image-engine.com (Mark Williams) Date: Wed, 06 Jun 2007 17:48:34 -0700 Subject: [C++-sig] Copying objects derived in python from C++? In-Reply-To: <925166.39290.qm@web31104.mail.mud.yahoo.com> References: <925166.39290.qm@web31104.mail.mud.yahoo.com> Message-ID: <466755E2.5040507@image-engine.com> Ralf W. Grosse-Kunstleve wrote: > This could be connected to missing pickle support. I think copy.copy() > essentially pickles/unpickles to make the copy. > I'd think if you add pickle support to your class it will work. > I'm not sure about the details. See the "pickle suite" docs (link on > main Boost.Python page). > Ralf Thanks, this certainly seems to be the case. If I add ".enable_pickling()" to my Base class definition, then the example I posted works as expected. However, if I then modify the Derived class constructor so that it takes an argument, e.g.: class Derived(Base): def __init__(self, arg): Base.__init__(self) d = Derived(None) func(d) d_copy = copy.copy(d) func(d_copy) I get an error such as: Traceback (most recent call last): File "test.py", line 20, in d_copy = copy.copy(d) File "python2.5/copy.py", line 95, in copy return _reconstruct(x, rv, 0) File "python2.5/copy.py", line 322, in _reconstruct y = callable(*args) TypeError: __init__() takes exactly 2 arguments (1 given) Cheers, Mark From mharidev at qualcomm.com Thu Jun 7 04:11:51 2007 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Wed, 6 Jun 2007 19:11:51 -0700 Subject: [C++-sig] Py++ Error for function operator *() Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> Hi Roman, We've been using Py++ 0.8.5 for a while now and it has been working great. I'm in the process of upgrading to Py++ 0.9.0. I currently have the following installed: 1. Gccxml (cvs-snapshot June 5, 2007): There is some problem with the extraction of the tarball at https://sourceforge.net/project/showfiles.php?group_id=118209&package_id =146545, so I'm just using the latest from cvs. And I am positive that this is not the source of the problem I'm running into. 2. Pygccxml (0.9.0) 3. Py++ (0.9.0) ----------------------------------------------------------------------- When I moved from Py++ 0.8.5 to Py++ 0.9.0, Py++ fails for the following function declaration during the module_builder's build_code_creator() phase: operator * (const ACE_Time_Value &tv, double d) { //..... } Here's the Error message: self.moduleBuilder.build_code_creator(self.moduleName, create_casting_constructor=flag_casting_constr) File "/opt/data/BTBLD_rhine_1080/thirdParty/lib/python2.4/site-packages/pyplu splus/module_builder/builder.py", line 247, in build_code_creator self.__code_creator = creator.create() File "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus /module_creator/creator.py", line 315, in create self._adopt_free_operator( operator ) File "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus /module_creator/creator.py", line 185, in _adopt_free_operator assert isinstance( arg_type, declarations.declarated_t ) AssertionError ----------------------------------------------------------------------- I narrowed down the Error to this part of the code (Py++ 0.9.0) in function _adopt_free_operator() of pyplusplus/module_creator/creator.py(line 178): arg_type = declarations.base_type( operator.arguments[0].type ) if isinstance( arg_type, declarations.fundamental_t ): arg_type = declarations.base_type( operator.arguments[1].type ) elif isinstance( arg_type, declarations.declarated_t ) and arg_type.declaration.ignore: arg_type = declarations.base_type( operator.arguments[1].type ) else: pass assert isinstance( arg_type, declarations.declarated_t ) ----------------------------------------------------------------------- Note that I don't have this problem with the earlier version (Py++ 0.8.5) when the code looked like this and didn't have the extra check: arg_type = declarations.base_type( operator.arguments[0].type ) if isinstance( arg_type, declarations.fundamental_t ): arg_type = declarations.base_type( operator.arguments[1].type ) assert isinstance( arg_type, declarations.declarated_t ) ----------------------------------------------------------------------- Any ideas to how this can be fixed? Thanks for your help, -Meghana. From meine at informatik.uni-hamburg.de Thu Jun 7 09:58:50 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 7 Jun 2007 09:58:50 +0200 Subject: [C++-sig] Copying objects derived in python from C++? In-Reply-To: <466755E2.5040507@image-engine.com> References: <925166.39290.qm@web31104.mail.mud.yahoo.com> <466755E2.5040507@image-engine.com> Message-ID: <200706070958.50343.meine@informatik.uni-hamburg.de> Am Donnerstag, 07. Juni 2007 02:48:34 schrieb Mark Williams: > Thanks, this certainly seems to be the case. If I add > ".enable_pickling()" to my Base class definition, then the example I > posted works as expected. However, if I then modify the Derived class > constructor so that it takes an argument, e.g.: > > [...] > TypeError: __init__() takes exactly 2 arguments (1 given) How about adding pickle functions (i.e. __getinitargs__) to Derived, then? -- Ciao, / / /--/ / / ANS From hans_meine at gmx.net Thu Jun 7 10:03:12 2007 From: hans_meine at gmx.net (Hans Meine) Date: Thu, 7 Jun 2007 10:03:12 +0200 Subject: [C++-sig] Better introspection/apidoc extraction support? In-Reply-To: <46669C6F.3050902@sympatico.ca> References: <682292.92957.qm@web31101.mail.mud.yahoo.com> <200706061248.37554.meine@informatik.uni-hamburg.de> <46669C6F.3050902@sympatico.ca> Message-ID: <200706071003.12948.hans_meine@gmx.net> Am Mittwoch, 06. Juni 2007 13:37:19 schrieb Stefan Seefeld: > Hans Meine wrote: > > AFAICS, the changes are quite trivial and should not be able to break > > anything, right? I would really like to see them in 1.34.0 then. > > Then make sure Thomas is reading this. And point him at the patch so > he can judge by himself. Unfortunately, I recently unsubscribed from the boost list (severe lack of time), and even if I knew who exactly is the release coordinator, I do not have a boost checkout, and I would not want to give him my older patch which is apparently superceded by Ralf's work. Could someone else tell him, please? I would be grateful. Ciao, / / /--/ / / ANS From luca.sbardella at gmail.com Thu Jun 7 17:20:35 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Thu, 7 Jun 2007 17:20:35 +0200 Subject: [C++-sig] inheritance and polyphormism Message-ID: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> hi, How do I expose properly a class tree so that classes can be derived from python in a polymorphic way? I've approached the problem is the following way. class base { public: virtual void method1(){} }; class derived: public base { public: virtual void method2(){} }; I then wrote two class templates to wrap the classes in the following way template class base_wrap: public T, public boost::python::wrapper { void method1() {....} }; template class derived_wrap: public base_wrap { void method2() {....} }; And finally class_, boost::noncopyable>("base") .def("method1", &base::method1) ; class_, boost::noncopyable>("derived") .def("method1", &derived::method1) <======== this seems redundant .def("method2", &derived::method2) ; This works fine, however I does't seem to be the optimal solution (see the comment on class_>). Is there a better way? Thanks Luca -------------- next part -------------- An HTML attachment was scrubbed... URL: From meine at informatik.uni-hamburg.de Fri Jun 8 13:48:35 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 8 Jun 2007 13:48:35 +0200 Subject: [C++-sig] with_custodian_and_ward problem Message-ID: <200706081348.35589.meine@informatik.uni-hamburg.de> Hi! I have a typical call policies problem, which I believed to be solvable with with_custodian_and_ward, but I cannot get it to compile. (I am using make_constructor, maybe that is relevant?) I guess that I simply did not understand BPL's reference counting policies correctly.. I created a testcase (attached, too): This is my class which internally stores a reference to an object given to the constructor: > struct T > { > T(int &foo) : foo_(foo) {} > int &foo_; > }; > > int someInt; > > static T *createT() > { > return new T(someInt); > } I tried using this export code (and some others), which is obviously wrong: > class_("T", no_init) > .def("__init__", make_constructor( > &createT, > with_custodian_and_ward_postcall<0, 1>())); How can I properly tell BPL to make sure that the object passed to the constructor must not be deleted before the "T" instance? Ciao, / / /--/ / / ANS PS: I am currently using 1.34.0beta, does that matter? -------------- next part -------------- A non-text attachment was scrubbed... Name: caw_testcase2.cxx Type: text/x-c++src Size: 491 bytes Desc: not available URL: From meine at informatik.uni-hamburg.de Fri Jun 8 17:06:36 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 8 Jun 2007 17:06:36 +0200 Subject: [C++-sig] How about class_<...>.enable_copy() ? Message-ID: <200706081706.37240.meine@informatik.uni-hamburg.de> Hi! I often use copy.[deep]copy() to copy python objects / BPL-exported types. This works if pickling support has been explicitly coded, by pickling and unpickling. It would be neat if there was an .enable_copy() or sth. like that, which would define a __copy__ (or __deepcopy__) method that simply calls the copy constructor. That would be more efficient than the pickling approach, both at runtime and in terms of saved LOCs. Have you thought about such a thing? Is there a common short idiom that does that already? Is there a rationale for not providing copying support? -- Ciao, / / /--/ / / ANS From meine at informatik.uni-hamburg.de Fri Jun 8 17:17:08 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 8 Jun 2007 17:17:08 +0200 Subject: [C++-sig] How about class_<...>.enable_copy() ? In-Reply-To: <200706081706.37240.meine@informatik.uni-hamburg.de> References: <200706081706.37240.meine@informatik.uni-hamburg.de> Message-ID: <200706081717.09112.meine@informatik.uni-hamburg.de> Hi again! Am Freitag, 08. Juni 2007 17:06:36 schrieb Hans Meine: > I often use copy.[deep]copy() to copy python objects / BPL-exported types. > This works if pickling support has been explicitly coded, by pickling and > unpickling. Oh, and BTW, there is a related thing that bugs me: When I copy.copy() a BPL exported type with pickling support and __getstate_manages_dict__ set, I get two objects with *the same* __dict__: In [15]: cm.__dict__ Out[15]: {} In [16]: cm2 = copy.copy(cm) In [17]: cm.foo = 42 In [18]: cm2.foo Out[18]: 42 That looks like a bug to me, and pickle3.cpp also does not copy the __dict__. Oh, but it uses update().. maybe that should be put into the docs. From pickle3.cpp: > // restore the object's __dict__ > dict d = extract(w_obj.attr("__dict__"))(); > d.update(state[0]); I suggest to add a sentence in the "Practical Advice" section: > If __getstate__ is required, include the instance's __dict__ in the Python > object that is returned**BEGIN**, and use the dict to update() your > __dict__ in __setstate__**END**. Also, above it says: > To resolve this problem, it should first be established that the > __getstate__ and __setstate__ methods manage the instances's __dict__ > correctly. without defining "correctly". ;-) -- Ciao, / / /--/ / / ANS From mark at image-engine.com Fri Jun 8 19:04:44 2007 From: mark at image-engine.com (Mark Williams) Date: Fri, 08 Jun 2007 10:04:44 -0700 Subject: [C++-sig] Copying objects derived in python from C++? In-Reply-To: <200706070958.50343.meine@informatik.uni-hamburg.de> References: <925166.39290.qm@web31104.mail.mud.yahoo.com> <466755E2.5040507@image-engine.com> <200706070958.50343.meine@informatik.uni-hamburg.de> Message-ID: <46698C2C.8060306@image-engine.com> Hans Meine wrote: > Am Donnerstag, 07. Juni 2007 02:48:34 schrieb Mark Williams: > >> Thanks, this certainly seems to be the case. If I add >> ".enable_pickling()" to my Base class definition, then the example I >> posted works as expected. However, if I then modify the Derived class >> constructor so that it takes an argument, e.g.: >> >> [...] >> TypeError: __init__() takes exactly 2 arguments (1 given) >> > > How about adding pickle functions (i.e. __getinitargs__) to Derived, then? > > Thanks. That was the missing step. Mark From rwgk at yahoo.com Fri Jun 8 20:39:52 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 8 Jun 2007 11:39:52 -0700 (PDT) Subject: [C++-sig] How about class_<...>.enable_copy() ? Message-ID: <10049.42978.qm@web31104.mail.mud.yahoo.com> > Oh, and BTW, there is a related thing that bugs me: When I copy.copy() a BPL > exported type with pickling support and __getstate_manages_dict__ set, I get > two objects with *the same* __dict__: Sorry, I didn't foresee this situation. But copying the dict would only push the problem one level down. A deepcopy of the dict could be expensive. Given that you can easily wrap the copy constructor, do you think this needs further attention? If you send me documentation patches I'll review them and check them in. Ralf ____________________________________________________________________________________ Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. http://answers.yahoo.com/dir/?link=list&sid=396545433 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Fri Jun 8 20:35:30 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 8 Jun 2007 11:35:30 -0700 (PDT) Subject: [C++-sig] How about class_<...>.enable_copy() ? Message-ID: <939641.51079.qm@web31114.mail.mud.yahoo.com> > Is there a common short idiom that does that already? Is > there a rationale for not providing copying support? Simply wrap the copy constructor with .def(init<>), e.g.: .def(init((arg("other")))) Ralf ____________________________________________________________________________________ Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From sipickles at hotmail.com Fri Jun 8 20:59:26 2007 From: sipickles at hotmail.com (Simon Pickles) Date: Fri, 08 Jun 2007 19:59:26 +0100 Subject: [C++-sig] Calling a Python function with parameters Message-ID: Hello, I've now managed to load a python module using boost::python::exec_file() I can extract variables and run functions from C++ too. But I am stumped on how to pass parameters from C++ to a python function. Not much use without that! I'm using boost::python::extract(global["pyFunc"]) to run the function, where the python module may be: ##------------------------ def func1(): return "hello from python" pyFunc = func1() ##----------------------------------- The docs don't seem to elaborate on how to add parameters. There is plenty on calling C++ functions from python...... What I want to do is something like this: // C++ answer = extract(global["pyFunc(""hi"", ""there"" )"] ## python def pyFunc( str1, str2 ): return str1+str2 Thanks for putting up with a newbie! Simon http://www.simonpickles.com --- http://www.squirtualreality.com _________________________________________________________________ Get a preview of Live Earth, the hottest event this summer - only on MSN http://liveearth.msn.com?source=msntaglineliveearthhm From tbrooks.mail at gmail.com Sat Jun 9 02:43:27 2007 From: tbrooks.mail at gmail.com (Tom Brooks) Date: Fri, 8 Jun 2007 20:43:27 -0400 Subject: [C++-sig] Emails to this SIG are not being accepted Message-ID: I've been trying to ask a question on this SIG for a bit now. Every time I try it, I get an error message! I was wondering if it had to do with it having an attachment (2.7mb, .zip file, no .exes inside)? I tried using a new email and subscription. No luck! Here's the error message: This is an automatically generated Delivery Status Notification Delivery to the following recipient failed permanently: c++-sig at python.org Technical details of permanent failure: PERM_FAILURE: SMTP Error (state 16): 554 permanent error Any thoughts? I'm just hoping that *this* email goes through. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Jun 9 18:59:06 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 9 Jun 2007 19:59:06 +0300 Subject: [C++-sig] Py++ Error for function operator *() In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> Message-ID: <7465b6170706090959n397fc411i3cd6257b415bdf7f@mail.gmail.com> On 6/7/07, Haridev, Meghana wrote: > Hi Roman, Hi, sorry for late response I was on vacation. I will try to understand what is going on and will let you know when fix is available. I hope I will have it in next few days. > We've been using Py++ 0.8.5 for a while now and it has been working > great. I'm in the process of upgrading to Py++ 0.9.0. > > I currently have the following installed: > 1. Gccxml (cvs-snapshot June 5, 2007): There is some problem with the > extraction of the tarball at > https://sourceforge.net/project/showfiles.php?group_id=118209&package_id > =146545, so I'm just using the latest from cvs. And I am positive that > this is not the source of the problem I'm running into. > 2. Pygccxml (0.9.0) > 3. Py++ (0.9.0) > > ----------------------------------------------------------------------- > When I moved from Py++ 0.8.5 to Py++ 0.9.0, Py++ fails for the following > function declaration during the module_builder's build_code_creator() > phase: > > operator * (const ACE_Time_Value &tv, double d) > { > //..... > } > > Here's the Error message: > > self.moduleBuilder.build_code_creator(self.moduleName, > create_casting_constructor=flag_casting_constr) > File > "/opt/data/BTBLD_rhine_1080/thirdParty/lib/python2.4/site-packages/pyplu > splus/module_builder/builder.py", line 247, in build_code_creator > self.__code_creator = creator.create() > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 315, in create > self._adopt_free_operator( operator ) > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 185, in _adopt_free_operator > assert isinstance( arg_type, declarations.declarated_t ) > AssertionError > > ----------------------------------------------------------------------- > I narrowed down the Error to this part of the code (Py++ 0.9.0) in > function _adopt_free_operator() of > pyplusplus/module_creator/creator.py(line 178): > > arg_type = declarations.base_type( operator.arguments[0].type ) > if isinstance( arg_type, declarations.fundamental_t ): > arg_type = declarations.base_type( operator.arguments[1].type ) > elif isinstance( arg_type, declarations.declarated_t ) and > > arg_type.declaration.ignore: > arg_type = declarations.base_type( operator.arguments[1].type ) > else: > pass > assert isinstance( arg_type, declarations.declarated_t ) > > ----------------------------------------------------------------------- > > Note that I don't have this problem with the earlier version (Py++ > 0.8.5) when the code looked like this and didn't have the extra check: > > arg_type = declarations.base_type( operator.arguments[0].type ) > if isinstance( arg_type, declarations.fundamental_t ): > arg_type = declarations.base_type( operator.arguments[1].type ) > assert isinstance( arg_type, declarations.declarated_t ) > > ----------------------------------------------------------------------- > > Any ideas to how this can be fixed? > > Thanks for your help, > -Meghana. > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 9 19:28:29 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 9 Jun 2007 20:28:29 +0300 Subject: [C++-sig] boost::shared_ptr getting back from Python with a PyObject inside In-Reply-To: <4665C14F.3020208@corest.com> References: <4665C14F.3020208@corest.com> Message-ID: <7465b6170706091028g150e4b96x4668d5efa23fc2ed@mail.gmail.com> On 6/5/07, Gabriel Becedillas wrote: > I have the following problem: > 1_) A boost::shared_ptr is converted to python. > 2_) The PyObject holding the boost::shared_ptr is converted back from > python, (apparently) yielding the same boost::shared_ptr. > 3_) The boost::shared_ptr hits refcount 0 somewhere else in C++Land > without holding the Python GIL. > 4_) Python's API gets called without holding the GIL because a > sp_counted_impl_pd with a shared_ptr_deleter modifies the PyObject's > refcount and Py_Dealloc gets called (check shared_ptr_deleter::operator()). > > This is wrong because you shouldn't use Python's API without holding the > GIL. Did you read this FAQ: http://boost.org/libs/python/doc/v2/faq.html#threadsupport? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 9 19:45:01 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 9 Jun 2007 20:45:01 +0300 Subject: [C++-sig] inheritance and polyphormism In-Reply-To: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> References: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> Message-ID: <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> On 6/7/07, Luca Sbardella wrote: > hi, > How do I expose properly a class tree so that classes can be derived from > python in a polymorphic way? > I've approached the problem is the following way. > > class base { > public: > virtual void method1(){} > }; > > class derived: public base { > public: > virtual void method2(){} > }; > > I then wrote two class templates to wrap the classes in the following way > > template > class base_wrap: public T, public boost::python::wrapper { > void method1() {....} > }; > > template > class derived_wrap: public base_wrap { > void method2() {....} > }; > > And finally > > class_, boost::noncopyable>("base") > .def("method1", &base::method1) > ; > > class_, boost::noncopyable>("derived") > .def("method1", &derived::method1) <======== this > seems redundant > .def("method2", &derived::method2) > ; > > This works fine, however I does't seem to be the optimal solution (see the > comment on class_>). > Is there a better way? Check this: http://boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.inheritance -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 9 19:56:10 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 9 Jun 2007 20:56:10 +0300 Subject: [C++-sig] with_custodian_and_ward problem In-Reply-To: <200706081348.35589.meine@informatik.uni-hamburg.de> References: <200706081348.35589.meine@informatik.uni-hamburg.de> Message-ID: <7465b6170706091056r3595611bs2631ecf798fb65d1@mail.gmail.com> On 6/8/07, Hans Meine wrote: > Hi! > > I have a typical call policies problem, which I believed to be solvable with > with_custodian_and_ward, but I cannot get it to compile. (I am using > make_constructor, maybe that is relevant?) I guess that I simply did not > understand BPL's reference counting policies correctly.. > > I created a testcase (attached, too): > > This is my class which internally stores a reference to an object given to the > constructor: > > struct T > > { > > T(int &foo) : foo_(foo) {} > > int &foo_; > > }; The constructor takes immutable type( int ) by reference. You cannot directly expose this constructor. > > int someInt; > > > > static T *createT() > > { > > return new T(someInt); > > } > > I tried using this export code (and some others), which is obviously wrong: > > class_("T", no_init) > > .def("__init__", make_constructor( > > &createT, > > with_custodian_and_ward_postcall<0, 1>())); > > How can I properly tell BPL to make sure that the object passed to the > constructor must not be deleted before the "T" instance? In the example you gave you didn't pass any argument to "createT" function. > > PS: I am currently using 1.34.0beta, does that matter? I don't think so -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Jun 9 20:01:29 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 9 Jun 2007 21:01:29 +0300 Subject: [C++-sig] Calling a Python function with parameters In-Reply-To: References: Message-ID: <7465b6170706091101o62130e47k3958fee1187dc56b@mail.gmail.com> On 6/8/07, Simon Pickles wrote: > Hello, > > I've now managed to load a python module using boost::python::exec_file() > > I can extract variables and run functions from C++ too. > > But I am stumped on how to pass parameters from C++ to a python function. > Not much use without that! > > I'm using boost::python::extract(global["pyFunc"]) to run the > function, where the python module may be: > > ##------------------------ > def func1(): > return "hello from python" > > pyFunc = func1() > ##----------------------------------- > > > The docs don't seem to elaborate on how to add parameters. There is plenty > on calling C++ functions from python...... > > What I want to do is something like this: > > // C++ > answer = extract(global["pyFunc(""hi"", ""there"" )"] > > ## python > def pyFunc( str1, str2 ): > return str1+str2 > > Thanks for putting up with a newbie! I guess this is what your are looking for: http://boost.org/libs/python/doc/v2/call.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From hans_meine at gmx.net Sat Jun 9 21:13:45 2007 From: hans_meine at gmx.net (Hans Meine) Date: Sat, 9 Jun 2007 21:13:45 +0200 Subject: [C++-sig] with_custodian_and_ward problem In-Reply-To: <7465b6170706091056r3595611bs2631ecf798fb65d1@mail.gmail.com> References: <200706081348.35589.meine@informatik.uni-hamburg.de> <7465b6170706091056r3595611bs2631ecf798fb65d1@mail.gmail.com> Message-ID: <200706092113.47042.hans_meine@gmx.net> Hi Roman, thanks for looking at my problem. On Samstag 09 Juni 2007, Roman Yakovenko wrote: > > I created a testcase (attached, too): > > > > This is my class which internally stores a reference to an object given > > to the > > > > constructor: > > > struct T > > > { > > > T(int &foo) : foo_(foo) {} > > > int &foo_; > > > }; > > The constructor takes immutable type( int ) by reference. You cannot > directly expose this constructor. Argh. OK. That's an artifact caused be /me trying to strip everything down as much as possible (in the original, complext classes and rvalue converters were involved). Just imagine I had used my own class. > > > int someInt; > > > > > > static T *createT() > > > { > > > return new T(someInt); > > > } > > > > [...] > > > class_("T", no_init) > > > .def("__init__", make_constructor( > > > &createT, > > > with_custodian_and_ward_postcall<0, 1>())); > > > > How can I properly tell BPL to make sure that the object passed to the > > constructor must not be deleted before the "T" instance? > > In the example you gave you didn't pass any argument to "createT" function. Oh, right. Again, I messed up the testcase. I hope I did better this time, see attachment. Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: caw_testcase2.cxx Type: text/x-c++src Size: 602 bytes Desc: not available URL: From hans_meine at gmx.net Sat Jun 9 21:15:15 2007 From: hans_meine at gmx.net (Hans Meine) Date: Sat, 9 Jun 2007 21:15:15 +0200 Subject: [C++-sig] Emails to this SIG are not being accepted In-Reply-To: References: Message-ID: <200706092115.24020.hans_meine@gmx.net> Hi Tom! On Samstag 09 Juni 2007, Tom Brooks wrote: > I've been trying to ask a question on this SIG for a bit now. Every time I > try it, I get an error message! I was wondering if it had to do with it > having an attachment (2.7mb, .zip file, no .exes inside)? I tried using a > new email and subscription. No luck! Here's the error message: Certainly you should not post such "monster" files to *any* mailing list. Just have a look for some free file hoster and post a link here. -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: From roman.yakovenko at gmail.com Sun Jun 10 09:50:03 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 10 Jun 2007 10:50:03 +0300 Subject: [C++-sig] with_custodian_and_ward problem In-Reply-To: <200706092113.47042.hans_meine@gmx.net> References: <200706081348.35589.meine@informatik.uni-hamburg.de> <7465b6170706091056r3595611bs2631ecf798fb65d1@mail.gmail.com> <200706092113.47042.hans_meine@gmx.net> Message-ID: <7465b6170706100050me4fa1f0r77cfed1c12881216@mail.gmail.com> On 6/9/07, Hans Meine wrote: > Hi Roman, > > thanks for looking at my problem. > > On Samstag 09 Juni 2007, Roman Yakovenko wrote: > > > I created a testcase (attached, too): > > > > > > This is my class which internally stores a reference to an object given > > > to the > > > > > > constructor: > > > > struct T > > > > { > > > > T(int &foo) : foo_(foo) {} > > > > int &foo_; > > > > }; > > > > The constructor takes immutable type( int ) by reference. You cannot > > directly expose this constructor. > > Argh. OK. That's an artifact caused be /me trying to strip everything down > as much as possible (in the original, complext classes and rvalue converters > were involved). Just imagine I had used my own class. > > > > > int someInt; > > > > > > > > static T *createT() > > > > { > > > > return new T(someInt); > > > > } > > > > > > [...] > > > > class_("T", no_init) > > > > .def("__init__", make_constructor( > > > > &createT, > > > > with_custodian_and_ward_postcall<0, 1>())); > > > > > > How can I properly tell BPL to make sure that the object passed to the > > > constructor must not be deleted before the "T" instance? > > > > In the example you gave you didn't pass any argument to "createT" function. > > Oh, right. Again, I messed up the testcase. I hope I did better this time, > see attachment. I guess you should put call policies on "def" and not on "make_constructor". I didn't test this: .def("__init__" , make_constructor( &createT ) , with_custodian_and_ward_postcall<0, 1>() ); -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From tbrooks.mail at gmail.com Sun Jun 10 13:33:53 2007 From: tbrooks.mail at gmail.com (Tom Brooks) Date: Sun, 10 Jun 2007 07:33:53 -0400 Subject: [C++-sig] Emails to this SIG are not being accepted Message-ID: > > Hi Tom! > > On Samstag 09 Juni 2007, Tom Brooks wrote: > > I've been trying to ask a question on this SIG for a bit now. Every time > I > > try it, I get an error message! I was wondering if it had to do with it > > having an attachment (2.7mb, .zip file, no .exes inside)? I tried using > a > > new email and subscription. No luck! Here's the error message: > > Certainly you should not post such "monster" files to *any* mailing list. > Just have a look for some free file hoster and post a link here. Hehe, Good point. I'm kinda new to mailing lists, so I forgot that it gets emailed to *everyone*. I'll host it separately next time. I happen to have resolved the issue I was going to ask about, so it's not necessary right now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sun Jun 10 22:03:51 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 10 Jun 2007 23:03:51 +0300 Subject: [C++-sig] Py++ Error for function operator *() In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> Message-ID: <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> On 6/7/07, Haridev, Meghana wrote: > When I moved from Py++ 0.8.5 to Py++ 0.9.0, Py++ fails for the following > function declaration during the module_builder's build_code_creator() > phase: > > operator * (const ACE_Time_Value &tv, double d) > { > //..... > } > > Here's the Error message: > > self.moduleBuilder.build_code_creator(self.moduleName, > create_casting_constructor=flag_casting_constr) > File > "/opt/data/BTBLD_rhine_1080/thirdParty/lib/python2.4/site-packages/pyplu > splus/module_builder/builder.py", line 247, in build_code_creator > self.__code_creator = creator.create() > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 315, in create > self._adopt_free_operator( operator ) > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 185, in _adopt_free_operator > assert isinstance( arg_type, declarations.declarated_t ) > AssertionError Hi. I tried to reproduce the bug, but failed. Here is the link to test case: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/free_operators_to_be_exported.hpp?revision=1051&view=markup I am testing the current version, but it is not that different from the 0.9.0. Can you modify the test to reproduce the bug? If not you can send me privately gccxml generated file and the Py++ script. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From littlesweetmelon at gmail.com Mon Jun 11 09:41:31 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Mon, 11 Jun 2007 15:41:31 +0800 Subject: [C++-sig] [c++-sig] Is it a BUG? boost.python makes doctest impossible to recursive test. Message-ID: Today, I encounter a tough problem about using doctest in class exposed by boost.python. For traditional python class which is define in python: class P: """ >>> .... # this line will be tested by doctest """ def func(self): """ >>>... # this line will be tested by doctest by recursively discovering __doc__ """ pass However, if I expose the same class by boost.python, class C { public: void func() {} }; char* doc_str[] = { // __doc__ for class ">>>...", // this line will be tested by doctest // __doc__ for func ">>>..." // this line will NOT be tested by doctest }; BOOST_PYTHON_MODULE(...) { class_("C", doc_str[0], init<>()) .def("func", &C::func, doc_str[1]); } In above case, doctest can only discover the __doc__ for class, but can NOT go further to discover __doc__ for method. I throughly studied the reason, and found the problem is: In doctest.py class DocTestFinder: def _find(self, tests, obj, name, module, source_lines, globs, seen): ..... # Look for tests in a class's contained objects. if inspect.isclass(obj) and self._recurse: for valname, val in obj.__dict__.items(): ..... # Recurse to methods, properties, and nested classes. BUT IT FAILS. if ((inspect.isfunction(val) or inspect.isclass(val) or isinstance(val, property)) and self._from_module(module, val)): .... inspect.isfunction(val) ALWAYS returns False, because the type of 'val' corresponding to 'func' in class C is: while for class P, the type of 'val' is , which will get True. Therefore, the strange type of the class' method exposed by boost.python suppresses the doctest to recursively discover __doc__. What should I do? Is is a bug for boost.python? Thank you --- ShenLei From meine at informatik.uni-hamburg.de Mon Jun 11 10:55:59 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 11 Jun 2007 10:55:59 +0200 Subject: [C++-sig] [c++-sig] Is it a BUG? boost.python makes doctest impossible to recursive test. In-Reply-To: References: Message-ID: <200706111055.59345.meine@informatik.uni-hamburg.de> Hi ??! You wrote: > inspect.isfunction(val) ALWAYS returns False, because the type of > 'val' corresponding to 'func' in class C is: > Here, I am getting , with MRO [, ]. > Therefore, the strange type of the class' method exposed by > boost.python suppresses the doctest to recursively discover __doc__. > What should I do? Is is a bug for boost.python? This relates to my recent postings on BPL and epydoc ("Better introspection/apidoc extraction support?" thread). It would be really cool if the inspect module could be enhanced to work with boost::python. AFAICS, for much functionality it would be needed to enhance boost::python, since much information is not even available. For example, the signature of functions is not available - now there is a string representation in the docstrings (only not disabled), but it is impossible to parse in general, since values of default arguments can have any string representation. A contrived example would be an object o with repr(o) == "1, foo = 23" which makes the parser believe that there's another argument, but there are many real-world cases where the repr() output does not allow creating an identical object, or not even recognizing the type. In your case, I see two solutions: Enhancing the 'inspect' module to recognize boost::python functions or make BPL methods be instances of the right type. But wait.. the latter already seems to be the case with 1.34.0beta: is types.MethodType! Consequently, inspect.ismethod() returns True, but inspect.isfunction() returns False. However, I am getting for free functions (I thought your example was about the method C.func?): In [11]: type(norm) Out[11]: In [12]: _.mro() Out[12]: [, ] Maybe Boost.Python.function could be derived from types.FunctionType? (Probably not, otherwise it would have been done already.) BTW: A good example for deriving from python types is numpy: In [16]: numpy.float64.mro() Out[16]: [, , , , , , ] Ciao, / / /--/ / / ANS From luca.sbardella at gmail.com Mon Jun 11 13:05:21 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Mon, 11 Jun 2007 13:05:21 +0200 Subject: [C++-sig] inheritance and polyphormism In-Reply-To: <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> References: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> Message-ID: <8315652a0706110405y65582570g64e560824301ca45@mail.gmail.com> The link doesn't answer the question, or at least I do not see the answer. At first, I though that using the following approach would work class derived_wrap: public derived, public boost::python::wrapper { void method2() {....} }; class_>("derived") .def("method2", &derived::method2) ; However in doing so the "method1" of the base class does not behave as expected. That is to say, if in Python I do the following class A(derived): def method1(self): ...... and I pass A class back to C++, the method1 has not been overwritten!!! method2 on the other hand works as expected. Best Luca On 09/06/07, Roman Yakovenko wrote: > > On 6/7/07, Luca Sbardella wrote: > > hi, > > How do I expose properly a class tree so that classes can be derived > from > > python in a polymorphic way? > > I've approached the problem is the following way. > > > > class base { > > public: > > virtual void method1(){} > > }; > > > > class derived: public base { > > public: > > virtual void method2(){} > > }; > > > > I then wrote two class templates to wrap the classes in the following > way > > > > template > > class base_wrap: public T, public boost::python::wrapper { > > void method1() {....} > > }; > > > > template > > class derived_wrap: public base_wrap { > > void method2() {....} > > }; > > > > And finally > > > > class_, boost::noncopyable>("base") > > .def("method1", &base::method1) > > ; > > > > class_, boost::noncopyable>("derived") > > .def("method1", &derived::method1) <======== > this > > seems redundant > > .def("method2", &derived::method2) > > ; > > > > This works fine, however I does't seem to be the optimal solution (see > the > > comment on class_>). > > Is there a better way? > > Check this: > > http://boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html#python.inheritance > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Mon Jun 11 13:20:57 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 11 Jun 2007 14:20:57 +0300 Subject: [C++-sig] inheritance and polyphormism In-Reply-To: <8315652a0706110405y65582570g64e560824301ca45@mail.gmail.com> References: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> <8315652a0706110405y65582570g64e560824301ca45@mail.gmail.com> Message-ID: <7465b6170706110420y1653d6afg69b169b81f14aa23@mail.gmail.com> On 6/11/07, Luca Sbardella wrote: > The link doesn't answer the question, or at least I do not see the answer. > > At first, I though that using the following approach would work > > > class derived_wrap: public derived, public > boost::python::wrapper { > void method2() {....} > }; You can derive from boost::python::wrapper< base > class too. I think this will do what you want. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From luca.sbardella at gmail.com Mon Jun 11 13:58:46 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Mon, 11 Jun 2007 13:58:46 +0200 Subject: [C++-sig] inheritance and polyphormism In-Reply-To: <7465b6170706110420y1653d6afg69b169b81f14aa23@mail.gmail.com> References: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> <8315652a0706110405y65582570g64e560824301ca45@mail.gmail.com> <7465b6170706110420y1653d6afg69b169b81f14aa23@mail.gmail.com> Message-ID: <8315652a0706110458i385d58fbja72fda2eb6e5d59e@mail.gmail.com> If you mean doing class derived_wrap: public derived, public boost::python::wrapper, public boost::python::wrapper { void method2() {....} }; This doesn't compile. It throw the error ambiguous access of 'get_override' inside the function method2(). I guess it creates a confusion to which class to overwrite (just a guess!!). Luca On 11/06/07, Roman Yakovenko wrote: > > On 6/11/07, Luca Sbardella wrote: > > The link doesn't answer the question, or at least I do not see the > answer. > > > > At first, I though that using the following approach would work > > > > > > class derived_wrap: public derived, public > > boost::python::wrapper { > > void method2() {....} > > }; > > You can derive from boost::python::wrapper< base > class too. I think > this will do what you want. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From littlesweetmelon at gmail.com Mon Jun 11 14:17:37 2007 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Mon, 11 Jun 2007 20:17:37 +0800 Subject: [C++-sig] [c++-sig] Is it a BUG? boost.python makes doctest impossible to recursive test. In-Reply-To: <200706111055.59345.meine@informatik.uni-hamburg.de> References: <200706111055.59345.meine@informatik.uni-hamburg.de> Message-ID: Thank you for your kind reply. I agree with you for extending inspect module to cooperate with boost.python. > However, I am getting for free > functions (I thought your example was about the method C.func?): > > In [11]: type(norm) > Out[11]: Well, your result is true, but, in my case, I didn't invoke isfunction or ismethod on C.func. Indeed, ismethod(C.func) will return true. But inspect module use 'isfunction' to determine whether go recursively. if ((inspect.isfunction(val) or inspect.isclass(val) or isinstance(val, property)) and self._from_module(module, val)): ..... Here the val comes from C.__dict__['func']. If you print C.__dict__, you will find a pair: 'func' : So: t = BPLclass.__dict__['func'] inspect.ismethod(t) # False inspect.isfunction(t) # False inspect.ismethod(BPLclass.func) # True inspect.isfunction(BPLclass.func) # False s = Pythonclass.__dict__['func'] inspect.ismethod(t) # False inspect.isfunction(t) # True inspect.ismethod(Pythonclass.func) # True inspect.isfunction(Pythonclass.func) # False Really interesting, Eh? --- ShenLei From gabriel.becedillas at corest.com Mon Jun 11 15:55:27 2007 From: gabriel.becedillas at corest.com (Gabriel Becedillas) Date: Mon, 11 Jun 2007 10:55:27 -0300 Subject: [C++-sig] boost::shared_ptr getting back from Python with a PyObject inside In-Reply-To: <7465b6170706091028g150e4b96x4668d5efa23fc2ed@mail.gmail.com> References: <4665C14F.3020208@corest.com> <7465b6170706091028g150e4b96x4668d5efa23fc2ed@mail.gmail.com> Message-ID: <466D544F.5010107@corest.com> Thanks Roman, but it has nothing to do with threads. Its as simple as I describe: 1_) Holding the GIL, you wrap a boost::shared_ptr and pass it to python. 2_) Later, a C++ wrapped function gets called with that boost::shared_ptr as an argument (since it is called from Python, you're holding the GIL). That function stores the boost::shared_ptr somewhere (for example a global variable). 3_) You release the GIL. 4_) The boost::shared_ptr that was passed to python, and went back from python, hits refcount 0, and you're not holding the GIL. If you take a look at shared_ptr_from_python::construct you'll see a NEW boost::shared_ptr being constructed with the original T* PLUS a shared_ptr_deleter(handle<>(borrowed(source))). I don't know why this was implemented that way, instead of simply copying the original boost::shared_ptr. I assume it was done that way to optimize shared_ptr_to_python, because its checking if the boost::shared_ptr holds a shared_ptr_deleter (with a PyObject inside). I think this was a bad choice. If I pass something to Python, and then I get it back from Python, I would like to get EXACTLY the same. Roman Yakovenko wrote: > On 6/5/07, Gabriel Becedillas wrote: >> I have the following problem: >> 1_) A boost::shared_ptr is converted to python. >> 2_) The PyObject holding the boost::shared_ptr is converted back from >> python, (apparently) yielding the same boost::shared_ptr. >> 3_) The boost::shared_ptr hits refcount 0 somewhere else in C++Land >> without holding the Python GIL. >> 4_) Python's API gets called without holding the GIL because a >> sp_counted_impl_pd with a shared_ptr_deleter modifies the PyObject's >> refcount and Py_Dealloc gets called (check shared_ptr_deleter::operator()). >> >> This is wrong because you shouldn't use Python's API without holding the >> GIL. > > Did you read this FAQ: > http://boost.org/libs/python/doc/v2/faq.html#threadsupport? > From fullung at gmail.com Mon Jun 11 16:10:10 2007 From: fullung at gmail.com (Albert Strasheim) Date: Mon, 11 Jun 2007 16:10:10 +0200 Subject: [C++-sig] Call policy for static property? Message-ID: <20070611141010.GB13444@dogbert.sdsl.sun.ac.za> Hello all I'm trying to add a static property to a class, where this property contains an instance of another class. #include namespace py = boost::python; struct Foo{}; struct Bar{}; static Bar& get_bar() { static Bar bar; return bar; } void export_foo() { py::class_("Bar", py::no_init); py::class_("Foo", py::no_init) .add_static_property("theonlybar", &get_bar); } so that I can write mymodule.Foo.theonlybar in Python and get this single instance of the Bar class. Unfortunately, this code doesn't compile as-is. I get: error C2027: use of undefined type 'boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning' c:\program files\boost\boost_1_34_0\boost\python\detail\caller.hpp which makes sense, since get_bar probably needs a return_internal_reference call policy. I tried to add it with make_function: make_function(&get_bar, py::return_internal_reference<>()) but it seems make_function is only for wrapping member functions, because I get: IndexError: boost::python::with_custodian_and_ward_postcall: argument index out of range when I try to access the property. Is there a way to specify a call policy for the function called by a static property getter? Alternatively, is there another way to accomplish what I'm trying to do? Thanks for your time. Regards, Albert From meine at informatik.uni-hamburg.de Mon Jun 11 17:07:18 2007 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 11 Jun 2007 17:07:18 +0200 Subject: [C++-sig] [c++-sig] Is it a BUG? boost.python makes doctest impossible to recursive test. In-Reply-To: References: <200706111055.59345.meine@informatik.uni-hamburg.de> Message-ID: <200706111707.18542.meine@informatik.uni-hamburg.de> Am Montag, 11. Juni 2007 14:17:37 schrieb ??: > Here the val comes from C.__dict__['func']. If you print C.__dict__, > you will find a pair: > 'func' : Ah, that is interesting. So that's obviously the difference between @staticmethods and normal ones - I did not know that that happens as late as when writing C.func, but I thought it was a matter of class definition time. Note to myself: type(C.func) != type(C.__dict__['func']) Which also explains why methods have the right type in boost::python.. they haven't. ;-) -- Ciao, / / /--/ / / ANS From luca.sbardella at gmail.com Tue Jun 12 16:06:20 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Tue, 12 Jun 2007 16:06:20 +0200 Subject: [C++-sig] inheritance and polyphormism In-Reply-To: <8315652a0706110458i385d58fbja72fda2eb6e5d59e@mail.gmail.com> References: <8315652a0706070820p66d7e605o90b031c897621fef@mail.gmail.com> <7465b6170706091045t3219c377k738b16cc42bb0f1b@mail.gmail.com> <8315652a0706110405y65582570g64e560824301ca45@mail.gmail.com> <7465b6170706110420y1653d6afg69b169b81f14aa23@mail.gmail.com> <8315652a0706110458i385d58fbja72fda2eb6e5d59e@mail.gmail.com> Message-ID: <8315652a0706120706jdb7255cq3fcbd722934ce2b@mail.gmail.com> I solved the problem of the ambiguous access of 'get_override' by qualifying the function call "get_override" with the class name. This is what I've done: class base { public: virtual void method1(){} }; class derived: public base { public: virtual void method2(){} }; I wrapped them with class base_wrap: public base, public boost::python::wrapper { void method1() {....} }; class derived_wrap: public derived, public boost::python::wrapper, public base_wrap { void method2() {....I use this->boost::python::wrapper::get_override("method2")....} }; However, the code won't compile and the error is ambiguous conversions from 'derived_wrap *' to 'boost::python::detail::wrapper_base *' Luca On 11/06/07, Luca Sbardella wrote: > > If you mean doing > > class derived_wrap: public derived, public > boost::python::wrapper, public boost::python::wrapper { > void method2() {....} > }; > > This doesn't compile. It throw the error ambiguous access of > 'get_override' inside the function method2(). I guess it creates a > confusion to which class to overwrite (just a guess!!). > Luca > > > > > On 11/06/07, Roman Yakovenko wrote: > > > > On 6/11/07, Luca Sbardella wrote: > > > The link doesn't answer the question, or at least I do not see the > > answer. > > > > > > At first, I though that using the following approach would work > > > > > > > > > class derived_wrap: public derived, public > > > boost::python::wrapper { > > > void method2() {....} > > > }; > > > > You can derive from boost::python::wrapper< base > class too. I think > > this will do what you want. > > > > -- > > Roman Yakovenko > > C++ Python language binding > > http://www.language-binding.net/ > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mharidev at qualcomm.com Tue Jun 12 19:41:36 2007 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Tue, 12 Jun 2007 10:41:36 -0700 Subject: [C++-sig] Py++ Error for function operator *() In-Reply-To: <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA88028A452A@NAEX11.na.qualcomm.com> Hi Roman, I have attached the files that reproduce this bug. These are modified versions of the files: pyplusplus/unittests/data/free_operators_to_be_exported.hpp and corresponding Py++ code in pyplusplus/unittests/free_operators_tester.py Note that I get the assertion error when I want to do the following in the Py++ code. #Exclude all classes first - say I want to expose just one class later and #want to get rid of all the other classes from being exposed mb.classes().exclude() #just expose one class: testclass mb.class_("testclass").include() ----------------------------------------------------- Traceback (most recent call last): File "/opt/data/pyplusplus/unittests/fundamental_tester_base.py", line 147, in test self._create_extension_source_file() File "/opt/data/pyplusplus/unittests/fundamental_tester_base.py", line 94, in _create_extension_source_file mb.build_code_creator( self.__module_name, doc_extractor=doc_extractor ) File "./../pyplusplus/module_builder/builder.py", line 247, in build_code_creator File "./../pyplusplus/module_creator/creator.py", line 316, in create File "./../pyplusplus/module_creator/creator.py", line 186, in _adopt_free_operator AssertionError ----------------------------------------------------- Thanks, Meghana. -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Sunday, June 10, 2007 1:04 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ Error for function operator *() On 6/7/07, Haridev, Meghana wrote: > When I moved from Py++ 0.8.5 to Py++ 0.9.0, Py++ fails for the following > function declaration during the module_builder's build_code_creator() > phase: > > operator * (const ACE_Time_Value &tv, double d) > { > //..... > } > > Here's the Error message: > > self.moduleBuilder.build_code_creator(self.moduleName, > create_casting_constructor=flag_casting_constr) > File > "/opt/data/BTBLD_rhine_1080/thirdParty/lib/python2.4/site-packages/pyplu > splus/module_builder/builder.py", line 247, in build_code_creator > self.__code_creator = creator.create() > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 315, in create > self._adopt_free_operator( operator ) > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 185, in _adopt_free_operator > assert isinstance( arg_type, declarations.declarated_t ) > AssertionError Hi. I tried to reproduce the bug, but failed. Here is the link to test case: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unitt ests/data/free_operators_to_be_exported.hpp?revision=1051&view=markup I am testing the current version, but it is not that different from the 0.9.0. Can you modify the test to reproduce the bug? If not you can send me privately gccxml generated file and the Py++ script. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- A non-text attachment was scrubbed... Name: free_operators_to_be_exported.hpp Type: application/octet-stream Size: 731 bytes Desc: free_operators_to_be_exported.hpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: free_operators_tester.py Type: application/octet-stream Size: 1015 bytes Desc: free_operators_tester.py URL: From mharidev at qualcomm.com Tue Jun 12 19:52:23 2007 From: mharidev at qualcomm.com (Haridev, Meghana) Date: Tue, 12 Jun 2007 10:52:23 -0700 Subject: [C++-sig] Py++ Error for function operator *() In-Reply-To: <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> Message-ID: <5383A81D5EB8F14FBDB487D9B5FBEA88028A4535@NAEX11.na.qualcomm.com> Hi Roman, Here's another use-case for which I get another error "IndexError" at the same location in addition to the "Assertion Error": File "./../pyplusplus/module_creator/creator.py", line 182, in _adopt_free_operator I am attaching another set of files free_operators_to_be_exported.hpp and corresponding Py++ code free_operators_tester.py to reproduce the IndexError. Note that in this case also, I get the index error when I want to do the following in the Py++ code. #Exclude all classes first - say I want to expose just one class later and #want to get rid of all the other classes from being exposed mb.classes().exclude() --------------------------------------------------------- Traceback (most recent call last): File "/opt/data/pyplusplus/unittests/fundamental_tester_base.py", line 147, in test self._create_extension_source_file() File "/opt/data/pyplusplus/unittests/fundamental_tester_base.py", line 94, in _create_extension_source_file mb.build_code_creator( self.__module_name, doc_extractor=doc_extractor ) File "./../pyplusplus/module_builder/builder.py", line 247, in build_code_creator File "./../pyplusplus/module_creator/creator.py", line 316, in create File "./../pyplusplus/module_creator/creator.py", line 182, in _adopt_free_operator IndexError: list index out of range --------------------------------------------------------- Thanks, -Meghana. -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Sunday, June 10, 2007 1:04 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Py++ Error for function operator *() On 6/7/07, Haridev, Meghana wrote: > When I moved from Py++ 0.8.5 to Py++ 0.9.0, Py++ fails for the following > function declaration during the module_builder's build_code_creator() > phase: > > operator * (const ACE_Time_Value &tv, double d) > { > //..... > } > > Here's the Error message: > > self.moduleBuilder.build_code_creator(self.moduleName, > create_casting_constructor=flag_casting_constr) > File > "/opt/data/BTBLD_rhine_1080/thirdParty/lib/python2.4/site-packages/pyplu > splus/module_builder/builder.py", line 247, in build_code_creator > self.__code_creator = creator.create() > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 315, in create > self._adopt_free_operator( operator ) > File > "/opt/or-tree/mharidev/thirdParty/lib/python2.4/site-packages/pyplusplus > /module_creator/creator.py", line 185, in _adopt_free_operator > assert isinstance( arg_type, declarations.declarated_t ) > AssertionError Hi. I tried to reproduce the bug, but failed. Here is the link to test case: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unitt ests/data/free_operators_to_be_exported.hpp?revision=1051&view=markup I am testing the current version, but it is not that different from the 0.9.0. Can you modify the test to reproduce the bug? If not you can send me privately gccxml generated file and the Py++ script. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- A non-text attachment was scrubbed... Name: free_operators_to_be_exported.hpp Type: application/octet-stream Size: 884 bytes Desc: free_operators_to_be_exported.hpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: free_operators_tester.py Type: application/octet-stream Size: 1015 bytes Desc: free_operators_tester.py URL: From kanand at qualcomm.com Tue Jun 12 21:03:51 2007 From: kanand at qualcomm.com (Anand, Kumar) Date: Tue, 12 Jun 2007 12:03:51 -0700 Subject: [C++-sig] Py++: auto_ptr held_type Message-ID: I am trying to expose a "MyTestClass" to python using py++ and with held_type as std::auto_ptr. Since Py++ creates a wrapper class for every C++ class that it exposes, should held_type be "std::auto_ptr" or "std::auto_ptr"? Can you point as to why one would choose one against the other? Thanks Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Jun 13 04:35:49 2007 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 12 Jun 2007 22:35:49 -0400 Subject: [C++-sig] Problems instantiating class Boost Python class References: <466DBBF1.1050601@homechoice.co.uk> Message-ID: <87r6ogtwca.fsf@grogan.peloton> on Mon Jun 11 2007, Phil wrote: > Hi, > > I'm a newbie having some problems instantiating a class written in C++ > in Python using Boost.Python. > > I can get a very simple example working when I expose a function outside > of a class, that returns a string, but the below fails as shown, despite > building. The enum in the same library however works fine. > > I've googled the error returned from Python and I get zero hits - has > anyone get any idea what I'm doing wrong? > > I'm using Python 2.5, GCC 4.0.1 and Boost 1.33 on Mac OS X 10.4.9. I > don't think it matters but I'm building the solution as a dynamic C++ > bsd library in XCode and the changing the Mac OS X .dylib extention to > .so as is required by Python. This all works for simpler examples and > the enum in this example. > > Error: TypeError: __init__() should return None, not 'NoneType' Phil, First, I suggest you take your question to a more subject-specific mailing list: http://www.boost.org/more/mailing_lists.htm#cplussig I have no clue what could be going wrong here; I've never seen that problem. My only suggestion to you is to further reduce your test case to the absolute minimal example that reproduces the behavior. That almost always makes the problem obvious, or at least easily diagnosed. Your example is small, but surely not minimal yet. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com From roman.yakovenko at gmail.com Wed Jun 13 09:49:47 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 13 Jun 2007 10:49:47 +0300 Subject: [C++-sig] Py++ Error for function operator *() In-Reply-To: <5383A81D5EB8F14FBDB487D9B5FBEA88028A452A@NAEX11.na.qualcomm.com> References: <5383A81D5EB8F14FBDB487D9B5FBEA88028A3E20@NAEX11.na.qualcomm.com> <7465b6170706101303tf269166hc62ebfd3747d1b3d@mail.gmail.com> <5383A81D5EB8F14FBDB487D9B5FBEA88028A452A@NAEX11.na.qualcomm.com> Message-ID: <7465b6170706130049i2418dec3jfec07be0e41ead6d@mail.gmail.com> On 6/12/07, Haridev, Meghana wrote: > Hi Roman, > I have attached the files that reproduce this bug. Thanks for this. Now I understand the bug and has a fix in SVN. Py++ exposes free operators, by finding the class the operator works on, and injects it to it. Boost.Python handles the rest. In your case you excluded the class, but not the operators. Py++ didn't deal well with the situation. The fix is trivial - Py++ will check whether the relevant classes exposed or not, and will behave like expected. Can you test the fix? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Wed Jun 13 10:33:39 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 13 Jun 2007 11:33:39 +0300 Subject: [C++-sig] Py++: auto_ptr held_type In-Reply-To: References: Message-ID: <7465b6170706130133x2b455f97q984be1d46ab681e1@mail.gmail.com> On 6/12/07, Anand, Kumar wrote: > I am trying to expose a "MyTestClass" to python using py++ and with > held_type as std::auto_ptr. > > Since Py++ creates a wrapper class for every C++ class that it exposes, This is not completely true, also Py++ always provides an explanation why it does this. > should held_type be "std::auto_ptr" or > "std::auto_ptr"? > > Can you point as to why one would choose one against the other? Py++ has transfer_ownership_tester.py. You welcome to play with it. I don't completely understand the issues related to boost::python::wrapper class and auto_ptr as held_type. I found that the whole mechanism doesn't work as expected. For me std::auto_ptr worked fine. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rbrown at gamry.com Wed Jun 13 17:06:29 2007 From: rbrown at gamry.com (Ron Brown, Jr.) Date: Wed, 13 Jun 2007 11:06:29 -0400 Subject: [C++-sig] len function? Message-ID: This is probably a ridiculous question, but how do I find the length of a boost::python::list object? I can't seem to find a straightforward answer in any of my searches. Thanks, Ron From luca.sbardella at gmail.com Wed Jun 13 19:25:51 2007 From: luca.sbardella at gmail.com (Luca Sbardella) Date: Wed, 13 Jun 2007 19:25:51 +0200 Subject: [C++-sig] len function? In-Reply-To: References: Message-ID: <8315652a0706131025x7f8253e7me719fc48bcdc23a1@mail.gmail.com> boost::python::list lis; using namespace boost::python; unsigned N = extract(lis.attr("__len__")()); On 13/06/07, Ron Brown, Jr. wrote: > > This is probably a ridiculous question, but how do I find the length of > a boost::python::list object? I can't seem to find a straightforward > answer in any of my searches. > > Thanks, > > > Ron > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From amohr at pixar.com Wed Jun 13 19:20:55 2007 From: amohr at pixar.com (Alex Mohr) Date: Wed, 13 Jun 2007 10:20:55 -0700 Subject: [C++-sig] len function? In-Reply-To: References: Message-ID: <46702777.9040003@pixar.com> Ron Brown, Jr. wrote: > This is probably a ridiculous question, but how do I find the length of > a boost::python::list object? I can't seem to find a straightforward > answer in any of my searches. In 1.33.1, you can do: #include boost::python::len(x); I don't know if that's changed in 1.34. Alex From rbrown at gamry.com Wed Jun 13 20:44:02 2007 From: rbrown at gamry.com (Ron Brown, Jr.) Date: Wed, 13 Jun 2007 14:44:02 -0400 Subject: [C++-sig] len function? In-Reply-To: <46702777.9040003@pixar.com> References: <46702777.9040003@pixar.com> Message-ID: Alex Mohr wrote: > In 1.33.1, you can do: > #include > boost::python::len(x); Thanks, Alex, this is what I ended up doing. Why is the len() function in the api_placeholder header? Shouldn't that be a standard boost.python function? - Ron From amohr at pixar.com Wed Jun 13 22:29:35 2007 From: amohr at pixar.com (Alex Mohr) Date: Wed, 13 Jun 2007 13:29:35 -0700 Subject: [C++-sig] len function? In-Reply-To: References: <46702777.9040003@pixar.com> Message-ID: <467053AF.9000806@pixar.com> > Thanks, Alex, this is what I ended up doing. Why is the len() function > in the api_placeholder header? Shouldn't that be a standard > boost.python function? I agree with you, but for an official response we'd have to ask David Abrahams. My guess is that his response would be, "Patches are welcome." Alex From rwgk at yahoo.com Wed Jun 13 23:18:02 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 13 Jun 2007 14:18:02 -0700 (PDT) Subject: [C++-sig] len function? Message-ID: <978768.1002.qm@web31107.mail.mud.yahoo.com> > > Thanks, Alex, this is what I ended up doing. Why is the len() function > > in the api_placeholder header? Shouldn't that be a standard > > boost.python function? > > I agree with you, but for an official response we'd have to ask David > Abrahams. My guess is that his response would be, "Patches are welcome." In the Boost CVS head and the 1.34.0 release, len() is defined in boost/python/object.hpp (ever since Jan or Feb 2006). api_placeholder.hpp is still there but only for backward compatibility. I'll remove it from the head in a year or two. Ralf ____________________________________________________________________________________ Bored stiff? Loosen up... Download and play hundreds of games for free on Yahoo! Games. http://games.yahoo.com/games/front -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.jaroszynski at gmail.com Thu Jun 14 02:20:13 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Thu, 14 Jun 2007 02:20:13 +0200 Subject: [C++-sig] C++ static function as __init__ Message-ID: <200706140220.13543.p.jaroszynski@gmail.com> Hello, I want to do possibly strange thing: struct Foo { Foo() {} static void init_me(PyObject * self) { ??? (I want to initialize self with a new Foo object using its constructor) } }; (...) bp::class_ foo("Foo", bp::no_init); foo.def("__init__", &Foo::init_me); The above "works" as in the signature matches, but I have no idea how to initialize the object properly given the PyObject self pointer. I was trying to dig in the code how is bp::init really working but I failed miserably :/ Any clues? ;] -- Best Regards, Piotr Jaroszy?ski From phil.beadling at homechoice.co.uk Thu Jun 14 02:16:19 2007 From: phil.beadling at homechoice.co.uk (Phil) Date: Thu, 14 Jun 2007 01:16:19 +0100 Subject: [C++-sig] __init__() should return None, not 'NoneType' with Boost.Python? Message-ID: <467088D3.50403@homechoice.co.uk> Hi, I'm a newbie having difficulty getting a very simple C++ class to expose in Python. I've narrowed this down to the simplest case I can to reproduce the error (code below - all in one cpp). I'm using Mac OS X 10.4.9, GCC 4.01, Python 2.5 and Boost 1.33. I'm using XCode to compile the below as a BSD Dynamic Library. It builds fine. I'm then renaming the resulting library from .dylib to .so (necessary extra step on Mac OS). On importing into Python I see get this: $ python Python 2.5.1 (r251:54863, Jun 10 2007, 17:57:56) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import libphil_boost >>> testing = libphil_boost.MyTest() Traceback (most recent call last): File "", line 1, in TypeError: __init__() should return None, not 'NoneType' >>> I can 'see' it like this tho: >>> libphil_boost >>> libphil_boost.MyTest >>> Using exactly the same method I can expose more basic C++ types. For example a basic enum or function works fine (for example the Hello World example in Boost docs). But I see the same error for any type of class I choose to try it with. I've tried googling this, and I've had no luck. Has anyone seen this before, or have any ideas what I may be doing wrong? Thanks for any help, Phil ______ #include using namespace boost::python; class MyTest { }; BOOST_PYTHON_MODULE(libphil_boost) { class_("MyTest"); } From amohr at pixar.com Thu Jun 14 02:29:27 2007 From: amohr at pixar.com (Alex Mohr) Date: Wed, 13 Jun 2007 17:29:27 -0700 Subject: [C++-sig] C++ static function as __init__ In-Reply-To: <200706140220.13543.p.jaroszynski@gmail.com> References: <200706140220.13543.p.jaroszynski@gmail.com> Message-ID: <46708BE7.3090302@pixar.com> > I want to do possibly strange thing: > > struct Foo { > Foo() {} > static void init_me(PyObject * self) { > ??? (I want to initialize self with a new Foo object using its constructor) > } > }; > (...) > bp::class_ foo("Foo", bp::no_init); > foo.def("__init__", &Foo::init_me); Does something like this work for you? struct Foo { Foo() {} static Foo *init_me() { return new Foo; } }; class_("Foo", no_init) .def("__init__", make_constructor(Foo::init_me)); I forget if you need manage_new_object in there or not... Alex From p.jaroszynski at gmail.com Thu Jun 14 02:50:43 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Thu, 14 Jun 2007 02:50:43 +0200 Subject: [C++-sig] C++ static function as __init__ In-Reply-To: <46708BE7.3090302@pixar.com> References: <200706140220.13543.p.jaroszynski@gmail.com> <46708BE7.3090302@pixar.com> Message-ID: <200706140250.44065.p.jaroszynski@gmail.com> On Thursday 14 of June 2007 02:29:27 Alex Mohr wrote: > Does something like this work for you? > > struct Foo { > Foo() {} > static Foo *init_me() { > return new Foo; > } > }; > > class_("Foo", no_init) > .def("__init__", make_constructor(Foo::init_me)); > > I forget if you need manage_new_object in there or not... I somehow missed the make_constructor before posting and found it just before receiving your reply. I did exactly the same but used shared_ptr instead of the raw pointer as I keep the real Foo in a shared_ptr anyway (probably, it doesn't matter, but shouldn't hurt, right?) Thanks and sorry for the noise :] -- Best Regards, Piotr Jaroszy?ski From pzs at dcs.gla.ac.uk Thu Jun 14 10:37:55 2007 From: pzs at dcs.gla.ac.uk (Peter Saffrey) Date: Thu, 14 Jun 2007 09:37:55 +0100 Subject: [C++-sig] bgl Python on Mac OS X Message-ID: I'm trying to build this. I've downloaded the boost libraries (version 1.34) and run configure, make and sudo make install without errors. Then I've downloaded bgl-python (0.9) and, as instructed, found the bjam executable from the boost hierarchy, copied it somewhere convenient and run it in the bgl-python directory. That gave me this error: Unable to load Boost.Build: could not find "boost-build.jam" --------------------------------------------------------------- Attempted search from /Users/pzs/incoming/bgl-python-0.9 up to the root and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: /usr/ share/boost-build. Please consult the documentation at 'http://www.boost.org'. So I set $BOOST_ROOT to be the root of the boost 1.34 directory and tried bjam again. This time I get: error: Could not find parent for project at '.' error: Did not find Jamfile or project-root.jam in any parent directory. I've also tried the binary, but that doesn't work either, probably because I'm running Python 2.5 and the binary is for 2.3. Any ideas? Peter From gazihan at cse.wustl.edu Thu Jun 14 18:46:46 2007 From: gazihan at cse.wustl.edu (Gazihan Alankus) Date: Thu, 14 Jun 2007 11:46:46 -0500 Subject: [C++-sig] bgl Python on Mac OS X References: Message-ID: I've had the exact same problem when trying to build my own simple library that's using Boost.Python. I remember realizing that the problem was I didn't follow the steps here and the boost.jam pages that it refers to: http://www.boost.org/libs/python/doc/building.html And I vaguely remember that the solution involved getting a user-config.jam created in my home directory with this content: # Boost.Build Configuration # Automatically generated by Boost configure # Compiler configuration using gcc ; # Python configuration using python : 2.4 : /usr ; You probably just need to configure boost.jam right. Hope this helps. -Gazi Peter Saffrey wrote: > I'm trying to build this. I've downloaded the boost libraries (version > 1.34) and run configure, make and sudo make install without errors. > > Then I've downloaded bgl-python (0.9) and, as instructed, found the > bjam executable from the boost hierarchy, copied it somewhere > convenient and run it in the bgl-python directory. That gave me this > error: > > Unable to load Boost.Build: could not find "boost-build.jam" > --------------------------------------------------------------- > Attempted search from /Users/pzs/incoming/bgl-python-0.9 up to the > root > and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: /usr/ > share/boost-build. > Please consult the documentation at 'http://www.boost.org'. > > So I set $BOOST_ROOT to be the root of the boost 1.34 directory and > tried bjam again. This time I get: > > error: Could not find parent for project at '.' > error: Did not find Jamfile or project-root.jam in any parent > directory. > > I've also tried the binary, but that doesn't work either, probably > because I'm running Python 2.5 and the binary is for 2.3. > > Any ideas? > > Peter From rbrown at gamry.com Fri Jun 15 17:24:15 2007 From: rbrown at gamry.com (Ron Brown, Jr.) Date: Fri, 15 Jun 2007 11:24:15 -0400 Subject: [C++-sig] len function? In-Reply-To: <978768.1002.qm@web31107.mail.mud.yahoo.com> References: <978768.1002.qm@web31107.mail.mud.yahoo.com> Message-ID: Ralf W. Grosse-Kunstleve wrote: > In the Boost CVS head and the 1.34.0 release, len() is defined in > boost/python/object.hpp (ever since Jan or Feb 2006). > api_placeholder.hpp is still there but only for backwa rd compatibility. > I'll remove it from the head in a year or two. > Ralf Makes sense, I'm using 1.33.1, and hadn't realized that a new version had been released. Thanks for the info, that's good to know! Ron From fullung at gmail.com Fri Jun 15 23:38:14 2007 From: fullung at gmail.com (Albert Strasheim) Date: Fri, 15 Jun 2007 23:38:14 +0200 Subject: [C++-sig] Exception translation Message-ID: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> Hello all I want to translate some of my exceptions from C++ to Python. I have registered an exception translator and it works rather well. However, I would like my translated exceptions to have their own type in Python, so I don't simply want to do: PyErr_SetString(PyExc_UserWarning, ex.what()); in my exception translator. Instead, I want my exception translator to take the exception, clone it (luckily I have an exception base class that allows me to do this), construct an instance of its wrapper type around it and use PyErr_SetObject instead. Something along these lines has been discussed previously: http://mail.python.org/pipermail/c++-sig/2006-April/010618.html Later in thread, Dave Abrahams said: Officially, it [Python] does require that exceptions be derived from PyExc_Exception (I don't remember where that's documented), but unofficially, you can throw anything :) I assume this policy exists so that users can write try/except blocks that catch Exception and have it catch any type derived from Exception. Now my question: is there a way to derive the Boost.Python wrapper type of my C++ exception class from PyExc_Exception using Boost.Python? I want to do this so that my exceptions can be caught in scenario described above. Even better, is there a way to derive an arbitrary Boost.Python wrapper type of any C++ class from an arbitrary Python type? This might turn out to be very handy for integrating C++ matrix libraries with NumPy. Thanks for any help. Cheers, Albert P.S. In thread, Roman Yakovenko mentioned that he might add support for this kind of thing to pyplusplus. Did something happen in this regard? From roman.yakovenko at gmail.com Sat Jun 16 12:13:12 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 16 Jun 2007 13:13:12 +0300 Subject: [C++-sig] Exception translation In-Reply-To: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> References: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> Message-ID: <7465b6170706160313u28e18fc3o855eca1e290df946@mail.gmail.com> On 6/16/07, Albert Strasheim wrote: > Hello all > > I want to translate some of my exceptions from C++ to Python. > > I have registered an exception translator and it works rather well. However, > I would like my translated exceptions to have their own type in Python, so I > don't simply want to do: > > PyErr_SetString(PyExc_UserWarning, ex.what()); > > in my exception translator. > > Instead, I want my exception translator to take the exception, clone it > (luckily I have an exception base class that allows me to do this), > construct an instance of its wrapper type around it and use PyErr_SetObject > instead. > > Something along these lines has been discussed previously: > > http://mail.python.org/pipermail/c++-sig/2006-April/010618.html > > Later in thread, Dave Abrahams said: > > Officially, it [Python] does require that exceptions be derived from > PyExc_Exception (I don't remember where that's documented), but > unofficially, you can throw anything :) > > I assume this policy exists so that users can write try/except blocks that > catch Exception and have it catch any type derived from Exception. > > Now my question: is there a way to derive the Boost.Python wrapper type of > my C++ exception class from PyExc_Exception using Boost.Python? I want to do > this so that my exceptions can be caught in scenario described above. > > Even better, is there a way to derive an arbitrary Boost.Python wrapper type > of any C++ class from an arbitrary Python type? This might turn out to be > very handy for integrating C++ matrix libraries with NumPy. > > Thanks for any help. > > Cheers, > > Albert > > P.S. In thread, Roman Yakovenko mentioned that he might add support for this > kind of thing to pyplusplus. Did something happen in this regard? Special for you :-) http://www.language-binding.net/pyplusplus/troubleshooting_guide/exceptions/exceptions.html I use this solution in Python-Ogre project and it works pretty well. Let me know whether this help or not. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From fullung at gmail.com Sat Jun 16 12:31:39 2007 From: fullung at gmail.com (Albert Strasheim) Date: Sat, 16 Jun 2007 12:31:39 +0200 Subject: [C++-sig] Exception translation References: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> <7465b6170706160313u28e18fc3o855eca1e290df946@mail.gmail.com> Message-ID: <003a01c7b001$866b8e00$0100a8c0@sun.ac.za> Hello all ----- Original Message ----- From: "Roman Yakovenko" To: "Development of Python/C++ integration" Sent: Saturday, June 16, 2007 12:13 PM Subject: Re: [C++-sig] Exception translation >> P.S. In thread, Roman Yakovenko mentioned that he might add support for >> this >> kind of thing to pyplusplus. Did something happen in this regard? > > Special for you :-) > http://www.language-binding.net/pyplusplus/troubleshooting_guide/exceptions/exceptions.html > > I use this solution in Python-Ogre project and it works pretty well. > > Let me know whether this help or not. Wow, very nice! Looks like it's going to work great for my exceptions. Cheers, Albert From p.jaroszynski at gmail.com Sat Jun 16 15:33:03 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Sat, 16 Jun 2007 15:33:03 +0200 Subject: [C++-sig] Exception translation In-Reply-To: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> References: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> Message-ID: <200706161533.03753.p.jaroszynski@gmail.com> On Friday 15 of June 2007 23:38:14 Albert Strasheim wrote: > Hello all > > I want to translate some of my exceptions from C++ to Python. FWIW, I have written some exception handling code too: http://paludis.pioto.org/trac/browser/trunk/python/exception.hh http://paludis.pioto.org/trac/browser/trunk/python/exception.cc It's a little project specific, but could be easily adjusted. -- Best Regards, Piotr Jaroszy?ski From fullung at gmail.com Sat Jun 16 17:04:12 2007 From: fullung at gmail.com (Albert Strasheim) Date: Sat, 16 Jun 2007 17:04:12 +0200 Subject: [C++-sig] Exception translation References: <002901c7af95$7a5a88d0$0100a8c0@sun.ac.za> <200706161533.03753.p.jaroszynski@gmail.com> Message-ID: <007801c7b027$9906eed0$0100a8c0@sun.ac.za> Hello all ----- Original Message ----- From: "Piotr Jaroszy?ski" To: Sent: Saturday, June 16, 2007 3:33 PM Subject: Re: [C++-sig] Exception translation > On Friday 15 of June 2007 23:38:14 Albert Strasheim wrote: >> Hello all >> >> I want to translate some of my exceptions from C++ to Python. > > FWIW, I have written some exception handling code too: > http://paludis.pioto.org/trac/browser/trunk/python/exception.hh > http://paludis.pioto.org/trac/browser/trunk/python/exception.cc > > It's a little project specific, but could be easily adjusted. Thanks very much for this. I was able to simplify you excellent code to suit my needs exactly. Luckily for me, the library I'm wrapping doesn't require anything too fancy, so I'm able to get away without Roman's rvalue converters. http://pyactivemq.googlecode.com/svn/trunk/src/main/CMSException.cpp Cheers, Albert From p.jaroszynski at gmail.com Sun Jun 17 20:56:08 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Sun, 17 Jun 2007 20:56:08 +0200 Subject: [C++-sig] r-value converter Message-ID: <200706172056.09490.p.jaroszynski@gmail.com> Hello, for one of the classes I had to write PythonFoo equivalent and hence I need a r-value converter from PythonFoo to Foo as implicit conversion is not possible. This what I have (more or less copy-n-paste from Roman's and boost's docs :) struct PackageDepSpecFromPython { PackageDepSpecFromPython() { bp::converter::registry::push_back(&convertible, &construct, boost::python::type_id()); } static void * convertible(PyObject * obj_ptr) { return obj_ptr; } static void construct(PyObject * obj_ptr, bp::converter::rvalue_from_python_stage1_data * data) { typedef bp::converter::rvalue_from_python_storage Storage; void * storage = reinterpret_cast(data)->storage.bytes; new (storage) PackageDepSpec("cat/123", pds_pm_permissive); [1] data->convertible = storage; } }; And a few questions: 1) First wrt [1], I would like to create the PackageDepSpec with properties taken from PythonPackageDepSpec equivalent - how can I get that C++ object from PyObject pointer? 2) Some of the functions taking PackageDepSpec want shared_ptr - how can I make a converter to that type? 3) Should I do any extra checks in convertible for such a custom type? -- Best Regards, Piotr Jaroszy?ski From p.jaroszynski at gmail.com Sun Jun 17 21:16:16 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Sun, 17 Jun 2007 21:16:16 +0200 Subject: [C++-sig] r-value converter In-Reply-To: <200706172056.09490.p.jaroszynski@gmail.com> References: <200706172056.09490.p.jaroszynski@gmail.com> Message-ID: <200706172116.16733.p.jaroszynski@gmail.com> > 2) Some of the functions taking PackageDepSpec want > shared_ptr - how can I make a converter to that type? Ok, that was easy, type_id > did the trick. And btw. If you think r-value converter is not the right way, tell me, too. I just couldn't think of anything else. -- Best Regards, Piotr Jaroszy?ski From p.jaroszynski at gmail.com Sun Jun 17 21:59:46 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Sun, 17 Jun 2007 21:59:46 +0200 Subject: [C++-sig] r-value converter In-Reply-To: <200706172056.09490.p.jaroszynski@gmail.com> References: <200706172056.09490.p.jaroszynski@gmail.com> Message-ID: <200706172159.46472.p.jaroszynski@gmail.com> > 1) First wrt [1], I would like to create the PackageDepSpec with properties > taken from PythonPackageDepSpec equivalent - how can I get that C++ object > from PyObject pointer? Ok, that was easy too. bp::extract(obj_ptr) :] -- Best Regards, Piotr Jaroszy?ski From groups at DavidBrownell.com Tue Jun 19 09:04:43 2007 From: groups at DavidBrownell.com (David Brownell) Date: Tue, 19 Jun 2007 07:04:43 +0000 (UTC) Subject: [C++-sig] Share C++ Object Extended in Python? Message-ID: I have an existing C++ definition that resembles the code below, and would like to extend the Events interface using Python. However, I get errors in Python when I attempt to create a Python object that is shared between Python and C++. struct Events { virtual void Foo(char const *tcString) = 0; }; struct Object { void Init(Events &events) { _pEvents = &events; } void DoFoo() { _pEvents->Foo("Fire foo!"); } Events * _pEvents; }; When using the following boost python code generated with Py++ things work well in some cases, but not all. struct Events_wrapper : Events, bp::wrapper< Events > { Events_wrapper() : Events() , bp::wrapper< Events >(){ // null constructor } virtual void Foo( char const * tcString ){ bp::override func_Foo = this->get_override( "Foo" ); func_Foo( tcString ); } }; BOOST_PYTHON_MODULE(tester){ bp::class_< Events_wrapper, boost::noncopyable >( "Events" ) .def( "Foo" , bp::pure_virtual( &::Events::Foo ) , ( bp::arg("tcString") ) ); bp::class_< Object >( "Object" ) .def( "DoFoo" , &::Object::DoFoo ) .def( "Init" , &::Object::Init , ( bp::arg("events") ) ); } This following Python code works fine: import tester class Events(tester.Events): def Foo(self s): print s e = Events() o = tester.Object() o.Init(e) o.DoFoo() But I get the error... Traceback (most recent call last): File "", line 1, in ? ArgumentError: Python argument types in Object.Init(Object, Events) did not match C++ signature: Init(struct Object {lvalue}, struct Events {lvalue} events) ...with the code: import tester class Events(tester.Events): def __init__(self): self.i = 0 def Foo(self s): print s e = Events() o = tester.Object() o.Init(e) o.DoFoo() It appears that I am not doing something right with the binding code, but so far I haven't been able to find the right combination of boost::python argument decorators to get the job done. It seems like I could use an auto_ptr if I wanted Object to take ownership of the event object, but I want both the Python and C++ code to continue to modify the same instance of Event. Is there some way I can do this? Thanks for your help! David Brownell From roman.yakovenko at gmail.com Tue Jun 19 09:42:17 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 19 Jun 2007 10:42:17 +0300 Subject: [C++-sig] Share C++ Object Extended in Python? In-Reply-To: References: Message-ID: <7465b6170706190042l2e5ad771w3ee110abfe58b8a2@mail.gmail.com> On 6/19/07, David Brownell wrote: > I have an existing C++ definition that resembles the code below, and would > like to extend the Events interface using Python. However, I get errors > in Python when I attempt to create a Python object that is shared between > Python and C++. > > struct Events > { > virtual void Foo(char const *tcString) = 0; > }; > > struct Object > { > void Init(Events &events) { _pEvents = &events; } > void DoFoo() { _pEvents->Foo("Fire foo!"); } > > Events * _pEvents; > }; > > When using the following boost python code generated with Py++ things work > well in some cases, but not all. > struct Events_wrapper : Events, bp::wrapper< Events > { > > Events_wrapper() > : Events() > , bp::wrapper< Events >(){ > // null constructor > } > > virtual void Foo( char const * tcString ){ > bp::override func_Foo = this->get_override( "Foo" ); > func_Foo( tcString ); > } > }; > > BOOST_PYTHON_MODULE(tester){ > bp::class_< Events_wrapper, boost::noncopyable >( "Events" ) > .def( > "Foo" > , bp::pure_virtual( &::Events::Foo ) > , ( bp::arg("tcString") ) ); > > bp::class_< Object >( "Object" ) > .def( > "DoFoo" > , &::Object::DoFoo ) > .def( > "Init" > , &::Object::Init > , ( bp::arg("events") ) ); > } > > This following Python code works fine: > > import tester > class Events(tester.Events): > def Foo(self s): > print s > e = Events() > o = tester.Object() > o.Init(e) > o.DoFoo() > > But I get the error... > > Traceback (most recent call last): > File "", line 1, in ? > ArgumentError: Python argument types in > Object.Init(Object, Events) > did not match C++ signature: > Init(struct Object {lvalue}, struct Events {lvalue} events) > > ...with the code: > > import tester > class Events(tester.Events): > def __init__(self): Try to add call to tester.Events.__init__. Does it help? > self.i = 0 > def Foo(self s): > print s > e = Events() > o = tester.Object() > o.Init(e) > o.DoFoo() > > It appears that I am not doing something right with the binding code, but > so far I haven't been able to find the right combination of boost::python > argument decorators to get the job done. It seems like I could use an auto_ptr > if I wanted Object to take ownership of the event object, but I want both > the Python and C++ code to continue to modify the same instance of Event. > Is there some way I can do this? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pk at cs.tut.fi Tue Jun 19 11:16:46 2007 From: pk at cs.tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 19 Jun 2007 12:16:46 +0300 Subject: [C++-sig] Py++ and 'using' declarations Message-ID: <46779EFE.5080609@cs.tut.fi> Is there a way in Py++ to deal with overloaded member functions introduced by 'using' declarations? For example, for the following declarations, Py++ creates the code below. ----------------------------------------------------- class B { public: void f(); }; class D : public B { public: void f(int i); using B::f; }; ----------------------------------------------------- // This file has been generated by Py++. #include "boost/python.hpp" #include "killme.hh" namespace bp = boost::python; BOOST_PYTHON_MODULE(killme){ bp::class_< B >( "B" ) .def("f", &::B::f ); bp::class_< D, bp::bases< B > >( "D" ) .def("f", &::D::f, ( bp::arg("i") ) ); } ----------------------------------------------------- Compiling this with g++ results in an "unresolved overloaded function type" error, because g++ cannot choose between D::f() and D::f(int). -- Pertti From roman.yakovenko at gmail.com Tue Jun 19 11:20:54 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 19 Jun 2007 12:20:54 +0300 Subject: [C++-sig] Py++ and 'using' declarations In-Reply-To: <46779EFE.5080609@cs.tut.fi> References: <46779EFE.5080609@cs.tut.fi> Message-ID: <7465b6170706190220l22a44927kb3ccb755f94fd1c2@mail.gmail.com> On 6/19/07, Pertti Kellom?ki wrote: > Is there a way in Py++ to deal with overloaded member functions > introduced by 'using' declarations? > > For example, for the following declarations, Py++ creates > the code below. > > ----------------------------------------------------- > class B { > public: > void f(); > }; > > class D : public B { > public: > void f(int i); > using B::f; > }; > ----------------------------------------------------- > // This file has been generated by Py++. > #include "boost/python.hpp" > #include "killme.hh" > namespace bp = boost::python; > > BOOST_PYTHON_MODULE(killme){ > bp::class_< B >( "B" ) > .def("f", &::B::f ); > bp::class_< D, bp::bases< B > >( "D" ) > .def("f", &::D::f, ( bp::arg("i") ) ); > } > ----------------------------------------------------- > > Compiling this with g++ results in an "unresolved overloaded > function type" error, because g++ cannot choose between > D::f() and D::f(int). You don't need "using": mb = module_builder_t( ... ) D = mb.class_( 'D' ) D.mem_fun( 'f' ).create_with_signature = True #or: mb.calldefs().create_with_signature = True #for all functions You can read more in documentation about the property: http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.calldef_wrapper.calldef_t-class.html#create_with_signature P.S. I will tweak Py++ to be aware to such use case, and it will guess right the default value of the property. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pk at cs.tut.fi Tue Jun 19 12:15:04 2007 From: pk at cs.tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 19 Jun 2007 13:15:04 +0300 Subject: [C++-sig] Py++ and 'using' declarations In-Reply-To: <7465b6170706190220l22a44927kb3ccb755f94fd1c2@mail.gmail.com> References: <46779EFE.5080609@cs.tut.fi> <7465b6170706190220l22a44927kb3ccb755f94fd1c2@mail.gmail.com> Message-ID: <4677ACA8.1000603@cs.tut.fi> Roman, Thanks again for a very speedy answer! -- Pertti From adrien-ml at wizzi.net Tue Jun 19 16:05:57 2007 From: adrien-ml at wizzi.net (Adrien Saladin) Date: Tue, 19 Jun 2007 16:05:57 +0200 Subject: [C++-sig] Py++: absolute or relative PATH for parsed files Message-ID: <200706191605.57333.adrien-ml@wizzi.net> Hello, I am switching from Pyste to Py++ for my project. Thanks for this great tool ! (and for boost python of course). I still have some problem with absolute and relative file paths: I have a file called "all.h" which only contains #include directives for the other .h files. In the Py++ driver file, when I use this first line, the bindings are generated: mb = module_builder.module_builder_t(files=[r"/nfs/to/my/home/Src/Tests/Python/Py++/all.h"]) As this way is not portable because of the absolte path, I just cut this line to mb = module_builder.module_builder_t(files=[r"all.h"]) and now the generated module is empty in my example directory. I attached files needed to reproduce the problem. What am I doing wrong ? Sorry if this question is trivial. I'm using Py++ 0.9 (installed from sources) pygccxml-0.9 and gccxml 0.7.0+cvs20060311-2 (debian Etch) Best Regards, Adrien Saladin -------------- next part -------------- #include "coord3d.h" -------------- next part -------------- A non-text attachment was scrubbed... Name: coord3d.cpp Type: text/x-c++src Size: 172 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: coord3d.h Type: text/x-c++hdr Size: 735 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: interface.py Type: application/x-python Size: 454 bytes Desc: not available URL: From groups at DavidBrownell.com Tue Jun 19 17:31:37 2007 From: groups at DavidBrownell.com (David Brownell) Date: Tue, 19 Jun 2007 15:31:37 +0000 (UTC) Subject: [C++-sig] Share C++ Object Extended in Python? References: <7465b6170706190042l2e5ad771w3ee110abfe58b8a2@mail.gmail.com> Message-ID: This fixed the problem - thank you very much! Who knew it would be so easy!? :) > Try to add call to tester.Events.__init__. Does it help? From roman.yakovenko at gmail.com Tue Jun 19 19:53:58 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 19 Jun 2007 20:53:58 +0300 Subject: [C++-sig] Py++: absolute or relative PATH for parsed files In-Reply-To: <200706191605.57333.adrien-ml@wizzi.net> References: <200706191605.57333.adrien-ml@wizzi.net> Message-ID: <7465b6170706191053r60d03e0ap798dab34184bec1d@mail.gmail.com> On 6/19/07, Adrien Saladin wrote: > Hello, > > I am switching from Pyste to Py++ for my project. Thanks for this great tool ! > (and for boost python of course). Thanks for nice words, but I cannot take credit for Boost.Python. David Abrahams and others are "the guilty party" :-) > I still have some problem with absolute and relative file paths: > > I have a file called "all.h" which only contains #include directives for the > other .h files. > > In the Py++ driver file, when I use this first line, the bindings are > generated: > mb = module_builder.module_builder_t(files=[r"/nfs/to/my/home/Src/Tests/Python/Py++/all.h"]) > > As this way is not portable because of the absolte path, I just cut this line > to > mb = module_builder.module_builder_t(files=[r"all.h"]) > > and now the generated module is empty in my example directory. > I attached files needed to reproduce the problem. > > What am I doing wrong ? > Sorry if this question is trivial. No the question is not trivial, Py++ has this usability bug that I should fix and I will do for next release. Read "Caveats" section in the document: http://www.language-binding.net/pyplusplus/documentation/best_practices.html Another solution is to use include\exclude functionality to define subset of declarations you want to export: mb = module_builder.module_builder_t(files=[r"all.h"]) mb.namespace( 'PTools' ).include() #this will expose all declaration from the namespace HTH P.S. Thanks for bug reporting. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeff.webb at nta-inc.net Tue Jun 19 22:32:53 2007 From: jeff.webb at nta-inc.net (Jeff Webb) Date: Tue, 19 Jun 2007 15:32:53 -0500 Subject: [C++-sig] using intrusive_ptr objects with boost python Message-ID: <46783D75.4050600@nta-inc.net> Let me first say that I am extremely impressed with boost python's elegant and powerful design. I would not have thought that it was possible to integrate C++ and python code in such a nice manner. Thanks for all the hard work and thoughtful design. I am writing a C++ library from scratch, and I want to develop boost python bindings for it simultaneously. My C++ library will instantiate many small objects that hold references to other objects. I had come up a consistent scheme for managing the objects using C++, but when I started trying to wrap the library using boost, I found that this scheme didn't mesh well with python's reference counting form of memory management. After quite a bit of reading, experimentation, and contemplation, it appears to me that using reference-counting smart pointers in C++ would be the most consistent and seamless way to provide a rich python binding for this type of library. Do others agree with this assertion? I wrote a simple test library using shared_ptr objects and found that wrapping it was very natural. Things 'just worked' as I would have hoped. The source code for this library is attached to this email as 's_ptr_lib.cpp'. A sample ipython session is shown below. In [1]: from s_ptr_lib import * In [2]: c1 = C('c1'); c2 = C('c2') C(c1) C(c2) In [3]: c1.set_ptr(c2) In [4]: ptr = c1.get_ptr() In [5]: ptr is c2 Out[5]: True In [6]: del(c2) In [7]: del(ptr) In [8]: del(c1) ~C(c1) ~C(c2) Very nice! Unfortunately, I think the overhead of using a shared_ptr will be too high, since my library will instantiate many small objects. I then discovered the intrusive_ptr, and I think it would be a better choice. I then converted my library to use intrusive_ptrs instead of shared_ptrs. The source code for this library is attached as 'i_ptr_lib.cpp'. When I tried to use this library from python, I found that the intrusive_ptr was not as well supported as the shared_ptr. A sample ipython session is shown below: In [1]: from i_ptr_lib import * In [2]: c1 = C('c1'); c2 = C('c2') C(c1) C(c2) In [3]: c1.set_ptr(c2) ------------------------------- Boost.Python.ArgumentError Traceback (most recent call last) ArgumentError: Python argument types in C.set_ptr(C, C) did not match C++ signature: set_ptr(C {lvalue}, boost::intrusive_ptr) It seems that I will need to supply all the necessary type conversions for the intrusive_ptr. I was hoping to not have to dig that deep into boost python's template magic at this point... Is there any good documentation on how to do this? I found the following post that seemed promising: http://mail.python.org/pipermail/c++-sig/2007-February/011961.html I downloaded the 'register_intrusive_ptr_from_python.hpp' and 'intrusive_ptr_from_python.hpp' file attachments from the above link and then modified my i_ptr_lib.cpp program by adding '#include register_intrusive_ptr_from_python.hpp' near the top, and this line after the end of the class_ declaration: boostPatch::register_intrusive_ptr_from_python_and_casts( (C *)0, class_::metadata::bases() ); I then tested the library again: In [1]: from i2_ptr_lib import * In [2]: c1 = C('c1'); c2 = C('c2') C(c1) C(c2) In [3]: c1.set_ptr(c2) In [4]: del(c2) ~C(c2) In [5]: c1.get_ptr() ------------------------ exceptions.TypeError Traceback (most recent call last) TypeError: No to_python (by-value) converter found for C++ type: boost::intrusive_ptr The set_ptr method no longer generates an exception, but c2's lifetime is not tied to c1 like it is for the shared_ptr version (the destructor gets called when c2 gets deleted). Another type conversion problem pops up in 'In[5]'. Am I on the right path here? Is it possible to make the intrusive_ptr work as seamlessly as the shared_ptr, or is there some fundamental problem with what I hope to achieve? Is there some technical reason why this is not already implemented, or is it just that there hasn't been a need up to this point? If I should continue down this path, can someone give me a skeleton of the code I need to write (and how to get it 'registered') to provide all the functionality that exists for the shared_ptr class? Thanks again, Jeff Webb s_ptr_lib.cpp -------------------------------------------------------------- #include #include #include #include using namespace std; using namespace boost; using namespace boost::python; class C; typedef shared_ptr CPtr; class C { public: C(const string &s) : name(s) { cout << "C(" << name << ")" << endl; } ~C() { cout << "~C(" << name << ")" << endl; } void set_ptr(CPtr ptr) { this->ptr = ptr; } void clear_ptr() { ptr.reset(); } CPtr get_ptr() { return ptr; } private: string name; CPtr ptr; }; BOOST_PYTHON_MODULE(s_ptr_lib) { class_("C", init()) .def("set_ptr", &C::set_ptr) .def("clear_ptr", &C::set_ptr) .def("get_ptr", &C::get_ptr) ; } i_ptr_lib.cpp -------------------------------------------------------------- #include #include #include #include using namespace std; using namespace boost; using namespace boost::python; class C; typedef intrusive_ptr CPtr; namespace boost { void intrusive_ptr_add_ref(C * ptr); void intrusive_ptr_release(C * ptr); } class C { public: C(const string &s) : name(s) { cout << "C(" << name << ")" << endl; } ~C() { cout << "~C(" << name << ")" << endl; } void set_ptr(CPtr ptr) { this->ptr = ptr; } void clear_ptr() { intrusive_ptr_release((C*) ptr.get()); } CPtr get_ptr() { return ptr; } private: friend void boost::intrusive_ptr_add_ref(C * ptr); friend void boost::intrusive_ptr_release(C * ptr); string name; CPtr ptr; int ref_count; }; namespace boost { inline void intrusive_ptr_add_ref(C * ptr) { ++(ptr->ref_count); } void intrusive_ptr_release(C * ptr) { if (--(ptr->ref_count) == 0) delete ptr; } } BOOST_PYTHON_MODULE(i_ptr_lib) { class_("C", init()) .def("set_ptr", &C::set_ptr) .def("clear_ptr", &C::set_ptr) .def("get_ptr", &C::get_ptr) ; } From adrien-ml at wizzi.net Wed Jun 20 16:19:58 2007 From: adrien-ml at wizzi.net (Adrien Saladin) Date: Wed, 20 Jun 2007 16:19:58 +0200 Subject: [C++-sig] Py++: absolute or relative PATH for parsed files In-Reply-To: <7465b6170706191053r60d03e0ap798dab34184bec1d@mail.gmail.com> References: <200706191605.57333.adrien-ml@wizzi.net> <7465b6170706191053r60d03e0ap798dab34184bec1d@mail.gmail.com> Message-ID: <200706201619.58569.adrien-ml@wizzi.net> Le mardi 19 juin 2007 19:53, Roman Yakovenko a ?crit?: > No the question is not trivial, Py++ has this usability bug that I should > fix and I will do for next release. > Read "Caveats" section in the document: > http://www.language-binding.net/pyplusplus/documentation/best_practices.htm >l > > Another solution is to use include\exclude functionality to define subset > of declarations you want to export: The first solution works very well. Thanks. Adrien From jfbosch at ucdavis.edu Thu Jun 21 22:49:55 2007 From: jfbosch at ucdavis.edu (Jim Bosch) Date: Thu, 21 Jun 2007 13:49:55 -0700 Subject: [C++-sig] boost::python, PyObject* members, and cyclic references Message-ID: <467AE473.20204@physics.ucdavis.edu> I am trying to wrap a class in which I'd like to expose some of its data as a numpy array, so in python it works like this: >>> o = array_holder() >>> a = o.array >>> a[4:6] = 3.14 Rather than constructing the array every time, I'd like to store the PyObject* (or something equivalent) in my array_holder wrapper, but I need to tie the lifetimes of 'o' and 'a' together, so nothing bad happens if someone does 'del o' while 'a' still exists. The numpy array I'm constructing holds a reference to the PyObject that owns its data (which I assume I can get from 'object(this).ptr()'), so I'm not worried about that end. And I assume something like 'return_internal_reference' is what I'm looking for at the other end, but I'm not quite sure how to work out the details (do I return a 'PyObject*', a 'handle', or an 'object'?) Finally, there's the question of whether either of these will ever get deleted at all - do boost::python wrapped objects participate in cyclic gc? If not, is there any way I can manually add it for this class (by suppling traverse and clear methods using the C API, for instance)? Thanks! Jim Bosch From fullung at gmail.com Thu Jun 21 23:19:03 2007 From: fullung at gmail.com (Albert Strasheim) Date: Thu, 21 Jun 2007 23:19:03 +0200 Subject: [C++-sig] boost::python, PyObject* members, and cyclic references References: <467AE473.20204@physics.ucdavis.edu> Message-ID: <002e01c7b449$cc161500$0100a8c0@sun.ac.za> Hello all ----- Original Message ----- From: "Jim Bosch" To: Sent: Thursday, June 21, 2007 10:49 PM Subject: [C++-sig] boost::python, PyObject* members, and cyclic references >I am trying to wrap a class in which I'd like to expose some of its data > as a numpy array, so in python it works like this: > > >>> o = array_holder() > >>> a = o.array > >>> a[4:6] = 3.14 > > Rather than constructing the array every time, I'd like to store the > PyObject* (or something equivalent) in my array_holder wrapper, but I > need to tie the lifetimes of 'o' and 'a' together, so nothing bad > happens if someone does 'del o' while 'a' still exists. You might be interested in this code for some inspiration: http://pyspkrec.googlecode.com/svn/trunk/numpycpp/ It implements __array_struct__ for some uBLAS and multi_array stuff and has some ideas for automatically converting a wrapper object to a NumPy array and vice versa when returning from C++ or calling into C++, respectively. __array_struct__ is described here: http://numpy.scipy.org/array_interface.shtml Cheers, Albert From Matt.Knox at tdam.com Fri Jun 22 20:34:42 2007 From: Matt.Knox at tdam.com (Knox, Matt) Date: Fri, 22 Jun 2007 14:34:42 -0400 Subject: [C++-sig] problems building Boost.Python with cygwin Message-ID: Hello all, Apologies in advance if this is not the correct forum for this... but I am trying to install the Boost.Python library (and then compile C++ python extensions after that) using cygwin and am not having much luck. I know I have the main part of boost working because I was able to compile and run the basic example for testing the boost configuration. Then to install Boost.Python I do the following: $ ./configure -with-libraries=python This generates the following output: Building Boost.Jam with toolset gcc... tools/jam/src/bin.cygwinx86/bjam Detecting Python version... 2.5 Detecting Python root... c:\Python25 Unicode/ICU support for Boost.Regex?... not found. Backing up existing Boost.Build configuration in user-config.jam.2 Generating Boost.Build configuration in user-config.jam... Generating Makefile... I then type "make install", which generates the following output: ./tools/jam/src/bin.cygwinx86/bjam --user-config=user-config.jam --prefix=/usr/local --exec-prefix= /usr/local --libdir=/usr/local/lib --includedir=/usr/local/include --with-python install WARNING: No python installation configured and autoconfiguration failed. See http://www.boost.org/libs/python/doc/building.html for configuration instructions or pass --without-python to suppress this message and silently skip all Boost.Python targets warning: Python location is not configured warning: the Boost.Python library won't be built warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned warning: Unable to construct ./install-unversioned ...found 7812 targets... Those warnings look rather problematic. And indeed, when I try to compile the basic example (/boost_1_34_0/libs/python/example/tutorial) by typing "bjam target-os=cygwin toolset=gcc", I get the following errors: Jamroot:17: in modules.load rule python-extension unknown in module Jamfile. /cygdrive/p/c_libs/boost_1_34_0/tools/build/v2/build/project.jam:312: in load-jamfile /cygdrive/p/c_libs/boost_1_34_0/tools/build/v2/build/project.jam:68: in load /cygdrive/p/c_libs/boost_1_34_0/tools/build/v2/build/project.jam:170: in project.find /cygdrive/p/c_libs/boost_1_34_0/tools/build/v2/build-system.jam:237: in load /cygdrive/p/c_libs/boost_1_34_0/libs/python/example/../../../tools/build /v2/kernel/modules.jam:261: in import /cygdrive/p/c_libs/boost_1_34_0/libs/python/example/../../../tools/build /v2/kernel/bootstrap.jam:132 : in boost-build /cygdrive/p/c_libs/boost_1_34_0/libs/python/example/boost-build.jam:7: in module scope Any ideas? Am I missing something obvious? Any help would be greatly appreciated. Thanks, - Matt - ******************** NOTICE OF CONFIDENTIALITY This communication including any information transmitted with it is intended only for the use of the addressees and is confidential. If you are not an intended recipient or responsible for delivering the message to an intended recipient, any review, disclosure, conversion to hard copy, dissemination, reproduction or other use of any part of this communication is strictly prohibited, as is the taking or omitting of any action in reliance upon this communication. If you receive this communication in error or without authorization please notify us immediately by return e-mail or otherwise and permanently delete the entire communication from any computer, disk drive, or other storage medium. If the above disclaimer is not properly readable, it can be found at www.td.com/legal AVERTISSEMENT DE CONFIDENTIALITE Ce courriel, ainsi que tout renseignement ci-inclus, destin? uniquement aux destinataires susmentionn?s, est confidentiel. Si vous n??tes pas le destinataire pr?vu ou un agent responsable de la livraison de ce courriel, tout examen, divulgation, copie, impression, reproduction, distribution, ou autre utilisation d?une partie de ce courriel est strictement interdit de m?me que toute intervention ou abstraction ? cet ?gard. Si vous avez re?u ce message par erreur ou sans autorisation, veuillez en aviser imm?diatement l?exp?diteur par retour de courriel ou par un autre moyen et supprimer imm?diatement cette communication enti?re de tout syst?me ?lectronique. Si l'avis de non-responsabilit? ci-dessus n'est pas lisible, vous pouvez le consulter ? www.td.com/francais/legale -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Jun 23 20:08:55 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 23 Jun 2007 21:08:55 +0300 Subject: [C++-sig] using intrusive_ptr objects with boost python In-Reply-To: <46783D75.4050600@nta-inc.net> References: <46783D75.4050600@nta-inc.net> Message-ID: <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> On 6/19/07, Jeff Webb wrote: > Let me first say that I am extremely impressed with boost python's elegant and powerful design. I would not have thought that it was possible to integrate C++ and python code in such a nice manner. Thanks for all the hard work and thoughtful design. > > I am writing a C++ library from scratch, and I want to develop boost python bindings for it simultaneously. My C++ library will instantiate many small objects that hold references to other objects. I had come up a consistent scheme for managing the objects using C++, but when I started trying to wrap the library using boost, I found that this scheme didn't mesh well with python's reference counting form of memory management. After quite a bit of reading, experimentation, and contemplation, it appears to me that using reference-counting smart pointers in C++ would be the most consistent and seamless way to provide a rich python binding for this type of library. Do others agree with this assertion? This is was my experience. > I wrote a simple test library using shared_ptr objects and found that wrapping it was very natural. Things 'just worked' as I would have hoped. The source code for this library is attached to this email as 's_ptr_lib.cpp'. A sample ipython session is shown below. Boost.Python has perfect support for boost::shared_ptr and in some cases to std::auto_ptr > Very nice! Unfortunately, I think the overhead of using a shared_ptr will be too high, since my library will instantiate many small objects. It looks like you know what you are doing, but don't you think this is a premature optimization? > Am I on the right path here? Is it possible to make the intrusive_ptr work as seamlessly as the shared_ptr, or is there some fundamental problem with what I hope to achieve? It is possible to create code that will work pretty closed to as shared_ptr one. If you search this mailing list you will even find the implementation. > Is there some technical reason why this is not already implemented, or is it just that there hasn't been a need up to this point? Boost.Python has special code that treats shared_ptr here and there. > If I should continue down this path, can someone give me a skeleton of the code I need to write (and how to get it 'registered') to provide all the functionality that exists for the shared_ptr class? > Just search this mailing list for "intrusive_ptr" and you will find many useful posts. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From kanand at qualcomm.com Tue Jun 26 00:27:48 2007 From: kanand at qualcomm.com (Anand, Kumar) Date: Mon, 25 Jun 2007 15:27:48 -0700 Subject: [C++-sig] Py++: How to specify noncopyable In-Reply-To: <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> Message-ID: I have a class in C++ which does not have the copy ctor or assignment operator as private. But I want to expose the class to python using Py++ and mark it boost::noncopyable. How do I do it in Py++? Thanks Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Jun 26 06:15:33 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 26 Jun 2007 07:15:33 +0300 Subject: [C++-sig] Py++: How to specify noncopyable In-Reply-To: References: <7465b6170706231108x152b8174xc90e0fb06904aec6@mail.gmail.com> Message-ID: <7465b6170706252115uca79be3qe795a0c6c54bbc9@mail.gmail.com> On 6/26/07, Anand, Kumar wrote: > > I have a class in C++ which does not have the copy ctor or assignment > operator as private. But I want to expose the class to python using Py++ and > mark it boost::noncopyable. > > How do I do it in Py++? I'll be surprised if Py++ will not do this for you. Anyway you can set noncopyable property to True ( http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.decl_wrappers.class_wrapper.class_t-class.html#noncopyable ) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From p.jaroszynski at gmail.com Mon Jun 25 23:00:48 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Mon, 25 Jun 2007 23:00:48 +0200 Subject: [C++-sig] docstring in enum Message-ID: <200706252300.49268.p.jaroszynski@gmail.com> Hello, Is it somehow possible to add docstring to enum_? I tried with PyObject_SetAttrString, but it doesn't work. Don't you think that docstrings would be useful in enums as well? -- Best Regards, Piotr Jaroszy?ski From eric.mahurin at gmail.com Tue Jun 26 20:34:35 2007 From: eric.mahurin at gmail.com (Eric Mahurin) Date: Tue, 26 Jun 2007 13:34:35 -0500 Subject: [C++-sig] Using boost.python to get STL containers of PyObect's. Message-ID: <29256ea00706261134j3b73037fy7c2fed067fe127f@mail.gmail.com> Hi, I'm new to the list and coming from using SWIG w/ python. I haven't used boost.python, but am considering it because of frustration with SWIG. With SWIG, I've been able to make changes to some of the existing SWIG/STL infrastructure to get to this point: * STL containers of a wrapped PyObject* (handles reference counting) * Support of using a callable PyObject* as a BinaryPredicate and other template function concepts in STL. This allows using a python lamda/function/method as the comparison function for various methods/constructors. * python read/write access to STL iterators * wrap any STL algorithm to be used with the above wrapped STL iterators. I should have made it work with any python object that implemented the python-STL iterator i/f, but for now it has to be one of these swig-wrapped STL iterators. Here are the problems: * various STL methods are missing, especially some of the overloaded methods. * STL big-O performance is not alway preserved. I think I've fixed the major issues (I've seen O(n**3) when it should be O(n)), but I'm sure there are others. * hacky and incomplete iterator API I'm getting tired of wading through the multiple layers and confusion that SWIG puts in to finish this. I think what is most bothersome is the way type conversion and overloading is handled. I'd rather see SWIG only try to distinguish between overloaded functions/methods by number of arguments. You'd be forced to rename otherwise. IMHO, overloading by type doesn't mix with a dynamically typed language (i.e. duck-typed). Has anybody done some similar with boost.python? Eric From roman.yakovenko at gmail.com Tue Jun 26 21:15:14 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 26 Jun 2007 22:15:14 +0300 Subject: [C++-sig] Using boost.python to get STL containers of PyObect's. In-Reply-To: <29256ea00706261134j3b73037fy7c2fed067fe127f@mail.gmail.com> References: <29256ea00706261134j3b73037fy7c2fed067fe127f@mail.gmail.com> Message-ID: <7465b6170706261215k732d432i1d365a5a8062574e@mail.gmail.com> On 6/26/07, Eric Mahurin wrote: > Hi, I'm new to the list and coming from using SWIG w/ python. I > haven't used boost.python, but am considering it because of > frustration with SWIG. > > With SWIG, I've been able to make changes to some of the existing > SWIG/STL infrastructure to get to this point: > > * STL containers of a wrapped PyObject* (handles reference counting) I guess boost::python::object will do this for you http://boost.org/libs/python/doc/v2/object.html > * Support of using a callable PyObject* as a BinaryPredicate and other > template function concepts in STL. This allows using a python > lamda/function/method as the comparison function for various > methods/constructors. I am not sure whether this directly supported or not, but small wrapper around next functions will do the job: http://boost.org/libs/python/doc/v2/call.html http://boost.org/libs/python/doc/v2/call_method.html > * python read/write access to STL iterators We call this indexing suite: http://boost.org/libs/python/doc/v2/indexing.html http://www.language-binding.net/pyplusplus/documentation/containers.html > * wrap any STL algorithm to be used with the above wrapped STL > iterators. I should have made it work with any python object that > implemented the python-STL iterator i/f, but for now it has to be one > of these swig-wrapped STL iterators. Well, only instantiation could be exposed. I guess this is not different from any other tool\framework > Here are the problems: > > * various STL methods are missing, especially some of the overloaded methods. You can find such problems in this library too > * STL big-O performance is not alway preserved. I think I've fixed > the major issues (I've seen O(n**3) when it should be O(n)), but I'm > sure there are others. I guess the wrappers preserve the performance, at least I didn't see something strange > * hacky and incomplete iterator API Boost.Python provides "Python-like" API for iterators. It doesn't try to expose 5 iterator categories. > I'm getting tired of wading through the multiple layers and confusion > that SWIG puts in to finish this. I think what is most bothersome is > the way type conversion and overloading is handled. I'd rather see > SWIG only try to distinguish between overloaded functions/methods by > number of arguments. You'd be forced to rename otherwise. IMHO, > overloading by type doesn't mix with a dynamically typed language > (i.e. duck-typed). No problem here. Overloading just works. For type conversion take a look on next link: http://www.language-binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/automatic_conversion.html > Has anybody done some similar with boost.python? All the time :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From oanjao at yahoo.com Wed Jun 27 00:01:24 2007 From: oanjao at yahoo.com (Craig Finch) Date: Tue, 26 Jun 2007 15:01:24 -0700 (PDT) Subject: [C++-sig] Extracting C++ objects of different types from a Python list Message-ID: <226587.23955.qm@web30309.mail.mud.yahoo.com> I have run into a problem that I don't know how to solve with Boost.python, and I can't find the answer online. I have a list of objects in Python, and the objects are of different classes. All the classes are derived from a common base class, and the classes are defined in C++ and exposed to Python. The list of objects is created in Python, and I would like to get this list into C++, where the the objects of different types will be handled differently. I can bring the list into C++ as a boost::python::list, but then I have to use extract to get the individual objects from the list. The problem is that extract works, but then all of the extracted objects are the same type. The information contained in the derived types is lost. Is it possible to do this with boost.python? Should I be thinking of a different way to design the code so that I can pass in a list of objects from a single class? Sincerely, Craig Finch -------------- Please reply to cfinch at ieee.org ____________________________________________________________________________________ Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. http://tv.yahoo.com/collections/222 From roman.yakovenko at gmail.com Wed Jun 27 09:58:24 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 27 Jun 2007 10:58:24 +0300 Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: <226587.23955.qm@web30309.mail.mud.yahoo.com> References: <226587.23955.qm@web30309.mail.mud.yahoo.com> Message-ID: <7465b6170706270058u2c10a708q485e5fe6d977893d@mail.gmail.com> On 6/27/07, Craig Finch wrote: > I have run into a problem that I don't know how to solve with > Boost.python, and I can't find the answer online. I have a list of > objects in Python, and the objects are of different classes. All the > classes are derived from a common base class, and the classes are > defined in C++ and exposed to Python. The list of objects is created > in Python, and I would like to get this list into C++, where the the > objects of different types will be handled differently. I can bring > the list into C++ as a boost::python::list, but then I have to use > extract to get the individual objects from the list. The > problem is that extract works, but then all of the extracted > objects are the same type. The information contained in the derived > types is lost. Try to extract "baseclass&". -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Wed Jun 27 14:43:52 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 27 Jun 2007 05:43:52 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) Message-ID: <11323712.post@talk.nabble.com> Hi! I've trying to use py++ for my project, it seems like a great tool but I feel a bit lost and I need your help ! I've installed gccxml,pygccxml, boost, python and py++ in their latest version but I'm having problems when it comes to use py++ ( gui ) on my project files! I'm currently testing it on very simple declaration files (no templates .., only simple functions) but I'm having gccxml errors during the code generation. "Error occured while running GCC-XML: C:/projet/include/Address.h:11: error: syntax error before `&' token" And here is the Address.h's 11th line : Address(Inet& ip,unsigned short port); The problem obliviously seems to be the Inet type (which is defined in an other .h file in the same directory as Address.h) that GCCXML doesn't recognize. But I don't know how to solve this problem. If I comment this line py++ works great. Being completely noob in boost.pyhton and py++ and afraid i'm missing an important step. :( Is this the case ? Thank you and sorry for my simple English ... -- View this message in context: http://www.nabble.com/Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11323712 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Wed Jun 27 14:56:55 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 27 Jun 2007 15:56:55 +0300 Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <11323712.post@talk.nabble.com> References: <11323712.post@talk.nabble.com> Message-ID: <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> On 6/27/07, Coockie_jr wrote: > > Hi! > I've trying to use py++ for my project, it seems like a great tool but I > feel a bit lost and I need your help ! > > I've installed gccxml,pygccxml, boost, python and py++ in their latest > version but I'm having problems when it comes to use py++ ( gui ) on my > project files! > > I'm currently testing it on very simple declaration files (no templates .., > only simple functions) but I'm having gccxml errors during the code > generation. > > "Error occured while running GCC-XML: C:/projet/include/Address.h:11: error: > syntax error before `&' token" > > And here is the Address.h's 11th line : > > Address(Inet& ip,unsigned short port); > > > The problem obliviously seems to be the Inet type (which is defined in an > other .h file in the same directory as Address.h) that GCCXML doesn't > recognize. But I don't know how to solve this problem. > If I comment this line py++ works great. > > Being completely noob in boost.pyhton and py++ and afraid i'm missing an > important step. :( > Is this the case ? > I don't think you are missing something. Did you succeed to compile the files with your compiler? Can you post small & complete example that reproduce the problem? Py++ GUI also has an option to add include paths, did you tried it? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Wed Jun 27 16:17:08 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 27 Jun 2007 07:17:08 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> Message-ID: <11325302.post@talk.nabble.com> Roman Yakovenko wrote: > > > >>>>I don't think you are missing something. Did you succeed to compile the files with your compiler? > I managed to compile the files when removing the external references ( in > this example the Inet type). Bjam generated the .pyd file without any > problems :) > >>>>Can you post small & complete example that reproduce the problem? > Here's my simple example Address.h > > class Address > { > unsigned long m_ip; > unsigned short m_port; > public: > Address(void); > Address(unsigned long ip,unsigned short port); > Address(Inet& ip,unsigned short port); // Here's the "Inet" problem > Address(char* addr,unsigned short port); > ~Address(void); > > unsigned long getIp()const{ > return m_ip; > } > > void setIp(unsigned long ip){ > m_ip = ip; > } > > unsigned short getPort()const{ > return m_port; > } > > void setPort(unsigned short port){ > m_port = port; > } > > > }; > > > > > >>>>Py++ GUI also has an option to add include paths, did you tried it? > Yes I set the path to the directory with all my header files, though it > would be the solution but I guess not > > > Thanks for your time > > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11325302 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Wed Jun 27 16:24:42 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 27 Jun 2007 17:24:42 +0300 Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <11325302.post@talk.nabble.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> Message-ID: <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> On 6/27/07, Coockie_jr wrote: > >>>>Can you post small & complete example that reproduce the problem? > > Here's my simple example Address.h > > > > class Address{...} It looks like this header doesn't contain any include or forward declaration of Inet. I think this is a mistake -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Wed Jun 27 16:39:58 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Wed, 27 Jun 2007 07:39:58 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> Message-ID: <11325785.post@talk.nabble.com> Hmmm I "only" forgot to post the most important patr of the file ... I edited it ... Anyway I think I found the solution, my Inet.h doesn't seem up to date especially in it's own dependencies ... Once again thank you for your time. Roman Yakovenko wrote: > > On 6/27/07, Coockie_jr wrote: >> >>>>Can you post small & complete example that reproduce the problem? >> > Here's my simple example Address.h >> > >> > class Address{...} > > It looks like this header doesn't contain any include or forward > declaration of Inet. > > I think this is a mistake > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11325785 Sent from the Python - c++-sig mailing list archive at Nabble.com. From oanjao at yahoo.com Wed Jun 27 20:06:08 2007 From: oanjao at yahoo.com (Craig Finch) Date: Wed, 27 Jun 2007 11:06:08 -0700 (PDT) Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: <7465b6170706270058u2c10a708q485e5fe6d977893d@mail.gmail.com> Message-ID: <954025.92821.qm@web30311.mail.mud.yahoo.com> Thank you for the suggestion--unfortunately it does not seem to work for me. In my Python code, I verified that the list is composed of different types of objects. However, in C++ I tried std::cout << typeid(extract(myList[j])).name(); and it shows that all of the extracted objects are of the same class (baseclass). Any other ideas? I want to be able to do the following in C++: for (i=0 to length of list) list[i].evaluate(); where the "evaluate" method is different depending on what kind of object is pulled from the list. Craig Finch --- Roman Yakovenko wrote: > On 6/27/07, Craig Finch wrote: > > I have run into a problem that I don't know how to solve with > > Boost.python, and I can't find the answer online. I have a list of > > objects in Python, and the objects are of different classes. All > the > > classes are derived from a common base class, and the classes are > > defined in C++ and exposed to Python. The list of objects is > created > > in Python, and I would like to get this list into C++, where the > the > > objects of different types will be handled differently. I can > bring > > the list into C++ as a boost::python::list, but then I have to use > > extract to get the individual objects from the list. The > > problem is that extract works, but then all of the > extracted > > objects are the same type. The information contained in the > derived > > types is lost. > > Try to extract "baseclass&". > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > -------------- Please reply to cfinch at ieee.org ___________________________________________________________________________________ You snooze, you lose. Get messages ASAP with AutoCheck in the all-new Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/newmail_html.html From amohr at pixar.com Wed Jun 27 20:12:18 2007 From: amohr at pixar.com (Alex Mohr) Date: Wed, 27 Jun 2007 11:12:18 -0700 Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: <954025.92821.qm@web30311.mail.mud.yahoo.com> References: <954025.92821.qm@web30311.mail.mud.yahoo.com> Message-ID: <4682A882.6090305@pixar.com> Craig Finch wrote: > Thank you for the suggestion--unfortunately it does not seem to work > for me. In my Python code, I verified that the list is composed of > different types of objects. However, in C++ I tried > > std::cout << typeid(extract(myList[j])).name(); > > and it shows that all of the extracted objects are of the same class > (baseclass). Any other ideas? I want to be able to do the following > in C++: > > for (i=0 to length of list) > list[i].evaluate(); > > where the "evaluate" method is different depending on what kind of > object is pulled from the list. Sorry if this feels like an "is it plugged in" type of question, but your baseclass is polymorphic (has virtual methods) right? And when you wrap the derived classes, you use boost::python::bases<> to inform the library of the hierarchy, yes? If you could post a minimal, complete example, it would be easier to diagnose the problem. Alex From seefeld at sympatico.ca Wed Jun 27 20:48:38 2007 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 27 Jun 2007 14:48:38 -0400 Subject: [C++-sig] docstring in enum In-Reply-To: <200706252300.49268.p.jaroszynski@gmail.com> References: <200706252300.49268.p.jaroszynski@gmail.com> Message-ID: <4682B106.4080405@sympatico.ca> Piotr Jaroszy?ski wrote: > Hello, > > Is it somehow possible to add docstring to enum_? I tried with > PyObject_SetAttrString, but it doesn't work. Don't you think that docstrings > would be useful in enums as well? docstrings are attached to modules, classes and functions in python, not arbitrary objects (read: only these have a __doc__ member). What would the document string you provide be bound to, in case of an enum ? It just maps to an int anyway... Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From p.jaroszynski at gmail.com Wed Jun 27 21:21:10 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Wed, 27 Jun 2007 21:21:10 +0200 Subject: [C++-sig] docstring in enum In-Reply-To: <4682B106.4080405@sympatico.ca> References: <200706252300.49268.p.jaroszynski@gmail.com> <4682B106.4080405@sympatico.ca> Message-ID: <200706272121.10588.p.jaroszynski@gmail.com> On Wednesday 27 of June 2007 20:48:38 Stefan Seefeld wrote: > What would the document string you provide be bound to, in case of an enum > ? It just maps to an int anyway... I meant the "py_enum" which you get after bp::enum_("py_enum"); I want to add docstring to it describing its purpose and listing possible values. It seems to be not possible using the boost.python api as far as I can see, moreover bp seems to set the __doc__ as a readonlty attribute and hence using PyObject_SetAttrString on py_enum.ptr() doesn't work either. -- Best Regards, Piotr Jaroszy?ski From oanjao at yahoo.com Wed Jun 27 23:28:27 2007 From: oanjao at yahoo.com (Craig Finch) Date: Wed, 27 Jun 2007 14:28:27 -0700 (PDT) Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: <4682A882.6090305@pixar.com> Message-ID: <211080.1944.qm@web30309.mail.mud.yahoo.com> > If you could post a minimal, complete example, it would be easier to > diagnose the problem. Here is a simple example of what I am trying to do. There is no problem if I know in advance the class of the objects to be imported. However, I don't know the class until runtime, so I don't know how set the appropriate class for extract . ---------------- C++ CODE--------------- class BaseClass { public: virtual void evaluate(void); }; class A : public BaseClass { public: int index; virtual void evaluate(void); }; class B : public BaseClass { public: float value; virtual void evaluate(void); }; class Importer { public: void setList (boost::python::list l); }; void BaseClass::evaluate (void) { std::cout << "Useless base class" << std::endl; } void A::evaluate (void) { std::cout << "Index is " << index << std::endl; } void B::evaluate (void) { std::cout << "Value is " << value << std::endl; } using namespace boost::python; void BaseClass::evaluate (void) { std::cout << "Useless base class" << std::endl; } void A::evaluate (void) { std::cout << "Index is " << index << std::endl; } void B::evaluate (void) { std::cout << "Value is " << value << std::endl; } void Importer::setList (list l) { BaseClass o; int len = extract(l.attr("__len__")()); for (int i=0; i (l[i])).name() << std::endl; o = extract (l[i]); o.evaluate(); } } BOOST_PYTHON_MODULE(C_test) { class_ ("BaseClass"); class_ > ("A") .def("evaluate", &A::evaluate) .def_readwrite("index", &A::index) ; class_ > ("B") .def("evaluate", &B::evaluate) .def_readwrite("value", &B::value) ; class_ ("Importer") .def("setList", &Importer::setList) ; } -------------- PYTHON CODE ------------------ import C_test # Derived Classes class A (C_test.A): def __init__ (self, int): C_test.A.__init__(self) self.index = int class B (C_test.B): def __init__ (self, float): C_test.B.__init__(self) self.value = float mixedList = [] mixedList.append(A(3)) mixedList.append(B(5.234)) imp = C_test.Importer() imp.setList(mixedList) --------------- OUTPUT ---------------- N5boost6python7extractIR9BaseClassEE Useless base class N5boost6python7extractIR9BaseClassEE Useless base class --------------------------------------- -------------- Please reply to cfinch at ieee.org ____________________________________________________________________________________ Never miss an email again! Yahoo! Toolbar alerts you the instant new Mail arrives. http://tools.search.yahoo.com/toolbar/features/mail/ From Lawrence.Spector at CanfieldSci.com Thu Jun 28 00:10:04 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Wed, 27 Jun 2007 18:10:04 -0400 Subject: [C++-sig] Boost.Python Memory Leaks? Message-ID: I was testing out some of my Boost.Python code using the Boost.Test framework. During the running, I got memory leaks reported. I ran a simple test to verify, which produced the following output: Running 1 test case... *** No errors detected Detected memory leaks! Dumping objects -> {168} normal block at 0x00366488, 12 bytes long. Data: < > 10 A5 03 10 A0 A5 03 10 00 00 00 00 {166} normal block at 0x003663F8, 12 bytes long. Data: < > C0 A2 03 10 80 A3 03 10 00 00 00 00 {164} normal block at 0x00366368, 12 bytes long. Data: < > D0 84 03 10 00 00 00 00 00 00 00 00 {163} normal block at 0x00366330, 8 bytes long. Data: < > D0 84 03 10 00 00 00 00 {161} normal block at 0x003662A0, 12 bytes long. Data: < > B0 A1 03 10 F0 A1 03 10 00 00 00 00 {159} normal block at 0x00366210, 12 bytes long. Data: < > B0 A0 03 10 F0 A0 03 10 00 00 00 00 {157} normal block at 0x00366180, 12 bytes long. Data:

70 9E 03 10 00 9F 03 10 00 00 00 00 {155} normal block at 0x003660F0, 12 bytes long. Data: <` > 60 9D 03 10 A0 9D 03 10 00 00 00 00 {153} normal block at 0x00366060, 12 bytes long. Data:

50 9C 03 10 90 9C 03 10 00 00 00 00 {151} normal block at 0x00365FD0, 12 bytes long. Data: <@ @ > 40 9A 03 10 40 9B 03 10 00 00 00 00 {149} normal block at 0x00365F40, 12 bytes long. Data: < > C0 98 03 10 00 99 03 10 00 00 00 00 {147} normal block at 0x00365EB0, 12 bytes long. Data: < > B0 96 03 10 80 97 03 10 00 00 00 00 {145} normal block at 0x00365E20, 12 bytes long. Data: < > A0 95 03 10 E0 95 03 10 00 00 00 00 {143} normal block at 0x00365D90, 12 bytes long. Data: < > 90 94 03 10 D0 94 03 10 00 00 00 00 {141} normal block at 0x00365D00, 12 bytes long. Data: < > 80 93 03 10 C0 93 03 10 00 00 00 00 {139} normal block at 0x00365C70, 12 bytes long. Data:

70 92 03 10 B0 92 03 10 00 00 00 00 {137} normal block at 0x00365BE0, 12 bytes long. Data: <` > 60 91 03 10 A0 91 03 10 00 00 00 00 {135} normal block at 0x00365B50, 12 bytes long. Data:

50 90 03 10 90 90 03 10 00 00 00 00 {133} normal block at 0x00365AC0, 12 bytes long. Data: < > B0 8E 03 10 80 8F 03 10 00 00 00 00 {131} normal block at 0x00365A30, 12 bytes long. Data: < > 10 8D 03 10 E0 8D 03 10 00 00 00 00 {129} normal block at 0x003659A0, 12 bytes long. Data: < > 90 8B 03 10 20 8C 03 10 00 00 00 00 Object dump complete. The code that produced this is as follows: BOOST_AUTO_TEST_CASE(testPythonDebugIntegration) { { Py_Initialize(); { boost::python::object m_mainModule((boost::python::handle<>( boost::python::borrowed(PyImport_AddModule("__main__"))))); boost::python::object m_mainNamespace(m_mainModule.attr("__dict__")); } Py_Finalize(); } } If I change the code to either of the following: 1) BOOST_AUTO_TEST_CASE(testPythonDebugIntegration) { { Py_Initialize(); { boost::python::object m_mainModule( ( boost::python::borrowed(PyImport_AddModule("__main__")))); } Py_Finalize(); } } OR 2) BOOST_AUTO_TEST_CASE(testPythonDebugIntegration) { { Py_Initialize(); { } Py_Finalize(); } } Then I get no memory leaks reported. Anyone have any clue why this is happening? The code I used was basically the suggested code from the Python tutorial from the Boost.Python page. Thanks in advance, Lawrence -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Thu Jun 28 05:39:14 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 27 Jun 2007 20:39:14 -0700 (PDT) Subject: [C++-sig] Boost.Python Memory Leaks? Message-ID: <379940.27910.qm@web31106.mail.mud.yahoo.com> This has come up many times before: Boost.Python doesn't support PyFinalize(). There is no way to cleanup the global type conversion registry. It wasn't on the agenda of the people funding Boost.Python version 2 development (i.e. embedding wasn't on the list of things considered important). The leaks are harmless. Just don't use PyFinalize() and ignore the memory occupied by the few globals Boost.Python instantiates. My way of finding "real" leaks is very simple: wrap your code in an endless loop and monitor the process with the top command (Linux or OSX). Let it run for a couple of hours and check again. I've done this many times (to check my own new C++ code). There are no "real" leaks in Python or Boost.Python. Ralf ____________________________________________________________________________________ Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From chryswoods at gmail.com Thu Jun 28 09:43:02 2007 From: chryswoods at gmail.com (Christopher Woods) Date: Thu, 28 Jun 2007 08:43:02 +0100 Subject: [C++-sig] Extracting C++ objects of different types from a Python list In-Reply-To: <211080.1944.qm@web30309.mail.mud.yahoo.com> References: <4682A882.6090305@pixar.com> <211080.1944.qm@web30309.mail.mud.yahoo.com> Message-ID: Hi Craig, I've played with your example and I've got it to work by changing your extract and extract into extract and extract. In the first case (extract) you were extracting the object in the list into a *copy*, which was of type BaseClass, so the "Useless base class" function of that copy was then called. By extracting into a pointer (via extract) you aren't performing a copy, and you obtain a polymorphic pointer to the original object. As for the typeid part of the example, I don't know why typeid gets it wrong when you use extract. I had to change this to extract and then do a typeid of the dereference of the resulting polymorphic pointer. Here is the modified version of 'setList' that worked on my box (linux, gcc 3.4, python 2.3); ============================== void Importer::setList (list l) { BaseClass *o; int len = extract(l.attr("__len__")()); for (int i=0; i (l[i])) ).name() << std::endl; o = extract (l[i]); o->evaluate(); } } ============================== This gave output; ============================== 1A Index is 3 1B Value is 5.234 ============================== I hope this helps, Christopher From achille.talon at gmail.com Thu Jun 28 10:10:04 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 28 Jun 2007 01:10:04 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> Message-ID: <11338838.post@talk.nabble.com> Hmmm I got another question regarding header files during the gccxml parsing. I have managed to make most of my files work (even with my own types ;) ) but I' having problems with vectors and probably other "functions". When I include I get the following errors Error occured while running GCC-XML: In file included from C:/Prog/GCC_XML/Support/Vc8/Include/iterator:6, from C:/Program Files/Microsoft Visual Studio 8/VC/include/memory:6, from C:/Prog/GCC_XML/Support/Vc8/Include/vector:6, from C:/Prog/Py++-0.9.0/build/scripts-2.5/include/project.h:1: C:/Prog/GCC_XML/Support/Vc8/Include/xutility:911: error: syntax error before `,' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility:957: error: syntax error before `,' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility:958: error: ` _Base_helper2' is not a class or namespace C:/Prog/GCC_XML/Support/Vc8/Include/xutility:958: error: ` _Checked_iterator_base_type' is not a class or namespace C:/Prog/GCC_XML/Support/Vc8/Include/xutility:958: error: ` _Base_helper2' fails to be a typedef or built in type C:/Prog/GCC_XML/Support/Vc8/Include/xutility:958: error: ISO C++ forbids declaration of `type name' with no type C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In member function `std::reverse_iterator::_Checked_iterator_base_type> std::reverse_iterator<_RanIt>::_Checked_iterator_base() const': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:1746: error: syntax error before `;' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `_OutElem* std::copy(_InIt, _InIt, _OutElem (&)[_Size])': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2364: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `_OutElem* std::_Move(_InIt, _InIt, _OutElem (&)[_Size])': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2438: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `std::pair<_InIt1, _InElem2*> std::mismatch(_InIt1, _InIt1, _InElem2 (&)[_Size])': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2662: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `std::pair<_InIt1, _InElem2*> std::mismatch(_InIt1, _InIt1, _InElem2 (&)[_Size], _Pr)': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2749: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `bool std::equal(_InIt1, _InIt1, _InElem2 (&)[_Size])': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2857: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `bool std::equal(_InIt1, _InIt1, _InElem2 (&)[_Size], _Pr)': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:2919: error: syntax error before `::' token C:/Prog/GCC_XML/Support/Vc8/Include/xutility: In function `void std::fill_n(_OutElem (&)[_Size], _Diff, const _Ty&)': C:/Prog/GCC_XML/Support/Vc8/Include/xutility:3065: error: syntax error before `::' token I've got the latest GCCXML and I don't think the solution would be top change those headers ... Is there a way to tell GCCXML not to look in some headers or something alike ? Thank you -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11338838 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Thu Jun 28 10:28:58 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 28 Jun 2007 11:28:58 +0300 Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <11338838.post@talk.nabble.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> <11338838.post@talk.nabble.com> Message-ID: <7465b6170706280128q7e8bdbb8y4845e9459b6f895c@mail.gmail.com> On 6/28/07, Coockie_jr wrote: > > Hmmm > I got another question regarding header files during the gccxml parsing. > > > I have managed to make most of my files work (even with my own types ;) ) > but I' having problems with vectors and probably other "functions". > > When I include I get the following errors > What is exactly the version of gccxml you are using? Try latest CVS version of GCCXMl. I think it solves the problem. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Thu Jun 28 11:14:56 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 28 Jun 2007 02:14:56 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <7465b6170706280128q7e8bdbb8y4845e9459b6f895c@mail.gmail.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> <11338838.post@talk.nabble.com> <7465b6170706280128q7e8bdbb8y4845e9459b6f895c@mail.gmail.com> Message-ID: <11339709.post@talk.nabble.com> gccxml -- version tells me 0.7.0 I downloaded and rebuild the cvs version and I still the the errors. Notice that I got an error during the gccxml built (with vc8) : the vcInstallPatch failed I don't know how important this part is. Roman Yakovenko wrote: > > On 6/28/07, Coockie_jr wrote: >> >> Hmmm >> I got another question regarding header files during the gccxml parsing. >> >> >> I have managed to make most of my files work (even with my own types ;) ) >> but I' having problems with vectors and probably other "functions". >> >> When I include I get the following errors >> > > What is exactly the version of gccxml you are using? > > Try latest CVS version of GCCXMl. I think it solves the problem. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11339709 Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Thu Jun 28 11:24:30 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 28 Jun 2007 12:24:30 +0300 Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <11339709.post@talk.nabble.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> <11338838.post@talk.nabble.com> <7465b6170706280128q7e8bdbb8y4845e9459b6f895c@mail.gmail.com> <11339709.post@talk.nabble.com> Message-ID: <7465b6170706280224y1447c0d3yd4a95348b393b05d@mail.gmail.com> On 6/28/07, Coockie_jr wrote: > > gccxml -- version tells me 0.7.0 > > I downloaded and rebuild the cvs version and I still the the errors. > > Notice that I got an error during the gccxml built (with vc8) : the > vcInstallPatch failed I don't know how important this part is. Very important: this functionality basically tells gccxml to "replace" the header files. Can you report the bug on gccxml mailing list? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From achille.talon at gmail.com Thu Jun 28 11:58:45 2007 From: achille.talon at gmail.com (Coockie_jr) Date: Thu, 28 Jun 2007 02:58:45 -0700 (PDT) Subject: [C++-sig] Using py++ GCCXML error (type definition ?) In-Reply-To: <7465b6170706280224y1447c0d3yd4a95348b393b05d@mail.gmail.com> References: <11323712.post@talk.nabble.com> <7465b6170706270556s66efe9c0v32bed7bca3cd2c7d@mail.gmail.com> <11325302.post@talk.nabble.com> <7465b6170706270724q7563a983h83945e8fb52a282c@mail.gmail.com> <11338838.post@talk.nabble.com> <7465b6170706280128q7e8bdbb8y4845e9459b6f895c@mail.gmail.com> <11339709.post@talk.nabble.com> <7465b6170706280224y1447c0d3yd4a95348b393b05d@mail.gmail.com> Message-ID: <11340265.post@talk.nabble.com> Done although the error log isn't very explicit :/ http://public.kitware.com/pipermail/gccxml/2007-June/000928.html Roman Yakovenko wrote: > > On 6/28/07, Coockie_jr wrote: >> >> gccxml -- version tells me 0.7.0 >> >> I downloaded and rebuild the cvs version and I still the the errors. >> >> Notice that I got an error during the gccxml built (with vc8) : the >> vcInstallPatch failed I don't know how important this part is. > > Very important: this functionality basically tells gccxml to "replace" > the header files. > > Can you report the bug on gccxml mailing list? > > Thanks > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--Using-py%2B%2B-GCCXML-error-%28type-definition--%29-tf3988097.html#a11340265 Sent from the Python - c++-sig mailing list archive at Nabble.com. From kir at lapshin.net Thu Jun 28 17:57:58 2007 From: kir at lapshin.net (Kirill Lapshin) Date: Thu, 28 Jun 2007 19:57:58 +0400 Subject: [C++-sig] [pygccxml] caching fails due to pickling recursion limit Message-ID: <4683DA86.3050204@lapshin.net> Hi Roman, everybody, First of all my apologies if it is a wrong list for pygccxml discussion. We are using py++/pygccxml on moderately sized project, and recently py++ started to fail silently on us. It runs gccxml and then silently quits. It turned out the offending piece of code was pickling cache. Something fails in cPickle and terminates the whole process. Most likely it is a stack overflow, because if cPickle replaced with pickle, then we get recursion limit runtime error. One can raise recursion limit and pickle will save cache just fine, but really slowly (not surprising at all). At the moment we've worked around this problem by disabling cache, however it would be nice to fix it properly. After reading a bit about pickling, it looks like (c)pickle don't work very well with recursive structures, which declarations obviously are. I just want to list some ideas I have on how to tackle this problem, and I would love to get some comments on their feasibility, or better yet alternative approaches. 1. Simple one, just set all parents to None before pickling and rebuild parents upon loading. Should be relatively simple, I'll try it first thing. Hopefully that would kill fair amount of recursion, but not all of it (e.g. class A refers to class B and B to A). 2. Add unique id to each declaration, have a global store that saves declarations by id, and define for each declaration __getstate__, __setstate__ that would serialize ids, rather then declaration instances. Then we just pickle the global store. In reality somewhat more complex approach needed to tackle recursive references. References: Reversible flatting out: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302535 Some details: we are running: Python 2.4.3 on Windows XP Py++/pygccxml 0.9 gccxml -- somewhat old CVS snapshot Kirill From Lawrence.Spector at CanfieldSci.com Thu Jun 28 19:51:41 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 28 Jun 2007 13:51:41 -0400 Subject: [C++-sig] Boost.Python Memory Leaks? In-Reply-To: <379940.27910.qm@web31106.mail.mud.yahoo.com> References: <379940.27910.qm@web31106.mail.mud.yahoo.com> Message-ID: If this is true, that's a little upsetting to hear. Boost is supposed to be one of the best and most complete libraries ever written. I haven't seen this awful practice elsewhere from within boost. Not releasing dynamically allocated memory is a bad programming practice and is not guaranteed to be freed on all platforms (although is on most). Furthermore, any destructors never get called. The Boost.Python group needs to address this issue, because IMHO this is a serious bug/design flaw. It also mucks with our tests, because we're working on making a set of automated tests and memory leaks are considered a type of failure. Why should poor programming practice inside Boost.Python be an exception? -Lawrence From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Wednesday, June 27, 2007 11:39 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python Memory Leaks? This has come up many times before: Boost.Python doesn't support PyFinalize(). There is no way to cleanup the global type conversion registry. It wasn't on the agenda of the people funding Boost.Python version 2 development (i.e. embedding wasn't on the list of things considered important). The leaks are harmless. Just don't use PyFinalize() and ignore the memory occupied by the few globals Boost.Python instantiates. My way of finding "real" leaks is very simple: wrap your code in an endless loop and monitor the process with the top command (Linux or OSX). Let it run for a couple of hours and check again. I've done this many times (to check my own new C++ code). There are no "real" leaks in Python or Boost.Python. Ralf ________________________________ Need a vacation? Get great deals to amazing places on Yahoo! Travel. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Jun 28 20:28:44 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 28 Jun 2007 21:28:44 +0300 Subject: [C++-sig] [pygccxml] caching fails due to pickling recursion limit In-Reply-To: <4683DA86.3050204@lapshin.net> References: <4683DA86.3050204@lapshin.net> Message-ID: <7465b6170706281128t1ae19117m2eae5c1833bddafc@mail.gmail.com> On 6/28/07, Kirill Lapshin wrote: > Hi Roman, everybody, Good evening > We are using py++/pygccxml on moderately sized project, and recently > py++ started to fail silently on us. It runs gccxml and then silently quits. I'd like to fix this bug. > It turned out the offending piece of code was pickling cache. Something > fails in cPickle and terminates the whole process. Most likely it is a > stack overflow, because if cPickle replaced with pickle, then we get > recursion limit runtime error. One can raise recursion limit and pickle > will save cache just fine, but really slowly (not surprising at all). > > At the moment we've worked around this problem by disabling cache, > however it would be nice to fix it properly. May I propose to use another format for cache - gccxml generated files. I am serious. I am not kidding. Last released version(0.9) has many performance improvements, one of them is parsing XML files. pygccxml now uses cElementTree iterparse functionality as XML parser when it available. You can find here the benchmarks http://effbot.org/zone/celementtree.htm . > After reading a bit about pickling, it looks like (c)pickle don't work > very well with recursive structures, which declarations obviously are. > > I just want to list some ideas I have on how to tackle this problem, and > I would love to get some comments on their feasibility, or better yet > alternative approaches. Right now I think that caching functionality was a mistake and it was better to use GCC-XML generated files in this role. The cache classes will stay for backward compatibility. > 1. Simple one, just set all parents to None before pickling and rebuild > parents upon loading. Should be relatively simple, I'll try it first > thing. Hopefully that would kill fair amount of recursion, but not all > of it (e.g. class A refers to class B and B to A). > > 2. Add unique id to each declaration, have a global store that saves > declarations by id, and define for each declaration __getstate__, > __setstate__ that would serialize ids, rather then declaration > instances. Then we just pickle the global store. In reality somewhat > more complex approach needed to tackle recursive references. Can you try the approach I propose? If this will not work for you I am sure we will find some other solution. Relevant API docs: module_builder_t.__init__ http://language-binding.net/pyplusplus/documentation/apidocs/pyplusplus.module_builder.builder.module_builder_t-class.html#__init__ file_configuration_t class doc: http://language-binding.net/pyplusplus/documentation/apidocs/pygccxml.parser.project_reader.file_configuration_t-class.html few convenience functions for constructing file_configuration_t class: http://language-binding.net/pyplusplus/documentation/apidocs/pygccxml.parser.project_reader-module.html#create_gccxml_fc HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From wilson.max at gmail.com Thu Jun 28 20:30:54 2007 From: wilson.max at gmail.com (Maximilian Wilson) Date: Thu, 28 Jun 2007 12:30:54 -0600 Subject: [C++-sig] Boost.Python Memory Leaks? In-Reply-To: References: <379940.27910.qm@web31106.mail.mud.yahoo.com> Message-ID: <2ddbda5f0706281130l63b89daer66f709478e0bf7e6@mail.gmail.com> On 6/28/07, Lawrence Spector wrote: > > If this is true, that's a little upsetting to hear. Boost is supposed to > be one of the best and most complete libraries ever written. I haven't > seen this awful practice elsewhere from within boost. Not releasing > dynamically allocated memory is a bad programming practice and is not > guaranteed to be freed on all platforms (although is on most). Furthermore, > any destructors never get called. The Boost.Python group needs to address > this issue, because IMHO this is a serious bug/design flaw. > > > > It also mucks with our tests, because we're working on making a set of > automated tests and memory leaks are considered a type of failure. Why > should poor programming practice inside Boost.Python be an exception? > Failing to free dynamically-allocated memory (and call destructors) is potentially bad for two reasons: 1.) It can lead to resource leakage, with the amount of resources consumed increasing without limit over time. 2.) When using the RAII paradigm, it can lead to improper management of external resources. Python isn't compatible with RAII anyway, since Python destructors are not deterministic and are not, in fact, even guaranteed to be called AFAIK. Resource leakage isn't a problem for something which is allocated on the heap ONCE and never released. Effectively it's a global variable that lives on the heap. "Poor programming practice" is a generalization which doesn't apply in this case. -Max Wilson -- Be pretty if you are, be witty if you can, But be cheerful if it kills you. Everything in Windows is very simple, but the simplest thing is difficult. -Clausewitz -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Thu Jun 28 20:41:41 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 28 Jun 2007 21:41:41 +0300 Subject: [C++-sig] Boost.Python Memory Leaks? In-Reply-To: References: <379940.27910.qm@web31106.mail.mud.yahoo.com> Message-ID: <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> On 6/28/07, Lawrence Spector wrote: > If this is true, that's a little upsetting to hear. Boost is supposed to be > one of the best and most complete libraries ever written. I don't think so, first of all they should be useful and only than ... Boost.Python is one of the most useful libraries for the bindings creation. > I haven't seen > this awful practice elsewhere from within boost. This is not as awful as you think about it. > Not releasing dynamically > allocated memory is a bad programming practice and is not guaranteed to be > freed on all platforms (although is on most). Furthermore, any destructors > never get called. I am not sure whether you understand what memory Boost.Python doesn't release. > The Boost.Python group needs to address this issue, > because IMHO this is a serious bug/design flaw. I am sure the developers will be glad to get the patches from you :-) http://boost.org/libs/python/todo.html#pyfinalize-safety -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Lawrence.Spector at CanfieldSci.com Thu Jun 28 20:51:56 2007 From: Lawrence.Spector at CanfieldSci.com (Lawrence Spector) Date: Thu, 28 Jun 2007 14:51:56 -0400 Subject: [C++-sig] Boost.Python Memory Leaks? In-Reply-To: <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> References: <379940.27910.qm@web31106.mail.mud.yahoo.com> <7465b6170706281141y447da08buf3a7c2cd270b7723@mail.gmail.com> Message-ID: >From the link you sent, it sounds like it will be taken care of in the future, so that's a good sign. -Lawrence -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Thursday, June 28, 2007 2:42 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python Memory Leaks? On 6/28/07, Lawrence Spector wrote: > If this is true, that's a little upsetting to hear. Boost is supposed to be > one of the best and most complete libraries ever written. I don't think so, first of all they should be useful and only than ... Boost.Python is one of the most useful libraries for the bindings creation. > I haven't seen > this awful practice elsewhere from within boost. This is not as awful as you think about it. > Not releasing dynamically > allocated memory is a bad programming practice and is not guaranteed to be > freed on all platforms (although is on most). Furthermore, any destructors > never get called. I am not sure whether you understand what memory Boost.Python doesn't release. > The Boost.Python group needs to address this issue, > because IMHO this is a serious bug/design flaw. I am sure the developers will be glad to get the patches from you :-) http://boost.org/libs/python/todo.html#pyfinalize-safety -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From bobbyrward at gmail.com Fri Jun 29 03:41:21 2007 From: bobbyrward at gmail.com (Bobby R. Ward) Date: Thu, 28 Jun 2007 20:41:21 -0500 Subject: [C++-sig] Seeking advice on wrapping library with boost::python Message-ID: <1183081286.22822.5.camel@sunstar> I'm looking to create a python module wrapping a C library and C is most certainly not my specialty. The library has structs in the the form struct sub_sub_item { // stuff }; struct sub_item { //stuff int num_sub_sub_items; sub_sub_item *sub_sub_items; }; struct item { //stuff int num_sub_items; sub_item *sub_items; }; The module would have to allow adding and removing from the arrays and wrapping the "stuff". Performance is not critical but it is fairly important. What would be the best way to go about creating this? Would I be better off creating the module some other way? From kir at lapshin.net Fri Jun 29 11:19:27 2007 From: kir at lapshin.net (Kirill Lapshin) Date: Fri, 29 Jun 2007 13:19:27 +0400 Subject: [C++-sig] [pygccxml] caching fails due to pickling recursion limit In-Reply-To: <7465b6170706281128t1ae19117m2eae5c1833bddafc@mail.gmail.com> References: <4683DA86.3050204@lapshin.net> <7465b6170706281128t1ae19117m2eae5c1833bddafc@mail.gmail.com> Message-ID: <4684CE9F.30202@lapshin.net> Roman Yakovenko wrote: > May I propose to use another format for cache - gccxml generated files. > I am serious. I am not kidding. Last released version(0.9) has many > performance improvements, one of them is parsing XML files. pygccxml > now uses cElementTree iterparse functionality as XML parser when it > available. You can find here the benchmarks > http://effbot.org/zone/celementtree.htm . Thanks for a prompt response. I gave it a try. So far looks promising, few caveats though: 1. cElementTree on windows is installed to the root of site-packages, so I had to modify your import line, e.g. replace: import xml.etree.cElementTree as ElementTree with try: import xml.etree.cElementTree as ElementTree except: import cElementTree as ElementTree 2. cElementTree helps, but not by a wide margin -- parsing used to take about 8.1 sec and with cElementTree it takes 5.7 sec, which is nowhere near speeds clamed on cElementTree page, but I guess most of the time is spent not in xml parsing, but in reader/scanner/whatever. 3. Overall time with xml cache is comparable to pickle cache (still about 10% slower though), however cold startup (when no cache is there) is about 15% faster. 4. xml as cache is not as robust as old style cache, meaning that there is no logic to refresh xml file when it gets outdated. Granted in ideal world pyplusplus shouldn't do it in first place, it is more of a build system responsibility, but many of us stuck with less then ideal build systems that can't automatically scan .hpp file dependency trees. I would migrate to xml cache in a heartbit, given our problems with pickle, but build system deficiencies prohibit this move at the moment. Are there any plans to obsolete xml cache file automatically whenever source file, or any files included by source file are modified? I can try to hack something myself, but if you are planning to work on it anyway, I may wait for proper solution. Performance stats for various scenarios (listing biggest offenders only): Note: I'm using py++/pygccxml 0.9 amended a bit to add more performance logging and to use cElementTree as described above. 1. xml using cache parsing xml 5.6 sec relinking declared types... parsing files - done (7.5 sec) setting declarations defaults - done (3.1 sec) preparing data structures for query optimizer (4.7 sec) --- total 26 sec --- total (logging off) 23 sec 2. xml not using cache (cache file has been deleted) creating xml 11.2 sec parsing xml 5.6 sec relinking declared types... parsing files - done (18.6 sec) setting declarations defaults - done (3.1 sec) preparing data structures for query optimizer (4.7 sec) --- total 39 sec --- total (logging off) 34 sec note: times do not add up! parsing files time looks suspicious. probably it includes parsing xml 3. pickle using cache parsing source file 3.1 sec relinking declared types... parsing files - done (5 sec) setting declarations defaults - done (2.7 sec) preparing data structures for query optimizer (4.5 sec) --- total 25 sec --- total (logging off) 21 sec 4. pickle not using cache (cache file has been deleted) parsing source file 22.3 sec relinking declared types... parsing files - done (24.24 sec) setting declarations defaults - done (3 sec) preparing data structures for query optimizer (4.7 sec) --- total 44 sec --- total (logging off) 40 sec Kirill From braddock at braddock.com Fri Jun 29 12:03:49 2007 From: braddock at braddock.com (Braddock Gaskill) Date: Fri, 29 Jun 2007 06:03:49 -0400 Subject: [C++-sig] CMake and getting starting with boost.python Message-ID: Yesterday I became a boost.python user, after years of heavy SWIG usage. I would have started using boost.python years ago except for the bjam learning curve. I spent hours TRYING on multiple occasions, but got lost every time trying to get the page one example to build with bjam. Here is how to build the "greet" example with a four line CMake file: cat >>CMakeLists.txt < Message-ID: For those who prefer Makefiles, I found the following Makefile also worked to build the greet example. It is based on some Makefiles posted to this list. I don't know how robust it is. Worked under Linux Ubuntu 6.10. CC = g++ CFLAGS = -Wall -W -fPIC -I/usr/include/boost \ -I/usr/include/python2.5 -DBOOST_PYTHON_DYNAMIC_LIB \ -O2 LDFLAGS = -L/usr/local/lib -lboost_python -L/usr/lib/python2.5 \ -Wl,-rpath-link,. -fPIC CXXFLAGS = $(CFLAGS) SLIB = hello.so all: $(SLIB) %.so : %.o /usr/bin/objcopy --set-section-flags .debug_str=contents,debug $^ $(CC) $(LDFLAGS) $^ -shared -o $@ clean : rm -f $(WORLD) $(OBJS) From rwgk at yahoo.com Fri Jun 29 17:26:32 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 29 Jun 2007 08:26:32 -0700 (PDT) Subject: [C++-sig] Boost.Python Memory Leaks? Message-ID: <686880.92306.qm@web31102.mail.mud.yahoo.com> What you see is the best we could do given the time and money we had. To give people like you a chance to improve on what we did, we released everything as open source. We hope this encourages others to contribute back. I have a couple of years of my life in Boost.Python (and Dave a lot more, of course). It works perfectly for my purposes. IMHO embedding is bad design from the outset. :-) Ralf ____________________________________________________________________________________ Finding fabulous fares is fun. Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains. http://farechase.yahoo.com/promo-generic-14795097 -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Jun 30 07:45:57 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 30 Jun 2007 08:45:57 +0300 Subject: [C++-sig] [pygccxml] caching fails due to pickling recursion limit In-Reply-To: <4684CE9F.30202@lapshin.net> References: <4683DA86.3050204@lapshin.net> <7465b6170706281128t1ae19117m2eae5c1833bddafc@mail.gmail.com> <4684CE9F.30202@lapshin.net> Message-ID: <7465b6170706292245l529faf23ua49c603fcab4b926@mail.gmail.com> On 6/29/07, Kirill Lapshin wrote: > Roman Yakovenko wrote: > > May I propose to use another format for cache - gccxml generated files. > > I am serious. I am not kidding. Last released version(0.9) has many > > performance improvements, one of them is parsing XML files. pygccxml > > now uses cElementTree iterparse functionality as XML parser when it > > available. You can find here the benchmarks > > http://effbot.org/zone/celementtree.htm . > > Thanks for a prompt response. > > I gave it a try. So far looks promising, few caveats though: > > 1. cElementTree on windows is installed to the root of site-packages, so > I had to modify your import line, e.g. replace: > > import xml.etree.cElementTree as ElementTree > > with > > try: > import xml.etree.cElementTree as ElementTree > except: > import cElementTree as ElementTree I will fix this. > 2. cElementTree helps, but not by a wide margin -- parsing used to take > about 8.1 sec and with cElementTree it takes 5.7 sec, which is nowhere > near speeds clamed on cElementTree page, but I guess most of the time is > spent not in xml parsing, but in reader/scanner/whatever. > > 3. Overall time with xml cache is comparable to pickle cache (still > about 10% slower though), however cold startup (when no cache is there) > is about 15% faster. This is because I don't have to save the cache to disk > 4. xml as cache is not as robust as old style cache, meaning that there > is no logic to refresh xml file when it gets outdated. Granted in ideal > world pyplusplus shouldn't do it in first place, it is more of a build > system responsibility, but many of us stuck with less then ideal build > systems that can't automatically scan .hpp file dependency trees. > > I would migrate to xml cache in a heartbit, given our problems with > pickle, but build system deficiencies prohibit this move at the moment. > > Are there any plans to obsolete xml cache file automatically whenever > source file, or any files included by source file are modified? I can > try to hack something myself, but if you are planning to work on it > anyway, I may wait for proper solution. I understand. I think I can add this functionality and than to start to deprecate the cache that use pickle. > Performance stats for various scenarios (listing biggest offenders only): > > Note: I'm using py++/pygccxml 0.9 amended a bit to add more performance > logging and to use cElementTree as described above. > > 1. xml using cache > parsing xml 5.6 sec > relinking declared types... > parsing files - done (7.5 sec) > setting declarations defaults - done (3.1 sec) > preparing data structures for query optimizer (4.7 sec) > --- total 26 sec > --- total (logging off) 23 sec > > 2. xml not using cache (cache file has been deleted) > creating xml 11.2 sec > parsing xml 5.6 sec > relinking declared types... > parsing files - done (18.6 sec) > setting declarations defaults - done (3.1 sec) > preparing data structures for query optimizer (4.7 sec) > --- total 39 sec > --- total (logging off) 34 sec > > note: times do not add up! parsing files time looks suspicious. > probably it includes parsing xml > > 3. pickle using cache > parsing source file 3.1 sec > relinking declared types... > parsing files - done (5 sec) > setting declarations defaults - done (2.7 sec) > preparing data structures for query optimizer (4.5 sec) > --- total 25 sec > --- total (logging off) 21 sec > > 4. pickle not using cache (cache file has been deleted) > parsing source file 22.3 sec > relinking declared types... > parsing files - done (24.24 sec) > setting declarations defaults - done (3 sec) > preparing data structures for query optimizer (4.7 sec) > --- total 44 sec > --- total (logging off) 40 sec It will be helpful if you could run your scripts under profiler. So we can see the bottlenecks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From tbrooks.mail at gmail.com Sat Jun 30 12:48:36 2007 From: tbrooks.mail at gmail.com (Tom Brooks) Date: Sat, 30 Jun 2007 06:48:36 -0400 Subject: [C++-sig] Pickling Enums Message-ID: Hello, I've searched the web, and this question has come up a couple of times, but I haven't been able to find an answer. My problem is that I get an error when trying to pickle an enum that's been exposed with Boost::Python. enum BlendType { NoBlend, Transparent, Additive }; BOOST_PYTHON_MODULE(Renderer) { enum_("BlendType") .value("NoBlend",NoBlend) .value("Transparent",Transparent) .value("Additive",Additive) .export_values() ; } The error is very long, but here's the end part of it: ... save(element) File "C:\Python24\lib\pickle.py", line 293, in save f(self, obj) # Call unbound method with explicit self File "C:\Python24\lib\pickle.py", line 760, in save_global raise PicklingError( pickle . PicklingError : Can't pickle : it's not found as __main__.Renderer.BlendType If it matters, this pickling happens when I pickle another class. I have no idea where to start, since you can't def_pickle or even .def for an enum_. How do I go about doing this? Thanks in advanced -------------- next part -------------- An HTML attachment was scrubbed... URL: From p.jaroszynski at gmail.com Sat Jun 30 19:18:01 2007 From: p.jaroszynski at gmail.com (Piotr =?utf-8?q?Jaroszy=C5=84ski?=) Date: Sat, 30 Jun 2007 19:18:01 +0200 Subject: [C++-sig] type traits Message-ID: <200706301918.01464.p.jaroszynski@gmail.com> Hello, I thought (and saw) that boost.python is using type traits to figure out the real type of polymorphic pointers/references and hence I am really surprised that with the following code it doesn't happen: #include namespace bp = boost::python; struct Base { }; struct Derived : Base { }; const boost::shared_ptr get_derived() { static boost::shared_ptr foo(boost::shared_ptr(new Derived())); return foo; } BOOST_PYTHON_MODULE(type_magic) { bp::class_("Base", bp::no_init); bp::register_ptr_to_python >(); bp::class_ >("Derived", bp::no_init); bp::def("get_derived", &get_derived); } in python get_derived gives me: For the "saw" part, I have working code, which does exactly what I expected (getting a Derived object in python) and I can't really find a difference between it and this basic testcase, but I am probably just missing something. Any clues what that could be? -- Best Regards, Piotr Jaroszy?ski From roman.yakovenko at gmail.com Sat Jun 30 20:09:21 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 30 Jun 2007 21:09:21 +0300 Subject: [C++-sig] type traits In-Reply-To: <200706301918.01464.p.jaroszynski@gmail.com> References: <200706301918.01464.p.jaroszynski@gmail.com> Message-ID: <7465b6170706301109m23257e01uda10667d8b74c86c@mail.gmail.com> On 6/30/07, Piotr Jaroszy?ski wrote: > Hello, > > I thought (and saw) that boost.python is using type traits to figure out the > real type of polymorphic pointers/references and hence I am really surprised > that with the following code it doesn't happen: > > #include > > namespace bp = boost::python; > > struct Base > { > }; > > struct Derived : > Base > { > }; > > const boost::shared_ptr > get_derived() > { > static boost::shared_ptr foo(boost::shared_ptr(new > Derived())); > return foo; > } > > BOOST_PYTHON_MODULE(type_magic) > { > bp::class_("Base", bp::no_init); > bp::register_ptr_to_python >(); > bp::class_ >("Derived", bp::no_init); > bp::def("get_derived", &get_derived); > } > > in python get_derived gives me: > > > For the "saw" part, I have working code, which does exactly what I expected > (getting a Derived object in python) and I can't really find a difference > between it and this basic testcase, but I am probably just missing something. > Any clues what that could be? I guess this happens because your classes don't have any virtual function. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From p.jaroszynski at gmail.com Sat Jun 30 20:41:14 2007 From: p.jaroszynski at gmail.com (Piotr =?iso-8859-2?q?Jaroszy=F1ski?=) Date: Sat, 30 Jun 2007 20:41:14 +0200 Subject: [C++-sig] type traits In-Reply-To: <7465b6170706301109m23257e01uda10667d8b74c86c@mail.gmail.com> References: <200706301918.01464.p.jaroszynski@gmail.com> <7465b6170706301109m23257e01uda10667d8b74c86c@mail.gmail.com> Message-ID: <200706302041.15117.p.jaroszynski@gmail.com> On Saturday 30 of June 2007 20:09:21 Roman Yakovenko wrote: > I guess this happens because your classes don't have any virtual function. Yeah that was really silly of me, many thanks! Now I have a testcase for the real problem, which lead me to writing one in the first place: #include namespace bp = boost::python; struct Base { virtual ~Base() { } }; struct Derived : Base { virtual ~Derived() { } }; struct MoreDerived : Derived { virtual ~MoreDerived() { } }; const Base * get_derived() { static Base * foo(new MoreDerived()); return foo; } BOOST_PYTHON_MODULE(type_magic) { bp::class_("Base", bp::no_init); bp::register_ptr_to_python(); bp::class_ >("Derived", bp::no_init); //bp::class_ >("MoreDerived", bp::no_init); bp::def("get_derived", &get_derived, bp::return_value_policy()); } With the code above (with commented out bp::class_...) get_derived gives me the Base object. When I uncomment the MoreDerived exposure I get the MoreDerived object. The question is whether it's possible to get the Derived object when the MoreDerived is not exposed. This is exactly the situation I have as the C++ hierarchy is considered public only to some level. -- Best Regards, Piotr Jaroszy?ski From awk at imm.dtu.dk Sat Jun 30 03:32:40 2007 From: awk at imm.dtu.dk (Anders Wang Kristensen) Date: Sat, 30 Jun 2007 03:32:40 +0200 Subject: [C++-sig] Handle class and lifetime Message-ID: Hi, I'm a little confused by the call policies in boost python. I have something like the following situation: struct vertex { graph* p; int x; }; struct graph { vertex get_vertex(int i); }; and in my python module: class_ pyg("graph") pyg.def("get_vertex", &graph::get_vertex, with_custodian_and_ward_postcall<0,1>()); Is this the right way to make sure that graphs wont be destroyed while there are still vertices around which reference these graphs? Thanks! -- Anders