From vishal.bayskar at nechclst.in Tue Jun 1 11:01:44 2010 From: vishal.bayskar at nechclst.in (vishal bayskar) Date: Tue, 1 Jun 2010 02:01:44 -0700 (PDT) Subject: [C++-sig] How to search constructors with namespace Message-ID: <28739257.post@talk.nabble.com> a.h === #ifndef _INEX_A__ #define _INEX_A__ #include "b.h" namespace parent{ namespace child{ class A{ public: A(int const &); A(int, int); A(B const &); int getA(int); }; }; }; #endif b.h === #ifndef _INEX_B__ #define _INEX_B__ namespace parent{ namespace child{ class B{ public: int getB(int); }; }; }; #endif export.py ======= import os import pygccxml from pyplusplus import module_builder mb=module_builder.module_builder_t(["/usr/vbayskar/a.h"]) cons = mb.constructors('A', arg_types=[None]) for con in cons: print con mb.build_code_creator(module_name = 'testModule') mb.write_module('testModule.cpp') Output for print statement (used in the above export.py file) ================== parent::child::A::A(parent::child::A const & arg0) [copy constructor] parent::child::A::A(int const & arg0) [constructor] parent::child::A::A(parent::child::B const & arg0) [constructor] My question is how do I search for the constructor parent::child::A::A(parent::child::B const & arg0) [constructor] What arg_types should I provide ? I have tried with and without namespaces like cons = mb.constructors('A', arg_types=['parent::child::B const &']) cons = mb.constructors('A', arg_types=['child::B const &']) cons = mb.constructors('A', arg_types=['B const &']) But every time it is giving an error raise RuntimeError( "Multi declaration query returned 0 declarations." ) I don't know what bits I am missing please suggest. -- View this message in context: http://old.nabble.com/How-to-search-constructors-with-namespace-tp28739257p28739257.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From vishal.bayskar at nechclst.in Tue Jun 1 12:19:39 2010 From: vishal.bayskar at nechclst.in (vishal bayskar) Date: Tue, 1 Jun 2010 03:19:39 -0700 (PDT) Subject: [C++-sig] How to search constructors with namespace In-Reply-To: <28739257.post@talk.nabble.com> References: <28739257.post@talk.nabble.com> Message-ID: <28739908.post@talk.nabble.com> >how do I search for the constructor >parent::child::A::A(parent::child::B const & arg0) [constructor] >What arg_types should I provide ? >I have tried with and without namespaces like >cons = mb.constructors('A', arg_types=['parent::child::B const &']) >cons = mb.constructors('A', arg_types=['child::B const &']) >cons = mb.constructors('A', arg_types=['B const &']) >But every time it is giving an error >raise RuntimeError( "Multi declaration query returned 0 declarations." ) >I don't know what bits I am missing please suggest. Now I have used cons = mb.constructors('A', arg_types=['::parent::child::B const &']) and it is working fine. Thanks can someone, please let me know the reason why :: (scope operator) is required in the start of the argument. -- View this message in context: http://old.nabble.com/How-to-search-constructors-with-namespace-tp28739257p28739908.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From roman.yakovenko at gmail.com Tue Jun 1 13:02:52 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Jun 2010 14:02:52 +0300 Subject: [C++-sig] How to search constructors with namespace In-Reply-To: <28739908.post@talk.nabble.com> References: <28739257.post@talk.nabble.com> <28739908.post@talk.nabble.com> Message-ID: On Tue, Jun 1, 2010 at 1:19 PM, vishal bayskar wrote: >>how do I search for the constructor >>parent::child::A::A(parent::child::B const & arg0) [constructor] > >>What arg_types should I provide ? > >>I have tried with and without namespaces like >>cons = mb.constructors('A', arg_types=['parent::child::B const &']) >>cons = mb.constructors('A', arg_types=['child::B const &']) >>cons = mb.constructors('A', arg_types=['B const &']) > >>But every time it is giving an error >>raise RuntimeError( "Multi declaration query returned 0 declarations." ) > >>I don't know what bits I am missing please suggest. > > Now I have used > cons = mb.constructors('A', arg_types=['::parent::child::B const &']) > and it is working fine. > > Thanks can someone, please let me know the reason why :: (scope operator) is > required in the start of the argument. I tried really hard to make this functionality more "user friendly", but failed. Take a look on http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pygccxml_dev/pygccxml/declarations/matchers.py?revision=1713&view=markup file, declaration_matcher_t class. I'll be glad, if you will improve the functionality. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From vishal.bayskar at nechclst.in Tue Jun 1 15:50:45 2010 From: vishal.bayskar at nechclst.in (vishal bayskar) Date: Tue, 1 Jun 2010 06:50:45 -0700 (PDT) Subject: [C++-sig] find out dependency from public part only Message-ID: <28742003.post@talk.nabble.com> Is there any function available in pyplusplus to findout the dependencies of some declaration from public part only? I searched but I didn't find any such functionality For example in below file (afile.h) if I find out dependency for class A it should not give class C as it is in the private part. afile.h ==== class C{ int getC(); }; class A{ public: A(int const &); int getA(int); private: A(C const &); C getC(); }; -- View this message in context: http://old.nabble.com/find-out-dependency-from-public-part-only-tp28742003p28742003.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From tinauser at libero.it Wed Jun 2 18:09:28 2010 From: tinauser at libero.it (tino) Date: Wed, 2 Jun 2010 16:09:28 +0000 (UTC) Subject: [C++-sig] using PyArray to pass pointer Message-ID: Hallo, I'm pretty new with both Python and C I have a C application that run a python script.The python script then uses some C functions written in the code that embedd the script itself. I want to pass array from the C code (where an API is giving pointer to data I want to plot in Python) and Python (a GUI). What I've done so far is to allocate before calling the Pyhon script a PyArray with PyArray_SimpleNew. Since the data are unsigned char, the command is: my_second_array = (PyArrayObject *)PyArray_SimpleNew(2,dim,NPY_UBYTE); When I call the Python script,I sent my_second_array.On a timer, my_second_array is used as a parameter for a C written function: the idea is to assign the pointer of a frame to my_second_array.data. PyArrayObject *Pymatout_img=NULL; PyArg_ParseTuple(args, "O", &Pymatout_img);//Pymatout_img is the matrix that was created in C during the initialization with PyArray_SimpleNew Pymatout_img->data= cam_frame->data; The problem is that the compiler (I'm using visual C 2008) says that cannot convert *char to *unsigned char... Can someone explains me what i'm doing wrong? From charlessolar at gmail.com Thu Jun 3 16:57:58 2010 From: charlessolar at gmail.com (Charles Solar) Date: Thu, 3 Jun 2010 09:57:58 -0500 Subject: [C++-sig] Boost exception on Solaris AMD64 when importing Message-ID: I am getting a boost exception when I try to import my project linked with boost python. It occurs in the python _init method so I am pretty sure it has something to do with boost python. I get this exception: terminate called after throwing an instance of 'boost::exception_detail::clone_impl' only on Solaris AMD64. I have tried on two such machines and got the same result. I should also mention that it is compiled with gcc and gnu binutils, NOT the sun compiler. I am wondering if anyone else is using boost python + solaris amd64 and may know what is going on. Here is the backtrace from gdb: #0 0xfffffd7fff09cb8a in _lwp_kill () from /lib/64/libc.so.1 #1 0xfffffd7fff095483 in thr_kill () from /lib/64/libc.so.1 #2 0xfffffd7fff041dc9 in raise () from /lib/64/libc.so.1 #3 0xfffffd7fff021340 in abort () from /lib/64/libc.so.1 #4 0xfffffd7ffc8c0d79 in __gnu_cxx::__verbose_terminate_handler () at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/vterminate.cc:48 #5 0xfffffd7ffc8be12a in __cxxabiv1::__terminate (handler=) at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:39 #6 0xfffffd7ffc8be183 in std::terminate () at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:49 #7 0xfffffd7ffc8be2fe in __cxa_rethrow () at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_throw.cc:116 #8 0xfffffd7ffc8c0d34 in __gnu_cxx::__verbose_terminate_handler () at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/vterminate.cc:78 #9 0xfffffd7ffc8be12a in __cxxabiv1::__terminate (handler=) at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:39 #10 0xfffffd7ffc8be183 in std::terminate () at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:49 #11 0xfffffd7ffc8be2a6 in __cxa_throw (obj=, tinfo=, dest=) at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_throw.cc:83 #12 0xfffffd7ffd9dbe7c in boost::copy_exception (e=...) at /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:42 #13 0xfffffd7ffd9dbfbf in boost::exception_detail::get_bad_alloc<42> () at /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:80 #14 0xfffffd7ffdb259ac in __static_initialization_and_destruction_0 () at /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:94 #15 global constructors keyed to Attributes.cpp () at Foobar/src/Attributes.cpp:219 #16 0xfffffd7ffdb25a76 in __do_global_ctors_aux () from /home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so #17 0xfffffd7ffd9ba1de in _init () from /home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so #18 0xfffffd7fff3ce0ba in call_init () from /lib/amd64/ld.so.1 #19 0xfffffd7fff3ce68d in load_completion () from /lib/amd64/ld.so.1 #20 0xfffffd7fff3d2fd9 in dlmopen_intn () from /lib/amd64/ld.so.1 #21 0xfffffd7fff3d312c in dlmopen_check () from /lib/amd64/ld.so.1 #22 0xfffffd7fff3d31f9 in dlopen () from /lib/amd64/ld.so.1 #23 0xfffffd7ffef2b67c in _PyImport_GetDynLoadFunc (fqname=, shortname=, pathname=0xfffffd7fffdfeb50 "/home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so", fp=0xfffffd7fff10b320) at Python/dynload_shlib.c:130 #24 0xfffffd7ffef103f1 in _PyImport_LoadDynamicModule (name=0xfffffd7fffdff040 "LbmCom", pathname=0xfffffd7fffdfeb50 "/home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so", fp=0xfffffd7fff10b320) at ./Python/importdl.c:42 #25 0xfffffd7ffef0e557 in import_submodule (mod=0xfffffd7fff1a5630, subname=0xfffffd7fffdff040 "Foobar", fullname=0xfffffd7fffdff040 "Foobar") at Python/import.c:2595 #26 0xfffffd7ffef0e80e in load_next (mod=0xfffffd7fff1a5630, altmod=0xfffffd7fff1a5630, p_name=, buf=0xfffffd7fffdff040 "Foobar", p_buflen=0xfffffd7fffdff450) at Python/import.c:2415 #27 0xfffffd7ffef0ee32 in import_module_level (name=, globals=, fromlist=, level=, name=, globals=, fromlist=, level=) at Python/import.c:2137 #28 0xfffffd7ffef0f41a in PyImport_ImportModuleLevel (name=0x7cd8f4 "Foobar", globals=0x6c7340, locals=, fromlist=0xfffffd7fff1a5630, level=-1) at Python/import.c:2188 #29 0xfffffd7ffeeedcd9 in builtin___import__ (self=, args=, kwds=) at Python/bltinmodule.c:49 -------------- next part -------------- An HTML attachment was scrubbed... URL: From wangx0802 at yahoo.com Thu Jun 3 18:35:27 2010 From: wangx0802 at yahoo.com (X Wang) Date: Thu, 3 Jun 2010 09:35:27 -0700 (PDT) Subject: [C++-sig] How to expose to a python user defined type with to/from_python convertors? In-Reply-To: Message-ID: <574907.97144.qm@web112612.mail.gq1.yahoo.com> --- On Tue, 5/25/10, Michele De Stefano wrote: > From: Michele De Stefano > Subject: Re: [C++-sig] How to expose to a python user defined type with to/from_python convertors? > To: "Development of Python/C++ integration" > Date: Tuesday, May 25, 2010, 10:52 AM > There's a very good tutorial on > writing from/to python converters. > This tutorial was suggested to me by one of the members of > this > mailing list and I've found it very useful. > > The link is this one: > http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ > > After reading this very useful article, I managed to write > my > mds-utils library (the link is at the end of this e-mail) > which you > can download to see how you can write a from/to python > converter. > > Bye. > Michele > It worked! Sorry for the late reply, I was tied up with a few other things... I just tested a bit and everything works now. I miseed the part where you need to import python type definitions into the C++ environment and somehow thought I could just add attributes on the fly. Thanks a lot! From charlessolar at gmail.com Fri Jun 4 20:50:06 2010 From: charlessolar at gmail.com (Charles Solar) Date: Fri, 4 Jun 2010 13:50:06 -0500 Subject: [C++-sig] Boost exception on Solaris AMD64 when importing In-Reply-To: References: Message-ID: I figured out that it was actually a bug in boost v1.43 apparently. I found this thread http://old.nabble.com/Boost-1.43---Exception-before-main%28%29-is-called-td28536505.html which led me to install the trunk version of boost and the problem went away. Posting this for any googler's out there. :) On Thu, Jun 3, 2010 at 9:57 AM, Charles Solar wrote: > I am getting a boost exception when I try to import my project linked with > boost python. It occurs in the python _init method so I am pretty sure it > has something to do with boost python. I get this exception: > > terminate called after throwing an instance of > 'boost::exception_detail::clone_impl' > > only on Solaris AMD64. I have tried on two such machines and got the same > result. I should also mention that it is compiled with gcc and gnu > binutils, NOT the sun compiler. > > I am wondering if anyone else is using boost python + solaris amd64 and may > know what is going on. Here is the backtrace from gdb: > > #0 0xfffffd7fff09cb8a in _lwp_kill () from /lib/64/libc.so.1 > #1 0xfffffd7fff095483 in thr_kill () from /lib/64/libc.so.1 > #2 0xfffffd7fff041dc9 in raise () from /lib/64/libc.so.1 > #3 0xfffffd7fff021340 in abort () from /lib/64/libc.so.1 > #4 0xfffffd7ffc8c0d79 in __gnu_cxx::__verbose_terminate_handler () at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/vterminate.cc:48 > #5 0xfffffd7ffc8be12a in __cxxabiv1::__terminate (handler= out>) at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:39 > #6 0xfffffd7ffc8be183 in std::terminate () at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:49 > #7 0xfffffd7ffc8be2fe in __cxa_rethrow () at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_throw.cc:116 > #8 0xfffffd7ffc8c0d34 in __gnu_cxx::__verbose_terminate_handler () at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/vterminate.cc:78 > #9 0xfffffd7ffc8be12a in __cxxabiv1::__terminate (handler= out>) at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:39 > #10 0xfffffd7ffc8be183 in std::terminate () at > /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_terminate.cc:49 > #11 0xfffffd7ffc8be2a6 in __cxa_throw (obj=, > tinfo=, dest=) > at /home/csolar/src/gcc-4.5.0/libstdc++-v3/libsupc++/eh_throw.cc:83 > #12 0xfffffd7ffd9dbe7c in > boost::copy_exception (e=...) > at > /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:42 > #13 0xfffffd7ffd9dbfbf in boost::exception_detail::get_bad_alloc<42> () > at > /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:80 > #14 0xfffffd7ffdb259ac in __static_initialization_and_destruction_0 () > at > /home/csolar/platforms/SunOS-5.10-amd64/usr/bin/32/../../lib/32/gcc/../../../../usr/include/boost/exception/detail/exception_ptr.hpp:94 > #15 global constructors keyed to Attributes.cpp () at > Foobar/src/Attributes.cpp:219 > #16 0xfffffd7ffdb25a76 in __do_global_ctors_aux () > from > /home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so > #17 0xfffffd7ffd9ba1de in _init () > from > /home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so > #18 0xfffffd7fff3ce0ba in call_init () from /lib/amd64/ld.so.1 > #19 0xfffffd7fff3ce68d in load_completion () from /lib/amd64/ld.so.1 > #20 0xfffffd7fff3d2fd9 in dlmopen_intn () from /lib/amd64/ld.so.1 > #21 0xfffffd7fff3d312c in dlmopen_check () from /lib/amd64/ld.so.1 > #22 0xfffffd7fff3d31f9 in dlopen () from /lib/amd64/ld.so.1 > #23 0xfffffd7ffef2b67c in _PyImport_GetDynLoadFunc (fqname= out>, shortname=, > pathname=0xfffffd7fffdfeb50 > "/home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so", > fp=0xfffffd7fff10b320) at Python/dynload_shlib.c:130 > #24 0xfffffd7ffef103f1 in _PyImport_LoadDynamicModule > (name=0xfffffd7fffdff040 "LbmCom", > pathname=0xfffffd7fffdfeb50 > "/home/csolar/platforms/SunOS-5.10-amd64/usr/lib/python2.7/site-packages/Foobar-0.1pre1dev_r943-py2.7-solaris-2.10-i86pc.egg/Foobar.so", > fp=0xfffffd7fff10b320) at ./Python/importdl.c:42 > #25 0xfffffd7ffef0e557 in import_submodule (mod=0xfffffd7fff1a5630, > subname=0xfffffd7fffdff040 "Foobar", fullname=0xfffffd7fffdff040 "Foobar") > at Python/import.c:2595 > #26 0xfffffd7ffef0e80e in load_next (mod=0xfffffd7fff1a5630, > altmod=0xfffffd7fff1a5630, p_name=, > buf=0xfffffd7fffdff040 "Foobar", > p_buflen=0xfffffd7fffdff450) at Python/import.c:2415 > #27 0xfffffd7ffef0ee32 in import_module_level (name=, > globals=, fromlist=, > level=, name=, globals= optimized out>, fromlist=, level=) > at Python/import.c:2137 > #28 0xfffffd7ffef0f41a in PyImport_ImportModuleLevel (name=0x7cd8f4 > "Foobar", globals=0x6c7340, locals=, > fromlist=0xfffffd7fff1a5630, > level=-1) at Python/import.c:2188 > #29 0xfffffd7ffeeedcd9 in builtin___import__ (self=, > args=, kwds=) at > Python/bltinmodule.c:49 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From embhi.karuche at gmail.com Sun Jun 6 21:30:48 2010 From: embhi.karuche at gmail.com (Embhi Karuche) Date: Sun, 6 Jun 2010 22:30:48 +0300 Subject: [C++-sig] Does Boost.Python consider this as "unsupported" (threading related) Message-ID: Hello I have read the FAQ ( http://bit.ly/dl8j8o ) about multi-threading/multi-interpretor support - but I don't quite understand it. Please help me get clarified with it. Suppose I have exposed a C++ class's member function using Boost.Python. This function internally starts a Boost.Thread. Is this kind of usage support by Boost.Python? Note that the Boost.Thread itself is not being exposed to Python... Here is a very simplified layout of the code: http://codepad.org/YVlmvJW7 Thank you, and thanks for the great library... Boost.Python is really like magic! From charlessolar at gmail.com Sun Jun 6 21:45:30 2010 From: charlessolar at gmail.com (Charles Solar) Date: Sun, 6 Jun 2010 14:45:30 -0500 Subject: [C++-sig] Does Boost.Python consider this as "unsupported" (threading related) In-Reply-To: References: Message-ID: No you can do this, I do the same thing in my project. However, without appropriate GIL locks your new thread cannot call into python. So make sure your new thread of not calling any python callables and you are fine. On Sun, Jun 6, 2010 at 2:30 PM, Embhi Karuche wrote: > Hello > > I have read the FAQ ( http://bit.ly/dl8j8o ) about > multi-threading/multi-interpretor support - but I don't quite > understand it. Please help me get clarified with it. > Suppose I have exposed a C++ class's member function using > Boost.Python. This function internally starts a Boost.Thread. Is this > kind of usage support by Boost.Python? Note that the Boost.Thread > itself is not being exposed to Python... > > Here is a very simplified layout of the code: > http://codepad.org/YVlmvJW7 > > Thank you, and thanks for the great library... Boost.Python is really > like magic! > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From embhi.karuche at gmail.com Mon Jun 7 02:00:54 2010 From: embhi.karuche at gmail.com (Embhi Karuche) Date: Mon, 7 Jun 2010 03:00:54 +0300 Subject: [C++-sig] Does Boost.Python consider this as "unsupported" (threading related) Message-ID: >No you can do this, I do the same thing in my project. >However, without appropriate GIL locks your new thread cannot call into >python. So make sure your new thread of not calling any python callables >and you are fine. In my worker thread (ie, the workCallback() which is invoked by the doHeavyWork()), I was merely appending to a boost::python::list. I stopped doing that and my problems seem to have gone.. I think. so are you saying that I cant even access "basic" python objects like python::str python::list from another thread?? From embhi.karuche at gmail.com Mon Jun 7 03:51:08 2010 From: embhi.karuche at gmail.com (Embhi Karuche) Date: Mon, 7 Jun 2010 04:51:08 +0300 Subject: [C++-sig] Fill a python::str with contents of a vector ? Message-ID: I have a vector whose contents I would like to copy into a python::str. Currently, I am doing: string temp(myvector.begin(), myvector.end()); python::str data(temp); How can I skip the intermediate copy? Thanks From charlessolar at gmail.com Mon Jun 7 04:31:01 2010 From: charlessolar at gmail.com (Charles Solar) Date: Sun, 6 Jun 2010 21:31:01 -0500 Subject: [C++-sig] Does Boost.Python consider this as "unsupported" (threading related) In-Reply-To: References: Message-ID: you can only access python from 1 thread at a time. I have not done any messing around with python types so I do not know if those require the gil but from what you said it seems like they may. In order to work with python from multiple threads you need to manage the gil in your app. Just do a search on this list for gil and you will get all the information you need. In the C api, I think the functions to look into are PyGILState_Ensure and PyGILState_Release. On Sun, Jun 6, 2010 at 7:00 PM, Embhi Karuche wrote: > >No you can do this, I do the same thing in my project. > >However, without appropriate GIL locks your new thread cannot call into > >python. So make sure your new thread of not calling any python callables > >and you are fine. > > In my worker thread (ie, the workCallback() which is invoked by the > doHeavyWork()), I was merely appending to a boost::python::list. I > stopped doing that and my problems seem to have gone.. I think. > > so are you saying that I cant even access "basic" python objects like > python::str python::list from another thread?? > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Mon Jun 7 06:06:57 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Sun, 06 Jun 2010 21:06:57 -0700 Subject: [C++-sig] Fill a python::str with contents of a vector ? In-Reply-To: References: Message-ID: <4C0C7061.5010607@gmail.com> On 06/06/2010 06:51 PM, Embhi Karuche wrote: > I have a vector whose contents I would like to copy > into a python::str. > Currently, I am doing: > > string temp(myvector.begin(), myvector.end()); > python::str data(temp); > > How can I skip the intermediate copy? > You'll need to use the regular Python C API to avoid the temporary: python::str data( python::handle<>( PyString_FromStringAndSize(&myvector.front(), myvector.size()) ) ); Note that this will not fail gracefully if myvector.empty(). Jim Bosch From zao at acc.umu.se Mon Jun 7 12:26:04 2010 From: zao at acc.umu.se (Lars Viklund) Date: Mon, 7 Jun 2010 12:26:04 +0200 Subject: [C++-sig] Fill a python::str with contents of a vector ? In-Reply-To: <4C0C7061.5010607@gmail.com> References: <4C0C7061.5010607@gmail.com> Message-ID: <20100607102604.GA3553@hatchepsut.acc.umu.se> On Sun, Jun 06, 2010 at 09:06:57PM -0700, Jim Bosch wrote: > On 06/06/2010 06:51 PM, Embhi Karuche wrote: >> I have a vector whose contents I would like to copy >> into a python::str. >> Currently, I am doing: >> >> string temp(myvector.begin(), myvector.end()); >> python::str data(temp); > > You'll need to use the regular Python C API to avoid the temporary: > > > python::str data( > python::handle<>( > PyString_FromStringAndSize(&myvector.front(), myvector.size()) > ) > ); Judging by the docs, there's str(char const*, char const*) and str(char const*, size_t) overloads. Won't they suffice? -- Lars Viklund | zao at acc.umu.se From pj at nexplore.ch Mon Jun 7 14:52:25 2010 From: pj at nexplore.ch (Philip Jonientz - NEXPLORE AG) Date: Mon, 7 Jun 2010 14:52:25 +0200 Subject: [C++-sig] building boost/python against stackless python and vs 2010 Message-ID: <6CE09052C7C40D45BA2FC06EE3184763012294AD@astronomix.nexplore.ch> Hello there, hopefully im doing it right, never used mailing-lists before. I recently tried building python boost(1.4.3) with stackless python(3.1) using bjam for msvc10, which worked it seems. I already have set up a Visual Studio 2010 project and got stackless python to run a basic simple string. When including boost/python and the libs, I get a linker error saying: error LNK1104: cannot open file 'boost_python-vc100-mt-1_42.lib' which is strange since I built v1.43 and the lib files are existent. I wonder where the linker looks for 1.42? Im testing embedding stackless python in my C++/CLI project and some day trying to write a wrapper for .net... My includes look something like this: C:\boost\; C:\Python31\include\Stackless; C:\Python31\include My Lib dirs: C:\boost\boost\bin.v2\libs\python\build\msvc-10.0\release\link-static\ru ntime-link-static; C:\boost\boost\bin.v2\libs\python\build\msvc-10.0\release\link-static\th reading-multi; C:\Python31\libs I really have problems with all this configuration and linking stuff, haven't done that often... Thanks in forward =) Phil -------------- next part -------------- An HTML attachment was scrubbed... URL: From imran.fanaswala at gmail.com Mon Jun 7 19:07:32 2010 From: imran.fanaswala at gmail.com (Imran Fanaswala) Date: Mon, 7 Jun 2010 20:07:32 +0300 Subject: [C++-sig] Fill a python::str with contents of a vector Message-ID: > On 06/06/2010 06:51 PM, Embhi Karuche wrote: >> I have a vector whose contents I would like to copy >> into a python::str. >> Currently, I am doing: >> >> string temp(myvector.begin(), myvector.end()); >> python::str data(temp); > > You'll need to use the regular Python C API to avoid the temporary: > > > python::str data( > python::handle<>( > PyString_FromStringAndSize(&myvector.front(), myvector.size()) > ) > ); This works: python::str stuff(reinterpret_cast(&foo_vector.front()), foo_vector.size()*sizeof(FooVector::value_type)); btw, the sizeof(FooVector::value_type) part is not necessary since its a vector ; nonetheless, it clearer and possibly robust. From merlin66b at gmail.com Tue Jun 8 21:54:22 2010 From: merlin66b at gmail.com (Thomas Berg) Date: Tue, 8 Jun 2010 21:54:22 +0200 Subject: [C++-sig] building boost/python against stackless python and vs 2010 In-Reply-To: <6CE09052C7C40D45BA2FC06EE3184763012294AD@astronomix.nexplore.ch> References: <6CE09052C7C40D45BA2FC06EE3184763012294AD@astronomix.nexplore.ch> Message-ID: Hi, On Mon, Jun 7, 2010 at 2:52 PM, Philip Jonientz - NEXPLORE AG wrote: > error LNK1104: cannot open file 'boost_python-vc100-mt-1_42.lib' > > > > which is strange since I built v1.43 and the lib files are existent. > > I wonder where the linker looks for 1.42? It's hard to tell without more information, but the boost headers use the auto-linking feature of Visual Studio (unless you define BOOST_ALL_NO_LIB). If you accidentally include an older boost header, something like this could easily happen. Hope this helps, Thomas From pj at nexplore.ch Wed Jun 9 09:41:20 2010 From: pj at nexplore.ch (Philip Jonientz - NEXPLORE AG) Date: Wed, 9 Jun 2010 09:41:20 +0200 Subject: [C++-sig] building boost/python against stackless python and vs2010 In-Reply-To: References: <6CE09052C7C40D45BA2FC06EE3184763012294AD@astronomix.nexplore.ch> Message-ID: <6CE09052C7C40D45BA2FC06EE3184763013E5DE9@astronomix.nexplore.ch> Well, thanks for your help. I realized, there was a previous version of boost installed in the same directory which I first didn't realize somehow... now I'm really happy it actually compiles fine, thanks again :) -----Urspr?ngliche Nachricht----- Von: cplusplus-sig-bounces+pj=nexplore.ch at python.org [mailto:cplusplus-sig-bounces+pj=nexplore.ch at python.org] Im Auftrag von Thomas Berg Gesendet: Dienstag, 8. Juni 2010 21:54 An: Development of Python/C++ integration Betreff: Re: [C++-sig] building boost/python against stackless python and vs2010 Hi, On Mon, Jun 7, 2010 at 2:52 PM, Philip Jonientz - NEXPLORE AG wrote: > error LNK1104: cannot open file 'boost_python-vc100-mt-1_42.lib' > > > > which is strange since I built v1.43 and the lib files are existent. > > I wonder where the linker looks for 1.42? It's hard to tell without more information, but the boost headers use the auto-linking feature of Visual Studio (unless you define BOOST_ALL_NO_LIB). If you accidentally include an older boost header, something like this could easily happen. Hope this helps, Thomas _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From charlessolar at gmail.com Wed Jun 9 21:11:38 2010 From: charlessolar at gmail.com (Charles Solar) Date: Wed, 9 Jun 2010 14:11:38 -0500 Subject: [C++-sig] Python exceptions in functions called from C++ Message-ID: I have a boost python library that I build python scripts with. I am not embedding python, I think that is worth mentioning right off the bat. In my C++ library I have a separate thread calling into python occasionally and I am finding that if the function I call in python has a python error in it, eg: def callMe(): crash = "Hello world" return crash() When my C++ app calls that I get the error_already_set exception from boost python. My problem with that is it offers no information from python like 'Strings are not callable on line 200 in crash.py' So my question is how can I connect the error_already_set exception on the other thread to python's exception handler so if python produces an exception while calling from C++ I get the python exception information and not just 'error already set'? -------------- next part -------------- An HTML attachment was scrubbed... URL: From Matthew.Scouten at tradingtechnologies.com Wed Jun 9 21:17:38 2010 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Wed, 9 Jun 2010 14:17:38 -0500 Subject: [C++-sig] Python exceptions in functions called from C++ In-Reply-To: References: Message-ID: <32490DFF7774554A85D65D23A9F0F9380D2EE664@chiex01> Something like this will get you some more info. Try: Dopythonstuff() Catch: if (PyErr_Occurred()) { PyErr_Print(); } You should probably re throw that error, too. From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of Charles Solar Sent: Wednesday, June 09, 2010 2:12 PM To: Development of Python/C++ integration Subject: [C++-sig] Python exceptions in functions called from C++ I have a boost python library that I build python scripts with. I am not embedding python, I think that is worth mentioning right off the bat. In my C++ library I have a separate thread calling into python occasionally and I am finding that if the function I call in python has a python error in it, eg: def callMe(): crash = "Hello world" return crash() When my C++ app calls that I get the error_already_set exception from boost python. My problem with that is it offers no information from python like 'Strings are not callable on line 200 in crash.py' So my question is how can I connect the error_already_set exception on the other thread to python's exception handler so if python produces an exception while calling from C++ I get the python exception information and not just 'error already set'? -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed Jun 9 21:41:14 2010 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 09 Jun 2010 15:41:14 -0400 Subject: [C++-sig] Python exceptions in functions called from C++ In-Reply-To: References: Message-ID: <4C0FEE5A.6090005@sympatico.ca> On 06/09/2010 03:11 PM, Charles Solar wrote: > I have a boost python library that I build python scripts with. I am > not embedding python, I think that is worth mentioning right off the bat. > In my C++ library I have a separate thread calling into python > occasionally If you call Python from C++, why are you saying you are not embedding Python ? What do you mean by that ? > and I am finding that if the function I call in python has a python > error in it, eg: > > def callMe(): > crash = "Hello world" > return crash() > > When my C++ app calls that I get the error_already_set exception from > boost python. My problem with that is it offers no information from > python like 'Strings are not callable on line 200 in crash.py' So my > question is how can I connect the error_already_set exception on the > other thread to python's exception handler so if python produces an > exception while calling from C++ I get the python exception > information and not just 'error already set'? Right now you need to use the Python C API to fetch those details (see http://docs.python.org/c-api/exceptions.html?highlight=pyerr_fetch#PyErr_Fetch). I keep meaning to write C++ wrappers around that API, but it always falls off of my (fixed-size) TODO list. Perhaps someone else will beat me to it ? ;-) Stefan -- ...ich hab' noch einen Koffer in Berlin... From charlessolar at gmail.com Wed Jun 9 22:18:09 2010 From: charlessolar at gmail.com (Charles Solar) Date: Wed, 9 Jun 2010 15:18:09 -0500 Subject: [C++-sig] Python exceptions in functions called from C++ In-Reply-To: <4C0FEE5A.6090005@sympatico.ca> References: <4C0FEE5A.6090005@sympatico.ca> Message-ID: Thanks for the quick replies. Ill try this fetch stuff, maybe i can find some way to hack it into boost python so I do not have to modify every override call I make in my project. >> If you call Python from C++, why are you saying you are not embedding Python ? What do you mean by that ? My app is a library that is imported into python. But my library can call into python for certain things. My definition of embedded python would be an executable that can be extended with python so if that is wrong then I misspoke sorry. Thanks On Wed, Jun 9, 2010 at 2:41 PM, Stefan Seefeld wrote: > On 06/09/2010 03:11 PM, Charles Solar wrote: > >> I have a boost python library that I build python scripts with. I am not >> embedding python, I think that is worth mentioning right off the bat. >> In my C++ library I have a separate thread calling into python >> occasionally >> > > If you call Python from C++, why are you saying you are not embedding > Python ? What do you mean by that ? > > > and I am finding that if the function I call in python has a python error >> in it, eg: >> >> def callMe(): >> crash = "Hello world" >> return crash() >> >> When my C++ app calls that I get the error_already_set exception from >> boost python. My problem with that is it offers no information from python >> like 'Strings are not callable on line 200 in crash.py' So my question is >> how can I connect the error_already_set exception on the other thread to >> python's exception handler so if python produces an exception while calling >> from C++ I get the python exception information and not just 'error already >> set'? >> > > Right now you need to use the Python C API to fetch those details (see > > http://docs.python.org/c-api/exceptions.html?highlight=pyerr_fetch#PyErr_Fetch > ). > > I keep meaning to write C++ wrappers around that API, but it always falls > off of my (fixed-size) TODO list. Perhaps someone else will beat me to it ? > ;-) > > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhishek.srivastava at nechclst.in Thu Jun 17 11:27:06 2010 From: abhishek.srivastava at nechclst.in (abhi.sri45) Date: Thu, 17 Jun 2010 02:27:06 -0700 (PDT) Subject: [C++-sig] problem exposing iterators Message-ID: <28912265.post@talk.nabble.com> Hi, I am facing some problem in exposing iterator(using pyplusplus), for this I have created a sample problem(to communicate this problem) #include #include using namespace std; class A { }; typedef vector< A > vectorA; class B { public: typedef vectorA::iterator iter; iter begin() { return this->aVect.begin(); } private: vectorA aVect; }; B getB() { return B(); } main() { B b(getB()); vectorA::iterator it = b.begin(); } Here in the above example begin() function in class returns vector ::iterator and I want to expose this function but while generating bindings it gives WARNING: __gnu_cxx::__normal_iterator > [class] > execution error W1040: The declaration is unexposed, but there are other > declarations, which refer to it. This could cause "no to_python > converter found" run time error. Declarations: > __gnu_cxx::__normal_iterator > > B::begin() [member > function] Due to this it gives run time error while using this function. I tried various methods to include it explicitly but it fails. Can you please help, whether I have missed something in my case. Code generator that I used for generating bindings. import sys import os from pyplusplus import module_builder from pyplusplus.module_builder import call_policies from pyplusplus import code_creators from pyplusplus.module_builder.ctypes_decls_dependencies import find_out_dependencies sourceFile = './testIterator.cpp' mb=module_builder.module_builder_t( files = [sourceFile], include_paths = './', indexing_suite_version = 2, #define_symbols = defines ) i=0 depList=[] #depList.append(a) def getDepend(): global i if i < len(depList): try: deps = find_out_dependencies ( [depList[i]] ) for dep in deps: if dep not in depList: depList.append(dep) except: print "No Dependency for class %s", x pass i = i + 1 getDepend() else: return 0 z = getDepend() for dep in depList: dep.include() print dep a = mb.free_function('getB') depList=[a] i = 0 z = getDepend() for dep in depList: dep.include() mb.build_code_creator( module_name = 'testIterator') mb.code_creator.license = '//Boost Software License(http://boost.org/more/license_info.html )' mb.write_module('bindings.cpp') With Regards, Abhishek Srivastava -- View this message in context: http://old.nabble.com/problem-exposing-iterators-tp28912265p28912265.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From abhishek.srivastava at nechclst.in Thu Jun 17 11:24:37 2010 From: abhishek.srivastava at nechclst.in (Abhishek Srivastava) Date: Thu, 17 Jun 2010 14:54:37 +0530 Subject: [C++-sig] problem exposing iterators Message-ID: <0A8CFEC45B7F4C419F7543867C47442302893A8F@mailserver.nechclst.in> Hi, I am facing some problem in exposing iterator, for this I have created a sample problem(to communicate this problem) #include #include using namespace std; class A { }; typedef vector< A > vectorA; class B { public: typedef vectorA::iterator iter; iter begin() { return this->aVect.begin(); } private: vectorA aVect; }; B getB() { return B(); } main() { B b(getB()); vectorA::iterator it = b.begin(); } Here in the above example begin() function in class returns vector::iterator and I want to expose this function but while generating bindings it gives WARNING: __gnu_cxx::__normal_iterator > > [class] > execution error W1040: The declaration is unexposed, but there are other declarations, which refer to it. This could cause "no to_python > converter found" run time error. Declarations: __gnu_cxx::__normal_iterator > > B::begin() [member > function] Due to this it gives run time error while using this function. I tried various methods to include it explicitly but it fails. Can you please help, whether I have missed something in my case. Code generator that I used for generating bindings. import sys import os from pyplusplus import module_builder from pyplusplus.module_builder import call_policies from pyplusplus import code_creators from pyplusplus.module_builder.ctypes_decls_dependencies import find_out_dependencies sourceFile = './testIterator.cpp' mb=module_builder.module_builder_t( files = [sourceFile], include_paths = './', indexing_suite_version = 2, #define_symbols = defines ) i=0 depList=[] #depList.append(a) def getDepend(): global i if i < len(depList): try: deps = find_out_dependencies ( [depList[i]] ) for dep in deps: if dep not in depList: depList.append(dep) except: print "No Dependency for class %s", x pass i = i + 1 getDepend() else: return 0 z = getDepend() for dep in depList: dep.include() print dep a = mb.free_function('getB') depList=[a] i = 0 z = getDepend() for dep in depList: dep.include() mb.build_code_creator( module_name = 'testIterator') mb.code_creator.license = '//Boost Software License(http://boost.org/more/license_info.html )' mb.write_module('bindings.cpp') With Regards, Abhishek Srivastava DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . ----------------------------------------------------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From abhishek.srivastava at nechclst.in Fri Jun 18 07:54:46 2010 From: abhishek.srivastava at nechclst.in (abhi.sri45) Date: Thu, 17 Jun 2010 22:54:46 -0700 (PDT) Subject: [C++-sig] problem exposing iterators In-Reply-To: <28912265.post@talk.nabble.com> References: <28912265.post@talk.nabble.com> Message-ID: <28922372.post@talk.nabble.com> Although for this case I can think of a workable solution, to create some kind of wrapper functions(only in bindings) which return *iterator by adding: classB = mb.class_( 'B' ) classB.add_declaration_code("A getA( B& b ){ vector< A >::iterator iter = b.begin(); return *iter ;}") classB.add_registration_code( 'def( "begin", &::getA )' , works_on_instance = True) in codeGenerator scripts. But can I get some kind of solution where I can expose iterators(some kind of support available for iterators). With Regards, Abhishek Srivastava -- View this message in context: http://old.nabble.com/problem-exposing-iterators-tp28912265p28922372.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From vishal.bayskar at nechclst.in Fri Jun 18 12:58:43 2010 From: vishal.bayskar at nechclst.in (vishal bayskar) Date: Fri, 18 Jun 2010 03:58:43 -0700 (PDT) Subject: [C++-sig] How to add new constructor in a class Message-ID: <28924798.post@talk.nabble.com> In the below example I need to add a constructor A(). How to do that? class A{ public: A(int); int getA(); private: int a; }; I have tried add_declaration_code and add_registration_code but it seems that these will not work for the case of contructor. Does these work and I am doing somthing wrong? I also tried to create constructor using decl_factory_t.create_constructor() but I am not able to add the constructor in the wrapper code Please let me know the possible solution One more query Can I overwrite some constructor If suppose a constructor is declared as private can I change it's access as a public (or can I overwrite it somehow)? -- View this message in context: http://old.nabble.com/How-to-add-new-constructor-in-a-class-tp28924798p28924798.html Sent from the Python - c++-sig mailing list archive at Nabble.com. From damien.dupuis at lip6.fr Fri Jun 18 13:23:26 2010 From: damien.dupuis at lip6.fr (Damien Dupuis) Date: Fri, 18 Jun 2010 13:23:26 +0200 Subject: [C++-sig] Problem with map_indexing_suite Message-ID: I'm trying to wrap a whole C++ that contains a lot of access to std::vector and std::map. I managed to wrap vectors but i've got problems with maps. The following simple example fails to compile with the error: error: no match for call to ?(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (X*)? ==================================================== #include #include #include using namespace boost::python; class X { public: X(std::string s): _s(s) {} std::string const repr() { return _s; } private: std::string _s; }; class Y { public: Y(): _vec(), _map() {}; void addToVec(X* x) { _vec.push_back(x); } void addToMap(int i, X* x) { _map[i] = x; } const std::vector& getXVec() { return _vec; } const std::map& getXMap() { return _map; } private: std::vector _vec; std::map _map; }; BOOST_PYTHON_MODULE(pyTEST) { class_("X", init()) .def("__repr__", &X::repr) ; class_ >("XVec") .def(vector_indexing_suite, true>()) ; class_ >("XMap") .def(map_indexing_suite, true>()) ; class_("Y", init<>()) .def("addToVec", &Y::addToVec) .def("addToMap", &Y::addToMap) .def("getXVec" , &Y::getXVec , return_internal_reference<>()) .def("getXMap" , &Y::getXMap , return_internal_reference<>()) ; } ==================================================== I tried to use boost::shared_ptr instead of X* in this small example and it works, but I would like not to have to correct all my existing C++ code to use boost::shared_ptr. And since it works well with std::vector, I think it should work with maps. Some google search make me think I should add a return_value_policy to the __getitem__ method of std::map class, but when I try I get the error error: address of overloaded function with no contextual type information I'm clearly doing something wrong here. Thanks for any help/advice. FYI: I'm using boost 1.42.0, with g++ 4.2.1 on snow leopard (10.6.3) ------------------------------- Damien Dupuis From roman.yakovenko at gmail.com Sun Jun 20 06:16:03 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 20 Jun 2010 07:16:03 +0300 Subject: [C++-sig] How to add new constructor in a class In-Reply-To: <28924798.post@talk.nabble.com> References: <28924798.post@talk.nabble.com> Message-ID: On Fri, Jun 18, 2010 at 1:58 PM, vishal bayskar wrote: > > In the below example I need to add a constructor A(). How to do that? > > class A{ > public: > ? ? ? ?A(int); > ? ? ? ?int getA(); > private: > ? ? ? ?int a; > }; > If you can modify source code - than just do it, otherwise you will have to use make_constructor( http://language-binding.net/pyplusplus/documentation/functions/make_constructor.html ) functionality. > I have tried add_declaration_code and add_registration_code but it seems > that these will not work for > the case of contructor. > > Does these work and I am doing somthing wrong? The functionality add_declaration_code and add_registration_code works, unless you have a test case which shows the opposite. > > I also tried to create constructor using decl_factory_t.create_constructor() > but I am not able to add the constructor in the wrapper code This is the wrong approach, since the desired constructor doesn't exist in the source code - so you will have a lot of problems later > Please let me know the possible solution > > One more query Can I overwrite some constructor > If suppose a constructor is declared as private can I change it's access as > a public (or can I overwrite it somehow)? #define private public #include this ugly trick will allow you to achieve what you want, but it may not work on some compilers/classes. You will have to check. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun Jun 20 06:20:14 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 20 Jun 2010 07:20:14 +0300 Subject: [C++-sig] problem exposing iterators In-Reply-To: <28922372.post@talk.nabble.com> References: <28912265.post@talk.nabble.com> <28922372.post@talk.nabble.com> Message-ID: On Fri, Jun 18, 2010 at 8:54 AM, abhi.sri45 wrote: > > Although for this case I can think of a workable solution, to create some > kind of wrapper functions(only in bindings) which return *iterator by > adding: > > classB = mb.class_( 'B' ) > classB.add_declaration_code("A getA( B& b ){ vector< A >::iterator iter = > b.begin(); return *iter ;}") > classB.add_registration_code( 'def( "begin", &::getA )' , works_on_instance > = True) > > in codeGenerator scripts. > But can I get some kind of solution where I can expose iterators(some kind > of support available for iterators). No need to reinvent the wheel: * http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/iterator.html - this functionality is not supported by py++ * http://language-binding.net/pyplusplus/documentation/indexing_suite_v2.html.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From heroxbd at gmail.com Sun Jun 20 08:39:55 2010 From: heroxbd at gmail.com (heroxbd at gmail.com) Date: Sun, 20 Jun 2010 15:39:55 +0900 Subject: [C++-sig] interfacing headle binary file library, raw pointer and buffer Message-ID: <86k4puyzpg.fsf@gmail.com> Dear all, I am trying to interface a binary file library using py++. There is a function in the library like int read(void* buffer, size_t len) which is hard to wrap. It read a piece (size len) of the file, and store it in buffer, and then return the buffer length (most likely equal to len). If I do nothing special, the py++ generated module would be like: ,---- | >>> s = "" | >>> l = 1 | >>> binary_file.read(s, l) | .... | did not match C++ signature: | (python str type could not match void*) `---- Here are what I have tried (with no success): 1. I found the keyword "opaque pointer" in boost.python and py++. My knowledge is so limited that I couldn't figure out if my case is _actually_ an opaque pointer problem, cuz all the documentation[1] for py++ and boost.python are talking about opaque return pointer, not a passed pointer. I poked around py++ to add some class policies (from the example of gmp wrapper) resulting in no change in the py++ generated boost.python code. 2. Then I tried to change the function to int read(char* buffer, size_t len) with type casting done internally in c++. Then ,---- | >>> s = "" | >>> l = 1 | >>> binary_file.read(s, l) | 1 | (the function executed successfully, with no c++ signature type mismatch) | >>> s | Segment Fault (python crash) `---- maybe it is the methodology of python that not touching "low level" mem management. I guess that's what making this problem non-trivial. I may recompile my python with debugging information an trace it with gdb to find out why it is crashing. But not yet. 3. I tried ctypes: ,---- | >>> s = ctypes.c_char_p | >>> l = 1 | >>> binary_file.read(s, l) | (c++ signature type mismatch) `---- I guess we just cannot mix ctypes with boost.python directly. Now I need to learn and try something new to solve this issue. After some web searching, I find some possiblities: 1. py++ ctypes integration[2]. It looks promising. I would like to confirm on this list if it is suited to my case. 2. write a wrapper like ,---- | struct void_p { | void * ptr | } `---- and then change all the original c++ interface from func(void * buf, ...) to func(void_p buf, ...) (there are around 6 such functions) and take care of the internal convertion by hand. But in this case the interface becomes thicker. I regard it as the last choice cuz I want to keep new c++ code minimum (hopefully all auto generated by py++). 3. I came across struct module[3] in python. It seems to suit my needs; I'm not sure. I couldn't figure out how to use it right now. 4. pyOgre might have been already solved this kind of raw memory problem. I could learn pyOgre team's example and apply their method to my case. There may be a sharp learning curve though. ... I am not sure which path I should take. I am a beginner in c++ and python and c++/python integration. The documentations and mailing list archives seems overwhelming to me. I couldn't find a fresh point to start digging into. Please give me some suggestion and advice. I am ready to learn and try and practise. Cheers! Benda footnotes: 1. http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/opaque.html http://language-binding.net/pyplusplus/documentation/functions/call_policies/call_policies.html 2. http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html 3. http://docs.python.org/library/struct.html -- XU Benda Research Center for Neutrino Science Tohoku University JAPAN http://www.awa.tohoku.ac.jp/~benda From heroxbd at gmail.com Sun Jun 20 09:11:13 2010 From: heroxbd at gmail.com (heroxbd at gmail.com) Date: Sun, 20 Jun 2010 16:11:13 +0900 Subject: [C++-sig] interfacing headle binary file library, raw pointer and buffer In-Reply-To: <86k4puyzpg.fsf@gmail.com> (heroxbd@gmail.com's message of "Sun, 20 Jun 2010 15:39:55 +0900") References: <86k4puyzpg.fsf@gmail.com> Message-ID: <86fx0iyy9a.fsf@gmail.com> Hello, I have just found this thread interesting http://thread.gmane.org/gmane.comp.python.c++/12912/focus=12913 the pointers are PyString_FromStringAndSize PyArg_ParseTuple* and http://docs.python.org/c-api/buffer.html How can those fit in py++ and boost.python? Cheers, -- XU Benda Research Center for Neutrino Science Tohoku University JAPAN http://www.awa.tohoku.ac.jp/~benda From nat at lindenlab.com Sun Jun 20 15:54:37 2010 From: nat at lindenlab.com (Nat Goodspeed) Date: Sun, 20 Jun 2010 09:54:37 -0400 Subject: [C++-sig] interfacing headle binary file library, raw pointer and buffer In-Reply-To: <86k4puyzpg.fsf@gmail.com> References: <86k4puyzpg.fsf@gmail.com> Message-ID: <4C1E1D9D.1000300@lindenlab.com> heroxbd at gmail.com wrote: > I am trying to interface a binary file library using py++. > > There is a function in the library like > > int read(void* buffer, size_t len) > > which is hard to wrap. It read a piece (size len) of the file, and store > it in buffer, and then return the buffer length (most likely equal to len). You want to write a C++ wrapper function something like this: std::string wrapped_read(size_t len) { // manually allocate buffer of size 'len', // e.g. by using std::vector int bytes_read = read(buffer, len); return std::string(buffer, bytes_read); // If you literally used 'new' or 'malloc' to obtain your 'buffer', // rather than a type such as std::vector which will release // its dynamic memory automatically, of course the 'return' // above would leak 'buffer'. In that case you'd have to declare // std::string result(buffer, bytes_read); // ...manually release 'buffer'... // return result; } Then wrap the C++ function wrapped_read() as the Python function "read". Boost.Python is very happy passing std::string in either direction. Trying to directly use char* or void* buffers is perilous and will, as you remark, make the consumers of your library unhappy. From pab at isotek.co.uk Mon Jun 21 16:01:40 2010 From: pab at isotek.co.uk (Phil Bass) Date: Mon, 21 Jun 2010 15:01:40 +0100 Subject: [C++-sig] Exposing std::list<> via Boost.Python Message-ID: <4C1F70C4.6060705@isotek.co.uk> We have a lot of C++ code using a home-grown Event class template. An Event is just a list of pointers to callback function objects. More precisely, an Event is a std::list*>, where unary_function is a polymorphic function object class. Code that generates an event iterates through the list, dereferences each pointer and calls the corresponding function. I'd like python code to be able to generate these C++ events. To do that Event<>s need to support Python's iterable interface, which requires random access to the container. Unfortunately, std::list<> doesn't support random access. Short of copying the contents of every std::list<> to a std::vector<> for Python's benefit I don't see how this can be accomplished. Does anyone have any ideas for a simpler, more natural implementation? -- Phil Bass (pab at isotek.co.uk) The views expressed in this e-mail/posting are those of the author and do not necessarily reflect those of Isotek Electronics Ltd. From Matthew.Scouten at tradingtechnologies.com Mon Jun 21 17:02:23 2010 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Mon, 21 Jun 2010 10:02:23 -0500 Subject: [C++-sig] How to add new constructor in a class In-Reply-To: <28924798.post@talk.nabble.com> References: <28924798.post@talk.nabble.com> Message-ID: <32490DFF7774554A85D65D23A9F0F9380D47991B@chiex01> Why not just subclass A as A_wrapper, add the necessary ctor to A_wrapper and expose that instead? -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of vishal bayskar Sent: Friday, June 18, 2010 5:59 AM To: cplusplus-sig at python.org Subject: [C++-sig] How to add new constructor in a class In the below example I need to add a constructor A(). How to do that? class A{ public: A(int); int getA(); private: int a; }; I have tried add_declaration_code and add_registration_code but it seems that these will not work for the case of contructor. Does these work and I am doing somthing wrong? I also tried to create constructor using decl_factory_t.create_constructor() but I am not able to add the constructor in the wrapper code Please let me know the possible solution One more query Can I overwrite some constructor If suppose a constructor is declared as private can I change it's access as a public (or can I overwrite it somehow)? -- View this message in context: http://old.nabble.com/How-to-add-new-constructor-in-a-class-tp28924798p2 8924798.html Sent from the Python - c++-sig mailing list archive at Nabble.com. _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From heroxbd at gmail.com Tue Jun 22 05:37:29 2010 From: heroxbd at gmail.com (heroxbd at gmail.com) Date: Tue, 22 Jun 2010 12:37:29 +0900 Subject: [C++-sig] interfacing headle binary file library, raw pointer and buffer In-Reply-To: <4C1E1D9D.1000300@lindenlab.com> (Nat Goodspeed's message of "Sun, 20 Jun 2010 09:54:37 -0400") References: <86k4puyzpg.fsf@gmail.com> <4C1E1D9D.1000300@lindenlab.com> Message-ID: <86ocf3ybye.fsf@gmail.com> Allo Nat, Thank you very much for your reply. I didn't realized I could have this flexibility with py++ generated code. Now I could interface these functions. Cheers! Benda Nat Goodspeed writes: > You want to write a C++ wrapper function something like this: > > std::string wrapped_read(size_t len) > { > // manually allocate buffer of size 'len', > // e.g. by using std::vector > int bytes_read = read(buffer, len); > return std::string(buffer, bytes_read); -- XU Benda Research Center for Neutrino Science Tohoku University JAPAN http://www.awa.tohoku.ac.jp/~benda From roman.yakovenko at gmail.com Tue Jun 22 07:02:03 2010 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 22 Jun 2010 08:02:03 +0300 Subject: [C++-sig] interfacing headle binary file library, raw pointer and buffer In-Reply-To: <86ocf3ybye.fsf@gmail.com> References: <86k4puyzpg.fsf@gmail.com> <4C1E1D9D.1000300@lindenlab.com> <86ocf3ybye.fsf@gmail.com> Message-ID: On Tue, Jun 22, 2010 at 6:37 AM, wrote: > Allo Nat, > > Thank you very much for your reply. I didn't realized I could have this > flexibility with py++ generated code. Yes it has(http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html), but your use case is not covered under the existing function transformations. So in this case, it has nothing to do with py++ - you just create another function and expose it. > Now I could interface these functions. If you have a lot of function like this, may be it makes sense to create a function transformation for them. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From talljimbo at gmail.com Wed Jun 23 03:46:25 2010 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 22 Jun 2010 18:46:25 -0700 Subject: [C++-sig] Exposing std::list<> via Boost.Python In-Reply-To: <4C1F70C4.6060705@isotek.co.uk> References: <4C1F70C4.6060705@isotek.co.uk> Message-ID: <4C216771.3090702@gmail.com> On 06/21/2010 07:01 AM, Phil Bass wrote: > We have a lot of C++ code using a home-grown Event class template. An > Event is just a list of pointers to callback function objects. More > precisely, an Event is a std::list*>, where > unary_function is a polymorphic function object class. Code that > generates an event iterates through the list, dereferences each pointer > and calls the corresponding function. > > I'd like python code to be able to generate these C++ events. To do that > Event<>s need to support Python's iterable interface, which requires > random access to the container.Unfortunately, std::list<> doesn't > support random access. Short of copying the contents of every > std::list<> to a std::vector<> for Python's benefit I don't see how this > can be accomplished. > > Does anyone have any ideas for a simpler, more natural implementation? > You don't need random access to make a python iterable at all - Python's built-in dict and set types are examples. All you need to do is define an __iter__ special function, and you should be able to do that fairly automatically using the stuff described here: http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/iterator.html Jim Bosch From cournia at gmail.com Wed Jun 23 06:13:34 2010 From: cournia at gmail.com (Nathan Cournia) Date: Tue, 22 Jun 2010 21:13:34 -0700 Subject: [C++-sig] wrapping a reference counted class Message-ID: Hi, I'm trying to wrap the following class: class Node { public: virtual ~Node(); virtual void compute(); void incRef(); void decRef(); private: unsigned _refCount }; As you can see, the class is reference counted. In most places in my code, I pass around Node* pointers. I rarely call incRef() and decRef() to avoid overhead. I only call incRef() and decRef() in places where they are absolutely needed. For instance: void addNode(Node* n) stores a pointer to n and calls n->incRef(). Likewise: void remNode() removes its copy of the Node pointer and calls n->decRef(). Finally: Node* getNode() Returns a pointer to the Node stored by addNode(). It does _not_ call n->incRef(). Now, let's say I wrapped the three functions above with Boost.Python. I'm looking for the following reference counting behavior when doing the following in Python: 0>> x = Node() # refs = 1 1>> addNode(x) # refs = 2 2>> y = getNode() # refs = 3 3>> del x # refs = 2 4>> del y # refs = 1 5>> remNode() # refs = 0 How do I wrap Node such that I get the reference counting behavior above? I took a look at: http://wiki.python.org/moin/boost.python/PointersAndSmartPointers but at first glance it doesn't appear to be what I want. I'm not using smart pointers, instead I'm manually incrementing and decrementing the reference count. Thanks in advance for any help. nathan From benoit.leveau at gmail.com Wed Jun 23 10:58:04 2010 From: benoit.leveau at gmail.com (=?ISO-8859-1?Q?Beno=EEt_Leveau?=) Date: Wed, 23 Jun 2010 09:58:04 +0100 Subject: [C++-sig] Exposing std::list<> via Boost.Python Message-ID: > > We have a lot of C++ code using a home-grown Event class template. An > > Event is just a list of pointers to callback function objects. More > > precisely, an Event is a std::list*>, where > > unary_function is a polymorphic function object class. Code that > > generates an event iterates through the list, dereferences each pointer > > and calls the corresponding function. > > > > I'd like python code to be able to generate these C++ events. To do that > > Event<>s need to support Python's iterable interface, which requires > > random access to the container.Unfortunately, std::list<> doesn't > > support random access. Short of copying the contents of every > > std::list<> to a std::vector<> for Python's benefit I don't see how this > > can be accomplished. > > > > Does anyone have any ideas for a simpler, more natural implementation? > > > > You don't need random access to make a python iterable at all - Python's built-in dict and set types are examples. All you need to do is define an __iter__ special function, and you should be able to do that fairly automatically using the stuff described here: > > http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/iterator.html > Jim Bosch I often refer to this page when I want to add the __iter__ function. It clearly shows all the available options. http://wiki.python.org/moin/boost.python/iterator Add to that boost::make_transform_iterator and possibilities are endless ;) From blake at hailmail.net Tue Jun 29 08:13:41 2010 From: blake at hailmail.net (Dane Springmeyer) Date: Mon, 28 Jun 2010 23:13:41 -0700 Subject: [C++-sig] boost python and clang++ Message-ID: Anyone tried building a boost python application using clang++? I noticed this post: http://blog.llvm.org/2010/05/clang-builds-boost.html#more and gave it a shot with mapnik (mapnik.org). Compiled fine (in nearly half the time), but it appears that exception translation is not working: http://trac.mapnik.org/ticket/565 Any thoughts or ideas welcome! Dane