[C++-sig] Cplusplus-sig Digest, Vol 125, Issue 5

Lewis Evans lewis.evans at bayforest.ai
Thu May 14 13:20:08 EDT 2020


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<Component> not extract<Component*>

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 <cplusplus-sig-request at python.org> 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 <carlos_wurt at zohomail.eu>
> To: "cplusplus-sig" <cplusplus-sig at python.org>
> 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 <boost/python.hpp>
>
>
>
> #include <DemiComponent.hpp>
>
> #include <DemiWu.hpp>
>
> #include <iostream>
>
> #include <string>
>
>
>
> 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<std::string>
> exclass(funcObj.attr("__class__").attr("__name__"));
>
> ????? if(exclass.check())
>
> ????? ????? std::cout << "test.test.__class__.__name__: " << exclass() <<
> "\n"; // exclass() == "class"
>
> ????? extract<std::string>
> exclass2(resultObj.attr("__class__").attr("__name__"));
>
> ????? if(exclass2.check())
>
> ????? ????? std::cout << "test.test().__class__.__name__: " << exclass2()
> << "\n"; // exclass2() == "test"
>
> ????? extract<std::string>
> 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<Component*> 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 <mailto:admin at bayforest.ai>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20200514/d16d0fd0/attachment.html>


More information about the Cplusplus-sig mailing list