From kamilzubair at yahoo.com Wed Apr 2 17:44:39 2008 From: kamilzubair at yahoo.com (Kamil Zubair) Date: Wed, 2 Apr 2008 08:44:39 -0700 (PDT) Subject: [C++-sig] How can I store shared_ptr in python list ? Message-ID: <232020.9883.qm@web36503.mail.mud.yahoo.com> Hi, I'm trying to do this : Python: ptr_list=[] def func(ptr, msg): if "insert"==msg: ptr_list.append(ptr) elif "remove"==msg: ptr_list.remove(ptr) C++: class MyClass{}; int main() { //initialize python exec_file("func.py", global, global); //func.py is the code above object func = global["func"]; shared_ptr mc(new MyClass()); func(mc, "insert"); func(mc, "remove"); <-- exception here } My question is how do I expose my class to python ? I tried class_ >("MyClass") but it always fails when I tried to remove an already inserted object. --------------------------------- You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost. -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant.tang at gmail.com Thu Apr 3 03:18:11 2008 From: grant.tang at gmail.com (Grant Tang) Date: Wed, 2 Apr 2008 20:18:11 -0500 Subject: [C++-sig] Problem with boost.python 1.35.0 Message-ID: My application works fine with previous versions of boost.python. But I tried to compile it with the boost.python 1.35.0, it fails with the compilation. Can some one help me? /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/detail/cv_traits_impl.hpp: In instantiation of 'const bool boost::detail::cv_traits_imp<::EMAN_Aligner_Wrapper*>::is_const': /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/is_const.hpp:53: instantiated from 'boost::is_const<::EMAN_Aligner_Wrapper>' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/cv_category.hpp:31: instantiated from 'boost::python::detail::cv_category<::EMAN_Aligner_Wrapper>' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:58: instantiated from 'typename Generator::result_type boost::python::detail::unwind_ptr_type(U*, Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::EMAN_Aligner_Wrapper]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:127: instantiated from 'static typename Generator::result_type boost::python::detail::unwind_helper2<2>::execute(U& (*)(), Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::EMAN_Aligner_Wrapper]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:165: instantiated from 'typename Generator::result_type boost::python::detail::unwind_type(boost::type*, Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::EMAN_Aligner_Wrapper&]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/converter/pytype_function.hpp:45: instantiated from 'boost::python::type_info boost::python::converter::detail::unwind_type_id_(boost::type*, mpl_::false_*) [with T = ::EMAN_Aligner_Wrapper&]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/converter/pytype_function.hpp:68: instantiated from 'static const PyTypeObject* boost::python::converter::expected_pytype_for_arg::get_pytype() [with T = ::EMAN_Aligner_Wrapper&]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/signature.hpp:98: instantiated from 'static const boost::python::detail::signature_element* boost::python::detail::signature_arity<5u>::impl::elements() [with Sig = boost::mpl::v_item::EMAN_Aligner_Wrapper&, boost::mpl::v_mask, 1>, 1>, 1>, 1>]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/caller.hpp:232: instantiated from 'static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<5u>::impl::signature() [with F = boost::python::detail::nullary_function_adaptor, Policies = boost::python::default_call_policies, Sig = boost::mpl::v_item::EMAN_Aligner_Wrapper&, boost::mpl::v_mask, 1>, 1>, 1>, 1>]' /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/object/py_function.hpp:48: instantiated from 'boost::python::detail::py_func_sig_info boost::python::objects::caller_py_function_impl::signature() const [with Caller = boost::python::detail::caller, boost::python::default_call_policies, boost::mpl::v_item::EMAN_Aligner_Wrapper&, boost::mpl::v_mask, 1>, 1>, 1>, 1> >]' /home/g/EMAN2/src/eman2/libpyEM/libpyAligner2.cpp:358: instantiated from here /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/detail/cv_traits_impl.hpp:37: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:5067 Please submit a full bug report, with preprocessed source if appropriate. See > for instructions. Preprocessed source stored into /tmp/cc2yhNUv.out file, please attach this to your bugreport. make[2]: *** [libpyEM/CMakeFiles/pyAligner2.dir/libpyAligner2.o] Error 1 make[1]: *** [libpyEM/CMakeFiles/pyAligner2.dir/all] Error 2 make: *** [all] Error 2 Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From srossross at gmail.com Sat Apr 5 17:33:25 2008 From: srossross at gmail.com (Sean Ross-Ross) Date: Sat, 5 Apr 2008 08:33:25 -0700 Subject: [C++-sig] Abort trap Message-ID: <7DF42994-EB00-4765-AE1C-2966CE0B9D90@gmail.com> Hi, I get an abort trap running a python script that calls a c++ function that calls a python function. this happens when the inner python function raises an exception. does anyone know why? Here is part of the gdb backtrace. I noticed that in line #8 throw_error_already_set is called, what am I doing that this function does not work for me. Program received signal SIGABRT, Aborted. 0x9003d66c in kill () (gdb) backtrace #0 0x9003d66c in kill () #1 0x9010e8cf in raise () #2 0x9010d422 in abort () #3 0x007c5798 in _Unwind_SetGR (context=0xbfffe038, index=0, val=6882112) at ../../gcc-4.2.2/gcc/unwind-dw2.c:223 #4 0x0207d308 in __gxx_personality_v0 (version=1, actions=2, exception_class=5138137972254386944, ue_header=0x690340, context=0xbfffe038) at ../../../../gcc-4.2.2/libstdc++-v3/libsupc++/ eh_personality.cc:681 #5 0x90bd7930 in _Unwind_RaiseException_Phase2 () #6 0x90bd7b60 in _Unwind_RaiseException () #7 0x90b43747 in __cxa_throw () #8 0x00599874 in boost::python::throw_error_already_set () #9 0x01019a9f in boost::python::expect_non_null<_object> (x=0x0) at / sw/include/boost/python/errors.hpp:45 #10 0x01019b9c in boost::python::converter::detail::return_object_manager_from_python::operator() (this=0xbfffe1bb, obj=0x0) at /sw/ include/boost/python/converter/return_from_python.hpp:156 #11 0x01021c48 in boost::python::call (callable=0x559430, a0=@0xbfffe3b0, a1=@0xbfffe3ac, a2=@0x6b5620) at /sw/include/boost/python/call.hpp:73 #12 0x01021ca9 in boost::python::api::object_operators::operat or() (this=0xbfffe244, a0=@0xbfffe3b0, a1=@0xbfffe3ac, a2=@0x6b5620) at /sw/include/boost/python/ object_call.hpp:19 #13 0x01024fee in OperatorTraits::ApplyAdj (A=@0xbfffe3b0, b=@0xbfffe3ac, result=@0x6b5620) at /Users/sean/workspace/UANA/ install/slim/python/PythonOperatorTraits.hpp:55 From lists at informa.tiker.net Sun Apr 6 22:16:33 2008 From: lists at informa.tiker.net (Andreas =?utf-8?q?Kl=C3=B6ckner?=) Date: Sun, 6 Apr 2008 16:16:33 -0400 Subject: [C++-sig] Boost.Python Vector indexing suite::extend should accept general iterables Message-ID: <200804061616.35348.lists@informa.tiker.net> Hi Joel, I'm following up on my patch allowing the extend() method of containers wrapped using the vector indexing suite to accept general iterables (such as generator expressions, sets, etc.), not just ones that have __len__ and __getitem__. It does so by using Eric Niebler's stl_input_iterator, already present in recent versions of Boost.Python. A while back (Jan 2 '08) you asked me to add a test case, I have since done so. The new version of the patch is attached. Could you please take a look? Thanks, Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: bpl-vis-extend-generator-v2.patch Type: text/x-diff Size: 2199 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From oschweitzer at mac.com Mon Apr 7 14:46:03 2008 From: oschweitzer at mac.com (Oliver Schweitzer) Date: Mon, 07 Apr 2008 05:46:03 -0700 Subject: [C++-sig] Problem writing out split files with C++ Message-ID: Hi, Py++ Module Builder has two methods (split_module and balanced_split_module) that allow, well, splitting of generated C++ source into several files. When I call one of those methods for my Module, Py++ tries to generate several additional header files, filename like __value_traits.pypp.hpp And I get the error: IOError: [Errno 2] No such file or directory: 'C:/TEMP/Develop/PythonWrapper/_basic_string< char, std::char_traits< char >, std::allocator< char > >__value_traits.pypp.hpp' When I write out the module as a single file the related code looks like this, I guess: [code] namespace boost { namespace python { namespace indexing { template<> struct value_traits< std::basic_string< char, std::char_traits< char >, std::allocator< char > > >{ static bool const equality_comparable = true; typedef std::equal_to< std::basic_string< char, std::char_traits< char >, std::allocator< char > > > equal_to; static bool const less_than_comparable = true; typedef std::less< std::basic_string< char, std::char_traits< char >, std::allocator< char > > > less; template static void visit_container_class(PythonClass &, Policy const &){ } }; }/*indexing*/ } /*python*/ } /*boost*/ [/code] Help: What is this? What is it needed for? Can I fix this/stop py++ from trying to write this? Best regards, Oliver From roman.yakovenko at gmail.com Mon Apr 7 15:35:06 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 7 Apr 2008 16:35:06 +0300 Subject: [C++-sig] Problem writing out split files with C++ In-Reply-To: References: Message-ID: <7465b6170804070635r4709f3c6tc3ffc1a7c69d9410@mail.gmail.com> On Mon, Apr 7, 2008 at 3:46 PM, Oliver Schweitzer wrote: > Hi, > > Py++ Module Builder has two methods (split_module and balanced_split_module) that allow, well, splitting of generated C++ source into several files. > > When I call one of those methods for my Module, Py++ tries to generate several additional header files, filename like __value_traits.pypp.hpp > > And I get the error: > > IOError: [Errno 2] No such file or directory: 'C:/TEMP/Develop/PythonWrapper/_basic_string< char, std::char_traits< char >, std::allocator< char > >__value_traits.pypp.hpp' > > When I write out the module as a single file the related code looks like this, I guess: > > [code] > namespace boost { namespace python { namespace indexing { > > template<> > struct value_traits< std::basic_string< char, std::char_traits< char >, std::allocator< char > > >{ > > static bool const equality_comparable = true; > typedef std::equal_to< std::basic_string< char, std::char_traits< char >, std::allocator< char > > > equal_to; > > static bool const less_than_comparable = true; > typedef std::less< std::basic_string< char, std::char_traits< char >, std::allocator< char > > > less; > > template > static void visit_container_class(PythonClass &, Policy const &){ > > } > > }; > > }/*indexing*/ } /*python*/ } /*boost*/ > [/code] > > Help: What is this? What is it needed for? Can I fix this/stop py++ from trying to write this? > This is a Py++ bug. Can you create small test case that reproduce the problem? Thanks P.S. This is a bug I was not able to reproduce for a long time. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Mon Apr 7 17:30:59 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 7 Apr 2008 18:30:59 +0300 Subject: [C++-sig] Problem writing out split files with C++ In-Reply-To: <1B9A74A8-0D09-4696-AFCF-6AB54E15774A@mac.com> References: <7465b6170804070635r4709f3c6tc3ffc1a7c69d9410@mail.gmail.com> <1B9A74A8-0D09-4696-AFCF-6AB54E15774A@mac.com> Message-ID: <7465b6170804070830s45b31031o7eddc6337d6f5fa6@mail.gmail.com> On Mon, Apr 7, 2008 at 5:07 PM, Oliver Schweitzer wrote: > Hi Roman, > > I should just have tried to prepare a testcase earlier, sorry for bringing > this up again so, late :( I'm trying to prepare one now. > > As a quick fix, is it possible to stop Py++ from generating those header > files? Yes, you can use split_module function and exclude every class that needs such functionality. Another quick fix will be to save "struct value_traits< std::basic_string< char, std::char_traits< char >, std::allocator< char > > >" definition to a file and then to use "search & replace" functionality on generated files. Both functions "split_module" and "balanced_split_module" return list of written files. I think this is even better fix. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From scott.stk at gmail.com Tue Apr 8 00:08:39 2008 From: scott.stk at gmail.com (Scott Cox) Date: Mon, 7 Apr 2008 17:08:39 -0500 Subject: [C++-sig] Introduction of myself. Message-ID: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> Hello there, I am interested in using Python as a community scripting language for a game/project I and my team of developers have been working on for quite a while. I'm not a programmer by any means, but I have been assigned this task. The game engine we are creating our game around, Valve's Source Game Engine, is mainly written in C++, but it is impossible for us to offer this as a modding system for our project. Our license gives our development team access to the source code for the engine, but we cannot keep the game open source. We need to develop a system for using Python as a means to access and mod the Source code in the engine. I, however, have no idea how this would be completed. By what I've seen of Python/C++ merging, I made the assumption that it's very complicated and requires every command to be "boosted" from C++ to Python format. That may pay off for our project in the long run, seeing as how it allows us to shape what commands we want available to the public, but I have no idea of what I need to accomplish the "boosting" of all these commands. I appreciate all help in advance, thank you. If you have anything at all to say regarding this, please do so. If you feel I'm asking in the wrong place for help on this, I kindly ask that you point me in the right direction. -Sigfig -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Tue Apr 8 00:21:54 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 07 Apr 2008 18:21:54 -0400 Subject: [C++-sig] Introduction of myself. In-Reply-To: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> References: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> Message-ID: <47FA9E82.70902@sympatico.ca> Scott Cox wrote: > I appreciate all help in advance, thank you. If you have anything > at all to say regarding this, please do so. If you feel I'm asking in > the wrong place for help on this, I kindly ask that you point me in the > right direction. As of now I'm not even sure what your question is. Are you asking for advice on how to wrap a large amount of C++ APIs in Python ? Something else ? Also, I'm not sure I understand your comments "we cannot keep the game open source" and its relevance to the rest of the mail. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From scott.stk at gmail.com Tue Apr 8 00:33:15 2008 From: scott.stk at gmail.com (Scott Cox) Date: Mon, 7 Apr 2008 17:33:15 -0500 Subject: [C++-sig] Introduction of myself. In-Reply-To: <47FA9E82.70902@sympatico.ca> References: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> <47FA9E82.70902@sympatico.ca> Message-ID: <7b22c6cc0804071533w1761086dr329e9abf03320616@mail.gmail.com> > > As of now I'm not even sure what your question is. Are you asking for > advice on how to wrap a large amount of C++ APIs in Python ? Something > else ? > > Also, I'm not sure I understand your comments "we cannot keep the game > open source" and its relevance to the rest of the mail. I was basically asking for help on how to get started. I'm not very intelligent when it comes to programming, I'm feeling my way around a dark room here. If you want me to simplify my question: I've got a very large amount of existing code that I need a python interface for, since I can't give users the C++ code itself. How would I go by creating this? -Sigfig -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Tue Apr 8 01:43:08 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 07 Apr 2008 19:43:08 -0400 Subject: [C++-sig] Introduction of myself. In-Reply-To: <7b22c6cc0804071533w1761086dr329e9abf03320616@mail.gmail.com> References: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> <47FA9E82.70902@sympatico.ca> <7b22c6cc0804071533w1761086dr329e9abf03320616@mail.gmail.com> Message-ID: <47FAB18C.1050200@sympatico.ca> Scott Cox wrote: > As of now I'm not even sure what your question is. Are you asking for > advice on how to wrap a large amount of C++ APIs in Python ? Something > else ? > > Also, I'm not sure I understand your comments "we cannot keep the game > open source" and its relevance to the rest of the mail. > > > I was basically asking for help on how to get started. I'm not very > intelligent when it comes to programming, I'm feeling my way around a > dark room here. > If you want me to simplify my question: I've got a very large > amount of existing code that I need a python interface for, since I > can't give users the C++ code itself. How would I go by creating this? Approach this from a Python-scripting point-of-view: Start by enumerating a set of things you want to be able to do via scripting, then figure out their corresponding API in C++ and wrap that. The boost.python tutorial will hopefully be of help: http://boost.org/doc/libs/1_35_0/libs/python/doc/tutorial/doc/html/index.html Once this is done, refine. In any case, this is indeed the task for someone with a medium - strong programming background. I'm certainly not the one to ask where you can find those in your team. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From swiftcoder at gmail.com Tue Apr 8 05:16:22 2008 From: swiftcoder at gmail.com (Tristam MacDonald) Date: Mon, 7 Apr 2008 23:16:22 -0400 Subject: [C++-sig] Introduction of myself. In-Reply-To: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> References: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> Message-ID: <8bdb0d630804072016w592b24e0uc9ef157db7cd5e2e@mail.gmail.com> 2008/4/7 Scott Cox : > > The game engine we are creating our game around, Valve's Source Game > Engine, is mainly written in C++, but it is impossible for us to offer this > as a modding system for our project. Our license gives our development > team access to the source code for the engine, but we cannot keep the game > open source. We need to develop a system for using Python as a means to > access and mod the Source code in the engine. > You may not be aware that the Source engine is already scriptable using python. Try here: http://python.eventscripts.com/pages/Main_Page - Tristam MacDonald -------------- next part -------------- An HTML attachment was scrubbed... URL: From d.bollmann at tu-berlin.de Tue Apr 8 12:31:34 2008 From: d.bollmann at tu-berlin.de (Dietrich Bollmann) Date: Tue, 08 Apr 2008 19:31:34 +0900 Subject: [C++-sig] segmentation fault when executing PyImport_ImportModule("sys") Message-ID: <1207650694.845.8.camel@pippi.pippi> Hi, (I already posted this mail at python-list at python.org - but probably this list is the better one for my question...) Since some time I get the following segmentation fault in an application which used to work fine until recently. I made a backtrace but couldn't find the reason for the segmentaion fault until now. In the hope that somebody might have encountered a similar problem or does understand the backtrace better than me and can explain it I posted the backtrace here... At the end of the backtrace I appended some more context concerning the involved code. Thanks for your help :) Dietrich Here comes the backtrace: ---- Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb046ab90 (LWP 9854)] threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154 154 ../Python/pystate.c: No such file or directory. in ../Python/pystate.c (gdb) bt full #0 threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154 No locals. #1 0xb7e8a897 in PyEval_GetGlobals () at ../Python/ceval.c:3340 current_frame = #2 0xb7eaeb67 in PyImport_Import (module_name=0xb7119480) at ../Python/import.c:2400 globals = import = builtins = r = silly_list = (PyObject *) 0xb738fb0c builtins_str = (PyObject *) 0xb7391c50 import_str = (PyObject *) 0xb7391fc0 #3 0xb7eaede5 in PyImport_ImportModule (name=0x901504b "sys") at ../Python/import.c:1903 pname = (PyObject *) 0xb7119480 result = (PyObject *) 0x0 #4 0x08996c9f in py_stdouterr_buffer_new () at source/blender/commandport/blender/src/py_stdouterr_buffer.c:75 buffer = (py_stdouterr_buffer) 0x94fd428 func_StringIO = (PyObject *) 0x9152a48 args_StringIO = (PyObject *) 0x0 #5 0x089967e1 in bcp_blender_handler_new () at source/blender/commandport/blender/src/bcp_blender.c:130 handler = (bcp_blender_handler) 0x9810420 #6 0x08998db3 in bcp_handle_client (client_socket=8) at source/blender/commandport/blender/src/bcp_handle_client.c:73 debug = 0 debug3 = 0 debug4 = 0 message_handler = (message_handler) 0x97eba10 blender_handler = (bcp_blender_handler) 0x0 command = 0x0 result = 0x9152a48 "%G?%@016\025\th%G??%@@\\%G?%@022v#\b \"v#\b%G??%@v#\bRv#\bbv#\brv#\b\202v#\b\222v#\b%G?%@v#\b%G?%@v#\b` \032%G?%@020\026%G???%@#\b%G?%@#\b\002w#\b\022w# \b\"w#\b2w#\bBw#\bRw#\bbw#\brw#\b\202w#\b\222w#\b%G?%@w#\b%G?%@w# \bp#p%G??%@#\b" package_number = -1216545219 #7 0x08998d60 in bcp_client_thread (args=0x0) at source/blender/commandport/blender/src/bcp_server.c:164 targs = (struct bcp_client_thread_args *) 0x0 client_socket = 8 client_thread = 2957421456 #8 0xb76b04fb in start_thread () from /lib/i686/cmov/libpthread.so.0 No symbol table info available. #9 0xb77c2d7e in clone () from /lib/i686/cmov/libc.so.6 No symbol table info available. (gdb) q The program is running. Exit anyway? (y or n) y --- and here some informations about its context: Python-2.4.4/Python/ceval.c line 3340: PyFrameObject *current_frame = PyEval_GetFrame(); context: --- PyObject * PyEval_GetGlobals(void) { PyFrameObject *current_frame = PyEval_GetFrame(); if (current_frame == NULL) return NULL; else return current_frame->f_globals; } --- Python-2.4.4/Python/pystate.c lign 154: { context: --- /* Default implementation for _PyThreadState_GetFrame */ static struct _frame * threadstate_getframe(PyThreadState *self) { return self->frame; } --- Python-2.4.4/Python/import.c lign 2400: globals = PyEval_GetGlobals(); context: --- PyObject * PyImport_Import(PyObject *module_name) { ... /* Get the builtins from current globals */ globals = PyEval_GetGlobals(); if (globals != NULL) { Py_INCREF(globals); builtins = PyObject_GetItem(globals, builtins_str); if (builtins == NULL) goto err; } ... } --- Python-2.4.4/Python/import.c lign 1903: result = PyImport_Import(pname); context: --- PyObject * PyImport_ImportModule(char *name) { PyObject *pname; PyObject *result; pname = PyString_FromString(name); if (pname == NULL) return NULL; result = PyImport_Import(pname); Py_DECREF(pname); return result; } --- source/blender/commandport/blender/src/py_stdouterr_buffer.c lign 75: buffer->mod_sys = PyImport_ImportModule("sys"); context: --- /** Make a new python io buffer. */ py_stdouterr_buffer py_stdouterr_buffer_new() { py_stdouterr_buffer buffer; buffer = (py_stdouterr_buffer) malloc(sizeof(py_stdouterr_buffer_struct)); if (buffer == NULL) { fprintf(stderr, "Couldn't allocate memory for new py_stdouterr_buffer! \n"); exit(ERROR_MEMORY); } buffer->mod_sys = PyImport_ImportModule("sys"); buffer->mod_cStringIO = PyImport_ImportModule("cStringIO"); /* store stdout and stderr */ buffer->stdout_obj = PyObject_GetAttrString(buffer->mod_sys, "stdout"); buffer->stderr_obj = PyObject_GetAttrString(buffer->mod_sys, "stderr"); /* make new string buffer for stdout and stderr */ PyObject *func_StringIO, *args_StringIO; func_StringIO = PyObject_GetAttrString(buffer->mod_cStringIO, "StringIO"); args_StringIO = Py_BuildValue("()"); buffer->outbuf_obj = PyEval_CallObject(func_StringIO, args_StringIO); buffer->errbuf_obj = PyEval_CallObject(func_StringIO, args_StringIO); Py_DECREF(args_StringIO); Py_DECREF(func_StringIO); return buffer; } --- -- http://mail.python.org/mailman/listinfo/python-list From Mark.English at rbccm.com Tue Apr 8 13:01:01 2008 From: Mark.English at rbccm.com (English, Mark) Date: Tue, 8 Apr 2008 12:01:01 +0100 Subject: [C++-sig] segmentation fault when executingPyImport_ImportModule("sys") In-Reply-To: <1207650694.845.8.camel@pippi.pippi> References: <1207650694.845.8.camel@pippi.pippi> Message-ID: > Dietrich Bollmann wrote: > Since some time I get the following segmentation fault in an > application which used to work fine until recently. Just a thought: have you called PyEval_InitThreads from the main thread at startup ? _______________________________________________________________________ This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential. Unauthorised use or disclosure is prohibited. If you receive this e-mail in error, please advise immediately and delete the original message without copying, using, or telling anyone about its contents. This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message. This message does not create or change any contract. Royal Bank of Canada and its subsidiaries accept no responsibility for damage caused by any viruses contained in this email or its attachments. Emails may be monitored. RBC Capital Markets is a business name used by branches and subsidiaries of Royal Bank of Canada, including Royal Bank of Canada, London branch and Royal Bank of Canada Europe Limited. In accordance with English law requirements, details regarding Royal Bank of Canada Europe Limited are set out below: ROYAL BANK OF CANADA EUROPE LIMITED Registered in England and Wales 995939 Registered Address: 71 Queen Victoria Street, London, EC4V 4DE. Authorised and regulated by the Financial Service Authority. Member of the London Stock Exchange From diresu at web.de Tue Apr 8 14:42:45 2008 From: diresu at web.de (Dietrich Bollmann) Date: Tue, 08 Apr 2008 21:42:45 +0900 Subject: [C++-sig] segmentation fault when executingPyImport_ImportModule("sys") In-Reply-To: References: <1207650694.845.8.camel@pippi.pippi> Message-ID: <1207658565.845.17.camel@pippi.pippi> Hi Mark, Thanks for your help! On Tue, 2008-04-08 at 12:01 +0100, English, Mark wrote: > > Dietrich Bollmann wrote: > > Since some time I get the following segmentation fault in an > > application which used to work fine until recently. > Just a thought: have you called PyEval_InitThreads from the main thread > at startup ? ? PyEval_InitThreads() was called after the function which starts the server thread from where the client threads are created. I changed the order but the segmentation fault is still there :( Dietrich From venkat83 at gmail.com Tue Apr 8 16:29:54 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Tue, 8 Apr 2008 19:59:54 +0530 Subject: [C++-sig] segmentation fault when executing PyImport_ImportModule("sys") In-Reply-To: <1207650694.845.8.camel@pippi.pippi> References: <1207650694.845.8.camel@pippi.pippi> Message-ID: On Tue, Apr 8, 2008 at 4:01 PM, Dietrich Bollmann wrote: > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0xb046ab90 (LWP 9854)] > threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154 > 154 ../Python/pystate.c: No such file or directory. > in ../Python/pystate.c > Am not sure whether i get the context right - but i was stumbling on a similar SIGSERV in a multithreaded app - profiling with Valgrind turned out to be much useful and the memory leak was fixed. > > malloc(sizeof(py_stdouterr_buffer_struct)); > > > is this memory getting freed? -- Venkat Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From scott.stk at gmail.com Wed Apr 9 00:15:38 2008 From: scott.stk at gmail.com (Scott Cox) Date: Tue, 8 Apr 2008 17:15:38 -0500 Subject: [C++-sig] Introduction of myself. In-Reply-To: <8bdb0d630804072016w592b24e0uc9ef157db7cd5e2e@mail.gmail.com> References: <7b22c6cc0804071508v688380c3hbd585c35df97c9a2@mail.gmail.com> <8bdb0d630804072016w592b24e0uc9ef157db7cd5e2e@mail.gmail.com> Message-ID: <7b22c6cc0804081515v4f784a8bv87d2fe0a3c07a8e1@mail.gmail.com> > > You may not be aware that the Source engine is already scriptable using > python. Try here > http://python.eventscripts.com/pages/Main_Page > > - Tristam MacDonald > Yeah, I looked into that a while ago. Problem is, that's not what we need. That's a scripted events plugin, which allows users to create small mods to the engine, like weapons and tools, but doesn't give them enough control to change some other aspects of the game, like the way the engine behaves or player properties. We need to give users a way to change certain areas of the C++ code without opening it. Anyways, thanks for all your help so far guys. -Sigfig -------------- next part -------------- An HTML attachment was scrubbed... URL: From nickm at sitius.com Wed Apr 9 18:28:57 2008 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 09 Apr 2008 12:28:57 -0400 Subject: [C++-sig] Problem with boost.python 1.35.0 References: Message-ID: <47FCEEC9.221918D9@sitius.com> Hi Grant, This seems to be related to the documentation patch I submitted some time ago. Could you try defining BOOST_PYTHON_NO_PY_SIGNATURES and see if this helps? Or could you provide small example, that duplicates the problem? What is the compiler version? Nikolay Mladenov Grant Tang wrote: > > My application works fine with previous versions of boost.python. But > I > tried to compile it with the boost.python 1.35.0, it fails with the > compilation. Can some one help me? > > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/detail/cv_traits_impl.hpp: > > In instantiation of 'const bool > boost::detail::cv_traits_imp<::EMAN_Aligner_Wrapper*>::is_const': > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/is_const.hpp:53: > > instantiated from 'boost::is_const<::EMAN_Aligner_Wrapper>' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/cv_category.hpp:31: > > instantiated from > 'boost::python::detail::cv_category<::EMAN_Aligner_Wrapper>' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:58: > > instantiated from 'typename Generator::result_type > boost::python::detail::unwind_ptr_type(U*, Generator*) [with Generator > = > boost::python::converter::detail::unwind_type_id_helper, U = > ::EMAN_Aligner_Wrapper]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:127: > > instantiated from 'static typename Generator::result_type > boost::python::detail::unwind_helper2<2>::execute(U& (*)(), > Generator*) > [with Generator = > boost::python::converter::detail::unwind_type_id_helper, U > = ::EMAN_Aligner_Wrapper]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/unwind_type.hpp:165: > > instantiated from 'typename Generator::result_type > boost::python::detail::unwind_type(boost::type*, Generator*) [with > Generator = boost::python::converter::detail::unwind_type_id_helper, U > = > ::EMAN_Aligner_Wrapper&]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/converter/pytype_function.hpp:45: > > instantiated from 'boost::python::type_info > boost::python::converter::detail::unwind_type_id_(boost::type*, > > mpl_::false_*) [with T = ::EMAN_Aligner_Wrapper&]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/converter/pytype_function.hpp:68: > > instantiated from 'static const PyTypeObject* > boost::python::converter::expected_pytype_for_arg::get_pytype() > [with T = > ::EMAN_Aligner_Wrapper&]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/signature.hpp:98: > > instantiated from 'static const > boost::python::detail::signature_element* > boost::python::detail::signature_arity<5u>::impl::elements() > [with Sig > = boost::mpl::v_item boost::mpl::v_item<::EMAN_Aligner_Wrapper&, > boost::mpl::v_mask > EMAN::Aligner&, EMAN::EMData*, EMAN::EMData*, const std::string&, > const > EMAN::Dict&>, 1>, 1>, 1>, 1>]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/detail/caller.hpp:232: > > instantiated from 'static boost::python::detail::py_func_sig_info > boost::python::detail::caller_arity<5u>::impl Sig>::signature() > [with F = boost::python::detail::nullary_function_adaptor, > > Policies = boost::python::default_call_policies, Sig = > boost::mpl::v_item boost::mpl::v_item<::EMAN_Aligner_Wrapper&, > boost::mpl::v_mask > EMAN::Aligner&, EMAN::EMData*, EMAN::EMData*, const std::string&, > const > EMAN::Dict&>, 1>, 1>, 1>, 1>]' > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/python/object/py_function.hpp:48: > > instantiated from 'boost::python::detail::py_func_sig_info > boost::python::objects::caller_py_function_impl::signature() > const > [with Caller = > boost::python::detail::caller > (*)()>, boost::python::default_call_policies, boost::mpl::v_item > boost::mpl::v_item<::EMAN_Aligner_Wrapper&, > boost::mpl::v_mask > EMAN::Aligner&, EMAN::EMData*, EMAN::EMData*, const std::string&, > const > EMAN::Dict&>, 1>, 1>, 1>, 1> >]' > /home/g/EMAN2/src/eman2/libpyEM/libpyAligner2.cpp:358: > instantiated from here > /home/g/library/boost_1_35_py2.5.ucs4/include/boost-1_35/boost/type_traits/detail/cv_traits_impl.hpp:37: > > internal compiler error: in make_rtl_for_nonlocal_decl, at > cp/decl.c:5067 > Please submit a full bug report, with preprocessed source if > appropriate. > See for instructions. > Preprocessed source stored into /tmp/cc2yhNUv.out file, please attach > this > to your bugreport. > make[2]: *** [libpyEM/CMakeFiles/pyAligner2.dir/libpyAligner2.o] Error > 1 > make[1]: *** [libpyEM/CMakeFiles/pyAligner2.dir/all] Error 2 > make: *** [all] Error 2 > > Grant > > --------------------------------------------------------------- > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From ndbecker2 at gmail.com Thu Apr 10 14:09:25 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 10 Apr 2008 08:09:25 -0400 Subject: [C++-sig] undefined symbols with def_readonly Message-ID: I have: struct turbo_enc_1_15 { ... static const int TAIL_BITS = 2*MEMORY; ... Then this wrapper: BOOST_PYTHON_MODULE(turbo_enc_1_15) { class_ ("turbo_enc_1_15", no_init) ... .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) ; At runtime I get this: ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE Anything obviously wrong here? From seefeld at sympatico.ca Thu Apr 10 14:44:44 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 10 Apr 2008 08:44:44 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: References: Message-ID: <47FE0BBC.2030205@sympatico.ca> Neal Becker wrote: > I have: > > struct turbo_enc_1_15 { > ... > static const int TAIL_BITS = 2*MEMORY; > ... > > Then this wrapper: > BOOST_PYTHON_MODULE(turbo_enc_1_15) > { > class_ ("turbo_enc_1_15", no_init) > ... > .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) > ; > > At runtime I get this: > ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE > > Anything obviously wrong here? The code above only shows the declaration of turbo_enc_1_15::TAIL_BITS, but not its definition. It seems the linker agrees with me that it is missing. (See 9.4.2/4 of the spec: "...The member shall still be defined in a namespace scope if it is used in the program..." It seems you can get away without the definition if you ever only take its value, but not its address. Note that in your code you pass the member's address to def_readonly(). May be what you really want is simply add an attribute to your class, using the (compile-time evaluated) value ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From ndbecker2 at gmail.com Thu Apr 10 15:03:19 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 10 Apr 2008 09:03:19 -0400 Subject: [C++-sig] undefined symbols with def_readonly References: <47FE0BBC.2030205@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Neal Becker wrote: >> I have: >> >> struct turbo_enc_1_15 { >> ... >> static const int TAIL_BITS = 2*MEMORY; >> ... >> >> Then this wrapper: >> BOOST_PYTHON_MODULE(turbo_enc_1_15) >> { >> class_ ("turbo_enc_1_15", no_init) >> ... >> .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) >> ; >> >> At runtime I get this: >> ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: >> _ZN14turbo_enc_1_159TAIL_BITSE >> >> Anything obviously wrong here? > > The code above only shows the declaration of turbo_enc_1_15::TAIL_BITS, > but not its definition. It seems the linker agrees with me that it is > missing. (See 9.4.2/4 of the spec: > > "...The member shall still be defined in a namespace scope if it is used > in the program..." > > It seems you can get away without the definition if you ever only take > its value, but not its address. > Note that in your code you pass the member's address to def_readonly(). > May be what you really want is simply add an attribute to your class, > using the (compile-time evaluated) value ? > Yes, I just want to get the (compile-time evaluated) value. What is the suggested way to do this? From seefeld at sympatico.ca Thu Apr 10 15:07:57 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 10 Apr 2008 09:07:57 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: References: <47FE0BBC.2030205@sympatico.ca> Message-ID: <47FE112D.2020006@sympatico.ca> Neal Becker wrote: >>> class_ ("turbo_enc_1_15", no_init) >>> ... >>> .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) [...] > Yes, I just want to get the (compile-time evaluated) value. What is the > suggested way to do this? Try .def_readonly ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) (i.e. without the address-of operator). If that doesn't work, simply set a raw attribute: .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From ndbecker2 at gmail.com Thu Apr 10 15:27:53 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 10 Apr 2008 09:27:53 -0400 Subject: [C++-sig] undefined symbols with def_readonly References: <47FE0BBC.2030205@sympatico.ca> <47FE112D.2020006@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Neal Becker wrote: > >>>> class_ ("turbo_enc_1_15", no_init) >>>> ... >>>> .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) > > [...] > >> Yes, I just want to get the (compile-time evaluated) value. What is the >> suggested way to do this? > > Try > > .def_readonly ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > > (i.e. without the address-of operator). If that doesn't work, simply set > a raw attribute: > > .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > HTH, > Stefan > Surprisingly, this still doesn't work: ... .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE From seefeld at sympatico.ca Thu Apr 10 15:35:12 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 10 Apr 2008 09:35:12 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: References: <47FE0BBC.2030205@sympatico.ca> <47FE112D.2020006@sympatico.ca> Message-ID: <47FE1790.1000403@sympatico.ca> Neal Becker wrote: > Surprisingly, this still doesn't work: > ... > .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE And this: int const tail_bits = turbo_enc_1_15::TAIL_BITS; ... .setattr("TAIL_BITS", tail_bits) ? Note that the class_<>::setattr() method still takes a reference of its second argument, which, if the compiler doesn't optimize it away, emits a symbol reference. So, introducing this local 'tail_bits' variable has basically the same effect as defining turbo_enc_1_15::TAIL_BITS. The latter would obviously be the more proper solution to your problem, but if you don't want or can't do that, such a local variable may be a viable workaround. (Not sure how portable it is, though.) Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From roman.yakovenko at gmail.com Thu Apr 10 15:43:48 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 10 Apr 2008 16:43:48 +0300 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: <47FE1790.1000403@sympatico.ca> References: <47FE0BBC.2030205@sympatico.ca> <47FE112D.2020006@sympatico.ca> <47FE1790.1000403@sympatico.ca> Message-ID: <7465b6170804100643o4c8a2be0i149c3ef082738870@mail.gmail.com> On Thu, Apr 10, 2008 at 4:35 PM, Stefan Seefeld wrote: > Neal Becker wrote: > > > Surprisingly, this still doesn't work: > > ... > > .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > > > ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE > > And this: > > int const tail_bits = turbo_enc_1_15::TAIL_BITS; > > ... > .setattr("TAIL_BITS", tail_bits) > > ? > > Note that the class_<>::setattr() method still takes a reference of its > second argument, which, if the compiler doesn't optimize it away, emits > a symbol reference. So, introducing this local 'tail_bits' variable has > basically the same effect as defining turbo_enc_1_15::TAIL_BITS. The > latter would obviously be the more proper solution to your problem, but > if you don't want or can't do that, such a local variable may be a > viable workaround. (Not sure how portable it is, though.) May be you should try some other way: using boost::python; scope().attr("TAIL_BITS") = object(TAIL_BITS); -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From ndbecker2 at gmail.com Thu Apr 10 15:55:45 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 10 Apr 2008 09:55:45 -0400 Subject: [C++-sig] undefined symbols with def_readonly References: <47FE0BBC.2030205@sympatico.ca> <47FE112D.2020006@sympatico.ca> <47FE1790.1000403@sympatico.ca> <7465b6170804100643o4c8a2be0i149c3ef082738870@mail.gmail.com> Message-ID: Roman Yakovenko wrote: > On Thu, Apr 10, 2008 at 4:35 PM, Stefan Seefeld > wrote: >> Neal Becker wrote: >> >> > Surprisingly, this still doesn't work: >> > ... >> > .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) >> > >> > ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: >> > _ZN14turbo_enc_1_159TAIL_BITSE >> >> And this: >> >> int const tail_bits = turbo_enc_1_15::TAIL_BITS; >> >> ... >> .setattr("TAIL_BITS", tail_bits) >> >> ? >> >> Note that the class_<>::setattr() method still takes a reference of its >> second argument, which, if the compiler doesn't optimize it away, emits >> a symbol reference. So, introducing this local 'tail_bits' variable has >> basically the same effect as defining turbo_enc_1_15::TAIL_BITS. The >> latter would obviously be the more proper solution to your problem, but >> if you don't want or can't do that, such a local variable may be a >> viable workaround. (Not sure how portable it is, though.) > > May be you should try some other way: > > using boost::python; > scope().attr("TAIL_BITS") = object(TAIL_BITS); > Will this make it an class variable? From lists at informa.tiker.net Thu Apr 10 17:11:34 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Thu, 10 Apr 2008 11:11:34 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: References: <47FE0BBC.2030205@sympatico.ca> Message-ID: <200804101111.38600.lists@informa.tiker.net> On Donnerstag 10 April 2008, Neal Becker wrote: > Stefan Seefeld wrote: > > Neal Becker wrote: > >> I have: > >> > >> struct turbo_enc_1_15 { > >> ... > >> static const int TAIL_BITS = 2*MEMORY; > >> ... > >> > >> Then this wrapper: > >> BOOST_PYTHON_MODULE(turbo_enc_1_15) > >> { > >> class_ ("turbo_enc_1_15", no_init) > >> ... > >> .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) > >> ; > >> > >> At runtime I get this: > >> ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: > >> _ZN14turbo_enc_1_159TAIL_BITSE > >> > >> Anything obviously wrong here? > > > > The code above only shows the declaration of turbo_enc_1_15::TAIL_BITS, > > but not its definition. It seems the linker agrees with me that it is > > missing. (See 9.4.2/4 of the spec: > > > > "...The member shall still be defined in a namespace scope if it is used > > in the program..." > > > > It seems you can get away without the definition if you ever only take > > its value, but not its address. > > Note that in your code you pass the member's address to def_readonly(). > > May be what you really want is simply add an attribute to your class, > > using the (compile-time evaluated) value ? > > Yes, I just want to get the (compile-time evaluated) value. What is the > suggested way to do this? You can add a static getter function and expose that. Works for me with the same problem: (snippet from my code) pic_wrap .add_static_property("dimensions_pos", &cl::get_dimensions_pos) Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From goldberg at coredp.com Thu Apr 10 18:12:20 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Thu, 10 Apr 2008 12:12:20 -0400 Subject: [C++-sig] to python conversion for derived facade Message-ID: <47FE3C64.6030200@corefa.com> Hi, I don't have a lot of experience with boost, expecially not with to_python_converters, and I've been getting some unexpected results. I have spent a while looking around to see what I can find, but I can't seem to solve my problem, hopefully someone here can give me a hand. Here's the situation. I have a facade class, and a class derived from it. The facade class is exposed to python but the derived class isn't (there are reasons for this, so exposing the derived class to python isn't an option). The derived class wraps a type (let's call it cpp_type - and it is also a type that I do not want exposed to python) that the base class does not. I several functions that return a cpp_type_sptr (a smart pointer to cpp_type). I would like to create a to python converter so that I don't have to manually wrap each function that returns a cpp_type_sptr. The to_python_converter that I wrote returns a facade to python instead of a facade_derived. As you will be able to see in the example (below) the facade_derived does get created properly in C++, but somehow when it gets passed to python, it gets converted to a facade. I have simlpified the code (a lot) to create a small subset that highlights exactly the issue that I am having. Here it is. C++ source code: #include #include #include using namespace boost::python; class cpp_type { public: cpp_type(std::string n="") : refcount(0), name_(n) { } std::string name() { return name_; } protected: friend class cpp_type_sptr; void ref() { ++refcount; } void unref() { if (--refcount <= 0) { // This is getting called twice. Instead of fixing the bug, I'm // going to ignore deletion, since it's not important to this // example //delete this; } } int refcount; std::string name_; }; class cpp_type_sptr { public: cpp_type_sptr(): ptr_(NULL) { } cpp_type_sptr(cpp_type* ct): ptr_(ct) { if (ptr_) { ptr_->ref(); } } virtual ~cpp_type_sptr() { if (ptr_) { ptr_->unref(); } } operator bool() const { return (ptr_ != (cpp_type*)0)? true : false; } bool operator!() const { return (ptr_ != (cpp_type*)0)? false : true; } cpp_type &operator * () const { return *ptr_; } cpp_type *operator -> () const { return ptr_; } private: cpp_type* ptr_; }; struct facade { facade() { } virtual std::string ct_name() { return "not telling"; } }; struct facade_derived : public facade { facade_derived(cpp_type_sptr x) { if (x) { ct = *x; } } virtual std::string ct_name() { return ct.name(); } cpp_type ct; }; struct facade_wrapper : facade,boost::python::wrapper { virtual std::string ct_name() { return this->get_override("ct_name")(); } }; facade * make_facade(cpp_type_sptr x = NULL) { if (!x) { return new facade(); } else { return new facade_derived(x); } }; struct type_to_facade { static PyObject* convert(cpp_type_sptr ct) { return incref(object(make_facade(ct)).ptr()); } }; cpp_type_sptr do_stuff(std::string s) { cpp_type *ct = new cpp_type(s); std::cout << "from C++ ct_name -> " << ct->name() << std::endl; return cpp_type_sptr(ct); } BOOST_PYTHON_MODULE(mod) { class_< facade >("facade", no_init); class_< facade_wrapper, boost::noncopyable >("facade") .def("name", &facade::ct_name) ; to_python_converter(); def("do_stuff", do_stuff); } using the python module: >>> from mod import * >>> g = do_stuff("some awesome name") from C++ ct_name -> some awesome name >>> g.name() 'not telling' As you can see, in C++ the object gets created correctly, but the python object does not. Thanks in advance for any help. -MG From per at gorep.se Fri Apr 11 02:26:20 2008 From: per at gorep.se (Per Ghosh) Date: Thu, 10 Apr 2008 17:26:20 -0700 (PDT) Subject: [C++-sig] 'iteritems', 'iterkeys' and 'itervalues' in dict In-Reply-To: <20061015200223.21926.qmail@web27907.mail.ukl.yahoo.com> References: <20061015200223.21926.qmail@web27907.mail.ukl.yahoo.com> Message-ID: <16622870.post@talk.nabble.com> I am new to boost.python but this is something that worked for me, Is there a more simple way to manage dicts and key/value pairs in the dict? void CPyFormat::Add( boost::python::dict& rdictValues ) { gd_std::wstring stringKey, stringValue; boost::python::object objectKey, objectValue; const boost::python::object objectKeys = rdictValues.iterkeys(); const boost::python::object objectValues = rdictValues.itervalues(); unsigned long ulCount = boost::python::extract(rdictValues.attr("__len__")()); for( unsigned long u = 0; u < ulCount; u++ ) { objectKey = objectKeys.attr( "next" )(); objectValue = objectValues.attr( "next" )(); char chCheckKey = objectKey.ptr()->ob_type->tp_name[0]; // simple check if( chCheckKey != 's' && chCheckKey != 'u' ) throw std::runtime_error( "Unknown key type" ); if( chCheckKey == 's' ) stringKey = boost::python::extract(objectKey); else stringKey = boost::python::extract(objectKey); char chCheckValue = objectValue.ptr()->ob_type->tp_name[0]; // simple check if( chCheckValue != 's' && chCheckValue != 'u' ) throw std::runtime_error( "Unknown value type" ); if( chCheckValue == 's' ) stringValue = boost::python::extract(objectValue); else stringValue = boost::python::extract(objectValue); m_vectorProperties.push_back( std::pair( stringKey.c_str(), stringValue.c_str() ) ); } } Nindi Singh wrote: > > Apolgies for not putting the subject line in my last email. > > In the Boost.Python dict class there are methods 'iteritems', 'iterkeys' > and 'itervalues' all returning objects. > How exactly are you supposed to use these objects (iterators) ? > > > ___________________________________________________________ > Inbox full of spam? Get leading spam protection and 1GB storage with All > New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--%27iteritems%27%2C-%27iterkeys%27-and-%27itervalues%27--in-dict-tp6824331p16622870.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From venkat83 at gmail.com Fri Apr 11 05:05:34 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Fri, 11 Apr 2008 03:05:34 +0000 Subject: [C++-sig] Passed by Reference or value Message-ID: Hi, While using the Boost::Python(extending) , when we pass objects from Python - are these passed to C/C++ by value or by reference? How do we pass objects by reference so that the additional overhead of copying the objetcs etc does not occur. -- Venkat Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bill at SynectixLtd.com Fri Apr 11 10:11:50 2008 From: Bill at SynectixLtd.com (Bill Davy) Date: Fri, 11 Apr 2008 09:11:50 +0100 Subject: [C++-sig] Need to supply (char*) argument Message-ID: <005c01c89bab$b1b06720$0201a8c0@rwdnb> Sorry if this is a bit simple but any help welcome. I am adding some C++ code to Python. From Python I want to be able to read data from a target device, over USB. My software does all the hard work and I have a class: typedef unsigned __int8 u8; typedef unsigned __int16 u16; typedef int ErrorT; class ViperUsbC { public: // snip snip ErrorT ReadSlaveMemory(u8 Slave, u16 Offset, u8* pData, u16 Length); // Snip,snip }; I use swigwin-1.3.34 to wrap it into a module called SHIP. In Python, I have: import SHIP ViperUsb = SHIP.ViperUsbC() Slave =7 Offset = 0 Length = 64 Buffer = 'a' * Length print "type(Buffer)=%s" % type(Buffer) print "len(Buffer)=%s" % len(Buffer) Result = ViperUsb.ReadSlaveMemory(Slave, Offset, Buffer, Length); That fails with: type(Buffer)= len(Buffer)=64 Traceback (most recent call last): File "H:\Husky\HostPC\V1\SHIP\test1.py", line 1970, in -toplevel- ViperTests() File "H:\Husky\HostPC\V1\SHIP\test1.py", line 1884, in ViperTests Result = ViperUsb.ReadSlaveMemory(Slave, Offset, Buffer, Length); File "H:\Husky\HostPC\V1\SHIP\Release\SHIP.py", line 1757, in ReadSlaveMemory def ReadSlaveMemory(*args): return _SHIP.ViperUsbC_ReadSlaveMemory(*args) TypeError: in method 'ViperUsbC_ReadSlaveMemory', argument 4 of type 'u8 *' How do I provide a buffer into which to read the data? It would not be intolerable to provide another layer using %extend, but I feel sure this should be automagic. Thanks in advance Bill PS This is a very small part of a much larger project so I cannot supply complete source code. ~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,.~*""*~., Privileged/Confidential information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and please notify us immediately. Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information expressed in this message are not given or endorsed by my firm or employer unless otherwise indicated by an authorised representative independent of this message. Although we utilise the most up to date virus checking procedures you should carry out your own virus check before opening any attachment. We accept no liability for any loss or damage which may be caused by software viruses. ~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,.~*""*~., Bill Davy, Synectix Limited, 12 King Alfred Way, Cheltenham, GL52 6QP, England Registered Office: as above Registered in England and Wales No 2946363 Telephone: +44 (0)1242 254411, Mobile: +44 (0)7866 451568, Fax: +44 (0)1242 256611 Work: mailto:Bill at SynectixLtd.com Home: mailto:Bill at XchelSys.co.uk Web: http://www.synectixltd.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart at myphones.com Fri Apr 11 10:34:00 2008 From: stuart at myphones.com (Stuart Marsden) Date: Fri, 11 Apr 2008 09:34:00 +0100 Subject: [C++-sig] Problem with boost.python 1.35.0 Message-ID: <47FF2278.5000007@myphones.com> Hi, this looks like the same problem - have created a simple test case this works on 1.35.0 on Centos 4 (gcc 3.4.6) but gives the same error as previous post on Centos 5 (4.1.2) more test.cpp #include #include #include #include #include #include #include #include #include namespace { class Test { public: Test (int aa, int bb, std::string cc) { } ~Test () { } int start (std::string ddd, int ee) { return 1; } int getport () { return 1; } private: }; } BOOST_PYTHON_MODULE (test) { using namespace boost::python; class_ < Test > ("Test", init < int, int, std::string >()) // Add regular member functions .def ("getport", &Test::getport) .def ("start", &Test::start ) ; } From stuart at myphones.com Fri Apr 11 11:27:30 2008 From: stuart at myphones.com (Stuart Marsden) Date: Fri, 11 Apr 2008 10:27:30 +0100 Subject: [C++-sig] Problem with boost.python 1.35.0 In-Reply-To: <47FF2278.5000007@myphones.com> References: <47FF2278.5000007@myphones.com> Message-ID: <47FF2F02.8050706@myphones.com> Defining BOOST_PYTHON_NO_PY_SIGNATURES fixes the problem Stuart Marsden wrote: > Hi, > > this looks like the same problem - have created a simple test case > this works on 1.35.0 on Centos 4 (gcc 3.4.6) but gives the same error > as previous post on Centos 5 (4.1.2) > > more test.cpp > #include > #include > #include > #include > #include > #include > #include > #include > #include > > namespace > { > > class Test > { > public: > Test (int aa, int bb, std::string cc) > { > } > ~Test () > { > } > int start (std::string ddd, int ee) > { > return 1; > } > int getport () > { > return 1; > } > private: > }; > } > > BOOST_PYTHON_MODULE (test) > { > using namespace boost::python; > class_ < Test > ("Test", init < int, int, std::string >()) > // Add regular member functions > .def ("getport", &Test::getport) > .def ("start", &Test::start ) > ; > } > From ndbecker2 at gmail.com Fri Apr 11 13:32:07 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 11 Apr 2008 07:32:07 -0400 Subject: [C++-sig] undefined symbols with def_readonly References: <47FE0BBC.2030205@sympatico.ca> <200804101111.38600.lists@informa.tiker.net> Message-ID: Andreas Kl?ckner wrote: > On Donnerstag 10 April 2008, Neal Becker wrote: >> Stefan Seefeld wrote: >> > Neal Becker wrote: >> >> I have: >> >> >> >> struct turbo_enc_1_15 { >> >> ... >> >> static const int TAIL_BITS = 2*MEMORY; >> >> ... >> >> >> >> Then this wrapper: >> >> BOOST_PYTHON_MODULE(turbo_enc_1_15) >> >> { >> >> class_ ("turbo_enc_1_15", no_init) >> >> ... >> >> .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) >> >> ; >> >> >> >> At runtime I get this: >> >> ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: >> >> _ZN14turbo_enc_1_159TAIL_BITSE >> >> >> >> Anything obviously wrong here? >> > >> > The code above only shows the declaration of turbo_enc_1_15::TAIL_BITS, >> > but not its definition. It seems the linker agrees with me that it is >> > missing. (See 9.4.2/4 of the spec: >> > >> > "...The member shall still be defined in a namespace scope if it is >> > used in the program..." >> > >> > It seems you can get away without the definition if you ever only take >> > its value, but not its address. >> > Note that in your code you pass the member's address to def_readonly(). >> > May be what you really want is simply add an attribute to your class, >> > using the (compile-time evaluated) value ? >> >> Yes, I just want to get the (compile-time evaluated) value. What is the >> suggested way to do this? > > You can add a static getter function and expose that. Works for me with > the same problem: (snippet from my code) > > pic_wrap > .add_static_property("dimensions_pos", &cl::get_dimensions_pos) > > Andreas Didn't work here. .add_static_property ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) Still gives ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE But what's _really_ weird, is: .add_static_property ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) gives: TypeError: 'int' object is not callable when that value is used. From seefeld at sympatico.ca Fri Apr 11 13:40:41 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 11 Apr 2008 07:40:41 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: References: <47FE0BBC.2030205@sympatico.ca> <200804101111.38600.lists@informa.tiker.net> Message-ID: <47FF4E39.9000805@sympatico.ca> Neal, you haven't commented on whether my (last two) suggestions worked. Did they ? Neal Becker wrote: >> pic_wrap >> .add_static_property("dimensions_pos", &cl::get_dimensions_pos) >> >> Andreas > > Didn't work here. > .add_static_property ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS) > > Still gives > ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE Yes of course. The problem is totally unrelated to boost.python, as I tried to explain in my very first reply. It's because you never define the static member, so no memory for it is allocated that you can dereference (and no associated symbol is emitted). Using its value itself works, as the compiler already knows that, so can fold it into the expression wherever it occurs. > But what's _really_ weird, is: > .add_static_property ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > gives: > TypeError: 'int' object is not callable That suggests that, even though the add_static_property function template is generic (read: unconstrained) in its second parameter (leading to the construction of a python 'int' object holding TAIL_BITS), such an object is not callable (as static properties should be). In other words, users are expected to pass function (pointers) or similar there, and the implementation of add_static_property just fails to enforce that. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From ndbecker2 at gmail.com Fri Apr 11 14:22:14 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 11 Apr 2008 08:22:14 -0400 Subject: [C++-sig] undefined symbols with def_readonly References: <47FE0BBC.2030205@sympatico.ca> <47FE112D.2020006@sympatico.ca> <47FE1790.1000403@sympatico.ca> Message-ID: Stefan Seefeld wrote: > Neal Becker wrote: > >> Surprisingly, this still doesn't work: >> ... >> .setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) >> >> ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: >> _ZN14turbo_enc_1_159TAIL_BITSE > > And this: > > int const tail_bits = turbo_enc_1_15::TAIL_BITS; > > ... > .setattr("TAIL_BITS", tail_bits) > > ? > > Note that the class_<>::setattr() method still takes a reference of its > second argument, which, if the compiler doesn't optimize it away, emits > a symbol reference. So, introducing this local 'tail_bits' variable has > basically the same effect as defining turbo_enc_1_15::TAIL_BITS. The > latter would obviously be the more proper solution to your problem, but > if you don't want or can't do that, such a local variable may be a > viable workaround. (Not sure how portable it is, though.) > > Regards, > Stefan > The above solution works fine, thanks. From lists at informa.tiker.net Fri Apr 11 16:26:51 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Fri, 11 Apr 2008 10:26:51 -0400 Subject: [C++-sig] undefined symbols with def_readonly In-Reply-To: <47FF4E39.9000805@sympatico.ca> References: <47FF4E39.9000805@sympatico.ca> Message-ID: <200804111026.52892.lists@informa.tiker.net> On Freitag 11 April 2008, Stefan Seefeld wrote: > > But what's _really_ weird, is: > > .add_static_property ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS) > > > > gives: > > TypeError: 'int' object is not callable > > That suggests that, even though the add_static_property function > template is generic (read: unconstrained) in its second parameter > (leading to the construction of a python 'int' object holding > TAIL_BITS), such an object is not callable (as static properties should > be). In other words, users are expected to pass function (pointers) or > similar there, and the implementation of add_static_property just fails > to enforce that. Yeah, that was kinda the whole point--you introduce a small static getter function to return the value of the static data member. That getter does not need to take the address of the member, and therefore you don't need to have memory allocated for it. Having the extra function "litter" around is not pretty, but it was acceptable to me. The address of the *getter* is what you pass to add_static_property(). Sorry for not being sufficiently clear. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From roman.yakovenko at gmail.com Fri Apr 11 19:51:03 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 11 Apr 2008 20:51:03 +0300 Subject: [C++-sig] to python conversion for derived facade In-Reply-To: <47FE3C64.6030200@corefa.com> References: <47FE3C64.6030200@corefa.com> Message-ID: <7465b6170804111051v236b374xb9daf6b6137743bf@mail.gmail.com> On Thu, Apr 10, 2008 at 7:12 PM, Moe Goldberg wrote: > Hi, > I don't have a lot of experience with boost, expecially not with > to_python_converters, and I've been getting some unexpected results. I > have spent a while looking around to see what I can find, but I can't > seem to solve my problem, hopefully someone here can give me a hand. > > Here's the situation. I have a facade class, and a class derived from > it. The facade class is exposed to python but the derived class isn't > (there are reasons for this, so exposing the derived class to python > isn't an option). The derived class wraps a type (let's call it cpp_type > - and it is also a type that I do not want exposed to python) that the > base class does not. > I several functions that return a cpp_type_sptr (a smart pointer to > cpp_type). I would like to create a to python converter so that I don't > have to manually wrap each function that returns a cpp_type_sptr. I am not sure whether I understand what you are trying to do, but if you want to return something different from the function you can define custom call policy. Take a look on custom call policies I defined docs: http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies source code: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/ This solution also allows you not to expose cpp_type_sptr class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Fri Apr 11 19:58:32 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 11 Apr 2008 20:58:32 +0300 Subject: [C++-sig] Need to supply (char*) argument In-Reply-To: <005c01c89bab$b1b06720$0201a8c0@rwdnb> References: <005c01c89bab$b1b06720$0201a8c0@rwdnb> Message-ID: <7465b6170804111058x5f08d066pd27a8c57d1461e9a@mail.gmail.com> 2008/4/11 Bill Davy : > Sorry if this is a bit simple but any help welcome. > > I am adding some C++ code to Python. From Python I want to be able to read > data from a target device, over USB. My software does all the hard work and > I have a class: > > > typedef unsigned __int8 u8; > > typedef unsigned __int16 u16; > > > > typedef int ErrorT; > > > class ViperUsbC > { > public: > // snip snip > ErrorT ReadSlaveMemory(u8 Slave, u16 Offset, u8* pData, u16 Length); > // Snip,snip > }; > > I use swigwin-1.3.34 to wrap it into a module called SHIP. I don't know how you can achieve this with SWIG, but the general idea is simple: define another function that read "n" u8 and return them in some Python object. The interface you have, could not be exposed as-is to Python. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From diresu at web.de Sat Apr 12 15:38:38 2008 From: diresu at web.de (Dietrich Bollmann) Date: Sat, 12 Apr 2008 22:38:38 +0900 Subject: [C++-sig] segmentation fault when executing PyImport_ImportModule("sys") In-Reply-To: <1207650694.845.8.camel@pippi.pippi> References: <1207650694.845.8.camel@pippi.pippi> Message-ID: <1208007518.5770.7.camel@pippi.pippi> Hi, I found the reason for the sementation fault and hope that my solution might be helpfull for somebody else some day :) On Tue, 2008-04-08 at 19:31 +0900, Dietrich Bollmann wrote: Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0xb046ab90 (LWP 9854)] > threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154 > 154 ../Python/pystate.c: No such file or directory. > in ../Python/pystate.c > (gdb) bt full > #0 threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154 > No locals. > #1 0xb7e8a897 in PyEval_GetGlobals () at ../Python/ceval.c:3340%G?% @ > ...snip... > #3 0xb7eaede5 in PyImport_ImportModule (name=0x901504b "sys")%G?%@ > ...snip... The segmentation fault was caused by the interaction of my own code with some changes made to the code base recently which where intended to make the python functions thread save: Here come the new additions to the function which starts the Python interpreter: void BPY_start_python( int argc, char **argv ) { PyThreadState *py_tstate = NULL; ... /* Initialize thread support (also acquires lock) */ PyEval_InitThreads(); /* Don'\''t allow the Python Interpreter to release the GIL on * its own, to guarantee PyNodes work properly. For Blender this * is currently the best default behavior. * The following code in C is equivalent in Python to: * "import sys; sys.setcheckinterval(sys.maxint)" */ _Py_CheckInterval = PyInt_GetMax(); ... py_tstate = PyGILState_GetThisThreadState(); PyEval_ReleaseThread(py_tstate); ... } Until recently only one thread accessed python objects and there was no need for any code making Python thread-save. This didn't cause any problem with my own code as I only inserted events in form of python code to execute into a thread save event queue which was worked off by the only thread accessing python objects. With the new python thread code added I had to surround all my code which accesses python objects with PyGILState_*() in order to solve the problem: PyGILState_STATE gstate; /* aquire python thread */ gstate = PyGILState_Ensure(); ...access python objects... /* release python thread */ PyGILState_Release(gstate); The PyGILState_*() functions ensure that a global Python thread lock is held by the current thread, protecting the Python objects from being accessed by other threads in the same time. For more detailled explanations see the chapter "8.1 Thread State and the Global Interpreter Lock" (http://docs.python.org/api/threads.html) in the Python/C API Reference Manual. Thanks for your help, Dietrich From diresu at web.de Sat Apr 12 15:46:45 2008 From: diresu at web.de (Dietrich Bollmann) Date: Sat, 12 Apr 2008 22:46:45 +0900 Subject: [C++-sig] segmentation fault when executing PyImport_ImportModule("sys") In-Reply-To: References: <1207650694.845.8.camel@pippi.pippi> Message-ID: <1208008005.5770.15.camel@pippi.pippi> Hi Venkatraman S, Thanks for you answer: On Tue, 2008-04-08 at 19:59 +0530, Venkatraman S wrote: > > > On Tue, Apr 8, 2008 at 4:01 PM, Dietrich Bollmann > wrote: > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0xb046ab90 (LWP 9854)] > threadstate_getframe (self=0xb7e8a889) > at ../Python/pystate.c:154 > 154 ../Python/pystate.c: No such file or directory. > in ../Python/pystate.c > > Am not sure whether i get the context right - but i was stumbling on > ?a similar SIGSERV in a multithreaded app - profiling with Valgrind > turned out to be much useful and the memory leak was fixed. I already had found the right trace and didn't need Valgrind anymore. (if you are interested, here is the solution to my problem: http://mail.python.org/pipermail/c++-sig/2008-April/013448.html ) But I had a look on Valgrind and found it very promising :) The next time in a similar situation I will definitely give it a try! Thanks again, Dietrich From d.bollmann at tu-berlin.de Sat Apr 12 16:00:14 2008 From: d.bollmann at tu-berlin.de (Dietrich Bollmann) Date: Sat, 12 Apr 2008 23:00:14 +0900 Subject: [C++-sig] segmentation fault when executingPyImport_ImportModule("sys") In-Reply-To: References: <1207650694.845.8.camel@pippi.pippi> Message-ID: <1208008814.5770.25.camel@pippi.pippi> Hi Mark - another answer to your last email... On Tue, 2008-04-08 at 12:01 +0100, English, Mark wrote: > > Dietrich Bollmann wrote: > > Since some time I get the following segmentation fault in an > > application which used to work fine until recently. > Just a thought: have you called PyEval_InitThreads from the main thread > at startup ? finally your answer pointed to the right direction: See http://mail.python.org/pipermail/c++-sig/2008-April/013448.html for the solution to my segmentaion fault problem :) Thanks, Dietrich From goldberg at coredp.com Mon Apr 14 22:12:59 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Mon, 14 Apr 2008 16:12:59 -0400 Subject: [C++-sig] to python conversion for derived facade In-Reply-To: <7465b6170804111051v236b374xb9daf6b6137743bf@mail.gmail.com> References: <47FE3C64.6030200@corefa.com> <7465b6170804111051v236b374xb9daf6b6137743bf@mail.gmail.com> Message-ID: <4803BACB.2070302@corefa.com> Thanks. In the end, I determined that I cannot autmoatically convert to a derived class unless I expose it, which makes sense, I guess. Roman Yakovenko wrote: >On Thu, Apr 10, 2008 at 7:12 PM, Moe Goldberg wrote: > > >>Hi, >> I don't have a lot of experience with boost, expecially not with >> to_python_converters, and I've been getting some unexpected results. I >> have spent a while looking around to see what I can find, but I can't >> seem to solve my problem, hopefully someone here can give me a hand. >> >> Here's the situation. I have a facade class, and a class derived from >> it. The facade class is exposed to python but the derived class isn't >> (there are reasons for this, so exposing the derived class to python >> isn't an option). The derived class wraps a type (let's call it cpp_type >> - and it is also a type that I do not want exposed to python) that the >> base class does not. >> I several functions that return a cpp_type_sptr (a smart pointer to >> cpp_type). I would like to create a to python converter so that I don't >> have to manually wrap each function that returns a cpp_type_sptr. >> >> > >I am not sure whether I understand what you are trying to do, but if >you want to return something different from the function you can >define custom call policy. > >Take a look on custom call policies I defined >docs: http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#py-defined-call-policies >source code: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/ > >This solution also allows you not to expose cpp_type_sptr class. > > > From nickm at sitius.com Mon Apr 14 23:56:01 2008 From: nickm at sitius.com (Nikolay Mladenov) Date: Mon, 14 Apr 2008 17:56:01 -0400 Subject: [C++-sig] Problem with boost.python 1.35.0 References: <47FF2278.5000007@myphones.com> Message-ID: <4803D2F1.BF330989@sitius.com> I couldn't duplicate this on with : ~/tmp/boost_1_34_0_RC.svn/libs/python/test$ gcc --version gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) Copyright (C) 2006 Free Software Foundation, Inc. could you post the error again, the way it is generated from your example? Nikolay Mladenov Stuart Marsden wrote: > > Hi, > > this looks like the same problem - have created a simple test case this > works on 1.35.0 on Centos 4 (gcc 3.4.6) but gives the same error as > previous post on Centos 5 (4.1.2) > > more test.cpp > #include > #include > #include > #include > #include > #include > #include > #include > #include > > namespace > { > > class Test > { > public: > Test (int aa, int bb, std::string cc) > { > } > ~Test () > { > } > int start (std::string ddd, int ee) > { > return 1; > } > int getport () > { > return 1; > } > private: > }; > } > > BOOST_PYTHON_MODULE (test) > { > using namespace boost::python; > class_ < Test > ("Test", init < int, int, std::string >()) > // Add regular member functions > .def ("getport", &Test::getport) > .def ("start", &Test::start ) > ; > } From hgroven at emgs.com Tue Apr 15 16:17:28 2008 From: hgroven at emgs.com (=?ISO-8859-1?Q?H=E5kon_Groven?=) Date: Tue, 15 Apr 2008 16:17:28 +0200 Subject: [C++-sig] try-except for non-standard exception Message-ID: <4804B8F8.8000909@emgs.com> Hi! I'm trying to expose my cpp-defined exception so that i can do something like this in Python: try: value = someObject.someFunction() except Pyelio.ElioError, e: print e.what() I have tried to do the following in the cpp wrapper: namespace { struct emgs_elio_ElioError_Wrapper: ElioError { emgs_elio_ElioError_Wrapper(PyObject* py_self_, const ElioError& p0): ElioError(p0), py_self(py_self_) {} emgs_elio_ElioError_Wrapper(PyObject* py_self_): ElioError(), py_self(py_self_) {} emgs_elio_ElioError_Wrapper(PyObject* py_self_, const std::string& p0): ElioError(p0), py_self(py_self_) {} const char* what() const throw() { return call_method< const char* >(py_self, "what"); } const char* default_what() const { return ElioError::what(); } PyObject* py_self; }; void translate(ElioError const& e) { PyErr_SetString(PyErr_NewException( "Pyelio.ElioError", PyExc_StandardError, NULL), e.what()); }; } BOOST_PYTHON_MODULE(Pyelio) { register_exception_translator(&translate(); class_< ElioError, emgs_elio_ElioError_Wrapper >("ElioError", init< const ElioError& >()) .def(init< optional< const std::string& > >()) .def("what", (const char* (ElioError::*)() const throw())&ElioError::what, (const char* (emgs_elio_ElioError_Wrapper::*)() const)&emgs_elio_ElioError_Wrapper::default_what) .def("printStackTrace", &ElioError::printStackTrace) ; } Because of my translate function my exception is a standard error on the python side and not a Pyelio.ElioError. However, if i print type(e) in python I get the string from my translate func: "Pyelio.ElioError". I would be very thankful if anybody could help me out/post a minimal example of how to wrap/expose a cpp-defined exception. Hakon. From roman.yakovenko at gmail.com Tue Apr 15 19:10:53 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 15 Apr 2008 20:10:53 +0300 Subject: [C++-sig] try-except for non-standard exception In-Reply-To: <4804B8F8.8000909@emgs.com> References: <4804B8F8.8000909@emgs.com> Message-ID: <7465b6170804151010p32d05316qc0972e69356299f@mail.gmail.com> On Tue, Apr 15, 2008 at 5:17 PM, H?kon Groven wrote: > Hi! > > I'm trying to expose my cpp-defined exception so that i can do something > like this in Python: > > try: > value = someObject.someFunction() > except Pyelio.ElioError, e: > print e.what() > > I have tried to do the following in the cpp wrapper: > > namespace > { > struct emgs_elio_ElioError_Wrapper: ElioError > { > emgs_elio_ElioError_Wrapper(PyObject* py_self_, const > ElioError& p0): > ElioError(p0), py_self(py_self_) > {} > > emgs_elio_ElioError_Wrapper(PyObject* py_self_): > ElioError(), py_self(py_self_) > {} > > emgs_elio_ElioError_Wrapper(PyObject* py_self_, const > std::string& p0): > ElioError(p0), py_self(py_self_) > {} > > const char* what() const throw() > { > return call_method< const char* >(py_self, "what"); > } > > const char* default_what() const > { > return ElioError::what(); > } > > PyObject* py_self; > }; > > void translate(ElioError const& e) > { > PyErr_SetString(PyErr_NewException( > "Pyelio.ElioError", > PyExc_StandardError, NULL), > e.what()); > }; > } > > BOOST_PYTHON_MODULE(Pyelio) > { > register_exception_translator(&translate(); > > class_< ElioError, emgs_elio_ElioError_Wrapper >("ElioError", init< > const ElioError& >()) > .def(init< optional< const std::string& > >()) > .def("what", (const char* (ElioError::*)() const > throw())&ElioError::what, (const char* > (emgs_elio_ElioError_Wrapper::*)() > const)&emgs_elio_ElioError_Wrapper::default_what) > .def("printStackTrace", &ElioError::printStackTrace) > ; > > } > > Because of my translate function my exception is a standard error on the > python side and not a Pyelio.ElioError. However, if i print type(e) in > python I get the string from my translate func: "Pyelio.ElioError". > > I would be very thankful if anybody could help me out/post a minimal > example of how to wrap/expose a cpp-defined exception. http://language-binding.net/pyplusplus/troubleshooting_guide/exceptions/exceptions.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From etrek at cox.net Wed Apr 16 09:40:07 2008 From: etrek at cox.net (etrek) Date: Wed, 16 Apr 2008 00:40:07 -0700 Subject: [C++-sig] bjam is not working for me Message-ID: <0B346CDAC4AB43A782FC646B0370D18A@Voyager> Hello, I cannot get the bjam command to create .pyd files or the boost_python.dll. I have MSVStudio 2005: MSVC 8.0 , Windows Vista32 I have Python25. Path to python is: C:\Python25 I installed Boost Library (BoostPro_1.34.1_Installer) from: http://www.boost-consulting.com/products/free This installation made it so that I did not have to "Build" the Boost libraries, unless I missunderstood the installation. Boost path: C:\Program Files\boost\boost_1_34_1 I am trying to do the Boost.Python tutorial and quickstart by following the directions on these webpages: http://www.boost.org/doc/libs/1_35_0/libs/python/doc/tutorial/doc/html/python/hello.html http://www.boost.org/doc/libs/1_35_0/libs/python/doc/building.html I put a user-config.jam file in my root directory. I set me environment variables PYTHON_ROOT and PYTHON_VERSION I cannot get bjam to work. No matter what I try. It updated targets and tests passed for ../examples/quickstart and created the bin folder, but the folder contained NO .pyd files or the boost_python.dll I ran bjam on the ../libs/python/tests folder. It said it was updating over 700+ targets and tests were reporting as passed. However, it did not create a bin folder or any .pyd files. I cannot get it to work at all with the ../example/tutorial folder. Here is the Jamroot file that came with the installation for the example/tutorial folder: # Copywrite David Abrahams 2006,,,etc. use-project boost : ../../../.. ; project : requirements /boost/python/boost_python ; python-extension hello : hello.cpp ; # end of Jamroot This Jamroot does not work. I keep getting this error: No best alternative for python-for-extensions. there is another minimalist Jamfile example in the help files. it does not work either. Can someone help me create a Jamfile that will work. Or if my environment is incorrect help me set it up. Thanks etrek -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart at myphones.com Wed Apr 16 17:05:14 2008 From: stuart at myphones.com (Stuart Marsden) Date: Wed, 16 Apr 2008 16:05:14 +0100 Subject: [C++-sig] Problem with boost.python 1.35.0 In-Reply-To: <4803D2F1.BF330989@sitius.com> References: <47FF2278.5000007@myphones.com> <4803D2F1.BF330989@sitius.com> Message-ID: <480615AA.40203@myphones.com> Hi, output from running bjam on exactly the sample code below centos5 32bit patched up to date gcc 4.1.2. 20070626 (Red Hat 4.1.2-14) Thanks Stuart warning: Graph library does not contain optional GraphML reader. note: to enable GraphML support, set EXPAT_INCLUDE and EXPAT_LIBPATH to the note: directories containing the Expat headers and libraries, respectively. warning: skipping optional Message Passing Interface (MPI) library. note: to enable MPI support, add "using mpi ;" to user-config.jam. note: to suppress this message, pass "--without-mpi" to bjam. note: otherwise, you can safely ignore this message. Building Boost.Regex with the optional Unicode/ICU support disabled. Please refer to the Boost.Regex documentation for more information (don't panic: this is a strictly optional feature). warning: No toolsets are configured. warning: Configuring default toolset "gcc". warning: If the default is wrong, your build may not work correctly. warning: Use the "--toolset=xxxxx" option to override our guess. warning: For more configuration options, please consult warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html ...patience... ...patience... ...found 1559 targets... ...updating 2 targets... gcc.compile.c++ bin/gcc-4.1.2/debug/threading-multi/client.o /usr/local/boost_1_35_0/boost/type_traits/detail/cv_traits_impl.hpp: In instantiation of 'const bool boost::detail::cv_traits_imp<::Test*>::is_const': /usr/local/boost_1_35_0/boost/type_traits/is_const.hpp:53: instantiated from 'boost::is_const<::Test>' /usr/local/boost_1_35_0/boost/python/detail/cv_category.hpp:31: instantiated from 'boost::python::detail::cv_category<::Test>' /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:58: instantiated from 'typename Generator::result_type boost::python::detail::unwind_ptr_type(U*, Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::Test]' /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:127: instantiated from 'static typename Generator::result_type boost::python::detail::unwind_helper2<2>::execute(U& (*)(), Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::Test]' /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:165: instantiated from 'typename Generator::result_type boost::python::detail::unwind_type(boost::type*, Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = ::Test&]' /usr/local/boost_1_35_0/boost/python/converter/pytype_function.hpp:45: instantiated from 'boost::python::type_info boost::python::converter::detail::unwind_type_id_(boost::type*, mpl_::false_*) [with T = ::Test&]' /usr/local/boost_1_35_0/boost/python/converter/pytype_function.hpp:68: instantiated from 'static const PyTypeObject* boost::python::converter::expected_pytype_for_arg::get_pytype() [with T = ::Test&]' /usr/local/boost_1_35_0/boost/python/detail/signature.hpp:98: instantiated from 'static const boost::python::detail::signature_element* boost::python::detail::signature_arity<3u>::impl::elements() [with Sig = boost::mpl::vector4::Test&, std::basic_string, std::allocator >, int>]' /usr/local/boost_1_35_0/boost/python/detail/caller.hpp:232: instantiated from 'static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<3u>::impl::signature() [with F = int (::Test::*)(std::string, int), Policies = boost::python::default_call_policies, Sig = boost::mpl::vector4::Test&, std::basic_string, std::allocator >, int>]' /usr/local/boost_1_35_0/boost/python/object/py_function.hpp:48: instantiated from 'boost::python::detail::py_func_sig_info boost::python::objects::caller_py_function_impl::signature() const [with Caller = boost::python::detail::caller::Test::*)(std::string, int), boost::python::default_call_policies, boost::mpl::vector4::Test&, std::basic_string, std::allocator >, int> >]' client.cpp:42: instantiated from here /usr/local/boost_1_35_0/boost/type_traits/detail/cv_traits_impl.hpp:37: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:4970 Please submit a full bug report, with preprocessed source if appropriate. See for instructions. Preprocessed source stored into /tmp/ccTc0vtd.out file, please attach this to your bugreport. "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -pthread -DBOOST_SYSTEM_DYN_LINK=1 -I"/usr/include/python2.4" -I"/usr/local/boost_1_35_0" -c -o "bin/gcc-4.1.2/debug/threading-multi/client.o" "client.cpp" ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/threading-multi/client.o... ...skipped rtpclient.so for lack of client.o... ...failed updating 1 target... ...skipped 1 target... > I couldn't duplicate this on with : > > ~/tmp/boost_1_34_0_RC.svn/libs/python/test$ gcc --version > gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) > Copyright (C) 2006 Free Software Foundation, Inc. > > could you post the error again, the way it is generated from your > example? > > Nikolay Mladenov > > Stuart Marsden wrote: > >> Hi, >> >> this looks like the same problem - have created a simple test case this >> works on 1.35.0 on Centos 4 (gcc 3.4.6) but gives the same error as >> previous post on Centos 5 (4.1.2) >> >> more test.cpp >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> namespace >> { >> >> class Test >> { >> public: >> Test (int aa, int bb, std::string cc) >> { >> } >> ~Test () >> { >> } >> int start (std::string ddd, int ee) >> { >> return 1; >> } >> int getport () >> { >> return 1; >> } >> private: >> }; >> } >> >> BOOST_PYTHON_MODULE (test) >> { >> using namespace boost::python; >> class_ < Test > ("Test", init < int, int, std::string >()) >> // Add regular member functions >> .def ("getport", &Test::getport) >> .def ("start", &Test::start ) >> ; >> } >> > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > From brian.o'kennedy at vicon.com Wed Apr 16 18:10:43 2008 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Wed, 16 Apr 2008 17:10:43 +0100 Subject: [C++-sig] Debug Boost Python (PY_DEBUG) libs and auto-linking Message-ID: <6BF44CD613458D479057BDB27207F2E0026479AA@omgsvr02.omg.local> Hi, Apologies for the long email, but I figured I might as well be detailed in my explanation. My two questions are below regarding the process of building Boost Python against a PY_DEBUG debug build of Python, and the failure of auto-linking of such debug libs of Boost Python (those with 'gyd' in the name). I'm using both the Release and Debug versions of Python 2.5.1 on Windows compiled with Visual Studio 2005. The Debug version of python produces python_d.exe and python25_d.dll, while the release version uses python.exe and python25.dll. I've downloaded and built Boost 1.35.0 with the following steps: 1. Edit Jamroot as follows: (lines I add start with a "+" ) BOOST_ALL_NO_LIB=1 + _SECURE_SCL=0 # Used to encode variant in target name. See the I do this since our codebase is compiled without the secure iterators for performance reasons. This isn't relevant to my question, but I might as well mention it. Also, I add the following to build the debug python libs: # location of python local python-root = [ MATCH "^--with-python-root=(.*)" : [ modules.peek : ARGV ] ] ; PYTHON_ROOT ?= $(python-root) ; + using python : 2.5 : C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PCbuild\\python.exe + : C:\\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\Include C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PC + : C:\\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PCbuild + : off ; + using python : 2.5 : C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PCbuild\\python_d.exe + : C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\Include C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PC + : C:\\3rdparty\\Python\\Python-2.5.1-vc8sp1-Patch1\\PCbuild + : on ; # Select the libraries to install. libraries = [ libraries-to-install $(all-libraries) ] ; I could also add this to my user-config.jam file but I got annoyed by bjam not picking that up if it is in the same folder as Jamroot, it would only find it if I put it in my user home. Then I trigger the builds using bjam: bjam.exe -d +2 --toolset=msvc --build-type=complete install bjam.exe -d +2 --toolset=msvc --with-python python-debugging=on install debug bjam.exe -d +2 --toolset=msvc --with-python python-debugging=off install release This gives me the complete Boost I want with the addition of the Release and Debug versions of Boost Python. The Debug version of Boost Python I'm after is boost_python-vc80-mt-gyd-1_35.dll and the release is boost_python-vc80-mt-1_35.dll So, my first question is: Surely there must be an easier way to do what I tried to achieve above? Should building a true debug (ie, a traditional python debug lib with PY_DEBUG enabled) version of Boost Python really take this much hackery? This is where people point out to me just how little I know about bjam / boost build... Second problem is the auto linking of Boost Python. If I create an DLL application in Visual Studio 2005, set the include directories, set the library directories, set the output target as BoostPythonTest.pyd in Release, and BoostPythonTest_d.pyd in Debug, I get the following situation. BoostPythonTest.cpp #include char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(BoostPythonTest) { using namespace boost::python; def("greet", greet); } This auto-links boost_python-vc80-mt-1_35.dll in Release mode just as it should and everything works just fine. In Debug mode, this auto links boost_python-vc80-gd-1_35.dll which is the Boost Python debug lib which does not define PY_DEBUG which is not the behaviour I want. The Boost Python docs makes some reference to using BOOST_DEBUG_PYTHON to change the behavior of wrap_python.hpp but no such support seems to exist to modify the auto-linking behavior. To get my module to link to release python in release mode, and debug python via boost_python-vc80-mt-gyd-1_35.lib (with PY_DEBUG, ie python25_d.dll) in debug mode, I need to do the following: BoostPythonTest.cpp #define BOOST_PYTHON_NO_LIB #ifdef _DEBUG #define BOOST_DEBUG_PYTHON #pragma comment(lib, "boost_python-vc80-mt-gyd-1_35.lib" ) #else #pragma comment(lib, "boost_python-vc80-mt-1_35.lib" ) #endif #include char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(BoostPythonTest) { using namespace boost::python; def("greet", greet); } I've had a look through the auto-linking code in boost and no special case seems to exist for the debug Python libraries. Once again, my question is whether this really is what I need to do to get Boost Python to play nicely with PY_DEBUG debug mode Python? Thanks for any advice, or general abuse for my misunderstanding on how to configure boost build properly. Brian Ps: If you do not do this and link to boost_python-vc80-gd-1_35.lib instead you get this warning when you try to import your lib into a debug python interpreter: >>> import BoostPythonTest Fatal Python error: Interpreter not initialized (version mismatch?) ________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From nickm at sitius.com Wed Apr 16 21:26:53 2008 From: nickm at sitius.com (Nikolay Mladenov) Date: Wed, 16 Apr 2008 15:26:53 -0400 Subject: [C++-sig] Problem with boost.python 1.35.0 References: <47FF2278.5000007@myphones.com> <4803D2F1.BF330989@sitius.com> <480615AA.40203@myphones.com> Message-ID: <480652FD.D19B15BD@sitius.com> Hi Stuart, It looks like a compiler bug. Is the unnamed namespace related to it? Nikolay Mladenov Stuart Marsden wrote: > > Hi, > > output from running bjam on exactly the sample code below centos5 32bit > patched up to date > > gcc 4.1.2. 20070626 (Red Hat 4.1.2-14) > > Thanks > > Stuart > > warning: Graph library does not contain optional GraphML reader. > note: to enable GraphML support, set EXPAT_INCLUDE and EXPAT_LIBPATH to the > note: directories containing the Expat headers and libraries, respectively. > warning: skipping optional Message Passing Interface (MPI) library. > note: to enable MPI support, add "using mpi ;" to user-config.jam. > note: to suppress this message, pass "--without-mpi" to bjam. > note: otherwise, you can safely ignore this message. > Building Boost.Regex with the optional Unicode/ICU support disabled. > Please refer to the Boost.Regex documentation for more information > (don't panic: this is a strictly optional feature). > warning: No toolsets are configured. > warning: Configuring default toolset "gcc". > warning: If the default is wrong, your build may not work correctly. > warning: Use the "--toolset=xxxxx" option to override our guess. > warning: For more configuration options, please consult > warning: > http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html > ...patience... > ...patience... > ...found 1559 targets... > ...updating 2 targets... > gcc.compile.c++ bin/gcc-4.1.2/debug/threading-multi/client.o > /usr/local/boost_1_35_0/boost/type_traits/detail/cv_traits_impl.hpp: In > instantiation of 'const bool > boost::detail::cv_traits_imp<::Test*>::is_const': > /usr/local/boost_1_35_0/boost/type_traits/is_const.hpp:53: > instantiated from 'boost::is_const<::Test>' > /usr/local/boost_1_35_0/boost/python/detail/cv_category.hpp:31: > instantiated from 'boost::python::detail::cv_category<::Test>' > /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:58: > instantiated from 'typename Generator::result_type > boost::python::detail::unwind_ptr_type(U*, Generator*) [with Generator = > boost::python::converter::detail::unwind_type_id_helper, U = > ::Test]' > /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:127: > instantiated from 'static typename Generator::result_type > boost::python::detail::unwind_helper2<2>::execute(U& (*)(), Generator*) > [with Generator = > boost::python::converter::detail::unwind_type_id_helper, U = > ::Test]' > /usr/local/boost_1_35_0/boost/python/detail/unwind_type.hpp:165: > instantiated from 'typename Generator::result_type > boost::python::detail::unwind_type(boost::type*, Generator*) [with > Generator = boost::python::converter::detail::unwind_type_id_helper, U = > ::Test&]' > /usr/local/boost_1_35_0/boost/python/converter/pytype_function.hpp:45: > instantiated from 'boost::python::type_info > boost::python::converter::detail::unwind_type_id_(boost::type*, > mpl_::false_*) [with T = ::Test&]' > /usr/local/boost_1_35_0/boost/python/converter/pytype_function.hpp:68: > instantiated from 'static const PyTypeObject* > boost::python::converter::expected_pytype_for_arg::get_pytype() [with > T = ::Test&]' > /usr/local/boost_1_35_0/boost/python/detail/signature.hpp:98: > instantiated from 'static const > boost::python::detail::signature_element* > boost::python::detail::signature_arity<3u>::impl::elements() [with > Sig = boost::mpl::vector4::Test&, std::basic_string std::char_traits, std::allocator >, int>]' > /usr/local/boost_1_35_0/boost/python/detail/caller.hpp:232: > instantiated from 'static boost::python::detail::py_func_sig_info > boost::python::detail::caller_arity<3u>::impl Sig>::signature() [with F = int (::Test::*)(std::string, int), > Policies = boost::python::default_call_policies, Sig = > boost::mpl::vector4::Test&, std::basic_string std::char_traits, std::allocator >, int>]' > /usr/local/boost_1_35_0/boost/python/object/py_function.hpp:48: > instantiated from 'boost::python::detail::py_func_sig_info > boost::python::objects::caller_py_function_impl::signature() > const [with Caller = boost::python::detail::caller (::Test::*)(std::string, int), > boost::python::default_call_policies, boost::mpl::vector4 ::Test&, std::basic_string, > std::allocator >, int> >]' > client.cpp:42: instantiated from here > /usr/local/boost_1_35_0/boost/type_traits/detail/cv_traits_impl.hpp:37: > internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:4970 > Please submit a full bug report, > with preprocessed source if appropriate. > See for instructions. > Preprocessed source stored into /tmp/ccTc0vtd.out file, please attach > this to your bugreport. > > "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -pthread > -DBOOST_SYSTEM_DYN_LINK=1 -I"/usr/include/python2.4" > -I"/usr/local/boost_1_35_0" -c -o > "bin/gcc-4.1.2/debug/threading-multi/client.o" "client.cpp" > > ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/threading-multi/client.o... > ...skipped rtpclient.so for lack > of client.o... > ...failed updating 1 target... > ...skipped 1 target... > > > I couldn't duplicate this on with : > > > > ~/tmp/boost_1_34_0_RC.svn/libs/python/test$ gcc --version > > gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) > > Copyright (C) 2006 Free Software Foundation, Inc. > > > > could you post the error again, the way it is generated from your > > example? > > > > Nikolay Mladenov > > > > Stuart Marsden wrote: > > > >> Hi, > >> > >> this looks like the same problem - have created a simple test case this > >> works on 1.35.0 on Centos 4 (gcc 3.4.6) but gives the same error as > >> previous post on Centos 5 (4.1.2) > >> > >> more test.cpp > >> #include > >> #include > >> #include > >> #include > >> #include > >> #include > >> #include > >> #include > >> #include > >> > >> namespace > >> { > >> > >> class Test > >> { > >> public: > >> Test (int aa, int bb, std::string cc) > >> { > >> } > >> ~Test () > >> { > >> } > >> int start (std::string ddd, int ee) > >> { > >> return 1; > >> } > >> int getport () > >> { > >> return 1; > >> } > >> private: > >> }; > >> } > >> > >> BOOST_PYTHON_MODULE (test) > >> { > >> using namespace boost::python; > >> class_ < Test > ("Test", init < int, int, std::string >()) > >> // Add regular member functions > >> .def ("getport", &Test::getport) > >> .def ("start", &Test::start ) > >> ; > >> } > >> > > > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > From diepen at astron.nl Thu Apr 17 10:22:56 2008 From: diepen at astron.nl (Ger van Diepen) Date: Thu, 17 Apr 2008 10:22:56 +0200 Subject: [C++-sig] boost.python and numpy.int32 on 64-bit system Message-ID: <48072501020000A900004448@server7.nfra.nl> I'm a happy user of Boost.Python and use it to convert strings, dicts, numpy and numarray arrays, etc. However, I have a problem with a function that accepts an int argument. It works fine when doing something like t.getcell(name, 1) but when doing arr=numpy.array([1,2,3],dtype='int32') t.getcell (name, arr[0]) I get the following error: ArgumentError: Python argument types in Table.getcell(table, str, numpy.int32) did not match C++ signature: getcell(casa::TableProxy {lvalue}, std::string columnname, int rownr) The problem only occurs on a 64-bit system (Suse, Debian as well as Ubuntu), but not on a 32-bit system. It also works fine if the array type is int64. I suspect that Boost.Python cannot handle this case, but I wonder if anybody had seen this before and if there is a solution. Of course, I can do t.getcell(name, int(arr[0])) but I regard that as a hack. Cheers, Ger van Diepen From lists at informa.tiker.net Thu Apr 17 14:52:04 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Thu, 17 Apr 2008 08:52:04 -0400 Subject: [C++-sig] boost.python and numpy.int32 on 64-bit system In-Reply-To: <48072501020000A900004448@server7.nfra.nl> References: <48072501020000A900004448@server7.nfra.nl> Message-ID: <200804170852.05670.lists@informa.tiker.net> On Donnerstag 17 April 2008, Ger van Diepen wrote: > ArgumentError: Python argument types in > Table.getcell(table, str, numpy.int32) ^^^^^^ > did not match C++ signature: > getcell(casa::TableProxy {lvalue}, std::string columnname, int rownr) This is numpy's fault, as it returns what they term an 'array scalar'. This is because Python's "int" on a 64-bit machine is 64 bits: >>> 2**39 549755813888 >>> 2**66 73786976294838206464L (see when the "L" shows up) But numpy wants to return the exact data type you have in your array, so it gives you something that's not an int. As BP doesn't know about numpy by default (and can't assume it's there), there's no support. You would need to install custom (from-/to-python) rvalue converters for numpy's array scalars. I have something in the works that might help you--watch for an announcement in the next few days. But for now the explicit conversion hack is probably your easiest route to success. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From diepen at astron.nl Thu Apr 17 15:10:14 2008 From: diepen at astron.nl (Ger van Diepen) Date: Thu, 17 Apr 2008 15:10:14 +0200 Subject: [C++-sig] boost.python and numpy.int32 on 64-bit system Message-ID: <48076856020000A900004465@server7.nfra.nl> Hi Andreas, Thanks for your answer. I'll have vacation in the coming 2 weeks, so I'll await your news. I indeed think that numpy should have returned a normal Python type. Cheers, Ger >>> Andreas Kl?ckner 04/17/08 2:52 PM >>> On Donnerstag 17 April 2008, Ger van Diepen wrote: > ArgumentError: Python argument types in > Table.getcell(table, str, numpy.int32) ^^^^^^ > did not match C++ signature: > getcell(casa::TableProxy {lvalue}, std::string columnname, int rownr) This is numpy's fault, as it returns what they term an 'array scalar'. This is because Python's "int" on a 64-bit machine is 64 bits: >>> 2**39 549755813888 >>> 2**66 73786976294838206464L (see when the "L" shows up) But numpy wants to return the exact data type you have in your array, so it gives you something that's not an int. As BP doesn't know about numpy by default (and can't assume it's there), there's no support. You would need to install custom (from-/to-python) rvalue converters for numpy's array scalars. I have something in the works that might help you--watch for an announcement in the next few days. But for now the explicit conversion hack is probably your easiest route to success. Andreas From furkankuru at gmail.com Fri Apr 18 17:24:18 2008 From: furkankuru at gmail.com (Furkan Kuru) Date: Fri, 18 Apr 2008 18:24:18 +0300 Subject: [C++-sig] boost.python Handling python objects in c++ efficiently Message-ID: <3a4a8f930804180824h38a0a072s1313496624c0967e@mail.gmail.com> Hello, I have a message queue and message handling system that is fed from python side and consumed by c++ side. The messages are not independent so they have to be handled in order. I go over the list every frame and handle the message objects one by one. The messages inherit from a common class and all message classes are exposed to python. There are two problems. The first problem is when I add a new message I have to change my message manager code adding a few more lines to check type. (which seems ugly) The second problem is that in order to assure the order of messages I go over the python list twice and I take objects using [] operator which is slow I think. ( I do this every frame and even if most of the time message queue is empty it is annoying) Any help is appreciated. the code looks like this (not same): boost::python::list actList ; actList=boost::python::extract (actListObj); int len=boost::python::len(actList); for(int i=0;i m1 (cur); if(m1.check()) { activeHandlers.push_back(new Message1Handler(m1(), params); continue; } boost::python::extract m2 (cur); if (m2.check()) { activeHandlers.push_back(new Message2Handler(m1(), params); continue; } } // finally clear the list for(int i=0;i From lists at informa.tiker.net Mon Apr 21 01:36:41 2008 From: lists at informa.tiker.net (Andreas =?utf-8?q?Kl=C3=B6ckner?=) Date: Sun, 20 Apr 2008 19:36:41 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy Message-ID: <200804201936.49665.lists@informa.tiker.net> Hi all, I'm pleased to announce the availability of PyUblas, a software bridge between Numpy and Boost.Ublas, for use with Boost.Python. PyUblas lets you use the "native" matrix library on either side of the language "fence". This is achieved without any copying at the language boundary. The end result is a very fast and convenient environment for writing hybrid numerical codes. To do its magic, PyUblas defines new Ublas-derived matrix and vector types, called numpy_matrix and numpy_vector. These hold their internal data in Numpy arrays, and can therefore be passed to and from Python without penalty. Variables of these types can be used directly in Ublas's C++ vector and matrix expressions, without any copying or conversion, and achieve the same speed as Ublas's native types. In addition, PyUblas exposes (copying) converters for many of Ublas's own types. The package also (optionally) wraps Ublas's sparse matrix types for use in Python. An add-on module called PyUblasExt supplies additional functionality for these types, such as solvers for linear systems and eigenvalue problems. There's much more material available here: http://mathema.tician.de/software/pyublas Enjoy, Andreas PS: PyUblas also automatically converts Numpy "array scalars" from Python to C++. Ger, you listening? :) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From brickenstein at mfo.de Mon Apr 21 08:25:26 2008 From: brickenstein at mfo.de (Michael Brickenstein) Date: Mon, 21 Apr 2008 08:25:26 +0200 Subject: [C++-sig] projects using boost::python Message-ID: <57180AE1-3199-4E51-9C4C-3C0F8583D545@mfo.de> Hi! I have an additional project using BOOST::python. PolyBoRi: http://polybori.sourceforge.net/ The core of PolyBoRi is a C++ library, which provides high-level data types for Boolean polynomials and monomials, exponent vectors, as well as for the underlying polynomial rings and subsets of the powerset of the Boolean variables. As a unique approach, binary decision diagrams are used as internal storage type for polynomial structures. On top of this C++-library we provide a Python interface. This allows parsing of complex polynomial systems, as well as sophisticated and extendable strategies for Gr?bner basis computation. Boost::python has helped us to create this interface in a very clean way. Best regards, Michael Brickenstein From diepen at astron.nl Mon Apr 21 09:19:45 2008 From: diepen at astron.nl (Ger van Diepen) Date: Mon, 21 Apr 2008 09:19:45 +0200 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy Message-ID: <480C5C32020000A9000044AA@server7.nfra.nl> Hi Andreas, I'm listening and it looks very nice. Are you internally using the numpy code to acces the arrays so that it also deals with numpy array slices without copying? I'm wondering what you are doing with the axes order. Blas is Fortran, while numpy is basically C. Although numpy supports axes in Fortran order, an array gets converted to C order as soon as you do operations on it. (e.g. when doing a=b+1 where b is in Fortran order, a will be in C order). Note that numpy is double as fast for arrays in C order compared to Fortran order. I think there is a difference between a numpy array scalar and a numpy scalar. E.g. a=array(1,dtype='int32') results in an array scalar (which cannot be indexed), while a=array([1,2],dtype='int32') a[0] results in an integer scalar of type numpy.int32 It is the latter that causes us problems in passing it via Boost.Python to a function expecting a normal integer. We have no problem handling a numpy array scalar to a function expecting an array. Cheers, Ger >>> Andreas Kl?ckner 04/21/08 1:36 AM >>> Hi all, I'm pleased to announce the availability of PyUblas, a software bridge between Numpy and Boost.Ublas, for use with Boost.Python. PyUblas lets you use the "native" matrix library on either side of the language "fence". This is achieved without any copying at the language boundary. The end result is a very fast and convenient environment for writing hybrid numerical codes. To do its magic, PyUblas defines new Ublas-derived matrix and vector types, called numpy_matrix and numpy_vector. These hold their internal data in Numpy arrays, and can therefore be passed to and from Python without penalty. Variables of these types can be used directly in Ublas's C++ vector and matrix expressions, without any copying or conversion, and achieve the same speed as Ublas's native types. In addition, PyUblas exposes (copying) converters for many of Ublas's own types. The package also (optionally) wraps Ublas's sparse matrix types for use in Python. An add-on module called PyUblasExt supplies additional functionality for these types, such as solvers for linear systems and eigenvalue problems. There's much more material available here: http://mathema.tician.de/software/pyublas Enjoy, Andreas PS: PyUblas also automatically converts Numpy "array scalars" from Python to C++. Ger, you listening? :) From ndbecker2 at gmail.com Mon Apr 21 13:14:55 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 21 Apr 2008 07:14:55 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy References: <200804201936.49665.lists@informa.tiker.net> Message-ID: Andreas Kl?ckner wrote: Thanks. I pulled from git today, I get: [nbecker at nbecker1 pyublasext]$ python setup.py build Traceback (most recent call last): File "setup.py", line 130, in main() File "setup.py", line 12, in main execfile("siteconf.py", conf) File "siteconf.py", line 62, in from pytools import flatten ImportError: No module named pytools From ndbecker2 at gmail.com Mon Apr 21 13:17:32 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 21 Apr 2008 07:17:32 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy References: <200804201936.49665.lists@informa.tiker.net> Message-ID: Andreas Kl?ckner wrote: If you could add a configure option to add RPATH into the link for the .so, that would be useful (I use boost svn which is in a non-standard place). From ndbecker2 at gmail.com Mon Apr 21 14:08:39 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 21 Apr 2008 08:08:39 -0400 Subject: [C++-sig] PyUblas do_test.py fails References: <200804201936.49665.lists@informa.tiker.net> Message-ID: LD_LIBRARY_PATH=/usr/local/src/boost.hg/stage/lib python ./do_test.py Traceback (most recent call last): File "./do_test.py", line 1, in from pyublas._internal import dblmat, dblvec ImportError: cannot import name dblmat From lists at informa.tiker.net Mon Apr 21 17:04:26 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Mon, 21 Apr 2008 11:04:26 -0400 Subject: [C++-sig] PyUblas do_test.py fails In-Reply-To: References: <200804201936.49665.lists@informa.tiker.net> Message-ID: <200804211104.37405.lists@informa.tiker.net> Hi Neal, On Montag 21 April 2008, Neal Becker wrote: > LD_LIBRARY_PATH=/usr/local/src/boost.hg/stage/lib python ./do_test.py > Traceback (most recent call last): > File "./do_test.py", line 1, in > from pyublas._internal import dblmat, dblvec > ImportError: cannot import name dblmat That test script is stale and should have been deleted long ago, sorry. PyUblas's tests are currently part of PyUblasExt. I'll fix that in one of the next releases. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From diresu at web.de Wed Apr 23 04:13:28 2008 From: diresu at web.de (Dietrich Bollmann) Date: Wed, 23 Apr 2008 11:13:28 +0900 Subject: [C++-sig] Extending/Embedding FAQ: How do I tell "incomplete input" from "invalid input"? Message-ID: <1208916808.4919.3.camel@pippi.pippi> Hi, some time ago I programmed an interactive python interpreter shell using paragraph 16 of the Extending/Embedding FAQ - 16 How do I tell "incomplete input" from "invalid input"? http://www.python.org/doc/faq/extending/#how-do-i-tell-incomplete-input-from-invalid-input For emulating the interactive behaviour of the python shell, the following problem has to be solved - in the words of the FAQ: Sometimes you want to emulate the Python interactive interpreter's behavior, where it gives you a continuation prompt when the input is incomplete (e.g. you typed the start of an "if" statement or you didn't close your parentheses or triple string quotes), but it gives you a syntax error message immediately when the input is invalid. The code relies on python error messages and the return values of PyParser_ParseString() in order to evaluate if an input is syntactically erroneous or just incomplete. But as both - error messages and the return values of PyParser_ParseString() - have changed the code does not work anymore. I wrote two postings to the python-list explaining my problems: - http://mail.python.org/pipermail/python-list/2008-April/487616.html - http://mail.python.org/pipermail/python-list/2008-April/487644.html but as I didn't get any answer I decided to post another message here. Is there anybody who has been able to write some similar code which also works for the current Python version? Thanks for your help, Dietrich By the way: Probably the FAQ should be corrected also. Does anybody know who is responsible for the "Extending/Embedding FAQ" ( http://www.python.org/doc/faq/extending/ ) ? From lists at informa.tiker.net Wed Apr 23 04:25:47 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Tue, 22 Apr 2008 22:25:47 -0400 Subject: [C++-sig] =?iso-8859-1?q?Extending/Embedding_FAQ=3A_How_do_I_tell?= =?iso-8859-1?q?_=22incomplete_input=22_from_=22invalid_input=22=3F?= In-Reply-To: <1208916808.4919.3.camel@pippi.pippi> References: <1208916808.4919.3.camel@pippi.pippi> Message-ID: <200804222225.48030.lists@informa.tiker.net> On Dienstag 22 April 2008, Dietrich Bollmann wrote: > Hi, > > some time ago I programmed an interactive python interpreter shell > using paragraph 16 of the Extending/Embedding FAQ Knee-Jerk reaction: Why don't you just use InteractiveConsole from the std library? http://docs.python.org/lib/module-code.html Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From diresu at web.de Wed Apr 23 11:30:36 2008 From: diresu at web.de (Dietrich Bollmann) Date: Wed, 23 Apr 2008 18:30:36 +0900 Subject: [C++-sig] Extending/Embedding FAQ: How do I tell "incomplete input" from "invalid input"? In-Reply-To: <200804222225.48030.lists@informa.tiker.net> References: <1208916808.4919.3.camel@pippi.pippi> <200804222225.48030.lists@informa.tiker.net> Message-ID: <1208943036.4294.18.camel@pippi.pippi> Hi Andreas, On Tue, 2008-04-22 at 22:25 -0400, Andreas Kl?ckner wrote: > On Dienstag 22 April 2008, Dietrich Bollmann wrote: > > Hi, > > > > some time ago I programmed an interactive python interpreter shell > > using paragraph 16 of the Extending/Embedding FAQ > > Knee-Jerk reaction: Why don't you just use InteractiveConsole from the std > library? > > http://docs.python.org/lib/module-code.html The reason was that the shell is split into a server part and a client part: The code is executed in the server but comes from the client which implements the shell. The other reason was, that I found the FAQ and that I preferred do do everything in c if I am already developing the client and server in c rather than wrapping python into c code. But I found another solution thanks to you answer :) The function `compile_command()': This function is useful for programs that want to emulate Python's interpreter main loop (a.k.a. the read-eval-print loop). The tricky part is to determine when the user has entered an incomplete command that can be completed by entering more text (as opposed to a complete command or a syntax error). This function almost always makes the same decision as the real interpreter main loop. (from http://docs.python.org/lib/module-code.html ) wrote a c wrapper around it and substituted it for `Py_CompileString()'. As `compile_command()' contrary to `Py_CompileString()' understands if a command is just incomplete or erroneous I got my code working again :) So you saved my day, thank you very much :) `compile_command()' uses a kind of strange strategy to decide if the code is complete or not: Approach: First, check if the source consists entirely of blank lines and comments; if so, replace it with 'pass', because the built-in parser doesn't always do the right thing for these. Compile three times: as is, with \n, and with \n\n appended. If it compiles as is, it's complete. If it compiles with one \n appended, we expect more. If it doesn't compile either way, we compare the error we get when compiling with \n or \n\n appended. If the errors are the same, the code is broken. But if the errors are different, we expect more. Not intuitive; not even guaranteed to hold in future releases; but this matches the compiler's behavior from Python 1.4 through 2.2, at least. (from the source file header) but for the moment it works and I hope that enough people depend on the code so that I do not have to fix my code for every new Python release... Still, the Python Extending/Embedding FAQ should be updated as other people might stumble over the same problem. Does anybody know who is responsible for the FAQ? Thanks for putting me into a good mood again :) Dietrich > Andreas From jkur at informatik.uni-bremen.de Wed Apr 23 12:28:42 2008 From: jkur at informatik.uni-bremen.de (Joerg Kurlbaum) Date: Wed, 23 Apr 2008 12:28:42 +0200 Subject: [C++-sig] how to return arbitrary (python-)objects from boost? Message-ID: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> Hello list, i'm using boost-python to wrap a C++ class that implements a camera with libdc1394. At some point i want to get the image from the camera, which is a uchar array into some python object. For further processing i converted the image to a numpy array. But for displaying the image the QImage class from pyqt4 is a better choice. To convert the numpy array to a QImage class i used toQimage() from pyqwt5. But importing pyqwt5 for only just function seems overkill to me and the image data follows a path from C++ --> Python --> C++ --> Python Now i want my boost wrapper to return a QImage directly that is usable with pyqt4. But i have no idea how i can return arbitrary objects with boost. For the numpy array i used the num_utils and can then do something like this: return boost::python::extract(obj); I tried to look at the code from pyqwt5 but at some point they use SIP magic. I'm kind of lost. Is this even possible with boost::python? Best regards, J?rg :-) -- J?rg Kurlbaum (jkur at informatik.uni-bremen.de) Cartesium 00.056 GPG-ID: CAC40EA9 Enrique Schmidt Str. 5 T: 0421/218-64201 Universit?t Bremen From seefeld at sympatico.ca Wed Apr 23 14:26:29 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 23 Apr 2008 08:26:29 -0400 Subject: [C++-sig] how to return arbitrary (python-)objects from boost? In-Reply-To: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> References: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> Message-ID: <480F2AF5.3060800@sympatico.ca> Joerg, I'm not sure I completely understand what you are trying to do, or whether that's actually needed... Joerg Kurlbaum wrote: > Now i want my boost wrapper to return a QImage directly that is usable > with pyqt4. But i have no idea how i can return arbitrary objects with > boost. For the numpy array i used the num_utils and can then do > something like this: > > return boost::python::extract(obj); If you mean by 'arbitrary objects' python objects, you can certainly pass those. In C++ they are spelled boost::python::object, and you can pass them as function arguments or return values as any other type. Conversion from C++ types to boost::python::object is implicit as long as there are registered converters. For a more specific answer it might be best if you show some code... Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From hgroven at emgs.com Wed Apr 23 16:50:11 2008 From: hgroven at emgs.com (=?ISO-8859-1?Q?H=E5kon_Groven?=) Date: Wed, 23 Apr 2008 16:50:11 +0200 Subject: [C++-sig] boost::posix_time::ptime conversion Message-ID: <480F4CA3.9030703@emgs.com> Hi! I'm converting boost::posix_time::ptime to python like this: namespace { struct ptime_to_python { static PyObject* convert(boost::posix_time::ptime const& pt) { boost::gregorian::date date = pt.date(); boost::posix_time::time_duration td = pt.time_of_day(); object result = datetime_datetime( (int)date.year() , (int)date.month() , (int)date.day() , td.hours() , td.minutes() , td.seconds() ); return incref(result.ptr()); } }; } BOOST_PYTHON_MODULE(Pyelio) { to_python_converter(); . . . . . . . } This works fine, but I cannot find out how to convert from python (datetime.datetime) into boost::posix_time::ptime in the opposite direction. I'd be glad if anybody could help me out! Best wishes, Haakon From jkur at informatik.uni-bremen.de Wed Apr 23 16:52:21 2008 From: jkur at informatik.uni-bremen.de (Joerg Kurlbaum) Date: Wed, 23 Apr 2008 16:52:21 +0200 Subject: [C++-sig] how to return arbitrary (python-)objects from boost? In-Reply-To: <480F2AF5.3060800@sympatico.ca> References: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> <480F2AF5.3060800@sympatico.ca> Message-ID: <20080423145221.GM5020@horkheimer.informatik.uni-bremen.de> On Wed, Apr 23, 2008 at 08:26:29AM -0400, Stefan Seefeld wrote: > Joerg, > > I'm not sure I completely understand what you are trying to do, or > whether that's actually needed... Hm, i supected that. > If you mean by 'arbitrary objects' python objects, you can certainly > pass those. In C++ they are spelled boost::python::object, and you can > pass them as function arguments or return values as any other type. > Conversion from C++ types to boost::python::object is implicit as long > as there are registered converters. Okay. I've read about converters. But the noddy example isn't very helpful. The problem is, i think, that all the types i want to use are already there. I have the QImage in C++ and in Python. I want to create a QImage in the wrapper code from the image data and return that to the python program. > For a more specific answer it might be best if you show some code... You are right. In the boost wrapper i derive from the class that does all the camera-specific handling in C/C++. I'm adding another function to convert from the uchar array with the image data to a numpy array (get_image_as_array). This code works. The actual handling of the RGB values is not important and can be ignored. Now i want to have a function that does not return a numpy array but a QImage, which is available in C++ and with pyqt4 in python as well. The function get_image_as_qimage() would be my naive approach to do that, but this code doesn't even compile, because the cast from python::object to QImage does not work and several other problems. And that makes sense if there isn't some information for boost::python what a QImage actually is. But maybe you can get an idea of what i wanted to do. Do i have to write a complete type description (like in the noddy example) for QImage? I would think that this description is already existent, because PyQt4 uses the QImage derived from the C++ library. #include #include #include #include "camera.h" class Camera_wrap : public Camera { public: // THIS CODE WORKS virtual numeric::array get_image_asarray() { int* size = reinterpret_cast(&rgbframe->size[0]); boost::python::object obj(boost::python::handle<>(PyArray_FromDims(2, size, NPY_UINT32))); void *arr_data = PyArray_DATA((PyArrayObject*) obj.ptr()); uint32_t* dest = static_cast(arr_data); unsigned char* src = rgbframe->image; unsigned char R,G,B,A; for ( uint32_t y = 0; y < rgbframe->size[1]; ++y) { for ( uint32_t x = 0; x < rgbframe->size[0]; ++x) { R = *src++; G = *src++; B = *src++; A = 255; unsigned char* pixel = reinterpret_cast( &(dest[x*size[1]+y]) ); *pixel++ = B; *pixel++ = G; *pixel++ = R; *pixel = A; } } return boost::python::extract(obj); } // THIS IS ONLY HOW I THINK I COULD LOOK LIKE virtual QImage get_image_qimage() { unsigned int nx = rgbframe->size[0]; unsigned int ny = rgbframe->size[1]; boost::python::object obj(boost::python::handle<>( new QImage(nx, ny, QImage::Format_ARGB32))); for (int j = 0; j < ny; ++j) { uint8_t* line = static_cast( reinterpret_cast(obj.ptr())->scanLine(j) ); uint8_t* data = rgbframe->image + j*nx*3; for (int i=0; i("Camera", init()) .def("capture", &Camera_wrap::capture) .def("capture_end", &Camera_wrap::capture_end) .def("get_image_asarray", &Camera_wrap::get_image_asarray ) .def("get_image_qimage", &Camera_wrap::get_image_qimage ) .def("image_size", &Camera_wrap::get_size_wrap ) ; // ... } Another approach i tried, is to create the QImage in python and pass it as an argument to a function in the wrapper, store the image data in the scanLines and return it (or as in the code modify a reference) void get_image_as_qimage2(boost::python::object obj) { QImage& img = extract(obj); // do some image stuff // ... } And in python: from camera1394 import * from PyQt4 import Qt, QtGui def main(): conf = Camera_Configuration() c = Camera(conf) c.capture() qimage = QtGui.QImage(640, 480, Qt.QImage.Format_ARGB32) c.get_image_as_qimage(qimage) c.capture_end() But here i get a type error: TypeError: No registered converter was able to extract a C++ reference to type QImage from this Python object of type QImage Okay. Now i would be in the situation to write a converter. There is an example in the FAQ with some custom_string class but as far i can see all this conversion does is breaking a custom string down to a char* which is then implicitly converted to a python string. This seems very different to what i'm trying. I hope i could make it a bit more clear what my problem is. Somehow i think this is more or less a standard/newbie problem when using boost::python but i haven't found suitable documentation. Greetings, J?rg :-) -- J?rg Kurlbaum (jkur at informatik.uni-bremen.de) Cartesium 00.056 GPG-ID: CAC40EA9 Enrique Schmidt Str. 5 T: 0421/218-64201 Universit?t Bremen From lists at informa.tiker.net Wed Apr 23 17:04:10 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Wed, 23 Apr 2008 11:04:10 -0400 Subject: [C++-sig] how to return arbitrary (python-)objects from boost? In-Reply-To: <20080423145221.GM5020@horkheimer.informatik.uni-bremen.de> References: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> <480F2AF5.3060800@sympatico.ca> <20080423145221.GM5020@horkheimer.informatik.uni-bremen.de> Message-ID: <200804231104.11252.lists@informa.tiker.net> On Mittwoch 23 April 2008, Joerg Kurlbaum wrote: > Okay. I've read about converters. But the noddy example isn't very > helpful. The problem is, i think, that all the types i want to use are > already there. I have the QImage in C++ and in Python. I want to create > a QImage in the wrapper code from the image data and return that to the > python program. Simple issue: PyQt uses sip to wrap Qt into Python. Boost.Python and sip are not on speaking terms. If what you're wrapping involves lots of Qt stuff, sip might be a better choice for a wrapper generator. This, of course, has the obvious "missing feature" implication: Why doesn't BP talk to sip? Any sip experts around to comment on what it would take? Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From lists at informa.tiker.net Thu Apr 24 03:35:32 2008 From: lists at informa.tiker.net (Andreas =?utf-8?q?Kl=C3=B6ckner?=) Date: Wed, 23 Apr 2008 21:35:32 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: References: <200804201936.49665.lists@informa.tiker.net> Message-ID: <200804232135.35102.lists@informa.tiker.net> On Montag 21 April 2008, Neal Becker wrote: > Andreas Kl?ckner wrote: > > Thanks. I pulled from git today, I get: > > [nbecker at nbecker1 pyublasext]$ python setup.py build > Traceback (most recent call last): > File "setup.py", line 130, in > main() > File "setup.py", line 12, in main > execfile("siteconf.py", conf) > File "siteconf.py", line 62, in > from pytools import flatten > ImportError: No module named pytools Argh. Sorry. Fixed in 0.91.2. --Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From lists at informa.tiker.net Thu Apr 24 03:35:40 2008 From: lists at informa.tiker.net (Andreas =?utf-8?q?Kl=C3=B6ckner?=) Date: Wed, 23 Apr 2008 21:35:40 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: References: <200804201936.49665.lists@informa.tiker.net> Message-ID: <200804232135.42009.lists@informa.tiker.net> On Montag 21 April 2008, Neal Becker wrote: > Andreas Kl?ckner wrote: > > If you could add a configure option to add RPATH into the link for the .so, > that would be useful (I use boost svn which is in a non-standard place). Config option --ldflags, new in 0.92.1. --Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From lists at informa.tiker.net Thu Apr 24 03:35:22 2008 From: lists at informa.tiker.net (Andreas =?utf-8?q?Kl=C3=B6ckner?=) Date: Wed, 23 Apr 2008 21:35:22 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <480C5C32020000A9000044AA@server7.nfra.nl> References: <480C5C32020000A9000044AA@server7.nfra.nl> Message-ID: <200804232135.23335.lists@informa.tiker.net> Hi Ger, first off, sorry for the long delay. On Montag 21 April 2008, you wrote: > Are you internally using the numpy code to acces the arrays so that it > also deals with numpy array slices without copying? Yes. There's one caveat, concerning non-contiguous slices. For performance reasons, I do not want to enforce the use of a strided storage iterator by default. You have to invoke numpy_vector::as_strided() (new in 0.92.1) to obtain an Ublas vector respecting the smallest stride of the numpy array. See the new test suite (test/test.py) for examples. numpy_matrix does not support non-contiguous slices. (Contiguous slices are fine.) > I'm wondering what you are doing with the axes order. Blas is Fortran, > while numpy is basically C. Although numpy supports axes in Fortran > order, an array gets converted to C order as soon as you do operations > on it. (e.g. when doing a=b+1 where b is in Fortran order, a will be in > C order). Note that numpy is double as fast for arrays in C order > compared to Fortran order. PyUblas leaves array order completely up to you. numpy_vector gives you access to the flattened data, regardless of its ordering. What you do with the numpy array's strides is completely up to you. You can obtain this information by the vector member functions ndim(), dims(), and strides(). (new in 0.92.1) numpy_matrix will enforce that the Python array matches its own order. > I think there is a difference between a numpy array scalar and a numpy > scalar. > E.g. > a = array(1,dtype='int32') > results in an array scalar (which cannot be indexed), while > b = array([1,2],dtype='int32') > c = b[0] > results in an integer scalar of type numpy.int32 > > It is the latter that causes us problems in passing it via Boost.Python > to a function expecting a normal integer. We have no problem handling a > numpy array scalar to a function expecting an array. To get the terminology straight: At least according to the numpy book, the variable 'c' above is an array scalar (cf. Section 17.5), where as 'a' is called a 'zero-dimensional array'. PyUblas converts array scalars for you, and hence should solve your problem. Oddly, as I've found out, the extra conversion is only needed on 64-bit platforms, for whatever reasons. In any case, it's there, and it doesn't seem to hurt on 32-bit. Zero-dim arrays are supported, too, if you pass them in as vectors. (as of 0.92.1) Also, there is now much more documentation than before, available at http://tiker.net/doc/pyublas/index.html. It should cover a superset of what I've said in this email. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From rwgk at yahoo.com Thu Apr 24 09:32:04 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 24 Apr 2008 00:32:04 -0700 (PDT) Subject: [C++-sig] how to return arbitrary (python-)objects from boost? Message-ID: <370112.39291.qm@web31104.mail.mud.yahoo.com> > This, of course, has the obvious "missing feature" implication: Why doesn't BP > talk to sip? Any sip experts around to comment on what it would take? A while ago I worked out a proof-of-principle for SWIG-Boost.Python conversions. The files are here: http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/ swig_arg.hpp swig_args_ext.cpp tst_swig_args.py Also look for "swig" in the SConscript. I'm guessing something similar could work for SIP, too, but I've never installed or used SIP. Ralf From rwgk at yahoo.com Thu Apr 24 09:35:43 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 24 Apr 2008 00:35:43 -0700 (PDT) Subject: [C++-sig] boost::posix_time::ptime conversion Message-ID: <147641.30005.qm@web31107.mail.mud.yahoo.com> You need a custom r-value converter. This is the essence: http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#custom_string Don't try this without valgrind! :-) ----- Original Message ---- From: H?kon Groven To: Development of Python/C++ integration ; hgroven at emgs.com Sent: Wednesday, April 23, 2008 7:50:11 AM Subject: [C++-sig] boost::posix_time::ptime conversion Hi! I'm converting boost::posix_time::ptime to python like this: namespace { struct ptime_to_python { static PyObject* convert(boost::posix_time::ptime const& pt) { boost::gregorian::date date = pt.date(); boost::posix_time::time_duration td = pt.time_of_day(); object result = datetime_datetime( (int)date.year() , (int)date.month() , (int)date.day() , td.hours() , td.minutes() , td.seconds() ); return incref(result.ptr()); } }; } BOOST_PYTHON_MODULE(Pyelio) { to_python_converter(); . . . . . . . } This works fine, but I cannot find out how to convert from python (datetime.datetime) into boost::posix_time::ptime in the opposite direction. I'd be glad if anybody could help me out! Best wishes, Haakon _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From jkur at informatik.uni-bremen.de Thu Apr 24 11:10:10 2008 From: jkur at informatik.uni-bremen.de (Joerg Kurlbaum) Date: Thu, 24 Apr 2008 11:10:10 +0200 Subject: [C++-sig] how to return arbitrary (python-)objects from boost (solved, kind of...)? In-Reply-To: <200804231104.11252.lists@informa.tiker.net> References: <20080423102842.GL5020@horkheimer.informatik.uni-bremen.de> <480F2AF5.3060800@sympatico.ca> <20080423145221.GM5020@horkheimer.informatik.uni-bremen.de> <200804231104.11252.lists@informa.tiker.net> Message-ID: <20080424091010.GO5020@horkheimer.informatik.uni-bremen.de> On Wed, Apr 23, 2008 at 11:04:10AM -0400, Andreas Kl?ckner wrote: > On Mittwoch 23 April 2008, Joerg Kurlbaum wrote: > > Okay. I've read about converters. But the noddy example isn't very > > helpful. The problem is, i think, that all the types i want to use are > > already there. I have the QImage in C++ and in Python. I want to create > > a QImage in the wrapper code from the image data and return that to the > > python program. > > Simple issue: PyQt uses sip to wrap Qt into Python. Boost.Python and sip are > not on speaking terms. If what you're wrapping involves lots of Qt stuff, sip > might be a better choice for a wrapper generator. Right now there is only QImage involved. I choose Boost::python for it's clearness and because it is independent of any other tools, that i would have to include in my toolchain/build system. Writing a python wrapper in pure C++ is awesome, as long as you don't have to trace errors in all that template stuff. But i found a solution for my special problem: In PyQt4 you can get a sip.voidptr to the scanLines of the QImage (which is acutally a byte buffer). You can convert this sip.voidptr to an integer with the Python int() function. Then i wrote a function that takes this pointer address and fills the buffer. I have to create the QImage in Python but that okay for me so far. Then in Python i write: cam = Camera() # my wrapped camera class image = QtGui.QImage(640, 480, Qt.QImage.Format_ARGB32) # ... cam.put_image_to_sippointer(int(image.scanLine(0))) In the boost::python wrapper: void put_image_to_sippointer(boost::python::object obj) { uint32_t address = extract(obj); uint8_t* line = reinterpret_cast(address); uint8_t* data = rgbframe->image; unsigned char R,G,B,A; while ( data < (rgbframe->image + (rgbframe->size[0]*rgbframe->size[1]*3)) ) { R = *data++; G = *data++; B = *data++; A = 255; *line++ = B; *line++ = G; *line++ = R; *line++ = A; } } This is a bit of a hack and i think the idea from Ralf would be much cleaner, but for now i have a solution that is fast enough and easy to implement. Thanks for all your answers. Regards, J?rg :-) -- J?rg Kurlbaum (jkur at informatik.uni-bremen.de) Cartesium 00.056 GPG-ID: CAC40EA9 Enrique Schmidt Str. 5 T: 0421/218-64201 Universit?t Bremen -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: From meherzadaga at yahoo.com Fri Apr 25 04:53:56 2008 From: meherzadaga at yahoo.com (Meherzad) Date: Thu, 24 Apr 2008 19:53:56 -0700 (PDT) Subject: [C++-sig] Debug C++ dlls from python Message-ID: <161391.52934.qm@web50206.mail.re2.yahoo.com> Hi, ????? ??? ??? I am new to python and am using easy eclipse for python.? I want to know is there any way of debuging C++ dlls which are called by python asuming the dlls are compiled in debug mode and i have the source code of the dlls.? i want to be able to single step?in the dll code while debuging and also be able to set breakpoints.? ? suppose that the dll i want to use is my_dll.dll and the function i want to call is myFunc in python i do myDll = ctypes.cdll.my_dll now i can?call the functions of myDll by using myDll.myFunc( ) i want to be able to debug and single step through the myFunc code when the python calls this function. Thankyou. Regards, Meherzad ? ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Fri Apr 25 08:21:42 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 25 Apr 2008 02:21:42 -0400 Subject: [C++-sig] Debug C++ dlls from python In-Reply-To: <161391.52934.qm@web50206.mail.re2.yahoo.com> References: <161391.52934.qm@web50206.mail.re2.yahoo.com> Message-ID: <48117876.6000209@sympatico.ca> Meherzad wrote: > Hi, > > I am new to python and am using easy eclipse for python. I want > to know is there any way of debuging C++ dlls which are called by python > asuming the dlls are compiled in debug mode and i have the source code > of the dlls. i want to be able to single step in the dll code while > debuging and also be able to set breakpoints. That's definitely possible. With gdb, you just set 'target exec python', then invoke the python script that runs your extension module. I have no idea how to do it with other debuggers. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From Nicolas.Rougier at loria.fr Fri Apr 25 16:06:46 2008 From: Nicolas.Rougier at loria.fr (Nicolas Rougier) Date: Fri, 25 Apr 2008 16:06:46 +0200 Subject: [C++-sig] Building python modules with Makefile, CMake or SCons Message-ID: <1209132406.831.15.camel@sulfur.loria.fr> Hello, I've been experiencing different solutions to build "cross modules" (where a class B in a module is a subclass of A in another module) using different tools (namely Makefiles, CMake and SCons) and I thought it might interest people to have some simple examples. The idea is to have a class A in module A and a class B, subclass of A, in a module B. To make it work, I build first two libraries libmodule_A and libmodule_B then I build python _module_A and _module_B and link them against the libraries. Prefix has been set to /home/local and you should have: /home/local/lib in your LD_LIBRARY_PATH /home/local/lib/python2.5/site-packages in your PYTHON_PATH Makefile version : ------------------ make make install >>> from boost.makefile.module_B import * >>> b = B() ?CMake version : --------------- mkdir build cd build cmake .. make make install >>> from boost.cmake.module_B import * >>> b = B() ?SCons version : --------------- scons install >>> from boost.scons.module_B import * >>> b = B() I'm not familiar enough with bjam to propose a version for it, if someone knows how to do it... Nicolas -------------- next part -------------- A non-text attachment was scrubbed... Name: boost-cmake.tgz Type: application/x-compressed-tar Size: 1334 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: boost-scons.tgz Type: application/x-compressed-tar Size: 1061 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: boost-makefile.tgz Type: application/x-compressed-tar Size: 1135 bytes Desc: not available URL: From RaoulGough at yahoo.co.uk Mon Apr 28 00:30:34 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 27 Apr 2008 23:30:34 +0100 Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] In-Reply-To: <826847.10185.qm@web31102.mail.mud.yahoo.com> References: <826847.10185.qm@web31102.mail.mud.yahoo.com> Message-ID: <4814FE8A.9080407@yahoo.co.uk> Ralf W. Grosse-Kunstleve wrote: > Hi Raoul, > Nice to hear from you! > Is indexing_v2 fully backward compatible with the current indexing suite? > If not, is it technically feasible to change indexing_v2 so that > it can co-exist with the current indexing suite? > After so many years, I fear too many things will break if indexing_v2 > isn't fully backward compatible. But it would be very nice if it were > generally available. > I've been looking into making my indexing suite co-exist with the original suite by Joel de Guzman. I think the easiest way is to move my headers into a different directory called boost/python/suite/indexing_v2. This would mean anybody already using the "new" suite would have to change their #include directives, e.g. #include #include --> #include #include Does anyone have a strong opinion about this? -- Cheers, Raoul. From rwgk at yahoo.com Mon Apr 28 02:43:11 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 27 Apr 2008 17:43:11 -0700 (PDT) Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] Message-ID: <37830.25337.qm@web31107.mail.mud.yahoo.com> > I've been looking into making my indexing suite co-exist with the > original suite by Joel de Guzman. I think the easiest way is to move my > headers into a different directory called > boost/python/suite/indexing_v2. I think it is a good idea. Ralf From lists at informa.tiker.net Mon Apr 28 03:09:02 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Sun, 27 Apr 2008 21:09:02 -0400 Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] In-Reply-To: <4814FE8A.9080407@yahoo.co.uk> References: <826847.10185.qm@web31102.mail.mud.yahoo.com> <4814FE8A.9080407@yahoo.co.uk> Message-ID: <200804272109.04146.lists@informa.tiker.net> On Sonntag 27 April 2008, Raoul Gough wrote: > #include > #include > > --> > > #include > #include > > Does anyone have a strong opinion about this? Sounds reasonable. What would the status of the "old" indexing suite become? Deprecated, to be removed in a future version? Kept indefinitely? Unrelatedly: I've been a user of the old indexing suite for a while now, and I'm overall happy with what it does. Can you summarize in a few words why I might want to look into the new one? Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From roman.yakovenko at gmail.com Mon Apr 28 07:45:18 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 28 Apr 2008 08:45:18 +0300 Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] In-Reply-To: <200804272109.04146.lists@informa.tiker.net> References: <826847.10185.qm@web31102.mail.mud.yahoo.com> <4814FE8A.9080407@yahoo.co.uk> <200804272109.04146.lists@informa.tiker.net> Message-ID: <7465b6170804272245p69db693bw87d958b8a4ebf37d@mail.gmail.com> 2008/4/28 Andreas Kl?ckner : > On Sonntag 27 April 2008, Raoul Gough wrote: > > #include > > #include > > > > --> > > > > #include > > #include > > > > Does anyone have a strong opinion about this? > > Sounds reasonable. What would the status of the "old" indexing suite become? > Deprecated, to be removed in a future version? Kept indefinitely? In my opinion old indexing suite could stay forever: it works, it is stable and have good documentation. > Unrelatedly: I've been a user of the old indexing suite for a while now, and > I'm overall happy with what it does. Can you summarize in a few words why I > might want to look into the new one? Here is a short list of items, I remember: 1. Support for almost all STL containers 2. Few new features, that allow you to expose even plain C arrays as Python containers 3. I didn't tried to change the old indexing suite, but I didn't have any problems to fix\add new to the V2 4. It is not that difficult to use V2 functionality as a building blocks and expose your own container. 5. You have pretty good control over exposed functionality. For example, if you class doesn't have operator==, you will not define "in" operator in the container class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From blkohn at hotmail.com Sat Apr 26 16:13:25 2008 From: blkohn at hotmail.com (Brandon Kohn) Date: Sat, 26 Apr 2008 09:13:25 -0500 Subject: [C++-sig] Calling reload() or PyImport_ReloadModule on modules implementing Boost.Python extensions Message-ID: Hello ladies and gents, I've been struggling for a day trying to get a system I've built using Boost.Python to be able to reload modules which hold python classes which derive from a C++ class via Boost.Python. I've tried both the PyImport_ReloadModule command and attempting to affect a reload internally from python via reload(). Niether has resulted in success. My question to the community is if anyone knows if this is even possible from a C++ extension with the current Boost.Python library? The code in question doesn't involve a recompile of any C++ dlls.. I only want to be able to make small changes to python scripts and then be able to reload them and reinstantiate associated instances of their classes without restarting my application. Is the answer to abandon Boost.Python and just go for a raw implementation via the C API? Cheers, Brandon From pertti.kellomaki at tut.fi Mon Apr 28 14:58:16 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 28 Apr 2008 15:58:16 +0300 Subject: [C++-sig] Py++ and inner template classes Message-ID: <4815C9E8.1050201@tut.fi> Can Py++ expose inner classes that come from templates? I have code which is basically equivalent to the following: class Outer { public: template class Inner { public: Inner(T); }; typedef Inner Inner_int; Inner_int f(); }; If I use the Py++ module_builder to create bindings for the code, the class Inner_int is not exposed, and I get the warning WARNING: Outer::Inner [class declaration] > execution error W1040: The declaration is unexposed, but there are other declarations, which refer to it. This > could cause "no to_python converter found" run time error. Declarations: Outer::Inner Outer::f() [member > function] -- Pertti From roman.yakovenko at gmail.com Mon Apr 28 17:26:01 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 28 Apr 2008 18:26:01 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <4815C9E8.1050201@tut.fi> References: <4815C9E8.1050201@tut.fi> Message-ID: <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> On Mon, Apr 28, 2008 at 3:58 PM, Pertti Kellom?ki wrote: > Can Py++ expose inner classes that come from templates? > I have code which is basically equivalent to the following: > > class Outer { > public: > template > class Inner { > public: > Inner(T); > }; > typedef Inner Inner_int; > Inner_int f(); > }; > > If I use the Py++ module_builder to create bindings for > the code, the class Inner_int is not exposed, and I get > the warning > > WARNING: Outer::Inner [class declaration] > > execution error W1040: The declaration is unexposed, but there are other > declarations, which refer to it. This > > could cause "no to_python converter found" run time error. Declarations: > Outer::Inner Outer::f() [member > > function] I just created new test case and everything works fine: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1315 I attached the generated code. I guess you somehow excluded the class. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: inner_tmpl_class.cpp URL: From RaoulGough at yahoo.co.uk Mon Apr 28 22:00:34 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Mon, 28 Apr 2008 21:00:34 +0100 Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] In-Reply-To: <7465b6170804272245p69db693bw87d958b8a4ebf37d@mail.gmail.com> References: <826847.10185.qm@web31102.mail.mud.yahoo.com> <4814FE8A.9080407@yahoo.co.uk> <200804272109.04146.lists@informa.tiker.net> <7465b6170804272245p69db693bw87d958b8a4ebf37d@mail.gmail.com> Message-ID: <48162CE2.9020608@yahoo.co.uk> Roman Yakovenko wrote: > 2008/4/28 Andreas Kl?ckner : > >> On Sonntag 27 April 2008, Raoul Gough wrote: >> > #include >> > #include >> > >> > --> >> > >> > #include >> > #include >> > >> > Does anyone have a strong opinion about this? >> >> Sounds reasonable. What would the status of the "old" indexing suite become? >> Deprecated, to be removed in a future version? Kept indefinitely? >> > > In my opinion old indexing suite could stay forever: it works, it is > stable and have good documentation. > Yes, the idea is to provide an alternative, but not to replace the original suite. There was some talk a number of years ago (when I originally worked on the new suite) about possibly replacing the original one, or even keeping its interface but implemented it with the new suite. I never looked into that in much detail though. At the moment it's more a question of getting the new suite into the mainline so it keeps working in future releases (currently it's only available on a branch, which doesn't get tested or officially released). >> Unrelatedly: I've been a user of the old indexing suite for a while now, and >> I'm overall happy with what it does. Can you summarize in a few words why I >> might want to look into the new one? >> > > Here is a short list of items, I remember: > > 1. Support for almost all STL containers > 2. Few new features, that allow you to expose even plain C arrays as > Python containers > 3. I didn't tried to change the old indexing suite, but I didn't have > any problems to fix\add new to the V2 > 4. It is not that difficult to use V2 functionality as a building > blocks and expose your own container. > 5. You have pretty good control over exposed functionality. For > example, if you class doesn't have operator==, you will not define > "in" operator in the container class. > Sounds like a good summary to me. The main problem with it (as far as I know) is the limited documentation, which I'll be trying to improve... -- Cheers, Raoul. From pertti.kellomaki at tut.fi Tue Apr 29 09:56:52 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 29 Apr 2008 10:56:52 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> Message-ID: <4816D4C4.6040000@tut.fi> Roman Yakovenko wrote: > I just created new test case and everything works fine: > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1315 If you remove the body of function f in the test case, i.e. instead of Inner_int f() { return Inner_int(23); } just have Inner_int f(); then the exposing code is not generated. Should a file a bug in Bugzilla for this? Is there some short term workaround to force the exposing code to be generated? Thanks, -- Pertti From roman.yakovenko at gmail.com Tue Apr 29 12:19:52 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Apr 2008 13:19:52 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <4816D4C4.6040000@tut.fi> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> Message-ID: <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> On Tue, Apr 29, 2008 at 10:56 AM, Pertti Kellom?ki wrote: > Roman Yakovenko wrote: > > > I just created new test case and everything works fine: > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1315 > > > > If you remove the body of function f in the test case, i.e. > instead of > > Inner_int f() { return Inner_int(23); } > > just have > > Inner_int f(); > > then the exposing code is not generated. Should a file a bug > in Bugzilla for this? No :-) > Is there some short term workaround to force the exposing code to be generated? This should help: http://language-binding.net/pyplusplus/documentation/how_to/templates.html Basically you have to instantiate that class, sizeof operator does this. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Tue Apr 29 12:39:35 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 29 Apr 2008 13:39:35 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> Message-ID: <4816FAE7.8040504@tut.fi> Roman Yakovenko wrote: > Basically you have to instantiate that class, sizeof operator does this. Oh, I see, it is the template instantiation issue. Thanks! -- Pertti From pertti.kellomaki at tut.fi Tue Apr 29 14:35:44 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Tue, 29 Apr 2008 15:35:44 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> Message-ID: <48171620.1060508@tut.fi> Roman Yakovenko wrote: > This should help: > http://language-binding.net/pyplusplus/documentation/how_to/templates.html > > Basically you have to instantiate that class, sizeof operator does this. One more thing. Is it possible to do this non-invasively? I tried to play around, but the only way I was able to get the inner template class exposed was to put the sizeof() somewhere in the same header file as the original class. I can do it if necessary, but I would prefer not to clutter the original header file if possible. -- Pertti From roman.yakovenko at gmail.com Tue Apr 29 19:42:02 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Apr 2008 20:42:02 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <48171620.1060508@tut.fi> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> <48171620.1060508@tut.fi> Message-ID: <7465b6170804291042p26ce5f5enc454f68ce9fed981@mail.gmail.com> On Tue, Apr 29, 2008 at 3:35 PM, Pertti Kellom?ki wrote: > Roman Yakovenko wrote: > > > This should help: > > http://language-binding.net/pyplusplus/documentation/how_to/templates.html > > > > Basically you have to instantiate that class, sizeof operator does this. > > > > One more thing. Is it possible to do this non-invasively? Yes >I tried > to play around, but the only way I was able to get the inner template > class exposed was to put the sizeof() somewhere in the same header file > as the original class. I can do it if necessary, but I would prefer > not to clutter the original header file if possible. You can create another header file and instantiate the class in it. Then you can pass it to Py++. Take a look on this page: http://www.language-binding.net/pyplusplus/documentation/how_to/best_practices.html The short version: create header file, that belongs to "bindings project" and include all other files from it. Instantiate the templates within the file. Then pass this file to Py++. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Wed Apr 30 10:06:26 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Wed, 30 Apr 2008 11:06:26 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804291042p26ce5f5enc454f68ce9fed981@mail.gmail.com> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> <48171620.1060508@tut.fi> <7465b6170804291042p26ce5f5enc454f68ce9fed981@mail.gmail.com> Message-ID: <48182882.50505@tut.fi> Roman Yakovenko wrote: > You can create another header file and instantiate the class in it. > Then you can pass it to Py++. Take a look on this page: > http://www.language-binding.net/pyplusplus/documentation/how_to/best_practices.html Not directly related to the inner class issue, but maybe I am not understanding something on the page correctly. It says: "Create one header file, which will include all project header files." However, when I do this, I do not get bindings for the project headers. I've attached a sample of files to show how I attempt to do it. Or do you mean that one should create one big header file by copying the contents of the headers into one file? That certainly works. I'm just not sure which one is meant by the page. -- Pertti -------------- next part -------------- A non-text attachment was scrubbed... Name: h1.hh Type: text/x-c++hdr Size: 28 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: h2.hh Type: text/x-c++hdr Size: 28 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: big_h.hh Type: text/x-c++hdr Size: 34 bytes Desc: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: big_h.pypp URL: From roman.yakovenko at gmail.com Wed Apr 30 20:06:03 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 30 Apr 2008 21:06:03 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <48182882.50505@tut.fi> References: <4815C9E8.1050201@tut.fi> <7465b6170804280826g2ee40e34u44a468263e3fdce1@mail.gmail.com> <4816D4C4.6040000@tut.fi> <7465b6170804290319k6d21efc7m565deb8c5d46b47a@mail.gmail.com> <48171620.1060508@tut.fi> <7465b6170804291042p26ce5f5enc454f68ce9fed981@mail.gmail.com> <48182882.50505@tut.fi> Message-ID: <7465b6170804301106j51e34d5cna7615f53162cd720@mail.gmail.com> 2008/4/30 Pertti Kellom?ki : > Not directly related to the inner class issue, but maybe I am > not understanding something on the page correctly. It says: > > "Create one header file, which will include all project header files." > > However, when I do this, I do not get bindings for the project > headers. I've attached a sample of files to show how I attempt > to do it. This is a known ( to me :-) ) issue: http://language-binding.net/pyplusplus/documentation/how_to/absolute_relative_paths.html > Or do you mean that one should create one big header > file by copying the contents of the headers into one file? That > certainly works. I'm just not sure which one is meant by the page. I've got it right: single header file, that include all others. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/