From lewis.evans at bayforest.ai Fri May 1 04:39:40 2020 From: lewis.evans at bayforest.ai (Lewis Evans) Date: Fri, 1 May 2020 09:39:40 +0100 Subject: [C++-sig] Compiling boost python In-Reply-To: References: Message-ID: We build boost-python using a simple setup: 1. build boost according to its own instructions 2. cmake to build our C++, using find_package for python and boost libraries we use the latest cmake, find_package with exact required components I personally found bjam tricky to use (very few examples or search results for problems), whereas cmake/gnumake are standard and widely used. Lewis Bayforest Technologies Limited 48 Dover St, Mayfair London W1S 4FF work1: +44 203 968 5167 email: lewis.evans at bayforest.ai web: https://bayforest.ai/ On Thu, Apr 30, 2020 at 10:27 PM wrote: > Send Cplusplus-sig mailing list submissions to > cplusplus-sig at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/cplusplus-sig > or, via email, send a message with subject or body 'help' to > cplusplus-sig-request at python.org > > You can reach the person managing the list at > cplusplus-sig-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Cplusplus-sig digest..." > > > Today's Topics: > > 1. Re: Compiling boost python (Axel Huebl) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 30 Apr 2020 14:21:40 -0700 > From: Axel Huebl > To: Development of Python/C++ integration > Subject: Re: [C++-sig] Compiling boost python > Message-ID: <6C53894D-D06A-4F18-AE8E-0C479DA9B201 at hzdr.de> > Content-Type: text/plain; charset="utf-8" > > Hi, > > Check out the bazel example or the plain build with setuptools: > > https://github.com/pybind/ > https://github.com/pybind/python_example > > Axel > > On April 30, 2020 9:05:39 AM PDT, Andrew Voelkel < > jandyman.voelkel at gmail.com> wrote: > >The examples all use cmake, and there is a cmake extension for pybind11 > >that takes care of a number of things for you. From the docs: > > > >For C++ codebases that have an existing CMake-based build system, a > >Python extension module can be created with just a few lines of code: > >cmake_minimum_required(VERSION 2.8.12) > >project(example) > > > >add_subdirectory(pybind11) > >pybind11_add_module(example example.cpp) > > > >More here: > > > > > https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake > > > > > >From: Cplusplus-sig > > on behalf > >of Alain O' Miniussi > >Reply-To: Development of Python/C++ integration > > > >Date: Thursday, April 30, 2020 at 8:30 AM > >To: Development of Python/C++ integration > >Subject: Re: [C++-sig] Compiling boost python > > > >But having one more lib outside boost means one more dependency. > > > >The sad thing is that dropping support for "the oldest and buggiest of > >compiler specimens" in Boost would be rational to do, there are plenty > >of old Boost releases for those. > >How the cmake support for pybind ? > > > >----- On 29 Avr 20, at 20:09, Andrew Voelkel > > wrote: > > > >This blurb might help with that question: > > > >The main issue with Boost.Python?and the reason for creating such a > >similar project?is Boost. Boost is an enormously large and complex > >suite of utility libraries that works with almost every C++ compiler in > >existence. This compatibility has its cost: arcane template tricks and > >workarounds are necessary to support the oldest and buggiest of > >compiler specimens. Now that C++11-compatible compilers are widely > >available, this heavy machinery has become an excessively large and > >unnecessary dependency. Think of this library as a tiny self-contained > >version of Boost.Python with everything stripped away that isn?t > >relevant for binding generation. Without comments, the core header > >files only require ~4K lines of code and depend on Python (2.7 or 3.x, > >or PyPy2.7 >= 5.7) and the C++ standard library. This compact > >implementation was possible thanks to some of the new C++11 language > >features (specifically: tuples, lambda functions and variadic > >templates). Since its creation, this library has grown beyond > >Boost.Python in many ways, leading to dramatically simpler binding code > >in many common situations. > > > > > > * Andy > > > >From: Cplusplus-sig > > on behalf > >of Torsten Kn?ppel > >Reply-To: Development of Python/C++ integration > > > >Date: Wednesday, April 29, 2020 at 8:15 AM > >To: Development of Python/C++ integration > >Subject: Re: [C++-sig] Re: Compiling boost python > > > >Hi Andy, > > > >thanks for the quick reply. I only came across pybind recently when I > >was encountering some dependency issues with > >boost.python and looked for an alternative. It > >looks really useful, but I hesitated to make the switch - but I think I > >will do it sooner or later. Maybe one question regarding pybind - is it > >easy to create bindings for different Python versions? > >Am 29.04.20, 16:42 schrieb Andrew Voelkel : > >Have you considered using pybind11? It?s the same basic idea as > >boost.python, but it is cleaner, much better supported and documented, > >and has a large user community. I just discovered this lately, have > >been using it, and I?m thrilled with it. The only catch is that you > >need to be compiling with at least a C++11 compiler, but that is a > >pretty low bar these days. > > > > > > * Andy > > > >From: Cplusplus-sig > > on behalf > >of Torsten Kn?ppel > >Reply-To: Development of Python/C++ integration > > > >Date: Wednesday, April 29, 2020 at 7:34 AM > >To: "cplusplus-sig at python.org" > >Subject: [C++-sig] Compiling boost python > > > >Dear all, > > > >I'm trying to compile boost.python with a version of python, that I've > >downloaded and built myself. > >Is the "No-install quickstart"-page > >( > https://www.boost.org/doc/libs/1_73_0/libs/python/doc/html/building/no_install_quickstart.html > ) > >still updated, because some of the links are broken and > >I honestly don't understand what is going on there. > >Some questions that I have: > >- What is the bjam "build driver"? When I go to Section 5 of the boost > >Getting Started page - they mention something about an easy install > >option and another one for custom binaries. > > The entire page mentions neither bjam, nor "build driver". > >- I manage to build boost, by first running the bootstrap script and > >then calling b2 - if I select e.g. graph - it is built and copied into > >the correct directory, that I've specified. However, > > it doesn't work with my own Python folder. > > I wrote a small script to automate all steps: > > > >#wget > >https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz > >#tar -xvf boost_1_73_0.tar.gz > >cd boost_1_73_0 > >./bootstrap.sh --prefix=../build_boost --with-libraries=python > >-with-python-root=../Python-3.6.10 --with-python-version=3.6 > >./b2 install -d+2 > >echo "using python : : ../Python-3.6.10/python ;" > user-config.jam > > > >My folder structure is as follows: > > > >buildBoost.sh (the script above) > >/Python-3.6.10 (contains the python source code and binaries that I've > >build myself) > > /boost_1_73_0 (boost source code as downloaded by the script) > > /build_boost (output folder as specified by prefix) > > > >When do I need to write this user-config.jam file? What are the > >compilation scripts looking for - can this process be debugged? > >I also have boost installed via apt - now I think that everytime I call > >b2 or bjam it uses > >the global versions of these programs, instead of the ones contained in > >the boost-directory I'm compiling - is that an issue? > > > >Thanks in advance. > >torsten > >_______________________________________________ Cplusplus-sig mailing > >list Cplusplus-sig at python.org > >https://mail.python.org/mailman/listinfo/cplusplus-sig > > > >_______________________________________________ > >Cplusplus-sig mailing list > >Cplusplus-sig at python.org > >https://mail.python.org/mailman/listinfo/cplusplus-sig > > -- > Sent from my smartphone. > Please excuse my brevity. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/cplusplus-sig/attachments/20200430/3dc80afb/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > > > ------------------------------ > > End of Cplusplus-sig Digest, Vol 124, Issue 5 > ********************************************* > -- Bayforest Capital Limited ( Bayforest?) is an Appointed Representative of G10 Capital Limited. G10 Capital Limited is authorised and regulated by the Financial Conduct Authority, registration number 648953. The information contained in this transmission may contain privileged and confidential information.? It is intended only for the use of the person(s) named above.? If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication 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 Bayforest Capital Limited and Bayforest Technologies Limited.? If you are not the intended recipient, please contact the sender by replying to this e-mail and destroy all copies of this e-mail (and any attachment(s)) from your system.? To reply to our e-mail administrator directly, please send an e-mail to admin at bayforest.ai . -------------- next part -------------- An HTML attachment was scrubbed... URL: From deepanshnagaria at gmail.com Fri May 1 01:17:55 2020 From: deepanshnagaria at gmail.com (deepansh) Date: Fri, 1 May 2020 00:17:55 -0500 (CDT) Subject: [C++-sig] Passing vector as argument to python function using boost python Message-ID: <1588310275430-0.post@n4.nabble.com> I followed https://riptutorial.com/boost/example/25280/wrapping-std--vector-in-boost-python but how to include vector_indexing_suite for passing vector as argument? I am getting the error: No Python class registered for C++ class std::vector > when running the code: BOOST_PYTHON_MODULE(Strat) { bp::class_ >("Long_vec") .def(bp::vector_indexing_suite >()) ; bp::class_("Strat") .def("gen_fibonacci", &Strat::gen_fibonacci) ; } int main() { try { Py_Initialize(); // register the python module we created, so our script can import it PyImport_AppendInittab("Strat",&initStrat); //PyImport_AppendInittab("StrategyFramework", &initStrategyFramework); // import the __main__ module and obtain the globals dict bp::object main = bp::import("__main__"); bp::object globals = main.attr("__dict__"); // import our strategy.py file bp::object module = import("Strat", "./python_plugins/strat1.py", globals); // obtain the strategy class and instantiate one bp::object Strategy = module.attr("Strategy"); bp::object strategy = Strategy(); std::cout<<"not here"; Helper a; strategy.attr("gen_fibonacci")(boost::ref(a.v),1,100); long ans=a.sum_series(a.v); std::cout<<"done"; return 0; } catch(const bp::error_already_set&) { std::cerr << ">>> Error! Uncaught exception:\n"; PyErr_Print(); return 1; } } what am i doing wrong? strat1.py: from Strat import * class Strategy: def gen_fibonacci(self,l,ind,n): num = 3 t1 = 0 t2 = 1 nextTerm = 0 i=1 if ind==1: l.append(0) l.append(1) i=3 if ind==2: l.append(1) i=2 while i=ind: i=i+1 l.append(nextTerm) num=num+1 return 0 -- Sent from: http://boost.2283326.n4.nabble.com/Python-c-sig-f2696818.html From carlos_wurt at zohomail.eu Tue May 12 06:11:36 2020 From: carlos_wurt at zohomail.eu (Carlos Duran) Date: Tue, 12 May 2020 12:11:36 +0200 Subject: [C++-sig] Beginner - How to extract a Python Class that inherits from C++ Class Message-ID: <172085e498d.e3349fd230005.5688831514627266454@zohomail.eu> Hi, I was being researching the Boost.Python library, this archive and stackoverflow but I couldn't find the correct answer. I tried the following: -First: I created the C++ Class. -------------------------------------------------------------------------- user at host ~/ProjectFolder: cat lib/DemiComponent.hpp #pragma once #include namespace DemiWu { ?? ?class Component ?? ?{ ?? ??? ?public: ?? ??? ?Component(){}; ?? ??? ?virtual ~Component(){}; ?? ??? ?virtual void on_create(){}; ?? ?}; ?? ?class ComponentWrap : public Component, public boost::python::wrapper ?? ?{ ?? ??? ?public: ?? ??? ?void empty(){} ?? ??? ?virtual void on_create() ?? ??? ?{ ?? ??? ??? ?this->get_override("on_create")(); ?? ??? ?} ?? ?}; ?? ?void import_component() ?? ?{ ?? ??? ?using namespace DemiWu; ?? ? ?? ?using namespace boost::python; ?? ??? ?class_("Component") ?? ??? ??? ?.def("on_create", &Component::on_create, &ComponentWrap::empty); ?? ?}; }; -------------------------------------------------------------------------- -Second: I exported to Python -------------------------------------------------------------------------- user at host ~/ProjectFolder: cat lib/DemiWu.hpp #pragma once #include #include BOOST_PYTHON_MODULE(DemiWu) { ?? ?DemiWu::import_component(); } -------------------------------------------------------------------------- ?cat lib/DemiWu.cpp #include --------------------------- -Third: I used Meson to compile, but I think that is not important. The module works on python3 interpreter. -------------------------------------------------------------------------- -Fourth: I wrote a Python Class that inherit form the C++ Class DemiWu::Component. -------------------------------------------------------------------------- user at host ~/ProjectFolder: cat build/test.py import DemiWu class test(DemiWu.Component): ??? def __init__(self): ??????? self.x = 10; ??????? self.y = 20; ??? def on_create(self): ??????? print("(",self.x, ",",self.y,")", sep="") ??????? self.x = self.x + 1 ??????? self.y = self.y + 1 -------------------------------------------------------------------------- Fifth: I write a program that extracts the test Python Class. -------------------------------------------------------------------------- user at host ~/ProjectFolder: cat src/DemiWu.cpp #include #include #include #include using namespace boost::python; using namespace DemiWu; int main() { ?? ?PyImport_AppendInittab("DemiWu", PyInit_DemiWu); ?? ?Py_Initialize(); ?? ?object main = import("__main__"); ?? ??? ?object global = main.attr("__dict__"); ?? ?PySys_SetPath(L"."); ?? ?global["test"] = import("test"); ?? ?object obj = eval("test.test()", global); ?? ?extract ex(obj); ?? ?if(ex.check()){ ??? ??? ?Component* b=ex(); ????? ?? b->on_create();? ?? ??? ? std::cout << "SUCCESS\n"; ?? ??? ? return 0; ?? ?} else { ?? ??? ?std::cout << "FAIL\n"; ?? ??? ?return 1; ?? ?} } -------------------------------------------------------------------------- Sixth: Compile the program successfully. -------------------------------------------------------------------------- Seventh: Execute and... the output is always "FAIL". -------------------------------------------------------------------------- How can I fix it? What did I miss? Thank you for your attention, Carlos PS: Sorry for the format of the mail, but I can't express on English well. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lewis.evans at bayforest.ai Wed May 13 09:37:35 2020 From: lewis.evans at bayforest.ai (Lewis Evans) Date: Wed, 13 May 2020 14:37:35 +0100 Subject: [C++-sig] Cplusplus-sig Digest, Vol 125, Issue 3 In-Reply-To: References: Message-ID: Hello, I suggest to avoid eval, in main() instead, after "import test" in main(): funcObj = global["test"].attr("test") // assuming your global["test"] is a successfully imported module resultObj = funcObj() then check resultObj: as well as extract-and-check, you can query repr/str, and is_none(), and check attributes __class__ and __class__.__name__ in boost-python say someObject.attr("attributeNameHere") Best Lewis Bayforest Technologies Limited 48 Dover St, Mayfair London W1S 4FF work1: +44 203 968 5167 email: lewis.evans at bayforest.ai web: https://bayforest.ai/ On Tue, May 12, 2020 at 5:00 PM wrote: > Send Cplusplus-sig mailing list submissions to > cplusplus-sig at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/cplusplus-sig > or, via email, send a message with subject or body 'help' to > cplusplus-sig-request at python.org > > You can reach the person managing the list at > cplusplus-sig-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Cplusplus-sig digest..." > > > Today's Topics: > > 1. Beginner - How to extract a Python Class that inherits from > C++ Class (Carlos Duran) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 12 May 2020 12:11:36 +0200 > From: Carlos Duran > To: "cplusplus-sig" > Subject: [C++-sig] Beginner - How to extract a Python Class that > inherits from C++ Class > Message-ID: > <172085e498d.e3349fd230005.5688831514627266454 at zohomail.eu> > Content-Type: text/plain; charset="utf-8" > > Hi, > > > > I was being researching the Boost.Python library, this archive and > stackoverflow but I couldn't find the correct answer. > > > > I tried the following: > -First: I created the C++ Class. > -------------------------------------------------------------------------- > > user at host ~/ProjectFolder: cat lib/DemiComponent.hpp > > #pragma once > > #include > > > > namespace DemiWu > > { > > ?? ?class Component > > ?? ?{ > > ?? ??? ?public: > > ?? ??? ?Component(){}; > > ?? ??? ?virtual ~Component(){}; > > ?? ??? ?virtual void on_create(){}; > > ?? ?}; > > > > ?? ?class ComponentWrap : public Component, public > boost::python::wrapper > > ?? ?{ > > ?? ??? ?public: > > ?? ??? ?void empty(){} > > ?? ??? ?virtual void on_create() > > ?? ??? ?{ > > ?? ??? ??? ?this->get_override("on_create")(); > > ?? ??? ?} > > ?? ?}; > > > > ?? ?void import_component() > > ?? ?{ > > ?? ??? ?using namespace DemiWu; > > ?? ? ?? ?using namespace boost::python; > > ?? ??? ?class_("Component") > > ?? ??? ??? ?.def("on_create", &Component::on_create, > &ComponentWrap::empty); > > > > ?? ?}; > > }; > > -------------------------------------------------------------------------- > > > > -Second: I exported to Python > > -------------------------------------------------------------------------- > > user at host ~/ProjectFolder: cat lib/DemiWu.hpp > > #pragma once > > #include > > #include > > > > BOOST_PYTHON_MODULE(DemiWu) > > { > > ?? ?DemiWu::import_component(); > > } > > -------------------------------------------------------------------------- > > ?cat lib/DemiWu.cpp > > #include > > --------------------------- > > > > -Third: I used Meson to compile, but I think that is not important. The > module works on python3 interpreter. > > -------------------------------------------------------------------------- > > > > -Fourth: I wrote a Python Class that inherit form the C++ Class > DemiWu::Component. > > -------------------------------------------------------------------------- > > user at host ~/ProjectFolder: cat build/test.py > > import DemiWu > > > > class test(DemiWu.Component): > > ??? def __init__(self): > > ??????? self.x = 10; > > ??????? self.y = 20; > > > > ??? def on_create(self): > > ??????? print("(",self.x, ",",self.y,")", sep="") > > ??????? self.x = self.x + 1 > > ??????? self.y = self.y + 1 > > -------------------------------------------------------------------------- > > > > Fifth: I write a program that extracts the test Python Class. > > -------------------------------------------------------------------------- > > user at host ~/ProjectFolder: cat src/DemiWu.cpp > > #include > > #include > > #include > > #include > > using namespace boost::python; > > using namespace DemiWu; > > > > int main() > > { > > ?? ?PyImport_AppendInittab("DemiWu", PyInit_DemiWu); > > ?? ?Py_Initialize(); > > ?? ?object main = import("__main__"); > > ?? ??? ?object global = main.attr("__dict__"); > > ?? ?PySys_SetPath(L"."); > > ?? ?global["test"] = import("test"); > > ?? ?object obj = eval("test.test()", global); > > ?? ?extract ex(obj); > > ?? ?if(ex.check()){ > > ??? ??? ?Component* b=ex(); > > ????? ?? b->on_create();? > > ?? ??? ? std::cout << "SUCCESS\n"; > > ?? ??? ? return 0; > > ?? ?} else { > > ?? ??? ?std::cout << "FAIL\n"; > > ?? ??? ?return 1; > > ?? ?} > > } > > -------------------------------------------------------------------------- > > > > Sixth: Compile the program successfully. > > -------------------------------------------------------------------------- > > > > Seventh: Execute and... the output is always "FAIL". > > -------------------------------------------------------------------------- > > > > How can I fix it? What did I miss? > > > > Thank you for your attention, > > > > Carlos > > > > PS: Sorry for the format of the mail, but I can't express on English well. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/cplusplus-sig/attachments/20200512/ef615230/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > > > ------------------------------ > > End of Cplusplus-sig Digest, Vol 125, Issue 3 > ********************************************* > -- Bayforest Capital Limited ( Bayforest?) is an Appointed Representative of G10 Capital Limited. G10 Capital Limited is authorised and regulated by the Financial Conduct Authority, registration number 648953. The information contained in this transmission may contain privileged and confidential information.? It is intended only for the use of the person(s) named above.? If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication 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 Bayforest Capital Limited and Bayforest Technologies Limited.? If you are not the intended recipient, please contact the sender by replying to this e-mail and destroy all copies of this e-mail (and any attachment(s)) from your system.? To reply to our e-mail administrator directly, please send an e-mail to admin at bayforest.ai . -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos_wurt at zohomail.eu Wed May 13 11:50:16 2020 From: carlos_wurt at zohomail.eu (Carlos Duran) Date: Wed, 13 May 2020 17:50:16 +0200 Subject: [C++-sig] Cplusplus-sig Digest, Vol 125, Issue 3 Message-ID: <1720ebab660.12aad1dbc94224.6884088036261319526@zohomail.eu> Hello again, I rewrite part of the code, but I didn't find my error. My new code is: cat ../src/DemiWu.cpp #include #include #include #include #include using namespace boost::python; using namespace DemiWu; #if PY_MAJOR_VERSION >= 3 #?? define INIT_MODULE PyInit_DemiWu ??? extern "C" PyObject* INIT_MODULE(); #else #?? define INIT_MODULE initDemiwu ??? extern "C" void INIT_MODULE(); #endif int main() { ????? PyImport_AppendInittab((char*)"DemiWu", INIT_MODULE); ????? Py_Initialize(); ????? object main = import("__main__"); ????? object global = main.attr("__dict__"); ????? PySys_SetPath(L"."); ????? global["test"] = import("test"); // How can I check the import? ????? object funcObj = global["test"].attr("test"); ????? std::cout << std::boolalpha; ????? std::cout << funcObj.is_none() << "\n"; // funcObj.is_none() == false ????? object resultObj = funcObj(); ????? std::cout << resultObj.is_none() << "\n"; // resultObj.is_none() == false ????? // I suppose that in "real" code I need to check every time I use attr method. ????? extract exclass(funcObj.attr("__class__").attr("__name__")); ????? if(exclass.check()) ????? ????? std::cout << "test.test.__class__.__name__: " << exclass() << "\n"; // exclass() == "class" ????? extract exclass2(resultObj.attr("__class__").attr("__name__")); ????? if(exclass2.check()) ????? ????? std::cout << "test.test().__class__.__name__: " << exclass2() << "\n"; // exclass2() == "test" ????? extract exbase(funcObj.attr("__base__").attr("__name__")); ????? if(exbase.check()) ????? ????? std::cout << "test.test.__base__.__name__: " << exbase() << "\n"; // exbase() == "Component" ????? // It seems that resultObj is correct, I think that I am using extract<> function wrong. ????? extract ex(resultObj); ????? if(ex.check()){ ????? ????? Component * const b=ex(); ????? ????? b->on_create(); ? ????? ????? std::cout << "SUCCESS\n"; ????? ????? return 0; ????? } else { ????? ????? std::cout << "FAIL\n"; // And again the program jumps here. ????? ????? return 1; ????? } } And the execution: ./DemiWu false false test.test.__class__.__name__: class test.test().__class__.__name__: test test.test.__base__.__name__: Component FAIL Thank you for your response Carlos -------------- next part -------------- An HTML attachment was scrubbed... URL: From lewis.evans at bayforest.ai Thu May 14 13:20:08 2020 From: lewis.evans at bayforest.ai (Lewis Evans) Date: Thu, 14 May 2020 18:20:08 +0100 Subject: [C++-sig] Cplusplus-sig Digest, Vol 125, Issue 5 In-Reply-To: References: Message-ID: I suggest (a) renaming as test.test is confusing, eg call the file/module test_file, and the class test_class (b) I think from your previous post that test.test() simply calls the constructor for class test, and this constructor is defined in python, returning an object not a pointer, so perhaps try extract not extract Best Lewis Bayforest Technologies Limited 48 Dover St, Mayfair London W1S 4FF work1: +44 203 968 5167 email: lewis.evans at bayforest.ai web: https://bayforest.ai/ On Thu, May 14, 2020 at 5:00 PM wrote: > Send Cplusplus-sig mailing list submissions to > cplusplus-sig at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/cplusplus-sig > or, via email, send a message with subject or body 'help' to > cplusplus-sig-request at python.org > > You can reach the person managing the list at > cplusplus-sig-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Cplusplus-sig digest..." > > > Today's Topics: > > 1. Re: Cplusplus-sig Digest, Vol 125, Issue 3 (Carlos Duran) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 13 May 2020 17:50:16 +0200 > From: Carlos Duran > To: "cplusplus-sig" > Subject: Re: [C++-sig] Cplusplus-sig Digest, Vol 125, Issue 3 > Message-ID: > <1720ebab660.12aad1dbc94224.6884088036261319526 at zohomail.eu> > Content-Type: text/plain; charset="utf-8" > > Hello again, > > > > I rewrite part of the code, but I didn't find my error. > > My new code is: > > cat ../src/DemiWu.cpp > > #include > > > > #include > > #include > > #include > > #include > > > > using namespace boost::python; > > using namespace DemiWu; > > > > #if PY_MAJOR_VERSION >= 3 > > #?? define INIT_MODULE PyInit_DemiWu > > ??? extern "C" PyObject* INIT_MODULE(); > > #else > > #?? define INIT_MODULE initDemiwu > > ??? extern "C" void INIT_MODULE(); > > #endif > > > > int main() > > { > > ????? PyImport_AppendInittab((char*)"DemiWu", INIT_MODULE); > > ????? Py_Initialize(); > > ????? object main = import("__main__"); > > ????? object global = main.attr("__dict__"); > > ????? PySys_SetPath(L"."); > > ????? global["test"] = import("test"); // How can I check the import? > > > > ????? object funcObj = global["test"].attr("test"); > > ????? std::cout << std::boolalpha; > > ????? std::cout << funcObj.is_none() << "\n"; // funcObj.is_none() == false > > ????? object resultObj = funcObj(); > > ????? std::cout << resultObj.is_none() << "\n"; // resultObj.is_none() == > false > > > > ????? // I suppose that in "real" code I need to check every time I use > attr method. > > ????? extract > exclass(funcObj.attr("__class__").attr("__name__")); > > ????? if(exclass.check()) > > ????? ????? std::cout << "test.test.__class__.__name__: " << exclass() << > "\n"; // exclass() == "class" > > ????? extract > exclass2(resultObj.attr("__class__").attr("__name__")); > > ????? if(exclass2.check()) > > ????? ????? std::cout << "test.test().__class__.__name__: " << exclass2() > << "\n"; // exclass2() == "test" > > ????? extract > exbase(funcObj.attr("__base__").attr("__name__")); > > ????? if(exbase.check()) > > ????? ????? std::cout << "test.test.__base__.__name__: " << exbase() << > "\n"; // exbase() == "Component" > > ????? // It seems that resultObj is correct, I think that I am using > extract<> function wrong. > > ????? extract ex(resultObj); > > ????? if(ex.check()){ > > ????? ????? Component * const b=ex(); > > ????? ????? b->on_create(); ? > > ????? ????? std::cout << "SUCCESS\n"; > > ????? ????? return 0; > > ????? } else { > > ????? ????? std::cout << "FAIL\n"; // And again the program jumps here. > > ????? ????? return 1; > > ????? } > > } > > > > And the execution: > > ./DemiWu > > false > > false > > test.test.__class__.__name__: class > > test.test().__class__.__name__: test > > test.test.__base__.__name__: Component > > FAIL > > > > Thank you for your response > > > > Carlos > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/cplusplus-sig/attachments/20200513/e8d19d13/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > > > ------------------------------ > > End of Cplusplus-sig Digest, Vol 125, Issue 5 > ********************************************* > -- Bayforest Capital Limited ( Bayforest?) is an Appointed Representative of G10 Capital Limited. G10 Capital Limited is authorised and regulated by the Financial Conduct Authority, registration number 648953. The information contained in this transmission may contain privileged and confidential information.? It is intended only for the use of the person(s) named above.? If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication 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 Bayforest Capital Limited and Bayforest Technologies Limited.? If you are not the intended recipient, please contact the sender by replying to this e-mail and destroy all copies of this e-mail (and any attachment(s)) from your system.? To reply to our e-mail administrator directly, please send an e-mail to admin at bayforest.ai . -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos_wurt at zohomail.eu Thu May 14 14:34:36 2020 From: carlos_wurt at zohomail.eu (Carlos Duran) Date: Thu, 14 May 2020 20:34:36 +0200 Subject: [C++-sig] Cplusplus-sig Digest, Vol 125, Issue 5 Message-ID: <17214778506.e751c195157288.4569798239162510324@zohomail.eu> Hi, I tried that solutions but they didn't work, furthermore, I thought that polymorphisim only works on pointers. I also tried changing to reference(Component&) and adding a HeldType in the import module: class_*/, boost::noncopyable>("Component", init<>()) but all of this is futile. Thank you Carlos -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos_wurt at zohomail.eu Sat May 16 03:00:48 2020 From: carlos_wurt at zohomail.eu (Carlos Duran) Date: Sat, 16 May 2020 09:00:48 +0200 Subject: [C++-sig] Beginner - How to extract a Python Class that inherits from C++ Class Message-ID: <1721c4909ba.d4e726c884005.2592559232324620859@zohomail.eu> Hi, I find the solution, first of all I need to add the initializer on the C++ class import: ????? ????? class_, boost::noncopyable>("Component", init<>()) ????? // I additionally added a Holder, but is not necessary. Then I add the base class initializer on the python class: ????? class Derived(DemiWu.Component): ????? ????? def __init__(self): ????? ????? ????? DemiWu.Component.__init__(self) I only find a problem, if a python class call the print function it doesn't work. Thanks, Carlos -------------- next part -------------- An HTML attachment was scrubbed... URL: From carlos_wurt at zohomail.eu Sat May 16 03:15:11 2020 From: carlos_wurt at zohomail.eu (Carlos Duran) Date: Sat, 16 May 2020 09:15:11 +0200 Subject: [C++-sig] Beginner How to debug a python class extracted in C++ Message-ID: <1721c563424.f120244784121.4788003184745915412@zohomail.eu> Hi, I recently started a Boost Python project, https://mail.python.org/pipermail/cplusplus-sig/2020-May/017585.html but I need to debug my python classes extracted in C++ in the main program. The only referece that I find to this topic is in https://www.boost.org/doc/libs/1_73_0/libs/python/doc/html/faq/how_do_i_debug_my_python_extensi.html How can I solve this? I am only using the gdb debugger. Thank you for your attention, Carlos -------------- next part -------------- An HTML attachment was scrubbed... URL: From giaym.mail at gmail.com Thu May 14 15:11:19 2020 From: giaym.mail at gmail.com (gia .) Date: Thu, 14 May 2020 14:11:19 -0500 Subject: [C++-sig] BOOST_PYTHON_TYPE_ID_NAME on Windows In-Reply-To: <17214778506.e751c195157288.4569798239162510324@zohomail.eu> References: <17214778506.e751c195157288.4569798239162510324@zohomail.eu> Message-ID: Good day, I'm having some hard to debug error likely related to shared pointers but I don't even know if it is a boost python issue or outdated configuration. I'm using boost 1.72 and msvc 2017 (15.9.7). What I noticed is that when I build on Linux (devtoolset 6), execution reaches further -fails in the end but checking with the debugger things seemed good even past the point I fail on Windows. Linux seems to enable the define BOOST_PYTHON_TYPE_ID_NAME, and this changes how the existence of valid converters is tested. On Linux an (existing) converter is found because it takes the path of that define. On Windows, the existing converter is reported as not. I tried to add the define to the command line and the build passed. But execution failed when loading the c++ extension into python with an assert during one of the registers: "slot->m_to_python == 0". So, before I go on a useless hunt, should BOOST_PYTHON_TYPE_ID_NAME (or lack of) work on Windows? -------------- next part -------------- An HTML attachment was scrubbed... URL: