From ndbecker2 at gmail.com Sun Sep 1 23:36:10 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 01 Sep 2013 17:36:10 -0400 Subject: [C++-sig] double free segfaults References: Message-ID: Ellery Newcomer wrote: > Hello all. > > I have been trying to wrap a third party C++ library with boost::python > (first time using boost::python!), and on a very simple example I seem to > be getting double free segfaults, so I am here soliciting advice. Does > anything stand out? > > In gdb, I can't seem to catch it calling any particular destructor more > than once. > > In pure c++, the class I am wrapping does not exhibit any such segfaults on > simple usage, eg > { > CMOOSApp *app = new CMOOSApp(); > delete app; > } > > and other classes in the library do not exhibit such segfaults when I wrap > them. > > c++: > > #include > #include > > using namespace boost::python; > > BOOST_PYTHON_MODULE(MOOSCore) > { > class_("MOOSApp"); > } > > python: > > import MOOSCore > > thing = MOOSCore.MOOSApp() > > results: > > $ python test.py > *** glibc detected *** python: double free or corruption (out): > 0x0000000000f92b50 *** > ======= Backtrace: ========= > /lib64/libc.so.6[0x3b8a4760e6] > /lib64/libc.so.6[0x3b8a478c13] > /usr/lib64/libboost_python.so.5(_ZN5boost6python15instance_holder10deallocateEP7_objectPv+0x15) [0x7f15ee57a0b5] > /usr/lib64/libboost_python.so.5(+0x2a394)[0x7f15ee57a394] > /usr/lib64/libpython2.6.so.1.0[0x3b9de9a715] > /usr/lib64/libpython2.6.so.1.0[0x3b9de78287] > /usr/lib64/libpython2.6.so.1.0(PyDict_SetItem+0xa7)[0x3b9de7acf7] > /usr/lib64/libpython2.6.so.1.0(_PyModule_Clear+0x16d)[0x3b9de7c66d] > /usr/lib64/libpython2.6.so.1.0(PyImport_Cleanup+0x18f)[0x3b9dee987f] > /usr/lib64/libpython2.6.so.1.0(Py_Finalize+0x11b)[0x3b9def28ab] > /usr/lib64/libpython2.6.so.1.0(Py_Main+0x596)[0x3b9deff2d6] > /lib64/libc.so.6(__libc_start_main+0xfd)[0x3b8a41ecdd] > python[0x400649] > > > the class CMOOSApp is defined here: > > https://oceanai.mit.edu/svn/moos-ivp-aro/releases/moos-ivp-13.5/MOOS_V10Beta_rc2/MOOSCore/Core/libMOOS/App/include/MOOS/libMOOS/App/MOOSApp.h > > my complete code can be found here on the off chance someone wants to > tinker with it: > > https://bitbucket.org/ariovistus/moos-python These issues can usually be traced using valgrind From arbitraryvalue at gmail.com Fri Sep 6 18:51:47 2013 From: arbitraryvalue at gmail.com (Alex K) Date: Fri, 6 Sep 2013 12:51:47 -0400 Subject: [C++-sig] Segfault when passing pointer from C++ to Python via Boost Python Message-ID: Hello all, I am having issues passing pointers from C++ to python, as I describe here: http://stackoverflow.com/questions/18646694/pass-pointer-from-c-to-python-w-boost-python In short, even the example of "Raw C++ pointers" from here: https://wiki.python.org/moin/boost.python/PointersAndSmartPointers causes a segfault when I compile and run it, although I can use other features of Boost Python successfully. The crash appears to be a segfault from invoke.hpp, in this function: template inline PyObject* invoke(invoke_tag_, RC const& rc, F& f BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(1, N, AC, & ac) ) { return rc(f( BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, ac, () BOOST_PP_INTERCEPT) )); } Does anyone have any suggestions? Thanks, Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: From simwarg at gmail.com Tue Sep 10 14:37:39 2013 From: simwarg at gmail.com (Simon W) Date: Tue, 10 Sep 2013 14:37:39 +0200 Subject: [C++-sig] import extension module in python on OSX Message-ID: Hello, I've compiled the example code for Boost.Python: #include char const* greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } It compiles and I got an BoostPythonTest.dylib produced by Xcode. I've tried to put that file in my site-packages folder and som other places in order to import it into the interpreter like: import BoostPythonTest Traceback (most recent call last): File "", line 1, in ImportError: No module named 'BoostPythonTest' >>> I've tried to rename it to BoostPythonTest.so and .pyd and so on: But it doesn't work. What is the proper extension name for boost python modules on OSX? I'm using boost 1.53, OSX 1.8 and Python 3.2 Thanks in advance, Simon -------------- next part -------------- An HTML attachment was scrubbed... URL: From wmamrak at gmail.com Thu Sep 12 00:54:22 2013 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Thu, 12 Sep 2013 00:54:22 +0200 Subject: [C++-sig] import extension module in python on OSX In-Reply-To: References: Message-ID: why didn't you follow the example to the end? Your module is called 'hello_ext'. 2013/9/10 Simon W : > Hello, > > I've compiled the example code for Boost.Python: > > #include > > char const* greet() > > { > > return "hello, world"; > > } > > BOOST_PYTHON_MODULE(hello_ext) > > { > > using namespace boost::python; > > def("greet", greet); > > } > > > It compiles and I got an BoostPythonTest.dylib produced by Xcode. I've tried > to put that file in my site-packages folder and som other places in order to > import it into the interpreter like: > > import BoostPythonTest > > Traceback (most recent call last): > > File "", line 1, in > > ImportError: No module named 'BoostPythonTest' > >>>> > > I've tried to rename it to BoostPythonTest.so and .pyd and so on: But it > doesn't work. What is the proper extension name for boost python modules on > OSX? I'm using boost 1.53, OSX 1.8 and Python 3.2 > > Thanks in advance, > Simon > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig From wamplerd at gmail.com Sun Sep 15 00:59:42 2013 From: wamplerd at gmail.com (Dave Wampler) Date: Sat, 14 Sep 2013 18:59:42 -0400 Subject: [C++-sig] pyplusplus generate for strict with char* member Message-ID: <-8316938237133242055@unknownmsgid> When I try to expose a struct with a char* member, I get a warning that pointer members aren't supported currently. Considering char* is so common in existing APIs, is there a current workaround or example (like conversion to std::string)? Thanks, Dave From ismail.savaskan at roketsan.com.tr Tue Sep 17 09:47:26 2013 From: ismail.savaskan at roketsan.com.tr (=?iso-8859-3?Q?=A9smail_SAVA=AAKAN?=) Date: Tue, 17 Sep 2013 07:47:26 +0000 Subject: [C++-sig] Py++: How to pickle a boost.python object? Message-ID: Hi, Is it possible to pickle an object loaded from a c++ library which contains py++ auto-generated code? For example a c++ struct: struct Coordinate { int x; int y; }; And its wrapper: BOOST_PYTHON_MODULE(pyplusplus_test){ bp::class_< Coordinate >( "Coordinate" ) .def_readwrite( "x", &Coordinate::x ) .def_readwrite( "y", &Coordinate::y ); } I built pyplusplus_test.so libray. Then I wrote a script such as: import sys import pickle sys.path.append('.') import pyplusplus_test cord = pyplusplus_test.Coordinate() cord.x = 23 cord.y = -11 pickle.dumps(cord) But it failed. The message is "RuntimeError: Pickling of "pyplusplus_test.Coordinate" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)" I know that I can arrange generated code adding def_pickle() calls. But I want to generate wrappers automatically. Any suggestion? Thanks. Bu e-posta mesaj? ve ekleri g?nderildi?i ki?i ya da kuruma ?zeldir ve gizlidir. Ayr?ca hukuken de gizli olabilir. Hi?bir ?ekilde ???nc? ki?ilere a??klanamaz ve yay?nlanamaz. Mesaj?n yetkili al?c?s? de?ilseniz hi?bir k?sm?n? kopyalayamaz, ba?kas?na g?nderemez veya hi?bir ?ekilde kullanamazs?n?z. E?er mesaj?n yetkili al?c?s? veya yetkili al?c?s?na iletmekten sorumlu ki?i siz de?ilseniz, l?tfen mesaj? sisteminizden siliniz ve g?ndereni uyar?n?z. G?nderen ve ROKETSAN ROKET SANAY?? VE T?CARET A.?. bu mesaj?n i?erdi?i bilgilerin do?rulu?u, b?t?nl??? ve g?ncelli?i konusunda bir garanti vermemektedir. Mesaj?n i?eri?inden, iletilmesinden, al?nmas?ndan, saklanmas?ndan, gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve sisteminizde yaratabilece?i zararlardan ROKETSAN ROKET SANAY?? VE T?CARET A.?. sorumlu tutulamaz. ?irketimiz hakk?nda bilgi almak i?in l?tfen web sitemizi ziyaret ediniz. www.roketsan.com.tr This e-mail and its attachments are private and confidential to the exclusive use of the individual or entity to whom it is addressed. It may also be legally confidential. Any disclosure, distribution or other dissemination of this message to any third party is strictly prohibited. If you are not the intended recipient, you may not copy, forward, send or use any part of it. If you are not the intended recipient or the person who is responsible to transmit to the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message and its attachments. The sender and ROKETSAN ROKET SANAY?? VE T?CARET A.S. do not warrant for the accuracy, currency, integrity or correctness of the information in the message and its attachments. ROKETSAN ROKET SANAY?? VE T?CARET A.S. shall have no liability with regard to the information contained in the message, its transmission, reception, storage, preservation of confidentiality, viruses or any damages caused in anyway to your computer system. To get information about our company please visit our web site. www.roketsan.com.tr -------------- next part -------------- An HTML attachment was scrubbed... URL: From developerdeveloper at yahoo.com Thu Sep 19 15:23:37 2013 From: developerdeveloper at yahoo.com (Q Q) Date: Thu, 19 Sep 2013 06:23:37 -0700 (PDT) Subject: [C++-sig] boost.python: Is a way to auto-fill __dict__ attribute? Message-ID: <1379597017.44902.YahooMailNeo@web161705.mail.bf1.yahoo.com> Hi, The python objects exposed from C++ classes via boost.python have empty __dict__ attributes. I generated python wrappers using py++. Can I access __dict__ attributes for boost.python objects? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kassiopik at gmail.com Sat Sep 21 16:52:31 2013 From: kassiopik at gmail.com (Kassiopi Kassiopi2) Date: Sat, 21 Sep 2013 17:52:31 +0300 Subject: [C++-sig] Boost python simple interfacing Message-ID: Hi, I want to call a c++ function from an embedded python shell, using boost python. All the examples I've seen online describe how to expose a whole class or some functions, but all cases refer to *standalone* parts of code. My case is different though. The function I want to expose is not standalone, and has a dependency: ------- start of documentModule.cpp -------- #include #include void newDocument( bool makeActive ) { // depends on commandManager here GetCommandMananager()->submitCommand( new newDocumentCmd( makeActive ) ); } BOOST_PYTHON(documentModule) { using namespace boost::python; def( "newDocument", myCadLib::pythonCommands::newDocument, arg("makeActive") ); } ------- end of documentModule.cpp -------- In reality the situation is more complicated and there are more dependencies than the one mentioned above. After generating a .so file with distutils, when I start my application and I attempt to load the module (.so file) in the embedded python shell I get an undefined symbols error complaining about the commandManager class. Of course this is a reasonable request from python and I understand that. However, I don't really care to generate a standalone python module per se. I just want it to work in my application's embedded python shell. Additionally, it wouldn't be meaningful to have the commandManager class exposed as well, since this is part of my applications internal structure. Is what I am asking possible with boost python? In the past I have used SWIG for that, and it generated some additional .cpp and .h files, as well as a .py module. I can live with generating additional source and header files if it is an issue for boost python and I don't care to have a standalone python module, as long as it works inside my application. I couldn't find anything online as well. All examples I could find where similar to the boost python tutorial, with standalone parts of code. Thank you in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cedric.gestes at gmail.com Mon Sep 23 10:04:00 2013 From: cedric.gestes at gmail.com (Cedric GESTES) Date: Mon, 23 Sep 2013 10:04:00 +0200 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: Message-ID: On Sep 23, 2013 1:48 AM, "Kassiopi Kassiopi2" wrote: > > Hi, > > I want to call a c++ function from an embedded python shell, using boost python. All the examples I've seen online describe how to expose a whole class or some functions, but all cases refer to standalone parts of code. > My case is different though. The function I want to expose is not standalone, and has a dependency: > > ------- start of documentModule.cpp -------- > #include > #include > > void newDocument( bool makeActive ) { > // depends on commandManager here > GetCommandMananager()->submitCommand( new newDocumentCmd( makeActive ) ); > } > > BOOST_PYTHON(documentModule) { > using namespace boost::python; > def( "newDocument", myCadLib::pythonCommands::newDocument, arg("makeActive") ); > } > ------- end of documentModule.cpp -------- > > In reality the situation is more complicated and there are more dependencies than the one mentioned above. > After generating a .so file with distutils, when I start my application and I attempt to load the module (.so file) in the embedded python shell I get an undefined symbols error complaining about the commandManager class. do you link the library containing commandManager to your python extension? > Of course this is a reasonable request from python and I understand that. However, I don't really care to generate a standalone python module per se. I just want it to work in my application's embedded python shell. Additionally, it wouldn't be meaningful to have the commandManager class exposed as well, since this is part of my applications internal structure. > Is what I am asking possible with boost python? In the past I have used SWIG for that, and it generated some additional .cpp and .h files, as well as a .py module. I can live with generating additional source and header files if it is an issue for boost python and I don't care to have a standalone python module, as long as it works inside my application. > I couldn't find anything online as well. All examples I could find where similar to the boost python tutorial, with standalone parts of code. > > Thank you in advance. > > > > > _______________________________________________ > 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: From j.reid at mail.cryst.bbk.ac.uk Tue Sep 24 09:31:42 2013 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 24 Sep 2013 08:31:42 +0100 Subject: [C++-sig] Use alternative launcher for bpl-test rule Message-ID: Hi, I'm having some problems asking boost.build to start the debugger or valgrind when it runs some of my python extension bpl-test rules. I saw in the boost.build code some comments that suggests it hijacks the testing.launcher feature which I thought would be the way to do this. Does anyone know if it is possible and what I should be doing? Thanks, John. From giuseppe.corbelli at copanitalia.com Tue Sep 24 09:33:17 2013 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Tue, 24 Sep 2013 09:33:17 +0200 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: Message-ID: <5241403D.6000906@copanitalia.com> On 21/09/2013 16:52, Kassiopi Kassiopi2 wrote: > Hi, > > I want to call a c++ function from an embedded python shell, using boost > python. All the examples I've seen online describe how to expose a whole class > or some functions, but all cases refer to *standalone* parts of code. > My case is different though. The function I want to expose is not standalone, > and has a dependency: > > ------- start of documentModule.cpp -------- > #include > #include > > void newDocument( bool makeActive ) { > // depends on commandManager here > GetCommandMananager()->submitCommand( new newDocumentCmd( makeActive ) ); > } > > BOOST_PYTHON(documentModule) { > using namespace boost::python; > def( "newDocument", myCadLib::pythonCommands::newDocument, > arg("makeActive") ); > } > ------- end of documentModule.cpp -------- > > In reality the situation is more complicated and there are more dependencies > than the one mentioned above. > After generating a .so file with distutils, when I start my application and I > attempt to load the module (.so file) in the embedded python shell I get an > undefined symbols error complaining about the commandManager class. > Of course this is a reasonable request from python and I understand that. > However, I don't really care to generate a standalone python module per se. I > just want it to work in my application's embedded python shell. Additionally, > it wouldn't be meaningful to have the commandManager class exposed as well, > since this is part of my applications internal structure. Seems to me you want both extending and embedding. Never embedded an interpreter in a C++ app, so I'm not of much use here. The two jobs should be fairly independent. Producing the .so to extend the interpreter needs to link the commandManager library. Your extension module needs to access the Command Manager, so make sure it has already been initialized before the module is loaded, else the GetCommandManager() may return NULL. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From wamplerd at gmail.com Mon Sep 23 03:30:45 2013 From: wamplerd at gmail.com (Dave Wampler) Date: Sun, 22 Sep 2013 21:30:45 -0400 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: Message-ID: <5032933403680633892@unknownmsgid> What you're trying to do is fine. You only need to expose the interface that python is accessing. You do need to link in the library that contains the symbols for the commandManager class however. On Sep 22, 2013, at 7:48 PM, Kassiopi Kassiopi2 wrote: Hi, I want to call a c++ function from an embedded python shell, using boost python. All the examples I've seen online describe how to expose a whole class or some functions, but all cases refer to *standalone* parts of code. My case is different though. The function I want to expose is not standalone, and has a dependency: ------- start of documentModule.cpp -------- #include #include void newDocument( bool makeActive ) { // depends on commandManager here GetCommandMananager()->submitCommand( new newDocumentCmd( makeActive ) ); } BOOST_PYTHON(documentModule) { using namespace boost::python; def( "newDocument", myCadLib::pythonCommands::newDocument, arg("makeActive") ); } ------- end of documentModule.cpp -------- In reality the situation is more complicated and there are more dependencies than the one mentioned above. After generating a .so file with distutils, when I start my application and I attempt to load the module (.so file) in the embedded python shell I get an undefined symbols error complaining about the commandManager class. Of course this is a reasonable request from python and I understand that. However, I don't really care to generate a standalone python module per se. I just want it to work in my application's embedded python shell. Additionally, it wouldn't be meaningful to have the commandManager class exposed as well, since this is part of my applications internal structure. Is what I am asking possible with boost python? In the past I have used SWIG for that, and it generated some additional .cpp and .h files, as well as a .py module. I can live with generating additional source and header files if it is an issue for boost python and I don't care to have a standalone python module, as long as it works inside my application. I couldn't find anything online as well. All examples I could find where similar to the boost python tutorial, with standalone parts of code. Thank you in advance. _______________________________________________ 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: From raghavendra.jain at gmail.com Tue Sep 24 10:06:31 2013 From: raghavendra.jain at gmail.com (Raghvendra Jain) Date: Tue, 24 Sep 2013 17:06:31 +0900 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: <5241403D.6000906@copanitalia.com> References: <5241403D.6000906@copanitalia.com> Message-ID: Well, I have embedded an interpreter inside C++ code, if your question is related to that, please write back. May be I can help you with that. cheers, Raghav On Tue, Sep 24, 2013 at 4:33 PM, Giuseppe Corbelli < giuseppe.corbelli at copanitalia.com> wrote: > On 21/09/2013 16:52, Kassiopi Kassiopi2 wrote: > >> Hi, >> >> I want to call a c++ function from an embedded python shell, using boost >> python. All the examples I've seen online describe how to expose a whole >> class >> or some functions, but all cases refer to *standalone* parts of code. >> >> My case is different though. The function I want to expose is not >> standalone, >> and has a dependency: >> >> ------- start of documentModule.cpp -------- >> #include >> #include >> >> void newDocument( bool makeActive ) { >> // depends on commandManager here >> GetCommandMananager()->**submitCommand( new newDocumentCmd( >> makeActive ) ); >> } >> >> BOOST_PYTHON(documentModule) { >> using namespace boost::python; >> def( "newDocument", myCadLib::pythonCommands::**newDocument, >> arg("makeActive") ); >> } >> ------- end of documentModule.cpp -------- >> >> In reality the situation is more complicated and there are more >> dependencies >> than the one mentioned above. >> After generating a .so file with distutils, when I start my application >> and I >> attempt to load the module (.so file) in the embedded python shell I get >> an >> undefined symbols error complaining about the commandManager class. >> Of course this is a reasonable request from python and I understand that. >> However, I don't really care to generate a standalone python module per >> se. I >> just want it to work in my application's embedded python shell. >> Additionally, >> it wouldn't be meaningful to have the commandManager class exposed as >> well, >> since this is part of my applications internal structure. >> > > Seems to me you want both extending and embedding. Never embedded an > interpreter in a C++ app, so I'm not of much use here. > The two jobs should be fairly independent. Producing the .so to extend the > interpreter needs to link the commandManager library. > Your extension module needs to access the Command Manager, so make sure it > has already been initialized before the module is loaded, else the > GetCommandManager() may return NULL. > > -- > Giuseppe Corbelli > WASP Software Engineer, Copan Italia S.p.A > Phone: +390303666318 Fax: +390302659932 > E-mail: giuseppe.corbelli at copanitalia.**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: From ndbecker2 at gmail.com Wed Sep 25 17:22:22 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 25 Sep 2013 11:22:22 -0400 Subject: [C++-sig] memory leak with __iadd__ Message-ID: I've been trying to track down a memory leak. When I use the following: .def ("__iadd__", &hist_t::operator+=, bp::return_self<>()) I have a leak. When changed to: .def (bp::self += hist_t::value_type()) there is no leak. Any ideas? I suppose I maybe should just start using the latter style and forget the former. From nikolay.mladenov at gmail.com Wed Sep 25 19:02:03 2013 From: nikolay.mladenov at gmail.com (Nikolay Mladenov) Date: Wed, 25 Sep 2013 13:02:03 -0400 Subject: [C++-sig] memory leak with __iadd__ In-Reply-To: References: Message-ID: On Wed, Sep 25, 2013 at 11:22 AM, Neal Becker wrote: > I've been trying to track down a memory leak. When I use the following: > > .def ("__iadd__", &hist_t::operator+=, bp::return_self<>()) > but this is no different then any other function def with return_self<> policy (which i do a lot)? when do you observe the leak? during def or during a+b in python? > > I have a leak. > > When changed to: > > .def (bp::self += hist_t::value_type()) > > there is no leak. Any ideas? I suppose I maybe should just start using > the > latter style and forget the former. > > > _______________________________________________ > 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: From kassiopik at gmail.com Wed Sep 25 22:06:57 2013 From: kassiopik at gmail.com (Kassiopi Kassiopi2) Date: Wed, 25 Sep 2013 23:06:57 +0300 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: <5241403D.6000906@copanitalia.com> Message-ID: Hi, I apologize for the delayed reply. I was hoping to avoid linking the commandManager into the .so file. I am trying to avoid that because then, I will have to do this for any other module that I create and uses the commandManager. I would prefer to declare it as extern or something similar if possible. If I link it into to .so, then I will have to link it to all the modules I intend to create, separately. Moreover, the commandManager is statically linked into my executable, so linking it in every single python module, feels like overkill. Furthermore, since my call to the commandManager looks like: GetCommandManager()->submitCommand( new newDocumentCommand(makeActive) ); I will have to also link against the commands that will be sent to the commandManager as well. And if there are hundreds of commands, it's obvious that there is a lot of redundant stuff, since all these classes are also declared, defined and statically linked in the executable of my application. So it all ends up to the question: Is it absolutely necessary? No other way? On Tue, Sep 24, 2013 at 11:06 AM, Raghvendra Jain < raghavendra.jain at gmail.com> wrote: > Well, I have embedded an interpreter inside C++ code, if your question is > related to that, please write back. May be I can help you with that. > cheers, > Raghav > > > On Tue, Sep 24, 2013 at 4:33 PM, Giuseppe Corbelli < > giuseppe.corbelli at copanitalia.com> wrote: > >> On 21/09/2013 16:52, Kassiopi Kassiopi2 wrote: >> >>> Hi, >>> >>> I want to call a c++ function from an embedded python shell, using boost >>> python. All the examples I've seen online describe how to expose a whole >>> class >>> or some functions, but all cases refer to *standalone* parts of code. >>> >>> My case is different though. The function I want to expose is not >>> standalone, >>> and has a dependency: >>> >>> ------- start of documentModule.cpp -------- >>> #include >>> #include >>> >>> void newDocument( bool makeActive ) { >>> // depends on commandManager here >>> GetCommandMananager()->**submitCommand( new newDocumentCmd( >>> makeActive ) ); >>> } >>> >>> BOOST_PYTHON(documentModule) { >>> using namespace boost::python; >>> def( "newDocument", myCadLib::pythonCommands::**newDocument, >>> arg("makeActive") ); >>> } >>> ------- end of documentModule.cpp -------- >>> >>> In reality the situation is more complicated and there are more >>> dependencies >>> than the one mentioned above. >>> After generating a .so file with distutils, when I start my application >>> and I >>> attempt to load the module (.so file) in the embedded python shell I get >>> an >>> undefined symbols error complaining about the commandManager class. >>> Of course this is a reasonable request from python and I understand that. >>> However, I don't really care to generate a standalone python module per >>> se. I >>> just want it to work in my application's embedded python shell. >>> Additionally, >>> it wouldn't be meaningful to have the commandManager class exposed as >>> well, >>> since this is part of my applications internal structure. >>> >> >> Seems to me you want both extending and embedding. Never embedded an >> interpreter in a C++ app, so I'm not of much use here. >> The two jobs should be fairly independent. Producing the .so to extend >> the interpreter needs to link the commandManager library. >> Your extension module needs to access the Command Manager, so make sure >> it has already been initialized before the module is loaded, else the >> GetCommandManager() may return NULL. >> >> -- >> Giuseppe Corbelli >> WASP Software Engineer, Copan Italia S.p.A >> Phone: +390303666318 Fax: +390302659932 >> E-mail: giuseppe.corbelli at copanitalia.**com >> >> ______________________________**_________________ >> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Thu Sep 26 16:44:08 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 26 Sep 2013 10:44:08 -0400 Subject: [C++-sig] memory leak with __iadd__ References: Message-ID: Nikolay Mladenov wrote: > On Wed, Sep 25, 2013 at 11:22 AM, Neal Becker wrote: > >> I've been trying to track down a memory leak. When I use the following: >> >> .def ("__iadd__", &hist_t::operator+=, bp::return_self<>()) >> > > but this is no different then any other function def with return_self<> > policy (which i do a lot)? > when do you observe the leak? during def or during a+b in python? > > The leak must be in using +=. The def is only executed once. This is a big leak, causing eventual OOM. From giuseppe.corbelli at copanitalia.com Fri Sep 27 12:39:46 2013 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Fri, 27 Sep 2013 12:39:46 +0200 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: <5241403D.6000906@copanitalia.com> Message-ID: <52456072.50302@copanitalia.com> On 25/09/2013 22:06, Kassiopi Kassiopi2 wrote: > Hi, > > I apologize for the delayed reply. > > I was hoping to avoid linking the commandManager into the .so file. I am > trying to avoid that because then, I will have to do this for any other module > that I create and uses the commandManager. I would prefer to declare it as > extern or something similar if possible. If I link it into to .so, then I will > have to link it to all the modules I intend to create, separately. Moreover, > the commandManager is statically linked into my executable, so linking it in > every single python module, feels like overkill. > Furthermore, since my call to the commandManager looks like: > > GetCommandManager()->submitCommand( new newDocumentCommand(makeActive) ); > > I will have to also link against the commands that will be sent to the > commandManager as well. And if there are hundreds of commands, it's obvious > that there is a lot of redundant stuff, since all these classes are also > declared, defined and statically linked in the executable of my application. Well, the .so needs to have access to the GetCommandManager symbol, so I see no way out here. Besides it also needs to create newDocumentCommand instances, so it must have access to the constructor, too. If command manager is something like a singleton make sure you're getting the same object in the C++ app and in the .so. Just declaring it static here and there doesn't work. In theory you could also have a static python library without module support, and link everything static. I just don't know how much work would it take. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From nikolay.mladenov at gmail.com Thu Sep 26 19:18:04 2013 From: nikolay.mladenov at gmail.com (Nikolay Mladenov) Date: Thu, 26 Sep 2013 13:18:04 -0400 Subject: [C++-sig] memory leak with __iadd__ In-Reply-To: References: Message-ID: if you .def ("test_iadd", &hist_t::operator+=, bp::return_self<>()) and you use it instead of += do you get the leak? On Thu, Sep 26, 2013 at 10:44 AM, Neal Becker wrote: > Nikolay Mladenov wrote: > > > On Wed, Sep 25, 2013 at 11:22 AM, Neal Becker > wrote: > > > >> I've been trying to track down a memory leak. When I use the following: > >> > >> .def ("__iadd__", &hist_t::operator+=, bp::return_self<>()) > >> > > > > but this is no different then any other function def with return_self<> > > policy (which i do a lot)? > > when do you observe the leak? during def or during a+b in python? > > > > > > The leak must be in using +=. The def is only executed once. This is a > big > leak, causing eventual OOM. > > _______________________________________________ > 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: From cedric.gestes at gmail.com Fri Sep 27 14:06:24 2013 From: cedric.gestes at gmail.com (Cedric GESTES) Date: Fri, 27 Sep 2013 14:06:24 +0200 Subject: [C++-sig] Boost python simple interfacing In-Reply-To: References: <5241403D.6000906@copanitalia.com> Message-ID: On Wed, Sep 25, 2013 at 10:06 PM, Kassiopi Kassiopi2 wrote: > Hi, > > I apologize for the delayed reply. > > I was hoping to avoid linking the commandManager into the .so file. I am > trying to avoid that because then, I will have to do this for any other > module that I create and uses the commandManager. I would prefer to declare > it as extern or something similar if possible. If I link it into to .so, > then I will have to link it to all the modules I intend to create, > separately. Moreover, the commandManager is statically linked into my > executable, so linking it in every single python module, feels like > overkill. > Furthermore, since my call to the commandManager looks like: > > GetCommandManager()->submitCommand( new newDocumentCommand(makeActive) ); > > I will have to also link against the commands that will be sent to the > commandManager as well. And if there are hundreds of commands, it's obvious > that there is a lot of redundant stuff, since all these classes are also > declared, defined and statically linked in the executable of my application. > > So it all ends up to the question: Is it absolutely necessary? No other > way? > Just link the command manager in dynamic everywhere. (you your singleton will works that way) > > > On Tue, Sep 24, 2013 at 11:06 AM, Raghvendra Jain < > raghavendra.jain at gmail.com> wrote: > >> Well, I have embedded an interpreter inside C++ code, if your question >> is related to that, please write back. May be I can help you with that. >> cheers, >> Raghav >> >> >> On Tue, Sep 24, 2013 at 4:33 PM, Giuseppe Corbelli < >> giuseppe.corbelli at copanitalia.com> wrote: >> >>> On 21/09/2013 16:52, Kassiopi Kassiopi2 wrote: >>> >>>> Hi, >>>> >>>> I want to call a c++ function from an embedded python shell, using boost >>>> python. All the examples I've seen online describe how to expose a >>>> whole class >>>> or some functions, but all cases refer to *standalone* parts of code. >>>> >>>> My case is different though. The function I want to expose is not >>>> standalone, >>>> and has a dependency: >>>> >>>> ------- start of documentModule.cpp -------- >>>> #include >>>> #include >>>> >>>> void newDocument( bool makeActive ) { >>>> // depends on commandManager here >>>> GetCommandMananager()->**submitCommand( new newDocumentCmd( >>>> makeActive ) ); >>>> } >>>> >>>> BOOST_PYTHON(documentModule) { >>>> using namespace boost::python; >>>> def( "newDocument", myCadLib::pythonCommands::**newDocument, >>>> arg("makeActive") ); >>>> } >>>> ------- end of documentModule.cpp -------- >>>> >>>> In reality the situation is more complicated and there are more >>>> dependencies >>>> than the one mentioned above. >>>> After generating a .so file with distutils, when I start my application >>>> and I >>>> attempt to load the module (.so file) in the embedded python shell I >>>> get an >>>> undefined symbols error complaining about the commandManager class. >>>> Of course this is a reasonable request from python and I understand >>>> that. >>>> However, I don't really care to generate a standalone python module per >>>> se. I >>>> just want it to work in my application's embedded python shell. >>>> Additionally, >>>> it wouldn't be meaningful to have the commandManager class exposed as >>>> well, >>>> since this is part of my applications internal structure. >>>> >>> >>> Seems to me you want both extending and embedding. Never embedded an >>> interpreter in a C++ app, so I'm not of much use here. >>> The two jobs should be fairly independent. Producing the .so to extend >>> the interpreter needs to link the commandManager library. >>> Your extension module needs to access the Command Manager, so make sure >>> it has already been initialized before the module is loaded, else the >>> GetCommandManager() may return NULL. >>> >>> -- >>> Giuseppe Corbelli >>> WASP Software Engineer, Copan Italia S.p.A >>> Phone: +390303666318 Fax: +390302659932 >>> E-mail: giuseppe.corbelli at copanitalia.**com >>> >>> ______________________________**_________________ >>> 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 >> > > > _______________________________________________ > 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: From asu_mcs at yahoo.com Mon Sep 30 17:40:29 2013 From: asu_mcs at yahoo.com (sam) Date: Mon, 30 Sep 2013 08:40:29 -0700 (PDT) Subject: [C++-sig] fault core dump error In-Reply-To: <1332405580.70881.YahooMailClassic@web45212.mail.sp1.yahoo.com> Message-ID: <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> Hello, I wrote a C program that loop inside a folder which has about 200 text files. Each file has almost 60000 lines. I created 2D array [60000][200] to store files in it. No compilation problem at all, but when I try to run it I get this error (fault core dump). Yes I did use malloc() This is my code: /////////////// #include #include #include #include #define WIDTH 200 // total number of files #define HEIGHT 60000 // total number of lines for each file int main () { double **array1; array1 [HEIGHT][WIDTH]; int w ,h; int fnum = 1; char filename [64]; double *data; FILE * fpr; FILE * fpw; // reading files data to array1 array1 = (double **) malloc(HEIGHT*sizeof(double)); for (w=0;w References: <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> Message-ID: <52499D80.3060607@esrf.fr> Hello, You are reading on a closed file, try moving the fclose to the other side of the curly bracket. HTH, Jon > fpr = fopen(filename, "r"); > > for (h=0;h { > array1[h] = (double *) malloc(WIDTH*sizeof(double)); > > > fscanf(fpr, "%lf", &array1 [h][w]); > > fclose(fpr); > > } > From talljimbo at gmail.com Mon Sep 30 17:56:51 2013 From: talljimbo at gmail.com (Jim Bosch) Date: Mon, 30 Sep 2013 11:56:51 -0400 Subject: [C++-sig] fault core dump error In-Reply-To: <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> References: <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> Message-ID: <52499F43.5070207@gmail.com> I think you may be sending to a mailing list that isn't really appropriate for your questions; this list concerns integrating C++ with Python (often focusing on Boost.Python), not general C/C++ programming. Good luck! Jim On 09/30/2013 11:40 AM, sam wrote: > Hello, > I wrote a C program that loop inside a folder which has about 200 text files. Each file has almost 60000 lines. I created 2D array [60000][200] to store files in it. No compilation problem at all, but when I try to run it I get this error (fault core dump). Yes I did use malloc() > This is my code: > > /////////////// > > > > #include > #include > #include > #include > > #define WIDTH 200 // total number of files > #define HEIGHT 60000 // total number of lines for each file > > int main () > { > > double **array1; array1 [HEIGHT][WIDTH]; > > > int w ,h; > int fnum = 1; > char filename [64]; > double *data; > FILE * fpr; > FILE * fpw; > > > // reading files data to array1 > > array1 = (double **) malloc(HEIGHT*sizeof(double)); > > > for (w=0;w { > > sprintf(filename, "C:/User/data%d.txt", fnum); > ; > > fpr = fopen(filename, "r"); > > for (h=0;h { > array1[h] = (double *) malloc(WIDTH*sizeof(double)); > > > fscanf(fpr, "%lf", &array1 [h][w]); > > fclose(fpr); > > } > > > > fnum ++; > } > > > return 0; > } > > > //////////////// > > Thank you, > Sam > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > From asu_mcs at yahoo.com Mon Sep 30 18:11:15 2013 From: asu_mcs at yahoo.com (sam) Date: Mon, 30 Sep 2013 09:11:15 -0700 (PDT) Subject: [C++-sig] fault core dump error In-Reply-To: <52499D80.3060607@esrf.fr> Message-ID: <1380557475.54044.YahooMailBasic@web160401.mail.bf1.yahoo.com> Thank you Jonathan for your quick response. well, i did move it. still same problem. it has something to do with memory -------------------------------------------- On Mon, 9/30/13, Jonathan WRIGHT wrote: Subject: Re: [C++-sig] fault core dump error To: cplusplus-sig at python.org Date: Monday, September 30, 2013, 9:49 AM Hello, You are reading on a closed file, try moving the fclose to the other side of the curly bracket. HTH, Jon ??? > ??? ???fpr = fopen(filename, "r"); > ??? > ??? ???for (h=0;h ??? ???{ > ??? ???array1[h] = (double *) malloc(WIDTH*sizeof(double)); > ??? > > ??? ??? ? fscanf(fpr, "%lf",? &array1 [h][w]); > ??? ??? > ??? ??? ? ? fclose(fpr); > ??? ??? ??? > ??? ???} > _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org https://mail.python.org/mailman/listinfo/cplusplus-sig From brandsmeier at gmx.de Mon Sep 30 18:18:56 2013 From: brandsmeier at gmx.de (Holger Brandsmeier) Date: Mon, 30 Sep 2013 18:18:56 +0200 Subject: [C++-sig] fault core dump error In-Reply-To: <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> References: <1332405580.70881.YahooMailClassic@web45212.mail.sp1.yahoo.com> <1380555629.58902.YahooMailBasic@web160403.mail.bf1.yahoo.com> Message-ID: Sam, this looks really awful: double **array1; array1 [HEIGHT][WIDTH]; do you mean: double **array1; //array1 [HEIGHT][WIDTH]; But this might not be your probablem. You say " folder which has about 200 text files", but your code is treating this as "exactly 200 text files", you need to do something there. Then again please recall the reminder of Jim Bosch and maybe post this problem on a different list, maybe stackexchange? -Holger On Mon, Sep 30, 2013 at 5:40 PM, sam wrote: > Hello, > I wrote a C program that loop inside a folder which has about 200 text files. Each file has almost 60000 lines. I created 2D array [60000][200] to store files in it. No compilation problem at all, but when I try to run it I get this error (fault core dump). Yes I did use malloc() > This is my code: > > /////////////// > > > > #include > #include > #include > #include > > #define WIDTH 200 // total number of files > #define HEIGHT 60000 // total number of lines for each file > > int main () > { > > double **array1; array1 [HEIGHT][WIDTH]; > > > int w ,h; > int fnum = 1; > char filename [64]; > double *data; > FILE * fpr; > FILE * fpw; > > > // reading files data to array1 > > array1 = (double **) malloc(HEIGHT*sizeof(double)); > > > for (w=0;w { > > sprintf(filename, "C:/User/data%d.txt", fnum); > ; > > fpr = fopen(filename, "r"); > > for (h=0;h { > array1[h] = (double *) malloc(WIDTH*sizeof(double)); > > > fscanf(fpr, "%lf", &array1 [h][w]); > > fclose(fpr); > > } > > > > fnum ++; > } > > > return 0; > } > > > //////////////// > > Thank you, > Sam > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig