From grant.tang at gmail.com Thu May 1 01:27:46 2008 From: grant.tang at gmail.com (Grant) Date: Wed, 30 Apr 2008 18:27:46 -0500 Subject: [C++-sig] undefined symbol problem help Message-ID: I need wrap a project into Python. All C++ classes are built as a shared library libGORGON.so. The boost.python wrapper file is built as libpyGORGON.so. But when I try to import libpyGORGON in Python prompt. I got error: Python 2.4.4 (#1, Oct 23 2006, 13:58:18) [GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import libpyGORGON.so Traceback (most recent call last): File "", line 1, in ? ImportError: /data2/Gorgon/lib/libGORGON.so: undefined symbol: _ZTIN8wustl_mm13Visualization8RendererE >>> I already set the LD_LIBRARY_PATH and PYTHONPATH to /data2/Gorgon/lib. I use ldd to check the libpyGORGON.so: libGORGON.so => /data2/Gorgon/lib/libGORGON.so (0x00002aaaaadf0000) libboost_python.so.2 => /usr/lib64/libboost_python.so.2 (0x00002aaaab157000) libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 (0x00002aaaab395000) libGL.so.1 => /usr/lib64/libGL.so.1 (0x00002aaaab6ca000) libGLU.so.1 => /usr/lib64/libGLU.so.1 (0x00002aaaab88d000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaabb0d000) libm.so.6 => /lib64/libm.so.6 (0x00002aaaabe0e000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaac091000) libc.so.6 => /lib64/libc.so.6 (0x00002aaaac29e000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaac5ed000) libdl.so.2 => /lib64/libdl.so.2 (0x00002aaaac807000) libutil.so.1 => /lib64/libutil.so.1 (0x00002aaaaca0b000) libXext.so.6 => /usr/lib64/libXext.so.6 (0x00002aaaacc0f000) libX11.so.6 => /usr/lib64/libX11.so.6 (0x00002aaaace20000) /lib64/ld-linux-x86-64.so.2 (0x0000555555554000) libXau.so.6 => /usr/lib64/libXau.so.6 (0x00002aaaad12c000) libXdmcp.so.6 => /usr/lib64/libXdmcp.so.6 (0x00002aaaad32e000) And also I search the symbol in libGORGON.so: $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE It actually finds the symbol. I am confused. Anybody help me out? By the way, I did not use bjam. I use cmake to create makefile for me. Thanks, Grant From grant.tang at gmail.com Thu May 1 17:40:57 2008 From: grant.tang at gmail.com (Grant) Date: Thu, 1 May 2008 10:40:57 -0500 Subject: [C++-sig] undefined symbol problem help References: Message-ID: I made a mistake, the result of $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE $ U _ZTIN8wustl_mm13Visualization8RendererE I build Render.cpp into libGORGON.so, really don't know why this symbol is undefined. "Grant" wrote in message news:fvav9j$t8r$1 at ger.gmane.org... >I need wrap a project into Python. All C++ classes are built as a shared >library libGORGON.so. The boost.python wrapper file is built as >libpyGORGON.so. But when I try to import libpyGORGON in Python prompt. I >got error: > > Python 2.4.4 (#1, Oct 23 2006, 13:58:18) [GCC 4.1.1 20061011 (Red Hat > 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for > more information. >>>> import libpyGORGON.so > Traceback (most recent call last): > File "", line 1, in ? > ImportError: /data2/Gorgon/lib/libGORGON.so: undefined symbol: > _ZTIN8wustl_mm13Visualization8RendererE >>>> > > I already set the LD_LIBRARY_PATH and PYTHONPATH to /data2/Gorgon/lib. > > I use ldd to check the libpyGORGON.so: > libGORGON.so => /data2/Gorgon/lib/libGORGON.so (0x00002aaaaadf0000) > libboost_python.so.2 => /usr/lib64/libboost_python.so.2 > (0x00002aaaab157000) > libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 > (0x00002aaaab395000) > libGL.so.1 => /usr/lib64/libGL.so.1 (0x00002aaaab6ca000) > libGLU.so.1 => /usr/lib64/libGLU.so.1 (0x00002aaaab88d000) > libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaabb0d000) > libm.so.6 => /lib64/libm.so.6 (0x00002aaaabe0e000) > libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaac091000) > libc.so.6 => /lib64/libc.so.6 (0x00002aaaac29e000) > libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaac5ed000) > libdl.so.2 => /lib64/libdl.so.2 (0x00002aaaac807000) > libutil.so.1 => /lib64/libutil.so.1 (0x00002aaaaca0b000) > libXext.so.6 => /usr/lib64/libXext.so.6 (0x00002aaaacc0f000) > libX11.so.6 => /usr/lib64/libX11.so.6 (0x00002aaaace20000) > /lib64/ld-linux-x86-64.so.2 (0x0000555555554000) > libXau.so.6 => /usr/lib64/libXau.so.6 (0x00002aaaad12c000) > libXdmcp.so.6 => /usr/lib64/libXdmcp.so.6 (0x00002aaaad32e000) > > And also I search the symbol in libGORGON.so: > $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE > > It actually finds the symbol. I am confused. Anybody help me out? > > By the way, I did not use bjam. I use cmake to create makefile for me. > > Thanks, > Grant From gjcarneiro at gmail.com Thu May 1 18:17:09 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Thu, 1 May 2008 17:17:09 +0100 Subject: [C++-sig] undefined symbol problem help In-Reply-To: References: Message-ID: 2008/5/1 Grant : > I made a mistake, the result of > $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE > $ U _ZTIN8wustl_mm13Visualization8RendererE gjc at dark-tower:~$ c++filt -t _ZTIN8wustl_mm13Visualization8RendererE typeinfo for wustl_mm::Visualization::Renderer As for the reasons for the problem, could be several, you have to google it. I found this: http://www.dbforums.com/archive/index.php/t-352689.html In which they say one of the possible reasons is the class missing the implementation of a virtual function. Hope it helps. > > I build Render.cpp into libGORGON.so, really don't know why this symbol is > undefined. > > "Grant" wrote in message > news:fvav9j$t8r$1 at ger.gmane.org... > >I need wrap a project into Python. All C++ classes are built as a shared > >library libGORGON.so. The boost.python wrapper file is built as > >libpyGORGON.so. But when I try to import libpyGORGON in Python prompt. I > >got error: > > > > Python 2.4.4 (#1, Oct 23 2006, 13:58:18) [GCC 4.1.1 20061011 (Red Hat > > 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" > for > > more information. > >>>> import libpyGORGON.so > > Traceback (most recent call last): > > File "", line 1, in ? > > ImportError: /data2/Gorgon/lib/libGORGON.so: undefined symbol: > > _ZTIN8wustl_mm13Visualization8RendererE > >>>> > > > > I already set the LD_LIBRARY_PATH and PYTHONPATH to /data2/Gorgon/lib. > > > > I use ldd to check the libpyGORGON.so: > > libGORGON.so => /data2/Gorgon/lib/libGORGON.so (0x00002aaaaadf0000) > > libboost_python.so.2 => /usr/lib64/libboost_python.so.2 > > (0x00002aaaab157000) > > libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 > > (0x00002aaaab395000) > > libGL.so.1 => /usr/lib64/libGL.so.1 (0x00002aaaab6ca000) > > libGLU.so.1 => /usr/lib64/libGLU.so.1 (0x00002aaaab88d000) > > libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaabb0d000) > > libm.so.6 => /lib64/libm.so.6 (0x00002aaaabe0e000) > > libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaac091000) > > libc.so.6 => /lib64/libc.so.6 (0x00002aaaac29e000) > > libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaac5ed000) > > libdl.so.2 => /lib64/libdl.so.2 (0x00002aaaac807000) > > libutil.so.1 => /lib64/libutil.so.1 (0x00002aaaaca0b000) > > libXext.so.6 => /usr/lib64/libXext.so.6 (0x00002aaaacc0f000) > > libX11.so.6 => /usr/lib64/libX11.so.6 (0x00002aaaace20000) > > /lib64/ld-linux-x86-64.so.2 (0x0000555555554000) > > libXau.so.6 => /usr/lib64/libXau.so.6 (0x00002aaaad12c000) > > libXdmcp.so.6 => /usr/lib64/libXdmcp.so.6 (0x00002aaaad32e000) > > > > And also I search the symbol in libGORGON.so: > > $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE > > > > It actually finds the symbol. I am confused. Anybody help me out? > > > > By the way, I did not use bjam. I use cmake to create makefile for me. > > > > Thanks, > > Grant > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant.tang at gmail.com Thu May 1 22:33:20 2008 From: grant.tang at gmail.com (Grant) Date: Thu, 1 May 2008 15:33:20 -0500 Subject: [C++-sig] undefined symbol problem help References: Message-ID: That's exactly the cause of this import error. Renderer has a viutual destructor which is not defined: virtual ~Renderer(); I change it to virtual ~Renderer() {} The problem solved. Thank you Gustavo! Grant "Gustavo Carneiro" wrote in message news:a467ca4f0805010917l60c83757v33a7b878ef68cbd5 at mail.gmail.com... 2008/5/1 Grant : I made a mistake, the result of $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE $ U _ZTIN8wustl_mm13Visualization8RendererE gjc at dark-tower:~$ c++filt -t _ZTIN8wustl_mm13Visualization8RendererE typeinfo for wustl_mm::Visualization::Renderer As for the reasons for the problem, could be several, you have to google it. I found this: http://www.dbforums.com/archive/index.php/t-352689.html In which they say one of the possible reasons is the class missing the implementation of a virtual function. Hope it helps. I build Render.cpp into libGORGON.so, really don't know why this symbol is undefined. "Grant" wrote in message news:fvav9j$t8r$1 at ger.gmane.org... >I need wrap a project into Python. All C++ classes are built as a shared >library libGORGON.so. The boost.python wrapper file is built as >libpyGORGON.so. But when I try to import libpyGORGON in Python prompt. I >got error: > > Python 2.4.4 (#1, Oct 23 2006, 13:58:18) [GCC 4.1.1 20061011 (Red Hat > 4.1.1-30)] on linux2 Type "help", "copyright", "credits" or "license" for > more information. >>>> import libpyGORGON.so > Traceback (most recent call last): > File "", line 1, in ? > ImportError: /data2/Gorgon/lib/libGORGON.so: undefined symbol: > _ZTIN8wustl_mm13Visualization8RendererE >>>> > > I already set the LD_LIBRARY_PATH and PYTHONPATH to /data2/Gorgon/lib. > > I use ldd to check the libpyGORGON.so: > libGORGON.so => /data2/Gorgon/lib/libGORGON.so (0x00002aaaaadf0000) > libboost_python.so.2 => /usr/lib64/libboost_python.so.2 > (0x00002aaaab157000) > libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 > (0x00002aaaab395000) > libGL.so.1 => /usr/lib64/libGL.so.1 (0x00002aaaab6ca000) > libGLU.so.1 => /usr/lib64/libGLU.so.1 (0x00002aaaab88d000) > libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002aaaabb0d000) > libm.so.6 => /lib64/libm.so.6 (0x00002aaaabe0e000) > libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaac091000) > libc.so.6 => /lib64/libc.so.6 (0x00002aaaac29e000) > libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaac5ed000) > libdl.so.2 => /lib64/libdl.so.2 (0x00002aaaac807000) > libutil.so.1 => /lib64/libutil.so.1 (0x00002aaaaca0b000) > libXext.so.6 => /usr/lib64/libXext.so.6 (0x00002aaaacc0f000) > libX11.so.6 => /usr/lib64/libX11.so.6 (0x00002aaaace20000) > /lib64/ld-linux-x86-64.so.2 (0x0000555555554000) > libXau.so.6 => /usr/lib64/libXau.so.6 (0x00002aaaad12c000) > libXdmcp.so.6 => /usr/lib64/libXdmcp.so.6 (0x00002aaaad32e000) > > And also I search the symbol in libGORGON.so: > $ nm libGORGON.so | grep _ZTIN8wustl_mm13Visualization8RendererE > > It actually finds the symbol. I am confused. Anybody help me out? > > By the way, I did not use bjam. I use cmake to create makefile for me. > > Thanks, > Grant _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert ------------------------------------------------------------------------------ _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From pertti.kellomaki at tut.fi Fri May 2 08:36:19 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Fri, 02 May 2008 09:36:19 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804301106j51e34d5cna7615f53162cd720@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> <48182882.50505@tut.fi> <7465b6170804301106j51e34d5cna7615f53162cd720@mail.gmail.com> Message-ID: <481AB663.1060002@tut.fi> Roman Yakovenko wrote: > This is a known ( to me :-) ) issue: > http://language-binding.net/pyplusplus/documentation/how_to/absolute_relative_paths.html [...] > I've got it right: single header file, that include all others. Ok, thanks. It might be worthwile to mention absolute paths where the single header file is discussed. I thought the issue was with the nesting level of header files. -- Pertti From stodge at gmail.com Sat May 3 02:11:44 2008 From: stodge at gmail.com (Mike Stoddart) Date: Fri, 2 May 2008 20:11:44 -0400 Subject: [C++-sig] Boost::Python - Question about object ownership and lifetime Message-ID: Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working nicely but I'm having a few issues, which I may post about later. A brief functional rundown of what I'm trying to prototype. Hopefully my explanation doesn't get too confusing! I'm embedding a python module into an application; Python will provide application logic, responding to events such as timers expiring or the user clicking widgets. I have the following classes I'm exporting to Python: Entity, DerivedEntity, EntityList (contains pointers to Entity). They all have varying types of copy/constructors, e.g. some are private, some have non-const copy constructors etc. It's inherited code that I can't mess with so I'm stuck with it. So the typical logic flow I'm looking at is: C++ Application: - Create an instance of EntityList called entity_list, populate with many instances of DerivedEntity. - Create an instance of EntityList called change_list - Invoke python function passing entity_list and change_list as parameters Python: - For each entity in entity_list: - Invoke C++ function clone_entity, pass entity as parameter C++ Application: - Create clone of entity like this --> DerivedEntity* entity_copy = new DerivedEntity(entity) - return entity_copy to Python Back in Python again: - Apply logic to entity_copy returned from clone_entity C++ function - If entity_copy updated add to change_list Back in C++ Application: - For each new_entity in change_list - Apply further logic to new_entity - Delete new_entity pointer - Clear the change_list I'm having problems in my prototype - it looks like I have a memory leak but I'm not sure where. So my question is, what should I be aware of in this logic flow with regards to object ownership and lifetime? When I receive entity_copy in Python, returned from clone_entity, what happens to this object when I insert it into change_list and subsequently delete the C++ pointer? I don't know how to prove that the Python object is being deleted and isn't hanging around due to a lifetime issue, I guess my main problem is that I'm entirely sure I understand object ownership - who owns what object when it's created in C++, passed to Python and then returned back to C++ to be deleted. So if any of this makes sense, I would greatly appreciated any suggestions or help. I'm very impressed with Boost Python so far but my own lack of understanding is holding me back I think. Thanks again Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From pertti.kellomaki at tut.fi Mon May 5 07:36:06 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 05 May 2008 08:36:06 +0300 Subject: [C++-sig] Py++ and inner template classes In-Reply-To: <7465b6170804301106j51e34d5cna7615f53162cd720@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> <48182882.50505@tut.fi> <7465b6170804301106j51e34d5cna7615f53162cd720@mail.gmail.com> Message-ID: <481E9CC6.8020708@tut.fi> Roman Yakovenko wrote: > This is a known ( to me :-) ) issue: > http://language-binding.net/pyplusplus/documentation/how_to/absolute_relative_paths.html After playing around a little bit I finally discovered what was causing my problems. It seems that Py++ does not generate bindings for files that are in a different branch of the directory tree. If I have my header files in /home/pk/project/include and I generate the bindings in /home/pk/project, everything works fine. But if I attempt to generate the bindings in /home/pk/project/bindings, nothing is exposed even if I use absolute paths. I don't know whether this is by design or if it is a bug, but it was not obvious to me that things would work like this. I want to keep the bindings separate from the rest of the project, that's why the directory structure is similar to what I outlined. Fortunately a couple of symbolic links were sufficient to make things work. -- Pertti From papafess at mail.ru Mon May 5 03:48:16 2008 From: papafess at mail.ru (fess dark) Date: Mon, 05 May 2008 05:48:16 +0400 Subject: [C++-sig] ! Message-ID: sorry :) From pertti.kellomaki at tut.fi Mon May 5 14:56:09 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 05 May 2008 15:56:09 +0300 Subject: [C++-sig] Boost.Python and std::string subclassing Message-ID: <481F03E9.9030101@tut.fi> The library I am wrapping creates a subclass TCEString of std::string. Py++ generates me bindings for the subclass, but in Python the subclass does not quite work like std::string. For example, the Python expression "%s.%s.%s" % (term.functionUnit().name(), term.port().name(), term.operation().name()) returns the string "universal_fu.OCSetting32." because term.operation().name() returns a TCEString instead of std::string. Is there some convenient way to make the subclass work like std::string? I know how to do it by defining a __str__ method in the Python class, but I am hoping that there might be a simpler way to do it using Boost.Python or Py++. -- Pertti From roman.yakovenko at gmail.com Mon May 5 20:12:34 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 5 May 2008 21:12:34 +0300 Subject: [C++-sig] Boost.Python and std::string subclassing In-Reply-To: <481F03E9.9030101@tut.fi> References: <481F03E9.9030101@tut.fi> Message-ID: <7465b6170805051112w1c9c7715rdc8db6086c7fadaf@mail.gmail.com> On Mon, May 5, 2008 at 3:56 PM, Pertti Kellom?ki wrote: > The library I am wrapping creates a subclass TCEString of std::string. > Py++ generates me bindings for the subclass, but in Python the > subclass does not quite work like std::string. For example, > the Python expression > > "%s.%s.%s" % (term.functionUnit().name(), term.port().name(), > term.operation().name()) > > returns the string > > "universal_fu.OCSetting32." > > because term.operation().name() returns a TCEString instead of std::string. > > Is there some convenient way to make the subclass work like std::string? > I know how to do it by defining a __str__ method in the Python class, > but I am hoping that there might be a simpler way to do it using > Boost.Python or Py++. I am not sure I fully understand you. Do you want to add new method "__str__" to TCEString ? If so take a look on this document: http://language-binding.net/pyplusplus/documentation/inserting_code.html If you want to "hide" from user class TCEString and to define your interface in terms of Python string than: 1. create custom converter ( http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#custom_string ) 2. In Py++ script mark TCEString classs as "already exposed", so you will not get warnings. See http://language-binding.net/pyplusplus/documentation/multi_module_development.html#already-exposed for an explanation. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From pertti.kellomaki at tut.fi Mon May 5 21:18:59 2008 From: pertti.kellomaki at tut.fi (=?ISO-8859-1?Q?Pertti_Kellom=E4ki?=) Date: Mon, 05 May 2008 22:18:59 +0300 Subject: [C++-sig] Boost.Python and std::string subclassing In-Reply-To: <7465b6170805051112w1c9c7715rdc8db6086c7fadaf@mail.gmail.com> References: <481F03E9.9030101@tut.fi> <7465b6170805051112w1c9c7715rdc8db6086c7fadaf@mail.gmail.com> Message-ID: <481F5DA3.3010106@tut.fi> Roman Yakovenko wrote: > I am not sure I fully understand you. > > Do you want to add new method "__str__" to TCEString ? If so take a > look on this document: > http://language-binding.net/pyplusplus/documentation/inserting_code.html Sorry for being obtuse. Since Boost.Python converts std::string to Python strings, I was hoping that I could easily tell either Boost.Python or Py++ to do the same thing for TCEString, by the virtue of it being a subclass of std::string. -- Pertti From roman.yakovenko at gmail.com Mon May 5 22:22:56 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 5 May 2008 23:22:56 +0300 Subject: [C++-sig] Boost.Python and std::string subclassing In-Reply-To: <481F5DA3.3010106@tut.fi> References: <481F03E9.9030101@tut.fi> <7465b6170805051112w1c9c7715rdc8db6086c7fadaf@mail.gmail.com> <481F5DA3.3010106@tut.fi> Message-ID: <7465b6170805051322g313302f3tdd8d17c4fac40b24@mail.gmail.com> On Mon, May 5, 2008 at 10:18 PM, Pertti Kellom?ki wrote: > Roman Yakovenko wrote: > > > I am not sure I fully understand you. > > > > Do you want to add new method "__str__" to TCEString ? If so take a > > look on this document: > > http://language-binding.net/pyplusplus/documentation/inserting_code.html > > > > Sorry for being obtuse. You don't have, really :-) > Since Boost.Python converts std::string > to Python strings, I was hoping that I could easily tell either > Boost.Python or Py++ to do the same thing for TCEString, by > the virtue of it being a subclass of std::string. In this case, my second receipt will work for you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From diepen at astron.nl Tue May 6 16:45:07 2008 From: diepen at astron.nl (Ger van Diepen) Date: Tue, 06 May 2008 16:45:07 +0200 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <200804232135.23335.lists@informa.tiker.net> References: <480C5C32020000A9000044AA@server7.nfra.nl> <200804232135.23335.lists@informa.tiker.net> Message-ID: <48208B0D.6086.00A9.0@astron.nl> Hi Andreas, Thanks for your answer and clarification. > 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. Indeed it is not needed for 32 bit systems. I took a look at your code where you handle the array scalar conversion. In there you use macros (or functions) PyArray_ScalarAsCtype and PyArray_TypeObjectFromType. However, I cannot find where they are defined in numpy or pyublas. Where are they defined? Regards, Ger From lists at informa.tiker.net Tue May 6 20:21:41 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Tue, 6 May 2008 14:21:41 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <48208B0D.6086.00A9.0@astron.nl> References: <480C5C32020000A9000044AA@server7.nfra.nl> <200804232135.23335.lists@informa.tiker.net> <48208B0D.6086.00A9.0@astron.nl> Message-ID: <200805061421.42290.lists@informa.tiker.net> On Dienstag 06 Mai 2008, Ger van Diepen wrote: > Hi Andreas, > > Thanks for your answer and clarification. > > > 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. > > Indeed it is not needed for 32 bit systems. > > I took a look at your code where you handle the array scalar conversion. In > there you use macros (or functions) PyArray_ScalarAsCtype and > PyArray_TypeObjectFromType. However, I cannot find where they are defined > in numpy or pyublas. Where are they defined? __multiarray_api.h. They're also documented in the numpy book, so they're not undocumented fishiness. 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 hans_meine at gmx.net Tue May 6 20:46:59 2008 From: hans_meine at gmx.net (Hans Meine) Date: Tue, 6 May 2008 20:46:59 +0200 Subject: [C++-sig] Boost::Python - Question about object ownership and lifetime In-Reply-To: References: Message-ID: <200805062046.59645.hans_meine@gmx.net> On Samstag 03 Mai 2008, Mike Stoddart wrote: > I guess my main problem is that I'm entirely sure I understand object > ownership - who owns what object when it's created in C++, passed to Python > and then returned back to C++ to be deleted. I may be far off with my answer since I skipped nearly everything above this paragraph of yours, but let me shoot in the dark: IMO it helps if you understand reference counting (I assume you do); now you must know that python always has reference counting, which you cannot turn off, and you cannot write a C++ function which deletes a Python object (you cannot delete the references that still exist in python, which include the deleting function's argument). So there are the following possibilities: Use refcounting in C++, too, and let python objects hold at least one reference to the C++ object (e.g. using shared_ptr<> as held type), use other means to make sure that the C++ object never vanishes throughout the lifetime of the Python objects (e.g. I sometimes let more complex Python object "a" hold a reference to a C++ array, and I assume that smaller Python objects "b_i" - e.g. returned from a.__getitem__ - do not live longer than a and do not need their own C++ lifetime management, but this is not the clean way), or catch the case that the C++ object has been deleted and throw exceptions whenever the corresponding Python objects are tried to be accessed (AFAICS, this way is chosen by sip/PyQt, but it is very uncommon with the BPL). -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- 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 dinara.olo2008 at gmail.com Tue May 6 23:15:11 2008 From: dinara.olo2008 at gmail.com (dinara.olo2008 at gmail.com) Date: Wed, 7 May 2008 01:15:11 +0400 Subject: [C++-sig] Hi. I shall be glad with you to communicate! Message-ID: <94248347.20080507011511@gmail.com> HI! I am very happy to you to write! I have found a paper where has written yours Email! I Can and I am mistaken. I long did not dare to write! But I have decided all to write to you! Because I think, that you the good person. And if I am mistaken in Email. Then it is destiny. Because I wish to find to myself good to the friend. As at me is not present much another. Also there is no beloved! I decide to write to you! I do not remember where we have got acquainted with you. But I remember that on a site of acquaintances! But I have written down yours email. And I consider hundred it is pleasure for me I now I can write to you! And I hope for your answer. I shall send the photo! And I hope to receive in the answer your photo! I shall a little write about myself. I live in the city of Moscow! But not in about mine in Moscow and Moscow suburbs! I work as the bookkeeper! Children At me are not present. I live with mum. And I have a native brother! My name is Dinara. To me 28 years put a birth at me on August, 29th! I wish you good day. And I hope soon to receive your letter! Dinara. -------------- next part -------------- A non-text attachment was scrubbed... Name: x_8fa3168b.jpg Type: image/jpeg Size: 49176 bytes Desc: not available URL: From klizhentas at gmail.com Wed May 7 17:28:08 2008 From: klizhentas at gmail.com (Alex Klizhentas) Date: Wed, 7 May 2008 19:28:08 +0400 Subject: [C++-sig] Spirit Python bindings Message-ID: <6310a8f80805070828s3452ae38pabae45fed820afa8@mail.gmail.com> Hi All, Are there any Python bindings for Spirit you are aware of? Thanks in advance, Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed May 7 17:41:12 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 07 May 2008 11:41:12 -0400 Subject: [C++-sig] Spirit Python bindings In-Reply-To: <6310a8f80805070828s3452ae38pabae45fed820afa8@mail.gmail.com> References: <6310a8f80805070828s3452ae38pabae45fed820afa8@mail.gmail.com> Message-ID: <4821CD98.8090802@sympatico.ca> Alex Klizhentas wrote: > Hi All, > > Are there any Python bindings for Spirit you are aware of? I assume you are talking about boost.spirit here, right ? Spirit seems to be all about (compile-time) metaprogramming. How can that possibly be 'bound' to Python, which is all about runtime ? Python has its own syntax, it's own support for operator overloading, and its own handling of ASTs, which may be useful in constructing DSLs, but I doubt that any of this relates to something as C++-frontend heavy as Spirit. Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin... From meine at informatik.uni-hamburg.de Wed May 7 18:02:07 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Wed, 7 May 2008 18:02:07 +0200 Subject: [C++-sig] Spirit Python bindings In-Reply-To: <4821CD98.8090802@sympatico.ca> References: <6310a8f80805070828s3452ae38pabae45fed820afa8@mail.gmail.com> <4821CD98.8090802@sympatico.ca> Message-ID: <200805071802.07349.meine@informatik.uni-hamburg.de> Am Mittwoch, 07. Mai 2008 17:41:12 schrieb Stefan Seefeld: > I assume you are talking about boost.spirit here, right ? > > Spirit seems to be all about (compile-time) metaprogramming. How can > that possibly be 'bound' to Python, which is all about runtime ? > > Python has its own syntax, it's own support for operator overloading, > and its own handling of ASTs, which may be useful in constructing DSLs, > but I doubt that any of this relates to something as C++-frontend heavy > as Spirit. But the OP could be interested in pyparsing, which basically is boost::spirit in Python. -- Ciao, / / /--/ / / ANS From erin.stone at 4DTechnology.com Wed May 7 22:47:07 2008 From: erin.stone at 4DTechnology.com (Erin Stone) Date: Wed, 7 May 2008 13:47:07 -0700 Subject: [C++-sig] Error when trying to embed python into C++ Message-ID: Hi - I'm a newbie to doing this and would appreciate any help / suggestions. Here's my problem, I have an existing python application and a 3rd party C++ dll that need to talk to each other. So far I have been able to follow the "Extending and Embedding Python" tutorial to create an extension to make the C++ dll available to my python app and have it (the extension) return back values (ints, strings, etc) to the python app. The 3rd party dll has one method that I need to use that requires a callback with a particular signature. My thinking is as follows: 1. create callback method in my python module 2. create a method in my C++ extension that would take as a parameter the method from step 1 and store it 3. create another method in my C++ extension that would act as the 3rd party dll callback with the particular signature 4. set the method in #3 to be the callback for the 3rd party dll 5. when the method in #3 is called back to from the 3rd party, parse the data into appropriate python objects and then call the python callback from #2 Problem is when I do this, I get a python.exe error and my application crashes - so any ideas on what I am missing?? I don't have the option of using boost because this is a legacy application and do cannot introduce another framework. Again, any help is appreciated! Thanks, Erin Here is the code: Python import wx import camera_ext #this is the C++ ext class frmMain(wx.Frame): def _init_ctrls(self, prnt): #we just initialize the controls on the form here def __init__(self, parent): self._init_ctrls(parent) def OnInstallHooker(self, event): installed = camera_ext.InstallFrameHooker(self._my_frame_hooker) # is this right? Or should it be a module method, not a method of the class? self.txtData.SetValue("installed hooker: " + str(installed)); def OnStartGrab(self, event): started = camera_ext.StartFrameGrab() self.txtData.SetValue("started grabbing: " + str(started)); def _my_frame_hooker(self): # should be called from the c++ ext print "I was called" # this never gets printed out ???? return True C++ (camera_ext) static void FrameCallBack( TProcessedDataProperty* Attributes, unsigned char *Frameptr ) { //once called, we need to package up to return it to python as an actual object PyObject *arglist; PyObject *result; printf("foo") //this does print out so I know the 3rdparty dll (BUFUSB is calling back) // All frame data is pointed by Frameptr // All frame related attributes is in Attributes. arglist = Py_BuildValue("i", Attributes->CameraID); result = PyObject_CallObject(my_python_callback,arglist); Py_DECREF(arglist); } static PyObject *install_frame_hooker(PyObject *dummy, PyObject *args){ int retVal = 0; PyObject *result = NULL; PyObject *tobj; if (!PyArg_ParseTuple(args, "O:set_callback", &tobj)) return NULL; // make sure second argument is a function if (!PyCallable_Check(tobj)) { PyErr_SetString(PyExc_TypeError, "Need a callable object!"); } Py_XINCREF(tobj); /*add a reference to the new callback instance*/ Py_XDECREF(my_python_callback); /*dispose of previous callback instance */ my_python_callback = tobj; /*save reference to new callback instance */ Py_INCREF(Py_None); result = Py_None; /*now this method must call the camera's SDK InstallFrameHooker to install the C++ FrameHooker - note that 0 is raw data, 1 is bmp data */ retVal = BUFUSB_InstallFrameHooker(0, FrameCallBack); return result; } static PyObject *start_frame_grab(PyObject *self, PyObject *args){ //starts grabbing data int retVal = 0; //start frame grab will cause camera engine to call on the frame hooker (callback) method to return camera data retVal = BUFUSB_StartFrameGrab(0x8888); return Py_BuildValue("i", retVal); } static PyMethodDef camera_ext_methods[] = { {"StartFrameGrab", start_frame_grab, METH_VARARGS, "Start grabbing frames, specify the number of frames to grab"}, {"InstallFrameHooker", install_frame_hooker, METH_VARARGS, "Set the callback function to notify caller everytime the camera engine gets a new frame"}, {NULL, NULL} }; void initcamera_ext(void) { import_array(); Py_InitModule("camera_ext", camera_ext_methods); } -------------- next part -------------- An HTML attachment was scrubbed... URL: From thrabe at burnham.org Wed May 7 22:48:13 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Wed, 7 May 2008 13:48:13 -0700 Subject: [C++-sig] Embedding Python - data exchange && no Boost Message-ID: Hi all, I am writing an embedded python application in C/C++ with the following features: 1. The user is able to execute python commands (works fine with PyRun_SimpleString) 2. I want the user to be able to load C objects from C into the current python interpreter, so that the user is able to manipulate the python copies with python tools -> no go. I first wrote a function within a module which is loaded after Py_Initialize(), returning an PyObject. I thought it might be possible to share a static variable between the module and the C application, where the module function could access the static variable, convert it to a PyObject and provide it to the interpreter. Think of this procedure in terms of python calls: import PA; //imports the module in the embedded interpreter a = PA.set() ; //access the static object, create a PyObject, return it as a The later python calls should be able to manipulate a and then return it back to C by setting the static object again like PA.get(a) ; //or similar However, it turned out that the static object in the interpreter differs from the one in the C program -> other adresses in memory, so that I can not share the memory space. Does anybody know of a solution for such a problem? Any tips? I do not use Boost because the program is supposed to process numpy's nd-arrays and, furthermore, must remain independent of additional libraries such as Boost. I'd use it otherwise... Thank you in advance for your help, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant.tang at gmail.com Wed May 7 23:55:55 2008 From: grant.tang at gmail.com (Grant) Date: Wed, 7 May 2008 16:55:55 -0500 Subject: [C++-sig] Problem with boost.python 1.35.0 References: <47FCEEC9.221918D9@sitius.com> Message-ID: Thanks. By defining this BOOST_PYTHON_NO_PY_SIGNATURES flag, my problem is solved. May I ask why? Grant "Nikolay Mladenov" wrote in message news:47FCEEC9.221918D9 at 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 thrabe at burnham.org Thu May 8 00:33:32 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Wed, 7 May 2008 15:33:32 -0700 Subject: [C++-sig] Embedded Python Terminal Output Message-ID: Hi all, I was wandering how one could catch the terminal output of an embedded python interface? Errors are beautifully displayed in the terminal of the caller program, and each python print command, but I want the output when I type only >>> 1 Regards, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From thrabe at burnham.org Thu May 8 01:22:45 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Wed, 7 May 2008 16:22:45 -0700 Subject: [C++-sig] Embedding Python - data exchange && no Boost References: Message-ID: Meanwhile, I have made up another possible approach to my problem. Is there a attribute in the PyObject structure storing the name of the PyObject in the interpreter. If we have a variable in the Python Interpreter for instance: a = 1 is there a name attribute in the PyObject representation stating (object.name == "a") == true ? Could it possible to set such a name of a custom object and load it into the highest level of the python namespace? C example code: PyObject a = PyObj_FromLong(1); a.name = "a"; PyObj_LoadToIntepreter(a); So that a is available in the embedded python terminal afterwards? Best, Thomas -----Original Message----- From: c++-sig-bounces at python.org on behalf of Thomas Hrabe Sent: Wed 5/7/2008 1:48 PM To: c++-sig at python.org Subject: [C++-sig] Embedding Python - data exchange && no Boost Hi all, I am writing an embedded python application in C/C++ with the following features: 1. The user is able to execute python commands (works fine with PyRun_SimpleString) 2. I want the user to be able to load C objects from C into the current python interpreter, so that the user is able to manipulate the python copies with python tools -> no go. I first wrote a function within a module which is loaded after Py_Initialize(), returning an PyObject. I thought it might be possible to share a static variable between the module and the C application, where the module function could access the static variable, convert it to a PyObject and provide it to the interpreter. Think of this procedure in terms of python calls: import PA; //imports the module in the embedded interpreter a = PA.set() ; //access the static object, create a PyObject, return it as a The later python calls should be able to manipulate a and then return it back to C by setting the static object again like PA.get(a) ; //or similar However, it turned out that the static object in the interpreter differs from the one in the C program -> other adresses in memory, so that I can not share the memory space. Does anybody know of a solution for such a problem? Any tips? I do not use Boost because the program is supposed to process numpy's nd-arrays and, furthermore, must remain independent of additional libraries such as Boost. I'd use it otherwise... Thank you in advance for your help, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From nat at lindenlab.com Thu May 8 04:28:27 2008 From: nat at lindenlab.com (Nat Goodspeed) Date: Wed, 07 May 2008 22:28:27 -0400 Subject: [C++-sig] Embedded Python Terminal Output In-Reply-To: References: Message-ID: <4822654B.9080304@lindenlab.com> Thomas Hrabe wrote: > I was wandering how one could catch the terminal output of an embedded > python interface? The straightforward thing would be to replace Python's sys.stdout with a Python class of your choice. From David.Walker at int.sc.mufg.jp Thu May 8 15:48:33 2008 From: David.Walker at int.sc.mufg.jp (David Walker) Date: Thu, 8 May 2008 14:48:33 +0100 Subject: [C++-sig] Problem embedding Python with Boost.Python Message-ID: <1D7DCB81D94A8445AF4638276B92BBFB0783D04B@GBLONEMB01.mfil.local> Hi, I'm trying to embed python in an add-in library (actually a DLL ). I'm starting from the example in embedding.cpp, overriding the C++ base class in Python then calling that overridden method from C++. I'm now in the situation where the code works OK in debug, but not in release. The call stack is showing the point of failure to be in the conversion of the python object to the object reference which results from the second line of this snippet - boost::python::object py_base = pyderived(); PyTestFunc2& py = boost::python::extract(py_base); Has anyone any ideas ? I have tried building a cut-down example but annoyingly that works in both release and debug mode. I'm assuming that something in my library is interfering with the boost.python calls (but I'm only explicitly calling the python stuff in my test, so the interaction presumably takes place when some static initialization is being done) - has anyone else seen this sort of thing ? Thanks, David ********************************************************** Mitsubishi UFJ Securities International plc ("MUSI") is registered in England, company number 1698498, registered office at 6 Broadgate, London EC2M 2AA, and is part of the Mitsubishi UFJ Financial Group. MUSI is authorised and regulated in the UK by The Financial Services Authority Limited (FSA). The information contained herein or attached hereto has been obtained from sources we believe to be reliable but we do not represent that it is accurate or complete and is not to be viewed as a 'personal recommendation' within the meaning of the FSA rules. The Information is not to be construed as an offer or solicitation to buy or sell any security, instrument or investment. Any reference to past performance should not be taken as an indication of future performance. MUSI or any affiliated company may have an interest, position, or effect transactions, in any investment mentioned herein. Any opinions or recommendations expressed herein are solely those of the author or analyst and are subject to change without notice. Neither MUSI nor any of its affiliates accept any liability whatsoever for any direct or consequential loss arising from any use of information or material contained herein. This message is intended solely for the individual addressee named above. The information contained in this e-mail is confidential and may be legally privileged. If you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. Messages sent via this medium may be subject to delays, non-delivery and unauthorised alteration. -------------- next part -------------- An HTML attachment was scrubbed... URL: From thrabe at burnham.org Thu May 8 19:16:16 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Thu, 8 May 2008 10:16:16 -0700 Subject: [C++-sig] Embedded Python Terminal Output References: <4822654B.9080304@lindenlab.com> Message-ID: Ok, and how would I do that? What other Python class will I choose then? -----Original Message----- From: c++-sig-bounces at python.org on behalf of Nat Goodspeed Sent: Wed 5/7/2008 7:28 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Embedded Python Terminal Output Thomas Hrabe wrote: > I was wandering how one could catch the terminal output of an embedded > python interface? The straightforward thing would be to replace Python's sys.stdout with a Python class of your choice. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From goldberg at coredp.com Thu May 8 20:44:41 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Thu, 08 May 2008 14:44:41 -0400 Subject: [C++-sig] boost python and keyword aguments Message-ID: <48234A19.90401@coredp.com> If I'm writing pure python, I can do the following: def pyfunc(**kwargs): print kwargs then call it as follows: >>> pyfunc() {} >>> pyfunc(a="b", c="d", arbitrary_key="value") {'a': 'b', 'c': 'd', arbitrary_key: 'value'} Is there a way with boost python to do the same thing? i.e. write a function in C++ something like: void cppfunc(boost::python::dict kwargs) { // ... do something ... } That can be called in python like this: >>> cppfunc(a="b", c="d", arbitrary_key="value") The important thinhg is that I be able to call it with keyword args, and not by passing a dict Thanks From stodge at gmail.com Fri May 9 01:21:41 2008 From: stodge at gmail.com (Mike Stoddart) Date: Thu, 8 May 2008 19:21:41 -0400 Subject: [C++-sig] Embedded Python Terminal Output In-Reply-To: References: <4822654B.9080304@lindenlab.com> Message-ID: This should help: http://forums.devshed.com/showpost.php?p=1963866&postcount=5 I implemented something similar and it works perfectly. On 5/8/08, Thomas Hrabe wrote: > > > Ok, and how would I do that? > What other Python class will I choose then? > > > > -----Original Message----- > From: c++-sig-bounces at python.org on > behalf of Nat Goodspeed > Sent: Wed 5/7/2008 7:28 PM > To: Development of Python/C++ integration > Subject: Re: [C++-sig] Embedded Python Terminal Output > > Thomas Hrabe wrote: > > > I was wandering how one could catch the terminal output of an embedded > > python interface? > > The straightforward thing would be to replace Python's sys.stdout with a > Python class of your choice. > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From diresu at web.de Fri May 9 04:55:33 2008 From: diresu at web.de (Dietrich Bollmann) Date: Fri, 09 May 2008 11:55:33 +0900 Subject: [C++-sig] Embedded Python Terminal Output In-Reply-To: References: <4822654B.9080304@lindenlab.com> Message-ID: <1210301733.4219.13.camel@pippi.pippi> On Thu, 2008-05-08 at 10:16 -0700, Thomas Hrabe wrote: > > Ok, and how would I do that? > What other Python class will I choose then? Not sure if this is what you want?: python Python 2.5.2 (r252:60911, Apr 27 2008, 11:46:35) [GCC 4.2.3 (Debian 4.2.3-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import sys >>> import cStringIO >>> print 'stdout' stdout >>> some error File "", line 1 some error ^ SyntaxError: invalid syntax >>> saveout = sys.stdout >>> outbuf = cStringIO.StringIO() >>> sys.stdout = outbuf >>> saveerr = sys.stderr >>> errbuf = cStringIO.StringIO() >>> sys.stderr = errbuf >>> print 'buffered stdout' >>> buffered error >>> sys.stderr = saveerr >>> errstr = errbuf.getvalue() >>> errbuf.close() >>> sys.stdout = saveout >>> outstr = outbuf.getvalue() >>> outbuf.close() >>> print outstr buffered stdout >>> print errstr File "", line 1 buffered error ^ SyntaxError: invalid syntax >>> print 'stdout' stdout >>> some error File "", line 1 some error ^ SyntaxError: invalid syntax >>> Here the same in c - implemented to be used in a python shell client for blender ( http://formgames.org/blender/command-port/ , http://www.blender.org/ ) - see the appended file stdouterr-buffer.tar.gz Dietrich $ gunzip stdouterr-buffer.tar.gz $ tar xvf stdouterr-buffer.tar stdouterr-buffer/ stdouterr-buffer/py_stdouterr_buffer.h stdouterr-buffer/py_stdouterr_buffer.c stdouterr-buffer/README stdouterr-buffer/py_stdouterr_buffer_test.c stdouterr-buffer/error_codes.h stdouterr-buffer/Makefile $ cd stdouterr-buffer $ cat README README - Dietrich Bollmann * py_stdouterr_buffer ** usage gunzip stdouterr-buffer.tar.gz tar xvf stdouterr-buffer.tar cd stdouterr-buffer PYTHON_INCLUDE=/usr/include/python2.5 PYTHON_LIB=/usr/lib/libpython2.5.so make ./py_stdouterr_buffer_test ** docs - 4.5 StringIO -- Read and write strings as files http://www.python.org/doc/current/lib/module-StringIO.html fin. $ PYTHON_INCLUDE=/usr/include/python2.5 PYTHON_LIB=/usr/lib/libpython2.5.so make gcc py_stdouterr_buffer_test.c -c -g -I/usr/include/python2.5/Include -I/usr/include/python2.5 -I. gcc py_stdouterr_buffer.c -c -g -I/usr/include/python2.5/Include -I/usr/include/python2.5 -I. gcc py_stdouterr_buffer_test.o py_stdouterr_buffer.o /usr/lib/libpython2.5.so -o py_stdouterr_buffer_test $ ./py_stdouterr_buffer_test >>> ======================================================== >>> redirect stdin / stdout to write into a string :) >>> -------------------------------------------------------- >>> ======================================================== >>> experiment 0 >>> -------------------------------------------------------- # buffered stdout: >>> <<< # buffered stderr: >>> <<< >>> ======================================================== >>> experiment 1 >>> -------------------------------------------------------- # buffered stdout: >>> <<< # buffered stderr: >>> <<< >>> ======================================================== >>> experiment 2 >>> -------------------------------------------------------- # buffered stdout: >>> <<< # buffered stderr: >>> <<< >>> ======================================================== >>> ======================================================== bye... :) $ -------------- next part -------------- A non-text attachment was scrubbed... Name: stdouterr-buffer.tar Type: application/x-tar Size: 20480 bytes Desc: not available URL: From j.reid at mail.cryst.bbk.ac.uk Fri May 9 17:50:56 2008 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 09 May 2008 16:50:56 +0100 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: Raoul Gough wrote: > 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? > Sounds good to me. Any news on when this might be in boost-trunk? Thanks for the new suite, John. From RaoulGough at yahoo.co.uk Sun May 11 12:33:11 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 11 May 2008 11:33:11 +0100 Subject: [C++-sig] Renaming indexing_v2 directory [was Re: Merging indexing_v2 to mainline] In-Reply-To: References: <826847.10185.qm@web31102.mail.mud.yahoo.com> <4814FE8A.9080407@yahoo.co.uk> Message-ID: <4826CB67.2050805@yahoo.co.uk> John Reid wrote: > Raoul Gough wrote: [snip] >> #include >> #include >> >> Does anyone have a strong opinion about this? >> > > Sounds good to me. Any news on when this might be in boost-trunk? > I haven't made much progress so far on improving the documentation, which is the main thing holding it back at the moment. Optimistically, I'd like to have something ready for review by the end of May... -- Cheers, Raoul. From paul.bilokon at lehman.com Sun May 11 23:54:19 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Sun, 11 May 2008 22:54:19 +0100 Subject: [C++-sig] Exposing C++ Functions with Container Arguments in Boost.Python Message-ID: Hi all, This is probably a trivial question, but after some research I was unable to find a "best practice" answer, so my sincere apologies. I am trying to expose a C++ function which takes an std::vector as its argument, some void A::foo(std::vector v); And perhaps void A::bar(std::vector & v); Whether it is a good practice to have such arguments is, of course, open to debate (shouldn't they be iterators?), but this is what I have to work with. The question remains, what is the best way to expose these to python? I cannot pass a Python list -- it's a type mismatch. Many thanks! Regards, Paul - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From nickm at sitius.com Tue May 13 16:13:37 2008 From: nickm at sitius.com (Nikolay Mladenov) Date: Tue, 13 May 2008 10:13:37 -0400 Subject: [C++-sig] boost python and keyword aguments In-Reply-To: <48234A19.90401@coredp.com> References: <48234A19.90401@coredp.com> Message-ID: Hi Moe, look at this: http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/raw_function.html HTH, Nikolay Mladenov Moe Goldberg wrote: > If I'm writing pure python, I can do the following: > > def pyfunc(**kwargs): > print kwargs > > then call it as follows: > >>> pyfunc() > {} > > >>> pyfunc(a="b", c="d", arbitrary_key="value") > {'a': 'b', 'c': 'd', arbitrary_key: 'value'} > > > Is there a way with boost python to do the same thing? i.e. write a > function in C++ something like: > void cppfunc(boost::python::dict kwargs) > { > // ... do something ... > } > > > That can be called in python like this: > >>> cppfunc(a="b", c="d", arbitrary_key="value") > > The important thinhg is that I be able to call it with keyword args, and > not by passing a dict > > Thanks From goldberg at coredp.com Tue May 13 17:03:01 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Tue, 13 May 2008 11:03:01 -0400 Subject: [C++-sig] boost python and keyword aguments In-Reply-To: References: <48234A19.90401@coredp.com> Message-ID: <4829ADA5.7090304@coredp.com> Thanks! That's pretty much what I am looking for. The docuemntation says, you can write a function this way tuple raw(tuple args, dict kw) { return make_tuple(args, kw); } Which is similar to raw(*args, **kwargs): return (args, kwargs) in pure python. Is there a way to write a C++ function with set args, but still use kwargs ... such as: myfunc(arg1, arg2, arg3, **kwargs): do_something() I tried to do this with raw_function, and got a compilation error. tuple myfunc(int arg1, int arg2, int arg3, dict kw) { return make_tuple(arg1, arg2, arg3, kw); } thanks again for your help. Nikolay Mladenov wrote: > Hi Moe, > > look at this: > http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/raw_function.html > > > HTH, > > Nikolay Mladenov > > Moe Goldberg wrote: > >> If I'm writing pure python, I can do the following: >> >> def pyfunc(**kwargs): >> print kwargs >> >> then call it as follows: >> >>> pyfunc() >> {} >> >> >>> pyfunc(a="b", c="d", arbitrary_key="value") >> {'a': 'b', 'c': 'd', arbitrary_key: 'value'} >> >> >> Is there a way with boost python to do the same thing? i.e. write a >> function in C++ something like: >> void cppfunc(boost::python::dict kwargs) >> { >> // ... do something ... >> } >> >> >> That can be called in python like this: >> >>> cppfunc(a="b", c="d", arbitrary_key="value") >> >> The important thinhg is that I be able to call it with keyword args, >> and not by passing a dict >> >> Thanks > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From grantj at lunainnovations.com Tue May 13 21:26:10 2008 From: grantj at lunainnovations.com (Jeff Grant) Date: Tue, 13 May 2008 15:26:10 -0400 Subject: [C++-sig] Problem compiling python extending sample Message-ID: <6AC0CCE02D1B684BBC8351F15E8F781B0C4512697E@e2k7.fsdomain> Hi, I hope this isn't a trivial problem, but I'm having problems compiling one of the sample applications that comes with Boost.Python 1.35.0. I can compile and test getting_started1.cpp in $BOOST_ROOT/libs/python/example/ (or any of the examples which do not expose a class) but getting_started2.cpp (or any other example which exposes a class) gives the error message I've included at the end of the email. I have also attached the preprocessed source if that helps. Some additional information which may be pertinent is: I've set LD_LIBRARY_PATH and PYTHONPATH to ~/usr/lib which is where the build process installed the compiled libs. The examples which export a class build correctly under Boost.Python 1.34.1. I have tried defining BOOST_PYTHON_NO_PY_SIGNATURES which does not seem to have an affect (although I'm not sure I'm doing this correctly). Additionally, Boost 1.35.0 appears to build the release version of the Boost.Python libraries by default, but the example code defaults to building debug objects by default and looks for the debug versions of the Boost.Python libs. Boost 1.34.1 appears to build both release and debug versions of the libs by default. I know this isn't related to the problem at hand, but wasn't sure if this was the intended behavior. Thanks for any help you can give, and let me know if you need anything else. Jeff [user at host example]$ bjam getting_started2 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... ...found 1128 targets... ...updating 2 targets... gcc.compile.c++ bin/gcc-4.1.2/debug/getting_started2.o ../../../boost/type_traits/detail/cv_traits_impl.hpp: In instantiation of ?const bool boost::detail::cv_traits_imp<::hello*>::is_const?: ../../../boost/type_traits/is_const.hpp:53: instantiated from ?boost::is_const<::hello>? ../../../boost/python/detail/cv_category.hpp:31: instantiated from ?boost::python::detail::cv_category<::hello>? ../../../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 = ::hello]? ../../../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 = ::hello]? ../../../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 = ::hello&]? ../../../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 = ::hello&]? ../../../boost/python/converter/pytype_function.hpp:68: instantiated from ?static const PyTypeObject* boost::python::converter::expected_pytype_for_arg::get_pytype() [with T = ::hello&]? ../../../boost/python/detail/signature.hpp:98: instantiated from ?static const boost::python::detail::signature_element* boost::python::detail::signature_arity<1u>::impl::elements() [with Sig = boost::mpl::vector2, std::allocator >, ::hello&>]? ../../../boost/python/detail/caller.hpp:232: instantiated from ?static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<1u>::impl::signature() [with F = std::string (::hello::*)()const, Policies = boost::python::default_call_policies, Sig = boost::mpl::vector2, std::allocator >, ::hello&>]? ../../../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::hello::*)()const, boost::python::default_call_policies, boost::mpl::vector2, std::allocator >, ::hello&> >]? getting_started2.cpp:41: instantiated from here ../../../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/ccIsDKof.out file, please attach this to your bugreport. "g++" -ftemplate-depth-128 -O0 -fno-inline -Wall -g -fPIC -I"../../.." -I"/usr/include/python2.4" -c -o "bin/gcc-4.1.2/debug/getting_started2.o" "getting_started2.cpp" ...failed gcc.compile.c++ bin/gcc-4.1.2/debug/getting_started2.o... ...skipped getting_started2.so for lack of getting_started2.o... ...failed updating 1 target... ...skipped 1 target... -- Jeffrey Grant Research Engineer Luna Innovations Incorporated 1 Riverside Circle Suite 400 Roanoke, VA 24016 www.lunainnovations.com grantj at lunainnovations.com 540-769-8481 (o) 540-769-8401 (f) From nickm at sitius.com Tue May 13 21:30:26 2008 From: nickm at sitius.com (Nikolay Mladenov) Date: Tue, 13 May 2008 15:30:26 -0400 Subject: [C++-sig] boost python and keyword aguments In-Reply-To: <4829ADA5.7090304@coredp.com> References: <48234A19.90401@coredp.com> <4829ADA5.7090304@coredp.com> Message-ID: Moe Goldberg wrote: > Is there a way to write a C++ function with set args, but still use > kwargs ... such as: > myfunc(arg1, arg2, arg3, **kwargs): > do_something() > I have not used raw_function much, but it seems to me that if you have: result_t myfunc( Type1 arg1, Type1 arg2, tuple posargs, dict kwargs) { do_something(); } you will have to wrap it first with: result_t raw_myfunc( tuple posargs, dict kwargs) { myfunc ( extract(fixed_args[0])() , extract(fixed_args[1])() , posargs.slice(2,_) , kwargs ); ) and then use: raw_function(raw_myfunc, 2); And may be you should check out the args : http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/args.html HTH, Nikolay Mladenov From diepen at astron.nl Wed May 14 16:10:29 2008 From: diepen at astron.nl (Ger van Diepen) Date: Wed, 14 May 2008 16:10:29 +0200 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <200805061421.42290.lists@informa.tiker.net> References: <480C5C32020000A9000044AA@server7.nfra.nl> <200804232135.23335.lists@informa.tiker.net> <48208B0D.6086.00A9.0@astron.nl> <200805061421.42290.lists@informa.tiker.net> Message-ID: <482B0EEC.6086.00A9.0@astron.nl> Hi Andreas, I was busy (and had a few days off) in the past weeks, but today I returned to the array scalar problem. I've implemented the conversion for array scalars in my code and it seems to work nicely. However, I did it a bit different as I need the possibility to convert to an AnyValue object (a kind of any object). This is needed for a function which can accept any basic scalar (and array) type (thus has AnyValue in its signature). I use boost::python::implicitly_convertible(); to be able to convert a numpy array scalar to int for functions accepting an int. Unfortunately the compiler complained about ambiguous constructors when using that for std::complex (e.g. double, complex and complex for complex). I have to see if I can work around that problem, but I'm afraid the problem is fundamental. Furthermore we have the possibility to convert a Python sequence to std::vector. I still have to add the code to accept numpy array scalars in such python sequences, so one can do in python something like: obj.func ([arr1[0], arr2[0]]) Note that using int64 numpy on a 32 bit system gives the same problem as int32 on a 64 bit system. The same problems arise for int16, float32, etc. I was wondering if your solution can convert a numpy int16 to a C++ int (on a 32 or 64 bit system) as it looks to me that only one PyTypeObject matches a C++ type. Cheers, Ger From mathieu.malaterre at gmail.com Wed May 14 16:24:45 2008 From: mathieu.malaterre at gmail.com (Mathieu Malaterre) Date: Wed, 14 May 2008 16:24:45 +0200 Subject: [C++-sig] std::exception propagated at python level Message-ID: Hi there, After searching for solutions on the web I could not find anything for my current issue. Are there any known problems when throwing and catching std::exception in a c++ library that would also be wrap in python ? I found some post about issue with gcc 2.95, but the issue is actually only happening on VS 2005, but cannot be reproduce using gcc 3.x or gcc 4.x Right now I am using CMake for the build process (and it is passing the proper exception flag to the cl compiler), and swig for wrapping the interface. Thanks for any link, -- Mathieu From michael.wieher at gmail.com Wed May 14 16:34:46 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Wed, 14 May 2008 09:34:46 -0500 Subject: [C++-sig] Include File Issue? Message-ID: Hey, I have this newbie question for all you experts. I have some .cpp file of the form: --------------------------------------------------------------------- #include "filename.h" classOne instanceOfClassOne; PyObject* filename_function(PyObject* self, PyObject* args) { function2(&instanceOfClassOne); return NULL; } PyMethod othername_methods[] = { {"xxxx",filename_function,METH_VARARGS}, {NULL,NULL}, }; ----------------------------------------------------------------- Straightforward, right? Now, in "filename.h" is a line ... #include "classOneHeader.h" which includes the defintion of the object "classOne" so I would expect it to include this file & the definition needed etc... Then I have the setup.py file, of the form: ------------------------------------------------------------------- from distutils.core import setup, Extension setup(name="othername",version="0.01",ext_modules=[Extension("othername",["nameofCPPfileabove.cpp"])]) -------------------------------------------------------------------- I run >python setup.py build_ext -i and a file, othername.so is generated so, I go to the python interpreter and get this: >>> import othername.so Traceback (most recent call last): File "", line 1, in ? ImportError: ./othername.so: undefined symbol: _Z8function2P7classOne >>> what I'm seeing is that the stuff from "classOneHeader.h" (and its paired .cpp file) are not linked correctly in the vtable... maybe I'm wrong about that guess, but cann anyone point me towards a workable solution? thanks! From lists at informa.tiker.net Wed May 14 17:14:08 2008 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Wed, 14 May 2008 11:14:08 -0400 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <482B0EEC.6086.00A9.0@astron.nl> References: <480C5C32020000A9000044AA@server7.nfra.nl> <200805061421.42290.lists@informa.tiker.net> <482B0EEC.6086.00A9.0@astron.nl> Message-ID: <200805141114.10272.lists@informa.tiker.net> Hi Ger, On Mittwoch 14 Mai 2008, Ger van Diepen wrote: > [snip] Unfortunately the compiler complained about ambiguous constructors > when using that for std::complex (e.g. double, complex and > complex for complex). I have to see if I can work around > that problem, but I'm afraid the problem is fundamental. I don't quite see what's going wrong--please post code if you need help. > Furthermore we have the possibility to convert a Python sequence to > std::vector. I still have to add the code to accept numpy array scalars in > such python sequences, so one can do in python something like: obj.func > ([arr1[0], arr2[0]]) Hmm--I don't quite understand. It sounds like you already have scalar conversion in place. Why wouldn't that automatically help with converting the vector elements? (Also, b::p::stl_input_iterator is easy to overlook, but good to know about, if you don't already) > Note that using int64 numpy on a 32 bit system gives the same problem as > int32 on a 64 bit system. The same problems arise for int16, float32, etc. > I was wondering if your solution can convert a numpy int16 to a C++ int (on > a 32 or 64 bit system) as it looks to me that only one PyTypeObject matches > a C++ type. In PyUblas, the types need to match exactly, by design. But numpy also has PyArray_CastScalarToCtype, so this is doable without declaring O(n^2) implicit conversion rules. That function might, however, be too lenient in what it accepts (floats, etc.). Depends on what you want. 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 nat at lindenlab.com Wed May 14 19:46:28 2008 From: nat at lindenlab.com (Nat Goodspeed) Date: Wed, 14 May 2008 13:46:28 -0400 Subject: [C++-sig] Include File Issue? In-Reply-To: References: Message-ID: <482B2574.2030408@lindenlab.com> Michael Wieher wrote: > I have this newbie question for all you experts. Not An Expert In This > Then I have the setup.py file, of the form: > ------------------------------------------------------------------- > from distutils.core import setup, Extension > > setup(name="othername",version="0.01",ext_modules=[Extension("othername",["nameofCPPfileabove.cpp"])]) > > -------------------------------------------------------------------- > > I run >> python setup.py build_ext -i > > and a file, othername.so is generated > > so, I go to the python interpreter > and get this: >>>> import othername.so ? Normally you'd just import othername, and let Python supply the extension. But that's not your problem here. > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ./othername.so: undefined symbol: _Z8function2P7classOne > > what I'm seeing is that the stuff from "classOneHeader.h" (and its > paired .cpp file) are not linked correctly in the vtable... This is only a wild guess -- but if you're asking setup to build your extension, maybe pass it "classOneHeader.cpp" as well as "nameofCPPFileabove.cpp"? From goldberg at coredp.com Wed May 14 22:55:25 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Wed, 14 May 2008 16:55:25 -0400 Subject: [C++-sig] lvalue converter - pass by reference (non-const) Message-ID: <482B51BD.1050000@coredp.com> Hi I was trying to pass an object by reference from python to C++ so that I could modify the object in C++. I am using the custom_string as an example for reference, and I am unable to get it to work. Instead of showing you my case, which is complicated, I will demonstrate with the custom_string example. If I change the definition of the size function from: std::size_t size(custom_string const& s) { return s.value().size(); } to std::size_t size(custom_string& s) { return s.value().size(); } (i.e. remove the const from s), and then try to run it as follows: >>> import custom_string >>> mystr="123" >>> custom_string.size(mystr) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in custom_string.size(str) did not match C++ signature: size(sandbox::(anonymous namespace)::custom_string {lvalue}) If both to_python and lvalue converters are registered, then why can't I do this? Or more importantly, how can I get this to work? Thanks! -MG From paul.bilokon at lehman.com Thu May 15 00:56:54 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Wed, 14 May 2008 23:56:54 +0100 Subject: [C++-sig] Boost.Python: Wrapping functions with std::ostream & and std::istream & arguments Message-ID: Hi, I reckon the subject expresses my question pretty well. Is it possible to wrap C++ functions that take std::ostream & and std::istream & arguments? How can I convert the corresponding Python objects? Are there any examples? Many thanks! Best wishes, Paul - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From seefeld at sympatico.ca Thu May 15 01:19:51 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 14 May 2008 19:19:51 -0400 Subject: [C++-sig] Boost.Python: Wrapping functions with std::ostream & and std::istream & arguments In-Reply-To: References: Message-ID: <482B7397.5060601@sympatico.ca> Bilokon, Paul wrote: > Hi, > > I reckon the subject expresses my question pretty well. > > Is it possible to wrap C++ functions that take std::ostream & and > std::istream & arguments? > Yes, if you provide wrappers or converters for those stream objects, too. > How can I convert the corresponding Python objects? Are there any > examples? > That depends on what kind of streams you expect there. You may wrap by types that provide the python 'file' protocol interface, for example. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From diepen at astron.nl Thu May 15 09:42:12 2008 From: diepen at astron.nl (Ger van Diepen) Date: Thu, 15 May 2008 09:42:12 +0200 Subject: [C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy In-Reply-To: <200805141114.10272.lists@informa.tiker.net> References: <480C5C32020000A9000044AA@server7.nfra.nl> <200805061421.42290.lists@informa.tiker.net> <482B0EEC.6086.00A9.0@astron.nl> <200805141114.10272.lists@informa.tiker.net> Message-ID: <482C056B.6086.00A9.0@astron.nl> Hi Andreas, I get the error shown at the end. Note that casa::ValueHolder is a typedef for AnyValue and casa::DComplex for std::complex. The problem is that AnyValue has conversion operators to double, complex, and complex, so the constructor complex(AnyValue) doesn't know which one to take. I get the same error for complex. I could resolve the problem by changing implicit.hpp to: Target tgt = get_source(); new (storage) Target(tgt); instead of new (storage) Target(get_source()); Probably that should be changed accordingly in Boost.Python (I checked version 1.35.0 still has this problem). Maybe other (better) solutions are possible. I think it is hard for me to use b::p::iterator, because we allow that a std::vector is constructed from any python sequence (also 1-dim numpy array) or scalar value. Furthermore we allow that a AnyValue is constructed from a sequence containing mixed types. You see we are very relaxed in the types one can pass, but I think weak typing is one of the basics of python programming. Cheers, Ger /Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp: In static member function 'static void boost::python::converter::implicit::construct(PyObject*, boost::python::converter::rvalue_from_python_stage1_data*) [with Source = casa::ValueHolder, Target = casa::DComplex]': /Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/implicit.hpp:21: instantiated from 'void boost::python::implicitly_convertible(boost::type*, boost::type*) [with Source = casa::ValueHolder, Target = casa::DComplex]' pyrap/Converters/PycArrayNP.cc:168: instantiated from here /Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp:37: error: call of overloaded 'complex(casa::ValueHolder&)' is ambiguous /usr/include/c++/4.0.0/complex:1470: note: candidates are: std::complex::complex(const std::complex&) /usr/include/c++/4.0.0/complex:1213: note: std::complex::complex(double, double) /usr/include/c++/4.0.0/complex:1155: note: std::complex::complex(const std::complex&) scons: *** [build_darwin_i386/opt/Converters/PycArrayNP.os] Error 1 scons: building terminated because of errors. >>> Andreas Kl?ckner 05/14/08 5:14 PM >>> Hi Ger, On Mittwoch 14 Mai 2008, Ger van Diepen wrote: > [snip] Unfortunately the compiler complained about ambiguous constructors > when using that for std::complex (e.g. double, complex and > complex for complex). I have to see if I can work around > that problem, but I'm afraid the problem is fundamental. I don't quite see what's going wrong--please post code if you need help. > Furthermore we have the possibility to convert a Python sequence to > std::vector. I still have to add the code to accept numpy array scalars in > such python sequences, so one can do in python something like: obj.func > ([arr1[0], arr2[0]]) Hmm--I don't quite understand. It sounds like you already have scalar conversion in place. Why wouldn't that automatically help with converting the vector elements? (Also, b::p::stl_input_iterator is easy to overlook, but good to know about, if you don't already) > Note that using int64 numpy on a 32 bit system gives the same problem as > int32 on a 64 bit system. The same problems arise for int16, float32, etc. > I was wondering if your solution can convert a numpy int16 to a C++ int (on > a 32 or 64 bit system) as it looks to me that only one PyTypeObject matches > a C++ type. In PyUblas, the types need to match exactly, by design. But numpy also has PyArray_CastScalarToCtype, so this is doable without declaring O(n^2) implicit conversion rules. That function might, however, be too lenient in what it accepts (floats, etc.). Depends on what you want. Andreas From brian.o'kennedy at vicon.com Thu May 15 10:07:20 2008 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Thu, 15 May 2008 09:07:20 +0100 Subject: [C++-sig] Boost.Python : Return std::string by ref? Message-ID: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> Hi All, I'm new to using Boost.Python so this might be a silly question, but bear with me. I've got a very simple c++ class as such: class MyClass { public: const std::string GetName() { return m_Name; }; void SetName( const std::string & Name ) { m_Name = Name; }; private: std::string m_Name; }; Which I wrap using Boost.Python: class_ < MyClass >("MyClass", "Testing String returned by value") .def( "GetName", &MyClass::GetName ) .def( "SetName", &MyClass::SetName); And I get to use it in Python as expected: >>> import BoostPythonTest >>> a = BoostPythonTest.MyClass() >>> a.SetName("foo") >>> a.GetName() 'foo' >>> type(a.GetName()) >>> ^Z The problem comes when I try to wrap this: class MyOtherClass { public: const std::string & GetName() { return m_Name; }; void SetName( const std::string & Name ) { m_Name = Name; }; private: std::string m_Name; }; Notice that GetName() now returns the string by const reference; this is done in a lot of our c++ code for efficiency sake. To wrap this using Boost.Python I do: class_ < MyOtherClass >("MyOtherClass", "Testing String returned by const ref") .def( "GetName", &MyOtherClass::GetName, return_internal_reference<>() ) .def( "SetName", &MyOtherClass::SetName); Which when used in Python does: >>> import BoostPythonTest >>> a = BoostPythonTest.MyOtherClass() >>> a.SetName('bar') >>> a.GetName() Traceback (most recent call last): File "", line 1, in TypeError: No Python class registered for C++ class class std::basic_string,class std::allocator > Is it possible to make Boost.Python automatically convert that const std::string & into a python string? Assume that I cannot go changing the c++ code of the classes that I want to wrap. Thanks, Brian ________________________________________________________________________ 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 paul.bilokon at lehman.com Thu May 15 11:38:46 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Thu, 15 May 2008 10:38:46 +0100 Subject: [C++-sig] Boost.Python: Wrapping functions with std::ostream & and std::istream & arguments In-Reply-To: <482B7397.5060601@sympatico.ca> References: <482B7397.5060601@sympatico.ca> Message-ID: Many thanks, Stefan, Do you reckon there is some open source code / code snippets that wrap Python "file" objects? It's not entirely trivial to wrap these classes. And since they are so ubiquitous, I'm sure someone has already done this? Best wishes, Paul -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: Thursday, May 15, 2008 12:20 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python: Wrapping functions with std::ostream & and std::istream & arguments Bilokon, Paul wrote: > Hi, > > I reckon the subject expresses my question pretty well. > > Is it possible to wrap C++ functions that take std::ostream & and > std::istream & arguments? > Yes, if you provide wrappers or converters for those stream objects, too. > How can I convert the corresponding Python objects? Are there any > examples? > That depends on what kind of streams you expect there. You may wrap by types that provide the python 'file' protocol interface, for example. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From meine at informatik.uni-hamburg.de Thu May 15 11:53:49 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 15 May 2008 11:53:49 +0200 Subject: [C++-sig] lvalue converter - pass by reference (non-const) In-Reply-To: <482B51BD.1050000@coredp.com> References: <482B51BD.1050000@coredp.com> Message-ID: <200805151153.50497.meine@informatik.uni-hamburg.de> Am Mittwoch, 14. Mai 2008 22:55:25 schrieb Moe Goldberg: > and then try to run it as follows: > >>> import custom_string > >>> mystr="123" > >>> custom_string.size(mystr) > > Traceback (most recent call last): > File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > custom_string.size(str) > did not match C++ signature: > size(sandbox::(anonymous namespace)::custom_string {lvalue}) You're not passing a custom_string, but a python str-object (which is furthermore immutable). How should the BPL extract a reference to a custom_string from a str-object? -- Ciao, / / /--/ / / ANS From meine at informatik.uni-hamburg.de Thu May 15 11:56:02 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 15 May 2008 11:56:02 +0200 Subject: [C++-sig] Boost.Python : Return std::string by ref? In-Reply-To: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> References: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> Message-ID: <200805151156.02410.meine@informatik.uni-hamburg.de> Am Donnerstag, 15. Mai 2008 10:07:20 schrieb Brian O'Kennedy: > Notice that GetName() now returns the string by const reference; this is > done in a lot of our c++ code for efficiency sake. To wrap this using > Boost.Python I do: > > [...] > .def( "GetName", &MyOtherClass::GetName, > return_internal_reference<>() ) I'd try copy_const_reference. -- Ciao, / / /--/ / / ANS From brian.o'kennedy at vicon.com Thu May 15 12:01:56 2008 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Thu, 15 May 2008 11:01:56 +0100 Subject: [C++-sig] Boost.Python : Return std::string by ref? In-Reply-To: <200805151156.02410.meine@informatik.uni-hamburg.de> References: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> <200805151156.02410.meine@informatik.uni-hamburg.de> Message-ID: <6BF44CD613458D479057BDB27207F2E00276021A@omgsvr02.omg.local> Hi Hans, Thanks for that, exactly what I wanted! I should have RTFA... :) For reference, here is my new binding: class_ < MyOtherClass >("MyOtherClass", "Testing String returned by const ref") .def( "GetName", &MyOtherClass::GetName, return_value_policy() ) .def( "SetName", &MyOtherClass::SetName); Thanks, Brian -----Original Message----- From: c++-sig-bounces+brian.okennedy=omg3d.com at python.org [mailto:c++-sig-bounces+brian.okennedy=omg3d.com at python.org] On Behalf Of Hans Meine Sent: 15 May 2008 10:56 To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python : Return std::string by ref? Am Donnerstag, 15. Mai 2008 10:07:20 schrieb Brian O'Kennedy: > Notice that GetName() now returns the string by const reference; this is > done in a lot of our c++ code for efficiency sake. To wrap this using > Boost.Python I do: > > [...] > .def( "GetName", &MyOtherClass::GetName, > return_internal_reference<>() ) I'd try copy_const_reference. -- Ciao, / / /--/ / / ANS _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig ________________________________________________________________________ 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 seefeld at sympatico.ca Thu May 15 12:50:19 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 15 May 2008 06:50:19 -0400 Subject: [C++-sig] Boost.Python : Return std::string by ref? In-Reply-To: <6BF44CD613458D479057BDB27207F2E00276021A@omgsvr02.omg.local> References: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> <200805151156.02410.meine@informatik.uni-hamburg.de> <6BF44CD613458D479057BDB27207F2E00276021A@omgsvr02.omg.local> Message-ID: <482C156B.2040109@sympatico.ca> Brian, Brian O'Kennedy wrote: > > Hi Hans, > > > > Thanks for that, exactly what I wanted! I should have RTFA... :) > Are you sure it really does what you think it does ? In Python strings are immutable, so there is little sense (other than performance) wanting to pass strings by reference. You can't modify them anyway. What observation makes you believe the string hasn't got copied in python ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From brian.o'kennedy at vicon.com Thu May 15 13:11:22 2008 From: brian.o'kennedy at vicon.com (Brian O'Kennedy) Date: Thu, 15 May 2008 12:11:22 +0100 Subject: [C++-sig] Boost.Python : Return std::string by ref? In-Reply-To: <482C156B.2040109@sympatico.ca> References: <6BF44CD613458D479057BDB27207F2E00276012B@omgsvr02.omg.local> <200805151156.02410.meine@informatik.uni-hamburg.de><6BF44CD613458D479057BDB27207F2E00276021A@omgsvr02.omg.local> <482C156B.2040109@sympatico.ca> Message-ID: <6BF44CD613458D479057BDB27207F2E002760293@omgsvr02.omg.local> Stefan, I'm aware that the std::string reference got copied into an immutable Python string which is the behaviour I wanted. I'm not intending to try and in-place modify a string, which is the reason the reference was const. The reason the c++ code returns the string by const reference is purely for performance in c++ code where these classes are mostly used. The usage of these classes in Python will require the copying of the std::string reference into a Python string which is immutable. Cheers, Brian -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Stefan Seefeld Sent: 15 May 2008 11:50 To: Development of Python/C++ integration Subject: Re: [C++-sig] Boost.Python : Return std::string by ref? Brian, Brian O'Kennedy wrote: > > Hi Hans, > > > > Thanks for that, exactly what I wanted! I should have RTFA... :) > Are you sure it really does what you think it does ? In Python strings are immutable, so there is little sense (other than performance) wanting to pass strings by reference. You can't modify them anyway. What observation makes you believe the string hasn't got copied in python ? Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig ________________________________________________________________________ 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. ________________________________________________________________________ From hgroven at emgs.com Thu May 15 13:23:24 2008 From: hgroven at emgs.com (=?ISO-8859-1?Q?H=E5kon_Groven?=) Date: Thu, 15 May 2008 13:23:24 +0200 Subject: [C++-sig] boost::posix_time::ptime conversion In-Reply-To: <480F4CA3.9030703@emgs.com> References: <480F4CA3.9030703@emgs.com> Message-ID: <482C1D2C.3010907@emgs.com> Hi again! Sorry for my late feedback! I've tried your (Ralf) advise by trying out http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#custom_string And this works fine! Actually I'm now converting from ptime to datetime, and from str(datetime) back to ptime. Here's some of my code illustrating what I've done: namespace { struct ptime_from_python_datetime_str { //str(datetime) => ptime ptime_from_python_datetime_str() { boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id ()); } static void* convertible(PyObject * obj_ptr) { if (!PyString_Check(obj_ptr)) return 0; return obj_ptr; } static void construct( PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data * data) { const char* value = PyString_AsString(obj_ptr); if (value == 0) boost::python::throw_error_already_set(); void* storage = ( (boost::python::converter::rvalue_from_python_storage*) data)->storage.bytes; new (storage) boost::posix_time::ptime(boost::posix_time::time_from_string(value)); data->convertible = storage; } }; struct ptime_to_python { //ptime => datetime 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()); } }; . . . } //end namespace BOOST_PYTHON_MODULE(mymodule) { . . . ptime_from_python_datetime_str(); to_python_converter (); . . . } -H?kon From goldberg at coredp.com Thu May 15 17:02:40 2008 From: goldberg at coredp.com (Moe Goldberg) Date: Thu, 15 May 2008 11:02:40 -0400 Subject: [C++-sig] lvalue converter - pass by reference (non-const) In-Reply-To: <200805151153.50497.meine@informatik.uni-hamburg.de> References: <482B51BD.1050000@coredp.com> <200805151153.50497.meine@informatik.uni-hamburg.de> Message-ID: <482C5090.1050401@coredp.com> That's a good point, I guess I was really thinking more of my case, where the python object that I am converting to/from contains a reference to the C++ object that I am converting from/to e.g. struct py_obj { py_obj() {} py_obj(const my_cpp_obj& value) : value_(value) {} cpp_obj& value_; }; void my_func(cpp_obj& co) { co.modify(); } then in python I want to call: >>> po = my_mod.py_obj() >>> my_mod.my_func(po) Is there a way to do this without manually wrapping myfunc? Hans Meine wrote: >Am Mittwoch, 14. Mai 2008 22:55:25 schrieb Moe Goldberg: > > >>and then try to run it as follows: >> >>> import custom_string >> >>> mystr="123" >> >>> custom_string.size(mystr) >> >>Traceback (most recent call last): >> File "", line 1, in ? >>Boost.Python.ArgumentError: Python argument types in >> custom_string.size(str) >>did not match C++ signature: >> size(sandbox::(anonymous namespace)::custom_string {lvalue}) >> >> > >You're not passing a custom_string, but a python str-object (which is >furthermore immutable). How should the BPL extract a reference to a >custom_string from a str-object? > > > From meine at informatik.uni-hamburg.de Thu May 15 17:51:23 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Thu, 15 May 2008 17:51:23 +0200 Subject: [C++-sig] lvalue converter - pass by reference (non-const) In-Reply-To: <482C5090.1050401@coredp.com> References: <482B51BD.1050000@coredp.com> <200805151153.50497.meine@informatik.uni-hamburg.de> <482C5090.1050401@coredp.com> Message-ID: <200805151751.23786.meine@informatik.uni-hamburg.de> Am Donnerstag, 15. Mai 2008 17:02:40 schrieb Moe Goldberg: > void my_func(cpp_obj& co) > { > co.modify(); > } > > then in python I want to call: > >>> po = my_mod.py_obj() > >>> my_mod.my_func(po) > > Is there a way to do this without manually wrapping myfunc? Let me ask the other way round: Is there a way to prevent this from working without manually wrapping myfunc? ;-) -- Ciao, / / /--/ / / ANS From chiang at ISI.EDU Thu May 15 19:34:38 2008 From: chiang at ISI.EDU (David Chiang) Date: Thu, 15 May 2008 10:34:38 -0700 Subject: [C++-sig] opaque_pointer_converter being used correctly? Message-ID: <482C742E.6000901@isi.edu> Greetings, I am trying to use the opaque pointer converter to pass a pointer from C++ to a Python function (code below). When I pass the pointer directly, it compiles and I get: $ test 0x12345 Segmentation fault When I pass a pointer to a pointer, I get: $ test 0x12345 f() 0x12345 Should the first option have worked, or should it at least have generated a compile error or exception? Is there a third correct way to do this that I've missed? Thanks in advance. David ----------------- test.cpp ------------------ #include #include using namespace std; using namespace boost::python; struct foo_t; BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(foo_t); int main (int argc, char *argv[]) { Py_Initialize(); opaque(); foo_t *pfoo = reinterpret_cast(0x12345); cout << hex << pfoo << endl; object module = import("test"); object f = module.attr("f"); try { //pfoo = extract(f(pfoo)); // this doesn't work pfoo = extract(f(&pfoo)); // is this right? } catch (error_already_set) { PyErr_Print(); } cout << hex << pfoo << endl; } ------------------- test.py ----------------------- def f(foo): print "f(%s)" % foo return foo From francis_moreau at hotmail.com Fri May 16 21:49:51 2008 From: francis_moreau at hotmail.com (Francis Moreau) Date: Fri, 16 May 2008 15:49:51 -0400 Subject: [C++-sig] python::object that takes ownership of a C++ instance Message-ID: Hi, I would like to know if there is the equivalent of manage_new_object return_policy but for an argument pass to Python? I have a Python class derived from a C++ base class: class PyEventProcessor(CppEventProcessor): def processEvent(in_event): # do something And then in C++ I want to call processEvent and transferring the ownership of the event to Python: void CppEventProcessor_Wrapped::pyProcessEvent(const Event& in_event) { // This following line is working well, but I want to transfert the ownership of the event instead of passing a reference on it. return python::call_method(m_pSelf, "processEvent", boost::ref(in_event)): // I tried something like this but it's not working. Event* pNewEvent = in_event.clone(); python::object obj(&pNewEvent); // Event is a type exposed in Python } I would like to know what is the best way to do something like this, is it by using a auto_ptr, or a from_python convertor, or something else? Also, I have a few types richer than Event, and exposed to Python too, and I want to be able to use them directly in Python, e.g.: class PyEventProcessor(CppEventProcessor): def processEvent(in_event): if in_event is ConnectionEvent: srcAddr = in_event.getSourceAddr() Thanks, Francis From venkat83 at gmail.com Sat May 17 04:06:39 2008 From: venkat83 at gmail.com (Venkatraman S) Date: Sat, 17 May 2008 07:36:39 +0530 Subject: [C++-sig] boost python and keyword aguments In-Reply-To: <4829ADA5.7090304@coredp.com> References: <48234A19.90401@coredp.com> <4829ADA5.7090304@coredp.com> Message-ID: On Tue, May 13, 2008 at 8:33 PM, Moe Goldberg wrote: > Thanks! That's pretty much what I am looking for. > > The docuemntation says, you can write a function this way > tuple raw(tuple args, dict kw) > { > return make_tuple(args, kw); > } > > Is the first arg(tuple) mandatory here?? Cant we just pass the dict alone? -- Venkat Blog @ http://blizzardzblogs.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat May 17 19:30:18 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 17 May 2008 20:30:18 +0300 Subject: [C++-sig] python::object that takes ownership of a C++ instance In-Reply-To: References: Message-ID: <7465b6170805171030h1e968979nd15d8c45c711cfa8@mail.gmail.com> On Fri, May 16, 2008 at 10:49 PM, Francis Moreau wrote: > Hi, > > I would like to know if there is the equivalent of manage_new_object > return_policy but for an argument pass to Python? > I have a Python class > derived from a C++ base class: > > class PyEventProcessor(CppEventProcessor): > def processEvent(in_event): > # do something > > And then in C++ I want to call processEvent and transferring the ownership > of the event to Python: > > void CppEventProcessor_Wrapped::pyProcessEvent(const Event& in_event) > { > // This following line is working well, but I want to transfert the > ownership of the event instead of passing a reference on it. > return python::call_method(m_pSelf, "processEvent", > boost::ref(in_event)): > > // I tried something like this but it's not working. > Event* pNewEvent = in_event.clone(); > python::object obj(&pNewEvent); // Event is a type exposed in Python > } If I remember right, you can pass here std::auto_ptr > I would like to know what is the best way to do something like this, is it > by using a auto_ptr, or a from_python convertor, or something else? Also, I > have a few types richer than Event, and exposed to Python too, and I want to > be able to use them directly in Python, e.g.: > > class PyEventProcessor(CppEventProcessor): > def processEvent(in_event): > if in_event is ConnectionEvent: > srcAddr = in_event.getSourceAddr() The last question is not clear. If you created module, than you can import it and use. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From RaoulGough at yahoo.co.uk Sun May 18 17:55:59 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 18 May 2008 16:55:59 +0100 Subject: [C++-sig] Raoul Gough's container suite with svn boost-trunkboost.python? In-Reply-To: References: <470E72FE.48A19C6D@sitius.com> Message-ID: <4830518F.1030000@yahoo.co.uk> John Reid wrote: > Nikolay Mladenov wrote: > >> I found it, >> >> the postcall_override template needs to have the following line >> >> typedef typename Policy::extract_return_type extract_return_type; >> >> > Do you mean I should insert that line as follows? > > namespace detail { > template > struct postcall_override > { > // This class overrides the Policy's postcall function and > // result_conveter to handle the list returned from get_slice. > // The Policy's result_converter is removed, since it gets > // applied within get_slice. Our postcall override applies the > // original postcall to each element of the Python list returned > // from get_slice. > > typedef typename Policy::extract_return_type extract_return_type; > > > [snip] > In my version of boost/python/suite/indexing/slice_handler.hpp this is > inserted on line 63. > > If I do this I get the following error: > /alma/home/john/software/boost/boost-trunk/boost/python/suite/indexing/slice_handler.hpp:63: > error: 'typename > boost::python::return_value_policy boost::python::default_call_policies>::extract_return_type' names > 'template struct > boost::python::default_call_policies::extract_return_type', which is not > a type > I've recently been working on the indexing_v2 suite again, and noticed that I also got an error with extract_return_type. However, this is not a type but rather a member class template, so you need this instead of a typedef: template struct extract_return_type : Policy::template extract_return_type { }; I've tested this on g++ 4.0.1 (darwin) and the tests compile and work, so I assume this is all that's required to fix it. FWIW, this would have been broken since the change to boost/python/default_call_policies.hpp on 2007-09-11 for the new docstring / C++ function signature features. I'll post some information on building from scratch with indexing_v2 from the branch, but in the mean time you can probably just apply the change above in your own copy of slice_handler.hpp -- Cheers, Raoul. From RaoulGough at yahoo.co.uk Sun May 18 19:36:15 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 18 May 2008 18:36:15 +0100 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: <4830690F.8030603@yahoo.co.uk> Raoul Gough wrote: > 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 OK, this turned out to be more work than I expected, but it should now be possible to add the indexing_v2 suite to an existing svn checkout of the boost trunk using the commands listed below. Note that this includes a new fix for the extract_return_type problem reported by John Reid back in October 2007. The indexing_v2 directories are completely new, so don't involve modifying any existing files in the trunk. However, you also need some modifications to the Jamfile.v2 files in libs/python/build and libs/python/test to make it build. I'm not sure what is the ideal way to do this in an existing checkout of the trunk, but the merge commands below seem to work. Remember not to try committing these to the trunk by mistake! I've tested this against trunk r45491 with i686-apple-darwin8-g++-4.0.1 Commands below assume you're in the top-level of the checkout, i.e. where LICENSE_1_0.txt is located ----8<------ commands start here svn co http://svn.boost.org/svn/boost/sandbox/python_indexing_v2/boost/python/suite/indexing_v2 boost/python/suite/indexing_v2 svn co http://svn.boost.org/svn/boost/sandbox/python_indexing_v2/libs/python/src/indexing_v2 libs/python/src/indexing_v2 svn co http://svn.boost.org/svn/boost/sandbox/python_indexing_v2/libs/python/test/indexing_v2 libs/python/test/indexing_v2 svn merge -r45485:HEAD http://svn.boost.org/svn/boost/sandbox/python_indexing_v2/libs/python/build/Jamfile.v2 libs/python/build/Jamfile.v2 svn merge -r45486:HEAD http://svn.boost.org/svn/boost/sandbox/python_indexing_v2/libs/python/test/Jamfile.v2 libs/python/test/Jamfile.v2 ----8<------ commands end here To undo the changes to the Jamfiles, the following should be sufficient: svn revert libs/python/build/Jamfile.v2 libs/python/test/Jamfile.v2 -- Cheers, Raoul. From paul.bilokon at lehman.com Mon May 19 14:30:59 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Mon, 19 May 2008 13:30:59 +0100 Subject: [C++-sig] Smart Pointers in Boost.Python with Automatic Dereferencing Message-ID: Hi all, I'm trying to find an authoritative resource on exposing functions that return smart pointers using Boost.Python. So far my best example is this: http://wiki.python.org/moin/boost.python/PointersAndSmartPointers However, I find the need to explicitly dereference the pointer in Python deeply unsatisfactory: print (+an_A).hello() This is essentially C++ programming in Python. The whole purpose of the exercise is to avoid the need for explicit memory management! Is there another method that will simply allow me to call print an_A.hello() Many thanks for your help! Best wishes, Paul P.S. Just for your information I'll paste the C++ code: #include using namespace boost; struct A { shared_ptr create () { return shared_ptr(new A); } std::string hello () { return "Just nod if you can hear me!"; } }; BOOST_PYTHON_MODULE(shared_ptr) { class_("A",init<>()) .def("create",&A::create,return_value_policy()) .staticmethod("create") .def("hello",&A::hello) ; class_< shared_ptr >("A_ptr", init& >()) .def("__pos__",&boost::shared_ptr::get,return_internal_reference<>()) ; } And the sample Python program: from shared_ptr import * an_A = A_ptr.create() print (+an_A).hello() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From rwgk at yahoo.com Mon May 19 18:51:42 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 19 May 2008 09:51:42 -0700 (PDT) Subject: [C++-sig] Smart Pointers in Boost.Python with Automatic Dereferencing Message-ID: <662262.86283.qm@web31105.mail.mud.yahoo.com> Boost.Python has special support for boost::shared_ptr<>. E.g. this should do what you want (untested): class_ >("A") It is more difficult only if you have your own smart pointers. Ralf ----- Original Message ---- From: "Bilokon, Paul" To: Development of Python/C++ integration Sent: Monday, May 19, 2008 5:30:59 AM Subject: [C++-sig] Smart Pointers in Boost.Python with Automatic Dereferencing Hi all, I'm trying to find an authoritative resource on exposing functions that return smart pointers using Boost.Python. So far my best example is this: http://wiki.python.org/moin/boost.python/PointersAndSmartPointers However, I find the need to explicitly dereference the pointer in Python deeply unsatisfactory: print (+an_A).hello() This is essentially C++ programming in Python. The whole purpose of the exercise is to avoid the need for explicit memory management! Is there another method that will simply allow me to call print an_A.hello() Many thanks for your help! Best wishes, Paul P.S. Just for your information I'll paste the C++ code: #include using namespace boost; struct A { shared_ptr create () { return shared_ptr(new A); } std::string hello () { return "Just nod if you can hear me!"; } }; BOOST_PYTHON_MODULE(shared_ptr) { class_("A",init<>()) .def("create",&A::create,return_value_policy()) .staticmethod("create") .def("hello",&A::hello) ; class_< shared_ptr >("A_ptr", init& >()) .def("__pos__",&boost::shared_ptr::get,return_internal_reference<>()) ; } And the sample Python program: from shared_ptr import * an_A = A_ptr.create() print (+an_A).hello() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From paul.bilokon at lehman.com Mon May 19 19:18:38 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Mon, 19 May 2008 18:18:38 +0100 Subject: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing In-Reply-To: <662262.86283.qm@web31105.mail.mud.yahoo.com> References: <662262.86283.qm@web31105.mail.mud.yahoo.com> Message-ID: Hi Ralf, Many thanks for your reply. Unfortunately, I do have a custom "smart" pointer and it would be very difficult to convert it. Do you know if there are any code examples for custom smart pointers? Many thanks, Paul -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Monday, May 19, 2008 5:52 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing Boost.Python has special support for boost::shared_ptr<>. E.g. this should do what you want (untested): class_ >("A") It is more difficult only if you have your own smart pointers. Ralf ----- Original Message ---- From: "Bilokon, Paul" To: Development of Python/C++ integration Sent: Monday, May 19, 2008 5:30:59 AM Subject: [C++-sig] Smart Pointers in Boost.Python with Automatic Dereferencing Hi all, I'm trying to find an authoritative resource on exposing functions that return smart pointers using Boost.Python. So far my best example is this: http://wiki.python.org/moin/boost.python/PointersAndSmartPointers However, I find the need to explicitly dereference the pointer in Python deeply unsatisfactory: print (+an_A).hello() This is essentially C++ programming in Python. The whole purpose of the exercise is to avoid the need for explicit memory management! Is there another method that will simply allow me to call print an_A.hello() Many thanks for your help! Best wishes, Paul P.S. Just for your information I'll paste the C++ code: #include using namespace boost; struct A { shared_ptr create () { return shared_ptr(new A); } std::string hello () { return "Just nod if you can hear me!"; } }; BOOST_PYTHON_MODULE(shared_ptr) { class_("A",init<>()) .def("create",&A::create,return_value_policy()) .staticmethod("create") .def("hello",&A::hello) ; class_< shared_ptr >("A_ptr", init& >()) .def("__pos__",&boost::shared_ptr::get,return_internal_reference<>()) ; } And the sample Python program: from shared_ptr import * an_A = A_ptr.create() print (+an_A).hello() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From michael.wieher at gmail.com Mon May 19 20:54:41 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Mon, 19 May 2008 13:54:41 -0500 Subject: [C++-sig] ?? building the shared library issue Message-ID: Problem: ------------- using python py build_ext -i my is not correct. The source="file.cpp" fle has an include and the included include includes other "name.h" files the object files are not being linked to the final library correctly how do I tell distutils how to handle multiple source-files when building my extensions? From michael.wieher at gmail.com Mon May 19 23:04:26 2008 From: michael.wieher at gmail.com (Michael Wieher) Date: Mon, 19 May 2008 16:04:26 -0500 Subject: [C++-sig] build error?? Message-ID: It looks like build_ext / distutils is failing to understand some parameters correctly? [michael at majw src]$ python setup-mempy.py build_ext -i running build_ext building 'pymem' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c libraries/classlib/dataset.cpplibraries/classlib/synobj.cpp -o build/temp.linux-i686-2.4/libraries/classlib/dataset.cpplibraries/classlib/synobj.o gcc: libraries/classlib/dataset.cpplibraries/classlib/synobj.cpp: No such file or directory gcc: no input files error: command 'gcc' failed with exit status 1 ----------------------------------------------------------------------------------------------------------------------------- #!/usr/bin/python from distutils.core import setup,Extension module1 = Extension('pymem', include_dirs=[ # '/home/michael/proj/pydata/src' # '/home/michael/proj/pydata/src/libraries', # '/home/michael/proj/pydata/src/libraries/support', # '/home/michael/proj/pydata/src/libraries/classlib', ], sources=[ 'memrid.cpp', 'libraries/datainit.cpp', 'libraries/classlib/dataset.cpp' 'libraries/classlib/synobj.cpp' # 'libraries/classlib/stack.cpp' # 'libraries/classlib/datarequest.cpp' # 'libraries/classlib/initdata.cpp' # 'libraries/classlib/bitvectorlib.cpp' ], ) setup(name='pymem', version='1.0', description='pythonextensioninC', ext_modules=[module1]) ----------------------------------------------------------------------------------------------------------------------------- Seems pretty simple! but as I uncomment further dependent libraries, it just starts getting confused and dies... any idea? looks like it forgets spaces somehow.. I'm not sure whats going on... From rwgk at yahoo.com Tue May 20 01:19:50 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 19 May 2008 16:19:50 -0700 (PDT) Subject: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing Message-ID: <570377.27871.qm@web31103.mail.mud.yahoo.com> No, sorry. Very wild idea: can your smart pointer be converted both ways to/from a boost::shared_ptr? And are all your smart pointer objects passed by value or const&? Then maybe a custom rvalue converter could do the trick. I hope someone else with actual experience in this area will be able to help. Ralf ----- Original Message ---- From: "Bilokon, Paul" To: Development of Python/C++ integration Sent: Monday, May 19, 2008 10:18:38 AM Subject: Re: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing Hi Ralf, Many thanks for your reply. Unfortunately, I do have a custom "smart" pointer and it would be very difficult to convert it. Do you know if there are any code examples for custom smart pointers? Many thanks, Paul -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: Monday, May 19, 2008 5:52 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing Boost.Python has special support for boost::shared_ptr<>. E.g. this should do what you want (untested): class_ >("A") It is more difficult only if you have your own smart pointers. Ralf ----- Original Message ---- From: "Bilokon, Paul" To: Development of Python/C++ integration Sent: Monday, May 19, 2008 5:30:59 AM Subject: [C++-sig] Smart Pointers in Boost.Python with Automatic Dereferencing Hi all, I'm trying to find an authoritative resource on exposing functions that return smart pointers using Boost.Python. So far my best example is this: http://wiki.python.org/moin/boost.python/PointersAndSmartPointers However, I find the need to explicitly dereference the pointer in Python deeply unsatisfactory: print (+an_A).hello() This is essentially C++ programming in Python. The whole purpose of the exercise is to avoid the need for explicit memory management! Is there another method that will simply allow me to call print an_A.hello() Many thanks for your help! Best wishes, Paul P.S. Just for your information I'll paste the C++ code: #include using namespace boost; struct A { shared_ptr create () { return shared_ptr(new A); } std::string hello () { return "Just nod if you can hear me!"; } }; BOOST_PYTHON_MODULE(shared_ptr) { class_("A",init<>()) .def("create",&A::create,return_value_policy()) .staticmethod("create") .def("hello",&A::hello) ; class_< shared_ptr >("A_ptr", init& >()) .def("__pos__",&boost::shared_ptr::get,return_internal_reference<>()) ; } And the sample Python program: from shared_ptr import * an_A = A_ptr.create() print (+an_A).hello() - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From Mark.English at rbccm.com Tue May 20 09:57:46 2008 From: Mark.English at rbccm.com (English, Mark) Date: Tue, 20 May 2008 08:57:46 +0100 Subject: [C++-sig] Smart Pointers in Boost.Python withAutomaticDereferencing In-Reply-To: <570377.27871.qm@web31103.mail.mud.yahoo.com> References: <570377.27871.qm@web31103.mail.mud.yahoo.com> Message-ID: <71C85D3C5CDA684C88DDE171F8C7EC29197160@SXLM-101.fg.rbc.com> -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Ralf W. Grosse-Kunstleve Sent: 20 May 2008 00:20 To: Development of Python/C++ integration Subject: Re: [C++-sig] Smart Pointers in Boost.Python withAutomaticDereferencing > No, sorry. > Very wild idea: can your smart pointer be converted both ways to/from a boost::shared_ptr? > And are all your smart pointer objects passed by value or const&? > Then maybe a custom rvalue converter could do the trick. > I hope someone else with actual experience in this area will be able to help. > Ralf Have you tried using your own custom pointer as the held_type for the class_ ? i.e. class_ >("A"); In many cases this works reasonably well as long as the suitable typedefs and functions are in place in my_custom_ptr. You will probably hit problems if you derive from your C++ types in Python (Python inheritance/polymorphism), store my_custom_ptr pointers to instances of these Python derived classes in your C++ code, and expose these back to your Python code. For some people that is not a concern. ----Apologies for this sig---- _______________________________________________________________________ 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 paul.bilokon at lehman.com Tue May 20 14:56:25 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Tue, 20 May 2008 13:56:25 +0100 Subject: [C++-sig] Non-const reference arguments and from_python conversions Message-ID: Hi all, I have written a from_python_stream converter for Python streams (like sys.stdout). The converter registers itself as follows: boost::python::converter::registry::push_back( &convertible, &construct, boost::python::type_id<_Stream>()); So nothing unusual here. _Stream is the template argument. Then I do the following: StreamConversions::from_python_stream >(); Again, nothing unusual here. I'm testing it on two functions: void outTest(const ostream & out) { // cout << "Test-----outTest successful" << endl; } void outTestRef(ostream & out) { cout << "Test-----outTest successful" << endl; } Which are registered like this: def("outTest", outTest); def("outTestRef", outTestRef); Obviously I need outTestRef to work. Otherwise I can't use operator<<, so what's the point. Unfortunately, outTest works, outTestRef does not work: outTest(sys.stderr) # works outTestRef(sys.stderr) # fails The error is: File "proto_test.py", line 23, in outTestRef(sys.stderr) Boost.Python.ArgumentError: Python argument types in pyamp.proto.outTestRef(file) did not match C++ signature: outTestRef(class std::basic_ostream > {lvalue}) Hence the question: is there absolutely no support for non-const reference arguments? Many thanks for your help! Regards, Paul - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From paul.bilokon at lehman.com Tue May 20 15:08:54 2008 From: paul.bilokon at lehman.com (Bilokon, Paul) Date: Tue, 20 May 2008 14:08:54 +0100 Subject: [C++-sig] Non-const reference arguments and from_python conversions In-Reply-To: References: Message-ID: P.S. I'm looking at http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/faq.html#questio n2 And it says Using custom rvalue converters. Boost.Python "rvalue converters" match function signatures such as: void foo(std::vector const& array); // pass by const-reference void foo(std::vector array); // pass by value Does this mean the argument MUST be passed by const-reference or by value (i.e. it can't be a non-const reference or a pointer)? Many thanks, Paul > _____________________________________________ > From: Bilokon, Paul > Sent: Tuesday, May 20, 2008 1:56 PM > To: Development of Python/C++ integration > Subject: Non-const reference arguments and from_python > conversions > > Hi all, > > I have written a from_python_stream converter for Python streams (like > sys.stdout). > > The converter registers itself as follows: > > boost::python::converter::registry::push_back( > &convertible, > &construct, > boost::python::type_id<_Stream>()); > > So nothing unusual here. _Stream is the template argument. > > Then I do the following: > > StreamConversions::from_python_stream > >(); > > Again, nothing unusual here. > > I'm testing it on two functions: > > void outTest(const ostream & out) > { > // cout << "Test-----outTest successful" << endl; > } > > void outTestRef(ostream & out) > { > cout << "Test-----outTest successful" << endl; > } > > Which are registered like this: > > def("outTest", outTest); > def("outTestRef", outTestRef); > > Obviously I need outTestRef to work. Otherwise I can't use operator<<, > so what's the point. > > Unfortunately, outTest works, outTestRef does not work: > > outTest(sys.stderr) # works > outTestRef(sys.stderr) # fails > > The error is: > > File "proto_test.py", line 23, in > outTestRef(sys.stderr) > Boost.Python.ArgumentError: Python argument types in > pyamp.proto.outTestRef(file) > did not match C++ signature: > outTestRef(class std::basic_ostream std::char_traits > {lvalue}) > > Hence the question: is there absolutely no support for non-const > reference arguments? > > Many thanks for your help! > > Regards, > Paul - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. From rwgk at yahoo.com Tue May 20 20:50:06 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 20 May 2008 11:50:06 -0700 (PDT) Subject: [C++-sig] Non-const reference arguments and from_python conversions Message-ID: <783827.86820.qm@web31105.mail.mud.yahoo.com> > Does this mean the argument MUST be passed by const-reference or by > value (i.e. it can't be a non-const reference or a pointer)? Yes. -- A few years ago we had a contract with David to implement support for "converters with write-back", but it turned out to be too difficult. In theory you can use indirection of some sort to get around the problem (e.g. make a proxy object holding a reference to the object you actually want to pass, pass the proxy by value). However, in most cases this will probably impose unacceptable restrictions on the interface. Ralf From roman.yakovenko at gmail.com Tue May 20 22:39:15 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 20 May 2008 23:39:15 +0300 Subject: [C++-sig] Smart Pointers in Boost.Python with AutomaticDereferencing In-Reply-To: References: <662262.86283.qm@web31105.mail.mud.yahoo.com> Message-ID: <7465b6170805201339p6ab70a5ar15652a41d8788f7@mail.gmail.com> On Mon, May 19, 2008 at 8:18 PM, Bilokon, Paul wrote: > > Hi Ralf, > > Many thanks for your reply. > > Unfortunately, I do have a custom "smart" pointer and it would be very > difficult to convert it. > > Do you know if there are any code examples for custom smart pointers? I guess this can help: http://language-binding.net/pyplusplus/troubleshooting_guide/smart_ptrs/smart_ptrs.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From enewhuis at gmail.com Wed May 21 03:03:57 2008 From: enewhuis at gmail.com (Eric Newhuis) Date: Tue, 20 May 2008 20:03:57 -0500 Subject: [C++-sig] Boost.Python Quickstart test failure/segfault on Boost 1.35.0 Python 2.5 on 64-bit Linux (RedHat) Message-ID: <483374FD.1010401@gmail.com> On my platform: Linux 2.6.9-67.0.1.ELsmp #1 SMP Fri Nov 30 11:57:43 EST 2007 x86_64 GNU/Linux I verified that the boost python tests fail only when I provide a user-config.jam file that points to a 64-bit Python 2.5. If I don?t provide such a file then the default choices made by BJAM result in a passing test. It doesn?t matter if threading=single or multi or variant=debug or release. I get similar results. Does anyone have a clue what is going on and how to fix this? After the stack trace see the bottom of this email for additional info about warnings I see during compilation. I don't know if they are related. The failing line in question appears to be decrementing a reference count. #0 0x0000000000000000 in ?? () #1 0x0000002a998830fc in ~object_base (this=0x7fbfffb0f0) at ../../../../boost/python/object_core.hpp:436 #2 0x0000002a998830c5 in ~object (this=0x7fbfffb0f0) at ../../../../boost/python/slice_nil.hpp:16 #3 0x0000002a99a254d1 in ~dict_base (this=0x7fbfffb0f0) at ../../../../boost/python/dict.hpp:89 #4 0x0000002a99a254b9 in ~dict (this=0x7fbfffb0f0) at ../../../../libs/python/src/object/enum.cpp:139 #5 0x0000002a99a28a6b in boost::python::objects::(anonymous namespace)::new_class (name=0x2a9988812a "hello", num_types=1, types=0x7fbfffb1e8, doc=0x0) at ../../../../libs/python/src/object/class.cpp:539 #6 0x0000002a99a27969 in class_base (this=0x7fbfffb250, name=0x2a9988812a "hello", num_types=1, types=0x7fbfffb1e8, doc=0x0) at ../../../../libs/python/src/object/class.cpp:546 #7 0x0000002a9988328c in class_ > (this=0x7fbfffb250, name=0x2a9988812a "hello", i=@0x7fbfffb230) at ../../../../boost/python/class.hpp:207 #8 0x0000002a99882e77 in init_module_extending () at extending.cpp:32 #9 0x0000002a99a416be in boost::detail::function::void_function_ref_invoker0::invoke (function_obj_ptr=@0x7fbfffb358) at ../../../../boost/function/function_template.hpp:193 #10 0x0000002a99a40fa8 in boost::function0 >::operator() (this=0x7fbfffb350) at ../../../../boost/function/function_template.hpp:824 #11 0x0000002a99a409fb in boost::python::handle_exception_impl (f= { = {vtable = 0x2a99b752e0, functor = {obj_ptr = 0x7fbfffb378, const_obj_ptr = 0x7fbfffb378, func_ptr = 0x7fbfffb378, bound_memfunc_ptr = {memfunc_ptr = {__pfn = 0x7fbfffb378, __delta = 548682052496}, obj_ptr = 0x2a99a4144f}, data = 120 'x'}}, static args = , static arity = }) at ../../../../libs/python/src/errors.cpp:25 #12 0x0000002a99a414d9 in boost::python::handle_exception (f=0x2a99882e4c ) at ../../../../boost/python/errors.hpp:29 #13 0x0000002a99a41347 in boost::python::detail::init_module (name=0x2a99888120 "extending", init_function=0x2a99882e4c ) at ../../../../libs/python/src/module.cpp:39 #14 0x0000002a99882e49 in initextending () at extending.cpp:29 #15 0x0000002a95647e43 in _PyImport_LoadDynamicModule (name=0x7fbfffc630 "extending", pathname=0x7fbfffb530 "/home/users/ericn/boost_1_35_0/libs/python/example/quickstart/bin/gcc-3.4.6/debug/threading-multi/extending.so", fp=0x632280) at ./Python/importdl.c:53 #16 0x0000002a956450a0 in load_module (name=0x7fbfffc630 "extending", fp=0x632280, buf=0x7fbfffb530 "/home/users/ericn/boost_1_35_0/libs/python/example/quickstart/bin/gcc-3.4.6/debug/threading-multi/extending.so", type=3, loader=0x0) at Python/import.c:1758 #17 0x0000002a956466e0 in import_submodule (mod=0x2a957be230, subname=0x7fbfffc630 "extending", fullname=0x7fbfffc630 "extending") at Python/import.c:2400 #18 0x0000002a95645ff5 in load_next (mod=0x2a957be230, altmod=0x2a957be230, p_name=0x7fbfffd668, buf=0x7fbfffc630 "extending", p_buflen=0x7fbfffc628) at Python/import.c:2220 #19 0x0000002a956457b7 in import_module_level (name=0x0, globals=0x60de80, locals=0x60de80, fromlist=0x2a991b8710, level=-1) at Python/import.c:2001 #20 0x0000002a95645b1b in PyImport_ImportModuleLevel (name=0x2a991be32c "extending", globals=0x60de80, locals=0x60de80, fromlist=0x2a991b8710, level=-1) at Python/import.c:2072 #21 0x0000002a9561dec4 in builtin___import__ (self=0x0, args=0x2a95b20d08, kwds=0x0) at Python/bltinmodule.c:47 #22 0x0000002a955ce52a in PyCFunction_Call (func=0x2a95abb5f0, arg=0x2a95b20d08, kw=0x0) at Objects/methodobject.c:77 #23 0x0000002a95599373 in PyObject_Call (func=0x2a95abb5f0, arg=0x2a95b20d08, kw=0x0) at Objects/abstract.c:1861 #24 0x0000002a9562bb14 in PyEval_CallObjectWithKeywords (func=0x2a95abb5f0, arg=0x2a95b20d08, kw=0x0) at Python/ceval.c:3442 #25 0x0000002a95628562 in PyEval_EvalFrameEx (f=0x6158d0, throwflag=0) at Python/ceval.c:2067 #26 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a95b26af8, globals=0x60de80, locals=0x60de80, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2836 #27 0x0000002a95623a42 in PyEval_EvalCode (co=0x2a95b26af8, globals=0x60de80, locals=0x60de80) at Python/ceval.c:494 #28 0x0000002a9562dc05 in exec_statement (f=0x630de0, prog=0x2a95b26af8, globals=0x60de80, locals=0x60de80) at Python/ceval.c:4177 #29 0x0000002a95626e60 in PyEval_EvalFrameEx (f=0x630de0, throwflag=0) at Python/ceval.c:1666 #30 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a989b5828, globals=0x518bb0, locals=0x0, args=0x617f80, argcount=4, kws=0x617fa0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2836 #31 0x0000002a9562c5b2 in fast_function (func=0x2a991bc230, pp_stack=0x7fbfffe080, n=4, na=4, nk=0) at Python/ceval.c:3669 #32 0x0000002a9562c311 in call_function (pp_stack=0x7fbfffe080, oparg=3) at Python/ceval.c:3594 #33 0x0000002a95628e6e in PyEval_EvalFrameEx (f=0x617dd0, throwflag=0) at Python/ceval.c:2272 #34 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a989b5990, globals=0x518bb0, locals=0x0, args=0x5209c0, argcount=2, kws=0x5209d0, kwcount=0, defs=0x2a991b7978, defcount=3, closure=0x0) at Python/ceval.c:2836 #35 0x0000002a9562c5b2 in fast_function (func=0x2a991bc398, pp_stack=0x7fbfffe450, n=2, na=2, nk=0) at Python/ceval.c:3669 #36 0x0000002a9562c311 in call_function (pp_stack=0x7fbfffe450, oparg=1) at Python/ceval.c:3594 #37 0x0000002a95628e6e in PyEval_EvalFrameEx (f=0x5207e0, throwflag=0) at Python/ceval.c:2272 #38 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a989bb378, globals=0x518bb0, locals=0x0, args=0x520780, argcount=1, kws=0x520788, kwcount=1, defs=0x2a98d5fbe8, defcount=9, closure=0x0) at Python/ceval.c:2836 #39 0x0000002a9562c5b2 in fast_function (func=0x2a991b95f0, pp_stack=0x7fbfffe820, n=3, na=1, nk=1) at Python/ceval.c:3669 #40 0x0000002a9562c311 in call_function (pp_stack=0x7fbfffe820, oparg=257) at Python/ceval.c:3594 #41 0x0000002a95628e6e in PyEval_EvalFrameEx (f=0x5205e0, throwflag=0) at Python/ceval.c:2272 #42 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a95b18300, globals=0x524510, locals=0x0, args=0x568f08, argcount=0, kws=0x568f08, kwcount=0, defs=0x2a95b244a8, defcount=1, closure=0x0) at Python/ceval.c:2836 #43 0x0000002a9562c5b2 in fast_function (func=0x2a95b11938, pp_stack=0x7fbfffebf0, n=0, na=0, nk=0) at Python/ceval.c:3669 #44 0x0000002a9562c311 in call_function (pp_stack=0x7fbfffebf0, oparg=0) at Python/ceval.c:3594 #45 0x0000002a95628e6e in PyEval_EvalFrameEx (f=0x568d80, throwflag=0) at Python/ceval.c:2272 #46 0x0000002a9562a7b6 in PyEval_EvalCodeEx (co=0x2a95b11648, globals=0x524510, locals=0x524510, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2836 #47 0x0000002a95623a42 in PyEval_EvalCode (co=0x2a95b11648, globals=0x524510, locals=0x524510) at Python/ceval.c:494 #48 0x0000002a95650e3c in run_mod (mod=0x51e130, filename=0x7fbffff4be "test_extending.py", globals=0x524510, locals=0x524510, flags=0x7fbffff050, arena=0x543950) at Python/pythonrun.c:1273 #49 0x0000002a95650dc6 in PyRun_FileExFlags (fp=0x501010, filename=0x7fbffff4be "test_extending.py", start=257, globals=0x524510, locals=0x524510, closeit=1, flags=0x7fbffff050) at Python/pythonrun.c:1259 #50 0x0000002a9564fdcf in PyRun_SimpleFileExFlags (fp=0x501010, filename=0x7fbffff4be "test_extending.py", closeit=1, flags=0x7fbffff050) at Python/pythonrun.c:879 #51 0x0000002a9564f711 in PyRun_AnyFileExFlags (fp=0x501010, filename=0x7fbffff4be "test_extending.py", closeit=1, flags=0x7fbffff050) at Python/pythonrun.c:698 #52 0x0000002a9565c5c2 in Py_Main (argc=2, argv=0x7fbffff1c8) at Modules/main.c:523 #53 0x0000000000400793 in main () I get the following warnings. Are they benign? 1. ../../../../libs/python/src/str.cpp: In function `boost::python::ssize_t boost::python::detail::::str_size_as_py_ssize_t(size_t)' : ../../../../libs/python/src/str.cpp:29: warning: comparison between signed and unsigned integer expressions 2. ../../../../libs/python/src/object/class.cpp: In function `boost::python::api::object boost::python::objects::::new_class(const char*, size_t, const boost::python::type_info*, const char*)': ../../../../libs/python/src/object/class.cpp:510: warning: comparison between signed and unsigned integer expressions 3. ../../../../libs/python/src/object/function.cpp: In member function `PyObject* boost::python::objects::function::call(PyObject*, PyObject*) const': ../../../../libs/python/src/object/function.cpp:169: warning: comparison between signed and unsigned integer expressions From Nicolas.Rougier at loria.fr Wed May 21 18:37:39 2008 From: Nicolas.Rougier at loria.fr (Nicolas Rougier) Date: Wed, 21 May 2008 18:37:39 +0200 Subject: [C++-sig] map of vectors with indexing suites Message-ID: <1211387859.6801.0.camel@oxygen> Hello, I've been using the vector_indexing_suite and the map_indexing_suite to interface a map of vector and it is almost working. My problem is when I want to iterate through the map: the type of elements is something like map_indexing_suite_MyMapClass_Entry while I would have expected a tuple of key/value. Do I do something wrong or is it the expected behavior ? What I would like to do in the end is to iterate through the map then iterate through each vector. Also, I would like to have a nice __repr__ method for the map and the vectors but I did not find how to add easily such methods (currently, I create a class that inherit the std::map only to add the repr method). Nicolas module.py ?---------------------------------------------------------------------- from _module import * u1 = Unit() u2 = Unit() u1.connect (u2, 'type1') u1.links['type1'].append (Link(u2)) u1.links['type2'] = LinkVec() print type (u1.links['type1']) print type (u1.links['type2']) for lst in u1.links: print lst, type(lst) # for l in ?? module.cc ---------------------------------------------------------------------- // g++ module.cc -I/usr/include/python2.5 -fPIC -shared -lboost_python -lpython2.5 -o _module.so #include #include #include #include #include #include #include typedef boost::shared_ptr LinkPtr; typedef boost::shared_ptr UnitPtr; typedef std::vector LinkVec; typedef boost::shared_ptr LinkVecPtr; typedef std::map LinkMap; typedef boost::shared_ptr LinkMapPtr; class Link { public: Link (UnitPtr src) : source(src) {}; virtual ~Link (void) {}; protected: UnitPtr source; }; class Unit { public: Unit (void) {}; virtual ~Unit (void) {}; void connect (UnitPtr other, std::string type) { if (not links[type]) links[type] = LinkVecPtr (new LinkVec); links[type]->push_back (LinkPtr (new Link (other))); } public: LinkMap links; }; BOOST_PYTHON_MODULE(_module) { using namespace boost::python; register_ptr_to_python (); register_ptr_to_python (); register_ptr_to_python (); register_ptr_to_python (); class_("LinkVec") .def(vector_indexing_suite ()) ; class_("LinkMap") .def(map_indexing_suite ()) ; class_ ("Unit", init<>()) .def ("connect", &Unit::connect) .def_readwrite ("links", &Unit::links) ; class_ ("Link", init()) ; } From enewhuis at gmail.com Wed May 21 20:03:04 2008 From: enewhuis at gmail.com (Eric Newhuis) Date: Wed, 21 May 2008 13:03:04 -0500 Subject: [C++-sig] Boost.Python Quickstart test failure/segfault on Boost 1.35.0 Python 2.5 on 64-bit Linux (RedHat) In-Reply-To: <483374FD.1010401@gmail.com> References: <483374FD.1010401@gmail.com> Message-ID: <483463D8.1030404@gmail.com> This appears to be a result of using Python 2.55 built from pkgsrc. I don't have this problem when I download and build Python "by hand". I'll take this up with the pkgsrc maintainers. > On my platform: Linux 2.6.9-67.0.1.ELsmp #1 SMP Fri Nov 30 11:57:43 EST > 2007 x86_64 GNU/Linux > > I verified that the boost python tests fail only when I provide a > user-config.jam file that points to a 64-bit Python 2.5. If I don?t > provide such a file then the default choices made by BJAM > result in a passing test. > > The failing line in question appears to be decrementing a reference count. > > #0 0x0000000000000000 in ?? () > #1 0x0000002a998830fc in ~object_base (this=0x7fbfffb0f0) at > ../../../../boost/python/object_core.hpp:436 > #2 0x0000002a998830c5 in ~object (this=0x7fbfffb0f0) at > ../../../../boost/python/slice_nil.hpp:16 > #3 0x0000002a99a254d1 in ~dict_base (this=0x7fbfffb0f0) at > ../../../../boost/python/dict.hpp:89 > #4 0x0000002a99a254b9 in ~dict (this=0x7fbfffb0f0) at > ../../../../libs/python/src/object/enum.cpp:139 > #5 0x0000002a99a28a6b in boost::python::objects::(anonymous > namespace)::new_class (name=0x2a9988812a "hello", num_types=1, > types=0x7fbfffb1e8, doc=0x0) From enewhuis at gmail.com Wed May 21 20:03:04 2008 From: enewhuis at gmail.com (Eric Newhuis) Date: Wed, 21 May 2008 13:03:04 -0500 Subject: [C++-sig] Boost.Python Quickstart test failure/segfault on Boost 1.35.0 Python 2.5 on 64-bit Linux (RedHat) In-Reply-To: <483374FD.1010401@gmail.com> References: <483374FD.1010401@gmail.com> Message-ID: <483463D8.1030404@gmail.com> This appears to be a result of using Python 2.55 built from pkgsrc. I don't have this problem when I download and build Python "by hand". I'll take this up with the pkgsrc maintainers. > On my platform: Linux 2.6.9-67.0.1.ELsmp #1 SMP Fri Nov 30 11:57:43 EST > 2007 x86_64 GNU/Linux > > I verified that the boost python tests fail only when I provide a > user-config.jam file that points to a 64-bit Python 2.5. If I don?t > provide such a file then the default choices made by BJAM > result in a passing test. > > The failing line in question appears to be decrementing a reference count. > > #0 0x0000000000000000 in ?? () > #1 0x0000002a998830fc in ~object_base (this=0x7fbfffb0f0) at > ../../../../boost/python/object_core.hpp:436 > #2 0x0000002a998830c5 in ~object (this=0x7fbfffb0f0) at > ../../../../boost/python/slice_nil.hpp:16 > #3 0x0000002a99a254d1 in ~dict_base (this=0x7fbfffb0f0) at > ../../../../boost/python/dict.hpp:89 > #4 0x0000002a99a254b9 in ~dict (this=0x7fbfffb0f0) at > ../../../../libs/python/src/object/enum.cpp:139 > #5 0x0000002a99a28a6b in boost::python::objects::(anonymous > namespace)::new_class (name=0x2a9988812a "hello", num_types=1, > types=0x7fbfffb1e8, doc=0x0) From rwgk at yahoo.com Thu May 22 19:40:10 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 22 May 2008 10:40:10 -0700 (PDT) Subject: [C++-sig] map of vectors with indexing suites Message-ID: <121369.28369.qm@web31105.mail.mud.yahoo.com> > Also, I would like to have a nice __repr__ method for the map and the > vectors but I did not find how to add easily such methods (currently, I > create a class that inherit the std::map only to add the repr method). You can simply .def() an unbound function implementing __repr__. The only requirement is that the first argument of the unbound function is "self". E.g. void foo(your_type const& self); class_("your_type") .def("foo", foo) ; Ralf From Nicolas.Rougier at loria.fr Thu May 22 20:51:05 2008 From: Nicolas.Rougier at loria.fr (Nicolas Rougier) Date: Thu, 22 May 2008 20:51:05 +0200 Subject: [C++-sig] map of vectors with indexing suites In-Reply-To: <121369.28369.qm@web31105.mail.mud.yahoo.com> References: <121369.28369.qm@web31105.mail.mud.yahoo.com> Message-ID: <1211482265.6098.0.camel@oxygen> Thanks, that helps a lot... Any idea on how to iterate ? Nicolas On Thu, 2008-05-22 at 10:40 -0700, Ralf W. Grosse-Kunstleve wrote: > > Also, I would like to have a nice __repr__ method for the map and the > > vectors but I did not find how to add easily such methods (currently, I > > create a class that inherit the std::map only to add the repr method). > > You can simply .def() an unbound function implementing __repr__. The only > requirement is that the first argument of the unbound function is "self". > E.g. > > void foo(your_type const& self); > > class_("your_type") > .def("foo", foo) > ; > > Ralf > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From thrabe at burnham.org Fri May 23 01:12:40 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Thu, 22 May 2008 16:12:40 -0700 Subject: [C++-sig] embedding python: PyGrammar_FindDFA error Message-ID: Hi all, I am experiencing an error with mz embedded python C program. I create an object in python, but can not retrieve it correctly. My code: PyObject *f_globals = PyModule_GetDict(mainModule); PyRun_SimpleString("a = 1"); PyObject* o = PyRun_String("a",0, f_globals, f_globals); The error: Assertion failed: (d->d_type == type), function PyGrammar_FindDFA, file Parser/grammar1.c, line 18. Python is initialised and everything. Does anybody know what this means. I assume that I do not call PyRun_String correctly. By the way, its osX Leopard, python 2.5 Does anybody have a clue? Best, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From thrabe at burnham.org Fri May 23 01:59:00 2008 From: thrabe at burnham.org (Thomas Hrabe) Date: Thu, 22 May 2008 16:59:00 -0700 Subject: [C++-sig] embedding python: PyGrammar_FindDFA error References: Message-ID: found it myself, it was a wrong flag for the second argument in PyRun_String. It has to be Py_eval_input Thanks -----Urspr?ngliche Nachricht----- Von: c++-sig-bounces+thrabe=burnham.org at python.org im Auftrag von Thomas Hrabe Gesendet: Do 22.05.2008 16:12 An: c++-sig at python.org Betreff: [C++-sig] embedding python: PyGrammar_FindDFA error Hi all, I am experiencing an error with mz embedded python C program. I create an object in python, but can not retrieve it correctly. My code: PyObject *f_globals = PyModule_GetDict(mainModule); PyRun_SimpleString("a = 1"); PyObject* o = PyRun_String("a",0, f_globals, f_globals); The error: Assertion failed: (d->d_type == type), function PyGrammar_FindDFA, file Parser/grammar1.c, line 18. Python is initialised and everything. Does anybody know what this means. I assume that I do not call PyRun_String correctly. By the way, its osX Leopard, python 2.5 Does anybody have a clue? Best, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From hohehohe2 at gmail.com Sun May 25 20:38:19 2008 From: hohehohe2 at gmail.com (hohe2 hohe) Date: Mon, 26 May 2008 03:38:19 +0900 Subject: [C++-sig] object.attr(object& attrname) proposal. Message-ID: Hello, I just wonder if my current idea has already been discussed (I searched the archive a bit but didn't find one). Curretnly object.attr() takes only string and it finally executes PyObject_GetAttrString() or PyObject_SetAttrString(). Those Python C/API call takes the most time and boost::python overhead is relatively small. It means if we can use PyObject_GetAttr() and PyObject_SetAttr() with boost::python then getting/setting attribute can become much faster, because PyObject_*Attr() is much faster than PyObject_*AttrString(). So my proposal is: If char const* is passed to objecjt.attr(), it uses PyObject_GetAttrStrng() or PyObject_SetAttrStrng(). If object is passed to objecjt.attr(), it takes the object as a Python string object and uses PyObject_GetAttr() or PyObject_SetAttr(). If attr() behaves like this, it can be useful when there are lots of objects which you know have the same attribute name. You can save time by first making a boost::python::object and passing it to every object's attr() inside a loop. I just made a bit of modification to boost:python locally and did a quick test, like test 1: for(int i = 0; i < n; ++i) { omain.attr(attrname) = 444; //attrname is a char const* } test 2: for(int i = 0; i < n; ++i) { object o = omain.attr(attrname); //attrname is a char const* } test 3: for(int i = 0; i < n; ++i) { omain.attr(oaaaa) = 444; //oaaaa is boost::python::object that represents a string } test 4: for(int i = 0; i < n; ++i) { object o = omain.attr(oaaaa); //oaaaa is boost::python::object that represents a string } and it reasonably reflected the difference between PyObject_*Attr() and PyObject_*AttrString. test 1 :2783ms test 2 :2357ms test 3 :1882ms test 4 :1267ms I'd like to know your opinions about this modification. - Koichi p.s. I made the modification for a test and it may be wrong (or even evil), but I'll write it here anyway. ----------------------------------------------------------------------------- diff -urN python/object_attributes.hpp python_p/object_attributes.hpp --- python/object_attributes.hpp 2008-03-22 17:45:00.000000000 +0900 +++ python_p/object_attributes.hpp 2008-05-25 21:58:10.000000000 +0900 @@ -17,6 +17,7 @@ { typedef char const* key_type; static object get(object const& target, char const* key); + static object get(object const& target, object const& key); }; struct attribute_policies : const_attribute_policies @@ -25,6 +26,18 @@ static void del(object const&target, char const* key); }; +struct const_objattribute_policies +{ + typedef object const key_type; + static object get(object const& target, object const& key); +}; + +struct objattribute_policies : const_objattribute_policies +{ + static object const& set(object const& target, object const& key, object const& value); + static void del(object const&target, object const& key); +}; + // // implementation // @@ -42,11 +55,30 @@ return const_object_attribute(x, name); } +template +inline object_objattribute object_operators::attr(object const& name) +{ + object_cref2 x = *static_cast(this); + return object_objattribute(x, name); +} + +template +inline const_object_objattribute object_operators::attr(object const& name) const +{ + object_cref2 x = *static_cast(this); + return const_object_objattribute(x, name); +} + inline object const_attribute_policies::get(object const& target, char const* key) { return python::getattr(target, key); } +inline object const_objattribute_policies::get(object const& target, object const& key) +{ + return python::getattr(target, key); +} + inline object const& attribute_policies::set( object const& target , char const* key @@ -56,6 +88,15 @@ return value; } +inline object const& objattribute_policies::set( + object const& target + , object const& key + , object const& value) +{ + python::setattr(target, key, value); + return value; +} + inline void attribute_policies::del( object const& target , char const* key) @@ -63,6 +104,13 @@ python::delattr(target, key); } +inline void objattribute_policies::del( + object const& target + , object const& key) +{ + python::delattr(target, key); +} + }}} // namespace boost::python::api #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP diff -urN python/object_core.hpp python_p/object_core.hpp --- python/object_core.hpp 2008-03-22 17:45:00.000000000 +0900 +++ python_p/object_core.hpp 2008-05-25 21:58:36.000000000 +0900 @@ -59,6 +59,8 @@ struct const_attribute_policies; struct attribute_policies; + struct const_objattribute_policies; + struct objattribute_policies; struct const_item_policies; struct item_policies; struct const_slice_policies; @@ -67,6 +69,8 @@ typedef proxy const_object_attribute; typedef proxy object_attribute; + typedef proxy const_object_objattribute; + typedef proxy object_objattribute; typedef proxy const_object_item; typedef proxy object_item; typedef proxy const_object_slice; @@ -108,6 +112,8 @@ // const_object_attribute attr(char const*) const; object_attribute attr(char const*); + const_object_objattribute attr(object const&) const; + object_objattribute attr(object const&); // item access // -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Sun May 25 22:10:43 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 25 May 2008 13:10:43 -0700 (PDT) Subject: [C++-sig] object.attr(object& attrname) proposal. Message-ID: <449484.81681.qm@web31108.mail.mud.yahoo.com> Hi Koichi, The patch looks OK to me. If you'd like this included in the main version, please also supply test and doc patches (probably libs/python/test/object.cpp and libs/python/doc/v2/object.html). Out of curiosity: did you also time calling PyObject_G/SetAttr() directly? How much of a difference does that make? Ralf ----- Original Message ---- From: hohe2 hohe To: c++-sig at python.org Sent: Sunday, May 25, 2008 11:38:19 AM Subject: [C++-sig] object.attr(object& attrname) proposal. Hello, I just wonder if my current idea has already been discussed (I searched the archive a bit but didn't find one). Curretnly object.attr() takes only string and it finally executes PyObject_GetAttrString() or PyObject_SetAttrString(). Those Python C/API call takes the most time and boost::python overhead is relatively small. It means if we can use PyObject_GetAttr() and PyObject_SetAttr() with boost::python then getting/setting attribute can become much faster, because PyObject_*Attr() is much faster than PyObject_*AttrString(). So my proposal is: If char const* is passed to objecjt.attr(), it uses PyObject_GetAttrStrng() or PyObject_SetAttrStrng(). If object is passed to objecjt.attr(), it takes the object as a Python string object and uses PyObject_GetAttr() or PyObject_SetAttr(). If attr() behaves like this, it can be useful when there are lots of objects which you know have the same attribute name. You can save time by first making a boost::python::object and passing it to every object's attr() inside a loop. I just made a bit of modification to boost:python locally and did a quick test, like test 1: for(int i = 0; i < n; ++i) { omain.attr(attrname) = 444; //attrname is a char const* } test 2: for(int i = 0; i < n; ++i) { object o = omain.attr(attrname); //attrname is a char const* } test 3: for(int i = 0; i < n; ++i) { omain.attr(oaaaa) = 444; //oaaaa is boost::python::object that represents a string } test 4: for(int i = 0; i < n; ++i) { object o = omain.attr(oaaaa); //oaaaa is boost::python::object that represents a string } and it reasonably reflected the difference between PyObject_*Attr() and PyObject_*AttrString. test 1 :2783ms test 2 :2357ms test 3 :1882ms test 4 :1267ms I'd like to know your opinions about this modification. - Koichi p.s. I made the modification for a test and it may be wrong (or even evil), but I'll write it here anyway. ----------------------------------------------------------------------------- diff -urN python/object_attributes.hpp python_p/object_attributes.hpp --- python/object_attributes.hpp 2008-03-22 17:45:00.000000000 +0900 +++ python_p/object_attributes.hpp 2008-05-25 21:58:10.000000000 +0900 @@ -17,6 +17,7 @@ { typedef char const* key_type; static object get(object const& target, char const* key); + static object get(object const& target, object const& key); }; struct attribute_policies : const_attribute_policies @@ -25,6 +26,18 @@ static void del(object const&target, char const* key); }; +struct const_objattribute_policies +{ + typedef object const key_type; + static object get(object const& target, object const& key); +}; + +struct objattribute_policies : const_objattribute_policies +{ + static object const& set(object const& target, object const& key, object const& value); + static void del(object const&target, object const& key); +}; + // // implementation // @@ -42,11 +55,30 @@ return const_object_attribute(x, name); } +template +inline object_objattribute object_operators::attr(object const& name) +{ + object_cref2 x = *static_cast(this); + return object_objattribute(x, name); +} + +template +inline const_object_objattribute object_operators::attr(object const& name) const +{ + object_cref2 x = *static_cast(this); + return const_object_objattribute(x, name); +} + inline object const_attribute_policies::get(object const& target, char const* key) { return python::getattr(target, key); } +inline object const_objattribute_policies::get(object const& target, object const& key) +{ + return python::getattr(target, key); +} + inline object const& attribute_policies::set( object const& target , char const* key @@ -56,6 +88,15 @@ return value; } +inline object const& objattribute_policies::set( + object const& target + , object const& key + , object const& value) +{ + python::setattr(target, key, value); + return value; +} + inline void attribute_policies::del( object const& target , char const* key) @@ -63,6 +104,13 @@ python::delattr(target, key); } +inline void objattribute_policies::del( + object const& target + , object const& key) +{ + python::delattr(target, key); +} + }}} // namespace boost::python::api #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP diff -urN python/object_core.hpp python_p/object_core.hpp --- python/object_core.hpp 2008-03-22 17:45:00.000000000 +0900 +++ python_p/object_core.hpp 2008-05-25 21:58:36.000000000 +0900 @@ -59,6 +59,8 @@ struct const_attribute_policies; struct attribute_policies; + struct const_objattribute_policies; + struct objattribute_policies; struct const_item_policies; struct item_policies; struct const_slice_policies; @@ -67,6 +69,8 @@ typedef proxy const_object_attribute; typedef proxy object_attribute; + typedef proxy const_object_objattribute; + typedef proxy object_objattribute; typedef proxy const_object_item; typedef proxy object_item; typedef proxy const_object_slice; @@ -108,6 +112,8 @@ // const_object_attribute attr(char const*) const; object_attribute attr(char const*); + const_object_objattribute attr(object const&) const; + object_objattribute attr(object const&); // item access // -------------- next part -------------- An HTML attachment was scrubbed... URL: From hohehohe2 at gmail.com Mon May 26 06:56:10 2008 From: hohehohe2 at gmail.com (hohe2 hohe) Date: Mon, 26 May 2008 13:56:10 +0900 Subject: [C++-sig] object.attr(object& attrname) proposal In-Reply-To: <449484.81681.qm@web31108.mail.mud.yahoo.com> References: <449484.81681.qm@web31108.mail.mud.yahoo.com> Message-ID: Hi Ralf, > Hi Koichi, > The patch looks OK to me. If you'd like this included in the main version, > please also supply test and doc patches (probably libs/python/test/object.cpp > and libs/python/doc/v2/object.html). Sure! I'll post it here when I've done it. > Out of curiosity: did you also time calling PyObject_G/SetAttr() directly? > How much of a difference does that make? Yes I did several other tests together with the last ones, test5: PyObject_SetAttrString(po_main, "aaaa", po_num444); test6: Py_DECREF(PyObject_GetAttrString(po_main, "aaaa")); test7: PyObject_SetAttr(po_main, po_aaaa, po_num444); test8: Py_DECREF(PyObject_GetAttr(po_main, po_aaaa)); (po_ prefixed variables are PyObject*), all inside each for loop, and the results were test 5 :2410ms test 6 :2277ms test 7 :1629ms test 8 :1094ms It's boost 1.35.0, Python 2.5 on linux(gcc4.1.2). I also did the same test on windows(vs8) and the tendency was not so different. - Koichi > Hi Koichi, > The patch looks OK to me. If you'd like this included in the main version, > please also supply test and doc patches (probably libs/python/test/object.cpp > and libs/python/doc/v2/object.html). > Out of curiosity: did you also time calling PyObject_G/SetAttr() directly? > How much of a difference does that make? > Ralf -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Mon May 26 07:53:13 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 25 May 2008 22:53:13 -0700 (PDT) Subject: [C++-sig] object.attr(object& attrname) proposal Message-ID: <181961.62964.qm@web31104.mail.mud.yahoo.com> Hi Koichi, > test 5 :2410ms > test 6 :2277ms > test 7 :1629ms > test 8 :1094ms Interesting. Thanks for sharing the timing results! Comparing tests 4 & 8, a 15% penalty for using the high-level approach isn't bad at all. When you post your patches, I'll try them out locally in our multi-platform build; if/once all is fine I'll check them into the boost trunk. Ralf From hohehohe2 at gmail.com Tue May 27 07:12:59 2008 From: hohehohe2 at gmail.com (hohe2 hohe) Date: Tue, 27 May 2008 14:12:59 +0900 Subject: [C++-sig] object.attr(object& attrname) proposa In-Reply-To: <181961.62964.qm@web31104.mail.mud.yahoo.com> References: <181961.62964.qm@web31104.mail.mud.yahoo.com> Message-ID: Hi Ralf, > When you post your patches, I'll try them out locally in our > multi-platform build; if/once all is fine I'll check them into > the boost trunk. I think I have done them. There are five files I've modified: boost/python/object_attributes.hpp boost/python/object_core.hpp same as before. libs/python/doc/v2/object.html Documentation. It may not be a natural English since I'm not a native. libs/python/test/object.cpp libs/python/test/object.py Basically I made new tests for the .attr(object&) method that is equivalent to the existing tests for attr(char const*) but I added a test to see if it surely fails when an object is not a string. I also added del() tests. If something is wrong or not natural, please feel free to fix it. -Koichi ------------------------------------------------------------------ diff -urN boost_1_35_0/boost/python/object_attributes.hpp boost_1_35_0_p/boost/python/object_attributes.hpp --- boost_1_35_0/boost/python/object_attributes.hpp 2008-03-23 06:45:55.000000000 +0900 +++ boost_1_35_0_p/boost/python/object_attributes.hpp 2008-05-27 13:44:00.000000000 +0900 @@ -17,6 +17,7 @@ { typedef char const* key_type; static object get(object const& target, char const* key); + static object get(object const& target, object const& key); }; struct attribute_policies : const_attribute_policies @@ -25,6 +26,18 @@ static void del(object const&target, char const* key); }; +struct const_objattribute_policies +{ + typedef object const key_type; + static object get(object const& target, object const& key); +}; + +struct objattribute_policies : const_objattribute_policies +{ + static object const& set(object const& target, object const& key, object const& value); + static void del(object const&target, object const& key); +}; + // // implementation // @@ -42,11 +55,30 @@ return const_object_attribute(x, name); } +template +inline object_objattribute object_operators::attr(object const& name) +{ + object_cref2 x = *static_cast(this); + return object_objattribute(x, name); +} + +template +inline const_object_objattribute object_operators::attr(object const& name) const +{ + object_cref2 x = *static_cast(this); + return const_object_objattribute(x, name); +} + inline object const_attribute_policies::get(object const& target, char const* key) { return python::getattr(target, key); } +inline object const_objattribute_policies::get(object const& target, object const& key) +{ + return python::getattr(target, key); +} + inline object const& attribute_policies::set( object const& target , char const* key @@ -56,6 +88,15 @@ return value; } +inline object const& objattribute_policies::set( + object const& target + , object const& key + , object const& value) +{ + python::setattr(target, key, value); + return value; +} + inline void attribute_policies::del( object const& target , char const* key) @@ -63,6 +104,13 @@ python::delattr(target, key); } +inline void objattribute_policies::del( + object const& target + , object const& key) +{ + python::delattr(target, key); +} + }}} // namespace boost::python::api #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP diff -urN boost_1_35_0/boost/python/object_core.hpp boost_1_35_0_p/boost/python/object_core.hpp --- boost_1_35_0/boost/python/object_core.hpp 2008-03-23 06:45:55.000000000 +0900 +++ boost_1_35_0_p/boost/python/object_core.hpp 2008-05-27 13:44:00.000000000 +0900 @@ -59,6 +59,8 @@ struct const_attribute_policies; struct attribute_policies; + struct const_objattribute_policies; + struct objattribute_policies; struct const_item_policies; struct item_policies; struct const_slice_policies; @@ -67,6 +69,8 @@ typedef proxy const_object_attribute; typedef proxy object_attribute; + typedef proxy const_object_objattribute; + typedef proxy object_objattribute; typedef proxy const_object_item; typedef proxy object_item; typedef proxy const_object_slice; @@ -108,6 +112,8 @@ // const_object_attribute attr(char const*) const; object_attribute attr(char const*); + const_object_objattribute attr(object const&) const; + object_objattribute attr(object const&); // item access // diff -urN boost_1_35_0/libs/python/doc/v2/object.html boost_1_35_0_p/libs/python/doc/v2/object.html --- boost_1_35_0/libs/python/doc/v2/object.html 2008-02-11 01:39:38.000000000 +0900 +++ boost_1_35_0_p/libs/python/doc/v2/object.html 2008-05-27 13:47:23.000000000 +0900 @@ -74,6 +74,32 @@ + + +
+
+
Class + const_objattribute_policies synopsis
+ +
Class + const_objattribute_policies static functions
+
+
+ +
Class + objattribute_policies
+ +
+
+
Class + objattribute_policies synopsis
+ +
Class + objattribute_policies static functions
+
+
+
Class const_item_policies
@@ -328,6 +354,102 @@ +

Class + const_objattribute_policies

+ +

The policies which are used for proxies representing an attribute + access to a const object when the attribute name is + given as a const object.

+ +

Class + const_objattribute_policies synopsis

+
+namespace boost { namespace python { namespace api
+{
+  struct const_objattribute_policies
+  {
+      typedef object const& key_type;
+      static object get(object const& target, object const& key);
+  };
+}}}
+
+ +

Class + const_objattribute_policies static functions

+
+static object get(object const& target, object const& key);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: accesses the attribute of target named + by key.
+ +
Returns: An object managing the result of the + attribute access.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+ +

Class + objattribute_policies

+ +

The policies which are used for proxies representing an attribute + access to a mutable object when the attribute name is + given as a const object.

+ +

Class + objattribute_policies synopsis

+
+namespace boost { namespace python { namespace api
+{
+  struct objattribute_policies : const_objattribute_policies
+  {
+      static object const& set(object const& target, object const&
key, object const& value);
+      static void del(object const&target, object const& key);
+  };
+}}}
+
+ +

Class + objattribute_policies static functions

+
+static object const& set(object const& target, object const& key,
object const& value);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: sets the attribute of target named by + key to value.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+
+static void del(object const&target, object const& key);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: deletes the attribute of target named + by key.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+ + +

Class const_item_policies

@@ -542,6 +664,8 @@ // proxy<const_object_attribute> attr(char const*) const; proxy<object_attribute> attr(char const*); + proxy<const_object_objattribute> attr(object const&) const; + proxy<object_objattribute> attr(object const&); // item access // @@ -608,6 +732,21 @@ name as its key.
+proxy<const_object_objattribute> attr(const object& name) const;
+proxy<object_objattribute> attr(const object& name);
+
+ +
+
Requires: name is a object holding a string.
+ +
Effects: accesses the named attribute of + *this.
+ +
Returns: a proxy object which binds + object(*static_cast<U*>(this)) as its target, and + name as its key.
+
+
 template <class T>
 proxy<const_object_item> operator[](T const& key) const;
 template <class T>
diff -urN boost_1_35_0/libs/python/test/object.cpp
boost_1_35_0_p/libs/python/test/object.cpp
--- boost_1_35_0/libs/python/test/object.cpp    2008-03-23
06:45:55.000000000 +0900
+++ boost_1_35_0_p/libs/python/test/object.cpp    2008-05-27
13:46:35.000000000 +0900
@@ -38,26 +38,61 @@
     return x.attr(name);
 }

+object obj_objgetattr(object x, object const& name)
+{
+    return x.attr(name);
+}
+
 object obj_const_getattr(object const& x, char const* name)
 {
     return x.attr(name);
 }

+object obj_const_objgetattr(object const& x, object const& name)
+{
+    return x.attr(name);
+}
+
 void obj_setattr(object x, char const* name, object value)
 {
     x.attr(name) = value;
 }

+void obj_objsetattr(object x, object const& name, object value)
+{
+    x.attr(name) = value;
+}
+
 void obj_setattr42(object x, char const* name)
 {
     x.attr(name) = 42;
 }

+void obj_objsetattr42(object x, object const& name)
+{
+    x.attr(name) = 42;
+}
+
 void obj_moveattr(object& x, char const* src, char const* dst)
 {
     x.attr(dst) = x.attr(src);
 }

+void obj_objmoveattr(object& x, object const& src, object const& dst)
+{
+    x.attr(dst) = x.attr(src);
+}
+
+void obj_delattr(object x, char const* name)
+{
+    x.attr(name).del();
+}
+
+void obj_objdelattr(object x, object const& name)
+{
+    x.attr(name).del();
+}
+
 object obj_getitem(object x, object key)
 {
     return x[key];
@@ -108,11 +143,21 @@
     return y.attr(name);
 }

+bool test_objattr(object y, object& name)
+{
+    return y.attr(name);
+}
+
 bool test_not_attr(object y, char* name)
 {
     return !y.attr(name);
 }

+bool test_not_objattr(object y, object& name)
+{
+    return !y.attr(name);
+}
+
 bool test_item(object y, object key)
 {
     return y[key];
@@ -301,11 +346,17 @@
     def("number", number);

     def("obj_getattr", obj_getattr);
+    def("obj_objgetattr", obj_objgetattr);
     def("obj_const_getattr", obj_const_getattr);
+    def("obj_const_objgetattr", obj_const_objgetattr);
     def("obj_setattr", obj_setattr);
+    def("obj_objsetattr", obj_objsetattr);
     def("obj_setattr42", obj_setattr42);
+    def("obj_objsetattr42", obj_objsetattr42);
     def("obj_moveattr", obj_moveattr);
-
+    def("obj_objmoveattr", obj_objmoveattr);
+    def("obj_delattr", obj_delattr);
+    def("obj_objdelattr", obj_objdelattr);

     def("obj_getitem", obj_getitem);
     def("obj_getitem3", obj_getitem);
@@ -319,7 +370,9 @@
     def("test_not", test_not);

     def("test_attr", test_attr);
+    def("test_objattr", test_objattr);
     def("test_not_attr", test_not_attr);
+    def("test_not_objattr", test_not_objattr);

     def("test_item", test_item);
     def("test_not_item", test_not_item);
diff -urN boost_1_35_0/libs/python/test/object.py
boost_1_35_0_p/libs/python/test/object.py
--- boost_1_35_0/libs/python/test/object.py    2004-08-11 01:14:51.000000000
+0900
+++ boost_1_35_0_p/libs/python/test/object.py    2008-05-27
13:46:40.000000000 +0900
@@ -34,29 +34,68 @@
 >>> try: obj_getattr(x, 'foo')
 ... except AttributeError: pass
 ... else: print 'expected an exception'
+>>> try: obj_objgetattr(x, 'objfoo')
+... except AttributeError: pass
+... else: print 'expected an exception'

 >>> obj_setattr(x, 'foo', 1)
 >>> x.foo
 1
+>>> obj_objsetattr(x, 'objfoo', 1)
+>>> try:obj_objsetattr(x, 1)
+... except TypeError: pass
+... else: print 'expected an exception'
+>>> x.objfoo
+1
 >>> obj_getattr(x, 'foo')
 1
+>>> obj_objgetattr(x, 'objfoo')
+1
+>>> try:obj_objgetattr(x, 1)
+... except TypeError: pass
+... else: print 'expected an exception'
 >>> obj_const_getattr(x, 'foo')
 1
+>>> obj_const_objgetattr(x, 'objfoo')
+1
 >>> obj_setattr42(x, 'foo')
 >>> x.foo
 42
+>>> obj_objsetattr42(x, 'objfoo')
+>>> x.objfoo
+42
 >>> obj_moveattr(x, 'foo', 'bar')
 >>> x.bar
 42
+>>> obj_objmoveattr(x, 'objfoo', 'objbar')
+>>> x.objbar
+42
 >>> test_attr(x, 'foo')
 1
+>>> test_objattr(x, 'objfoo')
+1
 >>> test_not_attr(x, 'foo')
 0
+>>> test_not_objattr(x, 'objfoo')
+0
 >>> x.foo = None
 >>> test_attr(x, 'foo')
 0
+>>> x.objfoo = None
+>>> test_objattr(x, 'objfoo')
+0
 >>> test_not_attr(x, 'foo')
 1
+>>> test_not_objattr(x, 'objfoo')
+1
+>>> obj_delattr(x, 'foo')
+>>> obj_objdelattr(x, 'objfoo')
+>>> try:obj_delattr(x, 'foo')
+... except AttributeError: pass
+... else: print 'expected an exception'
+>>> try:obj_objdelattr(x, 'objfoo')
+... except AttributeError: pass
+... else: print 'expected an exception'

         Items
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From diepen at astron.nl  Tue May 27 09:20:22 2008
From: diepen at astron.nl (Ger van Diepen)
Date: Tue, 27 May 2008 09:20:22 +0200
Subject: [C++-sig] boost.python and numpy.int32 on 64-bit system
In-Reply-To: <200804170852.05670.lists@informa.tiker.net>
References: <48072501020000A900004448@server7.nfra.nl>
	<200804170852.05670.lists@informa.tiker.net>
Message-ID: <483BD243.6086.00A9.0@astron.nl>

I've solved the boost.python / numpy issue by writing special converters for numpy array scalars. The PyUBlas converters of Andreas gave good insight how to do it (I couldn't use them because they are too strongly typed). 
It handles all conversions needed, so e.g. a numpy.int16 can be converted to an int or float.
It also handles numpy array scalars contained in sequences.
It works fine on 32-bit and 64-bit systems.

In the process I found a little problem in implicit.hpp about which I'll report in a separate message.

Ger




From diepen at astron.nl  Tue May 27 09:47:53 2008
From: diepen at astron.nl (Ger van Diepen)
Date: Tue, 27 May 2008 09:47:53 +0200
Subject: [C++-sig] Little problem in Boost.Python implicit.hpp
Message-ID: <483BD8B6.6086.00A9.0@astron.nl>

During my work to handle numpy array scalars correctly, I stumbled on a little problem in implicit.hpp making it impossible to use the implicitly_convertible class.

I have a class ValueHolder which is a kind of any class. It can hold values of the basic types and is convertible to types like double and DComplex (a typedef for std::complex).
Now I wanted to use
    boost::python::implicitly_convertible();
but the compiler gave errors like:

/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp: In static member function 'static void boost::python::converter::implicit::construct(PyObject*, boost::python::converter::rvalue_from_python_stage1_data*) [with Source = casa::ValueHolder, Target = casa::DComplex]':
/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/implicit.hpp:21:   instantiated from 'void boost::python::implicitly_convertible(boost::type*, boost::type*) [with Source = casa::ValueHolder, Target = casa::DComplex]'
pyrap/Converters/PycArrayNP.cc:168:   instantiated from here
/Users/diepen/conrad/svnConrad/3rdparty/boost/tags/boost-1.34.1/include/boost/python/converter/implicit.hpp:37: error: call of overloaded 'complex(casa::ValueHolder&)' is ambiguous
/usr/include/c++/4.0.0/complex:1470: note: candidates are: std::complex::complex(const std::complex&)
/usr/include/c++/4.0.0/complex:1213: note:                 std::complex::complex(double, double)
/usr/include/c++/4.0.0/complex:1155: note:                 std::complex::complex(const std::complex&)
scons: *** [build_darwin_i386/opt/Converters/PycArrayNP.os] Error 1
scons: building terminated because of errors.

The problem is the line
        new (storage) Target(get_source());
in implicit.hpp. 
However, It compiles fine when changing it to:
        Target tgt = get_source();
        new (storage) Target(tgt);
It might be better to use the default constructor and assign thereafter.

Maybe such a change needs to be made in the Boost.Python code. It will require, however, that the template parameter has a default ctor and assignment operator.

Cheers,
Ger



From michael.wieher at gmail.com  Tue May 27 19:17:30 2008
From: michael.wieher at gmail.com (Michael Wieher)
Date: Tue, 27 May 2008 12:17:30 -0500
Subject: [C++-sig] Incref / Decref Question
Message-ID: 

OK.  Same problem for the last week.  Not boost-related but rather
Python Extension / C C++ fundamental issue.
Please tell me if this looks OK or if its terribly, terribly stupid.

mainfile.cpp
----------------------------------------------------------------------------------
myClass instanceOfMyClass;               //----global data structure,
accessible to all functions

PyObject * function() {
    modifies, initliaizes, mallocs, etc. "instanceOfMyClass"
}

---------------------------------------------------------------------------------

That is the entire program.

It executes fine, if I call it from within python.py script, but if I
load the library.so into python interpreter >>> on exit, the
interpreter seg-faults.
Python 2.4.3 (#1, Mar 14 2007, 18:51:08)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymem
>>> pymem.initData()
0
>>>
Segmentation fault

(checking log-files I can be sure that all functionality is OK, and it
is executing correctly)

this is being run on a CentOS platform.
on Ubuntu, there is no seg-fault, and all else  is the same.

However, when Valgrind reviews the library (on both CentOS and Ubuntu)
I get the same message:
$>valgrind ./pymem.so
==5844== Process terminating with default action of signal 11 (SIGSEGV)
==5844==  Bad permissions for mapped region at address 0x38156080
==5844==    at 0x1: (within /home/michael/proj/pydata/src/pymem.so)

Now, I see this as a memory-address issue, which seems ridiculous to
me, since the library.so is compiled with -fPIC, thus removing it from
conflicting memory issues.

So, my logical conclusion is that somehow, when this global-instance
is modified, a reference-count is either incremented or decremented
incorrectly, and that when the python interpreter exits, it seg-faults
because it is either trying to clean up something that does not exist,
or thinking something doesn't exist when it does.

Any tips or ideas how to further debug this?


From rwgk at yahoo.com  Tue May 27 20:36:48 2008
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Tue, 27 May 2008 11:36:48 -0700 (PDT)
Subject: [C++-sig] object.attr(object& attrname) proposa
Message-ID: <822911.23682.qm@web31107.mail.mud.yahoo.com>

Hi Koichi,
I got the patches, thanks!
The doc changes look good to me. I'll only change the revision and
copyright date. I manually tested compilation with gcc 4.1 and EDG 245.
It will take a day to try them in our local multi-platform build system.
Ralf


From rwgk at yahoo.com  Thu May 29 21:50:35 2008
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Thu, 29 May 2008 12:50:35 -0700 (PDT)
Subject: [C++-sig] object.attr(object& attrname) proposa
Message-ID: <505118.42071.qm@web31106.mail.mud.yahoo.com>

Hi Koichi,
I've checked in your patches to the boost svn trunk, revision 45918.
Ralf

----- Original Message ----
From: Ralf W. Grosse-Kunstleve 
To: Development of Python/C++ integration 
Sent: Tuesday, May 27, 2008 11:36:48 AM
Subject: Re: [C++-sig] object.attr(object& attrname) proposa

Hi Koichi,
I got the patches, thanks!
The doc changes look good to me. I'll only change the revision and
copyright date. I manually tested compilation with gcc 4.1 and EDG 245.
It will take a day to try them in our local multi-platform build system.
Ralf


From rwgk at yahoo.com  Thu May 29 22:06:15 2008
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Thu, 29 May 2008 13:06:15 -0700 (PDT)
Subject: [C++-sig] projects using boost::python
Message-ID: <810668.22596.qm@web31101.mail.mud.yahoo.com>

I've checked this in to the boost svn trunk (revision 45920).
Thanks for the contribution! Sorry it took so long to get to this.
Ralf

----- Original Message ----
From: Michael Brickenstein 
To: c++-sig at python.org
Cc: Alexander Dreyer 
Sent: Sunday, April 20, 2008 11:25:26 PM
Subject: [C++-sig] projects using boost::python

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


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig



From amaignan at gmail.com  Fri May 30 16:08:34 2008
From: amaignan at gmail.com (=?ISO-8859-1?Q?Aur=E9lien_MAIGNAN?=)
Date: Fri, 30 May 2008 16:08:34 +0200
Subject: [C++-sig] Boost.Python hello tutorial issue ?
Message-ID: <2131ea990805300708r679ef5afma23d35c90f85f436@mail.gmail.com>

Hi
I have just started to see wrapping C++/Python and choose to use
boost.Python libs and further Py++ once mastered boost.Python.

So I read their tutorial introduction :
http://www.boost.org/doc/libs/1_35_0/libs/python/doc/tutorial/doc/html/index.html

Ok so i install Boost and choose Python lib at setup and msvc 8.0 as
compiler. (got 2005 express version).
Boost has been installed in this abs path : C:\Program
Files\boost\boost_1_35_0

Then i build the BJam tools usign the .bat isued with the Boost.Python
package.
I add the path in PATH Env Var.

Next and prior to use the bjam command in the tutorial directory (where
hello.cpp, hello.py and Jamroot files are)
i modified the user-config.jam file according to the tutorial :
This file is located in : C:\Program Files\boost\boost_1_35_0\tools\build\v2
here is  the modifications :

i added this :
#  Configure msvc (default version, searched in standard location
#  and PATH).
  using msvc : 8.0 ;

and this :
#  Python configuration
using python : 2.5 : C:/Python25 ;

the rest of the file hasn't change at all.

I doesn't touch the Jamroot file either

( **** note you can ignore the following it is another minor issue : ****

ok it is not totally right : i wish to change the default use-project rule
from :
use-project boost
  : ../../../.. ;   => default one
to
use-project boost
  : "$(BOOST_ROOT)  ;

where BOOST_ROOT is a user Env Var which store the path : C:\Program
Files\boost\boost_1_35_0

But that doesn't build using bjam command : the following error happend :
*** argument error
* rule use-project ( id : where )
* called with: ( boost :  )
* missing argument where

so finally i changed it to

use-project boost
  : "C:/Program Files/boost/boost_1_35_0" ;

but i would rather use the Env Var if possible

 **** end of the minor issue description **** )

so ok I launched bjam and after a while it finnished building the lib files,
and make me use the param *--preserve-test-targets* to bjam as indicated in
the tutorial for the 1.35 version.

 --> But the problem is that usign hello.py doesn't work due to the fact the
library weren't found by python.

Indeed the libs are generated in this paths :
C:\Program
Files\boost\boost_1_35_0\bin.v2\libs\python\build\msvc-8.0\debug\threading-multi\boost_python-vc80-mt-gd-1_35.dll
and :
C:\Program
Files\boost\boost_1_35_0\libs\python\example\tutorial\bin\msvc-8.0\debug\threading-multi\hello_ext.exp
C:\Program
Files\boost\boost_1_35_0\libs\python\example\tutorial\bin\msvc-8.0\debug\threading-multi\hello_ext.pyd
C:\Program
Files\boost\boost_1_35_0\libs\python\example\tutorial\bin\msvc-8.0\debug\threading-multi\hello_ext.lib

There is no way Python are aware of this new Libs !
Maybe i wrong but i though that bjam automated the creation of the library
for python and put the files where they need to be,
A clue of this is the fact that we needed to add :
#  Python configuration
using python : 2.5 : C:/Python25 ;
in the user-config.jam file, so i guessed that bjam would create
automatically the directory of the new module and put the libs there.

In order to make it work i had to copying the hello_ext.lib file to the
Python lib directory : C:\Python25\libs

and i had to create manually this directory :
C:\Python25\Lib\site-packages\hello_ext
In this directory I copied our libs files :
hello_ext.exp
hello_ext.pyd
boost_python-vc80-mt-gd-1_35.dll
And create also another file : __init__.py that contain the following :

import sys

sys.path.append('..\..')

# this brings in the DLL (pyd)
from hello_ext import *

And after this the new module was known from python and
hello.py work !
to sum up : does bjam automatically generate the module directory and plant
in the lib needed (and the __init__.py file) as I though it was
Or does i need to do this manually (and create another script/make like file
to automatize this) ?


Note 1 : this not my idea, in order to resolve my issue i found this on the
web wich is a similar case :
http://mail.python.org/pipermail/c++-sig/2007-November/013059.html
/Note 1


Note 2 : in this thread one advise to modified the Jamroot file and add this
:

# Declare a Python extension
python-extension _**name of ext goes here** # Declare a Python extension
  : **name of CPP with wrapper class(es) goes here**    # Source
  : **your includes go here**
    **your defines go here**
  : **your lib path goes
here**$(BOOST_ROOT)/stage/lib
  ;

so i putted this :

# Declare a Python extension
python-extension hello_ext # Declare a Python extension
  : hello.cpp    # Source
  #: **your includes go here**
  #  **your defines go here**
  #: **your lib path goes here**
  $(BOOST_ROOT)/stage/lib
  ;

But bjam doesn't work anymore (some error that imply some core .jam file
that is not from me) so I removed this and return to the the default vesion
:
# Declare the three extension modules.  You can specify multiple
# source files after the colon separated by spaces.
python-extension hello_ext : hello.cpp ;
/Note 2


THANKs for considering this post, a little long ^^ and excuse my english ;)

MAIGNAN Aur?lien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

Class + const_objattribute_policies