From schipo at dynamik.fb10.TU-Berlin.DE Mon May 2 14:20:40 2005 From: schipo at dynamik.fb10.TU-Berlin.DE (Thomas Schipolowski) Date: Mon, 02 May 2005 14:20:40 +0200 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? Message-ID: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Hello, in my c++ extension I have two classes which refer to each other, creating a reference cycle. Since 'Slave' objects are useless without an associated 'Master', I want to store the backward reference from the Slave to its Master using boost::weak_ptr. To further complicate things, I have different variants of the Master class implemented by inheritance. Only references to the base class are passed around with boost::shared_ptr. Please have a look at the test case below. The scenario works as expected when the objects are created in c++: >>> import test as t >>> m = t.create_master() Slave::Slave(master_ptr) master_ptr use count 2 master_ptr addr 12411040 weak_ptr use count 2 >>> m.status() MDerived::status() ==> Master::status() master addr 12411040 slave use count 1 Slave::status() master use count 1 >>> s = m.slave >>> del m >>> s.status() Slave::status() master use count 0 >>> The Master reference held by the Slave is valid as long as the Python Master object is alive. Fine. However, this is not the case when the MDerived and Slave objects are constructed from Python: >>> m = t.MDerived() >>> m.slave = t.Slave(m) Slave::Slave(master_ptr) master_ptr use count 3 master_ptr addr 12410784 weak_ptr use count 3 >>> m.status() MDerived::status() ==> Master::status() master addr 12410784 slave use count 1 Slave::status() master use count 0 >>> The Master reference held by the weak_ptr expires as soon as the Slave constructor finishes, although m is still alive. I wonder what the temporary shared_ptr did to the master object when the ref count went to zero in this moment? Note however that the behavior is as expected if the base class m = t.Master() is used instead of m = t.MDerived(). Please advise me on how to handle this situation correctly. It should work the same no matter whether objects are created from python or c++. Regards, Thomas. The test code (sorry, its rather long): #include #include #include #include using namespace boost; using namespace boost::python; class Master; typedef shared_ptr pMaster; typedef weak_ptr wpMaster; class Slave { public: Slave(pMaster m): master(m) { std::cout << "Slave::Slave(master_ptr)" << std::endl; std::cout << " master_ptr use count " << m.use_count() << std::endl; std::cout << " master_ptr addr " << (long)m.get() << std::endl; std::cout << " weak_ptr use count " << master.use_count() << std::endl; }; void status() { std::cout << "Slave::status()" << std::endl; std::cout << " master use count " << master.use_count() << std::endl; }; wpMaster master; }; typedef shared_ptr pSlave; class Master { public: virtual ~Master() {}; virtual void status() { std::cout << "Master::status()" << std::endl; std::cout << " master addr " << (long)this << std::endl; std::cout << " slave use count " << slave.use_count() << std::endl; if (slave) slave->status(); }; pSlave slave; }; class MDerived: public Master { public: //no modifications, the point is to demonstrate //that inheritance changes the behavior virtual ~MDerived() {}; virtual void status() { std::cout << "MDerived::status() ==> "; Master::status(); }; }; typedef shared_ptr pMDerived; pMaster create_master() { pMaster m(new MDerived()); pSlave s(new Slave(m)); m->slave = s; return m; } BOOST_PYTHON_MODULE(test) { class_("Slave", init()) .def("status", &Slave::status) ; class_("Master", init<>()) .def_readwrite("slave", &Master::slave) .def("status", &Master::status) ; class_ >("MDerived", init<>()) ; def("create_master", create_master); } I am using VC6 with boost-build v1 and boost_1_32_0 on Windows. The Python version is 2.3.4 From arnaud.picard at edfgdf.fr Mon May 2 21:00:31 2005 From: arnaud.picard at edfgdf.fr (Arnaud PICARD) Date: Mon, 2 May 2005 21:00:31 +0200 Subject: [C++-sig] Arnaud PICARD/IMA/DER/EDFGDF/FR est absent Message-ID: Je serai absent(e) du 01/05/2005 au 08/05/2005. Je r?pondrai ? votre message d?s mon retour. From faheem at email.unc.edu Tue May 3 00:00:26 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Mon, 2 May 2005 22:00:26 +0000 (UTC) Subject: [C++-sig] wrapping virtual base class with std::auto_ptr Message-ID: Hi, Consider the following simple example. This works fine if (for example) I replace std:auto_ptr with int (see commented-put lines). This also works if this is just a regular struct (if f is a normal function returning a std::auto::ptr). The compiler errors I get appear below. The offending line is. return this->get_override("f")(); I have a dim understanding of how Boost.Python works in general, but really don't understand what magic goes on in wrapping virtual functions etc. I've just copied the syntax below from the tutorial. Thanks in advance for help. Please cc me; I'm not subscribed. Faheem. ap.cc: In member function `virtual std::auto_ptr BaseWrap::f(int)': ap.cc:17: error: no matching function for call to `std::auto_ptr::auto_ptr (std::auto_ptr)' /usr/include/c++/3.3/memory:334: error: candidates are: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = int] /usr/include/c++/3.3/memory:204: error: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = int, _Tp = int] /usr/include/c++/3.3/memory:192: error: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = int] ap.cc:17: error: initializing temporary from result of ` boost::python::detail::method_result::operator T() [with T = std::auto_ptr]' error: command 'gcc' failed with exit status 1 ********************************************************************* ap.cc ********************************************************************* #include using namespace boost::python; struct Base { virtual std::auto_ptr f(int val) = 0; // virtual int f(int val) = 0; }; struct BaseWrap : Base, wrapper { BaseWrap():Base(){} std::auto_ptr f(int val) // int f(int val) { return this->get_override("f")(); } }; BOOST_PYTHON_MODULE(ap) { class_("Base") .def("f", pure_virtual(&Base::f)) ; } ********************************************************************* From faheem at email.unc.edu Tue May 3 00:50:51 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Mon, 2 May 2005 18:50:51 -0400 (EDT) Subject: [C++-sig] wrapping virtual base class with std::auto_ptr Message-ID: Hi, Consider the following simple example. This works fine if (for example) I replace std:auto_ptr with int (see commented-put lines). This also works if this is just a regular struct (if f is a normal function returning a std::auto::ptr). The compiler errors I get appear below. The offending line is. return this->get_override("f")(); I have a dim understanding of how Boost.Python works in general, but really don't understand what magic goes on in wrapping virtual functions etc. I've just copied the syntax below from the tutorial. Thanks in advance for help. Please cc me; I'm not subscribed. Faheem. ap.cc: In member function `virtual std::auto_ptr BaseWrap::f(int)': ap.cc:17: error: no matching function for call to `std::auto_ptr::auto_ptr (std::auto_ptr)' /usr/include/c++/3.3/memory:334: error: candidates are: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = int] /usr/include/c++/3.3/memory:204: error: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = int, _Tp = int] /usr/include/c++/3.3/memory:192: error: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = int] ap.cc:17: error: initializing temporary from result of ` boost::python::detail::method_result::operator T() [with T = std::auto_ptr]' error: command 'gcc' failed with exit status 1 ********************************************************************* ap.cc ********************************************************************* #include using namespace boost::python; struct Base { virtual std::auto_ptr f(int val) = 0; // virtual int f(int val) = 0; }; struct BaseWrap : Base, wrapper { BaseWrap():Base(){} std::auto_ptr f(int val) // int f(int val) { return this->get_override("f")(); } }; BOOST_PYTHON_MODULE(ap) { class_("Base") .def("f", pure_virtual(&Base::f)) ; } ********************************************************************* From Ben.Cain at us.army.mil Tue May 3 18:13:10 2005 From: Ben.Cain at us.army.mil (Cain, Ben (Contractor-Summit)) Date: Tue, 3 May 2005 11:13:10 -0500 Subject: [C++-sig] Building Hello World Message-ID: <6DB8567B5D54F443982465B984BE4AA99B2B34@amr-ex5.ds.amrdec.army.mil> Hello, I'm trying to go through the Tutorial. I have an extensive makefile system that is already used for an application affecting many developers. With that in mind, I'd really prefer not to switch to bjam ... at least not just yet. Do you have a GCC equivalent makefile that would build the Hello World example Win32 DLL and LIB? Here's an error I'm getting ... extending error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::detail::init_module(char const *,void (__cdecl*)(void))" (__imp_?init_module at detail@python at boost@@YAXPBDP6AXXZ at Z) referenced in function _inithello My apologies for asking you beginner questions. I've often done the same thing on other mailing lists. It can be tedious ... but, pays in the long run. Nonetheless, I have been through the FAQ and done Net searches. And, I have made several attempts with compiler options. Many Thanks, Ben From daw at pleiad.umdnj.edu Wed May 4 00:24:47 2005 From: daw at pleiad.umdnj.edu (Donald Winkelmann) Date: Tue, 03 May 2005 18:24:47 -0400 Subject: [C++-sig] Boost.Python Message-ID: <7fe77fadc08fcd86331737b88be6c467@pleiad.umdnj.edu> I've finally was able to get Boost.Python to build on OS X 10.3 following some suggestions from Tom Denninston. I'm really not familiar with Boost or Python, but I need it for an application, eman, that uses it. Now I've run into a libtool error that I don't understand and perhaps someone can enlighten me: /Users/daw/eman/libpyEM: building default_target Building dependencies. cmake.depends... Building shared library /Users/daw/eman/lib/libpyEM.dylib... ld: PyEMDataWrap.o illegal reference to symbol: _PyErr_SetString defined in indirectly referenced dynamic library /System/Library/Frameworks/Python.framework/Versions/2.3/Python /usr/bin/libtool: internal link edit command failed make[3]: *** [/Users/daw/eman/lib/libpyEM.dylib] Error 1 make[2]: *** [default_target] Error 2 make[1]: *** [default_target_libpyEM] Error 2 make: *** [default_target] Error 2 The libpyEM.dylib was linking to libboost_python-1_32.dylib when I encounter this error. Any suggestions? Thanks. daw -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 1093 bytes Desc: not available URL: From beyer at imb-jena.de Wed May 4 02:01:08 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Tue, 03 May 2005 17:01:08 -0700 Subject: [C++-sig] [C++-sig] Re: Pointer to existing Python object In-Reply-To: References: <425B363E.8090905@imb-jena.de> Message-ID: <427810C4.7050802@imb-jena.de> An HTML attachment was scrubbed... URL: From niacneb at yahoo.com Wed May 4 22:05:11 2005 From: niacneb at yahoo.com (Neb Naic) Date: Wed, 4 May 2005 13:05:11 -0700 (PDT) Subject: [C++-sig] Boost.Python embedding examples Message-ID: <20050504200511.16002.qmail@web60323.mail.yahoo.com> Hello, I've noticed there are no examples of embedded Python in the installation of Boost.Python. Why are the "getting started" examples only for extending Python? Is Boost.Python not viable for embedding Python? Should I use CXX or SWIG instead? Finally, the Boost.Python Web site builds up the extending case very well; but, the embedding aspects assume too much of a Python background (IMHO). And, no complete example is given. I really hope to not have to use the Python/C++ API. My application requires both extending and embedding. Please help! Thanks, Niac --------------------------------- Yahoo! Mail Stay connected, organized, and protected. Take the tour -------------- next part -------------- An HTML attachment was scrubbed... URL: From niacneb at yahoo.com Wed May 4 23:06:42 2005 From: niacneb at yahoo.com (Neb Naic) Date: Wed, 4 May 2005 14:06:42 -0700 (PDT) Subject: [C++-sig] Boost.Python embedding examples In-Reply-To: 6667 Message-ID: <20050504210642.11003.qmail@web60312.mail.yahoo.com> Hello, Assuming the Python code to embed is in it's own file. Does Boost.Python provide interface similar to: PyObject_CallObject PyTuple_SetItem I couldn't find any Boost.Python examples that encapsulate these functions. Writing them in Python/C++ API is very tedious and error prone. I was told that Boost.Python does this for you. But, I can't find an example of this anywhere. Thanks, Niac Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html From dave at boost-consulting.com Thu May 5 04:24:55 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 04 May 2005 22:24:55 -0400 Subject: [C++-sig] Boost.Python embedded examples? In-Reply-To: <20050504202025.20403.qmail@web60311.mail.yahoo.com> (Neb Naic's message of "Wed, 4 May 2005 13:20:25 -0700 (PDT)") References: <20050504202025.20403.qmail@web60311.mail.yahoo.com> Message-ID: Hi Neb, Neb Naic writes: > Hello, > > I've noticed there are no examples of embedded Python in the > installation of Boost.Python. There is one in libs/python/test/embedding.cpp. > Why are the "getting started" examples only for extending Python? No particular reason. It wasn't a high priority for those people that funded the work, I guess. > Is Boost.Python not viable for embedding Python? Should I use CXX > or SWIG instead? It is viable. > Finally, the Boost.Python Web site builds up the extending case very > well; but, the embedding aspects assume too much of a Python > background (IMHO). I think you're right; support for embedding could be stronger. > And, no complete example is given. > > I really hope to not have to use the Python/C++ API. My application > requires both extending and embedding. Please help! There are more than a few people on the C++-sig (http://www.boost.org/more/mailing_lists.htm#cplussig) who have done lots of embedding with Boost.Python. I suggest you ask there. [Actually, unless you want to pay Boost Consulting for support, you really should post your Boost.Python questions there, regardless. I hope you can understand that -- since Boost support is part of my business -- I can't really respond to personal email support requests except under contract.] HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Fri May 6 19:33:06 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 6 May 2005 10:33:06 -0700 (PDT) Subject: [C++-sig] Building Hello World In-Reply-To: 6667 Message-ID: <20050506173306.25395.qmail@web31504.mail.mud.yahoo.com> --- "Cain, Ben (Contractor-Summit)" wrote: > I'm trying to go through the Tutorial. I have an extensive makefile > system that is already used for an application affecting many > developers. With that in mind, I'd really prefer not to switch to bjam > ... at least not just yet. There is nothing magic about bjam, you just need to get the compilation and link commands right. E.g. we are using a SCons-based build system, but you can certainly also use make. The commands for a Windows build are shown here: http://cci.lbl.gov/cctbx_build/results/2005_05_05_2035/win_xp_py24_build_log Similarly, Linux g++: http://cci.lbl.gov/cctbx_build/results/2005_05_05_2337/fedora3_py24_build_log The build commands for boost_python.lib or libboost_python.so are near the beginning of the pages. These particular pages will go away eventually, but if you look around under the "summary" links at http://cci.lbl.gov/cctbx_build/all.html you should always be able to find the build commands. Cheers, Ralf P.S.: Ben, you have to post to c++-sig at python.org if you want everybody to see your messages. __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail From niacneb at yahoo.com Fri May 6 19:40:58 2005 From: niacneb at yahoo.com (Neb Naic) Date: Fri, 6 May 2005 10:40:58 -0700 (PDT) Subject: [C++-sig] test Message-ID: <20050506174058.20975.qmail@web60315.mail.yahoo.com> test __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From ron.clarke at hp.com Mon May 9 19:54:42 2005 From: ron.clarke at hp.com (Clarke, Ronald) Date: Mon, 9 May 2005 10:54:42 -0700 Subject: [C++-sig] Trouble accessing custom object Message-ID: <2A0DA7F7B6B34840A9C133E54514AC25019CA131@cacexc02.americas.cpqcorp.net> I am trying to access a custom object and am having a few problems. Hopefully someone can point out what I'm doing wrong. Here's the scenario: 1. We have a proprietary image class, scifiImage, written in C++ and wrapped for the Python environment using Boost Python. This part works well. 2. We have one of these image objects in a Python script, and are trying to access it from another C++ module. The Python script recognizes the image object (as expected, since this part has worked for quite a while), but we cannot access the "wrapped" image object from another C++ module. Here is the Python script, with some comments: from scifi_py import * #this is the library that contains scifiImage # Here we create an instance of the scifiImage object, initialize it, and print some # properties, just to validate the image construction works. This works fine. imageIn = scifiImage(1,10,10,8) imageIn.initRows(22) print "initial properties of imageIn...\n", imageIn.printProperties() Now here is the code from a C++ module that tries to access the 'imageIn' variable. Note this is not the same module that wraps scifiImage. Py_Initialize(); // this line imports the Python code listed above. The import succeeds, and the output // from imageIn.printProperties() appears as expected PyObject *pPyfilter = PyImport_ImportModule(const_cast(sfilterName)); // for test purposes, create another scifiImage object in the C++ world scifiImage* pimagetest = new scifiImage(3,5,5,8); pimagetest->initRows(50); //build a Python object using the new scifiImage object PyObject *pargsi = Py_BuildValue("O", &pimagetest); //Now set the 'imageIn' attribute in the Python script... int nattrreti = PyObject_SetAttrString(pPyfilter, "imageIn", pargsi); // ...and try calling printProperties() again, to see if the new image is printed int nrunres = PyRun_SimpleString("imageIn.printProperties()\n"); The address of pargsi looks reasonable, and the return code from the SetAttrString call is zero. However, PyRun_SimpleString fails with this error: Traceback (most recent call last): File "", line 1, in ? NameError: name 'imageIn' is not defined Can anyone tell me what I am doing wrong? Have I missed a step? Is my syntax in error? Any help is greatly appreciated. Thanks. _____________________________ Ron Clarke Digital Printing Technologies Hewlett-Packard Company ron.clarke at hp.com From niacneb at yahoo.com Mon May 9 21:07:00 2005 From: niacneb at yahoo.com (Neb Naic) Date: Mon, 9 May 2005 12:07:00 -0700 (PDT) Subject: [C++-sig] test ... not posting Message-ID: <20050509190700.39025.qmail@web60322.mail.yahoo.com> test __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Tue May 10 04:27:13 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 09 May 2005 22:27:13 -0400 Subject: [C++-sig] test Message-ID: Please ignore -- Dave Abrahams Boost Consulting www.boost-consulting.com From doug_bartholomew99 at yahoo.com Tue May 10 11:23:17 2005 From: doug_bartholomew99 at yahoo.com (doug bartholomew) Date: Tue, 10 May 2005 02:23:17 -0700 (PDT) Subject: [C++-sig] pickle an enum? Message-ID: <20050510092317.11685.qmail@web90001.mail.scd.yahoo.com> I have a cpp class that i have wrapped with boost python. now i would like to provide pickling ability. i have implemented the boost python pickling suite but have hit a stumbling block. my cpp class' constructor has an enum argument (yes, i have wrapped the cpp enum with boost python enum wrapping). the pickling plumbing is complaining that it doesnt know how to pickle the enum type. is there a nice way to apply the boost python pickling suite to a wrapped enum? Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html From niacneb at yahoo.com Tue May 10 15:53:35 2005 From: niacneb at yahoo.com (Neb Naic) Date: Tue, 10 May 2005 06:53:35 -0700 (PDT) Subject: [C++-sig] C++-sig not posting In-Reply-To: 6667 Message-ID: <20050510135335.79774.qmail@web60312.mail.yahoo.com> Hi, Thanks for acknowledging that your posts also don't show up. There hasn't been a post since April. Who maintains Python.org? Why hasn't a notice been sent to subscribed users? I'm new to Boost.Python. But, I thought the user base was larger. I must admit I'm not impressed. Maybe I subscribed at a bad time :) Sorry for cross-post ... not getting a response after numerous tries over the last number of days. Cheers, Niac --- "Ralf W. Grosse-Kunstleve" wrote: > Hi Niac, thanks for the notice! > I am having the same problems with my postings to > the Python C++-SIG. > Could someone at mailman at python.org please take a > look? > Thanks! > Ralf > Discover Yahoo! Stay in touch with email, IM, photo sharing and more. Check it out! http://discover.yahoo.com/stayintouch.html From dave at boost-consulting.com Tue May 10 16:13:14 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 10 May 2005 10:13:14 -0400 Subject: [C++-sig] C++-sig not posting In-Reply-To: <20050510135335.79774.qmail@web60312.mail.yahoo.com> References: <20050510135335.79774.qmail@web60312.mail.yahoo.com> Message-ID: <4280C17A.9070208@boost-consulting.com> Neb Naic wrote: > Hi, > > Thanks for acknowledging that your posts also don't > show up. There hasn't been a post since April. > > Who maintains Python.org? Why hasn't a notice been > sent to subscribed users? I'm new to Boost.Python. > But, I thought the user base was larger. How can you tell how big the user base is? > I must admit I'm not impressed. Maybe I subscribed at a bad > time :) Probably. This is the first time lists.python.org has failed us. We're trying to discover the cause. > Sorry for cross-post ... not getting a response after > numerous tries over the last number of days. You can always use one of the boost-specific mailing lists instead in the meantime. http://www.boost.org/more/mailing_lists.html HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From caleb.epstein at gmail.com Tue May 10 22:38:02 2005 From: caleb.epstein at gmail.com (Caleb Epstein) Date: Tue, 10 May 2005 16:38:02 -0400 Subject: [C++-sig] [python] Fix for embedding.cpp test on SunOS Message-ID: <989aceac050510133845ec08e5@mail.gmail.com> Re: http://tinyurl.com/a9dhn The Boost.Python embedding.cpp test fails on gcc-3_4_3-sunos because it tries to link with a nonexistent library "util". This library seems to be a BSD-ism from my Googling. It exists on Linux as well, and contains symbols like "login" and "openpty", which I can hardly imagine this test or Boost.Python depends on. So I submit the following patch for approval. With it, the embedding test compiles and runs cleanly on SunOS and Linux. This is the only Boost.Python test that fails on gcc-3_4_3-sunos, so it'll make the library 100% pass in this configuration. Index: tools/build/v1/python.jam =================================================================== RCS file: /cvsroot/boost/boost/tools/build/v1/python.jam,v retrieving revision 1.83 diff -u -b -r1.83 python.jam --- tools/build/v1/python.jam 27 Feb 2005 17:28:16 -0000 1.83 +++ tools/build/v1/python.jam 10 May 2005 20:28:14 -0000 @@ -69,7 +69,7 @@ } else { - PYTHON_EMBEDDED_LIBRARY = python$(PYTHON_VERSION) dl util ; + PYTHON_EMBEDDED_LIBRARY = python$(PYTHON_VERSION) dl ; } -- Caleb Epstein caleb dot epstein at gmail dot com From niacneb at yahoo.com Thu May 12 00:06:19 2005 From: niacneb at yahoo.com (Niac Neb) Date: Wed, 11 May 2005 15:06:19 -0700 (PDT) Subject: [C++-sig] Python/C++ wrapper comparisons? Message-ID: <20050511220619.39372.qmail@web60322.mail.yahoo.com> Hello, Didn't see this on site ... sorry if I missed it. I'm a newbie ... want to start on right foot :) Is there a Boost.Python comparison to say, SIP, SWIG, CXX ... considering ease-of-use, user base, maturity, good OS support, support for C++ class nesting, virtual methods, templates, overloading, etc.? Seems to me ... Boost.Python (among other things) has a more active user base, is better documented, and is the only solution that supports embedding Python. Although a great start, I do wish there were more examples in the Boost.Python Tutorial of embedding Python. Thanks, Niac Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html From cppsig-eric at sneakemail.com Thu May 12 05:19:00 2005 From: cppsig-eric at sneakemail.com (Eric) Date: Wed, 11 May 2005 20:19:00 -0700 Subject: [C++-sig] calling python logger module from C++ In-Reply-To: Message-ID: <21873-58778@sneakemail.com> I've been wondering how best to provide support for calling my python logger (which uses the standard logger module) from within my C++ extensions built using Boost.Python. My first thought was to do this: enum LogLevel { LogLevelCritical = 50, LogLevelError = 40, LogLevelWarning = 30, LogLevelInfo = 20, LogLevelDebug = 10 }; class PiLogger { public: virtual void Log( LogLevel level, std::wstring msg ) = 0; }; and then implement this class in python, setting it as a static variable in my C++. This works pretty well, but I'd like to be able to support format strings, which requires varargs. I couldn't figure out how to wrap a varargs function - is that even possible? If it's not, is there a better way to accomplish what I want? Thanks, Eric From suh at mails.tsinghua.edu.cn Thu May 12 06:46:19 2005 From: suh at mails.tsinghua.edu.cn (Hua Su) Date: Thu, 12 May 2005 12:46:19 +0800 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension Message-ID: <20050512044619.GA4156@dell.cad> Hi, I'v learnt Boost.Python for two weeks and now encounter some problems :( In brief, I can't find the way to use a C++ class, which is exported in an existing extension, in another extension written by myself. In detail, I'm writing a paint program with wxPython which is an extension for GUI library wxWidgets (wxWindows). I use wxPython to implement GUI, and use C++ to implement paint operations. ( In my application the paint operations is a bottleneck so I have to implement is in C++ ) When painting, I need to pass a pointer of DC from Python to my C++ code. The problem is, the class "wxDC" is a real C++ class writen in wxWidgets, and is exported in wxPython as Python class "DC", but I need use it in my code as C++ class "wxDC". I can't find support from Boost.Python for this problem. I have tried to pass pointer "void *" instead, but Boost.Python declares it does not support "void *" as argument or return type. Could someone give me some example? I work for this problem for days :( Thanks for your reply. regards, Clark From pankaj_jain_101 at yahoo.com Thu May 12 20:03:34 2005 From: pankaj_jain_101 at yahoo.com (pankaj jain) Date: Thu, 12 May 2005 11:03:34 -0700 (PDT) Subject: [C++-sig] IQuestion : nner class code boost.python Message-ID: <20050512180334.65910.qmail@web30308.mail.mud.yahoo.com> > Hi , > I have C++ code like > class A > { > class B; > --- > --- > } > can any body help me in how I can map inner class for building python > module. --------------------------------- Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. -------------- next part -------------- An HTML attachment was scrubbed... URL: From barry at python.org Fri May 13 00:28:35 2005 From: barry at python.org (Barry Warsaw) Date: Thu, 12 May 2005 18:28:35 -0400 Subject: [C++-sig] This is a test Message-ID: <1115936914.32261.26.camel@geddy.wooz.org> Please ignore. This is only a test. -Barry -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 307 bytes Desc: This is a digitally signed message part URL: From barry at python.org Fri May 13 04:41:37 2005 From: barry at python.org (Barry Warsaw) Date: Thu, 12 May 2005 22:41:37 -0400 Subject: [C++-sig] testing, please ignore Message-ID: <1115952097.20720.49.camel@geddy.wooz.org> Just checking to see if I've fixed this mailing list. -Barry -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 307 bytes Desc: This is a digitally signed message part URL: From seefeld at sympatico.ca Fri May 13 05:01:33 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 12 May 2005 23:01:33 -0400 Subject: [C++-sig] [C++-sig] [python] Fix for embedding.cpp test on SunOS In-Reply-To: <989aceac050510133845ec08e5@mail.gmail.com> References: <989aceac050510133845ec08e5@mail.gmail.com> Message-ID: <4284188D.9030209@sympatico.ca> Caleb Epstein wrote: > Re: http://tinyurl.com/a9dhn > > The Boost.Python embedding.cpp test fails on gcc-3_4_3-sunos because > it tries to link with a nonexistent library "util". This library > seems to be a BSD-ism from my Googling. It exists on Linux as well, > and contains symbols like "login" and "openpty", which I can hardly > imagine this test or Boost.Python depends on. I believe it is the python runtime itself that depends on libutil, at least on some systems, so you mustn't remove it if you want to embedd python. (In contrast I remember at least one python version to list a wrong dependency on 'util' on cygwin, where that library wasn't even installed.) Regards, Stefan From rwgk at yahoo.com Fri May 13 09:36:51 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 13 May 2005 00:36:51 -0700 (PDT) Subject: [C++-sig] Boost.Python In-Reply-To: <7fe77fadc08fcd86331737b88be6c467@pleiad.umdnj.edu> Message-ID: <20050513073656.11362.qmail@web31514.mail.mud.yahoo.com> Under OS X I build all "normal" libraries statically (i.e. as .a files). In the early days that seemed to be the only possible solution. I am not sure if this is still necessary, but I am sure it still works. I.e., I have: libboost_python.dylib libxxx.a # your "normal" libraries an_ext.so # Boost.Python extension that you import with "import an_ext" See also: http://cci.lbl.gov/cctbx_build/all.html Go to a recent "summary" link (e.g. currently 2005_05_12_1341), then to one of the Mac OS X build logs. --- Donald Winkelmann wrote: > I've finally was able to get Boost.Python to build on OS X 10.3 > following some suggestions from Tom Denninston. I'm really not familiar > with Boost or Python, but I need it for an application, eman, that uses > it. Now I've run into a libtool error that I don't understand and > perhaps someone can enlighten me: > > /Users/daw/eman/libpyEM: building default_target > Building dependencies. cmake.depends... > Building shared library /Users/daw/eman/lib/libpyEM.dylib... > ld: PyEMDataWrap.o illegal reference to symbol: _PyErr_SetString > defined in indirectly referenced dynamic library > /System/Library/Frameworks/Python.framework/Versions/2.3/Python > /usr/bin/libtool: internal link edit command failed > make[3]: *** [/Users/daw/eman/lib/libpyEM.dylib] Error 1 > make[2]: *** [default_target] Error 2 > make[1]: *** [default_target_libpyEM] Error 2 > make: *** [default_target] Error 2 > > The libpyEM.dylib was linking to libboost_python-1_32.dylib when I > encounter this error. Any suggestions? > > Thanks. > daw > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > __________________________________ Yahoo! Mail Mobile Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail From caleb.epstein at gmail.com Fri May 13 14:02:59 2005 From: caleb.epstein at gmail.com (Caleb Epstein) Date: Fri, 13 May 2005 08:02:59 -0400 Subject: [C++-sig] [python] Fix for embedding.cpp test on SunOS In-Reply-To: <4284188D.9030209@sympatico.ca> References: <989aceac050510133845ec08e5@mail.gmail.com> <4284188D.9030209@sympatico.ca> Message-ID: <989aceac050513050229246d23@mail.gmail.com> On 5/12/05, Stefan Seefeld wrote: > I believe it is the python runtime itself that depends on libutil, You're correct. I missed this in my initial analysis because I linked against a dynamic libpython that pulled in libutil automatically. My initial attempt broke configurations where a static libpython is used (requiring libutil to be specified explicitly). > at least on some systems, so you mustn't remove it if you want > to embedd python. (In contrast I remember at least one python > version to list a wrong dependency on 'util' on cygwin, where > that library wasn't even installed.) .. or on Solaris, where it doesn't exist. The end result of the fix is that PYTHON_EMBEDDED_LIBS includes python, dl and util on all UNIX platforms except Solaris, where util is excluded, and OSX, where the entire list is kept blank (not sure why, I just preserved the existing behavior). -- Caleb Epstein caleb dot epstein at gmail dot com From dave at boost-consulting.com Fri May 13 14:13:31 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 08:13:31 -0400 Subject: [C++-sig] wrapping virtual base class with std::auto_ptr References: Message-ID: Faheem Mitha writes: > Hi, > > Consider the following simple example. This works fine if (for > example) I replace std:auto_ptr with int (see commented-put > lines). This also works if this is just a regular struct (if f is a > normal function returning a std::auto::ptr). > > The compiler errors I get appear below. The offending line is. > > return this->get_override("f")(); > > I have a dim understanding of how Boost.Python works in general, but > really don't understand what magic goes on in wrapping virtual > functions etc. I've just copied the syntax below from the tutorial. > > Thanks in advance for help. Please cc me; I'm not subscribed. > > Faheem. > > ap.cc: In member function `virtual std::auto_ptr BaseWrap::f(int)': I think this has more to do with auto_ptr than with Boost.Python. Try changing: std::auto_ptr f(int val) { return this->get_override("f")(); } into: std::auto_ptr f(int val) { std::auto_ptr r( this->get_override("f")() ); return r; } HTH, Dave -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri May 13 14:38:15 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 08:38:15 -0400 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? References: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Message-ID: Thomas Schipolowski writes: > The Master reference held by the Slave is valid as long as the Python > Master object is alive. Fine. However, this is not the case when the > MDerived and Slave objects are constructed from Python: > > >>> m = t.MDerived() > >>> m.slave = t.Slave(m) > Slave::Slave(master_ptr) > master_ptr use count 3 > master_ptr addr 12410784 > weak_ptr use count 3 > >>> m.status() > MDerived::status() ==> Master::status() > master addr 12410784 > slave use count 1 > Slave::status() > master use count 0 > >>> > > The Master reference held by the weak_ptr expires as soon as the Slave > constructor finishes, although m is still alive. I wonder what the > temporary shared_ptr did to the master object when the ref count went to > zero in this moment? Note however that the behavior is as expected if > the base class m = t.Master() is used instead of m = t.MDerived(). > > Please advise me on how to handle this situation correctly. It should > work the same no matter whether objects are created from python or c++. Here's what's happening: when a wrapped function takes a boost::shared_ptr by value or by const reference, a new shared_ptr that holds a reference to the *Python* T object in its deleter is conjured up(*) so that if that shared_ptr is ever subsequently returned from a wrapped function we can deliver the same owning Python object. Of course, unless it's also stored elsewhere, that shared_ptr goes away, the moment the wrapped function it's passed to returns, and your weak_ptr expires. (*) shared_ptr --------+ (deleter) --+ | | | Python T V | +--------------------+ V | ... | +---+ |(**) shared_ptr ----->| T | | | +---+ +--------------------+ The only way to get ahold of the shared_ptr that the Python T object is using to hold onto the C++ T object(**) is to accept it by non-const reference, which requires Boost.Python to find a persistent object to which the reference can be bound. Slave(pMaster& m): master(m) ... Of course, passing *that* pointer back to Python won't get you the original Python object back. Fortunately, from your example it seems you don't care in this case. Peter: it would be interesting if there was a way to get ahold of the weak_ptr management stuff in the deleter of the outer shared_ptr, so that when (*) is destroyed its weak_ptrs could be re-seated to work on (**)... am I making any sense? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri May 13 14:50:22 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 08:50:22 -0400 Subject: [C++-sig] IQuestion : nner class code boost.python References: <20050512180334.65910.qmail@web30308.mail.mud.yahoo.com> Message-ID: pankaj jain writes: >> Hi , >> I have C++ code like >> class A >> { >> class B; >> --- >> --- >> } >> can any body help me in how I can map inner class for building python >> module. { scope a = class_("A") // whatever ... ; class_("B") // whatever ... ; } HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From petrucio at hoplon.com Fri May 13 15:46:49 2005 From: petrucio at hoplon.com (Petrucio) Date: Fri, 13 May 2005 10:46:49 -0300 Subject: [C++-sig] calling python logger module from C++ In-Reply-To: <21873-58778@sneakemail.com> References: <21873-58778@sneakemail.com> Message-ID: <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> I don't think it is possible. I usually export 'instances' of my varargs functions to python. This could be an issue if the types of your args are also variable, like the standard printf-like functions. You can in this case just export the most common uses, of a string and some other variable after, something like: Your real vararged function: virtual void Log( LogLevel level, std::wstring msg, ... ) = 0; Exported 'instances' virtual void Log( LogLevel level, std::wstring msg) = 0; virtual void Log( LogLevel level, std::wstring msg, int int_arg) = 0; virtual void Log( LogLevel level, std::wstring msg, std::wstring str_arg) = 0; Although I can't immediately see the need for this, since that better place to format your string than python? Beware of performance issues when using an inter-language polimorphic solution this this for something that will probably be called a lot like a logger. Petrucio - Game Programmer Hoplon Infotainment - www.taikodom.com.br At 00:19 12/5/2005, you wrote: >I've been wondering how best to provide support for calling my python logger >(which uses the standard logger module) from within my C++ extensions built >using Boost.Python. My first thought was to do this: > >enum LogLevel { > LogLevelCritical = 50, > LogLevelError = 40, > LogLevelWarning = 30, > LogLevelInfo = 20, > LogLevelDebug = 10 >}; > > >class PiLogger { >public: > > virtual void Log( LogLevel level, std::wstring msg ) = 0; > >}; > >and then implement this class in python, setting it as a static variable in >my C++. This works pretty well, but I'd like to be able to support format >strings, which requires varargs. I couldn't figure out how to wrap a varargs >function - is that even possible? If it's not, is there a better way to >accomplish what I want? > >Thanks, > >Eric > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From pdimov at gmail.com Fri May 13 15:09:45 2005 From: pdimov at gmail.com (Peter Dimov) Date: Fri, 13 May 2005 16:09:45 +0300 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? References: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Message-ID: David Abrahams wrote: > Peter: it would be interesting if there was a way to get ahold of the > weak_ptr management stuff in the deleter of the outer shared_ptr, so > that when (*) is destroyed its weak_ptrs could be re-seated to work on > (**)... am I making any sense? I don't think that this would be possible. Weak_ptr instances cannot be reseated since they can't be enumerated. From pdimov at gmail.com Fri May 13 15:08:00 2005 From: pdimov at gmail.com (Peter Dimov) Date: Fri, 13 May 2005 16:08:00 +0300 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? References: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Message-ID: Thomas Schipolowski wrote: [...] > Please advise me on how to handle this situation correctly. It should > work the same no matter whether objects are created from python or > c++. > > Regards, > Thomas. > > The test code (sorry, its rather long): [...] > class Slave { > public: > Slave(pMaster m): master(m) { I'm not sure that I understand what Boost.Python is doing when it sees your code, but you may want to try to inherit from enable_shared_from_this<> in your Master class and change the Slave constructor to: explicit Slave( Master const * pm ): master( pm->shared_from_this() ) From foo.Clark at gmail.com Fri May 13 16:58:32 2005 From: foo.Clark at gmail.com (Clark) Date: Fri, 13 May 2005 22:58:32 +0800 Subject: [C++-sig] IQuestion : nner class code boost.python In-Reply-To: <20050512180334.65910.qmail@web30308.mail.mud.yahoo.com> References: <20050512180334.65910.qmail@web30308.mail.mud.yahoo.com> Message-ID: <20050513145832.GA8525@dell.cad> On Thu, May 12, 2005 at 11:03:34AM -0700, pankaj jain wrote: > > > Hi , > > I have C++ code like > > class A > > { > > class B; > > --- > > --- > > } > > can any body help me in how I can map inner class for building > python > > module. Please see library reference of Boost.Python on Scope. On my machine the documents is /usr/share/doc/libboost-doc/HTML/libs/python/doc/v2/scope.html There is an example for mapping inner class. From dave at boost-consulting.com Fri May 13 18:03:33 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 12:03:33 -0400 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? References: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Message-ID: "Peter Dimov" writes: > David Abrahams wrote: > >> Peter: it would be interesting if there was a way to get ahold of the >> weak_ptr management stuff in the deleter of the outer shared_ptr, so >> that when (*) is destroyed its weak_ptrs could be re-seated to work on >> (**)... am I making any sense? > > I don't think that this would be possible. Weak_ptr instances cannot > be reseated since they can't be enumerated. I guess if you expanded the deleter's control block you could add a fallback method for the weak_ptr's conversion to shared_ptr... (?) I'm sure this is outside the scope of the library, but it's fun to speculate ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com From faheem at email.unc.edu Fri May 13 18:36:44 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Fri, 13 May 2005 16:36:44 +0000 (UTC) Subject: [C++-sig] wrapping virtual base class with std::auto_ptr References: Message-ID: On Fri, 13 May 2005 08:13:31 -0400, David Abrahams wrote: > Faheem Mitha writes: > >> Hi, >> >> Consider the following simple example. This works fine if (for >> example) I replace std:auto_ptr with int (see commented-put >> lines). This also works if this is just a regular struct (if f is a >> normal function returning a std::auto::ptr). >> >> The compiler errors I get appear below. The offending line is. >> >> return this->get_override("f")(); >> >> I have a dim understanding of how Boost.Python works in general, but >> really don't understand what magic goes on in wrapping virtual >> functions etc. I've just copied the syntax below from the tutorial. >> >> Thanks in advance for help. Please cc me; I'm not subscribed. >> >> Faheem. >> >> ap.cc: In member function `virtual std::auto_ptr BaseWrap::f(int)': > > I think this has more to do with auto_ptr than with Boost.Python. Try > changing: > > std::auto_ptr f(int val) > { > return this->get_override("f")(); > } > > into: > > std::auto_ptr f(int val) > { > std::auto_ptr r( this->get_override("f")() ); > return r; > } I discovered that using boost::shared_ptr works fine, and since I couldn't use auto_ptr anyway (since I wanted to put these pointers inside standard containers), this is what I went with. I went with std::auto_ptr instead, since I naively thought that something in the standard library would be more likely to work out of the box. My best guess at why std::auto_ptr does not work is that it is a limitation of how it is designed. Specifically, that the memory in question cannot be accessed in multiple places simultaneously. Perhaps Boost.Python is trying to do that, or something similar. I'll try your modification and see what happens. Faheem. From dave at boost-consulting.com Fri May 13 19:16:31 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 13:16:31 -0400 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension References: <20050512044619.GA4156@dell.cad> Message-ID: <7ji36o7k.fsf@boost-consulting.com> Hua Su writes: > Hi, > > I'v learnt Boost.Python for two weeks and now encounter some > problems :( In brief, I can't find the way to use a C++ class, which > is exported in an existing extension, in another extension written > by myself. If you are building with bjam per the recommendations at http://www.boost.org/libs/python/doc/building.html it should "just work." > In detail, I'm writing a paint program with wxPython > which is an extension for GUI library wxWidgets (wxWindows). I use > wxPython to implement GUI, and use C++ to implement paint > operations. ( In my application the paint operations is a > bottleneck so I have to implement is in C++ ) When painting, I need > to pass a pointer of DC from Python to my C++ code. The problem is, > the class "wxDC" is a real C++ class writen in wxWidgets, and is > exported in wxPython as Python class "DC", but I need use it in my > code as C++ class "wxDC". So... just use it. What's the problem? > I can't find support from Boost.Python for this problem. Are you seeing error messages? Does compilation fail? Linking? Runtime? Could you reduce your example to some simple code (2 C++ files -- one for each extension module and one Python file to drive the test) that doesn't depend on WxWindows? If you post that, it should be possible to help you. > I have tried to pass pointer "void *" instead, but Boost.Python > declares it does not support "void *" as argument or return type. > Could someone give me some example? I work for this problem for days > :( It isn't clear what problem you're having yet. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri May 13 19:21:11 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 13:21:11 -0400 Subject: [C++-sig] Trouble accessing custom object References: <2A0DA7F7B6B34840A9C133E54514AC25019CA131@cacexc02.americas.cpqcorp.net> Message-ID: <1x8b6nzs.fsf@boost-consulting.com> "Clarke, Ronald" writes: > // ...and try calling printProperties() again, to see if the new > image is printed > int nrunres = PyRun_SimpleString("imageIn.printProperties()\n"); > > > The address of pargsi looks reasonable, and the return code from the > SetAttrString call is zero. > However, PyRun_SimpleString fails with this error: > > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'imageIn' is not defined There's no reason for the unqualified name "imageIn" to be looked up in your filter module AFAICT. I suggest: int nrunres = PyRun_SimpleString( const_cast( extract( str("from %s import *; imageIn.printProperties()\n") % sfilterName ) ) ); HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From pdimov at gmail.com Fri May 13 20:12:23 2005 From: pdimov at gmail.com (Peter Dimov) Date: Fri, 13 May 2005 21:12:23 +0300 Subject: [C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference? References: <42761B18.7090609@dynamik.fb10.tu-berlin.de> Message-ID: David Abrahams wrote: > "Peter Dimov" writes: > >> David Abrahams wrote: >> >>> Peter: it would be interesting if there was a way to get ahold of >>> the weak_ptr management stuff in the deleter of the outer >>> shared_ptr, so that when (*) is destroyed its weak_ptrs could be >>> re-seated to work on (**)... am I making any sense? >> >> I don't think that this would be possible. Weak_ptr instances cannot >> be reseated since they can't be enumerated. > > I guess if you expanded the deleter's control block you could add a > fallback method for the weak_ptr's conversion to shared_ptr... (?) > > I'm sure this is outside the scope of the library, but it's fun to > speculate ;-) As long as we're just speculating, yes, it would be possible for lock() to ask the deleter when it sees use_count() == 0, I guess. This is an odd situation, though; if you can put the original shared_ptr in the deleter, you can also just return this shared_ptr instead of wrapping it. At least in pure C++ code, that is. :-) From beyer at imb-jena.de Fri May 13 20:18:18 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Fri, 13 May 2005 11:18:18 -0700 Subject: [C++-sig] calling python logger module from C++ In-Reply-To: <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> References: <21873-58778@sneakemail.com> <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> Message-ID: <4284EF6A.6020903@imb-jena.de> An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri May 13 23:25:11 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 17:25:11 -0400 Subject: [C++-sig] wrapping virtual base class with std::auto_ptr References: Message-ID: Faheem Mitha writes: > My best guess at why std::auto_ptr does not work is that it is a > limitation of how it is designed. Yes. > Specifically, that the memory in question cannot be accessed in > multiple places simultaneously. No, it has to do with the fact that the auto_ptr copy ctor doesn't take its rhs by const reference. > Perhaps Boost.Python is trying to do that, or something similar. No, this problem is almost entirely between you and the standard library, and has little to do with Boost.Python. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri May 13 23:27:18 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 17:27:18 -0400 Subject: [C++-sig] calling python logger module from C++ References: <21873-58778@sneakemail.com> <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> <4284EF6A.6020903@imb-jena.de> Message-ID: Andreas Beyer writes: > Maybe I am totally wrong... Not totally, but messages of one, long, continuous line are probably at least a _little_ wrong ;-) I didn't read it, FWIW -- too much effort to reformat. You might want to repost. -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Sat May 14 00:17:20 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Fri, 13 May 2005 15:17:20 -0700 Subject: [C++-sig] calling python logger module from C++ In-Reply-To: <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> References: <21873-58778@sneakemail.com> <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> Message-ID: <42852770.4010909@imb-jena.de> OK, once again without formatting. Sorry for that. Maybe I am totally wrong, but what about parsing the vargs inside C/C++, translating them into a std::string and then passing that string over to Python? Thus, you end up with an actual implementation of virtual void Log() in C++ (as opposed the abstract declaration). Internally it might call an abstract method, which only accepts the log-level and one string as arguments. This second method can then be implemented in Python. e.g. virtual void _Log( LogLevel level, std::wstring msg ) = 0; virtual void Log( LogLevel level, std::wstring msg, ... ) { // handle vargs here ... _Log(level, msg); } Andreas Petrucio wrote: >I don't think it is possible. > >I usually export 'instances' of my varargs functions to python. This could >be an issue if the types of your args are also variable, like the standard >printf-like functions. > >You can in this case just export the most common uses, of a string and some >other variable after, something like: > >Your real vararged function: >virtual void Log( LogLevel level, std::wstring msg, ... ) = 0; > >Exported 'instances' >virtual void Log( LogLevel level, std::wstring msg) = 0; >virtual void Log( LogLevel level, std::wstring msg, int int_arg) = 0; >virtual void Log( LogLevel level, std::wstring msg, std::wstring str_arg) = 0; > >Although I can't immediately see the need for this, since that better place >to format your string than python? > >Beware of performance issues when using an inter-language polimorphic >solution this this for something that will probably be called a lot like a >logger. > >Petrucio - Game Programmer >Hoplon Infotainment - www.taikodom.com.br > >At 00:19 12/5/2005, you wrote: > > >>I've been wondering how best to provide support for calling my python logger >>(which uses the standard logger module) from within my C++ extensions built >>using Boost.Python. My first thought was to do this: >> >>enum LogLevel { >> LogLevelCritical = 50, >> LogLevelError = 40, >> LogLevelWarning = 30, >> LogLevelInfo = 20, >> LogLevelDebug = 10 >>}; >> >> >>class PiLogger { >>public: >> >> virtual void Log( LogLevel level, std::wstring msg ) = 0; >> >>}; >> >>and then implement this class in python, setting it as a static variable in >>my C++. This works pretty well, but I'd like to be able to support format >>strings, which requires varargs. I couldn't figure out how to wrap a varargs >>function - is that even possible? If it's not, is there a better way to >>accomplish what I want? >> >>Thanks, >> >>Eric >> >> From dave at boost-consulting.com Sat May 14 00:21:16 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 13 May 2005 18:21:16 -0400 Subject: [C++-sig] wrapping virtual base class with std::auto_ptr References: Message-ID: <4qd66a3n.fsf@boost-consulting.com> David Abrahams writes: > Faheem Mitha writes: > >> My best guess at why std::auto_ptr does not work is that it is a >> limitation of how it is designed. > > Yes. > >> Specifically, that the memory in question cannot be accessed in >> multiple places simultaneously. > > No, it has to do with the fact that the auto_ptr copy ctor doesn't > take its rhs by const reference. > >> Perhaps Boost.Python is trying to do that, or something similar. > > No, this problem is almost entirely between you and the standard > library, and has little to do with Boost.Python. By way of explanation, let me remind you that get_override doesn't return an auto_ptr directly: it returns something that's *convertible* to auto_ptr. -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Sat May 14 01:01:59 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Fri, 13 May 2005 16:01:59 -0700 Subject: [C++-sig] Pointer to existing Python object In-Reply-To: <427810C4.7050802@imb-jena.de> References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> Message-ID: <428531E7.2030301@imb-jena.de> This message was also in HTML format. So I am sending it again. Sorry. David, thanks a lot for the help! However, I think your suggestion does not yet solve the problem. See below. David Abrahams wrote: >Andreas Beyer writes: > > > >>Hi: >> >>I know that there has been some discussion on this subject on c++ sig. >>However, I could not find a solution for my specific problem and maybe >>there is no solution. >> >>Here we go: >> >>I have a container class B that creates instances of class A - both >>in C++. In Python I can get instances of A from B with a get() >>method. I would like to get an existing Python object whenever such >>object existis and I would like to get a new Python object if no >>Python object for A exists. >> >> > >This is hard to do. I see that you're using shared_ptr and that's a >good start. What you need to do, the moment a shared_ptr is about to >be released to Python, is replace it: > > template > hold_python(shared_ptr& x) > { > x = extract >( python::object(x) ); > } > > > This doesn't seem to work. Below is an example Python session, get() still returns different objects. Is it possible, that boost::python deletes the internal smart-pointer immediately after exiting hold_python() because the python object does not persist beyond this block? I.e. when I call hold_python() again, does the boost::python environment still 'know' the pointer? I changed hold_python() such that it returns a copy of the python object, but that doesn't help either. The idea was, if the python interpreter holds a reference to the python object, the shared_ptr might survive. But maybe I am on the wrong track. Here is my attempt: template python::object hold_python(shared_ptr& x) { python::object py_x = python::object(x); x = python::extract >( py_x ); return py_x; } python::object get_b_a(B& b) { return hold_python(b.a); } This is my example Python session using David's suggestions (C++ code follows): >>> a=A() >>> b=B() >>> b.set(a) >>> a.val=10 >>> a.foo=42 >>> a2=b.get() >>> a >>> a2 >>> a.val 10 >>> a2.val 10 >>> a.foo 42 >>> a2.foo 42 >>> b=B() >>> a=b.get() # let b create an A >>> a.val=10 >>> a.foo=42 >>> a2=b.get() >>> a >>> a2 # Still not the same as 'a' >>> a.val 10 >>> a2.val 10 >>> a.foo 42 >>> a2.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'foo' >>> Thus, the C++ object is the same, the Python object isn't. #include #include #include using namespace boost; class A : public enable_shared_from_this { public: A() : val(0) {}; int val; typedef shared_ptr A_ptr; A_ptr self() { A_ptr self; self = shared_from_this(); return self; } }; class B { public: B() { a = A::A_ptr(new A()); } void set(A::A_ptr a) { this->a = a; } A::A_ptr get() { return a; } A::A_ptr a; }; template void hold_python(shared_ptr& x) { x = python::extract >( python::object(x) ); } A::A_ptr get_b_a(B& b) { hold_python(b.a); return b.get(); } BOOST_PYTHON_MODULE(ptr_test) { python::class_ ("A") .def("self", &A::self) .def_readwrite("val", &A::val) ; python::register_ptr_to_python< A::A_ptr >(); python::class_("B") .def("set", &B::set) // .def("get", &B::get) .def("get", get_b_a) ; } Thanks for the help, Andreas From petrucio at hoplon.com Sat May 14 01:26:56 2005 From: petrucio at hoplon.com (Petrucio) Date: Fri, 13 May 2005 20:26:56 -0300 Subject: [C++-sig] calling python logger module from C++ In-Reply-To: <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> References: <21873-58778@sneakemail.com> <6.0.2.0.1.20050513103400.01bf4ec0@mail.hoplon.com> Message-ID: <6.0.2.0.1.20050513202242.01b5e070@mail.hoplon.com> I was reading Andreas post and re-thinking about mine and it is actually a little nuts. Exporting wrapper instances of a var-argged function like this can only be done if you already have an implementor in C++ to call... Need coffee. At 10:46 13/5/2005, you wrote: >I don't think it is possible. > >I usually export 'instances' of my varargs functions to python. This could >be an issue if the types of your args are also variable, like the standard >printf-like functions. > >You can in this case just export the most common uses, of a string and some >other variable after, something like: > >Your real vararged function: >virtual void Log( LogLevel level, std::wstring msg, ... ) = 0; > >Exported 'instances' >virtual void Log( LogLevel level, std::wstring msg) = 0; >virtual void Log( LogLevel level, std::wstring msg, int int_arg) = 0; >virtual void Log( LogLevel level, std::wstring msg, std::wstring str_arg) = 0; > >Although I can't immediately see the need for this, since that better place >to format your string than python? > >Beware of performance issues when using an inter-language polimorphic >solution this this for something that will probably be called a lot like a >logger. > >Petrucio - Game Programmer >Hoplon Infotainment - www.taikodom.com.br > >At 00:19 12/5/2005, you wrote: > >I've been wondering how best to provide support for calling my python logger > >(which uses the standard logger module) from within my C++ extensions built > >using Boost.Python. My first thought was to do this: > > > >enum LogLevel { > > LogLevelCritical = 50, > > LogLevelError = 40, > > LogLevelWarning = 30, > > LogLevelInfo = 20, > > LogLevelDebug = 10 > >}; > > > > > >class PiLogger { > >public: > > > > virtual void Log( LogLevel level, std::wstring msg ) = 0; > > > >}; > > > >and then implement this class in python, setting it as a static variable in > >my C++. This works pretty well, but I'd like to be able to support format > >strings, which requires varargs. I couldn't figure out how to wrap a varargs > >function - is that even possible? If it's not, is there a better way to > >accomplish what I want? > > > >Thanks, > > > >Eric > > > >_______________________________________________ > >C++-sig mailing list > >C++-sig at python.org > >http://mail.python.org/mailman/listinfo/c++-sig > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From rwgk at yahoo.com Sat May 14 03:32:21 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 13 May 2005 18:32:21 -0700 (PDT) Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension In-Reply-To: 6667 Message-ID: <20050514013221.29299.qmail@web31501.mail.mud.yahoo.com> I guess the problem is that wxDC is not wrapped with Boost.Python, but with SWIG. Therefore Boost.Python doesn't know how to extract the wxDC instance (or a reference to the instance) from the Python object. I believe this can be solved in a nice and general (via a custom from_python converter), but first I'd experiment like this (untested): void foo(boost::python::object wxDC_swig_object) { } ... def("foo", foo); Pass your SWIG-wrapped wxDC instance to foo(). This should work in any case, I hope. Once you get this working, develop the body of foo(). I'd look at the SWIG generated code for a wxPython function that accepts a wxDC object as an argument. SWIG uses PyArg_ParseTuple() to get a PyObject*; in foo() you want to use wxDC_swig_object.ptr() to get the same pointer. You have to find out how SWIG extracts the wxDC instance given the PyObject* and emulate this in the body of foo(). From within foo() you can finally call your function expecting a wxDC object. Let us know if you get this far. The next step would be to rewrite foo() as a custom converter. However, it is only worth it if you want to wrap a number of functions with wxDC in the argument list. Otherwise the "thin wrapper" approach above (foo() is the thin wrapper) is the final solution. --- Hua Su wrote: > Hi, > > I'v learnt Boost.Python for two weeks and now encounter some problems :( > > In brief, I can't find the way to use a C++ class, which is exported in > an > > existing extension, in another extension written by myself. > > In detail, I'm writing a paint program with wxPython which is an > > extension for GUI library wxWidgets (wxWindows). I use wxPython to implement > > GUI, and use C++ to implement paint operations. > > ( In my application the paint operations is a bottleneck so I have to > implement > > is in C++ ) > > When painting, I need to pass a pointer of DC from Python to my C++ code. > > The problem is, the class "wxDC" is a real C++ class writen in wxWidgets, > > and is exported in wxPython as Python class "DC", but I need use it in my > > code as C++ class "wxDC". I can't find support from Boost.Python for > > this problem. I have tried to pass pointer "void *" instead, but Boost.Python > > declares it does not support "void *" as argument or return type. > > Could someone give me some example? I work for this problem for days :( > > Thanks for your reply. > > regards, > Clark __________________________________ Yahoo! Mail Mobile Take Yahoo! Mail with you! Check email on your mobile phone. http://mobile.yahoo.com/learn/mail From dave at boost-consulting.com Sat May 14 10:30:15 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 14 May 2005 04:30:15 -0400 Subject: [C++-sig] Pointer to existing Python object References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> Message-ID: Andreas Beyer writes: > David, thanks a lot for the help! However, I think your suggestion does > not yet solve the problem. See below. It should; I have a fix in the works. I'm preparing to check it into CVS. -- Dave Abrahams Boost Consulting www.boost-consulting.com From r.p.cornelisse at planet.nl Sat May 14 10:45:20 2005 From: r.p.cornelisse at planet.nl (Robert Cornelisse) Date: Sat, 14 May 2005 10:45:20 +0200 Subject: [C++-sig] Triaxis editor? Message-ID: <0IGH00JE81MTUK@smtp17.wxs.nl> Hi Hamilton, I was wondering if you are the person who created the Triaxis editor. :-) If so, I am desperately looking for the MIDI layout of the Triaxis and I was hoping that you would be so kind to send it to me. I have a v.1.0 Triaxis and the current editor can't deal with the sysex data, so I was thinking I'd write a v.1.0 editor and share it with the Triaxis community. Thanks, Robert r.p.cornelisse at planet.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From foo.Clark at gmail.com Mon May 16 03:47:14 2005 From: foo.Clark at gmail.com (Clark) Date: Mon, 16 May 2005 09:47:14 +0800 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension In-Reply-To: <20050514013221.29299.qmail@web31501.mail.mud.yahoo.com> References: <20050514013221.29299.qmail@web31501.mail.mud.yahoo.com> Message-ID: <20050516014714.GA28985@dell.cad> We know that cross-module type info share is easy with latest Swig or Boost.Python. But how to make it possible to do with Swig and Boost.Python together? For example, we have two c++ extension A and B, which are exposed with Swig and Boost.Python, respectively. They are as follows: ==============Module A wrapped with Swig =============== class Base { public: Base(); ... }; -------------------------------------------------------- ========== Module B wrapped with Boost.Python ========== void foo(Base *); class Derive: public Base { ... }; -------------------------------------------------------- I wish to use module A and B in Python like this: ============= Module A and B used in Python ============ >>>import A >>>import B >>>obj = A.Base() >>>B.foo(obj) >>>obj = B.Derive() >>>B.foo(obj) -------------------------------------------------------- Could anybody give me a solution or some hints? I've working for this for long. On Fri, May 13, 2005 at 06:32:21PM -0700, Ralf W. Grosse-Kunstleve wrote: > I guess the problem is that wxDC is not wrapped with Boost.Python, but with > SWIG. Therefore Boost.Python doesn't know how to extract the wxDC instance (or > a reference to the instance) from the Python object. I believe this can be Yes, wxPython uses SWIG. > solved in a nice and general (via a custom from_python converter), but first > I'd experiment like this (untested): > > void > foo(boost::python::object wxDC_swig_object) > { > } > > ... > > def("foo", foo); > > Pass your SWIG-wrapped wxDC instance to foo(). This should work in any case, I > hope. Once you get this working, develop the body of foo(). I'd look at the > SWIG generated code for a wxPython function that accepts a wxDC object as an > argument. SWIG uses PyArg_ParseTuple() to get a PyObject*; in foo() you want to > use wxDC_swig_object.ptr() to get the same pointer. You have to find out how > SWIG extracts the wxDC instance given the PyObject* and emulate this in the > body of foo(). From within foo() you can finally call your function expecting a > wxDC object. > > Let us know if you get this far. The next step would be to rewrite foo() as a > custom converter. However, it is only worth it if you want to wrap a number of > functions with wxDC in the argument list. Otherwise the "thin wrapper" approach > above (foo() is the thin wrapper) is the final solution. Thanks very much. It's very useful for me. Your solution should be correct, although I failed to test it for other reasons. I've tried your approach, but it seems something wrong with my SWIG. SWIG's manual says I need link my extension with SWIG run time library (libswigpy.a or libswigpy.so). But in my installation of SWIG there isn't nether libswigpy.a nor libswigpy.so. I don't know why. > > --- Hua Su wrote: > > Hi, > > > > I'v learnt Boost.Python for two weeks and now encounter some problems :( > > > > In brief, I can't find the way to use a C++ class, which is exported in > > an > > > > existing extension, in another extension written by myself. > > > > In detail, I'm writing a paint program with wxPython which is an > > > > extension for GUI library wxWidgets (wxWindows). I use wxPython to implement > > > > GUI, and use C++ to implement paint operations. > > > > ( In my application the paint operations is a bottleneck so I have to > > implement > > > > is in C++ ) > > > > When painting, I need to pass a pointer of DC from Python to my C++ code. > > > > The problem is, the class "wxDC" is a real C++ class writen in wxWidgets, > > > > and is exported in wxPython as Python class "DC", but I need use it in my > > > > code as C++ class "wxDC". I can't find support from Boost.Python for > > > > this problem. I have tried to pass pointer "void *" instead, but Boost.Python > > > > declares it does not support "void *" as argument or return type. > > > > Could someone give me some example? I work for this problem for days :( > > > > Thanks for your reply. > > > > regards, > > Clark > > > > > __________________________________ > Yahoo! Mail Mobile > Take Yahoo! Mail with you! Check email on your mobile phone. > http://mobile.yahoo.com/learn/mail > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From foo.Clark at gmail.com Mon May 16 03:49:46 2005 From: foo.Clark at gmail.com (Clark) Date: Mon, 16 May 2005 09:49:46 +0800 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension In-Reply-To: <7ji36o7k.fsf@boost-consulting.com> References: <20050512044619.GA4156@dell.cad> <7ji36o7k.fsf@boost-consulting.com> Message-ID: <20050516014946.GB28985@dell.cad> On Fri, May 13, 2005 at 01:16:31PM -0400, David Abrahams wrote: > Hua Su writes: > > > Hi, > > > > I'v learnt Boost.Python for two weeks and now encounter some > > problems :( In brief, I can't find the way to use a C++ class, which > > is exported in an existing extension, in another extension written > > by myself. > > If you are building with bjam per the recommendations at > http://www.boost.org/libs/python/doc/building.html it should "just > work." > > > In detail, I'm writing a paint program with wxPython > > which is an extension for GUI library wxWidgets (wxWindows). I use > > wxPython to implement GUI, and use C++ to implement paint > > operations. ( In my application the paint operations is a > > bottleneck so I have to implement is in C++ ) When painting, I need > > to pass a pointer of DC from Python to my C++ code. The problem is, > > the class "wxDC" is a real C++ class writen in wxWidgets, and is > > exported in wxPython as Python class "DC", but I need use it in my > > code as C++ class "wxDC". > > So... just use it. What's the problem? I'm sorry. I forgot to point out that wxPython is wrapped with SWIG, NOT Boost.Python. Thus I can't use it directly. > > > I can't find support from Boost.Python for this problem. > > Are you seeing error messages? Does compilation fail? Linking? > Runtime? > > Could you reduce your example to some simple code (2 C++ files -- one > for each extension module and one Python file to drive the test) that > doesn't depend on WxWindows? If you post that, it should be possible > to help you. > > > I have tried to pass pointer "void *" instead, but Boost.Python > > declares it does not support "void *" as argument or return type. > > Could someone give me some example? I work for this problem for days > > :( > > It isn't clear what problem you're having yet. I've posted another msg and given an simple example to illustrated my problem. > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From dave at boost-consulting.com Mon May 16 16:39:56 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 16 May 2005 10:39:56 -0400 Subject: [C++-sig] Pointer to existing Python object References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> Message-ID: David Abrahams writes: > Andreas Beyer writes: > >> David, thanks a lot for the help! However, I think your suggestion does >> not yet solve the problem. See below. > > It should; I have a fix in the works. I'm preparing to check it into > CVS. Done. Please let me know if it works for you. -- Dave Abrahams Boost Consulting www.boost-consulting.com From apocalypznow at gmail.com Tue May 17 01:19:07 2005 From: apocalypznow at gmail.com (apocalypznow) Date: Mon, 16 May 2005 16:19:07 -0700 Subject: [C++-sig] python callback - can it be stateful? Message-ID: Is there a way to have C++ call a Python callback, but have that Python callback operate on global python variables that have kept their state from previous callbacks? Another similar question: can a Python callback set a global variable while another Python callback get the state of that variable? From dreamingpython at 163.com Thu May 19 08:41:39 2005 From: dreamingpython at 163.com (ÒÊÃÉɽÈË) Date: Thu, 19 May 2005 14:41:39 +0800 Subject: [C++-sig] how to config a com object in a customize dll? Message-ID: why the com created in python were configed in python23com.dll? how can i config it in my customize dll? and how use it in VC++? From dave at boost-consulting.com Thu May 19 15:07:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 May 2005 09:07:35 -0400 Subject: [C++-sig] python callback - can it be stateful? References: Message-ID: apocalypznow writes: > Is there a way to have C++ call a Python callback, but have that Python > callback operate on global python variables that have kept their state > from previous callbacks? I don't understand the question. If the Python interpreter is still running (PyInitialize has been called and PyFinalize hasn't), any "global" Python variables (attributes of a Python module) remain unchanged. > Another similar question: can a Python callback set a global variable > while another Python callback get the state of that variable? This question is similarly confusing. FWIW, neither of these questions has anything specific to do with integrating Python and C++; you might want to try asking on comp.lang.python. Cheers, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu May 19 17:29:17 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 May 2005 11:29:17 -0400 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension References: <20050514013221.29299.qmail@web31501.mail.mud.yahoo.com> <20050516014714.GA28985@dell.cad> Message-ID: Clark writes: > We know that cross-module type info share is easy with latest Swig or > Boost.Python. > But how to make it possible to do with Swig and Boost.Python together? > > For example, we have two c++ extension A and B, which are exposed > with Swig and Boost.Python, respectively. They are as follows: > > ==============Module A wrapped with Swig =============== > class Base > { > public: > Base(); > ... > }; > -------------------------------------------------------- > > ========== Module B wrapped with Boost.Python ========== > void foo(Base *); > > class Derive: public Base > { > ... > }; > -------------------------------------------------------- > > I wish to use module A and B in Python like this: > > ============= Module A and B used in Python ============ >>>>import A >>>>import B >>>>obj = A.Base() >>>>B.foo(obj) >>>>obj = B.Derive() >>>>B.foo(obj) > -------------------------------------------------------- > > Could anybody give me a solution or some hints? I've working for > this for long. Well, you can use the raw converter stuff, which is documented in http://www.boost.org/libs/python/doc/v2/reference.html#type_conversion. You might also see the test code that exercises these facilities in libs/python/test/m1.cpp, libs/python/test/m2.cpp, and libs/python/test/newtest.py. If SWIG is generating a Python extension type object BaseType, and an extension instance type BaseObject corresponding to Base, you could use lvalue_from_pytype, something like: lvalue_from_pytype,&BaseType>(); Otherwise, you'll have to touch some ugly, undocumented details of Boost.Python. Let me know if you need that, and I'll try to help. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu May 19 17:40:06 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 19 May 2005 11:40:06 -0400 Subject: [C++-sig] how to config a com object in a customize dll? References: Message-ID: "????????" writes: > why the com created in python were configed in python23com.dll? how can i > config it in my customize dll? > > and how use it in VC++? This sounds like a Python/Windows/'C' API question. I suggest you ask on comp.lang.python. In particular, see if you can get Mark Hammond's attention; he's responsible for the Python/COM integration. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From suh at mails.tsinghua.edu.cn Fri May 20 03:05:46 2005 From: suh at mails.tsinghua.edu.cn (Hua Su) Date: Fri, 20 May 2005 09:05:46 +0800 Subject: [C++-sig] In a C++ extension, how to use a C++ class exported in another extension In-Reply-To: References: <20050514013221.29299.qmail@web31501.mail.mud.yahoo.com> <20050516014714.GA28985@dell.cad> Message-ID: <20050520010546.GA26126@dell.cad> On Thu, May 19, 2005 at 11:29:17AM -0400, David Abrahams wrote: > The following message is a courtesy copy of an article > that has been posted to gmane.comp.python.c++ as well. > > Clark writes: > > > We know that cross-module type info share is easy with latest Swig or > > Boost.Python. > > But how to make it possible to do with Swig and Boost.Python together? > > > > For example, we have two c++ extension A and B, which are exposed > > with Swig and Boost.Python, respectively. They are as follows: > > > > ==============Module A wrapped with Swig =============== > > class Base > > { > > public: > > Base(); > > ... > > }; > > -------------------------------------------------------- > > > > ========== Module B wrapped with Boost.Python ========== > > void foo(Base *); > > > > class Derive: public Base > > { > > ... > > }; > > -------------------------------------------------------- > > > > I wish to use module A and B in Python like this: > > > > ============= Module A and B used in Python ============ > >>>>import A > >>>>import B > >>>>obj = A.Base() > >>>>B.foo(obj) > >>>>obj = B.Derive() > >>>>B.foo(obj) > > -------------------------------------------------------- > > > > Could anybody give me a solution or some hints? I've working for > > this for long. > > Well, you can use the raw converter stuff, which is documented in > http://www.boost.org/libs/python/doc/v2/reference.html#type_conversion. > You might also see the test code that exercises these facilities in > libs/python/test/m1.cpp, libs/python/test/m2.cpp, and > libs/python/test/newtest.py. > > If SWIG is generating a Python extension type object BaseType, and an > extension instance type BaseObject corresponding to Base, you could > use lvalue_from_pytype, something like: > > lvalue_from_pytype BaseObject, Base, &BaseObject::value>,&BaseType>(); > > Otherwise, you'll have to touch some ugly, undocumented details of > Boost.Python. Let me know if you need that, and I'll try to help. > Thanks very much! This information is very useful for me. It should be the solution I've looking for. > HTH, > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From dreamingpython at 163.com Fri May 20 03:17:09 2005 From: dreamingpython at 163.com (????) Date: Fri, 20 May 2005 09:17:09 +0800 Subject: [C++-sig] how to config a com object in a customize dll? References: Message-ID: thank you very much! "David Abrahams" ???? news:ur7g3gr6x.fsf at boost-consulting.com... "????????" writes: > why the com created in python were configed in python23com.dll? how can i > config it in my customize dll? > > and how use it in VC++? This sounds like a Python/Windows/'C' API question. I suggest you ask on comp.lang.python. In particular, see if you can get Mark Hammond's attention; he's responsible for the Python/COM integration. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Fri May 20 04:11:42 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 19 May 2005 19:11:42 -0700 Subject: [C++-sig] Pointer to existing Python object In-Reply-To: References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> Message-ID: <428D475E.8020303@imb-jena.de> David Abrahams wrote: >David Abrahams writes: > > > >>Andreas Beyer writes: >> >> >> >>>David, thanks a lot for the help! However, I think your suggestion does >>>not yet solve the problem. See below. >>> >>> >>It should; I have a fix in the works. I'm preparing to check it into >>CVS. >> >> > >Done. Please let me know if it works for you. > > > It does. It works with the code at the end of my last posting: http://mail.python.org/pipermail/c++-sig/2005-May/008910.html Now I can do this: >>> from ptr_test import * >>> a=A() >>> b=B() >>> b.set(a) >>> a >>> b.get() >>> b=B() >>> a=b.get() # make new A inside b (factory method) >>> a2=b.get() # test if the two python wrappers are the same >>> a >>> a2 >>> a.foo=42 # alter object in python >>> a2.foo # container b 'remembers' the change 42 >>> I think this is a very strong concept of general interest: I can now change Python attributs of wrappers (such as adding attributs in Python), although the objects were created and are managed by C++ code. (By management I mean live-time management.) There is no difficulty if you get an object from a C++ factory class and store it in a Python container. However, I want to store it in a C++ container. In general, the two classes (the container and the factory) can of course be distinct. I don't think David's sollution is affected by this. Thanks! Andreas From dave at boost-consulting.com Fri May 20 13:03:36 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 20 May 2005 07:03:36 -0400 Subject: [C++-sig] Pointer to existing Python object References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> <428D475E.8020303@imb-jena.de> Message-ID: Andreas Beyer writes: > I think this is a very strong concept of general interest: I can now > change Python attributs of wrappers (such as adding attributs in > Python), although the objects were created and are managed by C++ > code. (By management I mean live-time management.) There is no > difficulty if you get an object from a C++ factory class and store > it in a Python container. However, I want to store it in a C++ > container. In general, the two classes (the container and the > factory) can of course be distinct. I don't think David's sollution > is affected by this. If you think there is something here of general interest, you might want to rephrase that. I _think_ I understand what you're saying, but I'm not sure that others will. FWIW, if you have total control over the C++ code involved, you can of course convert objects to Python "greedily", or even create them in Python to begin with: object py_a = class_("A") .def("self", &A::self) .def_readwrite("val", &A::val) ; // Now create A objects in Python via: object some_a = py_a(); Now you can store some_a in a C++ container. Or you can shared_ptr ap(extract(py_a)); and store ap, which will manage the lifetime of the same python object. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Fri May 20 19:47:52 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Fri, 20 May 2005 10:47:52 -0700 Subject: [C++-sig] Pointer to existing Python object In-Reply-To: References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> <428D475E.8020303@imb-jena.de> Message-ID: <428E22C8.8080403@imb-jena.de> Ok, I'll try it again: The code of my initial posting is already an example for what I am trying to outline here. If you understood the issues related with it, stop reading here. Assume you have two C++ classes A and B. Objects of A are stored in B (B is a container). You also have a C++ factory class, for simplicity lets assume this too is B, i.e. objects of kind A get created by B objects (in C++ code). When you now send instances of A back and forth between your python code and the container B, you would like to always have the same python wrapper around your As whenever the C++ instances are the same. This worked already when you initially created the objects in python and then stored them in the C++ container. However, it failed for instances created by factory objects that get placed in the container before(!) the newly created objects are returned to the python environment. That means: when you retreive the same C++ object twice you would get two different python wrappers around the same C++ object. There is no harm in this as long as you don't use the python wrappers for anything else than accessing the underlying C++ object. But already comparison might fail (unless you overwrite the == operator). Thus in python: >>> b = B() # make a container/factory >>> a1 = b.get() # get one wrapper for a contained in b >>> a2 = b.get() # try to get the *same* object >>> assert(a1 == a2) # will fail In this example a1 and a2 will refer to the same underlying C++ instance, but the wrappers are different. The technical problem is: boost::python does not 'know' that there is already an existing wrapper a1 when you call get() for the second time. (David, correct my if I'm wrong.) The sollution suggested by David is to create a temporary python wrapper in the C++ wrapper code. After that, the boost::python wizardry will remember the smart pointer (always use smart pointers in this business!) and return the same python wrapper for instances of A. See here http://mail.python.org/pipermail/c++-sig/2005-April/008849.html and here http://mail.python.org/pipermail/c++-sig/2005-May/008910.html for the solution. After aplying these changes you not only can compare the python instances as shown above, but you can even modify the wrappers themselve, e.g. by adding new (python) attributes. Comparison must work if you use instances of A as keys in a python dict. If you only need comparison to work properly it might also be possible to define __cmp__() in your wrapper code. I haven't tested this option, but I don't see why it shouldn't work. Finally, just to be very explicit: You don't need to consider all this stuff if either - you don't have C++ code where instances get placed in a container inside C++ before returning them to the python interpreter or - you *only* need the python wrapper to inspect/modify the underlying C++ instance. Hope this is better understandable. Andreas David Abrahams wrote: >Andreas Beyer writes: > > > >>I think this is a very strong concept of general interest: I can now >>change Python attributs of wrappers (such as adding attributs in >>Python), although the objects were created and are managed by C++ >>code. (By management I mean live-time management.) There is no >>difficulty if you get an object from a C++ factory class and store >>it in a Python container. However, I want to store it in a C++ >>container. In general, the two classes (the container and the >>factory) can of course be distinct. I don't think David's sollution >>is affected by this. >> >> > >If you think there is something here of general interest, you might >want to rephrase that. I _think_ I understand what you're saying, but >I'm not sure that others will. > > > > From mrovner at propel.com Fri May 20 20:39:36 2005 From: mrovner at propel.com (Mike Rovner) Date: Fri, 20 May 2005 11:39:36 -0700 Subject: [C++-sig] Pointer to existing Python object In-Reply-To: <428E22C8.8080403@imb-jena.de> References: <425B363E.8090905@imb-jena.de> <427810C4.7050802@imb-jena.de> <428531E7.2030301@imb-jena.de> <428D475E.8020303@imb-jena.de> <428E22C8.8080403@imb-jena.de> Message-ID: Andreas Beyer wrote: > environment. That means: when you retreive the same C++ object twice you > would get two different python wrappers around the same C++ object. Why can't you use reference_existing_object policy? Mike From ron.clarke at hp.com Tue May 24 00:42:43 2005 From: ron.clarke at hp.com (Ron Clarke) Date: Mon, 23 May 2005 15:42:43 -0700 Subject: [C++-sig] Trouble accessing custom object References: <2A0DA7F7B6B34840A9C133E54514AC25019CA131@cacexc02.americas.cpqcorp.net> <1x8b6nzs.fsf@boost-consulting.com> Message-ID: David - thanks for the reply. I was off working on something else for a while; now I'm back to this... Perhaps I'm more confused than I thought, but I'm not sure your answer gets to my issue. What I'm trying to do is assign a instance of a C++ object (whose class is wrapped by Boost) to a variable in a user-written Python script, in much the same way one would use Py_BuildValue and PyObject_SetAttrString to set values inherently understood by Python, such as integers and strings. I thought I could use syntax like this in my C++ code, after importing the Python script: PyObject &pargsi = PyBuildValue("O", &myimage); PyObject_SetAttrString(ptrFitler, "imageIn", pargsi); //where "imageIn" is the variable in the Python script I've not been able to get this to work. (I've tried several variations of this theme after reading the Boost Python docs again). By the way, I have tried setting integer and string variables in the Python script, just to make sure I understood the concepts. They worked fine. Am I missing something basic? Is there a way to do what I need to do? Thanks in advance. "David Abrahams" wrote in message news:1x8b6nzs.fsf at boost-consulting.com... > "Clarke, Ronald" writes: > >> // ...and try calling printProperties() again, to see if the new >> image is printed >> int nrunres = PyRun_SimpleString("imageIn.printProperties()\n"); >> >> >> The address of pargsi looks reasonable, and the return code from the >> SetAttrString call is zero. >> However, PyRun_SimpleString fails with this error: >> >> Traceback (most recent call last): >> File "", line 1, in ? >> NameError: name 'imageIn' is not defined > > There's no reason for the unqualified name "imageIn" to be looked up > in your filter module AFAICT. > > I suggest: > > int nrunres = PyRun_SimpleString( > const_cast( > extract( > str("from %s import *; imageIn.printProperties()\n") % > sfilterName > ) > ) > ); > > HTH, > > -- > Dave Abrahams > Boost Consulting > www.boost-consulting.com From dave at boost-consulting.com Tue May 24 13:40:23 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 24 May 2005 07:40:23 -0400 Subject: [C++-sig] Trouble accessing custom object References: <2A0DA7F7B6B34840A9C133E54514AC25019CA131@cacexc02.americas.cpqcorp.net> <1x8b6nzs.fsf@boost-consulting.com> Message-ID: "Ron Clarke" writes: > David - thanks for the reply. > > I was off working on something else for a while; now I'm back to this... > > Perhaps I'm more confused than I thought, but I'm not sure your > answer gets to my issue. Your use of terminology may have confused me. When there are two languages involved, precision is really important. > What I'm trying to do is assign a instance of a C++ object (whose > class is wrapped by Boost) to a variable in a user-written Python > script, in much the same way one would use Py_BuildValue and > PyObject_SetAttrString to set values inherently understood by > Python, such as integers and strings. In Python, you "bind" names to values. > I thought I could use syntax like this in my C++ code, after importing the > Python script: > PyObject &pargsi = PyBuildValue("O", &myimage); *-----------^ > PyObject_SetAttrString(ptrFitler, "imageIn", pargsi); //where "imageIn" > is the variable in the Python script The call to Py_BuildValue is not only misspelled, it doesn't do anything useful and will probably cause a crash. See http://docs.python.org/api/arg-parsing.html#l2h-214 for the expectations Python has about the 2nd argument when the first argument is "O" It's not a "variable," it's an attribute of the ptrFilter object -- which I presume is a pointer to a module. If you are trying to convert myimage to Python, I'd: python::object filter(handle<>(ptrFilter)); filter.attr("imageIn") = python::object(myImage); > I've not been able to get this to work. (I've tried several > variations of this theme after reading the Boost Python docs again). Which of the two lines doesn't work? What happens when it "doesn't work?" > By the way, I have tried setting integer and string variables in the > Python script, I think you meant you tried to set the integer and string variables in the python _module_. Setting them in a Python script would be something like: # Python code integer = 3 string = 'foo' > just to make sure I understood the concepts. They > worked fine. How did you try to set them, and what indicated to you that it worked? > Am I missing something basic? Is there a way to do what I need to > do? I still don't have a clear idea of what you're after or what problems you had. -- Dave Abrahams Boost Consulting www.boost-consulting.com From news4vovan at mail.ru Tue May 24 21:58:44 2005 From: news4vovan at mail.ru (Vladimir Sukhoy) Date: Tue, 24 May 2005 22:58:44 +0300 Subject: [C++-sig] pyste reports no-policy even if wrapper specified Message-ID: I specified a wrapper for a function (class static method in fact), which avoids returning reference, but pyste still reports an error. From nicodemus at esss.com.br Tue May 24 22:20:54 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Tue, 24 May 2005 17:20:54 -0300 Subject: [C++-sig] pyste reports no-policy even if wrapper specified In-Reply-To: References: Message-ID: <42938CA6.8090506@esss.com.br> Hi Vladimir, Could you post a small reproductible test case? Thanks, Bruno. Vladimir Sukhoy wrote: >I specified a wrapper for a function (class static method in fact), which >avoids returning reference, but pyste still reports an error. > > > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig > > > > From news4vovan at mail.ru Wed May 25 09:44:55 2005 From: news4vovan at mail.ru (Vladimir Sukhoy) Date: Wed, 25 May 2005 10:44:55 +0300 Subject: [C++-sig] pyste reports no-policy even if wrapper specified References: <42938CA6.8090506@esss.com.br> Message-ID: > Could you post a small reproductible test case? Ok: test.hpp : #include class test_class { public: static char * blah() { return "blah"; } }; std::string blah_wrapper() { return test_class::blah(); } pyste file: test = Class("test_class", "test.hpp") set_wrapper(test.blah, 'blah_wrapper') pyste output: ---> Error: test_class::blah returns a pointer or a reference, but no policy was specified. Module _test generated From smckay at yahoo-inc.com Fri May 27 00:19:51 2005 From: smckay at yahoo-inc.com (Scott McKay) Date: Thu, 26 May 2005 16:19:51 -0600 Subject: [C++-sig] policy in map_indexing_suite for map Message-ID: Is there a way to override the usage of default_call_policies in the map indexing suite without patching map_indexing_suite? I have a std::map with a const pointer as the data type - so I need to provide an appropriate call policy. Many thanks. Scott ---- Scott McKay Yahoo! -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant at grantgoodyear.org Fri May 27 00:31:13 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Thu, 26 May 2005 17:31:13 -0500 Subject: [C++-sig] pyste shared_ptr question Message-ID: <20050526223113.GI3776@bmb24.uth.tmc.edu> I'm slowly trying to convert some code that throws around raw pointers to use shared_ptr. My current pyste file looks like: Include("emdata.h") Enum("EMAN::fp_flag", "fundamentals.h") periodogram = Function("EMAN::periodogram", "fundamentals.h") set_policy(periodogram, return_value_policy(manage_new_object)) where periodogram returns an EMData*. So, I went through and changed my C++ code to return a shared_ptr, and manually patched my boost.python code to read: def("periodogram", &EMAN::periodogram); // removed return policy register_ptr_to_python< shared_ptr >(); and the code works beautifully, at least as far as I can tell. What's the magic pyste invocation to do the same thing? I'd like to avoid EMData = Class('EMAN::EMData', 'emdata.h') use_shared_ptr(EMData) because that seems to bring in all of the junk in EMData into this module. Help? Thanks, Grant Goodyear -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org From dking at nrao.edu Fri May 27 18:35:10 2005 From: dking at nrao.edu (David King) Date: Fri, 27 May 2005 10:35:10 -0600 Subject: [C++-sig] callbacks to python Message-ID: <42974C3E.9000002@nrao.edu> Hi all: Can you quickly tell me how boost might support calling back from C[++] into python, as described in the Python C API here: http://docs.python.org/ext/callingPython.html Thanks, dk From djowel at gmail.com Sat May 28 00:37:24 2005 From: djowel at gmail.com (Joel de Guzman) Date: Sat, 28 May 2005 06:37:24 +0800 Subject: [C++-sig] policy in map_indexing_suite for map In-Reply-To: References: Message-ID: <4297A124.5040906@boost-consulting.com> Scott McKay wrote: > Is there a way to override the usage of default_call_policies in the map > indexing suite without patching map_indexing_suite? > > I have a std::map with a const pointer as the data type - so I need to > provide an appropriate call policy. I'm sorry, but, no, not at the moment. If this is a common use case, perhaps we should make it a part of the DerivedPolicies? Thoughts? Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From dave at boost-consulting.com Sat May 28 04:16:38 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 27 May 2005 22:16:38 -0400 Subject: [C++-sig] callbacks to python References: <42974C3E.9000002@nrao.edu> Message-ID: David King writes: > Hi all: > > Can you quickly tell me how boost might support calling back from C[++] into > python, as described in the Python C API here: > > http://docs.python.org/ext/callingPython.html Once you get ahold of a callable Python object by your favorite means, and store it in a boost::python::object, it's as simple as calling that object. void call_back(boost::python::object f) { f(3.14, "hello, world"); // or whatever } HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From arunie at gmail.com Tue May 31 18:23:40 2005 From: arunie at gmail.com (Arunie) Date: Tue, 31 May 2005 12:23:40 -0400 Subject: [C++-sig] Traceback error: Pointer Message-ID: Hey, I keep running into this error and I can't figure out what it is that's going wrong. I wrote a code for C++, where it basically registers an interface. It's a test for now, so it goes out and gets the interface, registers it, and then unregisters it. Then I wrote a python file that does the same thing, and it uses SWIG to talk to C++ files. All this is done compiling with the Makefile. But when I try to run the python file, I keep getting this error that drives me nuts. I did not include the files generated by the Makefile commands, as they shouldn't be edited (I could be wrong). The original files are as follows : ========================================== // // Example.cpp // #include #include "Example.h" ExampleClass::ExampleClass() { std::cout << __PRETTY_FUNCTION__ << "\n"; this->init(); } ExampleClass::~ExampleClass() { std::cout << __PRETTY_FUNCTION__ << "\n"; } void ExampleClass::registerInterface(ExampleInterface* newInterface) { std::cout << __PRETTY_FUNCTION__ << "\n"; this->interface = newInterface; } void ExampleClass::callInterface() { std::cout << __PRETTY_FUNCTION__ << "\n"; if (this->interface) { this->interface->doMe(); } else { std::cout << "no callback currently registered\n"; } } void ExampleClass::unregisterInterface() { std::cout << __PRETTY_FUNCTION__ << "\n"; this->init(); } void ExampleClass::init() { std::cout << __PRETTY_FUNCTION__ << "\n"; this->interface = 0; } ============================================================== =========================== // // Example.h // #ifndef _EXAMPLE_H_ #define _EXAMPLE_H_ class ExampleInterface { public: virtual void doMe() = 0; }; class ExampleClass { public: ExampleClass(); ~ExampleClass(); void registerInterface(ExampleInterface* newInterface); void callInterface(); void unregisterInterface(); private: void init(); private: ExampleInterface* interface; }; #endif ================================================== ======================================================== // // Example.i // //%module("directors=1") Example %module Example %{ #include "Example.h" %} //%feature("director") ExampleInterface; class ExampleInterface { public: virtual void doMe() = 0; }; class ExampleClass { public: ExampleClass(); ~ExampleClass(); void registerInterface(ExampleInterface* newInterface); void callInterface(); void unregisterInterface(); }; ================================================================ ============================================================= // // Makefile // NAME = Example ALL = _${NAME}.so test${NAME} SRCS = ${NAME}.cpp test${NAME}.cpp OBJS = ${SRCS:.cpp=.o} CPP = g++ SRC_CFLAGS = -Wall SWIG_CFLAGS = -fpic -I/usr/include/python2.3 LDFLAGS = -shared all: ${ALL} clean: rm -f ${ALL} ${NAME}_wrap.cpp ${NAME}.py ${NAME}.pyc *.o *.doc *~ test: ${ALL} @echo "Running test${NAME}..." ./test${NAME} @echo @echo "Running test${NAME}.py..." ./test${NAME}.py _${NAME}.so: ${NAME}.o ${NAME}_wrap.o ${CPP} ${LDFLAGS} -o $@ $^ ${OBJS}: %.o: %.cpp ${CPP} ${SRC_CFLAGS} -c -o $@ $< ${NAME}_wrap.o: ${NAME}_wrap.cpp ${CPP} ${SWIG_CFLAGS} -c -o $@ $< ${NAME}_wrap.cpp: ${NAME}.i swig -python -c++ -o $@ $< test${NAME}: %: %.o ${OBJS} ${CPP} -o $@ $^ ============================================================ ================================================================ // // testExample.cpp // #include #include "Example.h" class TestInterface : public ExampleInterface { public: void doMe(); }; void TestInterface::doMe() { std::cout << __PRETTY_FUNCTION__ << "\n"; }; int main(int argc, char** argv) { ExampleClass myObject; TestInterface myInterface; myObject.registerInterface(&myInterface); myObject.callInterface(); myObject.unregisterInterface(); } =============================================================== AND OFCOURSE, MY PROBLEM: ============================================================ #!/usr/bin/python import Example class TestInterface(Example.ExampleInterface): def __init__(self): print "TestInterface::__init__()" def doMe(self): print "TestInterface::doMe()" myObject = Example.ExampleClass() myInterface = TestInterface() myObject.registerInterface(myInterface) myObject.callInterface() myObject.unregisterInterface() ================================================================= I run Red Hat Enterprise Linux 3. Python - 2.3.4-14 SWIG - 1.3.21-6 Now I run the command: make all and then the command: make test This is the error I get: ----------------------------------------------------------------------------- Running testExample... ./testExample ExampleClass::ExampleClass() void ExampleClass::init() void ExampleClass::registerInterface(ExampleInterface*) void ExampleClass::callInterface() virtual void TestInterface::doMe() void ExampleClass::unregisterInterface() void ExampleClass::init() ExampleClass::~ExampleClass() Running testExample.py... ./testExample.py make: ./testExample.py: Command not found make: *** [test] Error 127 ----------------------------------------------------------------------------------- And so I figured since ./testExample.py isn't going properly, I run the command: python testExample.py Results are this: ------------------------------------------------------------------------------- ExampleClass::ExampleClass() void ExampleClass::init() TestInterface::__init__() Traceback (most recent call last): File "testExample.py", line 14, in ? myObject.registerInterface(myInterface) File "/root/Originals/Example.py", line 68, in registerInterface def registerInterface(*args): return _Example.ExampleClass_registerInterface(*args) TypeError: Expected a pointer ExampleClass::~ExampleClass() ---------------------------------------------------------------------------------- I checked the file Example.py, but found nothing. I can't figure out where I'm going wrong. Any help would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lothar at xcerla.com Tue May 31 18:35:01 2005 From: lothar at xcerla.com (Lothar Werzinger) Date: Tue, 31 May 2005 09:35:01 -0700 Subject: [C++-sig] Traceback error: Pointer In-Reply-To: References: Message-ID: <200505310935.01985.lothar@xcerla.com> On Tuesday 31 May 2005 09:23, Arunie wrote: > ./testExample.py > make: ./testExample.py: Command not found > And so I figured since ./testExample.py isn't going properly, I run the > command: python testExample.py If I am not mistaken you try to run the Python script directly and it does not work and if you run it with the python interpreter it works? Could be any of the following: - file is not executable (check if the x bit is set) - file does not contain the line #!/usr/bin/python as the first line - file is not in the the current directory/search path during execution. Lothar Werzinger -- Lothar Werzinger Dipl.-Ing. Univ. framework & platform architect Xcerla Corporation 275 Tennant Avenue, Suite 202 Morgan Hill, Ca 95037 email: lothar at xcerla.com phone: +1-408-776-9018 From lothar at xcerla.com Tue May 31 20:33:13 2005 From: lothar at xcerla.com (Lothar Werzinger) Date: Tue, 31 May 2005 11:33:13 -0700 Subject: [C++-sig] Traceback error: Pointer In-Reply-To: References: <200505310935.01985.lothar@xcerla.com> Message-ID: <200505311133.13966.lothar@xcerla.com> On Tuesday 31 May 2005 10:57, Arunie wrote: > No, it doesn't work either way. The python part itself uses the swig > interface, and relies on other Example files. > The file is executable, but it won't execute. I am sorry, but I do not > understand what you mean by 'check if the x bit is set'. I tried to look it > up online, but no avail. Well, as you said you call ./testExample.py I assumed you are using a Unix system. On these systems scripts can specify the interpreter to use by putting a line like #!pathtointerpreter/interpreter as the FIRST line of the script. If this line is missing or wrong you can NOT execute the script like ./testExample.py you would have to write python ./testExample.py instead. If the script contains the line mentioned, it still has to be marked as executable. This can be achieved by issuing the command chmod +x ./testExample.py on the commandline Lothar -- Lothar Werzinger Dipl.-Ing. Univ. framework & platform architect Xcerla Corporation 275 Tennant Avenue, Suite 202 Morgan Hill, Ca 95037 email: lothar at xcerla.com phone: +1-408-776-9018 From skottmckay at gmail.com Tue May 31 21:44:38 2005 From: skottmckay at gmail.com (Scott McKay) Date: Tue, 31 May 2005 13:44:38 -0600 Subject: [C++-sig] policy in map_indexing_suite for map In-Reply-To: References: Message-ID: <51d01787050531124464d27984@mail.gmail.com> > From: Joel de Guzman > Subject: Re: [C++-sig] policy in map_indexing_suite for map Y*> > Message-ID: <4297A124.5040906 at boost-consulting.com> > > I'm sorry, but, no, not at the moment. If this is a common use case, > perhaps we should make it a part of the DerivedPolicies? Thoughts? I'll take a stab at adding it as a DerivedPolicy. Not totally sure how to, but doing so will be a good way to learn. From arunie at gmail.com Tue May 31 22:08:36 2005 From: arunie at gmail.com (Arunie) Date: Tue, 31 May 2005 16:08:36 -0400 Subject: [C++-sig] policy in map_indexing_suite for map In-Reply-To: <51d01787050531124464d27984@mail.gmail.com> References: <51d01787050531124464d27984@mail.gmail.com> Message-ID: Hey, just to let you know, you have left me clueless as what you are talking about. You must have the wrong person. On 5/31/05, Scott McKay wrote: > > > From: Joel de Guzman > > Subject: Re: [C++-sig] policy in map_indexing_suite for map > Y*> > > Message-ID: <4297A124.5040906 at boost-consulting.com> > > > > I'm sorry, but, no, not at the moment. If this is a common use case, > > perhaps we should make it a part of the DerivedPolicies? Thoughts? > > I'll take a stab at adding it as a DerivedPolicy. Not totally sure how > to, but doing so will be a good way to learn. > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: