From kalin.eh at gmail.com Sun Apr 3 10:52:15 2005 From: kalin.eh at gmail.com (kalin) Date: Sun, 03 Apr 2005 18:52:15 +1000 Subject: [C++-sig] Re: what happened with this std::string parameter in boost.python In-Reply-To: References: <20041216072015.4E0ED1E4008@bag.python.org> Message-ID: David Abrahams wrote: > Donnie Leen wrote: > >>I made a program embedding boost.python, writting a module as following: >> >>void write( std::string s ) >>{ >> // do nothing >>} >>BOOST_PYTHON_MODULE(mym) >>{ >> def( "write", &write ); >>} >> >> >>I run the python code: >>import mym >>s = 'hello' >>mym.write(s) >> >>it runs ok, but if i run the python code as following: >>import mym >>s = int.__doc__ >>mym.write(s) >> >>it crashed > > > What do you mean by "crashed?" Are you sure it didn't throw an > exception that was never caught? > > I had this problem earlier. It would just access violate, as though the string had a bad buffer pointer. I didn't look into it too much and changed it to const char*'s so I could just get things working. Although now, when I change it back to test, it doesn't crash anymore. :( FWIW kalin From H.Duerer at gmx.net Mon Apr 4 18:07:57 2005 From: H.Duerer at gmx.net (Holger Duerer) Date: Mon, 04 Apr 2005 17:07:57 +0100 Subject: [C++-sig] Re: what happened with this std::string parameter in boost.python References: <20041216072015.4E0ED1E4008@bag.python.org> Message-ID: <87u0mmy17m.fsf@ronaldann.demon.co.uk> >>>>> "kalin" == kalin writes: kalin> David Abrahams wrote: >> Donnie Leen wrote: >> >>> I made a program embedding boost.python, writting a module as following: >>> >>> void write( std::string s ) >>> { >>> // do nothing >>> } >>> BOOST_PYTHON_MODULE(mym) >>> { >>> def( "write", &write ); >>> } >>> >>> >>> I run the python code: >>> import mym >>> s = 'hello' >>> mym.write(s) >>> >>> it runs ok, but if i run the python code as following: >>> import mym >>> s = int.__doc__ >>> mym.write(s) >>> >>> it crashed >> What do you mean by "crashed?" Are you sure it didn't throw an >> exception that was never caught? >> [...] Is this under Windows? We had problems like that -- short string (<16 bytes?) work, long strings cause a crash. We traced this to multiple versions of the C++ runtime library. Are you linking the runtime library statically? Holger From paniq at paniq.org Tue Apr 5 05:39:09 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Tue, 05 Apr 2005 05:39:09 +0200 Subject: [C++-sig] doing iterators another way... Message-ID: <4252085D.6010304@paniq.org> the example that is given in the tutorial for iterators is giving a standard way of solving the problem for c++ iterators, but i'm also using enumerators which provide a set of current/next/reset commands. for those interested, this is how i turned my class into an iterator: template struct Enumerator : Mu::Interface::Unknown { typedef typename Ptrfy::Type ElementReturnType; virtual Mu::Result Mu_InterfaceCall MoveNext(Bool& succeeded) = 0; virtual Mu::Result Mu_InterfaceCall Current(T& current) = 0; virtual Mu::Result Mu_InterfaceCall Reset() = 0; Mu_WrapGetMethod(MoveNext,Bool); Mu_WrapGetMethod(Current,ElementReturnType); }; template typename T::ElementReturnType iterator_next(T* enumerator) { if (!enumerator->MoveNext()) { PyErr_SetString(PyExc_StopIteration,""); boost::python::throw_error_already_set(); } return enumerator->Current(); } template T* MakePythonIteratorFromEnumerator(T* enumerator) { enumerator->Reset(); return enumerator; } and here's some pseudo-boost.python code: class_ >("EnumeratorClass") .def("__iter__", &MakePythonIteratorFromEnumerator, return_internal_reference<>()) .def("next", &iterator_next) ; From paniq at paniq.org Tue Apr 5 10:16:28 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Tue, 05 Apr 2005 10:16:28 +0200 Subject: [C++-sig] doing iterators another way... In-Reply-To: <4252085D.6010304@paniq.org> References: <4252085D.6010304@paniq.org> Message-ID: <4252495C.9020604@paniq.org> the approach below has the flaw that recursive iterations will fail since the enumerator is not cloned. for that purpose i added a Clone() method to the enumerator interface which is called in MakePythonIteratorFromEnumerator, where a Ptr (a custom smart pointer class) is returned, hence suspending the need for a return value call policy. Leonard "paniq" Ritter wrote: > the example that is given in the tutorial for iterators is giving a > standard way of solving the problem for c++ iterators, but i'm also > using enumerators which provide a set of current/next/reset commands. > for those interested, this is how i turned my class into an iterator: > > template > struct Enumerator : Mu::Interface::Unknown > { typedef typename Ptrfy::Type > ElementReturnType; > > virtual Mu::Result Mu_InterfaceCall MoveNext(Bool& > succeeded) = 0; > virtual Mu::Result Mu_InterfaceCall Current(T& current) = 0; > virtual Mu::Result Mu_InterfaceCall Reset() = 0; > > Mu_WrapGetMethod(MoveNext,Bool); > Mu_WrapGetMethod(Current,ElementReturnType); > }; > > template > typename T::ElementReturnType iterator_next(T* enumerator) > { > if (!enumerator->MoveNext()) > { > PyErr_SetString(PyExc_StopIteration,""); > boost::python::throw_error_already_set(); > } > return enumerator->Current(); > } > > template > T* MakePythonIteratorFromEnumerator(T* enumerator) > { enumerator->Reset(); > return enumerator; > } > > and here's some pseudo-boost.python code: > > class_ > >("EnumeratorClass") > .def("__iter__", > &MakePythonIteratorFromEnumerator, > return_internal_reference<>()) > .def("next", &iterator_next) > ; > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From thomas.schipolowski at tu-berlin.de Tue Apr 5 13:28:55 2005 From: thomas.schipolowski at tu-berlin.de (Thomas Schipolowski) Date: Tue, 5 Apr 2005 13:28:55 +0200 Subject: [C++-sig] crashes on functions with std::string arguments Message-ID: <001101c539d2$a6d7c0c0$89689582@dynamik.local> Hello, I am using Python 2.3 and Boost_1_32_0 with VC6 on Windows 2000. I experience crashes due to heap corruption when a function or method with a std::string argument is called. The same problem is also triggered by the extract facility. The following test code reproduces both conditions: #include #include using namespace boost::python; int test1(std::string s) { return s.end() - s.begin(); } int test2(object o) { extract extr(o); if (extr.check()) { std::string s(extr()); return s.end() - s.begin(); } else { return -1; } } BOOST_PYTHON_MODULE(test) { def("test1", test1); def("test2", test2); } The error will not be immediately apparent until the extension is compiled in debug mode. Calling any of the above functions from python will then (always) pop up a message saying "Debug Assertion _CrtIsValidHeapPtr() failed". When compiled without debug, the function calls may succeed many times before an "unidentifyable C++ exception" is reported. The interpreter will segfault at this point or later on, depending on memory usage. Now I saw this message http://mail.python.org/pipermail/c++-sig/2005-April/008760.html on the list which seems related. With regard to the explanation given there (multiple versions of the C++ runtime library on windows) I agree that this is a possible reason in my case, as the problem mysteriously went away when I switched from my Win 2000 box at work to a Win XP Laptop. But yesterday I tried on a third computer (also XP) and there it crashed the same as on Win 2000. However, I think the standard library is statically linked in my case. (But I am not sure how to check and control this in the VC-IDE.) I tried to dig into the source with a debugger, but couldn't find a solution so far. Details are below. I would be glad about any advice on how to correct this or work around it. Many thanks, Thomas Schipolowski The debugger shows me that the error happens at the point where the temporary std::string object stored in rvalue_from_python_data<>::storage.bytes is destroyed. (In case of the test1() function this happens when detail::caller_arity<1>::impl<>::operator() finishes. In the test2() function it is the destruction of the extr variable when test2() returns.) Further inside the std::string destructor, the problem is apparently caused by the destructor trying to deallocate the internal character buffer. At this point I thought there might be something wrong with the copy-on-write implementation of std::string. In fact, the string s in test2() is destroyed first, deleting its buffer, and then it crashes when the string contained in extr is destroyed, again deleting its buffer. But I am not sure if there is actually anything shared between both string objects. From what I saw in the debugger, it appears that the constructor of s initializes its pointer to the character buffer of a temporary string which is created as return value of extract_rvalue::operator(). The buffer address of s is different from the buffer of the string in extract_rvalue<>.m_data.storage.bytes. I have no idea what can be wrong here. From dave at boost-consulting.com Tue Apr 5 14:11:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 05 Apr 2005 08:11:54 -0400 Subject: [C++-sig] Re: crashes on functions with std::string arguments References: <001101c539d2$a6d7c0c0$89689582@dynamik.local> Message-ID: "Thomas Schipolowski" writes: > Hello, > I am using Python 2.3 and Boost_1_32_0 with VC6 on Windows 2000. I > experience crashes due to heap corruption when a function or method with a > std::string argument is called. The same problem is also triggered by the > extract facility. > The following test code reproduces both conditions: Not by itself, it doesn't! What Python code do you need to execute to generate the crash? > #include > #include > using namespace boost::python; > > int test1(std::string s) { > return s.end() - s.begin(); > } > > int test2(object o) { > extract extr(o); > if (extr.check()) { > std::string s(extr()); > return s.end() - s.begin(); > } else { > return -1; > } > } > > BOOST_PYTHON_MODULE(test) > { > def("test1", test1); > def("test2", test2); > } -- Dave Abrahams Boost Consulting www.boost-consulting.com From thomas.schipolowski at tu-berlin.de Tue Apr 5 14:56:06 2005 From: thomas.schipolowski at tu-berlin.de (Thomas Schipolowski) Date: Tue, 5 Apr 2005 14:56:06 +0200 Subject: [C++-sig] Re: crashes on functions with std::string arguments References: <001101c539d2$a6d7c0c0$89689582@dynamik.local> Message-ID: <000701c539de$d4a3e180$89689582@dynamik.local> Thanks for the quick reply Dave! > > The following test code reproduces both conditions: > > Not by itself, it doesn't! What Python code do you need to execute to > generate the crash? I simple invoke python.exe in a console window (that's also what the debugger in the VC-IDE does) and say >>> import test >>> test.test1("Otto") or >>> test.test2("Otto") In debug mode, the message box with the _CrtIsValidHeapPointer Assertion Failure opens instantly before the python prompt returns. I can answer the message box with "Retry" and get an "unidentifyable C++ exception". When not compiled with debug, I do something like >>> for i in range(100): print i, test.test2("Otto") This prints "4" between 10 and 30 times, then prints the above mentioned exception. If I invoke the loop statement again I usually get only one "4" or even no "4", followed by the exception. Repeating the loop statement further, I get varying numbers of "4"s, but never again 20... At some point, the interpreter will crash with a memory write access violation (I dont know the English wording of the dialog.) This can happen at any time - I have seen it sometimes as early as the tenth invokation of test2() and sometimes only when I terminated the interpreter via Crtl-Z after many repetitions of the above loop command. However, calling test2() with something that is not accepted by extract, e.g. test2(None) or test2(10), will never crash (I tried the loop with range(100000)). It will print -1 as it should. Thanks again, Thomas. From dave at boost-consulting.com Tue Apr 5 16:19:51 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 05 Apr 2005 10:19:51 -0400 Subject: [C++-sig] Re: crashes on functions with std::string arguments References: <001101c539d2$a6d7c0c0$89689582@dynamik.local> <000701c539de$d4a3e180$89689582@dynamik.local> Message-ID: "Thomas Schipolowski" writes: > Thanks for the quick reply Dave! > >> > The following test code reproduces both conditions: >> >> Not by itself, it doesn't! What Python code do you need to execute to >> generate the crash? > > I simple invoke python.exe in a console window (that's also what the > debugger in the VC-IDE does) and say >>>> import test >>>> test.test1("Otto") > or >>>> test.test2("Otto") Works fine for me here, building and testing with Boost.Build. This is a build problem on your end (see the tip at the top of http://www.boost.org/libs/python/doc/tutorial/doc/html/python/hello.html). If you examine the build command-lines it should be easy to verify that you have multiple runtime libraries in use. -- Dave Abrahams Boost Consulting www.boost-consulting.com From thomas.schipolowski at tu-berlin.de Wed Apr 6 09:18:40 2005 From: thomas.schipolowski at tu-berlin.de (Thomas Schipolowski) Date: Wed, 6 Apr 2005 09:18:40 +0200 Subject: [C++-sig] Re: crashes on functions with std::string arguments References: <001101c539d2$a6d7c0c0$89689582@dynamik.local><000701c539de$d4a3e180$89689582@dynamik.local> Message-ID: <000501c53a78$dd1bcb80$89689582@dynamik.local> > Works fine for me here, building and testing with Boost.Build. This > is a build problem on your end Yes, I compiled the test case with BJam and now it works flawlessly. Great! One complication is left: I wonder now how to explain to BJam that some of my files need to be fed to a fortran compiler, before they are linked with the c++ objects. Would you say that using BJams 'prebuilt binaries' feature with an external fortran build is the best way to achieve that, or is it reasonably easy to tell BJam about the fortran toolchain? Is the latter documented somewhere? Again, thanks very much for the quick help. Thomas. From dave at boost-consulting.com Wed Apr 6 15:05:18 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 06 Apr 2005 09:05:18 -0400 Subject: [C++-sig] Re: crashes on functions with std::string arguments References: <001101c539d2$a6d7c0c0$89689582@dynamik.local> <000701c539de$d4a3e180$89689582@dynamik.local> <000501c53a78$dd1bcb80$89689582@dynamik.local> Message-ID: "Thomas Schipolowski" writes: >> Works fine for me here, building and testing with Boost.Build. This >> is a build problem on your end > > > Yes, I compiled the test case with BJam and now it works flawlessly. Great! > One complication is left: I wonder now how to explain to BJam that some of > my files need to be fed to a fortran compiler, before they are linked with > the c++ objects. Would you say that using BJams 'prebuilt binaries' feature > with an external fortran build is the best way to achieve that, or is it > reasonably easy to tell BJam about the fortran toolchain? Is the latter > documented somewhere? Well, Boost.Build v2 has a fortran toolset, but it seems to be under-documented $ bjam --v2 --help fortran Module 'fortran': This file contains common settings for all fortran tools Module 'fortran' classes: Use --help fortran. to get more information. * fortran-compiling-generator: I'm not sure what you need to do to configure it. Maybe its author can help? I suggest following up to the jamboost list (http://www.boost.org/more/mailing_lists.htm#jamboost). > Again, thanks very much for the quick help. > Thomas. -- Dave Abrahams Boost Consulting www.boost-consulting.com From jbrandmeyer at earthlink.net Thu Apr 7 05:25:31 2005 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Wed, 06 Apr 2005 23:25:31 -0400 Subject: [C++-sig] build system feature requests Message-ID: <1112844331.17274.34.camel@localhost.localdomain> Could you add two features to the build scripts for Boost.Python? First, when running bjam from libs/python/build, the libraries are not name mangled as described here: http://www.boost.org/more/getting_started.html#Results Second, It is fairly common (for me, at least), to have more than one version of Python installed on my system at any given time. Is it possible to add -py23, -py24, etc. to the standard mangling scheme and the build directory layout? Thanks, -Jonathan Brandmeyer From grafik.list at redshift-software.com Thu Apr 7 05:46:55 2005 From: grafik.list at redshift-software.com (Rene Rivera) Date: Wed, 06 Apr 2005 22:46:55 -0500 Subject: [C++-sig] build system feature requests In-Reply-To: <1112844331.17274.34.camel@localhost.localdomain> References: <1112844331.17274.34.camel@localhost.localdomain> Message-ID: <4254AD2F.4050808@redshift-software.com> Jonathan Brandmeyer wrote: > Could you add two features to the build scripts for Boost.Python? > First, when running bjam from libs/python/build, the libraries are not > name mangled as described here: > http://www.boost.org/more/getting_started.html#Results Ok that's easy enough. And other libraries already do that. > Second, It is fairly common (for me, at least), to have more than one > version of Python installed on my system at any given time. Is it > possible to add -py23, -py24, etc. to the standard mangling scheme and > the build directory layout? Also easy, but this one I would ask Dave and others to comment as I'm not an expert on BPL usage. I would think that this only applies to BPL extensions and the BPL library itself. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org From dave at boost-consulting.com Thu Apr 7 06:58:41 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 07 Apr 2005 00:58:41 -0400 Subject: [C++-sig] Re: build system feature requests References: <1112844331.17274.34.camel@localhost.localdomain> <4254AD2F.4050808@redshift-software.com> Message-ID: Rene Rivera writes: > Jonathan Brandmeyer wrote: >> Could you add two features to the build scripts for Boost.Python? >> First, when running bjam from libs/python/build, the libraries are not >> name mangled as described here: >> http://www.boost.org/more/getting_started.html#Results > > Ok that's easy enough. And other libraries already do that. > >> Second, It is fairly common (for me, at least), to have more than one >> version of Python installed on my system at any given time. Is it >> possible to add -py23, -py24, etc. to the standard mangling scheme and >> the build directory layout? > > Also easy, but this one I would ask Dave and others to comment as I'm > not an expert on BPL usage. I don't have much to say about it. Sounds OK to me. -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Thu Apr 7 23:42:01 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 07 Apr 2005 14:42:01 -0700 Subject: [C++-sig] "_POSIX_C_SOURCE" redefined Message-ID: <4255A929.9030200@imb-jena.de> Hi, I keep getting the "_POSIX_C_SOURCE" redefined warning when compiling my own project with BJAM. The problem was described in: http://mail.python.org/pipermail/c++-sig/2005-February/008564.html In my case the examples get compiled without a warning, but my own project causes the warning: gcc-C++-action bin/csrc/network.so/gcc/release/shared-linkable-true/network.o In file included from /cellar/users/abeyer/boost/boost_current/boost/python/detail/wrap_python.hpp:30, from /cellar/users/abeyer/boost/boost_current/boost/python/detail/prefix.hpp:13, from /cellar/users/abeyer/boost/boost_current/boost/python/args.hpp:8, from /cellar/users/abeyer/boost/boost_current/boost/python.hpp:11, from property_handle.hpp:16, from node.hpp:26, from connection.hpp:18, from network.cpp:13: /cellar/users/abeyer/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/include/c++/3.2.3/i386-redhat-linux/bits/os_defines.h:39, from /usr/include/c++/3.2.3/i386-redhat-linux/bits/c++config.h:34, from /usr/include/c++/3.2.3/string:45, from connection.hpp:15, from network.cpp:13: /usr/include/features.h:131:1: warning: this is the location of the previous definition Since examples work, I guess I am doing something wrong, but I can't figure out what. I tried different orderings of the includes in property_handle.hpp. I tried #include first, before the standard library includes (like etc.) and I tried including first the std-lib includes and including boost/python.hpp afterwards. Neither worked. So which ordering is correct? What do I have to look at? Thanks!! Andreas From rwgk at yahoo.com Fri Apr 8 00:29:42 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 7 Apr 2005 15:29:42 -0700 (PDT) Subject: [C++-sig] "_POSIX_C_SOURCE" redefined In-Reply-To: 6667 Message-ID: <20050407222942.2709.qmail@web31510.mail.mud.yahoo.com> --- Andreas Beyer wrote: > Since examples work, I guess I am doing something wrong, but I can't > figure out what. I tried different orderings of the includes in > property_handle.hpp. I tried #include first, before > the standard library includes (like etc.) and I tried including > first the std-lib includes and including boost/python.hpp afterwards. > Neither worked. > So which ordering is correct? What do I have to look at? #include should be at the very top of your wrapper code. Cheers, Ralf __________________________________ Do you Yahoo!? Yahoo! Personals - Better first dates. More second dates. http://personals.yahoo.com From lothar at xcerla.com Fri Apr 8 00:58:06 2005 From: lothar at xcerla.com (Lothar Werzinger) Date: Thu, 7 Apr 2005 15:58:06 -0700 Subject: [C++-sig] "_POSIX_C_SOURCE" redefined In-Reply-To: <20050407222942.2709.qmail@web31510.mail.mud.yahoo.com> References: <20050407222942.2709.qmail@web31510.mail.mud.yahoo.com> Message-ID: <200504071558.07154.lothar@xcerla.com> On Thursday 07 April 2005 15:29, Ralf W. Grosse-Kunstleve wrote: > --- Andreas Beyer wrote: > > Since examples work, I guess I am doing something wrong, but I can't > > figure out what. I tried different orderings of the includes in > > property_handle.hpp. I tried #include first, before > > the standard library includes (like etc.) and I tried including > > first the std-lib includes and including boost/python.hpp afterwards. > > Neither worked. > > So which ordering is correct? What do I have to look at? > > #include > > should be at the very top of your wrapper code. And even that may not be enough. We use boost::python and log4cplus and unfortunately log4cplus also defines some macros that conflict with macros previously defined in pythons headers. The only sane way for the probme is that the developers of Python (and log4cplus) fix their headers. /opt2/log4cplus/include/log4cplus/config.h:79:1: warning: "HAVE_STAT" redefined In file included from /opt2/python-2.4/include/python2.4/Python.h:55, from /opt2/boost/include/boost-1_32/boost/python/detail/wrap_python.hpp:121, from /opt2/boost/include/boost-1_32/boost/python/detail/prefix.hpp:13, from /opt2/boost/include/boost-1_32/boost/python/args.hpp:8, from /opt2/boost/include/boost-1_32/boost/python.hpp:11, from src/utility/PythonInterpreterGuard.h:10, from src/rating/test/PythonRatingStepTest.cpp:10: /opt2/python-2.4/include/python2.4/pyport.h:139:1: warning: this is the location of the previous definition 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 beyer at imb-jena.de Fri Apr 8 01:09:38 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 07 Apr 2005 16:09:38 -0700 Subject: [C++-sig] "_POSIX_C_SOURCE" redefined In-Reply-To: <200504071558.07154.lothar@xcerla.com> References: <20050407222942.2709.qmail@web31510.mail.mud.yahoo.com> <200504071558.07154.lothar@xcerla.com> Message-ID: <4255BDB2.8030006@imb-jena.de> Lothar Werzinger wrote: >On Thursday 07 April 2005 15:29, Ralf W. Grosse-Kunstleve wrote: > > >>--- Andreas Beyer wrote: >> >> >>>Since examples work, I guess I am doing something wrong, but I can't >>>figure out what. I tried different orderings of the includes in >>>property_handle.hpp. I tried #include first, before >>>the standard library includes (like etc.) and I tried including >>>first the std-lib includes and including boost/python.hpp afterwards. >>>Neither worked. >>>So which ordering is correct? What do I have to look at? >>> >>> >>#include >> >>should be at the very top of your wrapper code. >> >> > >And even that may not be enough. We use boost::python and log4cplus and >unfortunately log4cplus also defines some macros that conflict with macros >previously defined in pythons headers. The only sane way for the probme is >that the developers of Python (and log4cplus) fix their headers. > >/opt2/log4cplus/include/log4cplus/config.h:79:1: warning: "HAVE_STAT" >redefined >In file included from /opt2/python-2.4/include/python2.4/Python.h:55, > >from /opt2/boost/include/boost-1_32/boost/python/detail/wrap_python.hpp:121, > >from /opt2/boost/include/boost-1_32/boost/python/detail/prefix.hpp:13, > from /opt2/boost/include/boost-1_32/boost/python/args.hpp:8, > from /opt2/boost/include/boost-1_32/boost/python.hpp:11, > from src/utility/PythonInterpreterGuard.h:10, > from src/rating/test/PythonRatingStepTest.cpp:10: >/opt2/python-2.4/include/python2.4/pyport.h:139:1: warning: this is the >location of the previous definition > >Lothar > > Can you post that to the Python developers? I thought it was common sense, that include order shouldn't matter. Andreas From Marc.Kwiatkowski at veritas.com Fri Apr 8 01:13:36 2005 From: Marc.Kwiatkowski at veritas.com (Marc Kwiatkowski) Date: Thu, 7 Apr 2005 16:13:36 -0700 Subject: [C++-sig] "_POSIX_C_SOURCE" redefined Message-ID: <7AA63464B644CD40A3BAD0AFEF26FA5307ABE8@svlxchcln3.enterprise.veritas.com> This seems to be a bug introduced in the 2.4 configure.in/pyconfig.h.in logic. If _XOPEN_SOURCE is defined configure.in will also define _POSIX_C_SOURCE will also be defined and, for most platforms, configure.in does define _XOPEN_SOURCE. I try to avoid the hell that is autoconf. As a workaround you might try wrapping the _POSIX_C_SOURCE definition in pyconfig.h with a "#if !defined(_POSIX_C_SOURCE)" I tried coaxing configure to generate the right settings for RHEL AS3 but no luck. > -----Original Message----- > From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org]On > Behalf Of Lothar Werzinger > Sent: Thursday, April 07, 2005 15:58 > To: c++-sig at python.org > Subject: Re: [C++-sig] "_POSIX_C_SOURCE" redefined > > > On Thursday 07 April 2005 15:29, Ralf W. Grosse-Kunstleve wrote: > > --- Andreas Beyer wrote: > > > Since examples work, I guess I am doing something wrong, > but I can't > > > figure out what. I tried different orderings of the includes in > > > property_handle.hpp. I tried #include > first, before > > > the standard library includes (like etc.) and I > tried including > > > first the std-lib includes and including boost/python.hpp > afterwards. > > > Neither worked. > > > So which ordering is correct? What do I have to look at? > > > > #include > > > > should be at the very top of your wrapper code. > > And even that may not be enough. We use boost::python and > log4cplus and > unfortunately log4cplus also defines some macros that > conflict with macros > previously defined in pythons headers. The only sane way for > the probme is > that the developers of Python (and log4cplus) fix their headers. > > /opt2/log4cplus/include/log4cplus/config.h:79:1: warning: "HAVE_STAT" > redefined > In file included from /opt2/python-2.4/include/python2.4/Python.h:55, > > from > /opt2/boost/include/boost-1_32/boost/python/detail/wrap_python > .hpp:121, > > from /opt2/boost/include/boost-1_32/boost/python/detail/prefix.hpp:13, > from > /opt2/boost/include/boost-1_32/boost/python/args.hpp:8, > from > /opt2/boost/include/boost-1_32/boost/python.hpp:11, > from src/utility/PythonInterpreterGuard.h:10, > from src/rating/test/PythonRatingStepTest.cpp:10: > /opt2/python-2.4/include/python2.4/pyport.h:139:1: warning: > this is the > location of the previous definition > > 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 > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From jgresula at seznam.cz Fri Apr 8 16:20:06 2005 From: jgresula at seznam.cz (Jaroslav Gresula) Date: Fri, 08 Apr 2005 16:20:06 +0200 Subject: [C++-sig] [Pyste] template instantiation with a user defined type Message-ID: <42569316.5060109@seznam.cz> I have a problem with the following scenario: // -- file type.h class Type {}; // -- file template.h template class Templ { T m_data; }; // -- test.pyste Type = Class( "Type", "type.h" ) Templ = Template( "Templ", "template.h" ) Templ( "Type" ) When I run Pyste, it internally creates the following temporary file: // -- ~temporary #include "c:\absolute\path\to\template.h" typedef Templ< Type > Templ_Type; void __instantiate_Templ_Type() { sizeof(Templ_Type); } that is passed to gccxml which issues an error saying 'Type was not declared in this scope'. Obviously, type.h header is missing. Is Pyste capable of handling a template specialized with a user defined type? Thanks, Jarda From dave at boost-consulting.com Fri Apr 8 16:54:14 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 08 Apr 2005 10:54:14 -0400 Subject: [C++-sig] Re: [Pyste] template instantiation with a user defined type References: <42569316.5060109@seznam.cz> Message-ID: Jaroslav Gresula writes: > I have a problem with the following scenario: > > // -- file type.h > class Type {}; > > // -- file template.h > template > class Templ > { > T m_data; > }; > > // -- test.pyste > Type = Class( "Type", "type.h" ) > Templ = Template( "Templ", "template.h" ) > Templ( "Type" ) > > > When I run Pyste, it internally creates the following temporary file: > // -- ~temporary > #include "c:\absolute\path\to\template.h" > > typedef Templ< Type > Templ_Type; > void __instantiate_Templ_Type() ^^ I know this has no relevance to your problem, but all identifiers containing double underscores are reserved to the C++ implementation. Pyste should never be generating such names. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mvc at di.fct.unl.pt Fri Apr 8 17:10:00 2005 From: mvc at di.fct.unl.pt (Marco Correia) Date: Fri, 8 Apr 2005 16:10:00 +0100 Subject: [C++-sig] inheriting and overloading Message-ID: <200504081610.00461.mvc@di.fct.unl.pt> hi, I'm using an overload to a base class member: class Base { void something() {} }; class Derived : public Base { void something(int i) {} }; I don't get error by building this with boost::bython, but in python I'm not able to use the Base::something member. Is this a known issue? Should I post here a test case? thanks Marco -- Marco Correia From paniq at paniq.org Sun Apr 10 05:00:38 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Sun, 10 Apr 2005 05:00:38 +0200 Subject: [C++-sig] wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: <200504081610.00461.mvc@di.fct.unl.pt> References: <200504081610.00461.mvc@di.fct.unl.pt> Message-ID: <425896D6.30808@paniq.org> it seems that wrapper.cpp has been forgotten in the boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and .vcproj file... can someone verify this? i was wondering about a linker error concerning a missing symbol and found this to be the cause. From mike at thewilsonfamily.freeserve.co.uk Tue Apr 12 05:30:02 2005 From: mike at thewilsonfamily.freeserve.co.uk (Mike) Date: Tue, 12 Apr 2005 04:30:02 +0100 Subject: [C++-sig] wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> Message-ID: <001401c53f0f$ea41fe60$597c4e51@MIKESPC01> I had the same problem (with the .dsp file - but no .vcproj file in 1_32 as far as I'm aware(?)). As you imply, adding wrapper.cpp seems to solve the problem. Mike ----- Original Message ----- From: "Leonard "paniq" Ritter" To: "Development of Python/C++ integration" Sent: Sunday, April 10, 2005 4:00 AM Subject: [C++-sig] wrapper.cpp not in 1.32.0 dsp/vcproj file? > it seems that wrapper.cpp has been forgotten in the > boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and .vcproj > file... can someone verify this? > > i was wondering about a linker error concerning a missing symbol and > found this to be the cause. > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From paniq at paniq.org Sun Apr 10 15:55:15 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Sun, 10 Apr 2005 15:55:15 +0200 Subject: [C++-sig] wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: <001401c53f0f$ea41fe60$597c4e51@MIKESPC01> References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <001401c53f0f$ea41fe60$597c4e51@MIKESPC01> Message-ID: <42593043.7010501@paniq.org> ah yes, i guess i generated the sln/vcproj files in 7.1. so its the dsp that misses the file. Mike wrote: >I had the same problem (with the .dsp file - but no .vcproj file in 1_32 >as far as I'm aware(?)). >As you imply, adding wrapper.cpp seems to solve the problem. > >Mike >----- Original Message ----- >From: "Leonard "paniq" Ritter" >To: "Development of Python/C++ integration" >Sent: Sunday, April 10, 2005 4:00 AM >Subject: [C++-sig] wrapper.cpp not in 1.32.0 dsp/vcproj file? > > > > >>it seems that wrapper.cpp has been forgotten in the >>boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and .vcproj >>file... can someone verify this? >> >>i was wondering about a linker error concerning a missing symbol and >>found this to be the cause. >> >>_______________________________________________ >>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 dave at boost-consulting.com Sun Apr 10 15:57:34 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 10 Apr 2005 09:57:34 -0400 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> Message-ID: "Leonard \"paniq\" Ritter" writes: > it seems that wrapper.cpp has been forgotten in the > boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and .vcproj > file... can someone verify this? > > i was wondering about a linker error concerning a missing symbol and > found this to be the cause. The maintainer of that VC++ project is listed on the "building" page of the Boost.Python docs. You should contact him about this problem if you want it fixed. -- Dave Abrahams Boost Consulting www.boost-consulting.com From paniq at paniq.org Mon Apr 11 20:47:17 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Mon, 11 Apr 2005 20:47:17 +0200 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> Message-ID: <425AC635.4050200@paniq.org> no i dont want it fixed, i'm perfectly fine with a broken project file. besides for strengthening the elite and all, there should really be some things putting off the newbies. *ahem* seriously, i was only trying to verify if it was my or someone elses mistake. i contacted brett calcott for you ;) David Abrahams wrote: >"Leonard \"paniq\" Ritter" writes: > > > >>it seems that wrapper.cpp has been forgotten in the >>boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and .vcproj >>file... can someone verify this? >> >>i was wondering about a linker error concerning a missing symbol and >>found this to be the cause. >> >> > >The maintainer of that VC++ project is listed on the "building" page >of the Boost.Python docs. You should contact him about this problem >if you want it fixed. > > > From nicodemus at esss.com.br Tue Apr 12 02:19:52 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 11 Apr 2005 22:19:52 -0200 Subject: [C++-sig] [Pyste] template instantiation with a user defined type In-Reply-To: <42569316.5060109@seznam.cz> References: <42569316.5060109@seznam.cz> Message-ID: <425B1428.2080908@esss.com.br> Hi, Jaroslav Gresula wrote: > I have a problem with the following scenario: > > // -- file type.h > class Type {}; > > // -- file template.h > template > class Templ > { > T m_data; > }; > > // -- test.pyste > Type = Class( "Type", "type.h" ) > Templ = Template( "Templ", "template.h" ) > Templ( "Type" ) > > > When I run Pyste, it internally creates the following temporary file: > // -- ~temporary > #include "c:\absolute\path\to\template.h" > > typedef Templ< Type > Templ_Type; > void __instantiate_Templ_Type() > { sizeof(Templ_Type); } > > that is passed to gccxml which issues an error saying 'Type was not > declared in this scope'. Obviously, type.h header is missing. > > Is Pyste capable of handling a template specialized with a user > defined type? Not right now, but I don't see why we can't add support for it. I belive this would cover all cases: Templ( "Type", "type.h" ) and Templ( Type ) I will implement this shortly in CVS. Best Regards, Bruno. From nicodemus at esss.com.br Tue Apr 12 02:20:48 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 11 Apr 2005 22:20:48 -0200 Subject: [C++-sig] Pyste bug? Using Wrapper with member functions and --pyste-ns In-Reply-To: <5ab8740205032002161499b77d@mail.gmail.com> References: <5ab8740205032002161499b77d@mail.gmail.com> Message-ID: <425B1460.3090104@esss.com.br> Hi Dan, Dan Haffey wrote: >Hello, > >I just noticed that when using the Pyste Wrapper call to create a >member function wrapper, it places the wrapper definition code outside >of the specified (--pyste-ns=) namespace, but the generated module >code looks for it in the namespace. This doesn't seem to happen with >normal functions, just members. > > Really sorry for not responding earlier. I somehow missed your message. I will fix this bug shortly in CVS. Best Regards, Bruno. From beyer at imb-jena.de Tue Apr 12 04:45:18 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Mon, 11 Apr 2005 19:45:18 -0700 Subject: [C++-sig] Pointer to existing Python object Message-ID: <425B363E.8090905@imb-jena.de> 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. An example: 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()); } A::A_ptr a; void set(A::A_ptr a) { this->a = a; } A::A_ptr get() { return a->self(); } }; BOOST_PYTHON_MODULE(ptr_test) { python::class_ ("A") .def_readwrite("val", &A::val) ; python::register_ptr_to_python< A::A_ptr >(); python::class_("B") .def("set", &B::set) .def("get", &B::get) ; } In Python I would like to do this: >>> b = B() >>> a1 = b.get() # obtain instance of class A >>> a2 = b.get() # get the *same Python instance* again >>> assert(a1==a2) Traceback (most recent call last): File "", line 1, in ? AssertionError >>> The internal representations of instances of A are the same! Whenever I access a C++ member of A I am actually accessing the same object. So I can do this: >>> a1.val = 42 # change internal reference >>> print a2.val 42 >>> However, I cannot do this: >>> a1.foo = 42 >>> print a2.foo Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'foo' >>> I think instances of B have to check if there is already an existing Python object. In that case B (or a wrapper of B) should return the existing Python object (i.e. instances of python::object). Is there a way to find such an existing instance? Andreas From colin_irwin at hotmail.com Tue Apr 12 06:16:09 2005 From: colin_irwin at hotmail.com (Colin Irwin) Date: Tue, 12 Apr 2005 14:16:09 +1000 Subject: [C++-sig] Re: Wrapper for exception translation In-Reply-To: References: <2040C0A1CA23D51181A30050BAAC9902011046D8@berexch.ber.haufemg.com> Message-ID: Dave - In the previous post you stated that Daniel Wallin was doing a bit of cleaning in the code base for the named parameter library. Did this happen? Is it now possible to add unnamed parameter support? Anyway, I think I'm still keen to do whatever on this front to help with a wrapper to translate exceptions through into Python. Colin From paniq at paniq.org Wed Apr 13 00:38:33 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Wed, 13 Apr 2005 00:38:33 +0200 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: <425AC635.4050200@paniq.org> References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> Message-ID: <425C4DE9.4020205@paniq.org> fyi, the mail to brett calcott bounced. Leonard "paniq" Ritter wrote: > no i dont want it fixed, i'm perfectly fine with a broken project file. > > besides for strengthening the elite and all, there should really be > some things putting off the newbies. > > *ahem* > > seriously, i was only trying to verify if it was my or someone elses > mistake. i contacted brett calcott for you ;) > > David Abrahams wrote: > >> "Leonard \"paniq\" Ritter" writes: >> >> >> >>> it seems that wrapper.cpp has been forgotten in the >>> boost_1_32_0\libs\python\build\VisualStudio boost_python.dsp and >>> .vcproj file... can someone verify this? >>> >>> i was wondering about a linker error concerning a missing symbol and >>> found this to be the cause. >>> >> >> >> The maintainer of that VC++ project is listed on the "building" page >> of the Boost.Python docs. You should contact him about this problem >> if you want it fixed. >> >> >> > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From leejd80 at gmail.com Wed Apr 13 15:40:26 2005 From: leejd80 at gmail.com (Gerald Lee) Date: Wed, 13 Apr 2005 21:40:26 +0800 Subject: [C++-sig] Linker Error Message-ID: <7dbf822f05041306403f3e728d@mail.gmail.com> I will Embedded Python to my Application.The C++ compiler is BCB6's. I compiled the a simple code, OK, but error occured when link. The link error message followed: Build [Linker Error] Unresolved external '__Py_RefTotal' referenced from E:\PROJECT\GRIDCAM\SOURCE\IOSERVICES\NEWMODULE.OBJ [Linker Error] Unresolved external '__Py_NegativeRefcount' referenced from E:\PROJECT\GRIDCAM\SOURCE\IOSERVICES\NEWMODULE.OBJ [Linker Error] Unresolved external '__Py_Dealloc' referenced from E:\PROJECT\GRIDCAM\SOURCE\IOSERVICES\NEWMODULE.OBJ I already convert python23.lib to omf format. How to pass it? Best regard, Gerald Lee -- My Blog >> http://leejd.cndev.org My QQ >> 9847243 -------------- next part -------------- An HTML attachment was scrubbed... URL: From domma at procoders.net Wed Apr 13 15:52:19 2005 From: domma at procoders.net (Achim Domma (Procoders)) Date: Wed, 13 Apr 2005 15:52:19 +0200 Subject: [C++-sig] Initialize SparseVector Message-ID: <425D2413.40300@procoders.net> Hi, I have wrapped a sparse vector class, which currently can be used like this: v=svm.vector() v[3]=7 v[9]=-3.2 v[5]=0.3 ... Everything works finde so far, but I want to implement a more pythonic way to initialize the vector. Something like this would be nice: v=svm.vector( (3,7), (9,-3.2), (5,0.3), ... ) What's the easiest way to get something like this with boost.python? I have control over the complete code, so small modifications on the sparse vector class would be no problem. regards, Achim From nicodemus at esss.com.br Wed Apr 13 16:27:39 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Wed, 13 Apr 2005 11:27:39 -0300 Subject: [C++-sig] Initialize SparseVector In-Reply-To: <425D2413.40300@procoders.net> References: <425D2413.40300@procoders.net> Message-ID: <425D2C5B.3010702@esss.com.br> Hi Achim, Take a look at make_constructor. I don't have time right now to provide an example, but this should get you going. Regards, Bruno. Achim Domma (Procoders) wrote: > Hi, > > I have wrapped a sparse vector class, which currently can be used like > this: > > v=svm.vector() > v[3]=7 > v[9]=-3.2 > v[5]=0.3 > ... > > Everything works finde so far, but I want to implement a more pythonic > way to initialize the vector. Something like this would be nice: > > v=svm.vector( (3,7), (9,-3.2), (5,0.3), ... ) > > What's the easiest way to get something like this with boost.python? I > have control over the complete code, so small modifications on the > sparse vector class would be no problem. > > regards, > Achim > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From jgresula at seznam.cz Wed Apr 13 23:11:59 2005 From: jgresula at seznam.cz (Jaroslav Gresula) Date: Wed, 13 Apr 2005 23:11:59 +0200 Subject: [C++-sig] Pyste enhancements - mini patch Message-ID: <425D8B1F.7090709@seznam.cz> Hi, I extended my local copy of Pyste by the following two enhancements: i) a class can be declared as final: C = Class( 'C', 'c.h' ) final( C ) ii) registration of converters for user-defined smart pointers: C = Class( 'C', 'c.h' ) Include( "my_smart_pointers.h" ) use_smart_ptr( C, "my_shared_ptr" ) use_smart_ptr( C, "my_auto_ptr" ) I thought that also someone else might find it useful. If anyone is interested, the patch is attached. Cheers, Jarda -------------- next part -------------- A non-text attachment was scrubbed... Name: pyste-minipatch.zip Type: application/x-zip-compressed Size: 1398 bytes Desc: not available URL: From beyer at imb-jena.de Wed Apr 13 23:14:44 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Wed, 13 Apr 2005 14:14:44 -0700 Subject: [C++-sig] shared_ptr -> weak_ptr -> shared_ptr Message-ID: <425D8BC4.50905@imb-jena.de> Hi. I would like to transform a shared pointer originating from a python object to a weak pointer. Later I would like to transform it back to a shared pointer. For some strange reason I keep getting seg-faults when trying to lock the weak pointer. Is there any danger in storing shared pointers from python objects as weak pointers? According to the weak pointer's docu, lock() returns an empty shared_ptr if the refered object expired. However, in my example this shouldn't be the case anyway. The test case: using namespace boost; struct A { }; typedef shared_ptr A_ptr_shared; typedef weak_ptr A_ptr_weak; void transform(A_ptr_shared a) { std::cerr << a.get() << std::endl; A_ptr_weak aw(a); std::cerr << "have weak" << std::endl; A_ptr_shared as = aw.lock(); // boom! std::cerr << "lock is ok" << std::endl; std::cerr << as.get() << std::endl; } BOOST_PYTHON_MODULE(ptr_test) { python::class_ ("A"); python::register_ptr_to_python< A_ptr_shared >(); python::def("transform", &transform); } The python session: >>> from ptr_test import * >>> a=A() >>> transform(a) 0x8190a58 have weak Segmentation fault (core dumped) From cppsig-eric at sneakemail.com Thu Apr 14 03:11:33 2005 From: cppsig-eric at sneakemail.com (Eric) Date: Wed, 13 Apr 2005 18:11:33 -0700 Subject: [C++-sig] serializing threaded access to Boost.Python-wrapped class In-Reply-To: <425D8B1F.7090709@seznam.cz> Message-ID: <10212-54350@sneakemail.com> I have a C++ class, accessed from python via Boost.Python, that I am trying to prevent from being reentered in the context of a multithreaded program. I can do this relatively easily with the RLock class in the threading module. However this requires me to track down every caller of this class and wrap all calls in an acquire()/release() pair. I'm worried that it would be pretty easy to miss one of these and then cause hard-to-find bugs. Is there any way to do this automatically with Boost.Python? From gritsch at iue.tuwien.ac.at Thu Apr 14 09:27:07 2005 From: gritsch at iue.tuwien.ac.at (gritsch at iue.tuwien.ac.at) Date: Thu, 14 Apr 2005 09:27:07 +0200 Subject: [C++-sig] Re: Wrapper for exception translation Message-ID: <1113463627.425e1b4b2b242@l01.iue.tuwien.ac.at> Hi, I am also looking forward to some nice mechanism to integrate custom exceptions nicely with Boost.Python. However, in the meantime I use the following approach, and I wonder, if this is currently the correct way: --- 8< --- #include #include struct MyException { std::string what() const { return "MyException occurred"; } }; void throw_it() { throw MyException(); } static PyObject * my_exception = NULL; void translator( MyException const & e ) { PyErr_SetString( my_exception, e.what().c_str() ); } BOOST_PYTHON_MODULE( extest ) { my_exception = PyErr_NewException( "extest.MyException", NULL, NULL ); PyModule_AddObject( boost::python::scope().ptr(), "MyException", my_exception ); boost::python::register_exception_translator( translator ); boost::python::def( "throw_it", throw_it ); } --- 8< --- Do I really have to use the Python C-API funcions PyErr_NewException and PyModule_AddObject ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From gritsch at iue.tuwien.ac.at Thu Apr 14 09:33:22 2005 From: gritsch at iue.tuwien.ac.at (gritsch at iue.tuwien.ac.at) Date: Thu, 14 Apr 2005 09:33:22 +0200 Subject: [C++-sig] Re: Wrapper for exception translation Message-ID: <1113464002.425e1cc257eb1@l01.iue.tuwien.ac.at> Hi, I am also looking forward to some mechanism to integrate custom exceptions nicely with Boost.Python. However, in the meantime I use the following approach, and I wonder, if this is currently the correct way: --- 8< --- #include #include struct MyException { std::string what() const { return "MyException occurred"; } }; void throw_it() { throw MyException(); } static PyObject * my_exception = NULL; void translator( MyException const & e ) { PyErr_SetString( my_exception, e.what().c_str() ); } BOOST_PYTHON_MODULE( extest ) { my_exception = PyErr_NewException( "extest.MyException", NULL, NULL ); PyModule_AddObject( boost::python::scope().ptr(), "MyException", my_exception ); boost::python::register_exception_translator( translator ); boost::python::def( "throw_it", throw_it ); } --- 8< --- Do I really have to use the Python C-API funcions PyErr_NewException and PyModule_AddObject? The module can be used from Python as --- 8< --- import extest try: extest.throw_it() except extest.MyException, msg: print msg --- 8< --- Thank you for reading, and please excuse the accidentally sended incomplete email, Markus ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From dave at boost-consulting.com Thu Apr 14 09:48:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 14 Apr 2005 09:48:35 +0200 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: "Leonard \"paniq\" Ritter" writes: > fyi, the mail to brett calcott bounced. What a shame. > Leonard "paniq" Ritter wrote: > >> no i dont want it fixed, i'm perfectly fine with a broken project file. >> >> besides for strengthening the elite and all, there should really be >> some things putting off the newbies. >> >> *ahem* >> >> seriously, i was only trying to verify if it was my or someone elses >> mistake. i contacted brett calcott for you ;) It's not "for me." I told Brett I'd accept the project file if he would maintain it ongoingly, because I can't afford to test and maintain it. Unless Brett shows up or someone else volunteers I'm going to remove it from the CVS for the next release. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 14 09:51:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 14 Apr 2005 09:51:54 +0200 Subject: [C++-sig] Re: Wrapper for exception translation References: <2040C0A1CA23D51181A30050BAAC9902011046D8@berexch.ber.haufemg.com> Message-ID: Colin Irwin writes: > Dave - In the previous post you stated that Daniel Wallin was doing a > bit of cleaning in the code base for the named parameter library. Did > this happen? Yes, Daniel and I have done that cleanup. > Is it now possible to add unnamed parameter support? Yep, we're starting on it now. > Anyway, I think I'm still keen to do whatever on this front to help > with a wrapper to translate exceptions through into Python. Thanks; I'll keep it in mind. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 14 09:55:59 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 14 Apr 2005 09:55:59 +0200 Subject: [C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr References: <425D8BC4.50905@imb-jena.de> Message-ID: Andreas Beyer writes: > Hi. > > I would like to transform a shared pointer originating from a python > object to a weak pointer. Later I would like to transform it back to a > shared pointer. For some strange reason I keep getting seg-faults when > trying to lock the weak pointer. > Is there any danger in storing shared pointers from python objects as > weak pointers? Shouldn't be, especially in your case. This behavior really surprises me. Peter, do you have anything to say about this? > According to the weak pointer's docu, lock() returns an empty shared_ptr > if the refered object expired. However, in my example this shouldn't be > the case anyway. > > The test case: > > using namespace boost; > > struct A { }; > > typedef shared_ptr A_ptr_shared; > typedef weak_ptr A_ptr_weak; > > void transform(A_ptr_shared a) { > std::cerr << a.get() << std::endl; > A_ptr_weak aw(a); > std::cerr << "have weak" << std::endl; > A_ptr_shared as = aw.lock(); // boom! > std::cerr << "lock is ok" << std::endl; > std::cerr << as.get() << std::endl; > } > > BOOST_PYTHON_MODULE(ptr_test) { > python::class_ ("A"); > python::register_ptr_to_python< A_ptr_shared >(); > > python::def("transform", &transform); > } > > > The python session: > >>>> from ptr_test import * >>>> a=A() >>>> transform(a) > 0x8190a58 > have weak > Segmentation fault (core dumped) -- Dave Abrahams Boost Consulting www.boost-consulting.com From ghost at cs.msu.su Thu Apr 14 11:32:26 2005 From: ghost at cs.msu.su (Vladimir Prus) Date: Thu, 14 Apr 2005 13:32:26 +0400 Subject: [C++-sig] Re: serializing threaded access to Boost.Python-wrapped class References: <425D8B1F.7090709@seznam.cz> <10212-54350@sneakemail.com> Message-ID: Eric wrote: > I have a C++ class, accessed from python via Boost.Python, that I am > trying to prevent from being reentered in the context of a multithreaded > program. I can do this relatively easily with the RLock class in the > threading module. However this requires me to track down every caller of > this class and wrap all calls in an acquire()/release() pair. I'm worried > that it would be pretty easy to miss one of these and then cause > hard-to-find bugs. > > Is there any way to do this automatically with Boost.Python? There's a Python-only solution -- after importing a class, you can walk over all its methods, and "decorate" them, adding any pre/post processing you like. The attached example does this with the 'hello' class from 'example/getting_started2' example. This is much easier that tracking down every caller -- this only requires to to call a function for each imported *class*. - Volodya -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pre_post.py URL: From pdimov at mmltd.net Thu Apr 14 11:42:11 2005 From: pdimov at mmltd.net (Peter Dimov) Date: Thu, 14 Apr 2005 12:42:11 +0300 Subject: [C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr References: <425D8BC4.50905@imb-jena.de> Message-ID: David Abrahams wrote: > Andreas Beyer writes: > >> Hi. >> >> I would like to transform a shared pointer originating from a python >> object to a weak pointer. Later I would like to transform it back to >> a shared pointer. For some strange reason I keep getting seg-faults >> when trying to lock the weak pointer. >> Is there any danger in storing shared pointers from python objects as >> weak pointers? > > Shouldn't be, especially in your case. This behavior really surprises > me. Peter, do you have anything to say about this? It should work. Is it possible that Boost.Python is single-threaded but ptr_test is mutlithreaded? Which platform? From dave at boost-consulting.com Thu Apr 14 09:48:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 14 Apr 2005 09:48:35 +0200 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: <425C4DE9.4020205@paniq.org> (Leonard Ritter's message of "Wed, 13 Apr 2005 00:38:33 +0200") References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: "Leonard \"paniq\" Ritter" writes: > fyi, the mail to brett calcott bounced. What a shame. > Leonard "paniq" Ritter wrote: > >> no i dont want it fixed, i'm perfectly fine with a broken project file. >> >> besides for strengthening the elite and all, there should really be >> some things putting off the newbies. >> >> *ahem* >> >> seriously, i was only trying to verify if it was my or someone elses >> mistake. i contacted brett calcott for you ;) It's not "for me." I told Brett I'd accept the project file if he would maintain it ongoingly, because I can't afford to test and maintain it. Unless Brett shows up or someone else volunteers I'm going to remove it from the CVS for the next release. -- Dave Abrahams Boost Consulting www.boost-consulting.com From beyer at imb-jena.de Thu Apr 14 18:16:12 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 14 Apr 2005 09:16:12 -0700 Subject: [C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr In-Reply-To: References: <425D8BC4.50905@imb-jena.de> Message-ID: <425E974C.20103@imb-jena.de> My platform is Python 2.4.1 (#1, Apr 8 2005, 15:53:09) gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20) boost cvs download from Apr. 5th The program runs single-threaded. There is nothing else as what I gave in my example. I didn't even use Idle for the python part, but just a plain python shell. Can someone else try to reproduce this behavior on another Linux platform? David, are there other ways to obtain a weak pointer from a python object? Thanks! Andreas Peter Dimov wrote: >David Abrahams wrote: > > >>Andreas Beyer writes: >> >> >> >>>Hi. >>> >>>I would like to transform a shared pointer originating from a python >>>object to a weak pointer. Later I would like to transform it back to >>>a shared pointer. For some strange reason I keep getting seg-faults >>>when trying to lock the weak pointer. >>>Is there any danger in storing shared pointers from python objects as >>>weak pointers? >>> >>> >>Shouldn't be, especially in your case. This behavior really surprises >>me. Peter, do you have anything to say about this? >> >> > >It should work. Is it possible that Boost.Python is single-threaded but >ptr_test is mutlithreaded? Which platform? > > > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig > > > From beyer at imb-jena.de Thu Apr 14 19:02:05 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 14 Apr 2005 10:02:05 -0700 Subject: [C++-sig] Pointer to existing Python object Message-ID: <425EA20D.5050700@imb-jena.de> Hi, I just want to bring this issue back on the table. I still didn't get a brilliant idea how to solve it. So far, I see only this option: - Wrap B, in particular wrap B.get(). - In get() create the actual python object, like: python::object py_a(B::get()); - Store those objects in a map. - When B_wrap.get() gets called again, check if a python object already exists and return it. However, in my real-world application I had to wrap quite a lot of methods returning As. I also have methods returning vectors of A_ptr, which makes it even more enoying. (I would have to wrap the vector, too.) What is this has_back_reference doing? Is that somehow related to my problem? (I regret that I don't really understand what it is doing, as I don't know what a "predicate metafunction" is.) Just adopting the example at http://www.boost.org/libs/python/doc/v2/has_back_reference.html is not really a solution, because my instances of A are created inside the C++ code (by factory methods in class B). I would have to be very intrusive and make the actual class B aware of Python/boost::python for adopting the above solution. I know that boost::python is collecting the shared pointers somewhere. Is it possible to use that mechanism somewhow for solving my problem? Any ideas? Thanks!! Andreas From cludwig at cdc.informatik.tu-darmstadt.de Thu Apr 14 19:18:16 2005 From: cludwig at cdc.informatik.tu-darmstadt.de (Christoph Ludwig) Date: Thu, 14 Apr 2005 19:18:16 +0200 Subject: [C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr In-Reply-To: <425E974C.20103@imb-jena.de> References: <425D8BC4.50905@imb-jena.de> <425E974C.20103@imb-jena.de> Message-ID: <20050414171816.GE2729@lap200.cdc.informatik.tu-darmstadt.de> On Thu, Apr 14, 2005 at 09:16:12AM -0700, Andreas Beyer wrote: > My platform is > Python 2.4.1 (#1, Apr 8 2005, 15:53:09) > gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20) > boost cvs download from Apr. 5th > > The program runs single-threaded. There is nothing else as what I gave > in my example. I didn't even use Idle for the python part, but just a > plain python shell. Have you BOOST_DISABLE_THREADS defined in boost/config/user.hpp or on the compiler's command line? The Boost config system cannot reliable detect under Linux whether the compiler was called with the option -pthread. IIRC it assumes the code is MT unless BOOST_DISABLE_THREADS was defined. So your python interpreter may be single-threaded and you compiled and linked your test program without -pthread, but the shared_ptr code still refers to pthread symbols unless you defined BOOST_DISABLE_THREADS. (For some reason such mismatches are not caught by the linker.) I experienced the same problem some time ago and spent many hours with the debugger before I found the problem's cause. The symptoms were similar to what you report. > Can someone else try to reproduce this behavior on another Linux platform? I can't reproduce it, but then I have no single-threaded python interpreter installed anymore. So even if the shared_ptr code refers to pthread symbols they can be resolved when the extension module is loaded. HTH, regards Christoph > Peter Dimov wrote: > > >David Abrahams wrote: > > > > > >>Andreas Beyer writes: > >> > >> > >> > >>>Hi. > >>> > >>>I would like to transform a shared pointer originating from a python > >>>object to a weak pointer. Later I would like to transform it back to > >>>a shared pointer. For some strange reason I keep getting seg-faults > >>>when trying to lock the weak pointer. > >>>Is there any danger in storing shared pointers from python objects as > >>>weak pointers? > >>> > >>> > >>Shouldn't be, especially in your case. This behavior really surprises > >>me. Peter, do you have anything to say about this? > >> > >> > > > >It should work. Is it possible that Boost.Python is single-threaded but > >ptr_test is mutlithreaded? Which platform? > > > > > > > >_______________________________________________ > >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 > > -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html From beyer at imb-jena.de Thu Apr 14 23:52:59 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 14 Apr 2005 14:52:59 -0700 Subject: [C++-sig] Re: shared_ptr -> weak_ptr -> shared_ptr In-Reply-To: <20050414171816.GE2729@lap200.cdc.informatik.tu-darmstadt.de> References: <425D8BC4.50905@imb-jena.de> <425E974C.20103@imb-jena.de> <20050414171816.GE2729@lap200.cdc.informatik.tu-darmstadt.de> Message-ID: <425EE63B.4010705@imb-jena.de> Unfortunately that doesn't help. I called bjam like this: bjam -sBUILD=release -sBOOST_DISABLE_THREADS -q and I get the same problem. I then tried to compile the debug version and the story gets even worse: I get an internal comiler error: bjam -sBUILD=debug -sBOOST_DISABLE_THREADS -q [...] gcc-C++-action bin/csrc/ptr_test.so/gcc/debug/shared-linkable-true/ptr_test.o /cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp: In function `long int boost::detail::atomic_conditional_increment(long int*)': /cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp:94: Internal compiler error in instantiate_virtual_regs_1, at function.c:3974 Please submit a full bug report, with preprocessed source if appropriate. See for instructions. set -e "g++" -c -Wall -ftemplate-depth-255 -DBOOST_PYTHON_DYNAMIC_LIB -g -O0 -fno-inline -fPIC -I"bin/csrc" -I "/cellar/users/abeyer//include/python2.4" -I "/cellar/users/abeyer/boost/boost_current" -o "bin/csrc/ptr_test.so/gcc/debug/shared-linkable-true/ptr_test.o" "ptr_test.cpp" "/usr/bin/objcopy" --set-section-flags .debug_str=contents,debug "bin/csrc/ptr_test.so/gcc/debug/shared-linkable-true/ptr_test.o" This error is caused by the same line of code that causes the seg-fault in the release version. If I comment out the following line of code, the compiler works fine: A_ptr_shared as = aw.lock(); // boom! I would assume that many people work with Red Hat's gcc 3.2.3. I tried gcc 3.2.3-20 and 3.2.3-49; both crash in the respective line of code. Christoph Ludwig wrote: >On Thu, Apr 14, 2005 at 09:16:12AM -0700, Andreas Beyer wrote: > > >>My platform is >> Python 2.4.1 (#1, Apr 8 2005, 15:53:09) >> gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20) >> boost cvs download from Apr. 5th >> >>The program runs single-threaded. There is nothing else as what I gave >>in my example. I didn't even use Idle for the python part, but just a >>plain python shell. >> >> > >Have you BOOST_DISABLE_THREADS defined in boost/config/user.hpp or on the >compiler's command line? > >The Boost config system cannot reliable detect under Linux whether the >compiler was called with the option -pthread. IIRC it assumes the code is MT >unless BOOST_DISABLE_THREADS was defined. So your python interpreter may be >single-threaded and you compiled and linked your test program without >-pthread, but the shared_ptr code still refers to pthread symbols unless >you defined BOOST_DISABLE_THREADS. (For some reason such mismatches are not >caught by the linker.) > >I experienced the same problem some time ago and spent many hours with the >debugger before I found the problem's cause. The symptoms were similar to what >you report. > > > >>Can someone else try to reproduce this behavior on another Linux platform? >> >> > >I can't reproduce it, but then I have no single-threaded python interpreter >installed anymore. So even if the shared_ptr code refers to pthread symbols >they can be resolved when the extension module is loaded. > > >HTH, regards > >Christoph > > > >>Peter Dimov wrote: >> >> >> >>>David Abrahams wrote: >>> >>> >>> >>> >>>>Andreas Beyer writes: >>>> >>>> >>>> >>>> >>>> >>>>>Hi. >>>>> >>>>>I would like to transform a shared pointer originating from a python >>>>>object to a weak pointer. Later I would like to transform it back to >>>>>a shared pointer. For some strange reason I keep getting seg-faults >>>>>when trying to lock the weak pointer. >>>>>Is there any danger in storing shared pointers from python objects as >>>>>weak pointers? >>>>> >>>>> >>>>> >>>>> >>>>Shouldn't be, especially in your case. This behavior really surprises >>>>me. Peter, do you have anything to say about this? >>>> >>>> >>>> >>>> >>>It should work. Is it possible that Boost.Python is single-threaded but >>>ptr_test is mutlithreaded? Which platform? >>> >>> >>> >>> >>> >>> From pdimov at mmltd.net Fri Apr 15 00:10:37 2005 From: pdimov at mmltd.net (Peter Dimov) Date: Fri, 15 Apr 2005 01:10:37 +0300 Subject: [C++-sig] Re: Re: shared_ptr -> weak_ptr -> shared_ptr References: <425D8BC4.50905@imb-jena.de> <425E974C.20103@imb-jena.de><20050414171816.GE2729@lap200.cdc.informatik.tu-darmstadt.de> <425EE63B.4010705@imb-jena.de> Message-ID: Andreas Beyer wrote: > Unfortunately that doesn't help. I called bjam like this: > bjam -sBUILD=release -sBOOST_DISABLE_THREADS -q > and I get the same problem. > I then tried to compile the debug version and the story gets even > worse: I get an internal comiler error: > > bjam -sBUILD=debug -sBOOST_DISABLE_THREADS -q > [...] > gcc-C++-action > bin/csrc/ptr_test.so/gcc/debug/shared-linkable-true/ptr_test.o > /cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp: > In > function `long int boost::detail::atomic_conditional_increment(long > int*)': > /cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp:94: > Internal > compiler error in instantiate_virtual_regs_1, at function.c:3974 > Please submit a full bug report, > with preprocessed source if appropriate. > See for instructions. Please try the latest CVS version, where this problem has been fixed. Hopefully it will take care of your other issue as well. Please let us know whether this solves the problem. From beyer at imb-jena.de Fri Apr 15 02:20:22 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 14 Apr 2005 17:20:22 -0700 Subject: [C++-sig] Re: Re: shared_ptr -> weak_ptr -> shared_ptr In-Reply-To: References: <425D8BC4.50905@imb-jena.de> <425E974C.20103@imb-jena.de><20050414171816.GE2729@lap200.cdc.informatik.tu-darmstadt.de> <425EE63B.4010705@imb-jena.de> Message-ID: <425F08C6.6060503@imb-jena.de> Peter Dimov wrote: >Andreas Beyer wrote: > > >>Unfortunately that doesn't help. I called bjam like this: >>bjam -sBUILD=release -sBOOST_DISABLE_THREADS -q >>and I get the same problem. >>I then tried to compile the debug version and the story gets even >>worse: I get an internal comiler error: >> >>bjam -sBUILD=debug -sBOOST_DISABLE_THREADS -q >>[...] >>gcc-C++-action >>bin/csrc/ptr_test.so/gcc/debug/shared-linkable-true/ptr_test.o >>/cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp: >>In >> function `long int boost::detail::atomic_conditional_increment(long >>int*)': >>/cellar/users/abeyer/boost/boost_current/boost/detail/sp_counted_base_gcc_x86.hpp:94: >>Internal >> compiler error in instantiate_virtual_regs_1, at function.c:3974 >>Please submit a full bug report, >>with preprocessed source if appropriate. >>See for instructions. >> >> > >Please try the latest CVS version, where this problem has been fixed. >Hopefully it will take care of your other issue as well. Please let us know >whether this solves the problem. > > > That's it! Now it works even without the -sBOOST_DISABLE_THREADS flag. Both problems are gone. Peter, thanks a lot!! Andreas From paniq at paniq.org Sun Apr 17 15:01:40 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Sun, 17 Apr 2005 15:01:40 +0200 Subject: [C++-sig] virtual overrides and custom smart pointers Message-ID: <42625E34.7000408@paniq.org> hi, i'm running into a problem i'm trying to fix since several days without much luck. it seems my custom smart pointer class becomes worthless when wrapper<> is used to construct an object whose methods can be overridden in python. wrapper export code: class_, Ptr, boost::noncopyable>("WindowEvents") .def("OnWidgetEvent",pure_virtual(&WindowEvents::OnWidgetEvent)) .def("WidgetEventHandled",pure_virtual(&WindowEvents::WidgetEventHandled)) ; wrapper declaration: struct WindowEventsWrap : InterfaceImplementation >, wrapper< Mu::Sandoz::Interface::WindowEvents > python test code: class MyWindowEvents(Sandoz.WindowEvents): def OnWidgetEvent(self, event): print event.type return Sandoz.Result.NotImplemented def WidgetEventHandled(self, event, widget): print event.type, widget return Sandoz.Result.NotImplemented def Main(): mwe = MyWindowEvents() view = Sandoz.ViewFrame("?.Sandoz.ViewFrame") view.Connect(mwe) del mwe connect adds a reference to the mwe callback object and view calls that object later on. this is known to work. however when i delete mwe right after Connect(), the object itself persists, but its overridden methods (and i guess the underlying python object as well) are gone. no Release or AddReference on my object is called from wrapper_base, so i assume it is not using my custom smart pointer class which deals with this stuff. can someone suggest a solution to this problem? best regards, leonard From blast2001 at 21cn.com Mon Apr 18 04:11:32 2005 From: blast2001 at 21cn.com (Blade) Date: Mon, 18 Apr 2005 10:11:32 +0800 Subject: [C++-sig] Ask for help . Message-ID: <000001c543be$9e3974e0$68c810ac@TEOMartin> Hi everyone, I am a new boost.python user. I am trying to extend and embed python with my C++ application. now I encounter the following problem: My do steps: 1. Write a simple python extend module(library). 2. Write some python scripts according to extend module. 3. In my application, call PyRun_SimpleString function to execute the scripts. It works well. My question: how to exchange info or access variable(defined in C++ application or Python script) between C++ and scripts? That is to say: in scripts, how to access global variable which has been defined in C++ main application ? Could someone show me a example ? Thanks in advance, Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Mon Apr 18 04:41:53 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 17 Apr 2005 22:41:53 -0400 Subject: [C++-sig] Ask for help . In-Reply-To: <000001c543be$9e3974e0$68c810ac@TEOMartin> References: <000001c543be$9e3974e0$68c810ac@TEOMartin> Message-ID: <42631E71.1040905@sympatico.ca> Blade wrote: > My question: how to exchange info or access variable(defined in C++ > application or Python script) between C++ and scripts? > That is to say: in scripts, how to access global variable which has > been defined in C++ main application ? To reflect C++ variables into your python environment you have to bind them to names in the dictionary that gets passed to PyRun_SimpleString(). The same works in the other direction, too: once PyRun_SimpleString() has finished, you can query the same dictionary for variables that your script defined. HTH, Stefan From tom.denniston at gmail.com Mon Apr 18 04:54:15 2005 From: tom.denniston at gmail.com (Tom Denniston) Date: Sun, 17 Apr 2005 22:54:15 -0400 Subject: [C++-sig] boost.python on mac os x Message-ID: When I look at the regression test results for boost I notice that the Darwin platform does not have a result for Boost.Python. Does this mean that Boost.Python does not support mac os x? If it does not is this because of something about the mac that makes it particularly difficult to support or is there just a lack of interest in that platform? Has anyone succeeded in compiling boost.python for mac os x. When I try I get the following GCC error. From googling it seems that there is not much you can do about it. The error I get is below: ...failed gcc-Link-action bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... gcc-Link-action bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib c++: unrecognized option `-shared' -Tom From blast2001 at 21cn.com Mon Apr 18 05:06:56 2005 From: blast2001 at 21cn.com (Blade) Date: Mon, 18 Apr 2005 11:06:56 +0800 Subject: [C++-sig] Ask for help . References: <000001c543be$9e3974e0$68c810ac@TEOMartin> <42631E71.1040905@sympatico.ca> Message-ID: <003401c543c3$b07a83b0$68c810ac@TEOMartin> Thanks for your answer! Further: how to bind the C++ variables into the dictionary with boost.python not using Python/C API ? I have not found the boost.python Doc mentioned these. Could you give me some hints or some relative resource ? Are there any open source projects using python for script language for reference ? Thanks again ! Best Regards, Blade Ps: My english is not good enough, Maybe I have described something unclearly. :) ----- Original Message ----- From: "Stefan Seefeld" To: "Blade" ; "Development of Python/C++ integration" Sent: Monday, April 18, 2005 10:41 AM Subject: Re: [C++-sig] Ask for help . > Blade wrote: > > > My question: how to exchange info or access variable(defined in C++ > > application or Python script) between C++ and scripts? > > That is to say: in scripts, how to access global variable which has > > been defined in C++ main application ? > > To reflect C++ variables into your python environment you have to bind > them to names in the dictionary that gets passed to PyRun_SimpleString(). > > The same works in the other direction, too: once PyRun_SimpleString() has > finished, you can query the same dictionary for variables that your script > defined. > > HTH, > Stefan > From seefeld at sympatico.ca Mon Apr 18 05:31:56 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 17 Apr 2005 23:31:56 -0400 Subject: [C++-sig] Ask for help . In-Reply-To: <003401c543c3$b07a83b0$68c810ac@TEOMartin> References: <000001c543be$9e3974e0$68c810ac@TEOMartin> <42631E71.1040905@sympatico.ca> <003401c543c3$b07a83b0$68c810ac@TEOMartin> Message-ID: <42632A2C.7040309@sympatico.ca> Blade wrote: > Thanks for your answer! > > Further: how to bind the C++ variables into the dictionary with boost.python not using Python/C API ? > > I have not found the boost.python Doc mentioned these. > Could you give me some hints or some relative resource ? > Are there any open source projects using python for script language for reference ? You may want to look into the 'embedded.cpp' test that ships with the boost sources, i.e. 'boost/libs/python/test/embedding.cpp'. It shows how the 'main_namespace' dictionary is constructed before being passed to a call to 'PyRun_String()'. Try some modifications, i.e. add new variables to it before calling PyRun_String(), and then try accessing them from inside the executed python script. Regards, Stefan From patrick.hartling at gmail.com Mon Apr 18 14:40:23 2005 From: patrick.hartling at gmail.com (Patrick Hartling) Date: Mon, 18 Apr 2005 07:40:23 -0500 Subject: [C++-sig] boost.python on mac os x In-Reply-To: References: Message-ID: <944f7d8e050418054024acc20a@mail.gmail.com> On 4/17/05, Tom Denniston wrote: > When I look at the regression test results for boost I notice that the > Darwin platform does not have a result for Boost.Python. Does this > mean that Boost.Python does not support mac os x? If it does not is > this because of something about the mac that makes it particularly > difficult to support or is there just a lack of interest in that > platform? Boost.Python works fine for me on Mac OS X. I have used Boost.Python from the 1.31.0 and 1.32.0 releases of Boost. From looking through many messages on the Boost developer list, I believe that support for OS X was improved between 1.31.0 and 1.32.0. Furthermore, the hard work of the Boost developers to get support for OS X solidified in Boost in general helped me improve the usability of my own software on Mac OS X. > Has anyone succeeded in compiling boost.python for mac os x. When I > try I get the following GCC error. From googling it seems that there > is not much you can do about it. > > The error I get is below: > > ...failed gcc-Link-action > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... > gcc-Link-action > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib > c++: unrecognized option `-shared' It looks as though you are using the 'gcc' toolset, which is the default on OS X. Try the 'darwin' toolset instead. I am not sure why the 'darwin' toolset is not the default. There is one caveat, however: there is a file in the boost_wserialization library that requires more RAM to compile than my PowerBook has. As such, I usually restrict the build so that it either excludes that library or so that it only builds the Boost libraries that I am going to use. -Patrick -- Patrick L. Hartling http://www.137.org/patrick/ From beyer at imb-jena.de Mon Apr 18 21:02:33 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Mon, 18 Apr 2005 12:02:33 -0700 Subject: [C++-sig] Pointer to existing Python object In-Reply-To: <425EA20D.5050700@imb-jena.de> References: <425EA20D.5050700@imb-jena.de> Message-ID: <42640449.1030602@imb-jena.de> Well, still no response, maybe the issue is really tough. I keep thinking about it, this is my current state: It is already possible to obtain smart pointers for objects that are created in the Python environment. Coming back to my initial example: http://mail.python.org/pipermail/c++-sig/2005-April/008787.html I can create 'A's in Python, pass them to instances of B and B::get() will return the same *Python* object. I think this feature is enabled by python::register_ptr_to_python< A::A_ptr >(); I am looking for the reverse, objects A created by instances of B (i.e. inside C++) need to be recognized by boost::python whenever the Python environment asks for them. That means, whenever instances of B return a smart pointer to an object for which a Python object exists already, that existing Python object should be returned. For objects created in the C++ environment this means, the first call to B::get() should return a new Python wrapper, subsequent calls should return the existing object. This could become tricky. E.g., this concept may not work for all kinds of return policies. However, I am looking for a specific solution for my code, where it may be possible to circumvent these difficulties. It should be possible to implement the idea by defining a to_python_converter for A_ptr. That to_python_converter had to check for existing Pyhon objects. I tried a few things, but so-far I was unsuccessfull. Could somebody give me advice on how to proceed? 1. Are my thoughts on the right track? 2. I never wrote a to_python_converter. I am not even sure I have to: converting A* to Python with the default mechanism is no problem. In fact I want to wrap the A_ptr -> Python conversion. Can I somehow use the existing boost::python tools for converting A* inside my custom converter? How? 3. Is there an existing solution for a similar problem on which I could expand on? Thanks!! Andreas PS: Another difficulty: The wrapper that I am thinking of would manage some kind of global map, which maps pointers A* to their respective python wrappers. Pointers not in the map would get new python wrappers. But what about objects that are deleted? How gets my code informed about this? If I don't delete those entries from the map, the map will keep growing and growing. Is there a solution without changing ~A()? Andreas Beyer wrote: > Hi, > > I just want to bring this issue back on the table. I still didn't get > a brilliant idea how to solve it. > > So far, I see only this option: > - Wrap B, in particular wrap B.get(). > - In get() create the actual python object, like: > python::object py_a(B::get()); > - Store those objects in a map. > - When B_wrap.get() gets called again, check if a python object > already exists and return it. > > However, in my real-world application I had to wrap quite a lot of > methods returning As. I also have methods returning vectors of A_ptr, > which makes it even more enoying. (I would have to wrap the > vector, too.) > > What is this has_back_reference doing? Is that somehow related to my > problem? (I regret that I don't really understand what it is doing, as > I don't know what a "predicate metafunction" is.) > Just adopting the example at > http://www.boost.org/libs/python/doc/v2/has_back_reference.html is not > really a solution, because my instances of A are created inside the > C++ code (by factory methods in class B). I would have to be very > intrusive and make the actual class B aware of Python/boost::python > for adopting the above solution. > > I know that boost::python is collecting the shared pointers somewhere. > Is it possible to use that mechanism somewhow for solving my problem? > Any ideas? > > Thanks!! > Andreas > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From tom.denniston at gmail.com Tue Apr 19 01:15:32 2005 From: tom.denniston at gmail.com (Tom Denniston) Date: Mon, 18 Apr 2005 18:15:32 -0500 Subject: [C++-sig] boost.python on mac os x In-Reply-To: <944f7d8e050418054024acc20a@mail.gmail.com> References: <944f7d8e050418054024acc20a@mail.gmail.com> Message-ID: how do I use darwin rather than gcc? On 4/18/05, Patrick Hartling wrote: > On 4/17/05, Tom Denniston wrote: > > When I look at the regression test results for boost I notice that the > > Darwin platform does not have a result for Boost.Python. Does this > > mean that Boost.Python does not support mac os x? If it does not is > > this because of something about the mac that makes it particularly > > difficult to support or is there just a lack of interest in that > > platform? > > Boost.Python works fine for me on Mac OS X. I have used Boost.Python > from the 1.31.0 and 1.32.0 releases of Boost. From looking through > many messages on the Boost developer list, I believe that support for > OS X was improved between 1.31.0 and 1.32.0. Furthermore, the hard > work of the Boost developers to get support for OS X solidified in > Boost in general helped me improve the usability of my own software on > Mac OS X. > > > Has anyone succeeded in compiling boost.python for mac os x. When I > > try I get the following GCC error. From googling it seems that there > > is not much you can do about it. > > > > The error I get is below: > > > > ...failed gcc-Link-action > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... > > gcc-Link-action > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib > > c++: unrecognized option `-shared' > > It looks as though you are using the 'gcc' toolset, which is the > default on OS X. Try the 'darwin' toolset instead. I am not sure > why the 'darwin' toolset is not the default. There is one caveat, > however: there is a file in the boost_wserialization library that > requires more RAM to compile than my PowerBook has. As such, I > usually restrict the build so that it either excludes that library or > so that it only builds the Boost libraries that I am going to use. > > -Patrick > > -- > Patrick L. Hartling > http://www.137.org/patrick/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From patrick.hartling at gmail.com Tue Apr 19 02:10:07 2005 From: patrick.hartling at gmail.com (Patrick Hartling) Date: Mon, 18 Apr 2005 19:10:07 -0500 Subject: [C++-sig] boost.python on mac os x In-Reply-To: References: <944f7d8e050418054024acc20a@mail.gmail.com> Message-ID: <944f7d8e050418171059edbbdc@mail.gmail.com> On 4/18/05, Tom Denniston wrote: > how do I use darwin rather than gcc? Just as described in the documentation for building Boost: http://www.boost.org/more/getting_started.html#step5 Just specify the "darwin" toolset. A brief descrption of all the toolsets can also be found on that page, along with links to more detailed information. -Patrick > On 4/18/05, Patrick Hartling wrote: > > On 4/17/05, Tom Denniston wrote: > > > When I look at the regression test results for boost I notice that the > > > Darwin platform does not have a result for Boost.Python. Does this > > > mean that Boost.Python does not support mac os x? If it does not is > > > this because of something about the mac that makes it particularly > > > difficult to support or is there just a lack of interest in that > > > platform? > > > > Boost.Python works fine for me on Mac OS X. I have used Boost.Python > > from the 1.31.0 and 1.32.0 releases of Boost. From looking through > > many messages on the Boost developer list, I believe that support for > > OS X was improved between 1.31.0 and 1.32.0. Furthermore, the hard > > work of the Boost developers to get support for OS X solidified in > > Boost in general helped me improve the usability of my own software on > > Mac OS X. > > > > > Has anyone succeeded in compiling boost.python for mac os x. When I > > > try I get the following GCC error. From googling it seems that there > > > is not much you can do about it. > > > > > > The error I get is below: > > > > > > ...failed gcc-Link-action > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... > > > gcc-Link-action > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib > > > c++: unrecognized option `-shared' > > > > It looks as though you are using the 'gcc' toolset, which is the > > default on OS X. Try the 'darwin' toolset instead. I am not sure > > why the 'darwin' toolset is not the default. There is one caveat, > > however: there is a file in the boost_wserialization library that > > requires more RAM to compile than my PowerBook has. As such, I > > usually restrict the build so that it either excludes that library or > > so that it only builds the Boost libraries that I am going to use. > > > > -Patrick > > > > -- > > Patrick L. Hartling > > http://www.137.org/patrick/ > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > -- Patrick L. Hartling http://www.137.org/patrick/ From jbrandmeyer at earthlink.net Tue Apr 19 02:34:15 2005 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Mon, 18 Apr 2005 20:34:15 -0400 Subject: [C++-sig] boost.python on mac os x In-Reply-To: References: Message-ID: <1113870856.4652.7.camel@localhost.localdomain> On Sun, 2005-04-17 at 22:54 -0400, Tom Denniston wrote: > When I look at the regression test results for boost I notice that the > Darwin platform does not have a result for Boost.Python. Does this > mean that Boost.Python does not support mac os x? If it does not is > this because of something about the mac that makes it particularly > difficult to support or is there just a lack of interest in that > platform? > > Has anyone succeeded in compiling boost.python for mac os x. There is a prebuilt package in Fink. http://fink.sourceforge.net/pdb/search.php?summary=boost HTH, -Jonathan From tom.denniston at gmail.com Tue Apr 19 04:36:44 2005 From: tom.denniston at gmail.com (Tom Denniston) Date: Mon, 18 Apr 2005 22:36:44 -0400 Subject: [C++-sig] boost.python on mac os x In-Reply-To: <944f7d8e050418171059edbbdc@mail.gmail.com> References: <944f7d8e050418054024acc20a@mail.gmail.com> <944f7d8e050418171059edbbdc@mail.gmail.com> Message-ID: That works, all the targets seem to compile except one (see below). It seems to just hang. Is this the one you were having trouble with. what surprises me is that I have 1 GB of ram and still have the problem. The ouput I am seeing is below: Tom-Dennistons-Computer:/development/libraries/boost_1_32_0 tomdenniston$ /development/bjam-3.1.10-1/bjam -sTOOLS=darwin -sPYTHON_VERSION=2.3 ...found 8239 targets... ...updating 261 targets... darwin-C++-action bin/boost/libs/serialization/build/libboost_serialization.a/darwin/release/xml_grammar.o On 4/18/05, Patrick Hartling wrote: > On 4/18/05, Tom Denniston wrote: > > how do I use darwin rather than gcc? > > Just as described in the documentation for building Boost: > > http://www.boost.org/more/getting_started.html#step5 > > Just specify the "darwin" toolset. A brief descrption of all the > toolsets can also be found on that page, along with links to more > detailed information. > > -Patrick > > > On 4/18/05, Patrick Hartling wrote: > > > On 4/17/05, Tom Denniston wrote: > > > > When I look at the regression test results for boost I notice that the > > > > Darwin platform does not have a result for Boost.Python. Does this > > > > mean that Boost.Python does not support mac os x? If it does not is > > > > this because of something about the mac that makes it particularly > > > > difficult to support or is there just a lack of interest in that > > > > platform? > > > > > > Boost.Python works fine for me on Mac OS X. I have used Boost.Python > > > from the 1.31.0 and 1.32.0 releases of Boost. From looking through > > > many messages on the Boost developer list, I believe that support for > > > OS X was improved between 1.31.0 and 1.32.0. Furthermore, the hard > > > work of the Boost developers to get support for OS X solidified in > > > Boost in general helped me improve the usability of my own software on > > > Mac OS X. > > > > > > > Has anyone succeeded in compiling boost.python for mac os x. When I > > > > try I get the following GCC error. From googling it seems that there > > > > is not much you can do about it. > > > > > > > > The error I get is below: > > > > > > > > ...failed gcc-Link-action > > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... > > > > gcc-Link-action > > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib > > > > c++: unrecognized option `-shared' > > > > > > It looks as though you are using the 'gcc' toolset, which is the > > > default on OS X. Try the 'darwin' toolset instead. I am not sure > > > why the 'darwin' toolset is not the default. There is one caveat, > > > however: there is a file in the boost_wserialization library that > > > requires more RAM to compile than my PowerBook has. As such, I > > > usually restrict the build so that it either excludes that library or > > > so that it only builds the Boost libraries that I am going to use. > > > > > > -Patrick > > > > > > -- > > > Patrick L. Hartling > > > http://www.137.org/patrick/ > > > _______________________________________________ > > > C++-sig mailing list > > > C++-sig at python.org > > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > > -- > Patrick L. Hartling > http://www.137.org/patrick/ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From blast2001 at 21cn.com Tue Apr 19 09:50:30 2005 From: blast2001 at 21cn.com (Blade) Date: Tue, 19 Apr 2005 15:50:30 +0800 Subject: Fw: [C++-sig] Ask for help . Message-ID: <00c801c544b4$799c0fc0$68c810ac@TEOMartin> Sorry to interrupt you again ! I understand your standpoint, but don't know the specific steps to implement those. add new variables to it before calling PyRun_String(), ------------- how to do it ? try accessing them from inside the executed python script. ---------- How ? Regards, Blade ----- Original Message ----- From: "Stefan Seefeld" To: "Blade" ; "Development of Python/C++ integration" Sent: Monday, April 18, 2005 11:31 AM Subject: Re: [C++-sig] Ask for help . > Blade wrote: > > Thanks for your answer! > > > > Further: how to bind the C++ variables into the dictionary with boost.python not using Python/C API ? > > > > I have not found the boost.python Doc mentioned these. > > Could you give me some hints or some relative resource ? > > Are there any open source projects using python for script language for reference ? > > You may want to look into the 'embedded.cpp' test that ships with the boost sources, i.e. > 'boost/libs/python/test/embedding.cpp'. It shows how the 'main_namespace' dictionary > is constructed before being passed to a call to 'PyRun_String()'. Try some modifications, > i.e. add new variables to it before calling PyRun_String(), and then try accessing them > from inside the executed python script. > > Regards, > Stefan > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brett at coombs.anu.edu.au Tue Apr 19 07:42:58 2005 From: brett at coombs.anu.edu.au (Brett Calcott) Date: Tue, 19 Apr 2005 15:42:58 +1000 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: <425C4DE9.4020205@paniq.org> References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: Leonard "paniq" Ritter wrote: > fyi, the mail to brett calcott bounced. > That is me. My apologies. I haven't been using Boost Python for some time now. I have had my head buried in my PhD. This email should be more stable: brett.calcott at gmail.com I am still happy to maintain the vc build support. Leonard I assume that this just requires the addition of a file? Also, I owe Dave a personal apology. I promised some documentation of the internals way back in '03, and Dave took the time to answer some of my questions (http://www.boost.org/libs/python/doc/internals.html). I never did this. I remember making some notes, and finding it to be the hardest code to understand I had ever looked at. But I never sent anything to the list. Dave, are you still happy for me to maintain this given my track record here? The gmail address will be stable. Brett From blast2001 at 21cn.com Tue Apr 19 11:10:59 2005 From: blast2001 at 21cn.com (Blade) Date: Tue, 19 Apr 2005 17:10:59 +0800 Subject: [C++-sig] Ask for help . Message-ID: <00e601c544bf$b4e66ed0$68c810ac@TEOMartin> Hi everyone, Now I have solved the following 2 issues when the variable is simple type, but when I bind the C++ class object into the dictionary, it compile successfully, it will abort once execute it. The below is the c++ source code: if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1) throw std::runtime_error("Failed to add embedded_hello to the interpreter's " "builtin modules"); Py_Initialize(); python::object main_module(( python::handle<>(python::borrowed(PyImport_AddModule("__main__"))))); python::object main_namespace((main_module.attr("__dict__"))); Base * pBase = new Base(2000); main_namespace["retValue"] = 5; main_namespace["AppBase"] = pBase; //abort here python::handle<> result( PyRun_String( "from embedded_hello import * \n" "print AppBase.i \n" Py_file_input, main_namespace.ptr(), main_namespace.ptr()) ); Notes: Base is the class name I defined and main_namespace is the dict which is passed to PyRun_String. Could someone figure out the cause ? Thanks very much ! Best Regards, Blade ----- Original Message ----- From: Blade To: Stefan Seefeld Cc: c++-sig at python.org Sent: Tuesday, April 19, 2005 3:50 PM Subject: Fw: [C++-sig] Ask for help . Sorry to interrupt you again ! I understand your standpoint, but don't know the specific steps to implement those. add new variables to it before calling PyRun_String(), ------------- how to do it ? try accessing them from inside the executed python script. ---------- How ? Regards, Blade ----- Original Message ----- From: "Stefan Seefeld" To: "Blade" ; "Development of Python/C++ integration" Sent: Monday, April 18, 2005 11:31 AM Subject: Re: [C++-sig] Ask for help . > Blade wrote: > > Thanks for your answer! > > > > Further: how to bind the C++ variables into the dictionary with boost.python not using Python/C API ? > > > > I have not found the boost.python Doc mentioned these. > > Could you give me some hints or some relative resource ? > > Are there any open source projects using python for script language for reference ? > > You may want to look into the 'embedded.cpp' test that ships with the boost sources, i.e. > 'boost/libs/python/test/embedding.cpp'. It shows how the 'main_namespace' dictionary > is constructed before being passed to a call to 'PyRun_String()'. Try some modifications, > i.e. add new variables to it before calling PyRun_String(), and then try accessing them > from inside the executed python script. > > Regards, > Stefan > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Tue Apr 19 14:22:04 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 19 Apr 2005 14:22:04 +0200 Subject: [C++-sig] Re: Pointer to existing Python object References: <425EA20D.5050700@imb-jena.de> <42640449.1030602@imb-jena.de> Message-ID: Andreas Beyer writes: > Well, still no response, maybe the issue is really tough. I keep > thinking about it, this is my current state: Andreas, I have been travelling and on vacation, so I haven't had a chance to look at your problem yet. I'll try to give it a look before I get home on 2005/4/25, but I can't make any promises. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Apr 19 18:50:51 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 19 Apr 2005 18:50:51 +0200 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: Brett Calcott writes: > Leonard "paniq" Ritter wrote: >> fyi, the mail to brett calcott bounced. >> > > That is me. My apologies. I haven't been using Boost Python for some > time now. I have had my head buried in my PhD. This email should be more > stable: > brett.calcott at gmail.com > > I am still happy to maintain the vc build support. Leonard I assume that > this just requires the addition of a file? > > Also, I owe Dave a personal apology. I promised some documentation of > the internals way back in '03, and Dave took the time to answer some of > my questions (http://www.boost.org/libs/python/doc/internals.html). I > never did this. I remember making some notes, and finding it to be the > hardest code to understand I had ever looked at. But I never sent > anything to the list. > > Dave, are you still happy for me to maintain this given my track record > here? The gmail address will be stable. If you will actually do it, I'm happy for you to do it ;-) If you are saying that you are going to be unreliable, that's another matter. -- Dave Abrahams Boost Consulting www.boost-consulting.com From mike at thewilsonfamily.freeserve.co.uk Thu Apr 21 14:31:34 2005 From: mike at thewilsonfamily.freeserve.co.uk (Mike) Date: Thu, 21 Apr 2005 13:31:34 +0100 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org><425C4DE9.4020205@paniq.org> Message-ID: <000401c5466e$0ef7e0c0$d8b44c51@MIKESPC01> Bret Calcott wrote.... > > I am still happy to maintain the vc build support. Leonard I assume that > this just requires the addition of a file? > I have just noticed that slice.cpp also needs to be added to the project (besides wrapper.cpp). Mike From patrick.hartling at gmail.com Wed Apr 20 00:08:54 2005 From: patrick.hartling at gmail.com (Patrick Hartling) Date: Tue, 19 Apr 2005 17:08:54 -0500 Subject: [C++-sig] boost.python on mac os x In-Reply-To: References: <944f7d8e050418054024acc20a@mail.gmail.com> <944f7d8e050418171059edbbdc@mail.gmail.com> Message-ID: <944f7d8e0504191508371993cf@mail.gmail.com> On 4/18/05, Tom Denniston wrote: > That works, all the targets seem to compile except one (see below). > It seems to just hang. Is this the one you were having trouble with. > what surprises me is that I have 1 GB of ram and still have the > problem. > > The ouput I am seeing is below: > > Tom-Dennistons-Computer:/development/libraries/boost_1_32_0 > tomdenniston$ /development/bjam-3.1.10-1/bjam -sTOOLS=darwin > -sPYTHON_VERSION=2.3 > ...found 8239 targets... > ...updating 261 targets... > darwin-C++-action > bin/boost/libs/serialization/build/libboost_serialization.a/darwin/release/xml_grammar.o That's the one. Perhaps it's not a memory problem but rather a compiler bug? I haven't ever bothered to dig into it because I am not using the serialization library. As I said before, I usually restrict the build to just the libraries that I need. It saves time and space. -Patrick > On 4/18/05, Patrick Hartling wrote: > > On 4/18/05, Tom Denniston wrote: > > > how do I use darwin rather than gcc? > > > > Just as described in the documentation for building Boost: > > > > http://www.boost.org/more/getting_started.html#step5 > > > > Just specify the "darwin" toolset. A brief descrption of all the > > toolsets can also be found on that page, along with links to more > > detailed information. > > > > -Patrick > > > > > On 4/18/05, Patrick Hartling wrote: > > > > On 4/17/05, Tom Denniston wrote: > > > > > When I look at the regression test results for boost I notice that the > > > > > Darwin platform does not have a result for Boost.Python. Does this > > > > > mean that Boost.Python does not support mac os x? If it does not is > > > > > this because of something about the mac that makes it particularly > > > > > difficult to support or is there just a lack of interest in that > > > > > platform? > > > > > > > > Boost.Python works fine for me on Mac OS X. I have used Boost.Python > > > > from the 1.31.0 and 1.32.0 releases of Boost. From looking through > > > > many messages on the Boost developer list, I believe that support for > > > > OS X was improved between 1.31.0 and 1.32.0. Furthermore, the hard > > > > work of the Boost developers to get support for OS X solidified in > > > > Boost in general helped me improve the usability of my own software on > > > > Mac OS X. > > > > > > > > > Has anyone succeeded in compiling boost.python for mac os x. When I > > > > > try I get the following GCC error. From googling it seems that there > > > > > is not much you can do about it. > > > > > > > > > > The error I get is below: > > > > > > > > > > ...failed gcc-Link-action > > > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/debug/shared-linkable-true/libboost_regex-gcc-d-1_32.dylib... > > > > > gcc-Link-action > > > > > bin/boost/libs/regex/build/libboost_regex.dylib/gcc/release/shared-linkable-true/libboost_regex-gcc-1_32.dylib > > > > > c++: unrecognized option `-shared' > > > > > > > > It looks as though you are using the 'gcc' toolset, which is the > > > > default on OS X. Try the 'darwin' toolset instead. I am not sure > > > > why the 'darwin' toolset is not the default. There is one caveat, > > > > however: there is a file in the boost_wserialization library that > > > > requires more RAM to compile than my PowerBook has. As such, I > > > > usually restrict the build so that it either excludes that library or > > > > so that it only builds the Boost libraries that I am going to use. > > > > > > > > -Patrick > > > > > > > > -- > > > > Patrick L. Hartling > > > > http://www.137.org/patrick/ > > > > _______________________________________________ > > > > C++-sig mailing list > > > > C++-sig at python.org > > > > http://mail.python.org/mailman/listinfo/c++-sig > > > > > > > > > > > -- > > Patrick L. Hartling > > http://www.137.org/patrick/ > > _______________________________________________ > > C++-sig mailing list > > C++-sig at python.org > > http://mail.python.org/mailman/listinfo/c++-sig > > > -- Patrick L. Hartling http://www.137.org/patrick/ From mikeowen at llnl.gov Thu Apr 21 02:50:14 2005 From: mikeowen at llnl.gov (J. Michael Owen) Date: Wed, 20 Apr 2005 17:50:14 -0700 Subject: [C++-sig] RTLD_GLOBAL cures my g++ + Boost.Python + cross module blues? Message-ID: <200504201750.14065.mikeowen@llnl.gov> I've recently come across a method to get my g++ compiled Boost.Python classes wrapped in different shared libraries to work (cross module class inheritance, dynamic_cast, etc.), and I thought I'd share this to see if it's useful to anyone else here, as well as see if anyone knows of any problems with this approach. For completeness I'm using Python 2.3.4, g++ 3.4.1, and the last Boost release (1.32.0) on Linux x86. When compiling with g++ I've been plagued by the cross library type_info problems described elsewhere (http://www.python.org/moin/boost.python/CrossExtensionModuleDependencies), but recently I discovered that if I force python's dlopen to use RTLD_GLOBAL then upon importing my extensions the different libraries resolve these type_info problems and everything starts working. All I've done is issue the following python commands before importing any Boost.Python wrapped code: import sys, dl sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL) While this seems to have solved all of my current cross-library problems, I'm suspicious that it could be this simple. Does anyone else here have any experience with these g++/Boost.Python/cross module issues? Is there a reason the above might be a bad idea? Mike. -- "Hey...where are the sunflower seeds?" | J. Michael Owen o_o / | (") | Email: mikeowen at llnl.gov \/'\/ | ____(__(,_,)_______________________________________________________________ From brett at coombs.anu.edu.au Thu Apr 21 05:48:13 2005 From: brett at coombs.anu.edu.au (Brett Calcott) Date: Thu, 21 Apr 2005 13:48:13 +1000 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? In-Reply-To: References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: David Abrahams wrote: > > If you will actually do it, I'm happy for you to do it ;-) Yes. I will do it. I have VC6 and 7.1, so should be able to sort this in the next week. > > If you are saying that you are going to be unreliable, that's another > matter. > Looking after the vc build is doable. I can be relied on for this. I bit off more than I could chew with documenting internals :( Cheers, Brett From news4vovan at mail.ru Fri Apr 22 17:24:21 2005 From: news4vovan at mail.ru (Vladimir Sukhoy) Date: Fri, 22 Apr 2005 18:24:21 +0300 Subject: [C++-sig] pyste, shared_ptr and constructor override Message-ID: I use boost.python to export class which is enclosed in smart pointer and has protected constructor to force smart pointer usage, like that: class MyClass; typedef boost::shared_ptr MyClassPtr; class MyClass { public: static MyClassPtr Create(); virtual ~MyClass(); protected: MyClass(); }; So, after pyste has processed the code for MyClass I have something like that: class_< MyClass, bases< boost::noncopyable_::noncopyable > , boost::noncopyable >("MyClass", no_init) .def("Create", &MyClass::Create) .... register_ptr_to_python< boost::shared_ptr< space::http::SimpleGet > >(); So after compiling extension module I can use MyClass from python like that mc = MyClass.Create() But that's not exactly what I want, because I really meant that shared_ptr IS MyClass, so I want to write mc = MyClass() and have C++ function MyClass::Create being called instead. Of course, I can override this with Python (which rox), even procedurally, like that: def override_constructor(cls, cons, d): def override_func(cls, *args, **kwargs): return cons(*args, **kwargs) dc = {'__new__' : override_func} from new import classobj d[cls.__name__] = classobj(cls.__name__, (cls,), dc) override_constructor(MyClass, MyClass.Create, globals()) Is there a way to do the same thing with pyste at wrapper generation step? From tom.denniston at gmail.com Sat Apr 23 20:36:49 2005 From: tom.denniston at gmail.com (Tom Denniston) Date: Sat, 23 Apr 2005 14:36:49 -0400 Subject: [C++-sig] Running python using Boost.Python modules Message-ID: Is there a way to run python so that it picks up the C++ modules compiled using Boost.Python and bjam. I saw in the examples that you could run python from a bjam target such as the following: # Declare a test for the extension module boost-python-runtest test1 : # Python test driver src/python/test_getting_started1.py # extension modules to use getting_started1 ; But I didn't see anything on how to run a python process independent of a bjam target. one possibility is to copy the modules into the python installation but i would prefer to use the libraries from python without having and side efffect on my python installation. Would appreciate any thoughts or direction toward the appropriate documentation. I might just be missing something really obvious here. -Tom From jbrandmeyer at earthlink.net Sat Apr 23 22:36:10 2005 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Sat, 23 Apr 2005 16:36:10 -0400 Subject: [C++-sig] Running python using Boost.Python modules In-Reply-To: References: Message-ID: <1114288570.20396.11.camel@localhost.localdomain> On Sat, 2005-04-23 at 14:36 -0400, Tom Denniston wrote: > Is there a way to run python so that it picks up the C++ modules > compiled using Boost.Python and bjam. I saw in the examples that you > could run python from a bjam target such as the following: > > # Declare a test for the extension module > boost-python-runtest test1 > : # Python test driver > src/python/test_getting_started1.py > # extension modules to use > getting_started1 ; > > > > But I didn't see anything on how to run a python process independent > of a bjam target. one possibility is to copy the modules into the > python installation but i would prefer to use the libraries from > python without having and side efffect on my python installation. > > Would appreciate any thoughts or direction toward the appropriate > documentation. I might just be missing something really obvious here. See sys.path in the Python Library Reference, and Installing Python Modules, section 4.1. HTH, -Jonathan From nicodemus at esss.com.br Sun Apr 24 17:49:16 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Sun, 24 Apr 2005 13:49:16 -0200 Subject: [C++-sig] pyste, shared_ptr and constructor override In-Reply-To: References: Message-ID: <426BBFFC.5020900@esss.com.br> Hi Vladmir, Vladimir Sukhoy wrote: >But that's not exactly what I want, because I really meant that shared_ptr >IS MyClass, >so I want to write > >mc = MyClass() > >and have C++ function MyClass::Create being called instead. > >Of course, I can override this with Python (which rox), even procedurally, >like that: > >def override_constructor(cls, cons, d): > def override_func(cls, *args, **kwargs): > return cons(*args, **kwargs) > dc = {'__new__' : override_func} > from new import classobj > d[cls.__name__] = classobj(cls.__name__, (cls,), dc) > >override_constructor(MyClass, MyClass.Create, globals()) > >Is there a way to do the same thing with pyste at wrapper generation step? > > Not right now, and I don't have any definite plans for it either. :/ I suggest you keep inserting the constructor like you are doing. Regards, Bruno. From itamar at itamarst.org Mon Apr 25 17:54:58 2005 From: itamar at itamarst.org (Itamar Shtull-Trauring) Date: Mon, 25 Apr 2005 11:54:58 -0400 Subject: [C++-sig] RTLD_GLOBAL cures my g++ + Boost.Python + cross module blues? In-Reply-To: <200504201750.14065.mikeowen@llnl.gov> References: <200504201750.14065.mikeowen@llnl.gov> Message-ID: <1114444498.8213.29.camel@localhost.localdomain> On Wed, 2005-04-20 at 17:50 -0700, J. Michael Owen wrote: > import sys, dl > sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL) > > While this seems to have solved all of my current cross-library problems, I'm > suspicious that it could be this simple. Does anyone else here have any > experience with these g++/Boost.Python/cross module issues? Is there a > reason the above might be a bad idea? This is what I do. The only possible problem, I think, is that the symbols might conflict with other C modules you will load later. Using namespaces should make this unlikely, and I typically reset dlopenflags back to normal (i.e. no RTLD_GLOBAL) once I've imported my boost module. And of course this won't work on Windows :) From nicodemus at esss.com.br Tue Apr 26 00:11:32 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 25 Apr 2005 20:11:32 -0200 Subject: [C++-sig] Getting the pointer for a member operator Message-ID: <426D6B14.9040309@esss.com.br> Hello all, Currently Pyste does this: // C++ code struct C { operator const char*() { return "C"; } }; // generated: BOOST_PYTHON_MODULE(_operators) { class_< operators::C >("C", init< >()) .def("__str__", &operators::C::operator const char*) ; } Problem is that this is broken under MSVC.NET 2003. The compiler complains with: """ _operators.cpp(24) : error C2833: 'operator const' is not a recognized operator or type """ ie, the compiler doesn't realize that its the operator const char* that it should get the address to. I tried changing it to: .def("__str__", &operators::C::operator (const char*)) But without success. Does anybody know how I can fix this? Best Regards, Nicodemus. From nicodemus at esss.com.br Tue Apr 26 00:40:36 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 25 Apr 2005 20:40:36 -0200 Subject: [C++-sig] Pyste bug? Using Wrapper with member functions and --pyste-ns In-Reply-To: <5ab8740205032002161499b77d@mail.gmail.com> References: <5ab8740205032002161499b77d@mail.gmail.com> Message-ID: <426D71E4.3040605@esss.com.br> Dan Haffey wrote: >Hello, > >I just noticed that when using the Pyste Wrapper call to create a >member function wrapper, it places the wrapper definition code outside >of the specified (--pyste-ns=) namespace, but the generated module >code looks for it in the namespace. This doesn't seem to happen with >normal functions, just members. > > Fixed. Thanks Dan! Regards, Nicodemus. From news4vovan at mail.ru Tue Apr 26 16:01:49 2005 From: news4vovan at mail.ru (Vladimir Sukhoy) Date: Tue, 26 Apr 2005 17:01:49 +0300 Subject: [C++-sig] Re: Getting the pointer for a member operator References: <426D6B14.9040309@esss.com.br> Message-ID: > Problem is that this is broken under MSVC.NET 2003. The compiler complains > with: I tried similar with .NET 2003 compiler - it works, and I cannot reproduce this error! The full module code is: #include using namespace boost::python; namespace operators { struct C { operator const char*() { return "C"; } }; } BOOST_PYTHON_MODULE(_ace) { class_< operators::C >("C", init< >()) .def("__str__", &operators::C::operator const char*) ; } From blast2001 at 21cn.com Wed Apr 27 05:44:25 2005 From: blast2001 at 21cn.com (Martin Dai) Date: Wed, 27 Apr 2005 11:44:25 +0800 Subject: [C++-sig] Pass C++ object to python issue Message-ID: Hi everyone, Now I have solved the pass variable when the variable is simple type, but when I bind the C++ class object into the dictionary, it compile successfully, it will abort once execute it. The below is the c++ source code: if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1) throw std::runtime_error("Failed to add embedded_hello to the interpreter's " "builtin modules"); Py_Initialize(); python::object main_module(( python::handle<>(python::borrowed(PyImport_AddModule("__main__"))))); python::object main_namespace((main_module.attr("__dict__"))); Base * pBase = new Base(2000); main_namespace["retValue"] = 5; main_namespace["AppBase"] = python::object(python::ptr(pBase)); //abort here python::handle<> result( PyRun_String( "from embedded_hello import * \n" "print AppBase.i \n" Py_file_input, main_namespace.ptr(), main_namespace.ptr()) ); Notes: Base is the class name I defined and main_namespace is the dict which is passed to PyRun_String. Could someone figure out the cause ? Thanks very much ! Best Regards, Blade From ghost at cs.msu.su Wed Apr 27 09:32:42 2005 From: ghost at cs.msu.su (Vladimir Prus) Date: Wed, 27 Apr 2005 11:32:42 +0400 Subject: [C++-sig] Re: Pass C++ object to python issue References: Message-ID: Martin Dai wrote: > Hi everyone, > > Now I have solved the pass variable when the variable is simple > type, > but when I bind the C++ class object into the dictionary, it compile > successfully, it will abort once execute it. With what error message? > The below is the c++ source code: > > if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == > -1) Please always provide a complete program. > main_namespace["AppBase"] = python::object(python::ptr(pBase)); > //abort here > > python::handle<> result( > PyRun_String( > "from embedded_hello import * \n" > "print AppBase.i \n" > Py_file_input, main_namespace.ptr(), main_namespace.ptr()) > ); I've tried to reproduce this, and got: http://zigzag.cs.msu.su/~ghost/e3.cpp that works fine. However, when I move the main_namespace["context"] = ptr(b); above call to PyRun_String (as is done in your example), http://zigzag.cs.msu.su/~ghost/e3f.cpp I get this: TypeError: No Python class registered for C++ class B which looks quite reasonable. Python has no idea that class 'B' even exists, but you're trying to add instance of that class. I wonder if it's possible to automatically register Python class in this case, though. - Volodya From Ben.Cain at us.army.mil Wed Apr 27 16:09:52 2005 From: Ben.Cain at us.army.mil (Cain, Ben (Contractor-Summit)) Date: Wed, 27 Apr 2005 09:09:52 -0500 Subject: [C++-sig] Newbie ... trouble compiling Boost.Python Message-ID: <6DB8567B5D54F443982465B984BE4AA99B2B18@amr-ex5.ds.amrdec.army.mil> Hello, I'm getting an error when trying to compile Boost.Python (using GCC on Windows). Most of Boost seemed to compile successfully. I used the following command to compile from C:\Boost_1_32_0 bjam "-sTOOLS=gcc" install However, I get the following error during the Boost.Python build phase: Python.h: No such file or directory I have the following environment variables set with Python 2.3.5 installed: PYTHON_ROOT C:\Python23 PYTHON_VERSION 2.3 PYTHON_INCLUDES C:\Python23\include PYTHON_LIB_PATH C:\Python23\libs I then tried to build Boost.Python directly from C:\Boost_1_32_0\libs\python\build. However, bjam didn't know how to build from this directory. Any help will be greatly appreciated. Thanks, Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Apr 27 20:34:39 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 27 Apr 2005 14:34:39 -0400 Subject: [C++-sig] Re: wrapper.cpp not in 1.32.0 dsp/vcproj file? References: <200504081610.00461.mvc@di.fct.unl.pt> <425896D6.30808@paniq.org> <425AC635.4050200@paniq.org> <425C4DE9.4020205@paniq.org> Message-ID: Brett Calcott writes: > David Abrahams wrote: >> If you will actually do it, I'm happy for you to do it ;-) > > Yes. I will do it. I have VC6 and 7.1, so should be able to sort this in > the next week. Thanks! -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Apr 27 20:51:53 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 27 Apr 2005 14:51:53 -0400 Subject: [C++-sig] Re: Getting the pointer for a member operator References: <426D6B14.9040309@esss.com.br> Message-ID: Nicodemus writes: > Problem is that this is broken under MSVC.NET 2003. The compiler > complains with: > > """ > _operators.cpp(24) : error C2833: 'operator const' is not a recognized > operator or type > """ > > ie, the compiler doesn't realize that its the operator const char* that > it should get the address to. I tried changing it to: > > .def("__str__", &operators::C::operator (const char*)) > > But without success. Does anybody know how I can fix this? Did you try a typedef? typedef char const* string; ... .def("__str__", &operators::C::operator string) -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Apr 27 20:56:36 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 27 Apr 2005 14:56:36 -0400 Subject: [C++-sig] Re: Newbie ... trouble compiling Boost.Python References: <6DB8567B5D54F443982465B984BE4AA99B2B18@amr-ex5.ds.amrdec.army.mil> Message-ID: "Cain, Ben (Contractor-Summit)" writes: > Hello, > > I'm getting an error when trying to compile Boost.Python (using GCC on > Windows). Most of Boost seemed to compile successfully. > > I used the following command to compile from C:\Boost_1_32_0 > bjam "-sTOOLS=gcc" install > > However, I get the following error during the Boost.Python build phase: > Python.h: No such file or directory > > I have the following environment variables set with Python 2.3.5 > installed: > PYTHON_ROOT C:\Python23 > PYTHON_VERSION 2.3 > PYTHON_INCLUDES C:\Python23\include > PYTHON_LIB_PATH C:\Python23\libs > > I then tried to build Boost.Python directly from > C:\Boost_1_32_0\libs\python\build. However, bjam didn't know how to > build from this directory. The directory is not the issue. My guess is that you are trying to use a Cygwin GCC from a Windows command-prompt with a Windows (not Cygwin) installation of Python? You either need to use a MinGW compiler (or gcc-nocygwin) or use a Cygwin-based python. See http://www.boost.org/libs/python/doc/building.html#cygwin_configuration -- Dave Abrahams Boost Consulting www.boost-consulting.com From Ben.Cain at us.army.mil Thu Apr 28 00:45:23 2005 From: Ben.Cain at us.army.mil (Cain, Ben (Contractor-Summit)) Date: Wed, 27 Apr 2005 17:45:23 -0500 Subject: [C++-sig] Re: Newbie ... trouble compiling Boost.Python Message-ID: <6DB8567B5D54F443982465B984BE4AA99B2B1F@amr-ex5.ds.amrdec.army.mil> David, I am trying to build from Windows command-prompt. However, I think I'm using MinGW's gcc. gcc -v yields Reading specs from C:/MinGW/bin/../lib/gcc-lib/mingw32/3.2.3/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry --disable-shared --enable-sjlj-exceptions Thread model: win32 gcc version 3.2.3 (mingw special 20030504-1) I downloaded Python from ... http://www.python.org/ftp/python/2.3.5/Python-2.3.5.exe I downloaded Boost from ... http://prdownloads.sourceforge.net/boost/boost_1_32_0.exe?download Thanks, Ben David Abrahams wrote: > > My guess is that you are trying to > use a Cygwin GCC from a Windows command-prompt with a Windows (not > Cygwin) installation of Python? > > You either need to use a MinGW compiler (or gcc-nocygwin) or use a > Cygwin-based python. From nyamatongwe at gmail.com Thu Apr 28 01:19:31 2005 From: nyamatongwe at gmail.com (Neil Hodgson) Date: Thu, 28 Apr 2005 09:19:31 +1000 Subject: [C++-sig] Visual C++ 2005 Message-ID: <50862ebd050427161953cfc3ab@mail.gmail.com> Does anyone know if compilation of Boost.Python based code works better with Visual C++ 2005 compared to the 2003 version? Visual C++ 2003 is OK but requires breaking wrappers up into multiple files and compilation can be very slow and memory-intensive. How can Boost.Jam be instructed to look for Visual C++ 2005? Both versions of the compiler are installed here and Boost.Jam always finds 2003. A beta of the express edition of Visual C++ 2005 is a free download, IIRC about 60 Megs. Neil From blast2001 at 21cn.com Thu Apr 28 03:47:35 2005 From: blast2001 at 21cn.com (Martin Dai) Date: Thu, 28 Apr 2005 09:47:35 +0800 Subject: [C++-sig] Re: Pass C++ object to python issue References: Message-ID: Hi Volodya, Thanks for your great help. I have tried those two files(those are very visual :). But just as you mentioned: is it possible to register the corresponding Python class for custom C++ class by an explicit way before Invoke PyRun_String? Best Regards, Martin "Vladimir Prus" ???? news:d4neu4$qas$1 at sea.gmane.org... > Martin Dai wrote: > > > Hi everyone, > > > > Now I have solved the pass variable when the variable is simple > > type, > > but when I bind the C++ class object into the dictionary, it compile > > successfully, it will abort once execute it. > > With what error message? > > > The below is the c++ source code: > > > > if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == > > -1) > > Please always provide a complete program. > > > main_namespace["AppBase"] = python::object(python::ptr(pBase)); > > //abort here > > > > python::handle<> result( > > PyRun_String( > > "from embedded_hello import * \n" > > "print AppBase.i \n" > > Py_file_input, main_namespace.ptr(), main_namespace.ptr()) > > ); > > I've tried to reproduce this, and got: > > http://zigzag.cs.msu.su/~ghost/e3.cpp > > that works fine. However, when I move the > > main_namespace["context"] = ptr(b); > > above call to PyRun_String (as is done in your example), > > http://zigzag.cs.msu.su/~ghost/e3f.cpp > > I get this: > > TypeError: No Python class registered for C++ class B > > which looks quite reasonable. Python has no idea that class 'B' even exists, > but you're trying to add instance of that class. I wonder if it's possible > to automatically register Python class in this case, though. > > - Volodya From paniq at paniq.org Thu Apr 28 19:54:15 2005 From: paniq at paniq.org (Leonard "paniq" Ritter) Date: Thu, 28 Apr 2005 19:54:15 +0200 Subject: [C++-sig] virtual overrides and custom smart pointers In-Reply-To: <42625E34.7000408@paniq.org> References: <42625E34.7000408@paniq.org> Message-ID: <42712347.6090902@paniq.org> the problem still persists. does anyone have a solution? Leonard "paniq" Ritter wrote: > hi, > > i'm running into a problem i'm trying to fix since several days > without much luck. it seems my custom smart pointer class becomes > worthless when wrapper<> is used to construct an object whose methods > can be overridden in python. > > wrapper export code: > > class_, > Ptr, boost::noncopyable>("WindowEvents") > > .def("OnWidgetEvent",pure_virtual(&WindowEvents::OnWidgetEvent)) > > .def("WidgetEventHandled",pure_virtual(&WindowEvents::WidgetEventHandled)) > > ; > > wrapper declaration: > > struct WindowEventsWrap > : InterfaceImplementation Implements >, > wrapper< Mu::Sandoz::Interface::WindowEvents > > > python test code: > > class MyWindowEvents(Sandoz.WindowEvents): > def OnWidgetEvent(self, event): > print event.type > return Sandoz.Result.NotImplemented > def WidgetEventHandled(self, event, widget): > print event.type, widget > return Sandoz.Result.NotImplemented > > def Main(): > mwe = MyWindowEvents() > view = Sandoz.ViewFrame("?.Sandoz.ViewFrame") > view.Connect(mwe) > del mwe > > connect adds a reference to the mwe callback object and view calls > that object later on. this is known to work. however when i delete mwe > right after Connect(), the object itself persists, but its overridden > methods (and i guess the underlying python object as well) are gone. > no Release or AddReference on my object is called from wrapper_base, > so i assume it is not using my custom smart pointer class which deals > with this stuff. > > can someone suggest a solution to this problem? > > best regards, > leonard > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From dave at boost-consulting.com Thu Apr 28 23:09:21 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 28 Apr 2005 17:09:21 -0400 Subject: [C++-sig] Re: Pointer to existing Python object References: <425B363E.8090905@imb-jena.de> Message-ID: 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) ); } > An example: > > > 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()); > } > A::A_ptr a; > void set(A::A_ptr a) { > this->a = a; > } > > A::A_ptr get() { > return a->self(); What was wrong with return a; here? > } > }; > A::A_ptr get_b_a(B& b) { hold_python(b.a); return b.a; } > BOOST_PYTHON_MODULE(ptr_test) { > python::class_ ("A") > .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) // <=== here > ; > } > > > In Python I would like to do this: > >>>> b = B() >>>> a1 = b.get() # obtain instance of class A >>>> a2 = b.get() # get the *same Python instance* again >>>> assert(a1==a2) > Traceback (most recent call last): > File "", line 1, in ? > AssertionError >>>> > > The internal representations of instances of A are the same! Whenever I > access a C++ member of A I am actually accessing the same object. So I > can do this: >>>> a1.val = 42 # change internal reference >>>> print a2.val > 42 >>>> > However, I cannot do this: >>>> a1.foo = 42 >>>> print a2.foo > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'A' object has no attribute 'foo' >>>> > > I think instances of B have to check if there is already an existing > Python object. In that case B (or a wrapper of B) should return the > existing Python object (i.e. instances of python::object). Is there a > way to find such an existing instance? HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 28 16:51:47 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 28 Apr 2005 10:51:47 -0400 Subject: [C++-sig] Re: Visual C++ 2005 References: <50862ebd050427161953cfc3ab@mail.gmail.com> Message-ID: Neil Hodgson writes: > Does anyone know if compilation of Boost.Python based code works > better with Visual C++ 2005 compared to the 2003 version? Visual C++ > 2003 is OK but requires breaking wrappers up into multiple files and > compilation can be very slow and memory-intensive. > > How can Boost.Jam be instructed to look for Visual C++ 2005? With the latest Boost CVS, myjam -sTOOLS=vc-8_0 whatever -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Apr 28 15:35:07 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 28 Apr 2005 09:35:07 -0400 Subject: [C++-sig] Re: Newbie ... trouble compiling Boost.Python References: <6DB8567B5D54F443982465B984BE4AA99B2B1F@amr-ex5.ds.amrdec.army.mil> Message-ID: "Cain, Ben (Contractor-Summit)" writes: > David, > > I am trying to build from Windows command-prompt. However, I think I'm > using MinGW's gcc. > > gcc -v yields > > Reading specs from C:/MinGW/bin/../lib/gcc-lib/mingw32/3.2.3/specs > Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as > --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads > --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry > --disable-shared --enable-sjlj-exceptions > Thread model: win32 > gcc version 3.2.3 (mingw special 20030504-1) > > I downloaded Python from ... > > http://www.python.org/ftp/python/2.3.5/Python-2.3.5.exe > > I downloaded Boost from ... > > http://prdownloads.sourceforge.net/boost/boost_1_32_0.exe?download In that case you need to use -sTOOLS=mingw. http://www.boost.org/more/getting_started.html#Tools shows that -sTOOLS=gcc is reserved for Unix and Cygwin. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ustc9305 at yahoo.com Thu Apr 28 23:17:41 2005 From: ustc9305 at yahoo.com (jianbing wu) Date: Thu, 28 Apr 2005 14:17:41 -0700 (PDT) Subject: [C++-sig] for python library file Message-ID: <20050428211741.42216.qmail@web51109.mail.yahoo.com> Hi guys, I am currently write a C++ program which will use the "python24.lib", but when I compiled my program under the debug version, the .Net compiler complains not finding "pythod24_d.lib" (as I knew this library file is only used for debugging purpose). But I cannot find it in the python installation folder. Would someone please give me this file or tell me how to create this file? Thank you, Ivory __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From Ben.Cain at us.army.mil Fri Apr 29 04:24:22 2005 From: Ben.Cain at us.army.mil (Cain, Ben (Contractor-Summit)) Date: Thu, 28 Apr 2005 21:24:22 -0500 Subject: [C++-sig] Re: Newbie ... trouble compiling Boost.Python Message-ID: <6DB8567B5D54F443982465B984BE4AA99B2B26@amr-ex5.ds.amrdec.army.mil> David, Thank you for your patience with a Python newbie. I hope to contribute to this mailing list as I come up to speed. Many Thanks, Ben David Abrahams wrote: > > In that case you need to use -sTOOLS=mingw. > http://www.boost.org/more/getting_started.html#Tools shows that > -sTOOLS=gcc is reserved for Unix and Cygwin. .org/mailman/listinfo/c++-sig [Ben Cain wrote:] From sascha at askja.de Fri Apr 29 08:36:38 2005 From: sascha at askja.de (Sascha Jensen) Date: Fri, 29 Apr 2005 08:36:38 +0200 Subject: [C++-sig] for python library file In-Reply-To: <20050428211741.42216.qmail@web51109.mail.yahoo.com> References: <20050428211741.42216.qmail@web51109.mail.yahoo.com> Message-ID: <4271D5F6.2040607@askja.de> jianbing wu wrote: > Hi guys, > I am currently write a C++ program which will use the > "python24.lib", but when I compiled my program under > the debug version, the .Net compiler complains not > finding "pythod24_d.lib" (as I knew this library file > is only used for debugging purpose). But I cannot find > it in the python installation folder. Would someone > please give me this file or tell me how to create this > file? in pyconfig.h is defined to use python24_d.lib #ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext */ # if defined(_MSC_VER) /* So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) */ # ifdef _DEBUG # pragma comment(lib,"python24_d.lib") # else # pragma comment(lib,"python24.lib") # endif /* _DEBUG */ # endif /* _MSC_VER */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ i used this inside my header to undefine _DEBUG for the Python lib, because i did not need debugging #ifdef _DEBUG #undef _DEBUG #include "Python.h" #define _DEBUG #else #include "Python.h" #endif probably there is a more elegant way, but this works fine for me, Sascha From dave at boost-consulting.com Fri Apr 29 16:40:25 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 29 Apr 2005 10:40:25 -0400 Subject: [C++-sig] Re: virtual overrides and custom smart pointers References: <42625E34.7000408@paniq.org> <42712347.6090902@paniq.org> Message-ID: "Leonard \"paniq\" Ritter" writes: >> can someone suggest a solution to this problem? Post a minimal complete test case and I might be able to help. -- Dave Abrahams Boost Consulting www.boost-consulting.com From jaehokim1 at yahoo.com Fri Apr 29 17:19:25 2005 From: jaehokim1 at yahoo.com (jaeho kim) Date: Fri, 29 Apr 2005 08:19:25 -0700 (PDT) Subject: [C++-sig] Need to understand the following Python Program- Help me.. Message-ID: <20050429151925.32787.qmail@web51409.mail.yahoo.com> Hi,,, I am very interested about the following Python program, but I am very beginner on Python.. I do not understand this algorithm,, I would appreciated if you give me this algorithm to some other popular programming language. filename="Karp.py" from __future__ import nested_scopes import bisect class _Num: def __init__(self, value, index): self.value = value self.i = index def __lt__(self, other): return self.value < other.value # This implements the Karmarkar-Karp heuristic for partitioning a set # in two, i.e. into two disjoint subsets s.t. their sums are # approximately equal. It produces only one result, in O(N*log N) # time. A remarkable property is that it loves large sets: in # general, the more numbers you feed it, the better it does. class Partition: def __init__(self, nums): self.nums = nums sorted = [_Num(nums[i], i) for i in range(len(nums))] sorted.sort() self.sorted = sorted def run(self): sorted = self.sorted[:] N = len(sorted) connections = [[] for i in range(N)] while len(sorted) > 1: bigger = sorted.pop() smaller = sorted.pop() # Force these into different sets, by "drawing a # line" connecting them. i, j = bigger.i, smaller.i connections[i].append(j) connections[j].append(i) diff = bigger.value - smaller.value assert diff >= 0 bisect.insort(sorted, _Num(diff, i)) # Now sorted contains only 1 element x, and x.value is # the difference between the subsets' sums. # Theorem: The connections matrix represents a spanning tree # on the set of index nodes, and any tree can be 2-colored. # 2-color this one (with "colors" 0 and 1). index2color = [None] * N def color(i, c): if index2color[i] is not None: assert index2color[i] == c return index2color[i] = c for j in connections[i]: color(j, 1-c) color(0, 0) # Partition the indices by their colors. subsets = [[], []] for i in range(N): subsets[index2color[i]].append(i) return subsets N = 50 import math x = [math.sqrt(i) for i in range(1, N+1)] p = Partition(x) s, t = p.run() sum1 = 0L sum2 = 0L for i in s: sum1 += x[i] for i in t: sum2 += x[i] print "Set 1 sum", repr(sum1) print "Set 2 sum", repr(sum2) print "difference", repr(abs(sum1 - sum2)) Thanks for you help... Larry Jaeho Kim Larry Jaeho Kim __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From MKhesin at liquidnet.com Fri Apr 29 17:25:24 2005 From: MKhesin at liquidnet.com (Max Khesin) Date: Fri, 29 Apr 2005 11:25:24 -0400 Subject: [C++-sig] Need to understand the following Python Program- He lp me.. Message-ID: <4B6FB7F60D37D41188C300B0D022E0C0039653FD@exchange.lnholdings.com> Wrong forum - this one is dedicated to Python/C++ binding. Please try comp.lang.python on Usenet, or better yet google "karp algorithm" - I am sure you will find many implementations. max -----Original Message----- From: jaeho kim [mailto:jaehokim1 at yahoo.com] Sent: Friday, April 29, 2005 11:19 AM To: c++-sig at python.org Subject: [C++-sig] Need to understand the following Python Program- Help me.. Hi,,, I am very interested about the following Python program, but I am very beginner on Python.. I do not understand this algorithm,, I would appreciated if you give me this algorithm to some other popular programming language. filename="Karp.py" from __future__ import nested_scopes import bisect class _Num: def __init__(self, value, index): self.value = value self.i = index def __lt__(self, other): return self.value < other.value # This implements the Karmarkar-Karp heuristic for partitioning a set # in two, i.e. into two disjoint subsets s.t. their sums are # approximately equal. It produces only one result, in O(N*log N) # time. A remarkable property is that it loves large sets: in # general, the more numbers you feed it, the better it does. class Partition: def __init__(self, nums): self.nums = nums sorted = [_Num(nums[i], i) for i in range(len(nums))] sorted.sort() self.sorted = sorted def run(self): sorted = self.sorted[:] N = len(sorted) connections = [[] for i in range(N)] while len(sorted) > 1: bigger = sorted.pop() smaller = sorted.pop() # Force these into different sets, by "drawing a # line" connecting them. i, j = bigger.i, smaller.i connections[i].append(j) connections[j].append(i) diff = bigger.value - smaller.value assert diff >= 0 bisect.insort(sorted, _Num(diff, i)) # Now sorted contains only 1 element x, and x.value is # the difference between the subsets' sums. # Theorem: The connections matrix represents a spanning tree # on the set of index nodes, and any tree can be 2-colored. # 2-color this one (with "colors" 0 and 1). index2color = [None] * N def color(i, c): if index2color[i] is not None: assert index2color[i] == c return index2color[i] = c for j in connections[i]: color(j, 1-c) color(0, 0) # Partition the indices by their colors. subsets = [[], []] for i in range(N): subsets[index2color[i]].append(i) return subsets N = 50 import math x = [math.sqrt(i) for i in range(1, N+1)] p = Partition(x) s, t = p.run() sum1 = 0L sum2 = 0L for i in s: sum1 += x[i] for i in t: sum2 += x[i] print "Set 1 sum", repr(sum1) print "Set 2 sum", repr(sum2) print "difference", repr(abs(sum1 - sum2)) Thanks for you help... Larry Jaeho Kim Larry Jaeho Kim __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicodemus at esss.com.br Fri Apr 29 23:05:43 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Fri, 29 Apr 2005 19:05:43 -0200 Subject: [C++-sig] Re: Getting the pointer for a member operator In-Reply-To: References: <426D6B14.9040309@esss.com.br> Message-ID: <4272A1A7.8000401@esss.com.br> Vladimir Sukhoy wrote: >>Problem is that this is broken under MSVC.NET 2003. The compiler complains >>with: >> >I tried similar with .NET 2003 compiler - it works, and I cannot reproduce >this error! The full module code is: > > > Thanks for trying it Vladimir! Indeed the above code does work. Since the error message is pretty specific, I assumed the error was on that line. If I tried to post a reproductible test case, as I should, I would learn that the error only shows in the following code: //---------------------------------------- #include using namespace boost::python; namespace operators { struct C { operator int() const { return 1; } operator const char*() { return "C"; } }; } BOOST_PYTHON_MODULE(_ace) { class_< operators::C >("C", init< >()) .def("__int__", &operators::C::operator int) // comment this line .def("__str__", &operators::C::operator const char*) ; } //---------------------------------------- If you comment the marked line, the code compiles fine. Otherwise, it gives this error: op2.cpp(16) : error C2833: 'operator const' is not a recognized operator or type Does anyone know what is going on? From nicodemus at esss.com.br Fri Apr 29 23:09:27 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Fri, 29 Apr 2005 19:09:27 -0200 Subject: [C++-sig] Re: Getting the pointer for a member operator In-Reply-To: References: <426D6B14.9040309@esss.com.br> Message-ID: <4272A287.1080802@esss.com.br> David Abrahams wrote: >Nicodemus writes: > > > >>But without success. Does anybody know how I can fix this? >> >> > >Did you try a typedef? > > typedef char const* string; > > ... > > .def("__str__", &operators::C::operator string) > > > Hi Dave, This would work, but I would like to avoid that for Pyste. I believe its just a matter of syntax, hence easily solvable. I googled around a bit, but without success. Please take a look at my post for Valdimir, I posted a reproductible test case there. Perhaps you can shed some light in the matter? Thanks, Bruno. From dave at boost-consulting.com Sat Apr 30 01:53:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 29 Apr 2005 19:53:54 -0400 Subject: [C++-sig] Re: Need to understand the following Python Program- Help me.. References: <20050429151925.32787.qmail@web51409.mail.yahoo.com> Message-ID: jaeho kim writes: > Hi,,, > > I am very interested about the following Python program, but I am > very beginner on Python.. I do not understand this algorithm,, You're in the wrong forum for pure Python questions; this list is about Python/C++ integration. I suggest you try comp.lang.python (http://groups-beta.google.com/group/comp.lang.python) HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sat Apr 30 01:53:54 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 29 Apr 2005 19:53:54 -0400 Subject: [C++-sig] Re: Need to understand the following Python Program- Help me.. References: <20050429151925.32787.qmail@web51409.mail.yahoo.com> Message-ID: jaeho kim writes: > Hi,,, > > I am very interested about the following Python program, but I am > very beginner on Python.. I do not understand this algorithm,, You're in the wrong forum for pure Python questions; this list is about Python/C++ integration. I suggest you try comp.lang.python (http://groups-beta.google.com/group/comp.lang.python) HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sat Apr 30 03:25:37 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 29 Apr 2005 21:25:37 -0400 Subject: [C++-sig] Re: Getting the pointer for a member operator References: <426D6B14.9040309@esss.com.br> <4272A287.1080802@esss.com.br> Message-ID: Nicodemus writes: > David Abrahams wrote: > >>Nicodemus writes: >> >> >> >>>But without success. Does anybody know how I can fix this? >>> >>> >> >>Did you try a typedef? >> >> typedef char const* string; >> >> ... >> >> .def("__str__", &operators::C::operator string) >> >> >> > > Hi Dave, > > This would work, but I would like to avoid that for Pyste. I don't know why. > I believe its just a matter of syntax, hence easily solvable. I > googled around a bit, but without success. Please take a look at my > post for Valdimir, I posted a reproductible test case there. Perhaps > you can shed some light in the matter? No, I've already supplied one workaround. I don't know why it's not good enough for you. -- Dave Abrahams Boost Consulting www.boost-consulting.com From news4vovan at mail.ru Sat Apr 30 12:36:33 2005 From: news4vovan at mail.ru (Vladimir Sukhoy) Date: Sat, 30 Apr 2005 13:36:33 +0300 Subject: [C++-sig] Re: Re: Getting the pointer for a member operator References: <426D6B14.9040309@esss.com.br> <4272A1A7.8000401@esss.com.br> Message-ID: > Does anyone know what is going on? Well, I dont know, but if you do something like that: BOOST_PYTHON_MODULE(_ace) { class_< operators::C > ref("C", init< >()); ref.def("__int__", &operators::C::operator int); ref.def("__str__", &operators::C::operator const char*); } it compiles successfully. In fact, it looks like lexer problem. From nicodemus at esss.com.br Sat Apr 30 21:52:16 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Sat, 30 Apr 2005 16:52:16 -0300 Subject: [C++-sig] Re: Getting the pointer for a member operator In-Reply-To: References: <426D6B14.9040309@esss.com.br> <4272A287.1080802@esss.com.br> Message-ID: <4273E1F0.8030402@esss.com.br> David Abrahams wrote: >No, I've already supplied one workaround. I don't know why it's not >good enough for you. > Fine, thanks for the help. Regards, Bruno.