From vivh.29 at hotmail.fr Sun Nov 1 12:25:01 2015 From: vivh.29 at hotmail.fr (Vivien Henry) Date: Sun, 1 Nov 2015 18:25:01 +0100 Subject: [C++-sig] Accessing pointer properties with boost-python ? Message-ID: Hello everyone, I am new on this mailing-list, so; first, My name is Vivien Henry, working as Electrical Engineer in France I am currently trying to wrap a CAD software, gerbv (http://gerbv.geda-project.org/), which is designed to handle Gerber files. (They also provide it as a library) the file wrapper.cpp is generated through a personal script The script is still a work in progress. The generated code compiles, creating objects looks ok, accessing their attributes (numbers.. enums) as well. BUT, the problem is when i want to access a property which is actually a pointer... For instance, with this script: >>> from gerbv import * >>> >>> >>> >>> i = gerbv_instruction_t() >>> i >>> i.opcode gerbv.gerbv_opcodes_t.GERBV_OPCODE_NOP >>> a = gerbv_amacro_t() >>> a >>> a.program Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in None.None(gerbv_amacro_t) did not match C++ signature: None(amacro {lvalue}) >>> I can't figure out what is happening here ! (you ll see that i am creating a proxy to access string and char array...) Any help is welcome :D Thanks a lot, Vivien Henry here the specific code for this error, which is in the file wrapper.cpp class gerbv_amacro_t_proxy: public gerbv_amacro_t{ public: std::string get_name(){ std::string s(name); return s; } void set_name(std::string s){ name = (gchar*)s.c_str(); } gerbv_amacro_t_proxy() { } }; // in boost_python macro... l655 class_ >("gerbv_amacro_t") //Methods //Properties .add_property("name", &gerbv_amacro_t_proxy::get_name, &gerbv_amacro_t_proxy::set_name) .add_property("program", make_getter(&gerbv_amacro_t_proxy::program, return_internal_reference<>()), make_setter(&gerbv_amacro_t_proxy::program, return_internal_reference<>())) .def_readwrite("nuf_push", &gerbv_amacro_t_proxy::nuf_push) .add_property("next", make_getter(&gerbv_amacro_t_proxy::next, return_internal_reference<>()), make_setter(&gerbv_amacro_t_proxy::next, return_internal_reference<>())) ; // in boost python macro l918 class_ >("gerbv_instruction_t") //Methods //Properties .def_readwrite("opcode", &gerbv_instruction_t::opcode) .def_readwrite("data", &gerbv_instruction_t::data) .add_property("next", make_getter(&gerbv_instruction_t::next, return_internal_reference<>()), make_setter(&gerbv_instruction_t::next, return_internal_reference<>())) ; -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: wrapper.cpp Type: text/x-c Size: 46604 bytes Desc: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: gerbv.h URL: From zhanli1986 at gmail.com Tue Nov 3 17:13:19 2015 From: zhanli1986 at gmail.com (Zhan Li) Date: Tue, 3 Nov 2015 17:13:19 -0500 Subject: [C++-sig] Expose a C++ function with an argument of template vector to Python: Boost.Python.ArgumentError Message-ID: Greetings, I'm new to Boost.Python. I have a C++ library (written and shipped by another party) that I want to wrap into Python modules so that I can use several functions in Python. One function takes an argument that is a C++ template vector. How can I export this function to a python function? In a nutshell, here is what I'm doing now but without luck. I wrap the template vector into a Python class using Boost.Python's vector_indexing_suite. Then in the Python script, I first declare this Python class and then pass it to the function. But I got no luck and the following error message, " Boost.Python.ArgumentError: Python argument types in canupo.read_msc_header(MSCFile, FloatVec, int) did not match C++ signature: read_msc_header(MSCFile {lvalue}, std::vector > {lvalue}, int {lvalue}) " More specifically, here are the C++ code and Python script I have. In the C++ library code file "helper.hpp", it has a struct MSCFile and a function read_msc_header. struct MSCFile { // definition of MSCFile }; int read_msc_header(MSCFile& mscfile, std::vector& scales, int& ptn) { // implementation of read_msc_header } The "FloatType" is just a alias for float. In the C++ wrapper code file "wrapper.cpp" #include "helpers.hpp" #include #include #include #include #include BOOST_PYTHON_MODULE(canupo) { using namespace boost::python; class_ >("FloatVec") .def(vector_indexing_suite >()) ; class_("MSCFile", init()) ; def("read_msc_header", read_msc_header); } In the python script, I tried to use the function as following but failed. import canupo mscfile = canupo.MSCFile("msc_file_name") scales = canupo.FloatVec() ptnparams = 0 print canupo.read_msc_header(mscfile, scales, ptnparams) And the error goes like this: Boost.Python.ArgumentError: Python argument types in canupo.read_msc_header(MSCFile, FloatVec, int) did not match C++ signature: read_msc_header(MSCFile {lvalue}, std::vector > {lvalue}, int {lvalue}) I googled around but didn't find a good solution or a solution that I can understand well. Most requires rewrite the function with Boost.Python. But I don't want to change the C++ library code itself. I think there may be a good way to expose such a function to Python. Thanks a lot! Zhan. -- Zhan Li, ??; Earth & Environment, Boston University, USA; 2008 - 2011, in Chinese Academy of Sciences, China; 2004 - 2008, in Nanjing University, China; -------------- next part -------------- An HTML attachment was scrubbed... URL: From herron at ELLINGTON.com Wed Nov 4 10:40:25 2015 From: herron at ELLINGTON.com (Liam Herron) Date: Wed, 4 Nov 2015 15:40:25 +0000 Subject: [C++-sig] Expose a C++ function with an argument of template vector to Python: Boost.Python.ArgumentError In-Reply-To: References: Message-ID: <96426055F003C542B3FB8A0928736DF9023A627EBA@ex0.ELLINGTON.com> What happens if you do: print canupo.read_msc_header(mscfile, scales, float(ptnparams)) ? From: Cplusplus-sig [mailto:cplusplus-sig-bounces+herron=ellington.com at python.org] On Behalf Of Zhan Li Sent: Tuesday, November 03, 2015 5:13 PM To: cplusplus-sig at python.org Subject: [C++-sig] Expose a C++ function with an argument of template vector to Python: Boost.Python.ArgumentError Greetings, I'm new to Boost.Python. I have a C++ library (written and shipped by another party) that I want to wrap into Python modules so that I can use several functions in Python. One function takes an argument that is a C++ template vector. How can I export this function to a python function? In a nutshell, here is what I'm doing now but without luck. I wrap the template vector into a Python class using Boost.Python's vector_indexing_suite. Then in the Python script, I first declare this Python class and then pass it to the function. But I got no luck and the following error message, " Boost.Python.ArgumentError: Python argument types in canupo.read_msc_header(MSCFile, FloatVec, int) did not match C++ signature: read_msc_header(MSCFile {lvalue}, std::vector > {lvalue}, int {lvalue}) " More specifically, here are the C++ code and Python script I have. In the C++ library code file "helper.hpp", it has a struct MSCFile and a function read_msc_header. struct MSCFile { // definition of MSCFile }; int read_msc_header(MSCFile& mscfile, std::vector& scales, int& ptn) { // implementation of read_msc_header } The "FloatType" is just a alias for float. In the C++ wrapper code file "wrapper.cpp" #include "helpers.hpp" #include #include #include #include #include BOOST_PYTHON_MODULE(canupo) { using namespace boost::python; class_ >("FloatVec") .def(vector_indexing_suite >()) ; class_("MSCFile", init()) ; def("read_msc_header", read_msc_header); } In the python script, I tried to use the function as following but failed. import canupo mscfile = canupo.MSCFile("msc_file_name") scales = canupo.FloatVec() ptnparams = 0 print canupo.read_msc_header(mscfile, scales, ptnparams) And the error goes like this: Boost.Python.ArgumentError: Python argument types in canupo.read_msc_header(MSCFile, FloatVec, int) did not match C++ signature: read_msc_header(MSCFile {lvalue}, std::vector > {lvalue}, int {lvalue}) I googled around but didn't find a good solution or a solution that I can understand well. Most requires rewrite the function with Boost.Python. But I don't want to change the C++ library code itself. I think there may be a good way to expose such a function to Python. Thanks a lot! Zhan. -- Zhan Li, ??; Earth & Environment, Boston University, USA; 2008 - 2011, in Chinese Academy of Sciences, China; 2004 - 2008, in Nanjing University, China; ============================================================================================= Email transmissions can not be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of email transmission. In addition, the information contained in this email message is intended only for use of the individual or entity named above. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution,or copying of this communication, disclosure of the parties to it, or any action taken or omitted to be taken in reliance on it, is strictly prohibited, and may be unlawful. If you are not the intended recipient please delete this email message. ============================================================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From afalanga at micron.com Tue Nov 17 16:17:47 2015 From: afalanga at micron.com (Andy Falanga (afalanga)) Date: Tue, 17 Nov 2015 21:17:47 +0000 Subject: [C++-sig] C++ comments to docstrings Message-ID: <564B9958.9030809@micron.com> Hello, My team produces a C++ library exported to python via Boost.Python. We've documented our functions and classes with C#-ish style comments. These are parse-able by Visual Studio and XML files are built from them. When our shared object file is imported in python, a function opens these files and makes the association of the appropriate "docstring" in the XML file with the __doc__ property at runtime. Now that you know how we do it currently, I'd like to know are there better methods in use by, or known to, those in this list? The main hurdle to overcome at this point is that our library is built for both Windows and Linux. Because the documentation method has been to use Visual Studio to build the XML, the Windows build must be done first and the XML left in some place that the Linux build can reach. I'd like to eliminate this dependency for Linux. Andy From amohr at pixar.com Thu Nov 19 13:06:40 2015 From: amohr at pixar.com (Alex Mohr) Date: Thu, 19 Nov 2015 10:06:40 -0800 Subject: [C++-sig] C++ comments to docstrings In-Reply-To: <564B9958.9030809@micron.com> References: <564B9958.9030809@micron.com> Message-ID: <564E0FB0.7090404@pixar.com> Hi Andy, We do something very similar to what you describe, except we use doxygen (www.doxygen.org) to output XML files that we use to generate __doc__ strings for our python bindings. We're primarily a linux shop. I don't know how hard it would be to switch to doxygen, maybe it can deal with C#-ish style comments? But I believe it runs on Linux and Windows so perhaps it might help? Alex On 11/17/2015 1:17 PM, Andy Falanga (afalanga) wrote: > Hello, > > My team produces a C++ library exported to python via Boost.Python. > We've documented our functions and classes with C#-ish style comments. > These are parse-able by Visual Studio and XML files are built from > them. When our shared object file is imported in python, a function > opens these files and makes the association of the appropriate > "docstring" in the XML file with the __doc__ property at runtime. > > Now that you know how we do it currently, I'd like to know are there > better methods in use by, or known to, those in this list? The main > hurdle to overcome at this point is that our library is built for both > Windows and Linux. Because the documentation method has been to use > Visual Studio to build the XML, the Windows build must be done first and > the XML left in some place that the Linux build can reach. I'd like to > eliminate this dependency for Linux. > > Andy > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > From afalanga at micron.com Thu Nov 19 19:33:58 2015 From: afalanga at micron.com (Andy Falanga (afalanga)) Date: Fri, 20 Nov 2015 00:33:58 +0000 Subject: [C++-sig] C++ comments to docstrings In-Reply-To: <564E0FB0.7090404@pixar.com> References: <564B9958.9030809@micron.com> <564E0FB0.7090404@pixar.com> Message-ID: <564E6A33.3090001@micron.com> On 11/19/2015 11:06 AM, Alex Mohr wrote: > Hi Andy, > > We do something very similar to what you describe, except we use > doxygen (www.doxygen.org) to output XML files that we use to generate > __doc__ strings for our python bindings. We're primarily a linux shop. > > I don't know how hard it would be to switch to doxygen, maybe it can > deal with C#-ish style comments? But I believe it runs on Linux and > Windows so perhaps it might help? > > Alex Alex, Knowing better how our system works, using doxygen may be a viable alternative. I'll investigate this. I've used it before on our codebase and it worked fairly well. However, the output wasn't the same as the XML produced by VS. At the time, I thought this was a showstopper. Knowing more now, however, it might be possible to alter our parsing routines to evaluate the doxygen XML. This would be grand since doxygen is pretty simple to install on Linux. Thanks again, Andy From machang at princeton.edu Mon Nov 23 17:45:21 2015 From: machang at princeton.edu (Michael Chang) Date: Mon, 23 Nov 2015 17:45:21 -0500 Subject: [C++-sig] Compilation (?) Problem with boost.python Message-ID: Hello, I am running boost_1_59_0 on Ubuntu, and I bootstrapped/installed (using b2) boost.python without any errors. When I run the quick start example, I get the following error: chachang at chachang-Lenovo-Y50-70:~/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/libs/python/example/quickstart$ bjam toolset=gcc --verbose-test test warning: mismatched versions of Boost.Build engine and core warning: Boost.Build engine (bjam) is 2011.12.01 warning: Boost.Build core (at /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src) is 2015.07-git Performing configuration checks - 32-bit : no - 64-bit : yes - arm : no - mips1 : no - power : no - sparc : no - x86 : yes - symlinks supported : yes */home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/tools/link.jam:398: in link-recursively* *ERROR: rule "READLINK" unknown in module "link".* /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/tools/link.jam:472: in link.do-link-recursively /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/kernel/modules.jam:107: in modules.call-in /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/util/indirect.jam:98: in indirect.call /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:798: in class at action.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:311: in actualize-action /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:497: in actualize-no-scanner /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:134: in class at virtual-target.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:855: in actualize-sources /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:780: in class at action.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:311: in actualize-action /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:497: in actualize-no-scanner /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:134: in class at virtual-target.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:819: in actualize-source-type /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:840: in actualize-sources /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:780: in class at action.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:311: in actualize-action /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:497: in actualize-no-scanner /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:134: in class at virtual-target.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:819: in actualize-source-type /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:840: in actualize-sources /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:780: in class at action.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:311: in actualize-action /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:497: in actualize-no-scanner /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:134: in class at virtual-target.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:819: in actualize-source-type /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:840: in actualize-sources /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:780: in class at action.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:311: in actualize-action /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:497: in actualize-no-scanner /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build/virtual-target.jam:134: in class at virtual-target.actualize /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/tools/build/src/build-system.jam:720: in load /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/libs/python/example/quickstart/../../../../tools/build/src/kernel/modules.jam:295: in import /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/libs/python/example/quickstart/../../../../tools/build/src/kernel/bootstrap.jam:139: in boost-build /home/chachang/Desktop/thesis/VeriFlow-v0.3/boost_1_59_0/libs/python/example/quickstart/boost-build.jam:7: in module scope Is there any insight to what could be causing this problem? I have installed Boost at local prefix (not /usr/local/); where can I specify the non-default prefix when I run/compile the code? Thanks! Michael Alan Chang Princeton University '16 Computer Science -------------- next part -------------- An HTML attachment was scrubbed... URL: From slide.o.mix at gmail.com Tue Nov 24 18:30:05 2015 From: slide.o.mix at gmail.com (Slide) Date: Tue, 24 Nov 2015 23:30:05 +0000 Subject: [C++-sig] Boost Python in dynamic libraries Message-ID: I have a set of plugins that I am loading from shared libraries on Linux. I thought I would want to call the initModule function when loading the library, but I am getting the following error when I do so: Fatal Python error: PyThreadState_Get: no current thread Aborted (core dumped) Can anyone point me to an example of something like this? I am using BOOST_PYTHON_MODULE in my shared libraries and then loading them at runtime. I would like to import that module into my main namespace where most of my code is being run. Thanks! slide -------------- next part -------------- An HTML attachment was scrubbed... URL: From giuseppe.corbelli at copangroup.com Wed Nov 25 03:51:56 2015 From: giuseppe.corbelli at copangroup.com (Giuseppe Corbelli) Date: Wed, 25 Nov 2015 09:51:56 +0100 Subject: [C++-sig] Boost Python in dynamic libraries In-Reply-To: References: Message-ID: <565576AC.3020709@copangroup.com> On 25/11/2015 00:30, Slide wrote: > I have a set of plugins that I am loading from shared libraries on Linux. I > thought I would want to call the initModule function when loading the library, > but I am getting the following error when I do so: > > Fatal Python error: PyThreadState_Get: no current thread > Aborted (core dumped) > > Can anyone point me to an example of something like this? I am using > BOOST_PYTHON_MODULE in my shared libraries and then loading them at runtime. I > would like to import that module into my main namespace where most of my code > is being run. If you have a look at the interpreter code (assuming 2.7 series), you'll see that PyThreadState * PyThreadState_Get(void) { if (_PyThreadState_Current == NULL) Py_FatalError("PyThreadState_Get: no current thread"); return _PyThreadState_Current; } PyThreadState *_PyThreadState_Current is defined in Python/pystate.c and initialized as NULL. In Python/pythonrun.c within Py_InitializeEx() call a new thread state is initialized and PyThreadState_Swap() sets it. In short: I'd say you didn't call Py_Initialize() before dlopen()ing the shared objects. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copangroup.com From slide.o.mix at gmail.com Wed Nov 25 11:01:28 2015 From: slide.o.mix at gmail.com (Slide) Date: Wed, 25 Nov 2015 16:01:28 +0000 Subject: [C++-sig] Boost Python in dynamic libraries In-Reply-To: <565576AC.3020709@copangroup.com> References: <565576AC.3020709@copangroup.com> Message-ID: Wow, that was great! I appreciate your help. I indeed was not calling Py_Initialize before loading the libraries. Much appreciated! On Wed, Nov 25, 2015 at 7:40 AM Giuseppe Corbelli < giuseppe.corbelli at copangroup.com> wrote: > On 25/11/2015 00:30, Slide wrote: > > I have a set of plugins that I am loading from shared libraries on > Linux. I > > thought I would want to call the initModule function when loading the > library, > > but I am getting the following error when I do so: > > > > Fatal Python error: PyThreadState_Get: no current thread > > Aborted (core dumped) > > > > Can anyone point me to an example of something like this? I am using > > BOOST_PYTHON_MODULE in my shared libraries and then loading them at > runtime. I > > would like to import that module into my main namespace where most of my > code > > is being run. > > If you have a look at the interpreter code (assuming 2.7 series), you'll > see that > > PyThreadState * > PyThreadState_Get(void) > { > if (_PyThreadState_Current == NULL) > Py_FatalError("PyThreadState_Get: no current thread"); > > return _PyThreadState_Current; > } > > PyThreadState *_PyThreadState_Current is defined in Python/pystate.c and > initialized as NULL. > > In Python/pythonrun.c within Py_InitializeEx() call a new thread state is > initialized and PyThreadState_Swap() sets it. > > In short: I'd say you didn't call Py_Initialize() before dlopen()ing the > shared objects. > > -- > Giuseppe Corbelli > WASP Software Engineer, Copan Italia S.p.A > Phone: +390303666318 Fax: +390302659932 > E-mail: giuseppe.corbelli at copangroup.com > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: