From roman.yakovenko at gmail.com Tue Nov 1 06:37:26 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Nov 2005 07:37:26 +0200 Subject: [C++-sig] void* questions\thoughts In-Reply-To: References: <436678A5.28245.56992A94@localhost> Message-ID: <7465b6170510312137i4388ff9aj5cebcc156d70f449@mail.gmail.com> On 10/31/05, David Abrahams wrote: "Niall Douglas" writes: > > Would you integrate a patch adding void * as an opaque type if it > > came with docs, a testcase and ran on vc6? > > I'll go you one better. If you give me everything else -- docs, > tests, and your best guess at a portable solution -- I'll make sure it > works on vc6. The thing is, I suspect 1.33.1 is going to probably > freeze any day now, so the chance of getting it in is evaporating > fast. In fact, only by calling it a regression does it have a hope. > I asked my question in order to get better understanding of void*, beffore I implements support to it in pyplusplus. ( TnFOX makes an extensive use of it. ) Now it seems that nothing should be done in pyplusplus, am I right? Thanks Roman Yakovenko From dave at boost-consulting.com Tue Nov 1 11:54:33 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 05:54:33 -0500 Subject: [C++-sig] void* questions\thoughts References: <436678A5.28245.56992A94@localhost> <7465b6170510312137i4388ff9aj5cebcc156d70f449@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On 10/31/05, David Abrahams wrote: > "Niall Douglas" writes: >> > Would you integrate a patch adding void * as an opaque type if it >> > came with docs, a testcase and ran on vc6? >> >> I'll go you one better. If you give me everything else -- docs, >> tests, and your best guess at a portable solution -- I'll make sure it >> works on vc6. The thing is, I suspect 1.33.1 is going to probably >> freeze any day now, so the chance of getting it in is evaporating >> fast. In fact, only by calling it a regression does it have a hope. >> > > I asked my question in order to get better understanding of void*, > beffore I implements > support to it in pyplusplus. ( TnFOX makes an extensive use of it. ) > > Now it seems that nothing should be done in pyplusplus, am I right? We'll see if Niall comes up with the goods. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Tue Nov 1 12:56:51 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 01 Nov 2005 11:56:51 -0000 Subject: [C++-sig] void* questions\thoughts In-Reply-To: Message-ID: <43675803.787.5A01B0CA@localhost> On 1 Nov 2005 at 5:54, David Abrahams wrote: > > I asked my question in order to get better understanding of void*, > > beffore I implements > > support to it in pyplusplus. ( TnFOX makes an extensive use of it. ) > > > > Now it seems that nothing should be done in pyplusplus, am I right? > > We'll see if Niall comes up with the goods. I will start work on Sunday morning or afternoon and will let you know of my progress. Cheers, Niall From roman.yakovenko at gmail.com Tue Nov 1 15:14:00 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 1 Nov 2005 16:14:00 +0200 Subject: [C++-sig] Pyste & pyplusplus Message-ID: <7465b6170511010614s3a19a572neeac5296e6d0d23c@mail.gmail.com> Hi. I have few question to Pyste users. I am going to create comparison table between Pyste and pyplusplus. What information do you like to find within the table? I can think about: user interface, dependencies, design, features list, performance, generated code. Something else? Also an other question is about backward computability. Do you need pyplusplus to be able to run Pyste scripts? Thanks for help. Roman Yakovenko From dave at boost-consulting.com Tue Nov 1 15:58:48 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 09:58:48 -0500 Subject: [C++-sig] c++ bool to python bool References: <20050902143531.16d4274b.Nicolas.Rougier@loria.fr> Message-ID: "Nicolas P. Rougier" writes: > Hello, > > This is certainly a newbie question but how do I get boost python to > wrap a c++ bool type to a python bool type ? > > Here is what I tried: > > #include > class Boolean { > public: > Boolean (bool v) : value(v) {} > bool value; > }; > > BOOST_PYTHON_MODULE(boolean) { > using namespace boost::python; > class_("Boolean", init () ) > .def_readwrite ("value", &Boolean::value); > } > > But the value property is considered as being an 'int' in python (and > it's important for me to get the right type). I saw that boost python > changelog indicates support for python's bool type but I found no > further documentation. Did I miss something ? It works for me; are you sure your Python actually includes bool support? python -c "print bool" -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Nov 1 16:17:41 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 10:17:41 -0500 Subject: [C++-sig] how to handle bare references with a shared_ptr HeldType References: <200509221932.33058.meine@kogs.informatik.uni-hamburg.de> <200509241329.15613.hans_meine@gmx.net> Message-ID: Hans Meine writes: > Finally, I propose the attached (not-too-related) patch to the documentation, > which basically reorders some HeldType explanations to make their overall > relation more clear. I do appreciate your efforts, but I'm sorry to say that I don't see how that patch clarifies anything. If you can explain that, I might be inclined to apply it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Nov 1 16:23:14 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 10:23:14 -0500 Subject: [C++-sig] GCC version compatibility References: <42CDA654.2080106@v.loewis.de> <20050708072807.GC3581@lap200.cdc.informatik.tu-darmstadt.de> <42CEF948.3010908@v.loewis.de> <20050709102010.GA3836@lap200.cdc.informatik.tu-darmstadt.de> <42D0D215.9000708@v.loewis.de> <20050710125458.GA3587@lap200.cdc.informatik.tu-darmstadt.de> <42D15DB2.3020300@v.loewis.de> <20050716101357.GC3607@lap200.cdc.informatik.tu-darmstadt.de> <20051012120917.GA11058@lap200.cdc.informatik.tu-darmstadt.de> Message-ID: Christoph Ludwig writes: > Hi, > > this is to continue a discussion started back in July by a posting by > Dave Abrahams > regarding the compiler (C vs. C++) used to compile python's main() and to link > the executable. > > > On Sat, Jul 16, 2005 at 12:13:58PM +0200, Christoph Ludwig wrote: >> On Sun, Jul 10, 2005 at 07:41:06PM +0200, "Martin v. L?wis" wrote: >> > Maybe. For Python 2.4, feel free to contribute a more complex test. For >> > Python 2.5, I would prefer if the entire code around ccpython.cc was >> > removed. >> >> I submitted patch #1239112 that implements the test involving two TUs for >> Python 2.4. I plan to work on a more comprehensive patch for Python 2.5 but >> that will take some time. > > > I finally had the spare time to look into this problem again and submitted > patch #1324762. The proposed patch implements the following: Christoph, thanks so much for doing this! Is there anything we should do in the build system to account for your changes? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Nov 1 16:21:24 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 10:21:24 -0500 Subject: [C++-sig] how to handle bare references with ashared_ptrHeldType References: Message-ID: "Gregory Price" writes: > Here's another version of that passage: > > HeldType may be a smart pointer to T. In this case > Boost.Python will allow Python T instances to hold > either a C++ T instance or a C++ HeldType instance. > If HeldType is shared_ptr, a from_python converter > will be registered to accept a Python T instance holding > a C++ T instance and return a shared_ptr instance > with a custom deleter that decrements the Python refcount. > > Is this right? Yes, although I don't think details about refcounts would be appropriate at that point in the docs. > In particular, have I correctly gathered the following > about how Boost.Python works (and about its terminology): > > When a Boost.Python function is called (in Python), > it finds a from_python converter to convert each > of the arguments to a C++ object of the required type. > Similarly, after invoking the underlying C++ function, > a to_python converter is found to convert its return value > into a Python object. Right. > Where in the documentation is this sort of orientation > material found? (Or where should it be?) I dunno. Maybe in the tutorial somewhere? -- Dave Abrahams Boost Consulting www.boost-consulting.com From meine at kogs1.informatik.uni-hamburg.de Tue Nov 1 17:02:23 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Tue, 1 Nov 2005 17:02:23 +0100 Subject: [C++-sig] how to handle bare references with a shared_ptr HeldType In-Reply-To: References: <200509241329.15613.hans_meine@gmx.net> Message-ID: <200511011702.23863.meine@kogs.informatik.uni-hamburg.de> On Tuesday 01 November 2005 16:17, David Abrahams wrote: > I do appreciate your efforts, but I'm sorry to say that I don't see > how that patch clarifies anything. If you can explain that, I might > be inclined to apply it. I guess that it does not make things clearer for you, since you know what it explains and you have no difficulties in following the explanations; for me it makes things clearer simply because all items begin with "if/when ", so I get a faster impression of what cases there are and whether the whole table is of interest for me. Ciao, / / /--/ / / ANS From cludwig at cdc.informatik.tu-darmstadt.de Tue Nov 1 17:15:34 2005 From: cludwig at cdc.informatik.tu-darmstadt.de (Christoph Ludwig) Date: Tue, 1 Nov 2005 17:15:34 +0100 Subject: [C++-sig] GCC version compatibility In-Reply-To: References: <20050708072807.GC3581@lap200.cdc.informatik.tu-darmstadt.de> <42CEF948.3010908@v.loewis.de> <20050709102010.GA3836@lap200.cdc.informatik.tu-darmstadt.de> <42D0D215.9000708@v.loewis.de> <20050710125458.GA3587@lap200.cdc.informatik.tu-darmstadt.de> <42D15DB2.3020300@v.loewis.de> <20050716101357.GC3607@lap200.cdc.informatik.tu-darmstadt.de> <20051012120917.GA11058@lap200.cdc.informatik.tu-darmstadt.de> Message-ID: <20051101161534.GC8657@lap200.cdc.informatik.tu-darmstadt.de> On Tue, Nov 01, 2005 at 10:23:14AM -0500, David Abrahams wrote: > Christoph Ludwig writes: > > I finally had the spare time to look into this problem again and submitted > > patch #1324762. The proposed patch implements the following: > > > > Christoph, thanks so much for doing this! You are welcome. It was pretty straight forward once I realized how the C++ compiler is communicated from configure to distutils. But the patch has not been applied to Python's CVS yet; I don't know how the Python developers think about it. > Is there anything we should > do in the build system to account for your changes? > You mean in Boost.Build? I don't think so. My patches affect how you configure Python itself and, by default, Python's main is now compiled and linked with the C compiler. But AFAICT that does not change how you need to build C++ extension modules. Regards Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html From dave at boost-consulting.com Tue Nov 1 17:23:20 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 11:23:20 -0500 Subject: [C++-sig] GCC version compatibility In-Reply-To: <20051101161534.GC8657@lap200.cdc.informatik.tu-darmstadt.de> (Christoph Ludwig's message of "Tue, 1 Nov 2005 17:15:34 +0100") References: <20050708072807.GC3581@lap200.cdc.informatik.tu-darmstadt.de> <42CEF948.3010908@v.loewis.de> <20050709102010.GA3836@lap200.cdc.informatik.tu-darmstadt.de> <42D0D215.9000708@v.loewis.de> <20050710125458.GA3587@lap200.cdc.informatik.tu-darmstadt.de> <42D15DB2.3020300@v.loewis.de> <20050716101357.GC3607@lap200.cdc.informatik.tu-darmstadt.de> <20051012120917.GA11058@lap200.cdc.informatik.tu-darmstadt.de> <20051101161534.GC8657@lap200.cdc.informatik.tu-darmstadt.de> Message-ID: Christoph Ludwig writes: > On Tue, Nov 01, 2005 at 10:23:14AM -0500, David Abrahams wrote: >> Christoph Ludwig writes: >> > I finally had the spare time to look into this problem again and submitted >> > patch #1324762. The proposed patch implements the following: >> >> >> >> Christoph, thanks so much for doing this! > > You are welcome. It was pretty straight forward once I realized how the C++ > compiler is communicated from configure to distutils. But the patch has not > been applied to Python's CVS yet; I don't know how the Python developers think > about it. Hmm, maybe I should post encouraging someone to look at this. >> Is there anything we should >> do in the build system to account for your changes? >> > > You mean in Boost.Build? I don't think so. My patches affect how you configure > Python itself and, by default, Python's main is now compiled and linked with > the C compiler. But AFAICT that does not change how you need to build C++ > extension modules. OK, thanks again. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Nov 1 17:28:23 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 11:28:23 -0500 Subject: [C++-sig] how to handle bare references with a shared_ptr HeldType References: <200509241329.15613.hans_meine@gmx.net> <200511011702.23863.meine@kogs.informatik.uni-hamburg.de> Message-ID: Hans Meine writes: > On Tuesday 01 November 2005 16:17, David Abrahams wrote: >> I do appreciate your efforts, but I'm sorry to say that I don't see >> how that patch clarifies anything. If you can explain that, I might >> be inclined to apply it. > > I guess that it does not make things clearer for you, since you know > what it explains and you have no difficulties in following the > explanations; for me it makes things clearer simply because all > items begin with "if/when ", so I get a faster impression > of what cases there are and whether the whole table is of interest > for me. Hmm. Can we get someone to agree with Hans? The problem is that of course Hans' version is clearer to him, just like mine is perfectly fine for me. For reference, his patch is attached to http://article.gmane.org/gmane.comp.python.c++/8631 -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Nov 1 17:52:44 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 01 Nov 2005 11:52:44 -0500 Subject: [C++-sig] how to handle bare references with a shared_ptr HeldType References: <200509221932.33058.meine@kogs.informatik.uni-hamburg.de> <200509241329.15613.hans_meine@gmx.net> Message-ID: Hans Meine writes: > On Saturday 24 September 2005 00:38, David Abrahams wrote: >> Hans Meine writes: >> > OTOH, if you use return_internal_reference, BP should know that creating >> > a shared_ptr with a refcount of 1 is evil.. is that really what it does? >> >> No, that's not what it does. When you use return_internal_reference >> it creates a Python object holding the C++ object with a raw pointer. >> Isn't that in the documentation? > > That's how I understood it in the past, but I am not experienced with > customized HeldTypes, and Gregory seemed to be concerned that it does so: > >> > On Thursday 22 September 2005 16:37, Gregory Price wrote: >> >> Is there a way to tell Boost.Python not to make a shared_ptr >> >> for this return value -- to override the HeldType just for this >> >> function's return value? > > So the answer really is: Use return_internal_reference. > > Concerning the documentation question: The class_ documentation reads > "Heldtype [...] Specifies the type which is actually embedded in a Python > object wrapping a T instance. More details below." > So I would've assumed that every T wrapper actually contains a smart_ptr if > that's the HeldType. One could then make more clear that it's not always the > case. Clarified, thanks. -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Tue Nov 1 23:00:25 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 1 Nov 2005 14:00:25 -0800 (PST) Subject: [C++-sig] new stl_iterator doesn't work with EDGs Message-ID: <20051101220025.20032.qmail@web31505.mail.mud.yahoo.com> The output below is an error message produced by Tru64 cxx 7.1, which is based on EDG 304. I got a similar error message with EDG 238 under IRIX. I guess it probably is the same for all EDGs in between. I'd be happy to try out ideas for fixes. We have EDG 238, 245 and 304 available. Cheers, Ralf BTW: I just checked in a patch to reorder the includes. Due to Python requirements, boost/python includes have to appear before any system includes. cxx -o boost/libs/python/test/stl_iterator.o -c -std strict_ansi -msg_display_number -msg_disable 186,450,1115,1133 -tlocal -DBOOST_DISABLE_THREADS -DNDEBUG -O2 -fast -DBOOST_PYTHON_MAX_BASES=2 -I/net/legless/scratch1/rwgk/hot/boost -I/usr/local_cci/Python-2.4.2_ticker_simple/include/python2.4 /net/legless/scratch1/rwgk/hot/boost/libs/python/test/stl_iterator.cpp cxx: Error: /net/legless/scratch1/rwgk/hot/boost/boost/iterator/iterator_facade.hpp, line 535: #265-D function "boost::python::stl_input_iterator::equal [with ValueT=int]" is inaccessible detected during: instantiation of "bool boost::iterator_core_access::equal(const Facade1 &, const Facade2 &, mpl_::true_) [with Facade1=boost::python::stl_input_iterator, Facade2=boost::python::stl_input_iterator]" at line 838 instantiation of "boost::detail::enable_if_interoperable::type>::type boost::operator!=(const boost::iterator_facade &, const boost::iterator_facade &) [with Derived1=boost::python::stl_input_iterator, V1=int, TC1=std::input_iterator_tag, R1=int, D1=std::ptrdiff_t={signed long}, Derived2=boost::python::stl_input_iterator, V2=int, TC2=std::input_iterator_tag, R2=int, D2=std::ptrdiff_t={signed long}]" at line 845 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list" instantiation of "void std::list::_RWinsert_interval_dispatch(std::list::iterator, InputIterator, InputIterator, std::input_iterator_tag) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" at line 156 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list.cc" instantiation of "void std::list::insert(std::list::iterator, InputIterator, InputIterator) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" return f1.equal(f2); --------------------^ cxx: Error: /net/legless/scratch1/rwgk/hot/boost/boost/iterator/iterator_facade.hpp, line 517: #265-D function "boost::python::stl_input_iterator::dereference [with ValueT=int]" is inaccessible detected during: instantiation of "Facade::reference boost::iterator_core_access::dereference(const Facade &) [with Facade=boost::python::stl_input_iterator]" at line 635 instantiation of "boost::iterator_facade::reference boost::iterator_facade::operator*() const [with Derived=boost::python::stl_input_iterator, Value=int, CategoryOrTraversal=std::input_iterator_tag, Reference=int, Difference=std::ptrdiff_t={signed long}]" at line 846 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list" instantiation of "void std::list::_RWinsert_interval_dispatch(std::list::iterator, InputIterator, InputIterator, std::input_iterator_tag) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" at line 156 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list.cc" instantiation of "void std::list::insert(std::list::iterator, InputIterator, InputIterator) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" return f.dereference(); -------------------^ cxx: Error: /net/legless/scratch1/rwgk/hot/boost/boost/iterator/iterator_facade.hpp, line 523: #265-D function "boost::python::stl_input_iterator::increment [with ValueT=int]" is inaccessible detected during: instantiation of "void boost::iterator_core_access::increment(Facade &) [with Facade=boost::python::stl_input_iterator]" at line 665 instantiation of "Derived &boost::iterator_facade::operator++() [with Derived=boost::python::stl_input_iterator, Value=int, CategoryOrTraversal=std::input_iterator_tag, Reference=int, Difference=std::ptrdiff_t={signed long}]" at line 848 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list" instantiation of "void std::list::_RWinsert_interval_dispatch(std::list::iterator, InputIterator, InputIterator, std::input_iterator_tag) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" at line 156 of "/usr/lib/cmplrs/cxx/V7.1-006/include/cxx/list.cc" instantiation of "void std::list::insert(std::list::iterator, InputIterator, InputIterator) [with T=int, Allocator=std::allocator, InputIterator=boost::python::stl_input_iterator]" f.increment(); ------------^ cxx: Info: 3 errors detected in the compilation of "/net/legless/scratch1/rwgk/hot/boost/libs/python/test/stl_iterator.cpp". scons: *** [boost/libs/python/test/stl_iterator.o] Error 1 __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From eric at boost-consulting.com Wed Nov 2 19:03:51 2005 From: eric at boost-consulting.com (Eric Niebler) Date: Wed, 02 Nov 2005 10:03:51 -0800 Subject: [C++-sig] new stl_iterator doesn't work with EDGs In-Reply-To: <20051101220025.20032.qmail@web31505.mail.mud.yahoo.com> References: <20051101220025.20032.qmail@web31505.mail.mud.yahoo.com> Message-ID: <4368FF87.8060409@boost-consulting.com> Ralf W. Grosse-Kunstleve wrote: > cxx: Error: > /net/legless/scratch1/rwgk/hot/boost/boost/iterator/iterator_facade.hpp, line > 535: #265-D > function > "boost::python::stl_input_iterator::equal [with ValueT=int]" > is inaccessible > detected during: > instantiation of "bool boost::iterator_core_access::equal Odd. EDG doesn't seem to be picking up the friend declaration. The attached version works around the problem. Can you give it a shot? > BTW: I just checked in a patch to reorder the includes. Due to Python > requirements, boost/python includes have to appear before any system includes. Thanks. -- Eric Niebler Boost Consulting www.boost-consulting.com -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: stl_iterator.hpp URL: From rwgk at yahoo.com Wed Nov 2 23:21:07 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 2 Nov 2005 14:21:07 -0800 (PST) Subject: [C++-sig] new stl_iterator doesn't work with EDGs In-Reply-To: <4368FF87.8060409@boost-consulting.com> Message-ID: <20051102222107.33128.qmail@web31502.mail.mud.yahoo.com> --- Eric Niebler wrote: > Odd. EDG doesn't seem to be picking up the friend declaration. The > attached version works around the problem. Can you give it a shot? > ... > #if !BOOST_WORKAROUND(__EDG_VERSION__, BOOST_TESTED_AT(304)) > private: > friend class iterator_core_access; > #endif Your patch works (tested with EDG 304) but this one works (tested with EDG 238 and 304), too: Index: stl_iterator.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/python/stl_iterator.hpp,v retrieving revision 1.1 diff -r1.1 stl_iterator.hpp 39c39 < friend class iterator_core_access; --- > friend class boost::iterator_core_access; With the original version of stl_iterator.hpp EDG seems to "think" the friend is boost::python::iterator_core_access (which doesn't exist). Is this a bug in the EDG name lookup? Or is it a non-standard feature that it works with g++? Let me know which patch you prefer and I'll test it on more platforms. Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From amohr at pixar.com Wed Nov 2 23:22:23 2005 From: amohr at pixar.com (Alex Mohr) Date: Wed, 02 Nov 2005 14:22:23 -0800 Subject: [C++-sig] Something like boost::any ... custom conversions? Message-ID: <43693C1F.9090101@pixar.com> Suppose I have a type that is much like boost::any. If I have an instance of this in python (say holding an int), then I want to be able to call wrapped c++ code which takes arguments of held types (say foo(int)) by passing my any-like object directly. That is, I want my any-like object to try to convert to the desired c++ type by checking to see if it's holding the desired c++ type. Can anyone point me in a general direction of where to look to do this sort of thing? I've tried looking at the conversion information in the reference manual, and I've looked at container_conversions.h, but I have to admit that things are still muddy for me. The lvalue_from_pytype stuff seems like it might be in the right direction, but I don't really want lvalue conversion. I only care about passing these things as rvalues. Thanks a lot, Alex From eric at boost-consulting.com Wed Nov 2 23:48:27 2005 From: eric at boost-consulting.com (Eric Niebler) Date: Wed, 02 Nov 2005 14:48:27 -0800 Subject: [C++-sig] new stl_iterator doesn't work with EDGs In-Reply-To: <20051102222107.33128.qmail@web31502.mail.mud.yahoo.com> References: <4368FF87.8060409@boost-consulting.com> <20051102222107.33128.qmail@web31502.mail.mud.yahoo.com> Message-ID: <4369423B.8000906@boost-consulting.com> Ralf W. Grosse-Kunstleve wrote: > > Your patch works (tested with EDG 304) but this one works (tested with EDG 238 > and 304), too: > > Index: stl_iterator.hpp > =================================================================== > RCS file: /cvsroot/boost/boost/boost/python/stl_iterator.hpp,v > retrieving revision 1.1 > diff -r1.1 stl_iterator.hpp > 39c39 > < friend class iterator_core_access; > --- > > > friend class boost::iterator_core_access; > Better. This is the right fix, so I went ahead and committed it. I tested it with VC7.1 and gcc, and the regression tests will tell us if any other compilers have a problem with it. Thanks! -- Eric Niebler Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Thu Nov 3 02:38:23 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 02 Nov 2005 20:38:23 -0500 Subject: [C++-sig] Something like boost::any ... custom conversions? In-Reply-To: <43693C1F.9090101@pixar.com> References: <43693C1F.9090101@pixar.com> Message-ID: <43696A0F.6060102@sympatico.ca> Alex Mohr wrote: > Suppose I have a type that is much like boost::any. If I have an > instance of this in python (say holding an int), then I want to be able > to call wrapped c++ code which takes arguments of held types (say > foo(int)) by passing my any-like object directly. Out of curiosity, why don't you just let python do the type dispatching for you ? It seems strange to work in a hybrid python/C++ world and then use a tool that adds dynamic (i.e. runtime-) type dispatching to C++. Thanks, Stefan From tmaisnam at yahoo.com Thu Nov 3 03:40:26 2005 From: tmaisnam at yahoo.com (T Maisnam) Date: Wed, 2 Nov 2005 18:40:26 -0800 (PST) Subject: [C++-sig] help on quant finance code Message-ID: <20051103024027.75182.qmail@web30809.mail.mud.yahoo.com> Hi Holger, I am currently studying a financial engineering course in sydney and am from an IT background. I came across your name in one of the bulletin boards. Can you please send me any links to financial program codes that I can look into. I am never worked in finance and i want to see some code implementation besides the abstract math concepts that I am studying now. cheers, Tony Maisnam __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From raghavendra_hpt at yahoo.co.in Thu Nov 3 14:39:12 2005 From: raghavendra_hpt at yahoo.co.in (Raghavendra K . B) Date: Thu, 3 Nov 2005 13:39:12 +0000 (GMT) Subject: [C++-sig] Warning: non-POD class type passed through Message-ID: <20051103133912.89821.qmail@web8401.mail.in.yahoo.com> Hi All, I am getting following Warning : non-POD class type passed through buf.Format(KKeyCreateTime, rate, noKeyPairCreations, keyCreateTime); ^ If any one has faced this problem , please let me know the solution .I badly need solution for this Thanks in Advance. Raghavendra K.B --------------------------------- Enjoy this Diwali with Y! India Click here -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Thu Nov 3 15:13:48 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 03 Nov 2005 09:13:48 -0500 Subject: [C++-sig] Warning: non-POD class type passed through References: <20051103133912.89821.qmail@web8401.mail.in.yahoo.com> Message-ID: "Raghavendra K . B" writes: > Hi All, > > I am getting following Warning : non-POD class type passed through > > buf.Format(KKeyCreateTime, rate, noKeyPairCreations, keyCreateTime); > ^ > > If any one has faced this problem , please let me know the solution .I badly need solution for this You are asking in the wrong list. Followups should go to comp.lang.c++ or comp.lang.c++.moderated. To save you some trouble, Format almost certainly has a ... in its signature. If you pass a non-POD (http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html) through ... you get undefined behavior. Don't do that. -- Dave Abrahams Boost Consulting www.boost-consulting.com From amohr at pixar.com Thu Nov 3 18:45:44 2005 From: amohr at pixar.com (Alex Mohr) Date: Thu, 03 Nov 2005 09:45:44 -0800 Subject: [C++-sig] Something like boost::any ... custom conversions? In-Reply-To: <43696A0F.6060102@sympatico.ca> References: <43693C1F.9090101@pixar.com> <43696A0F.6060102@sympatico.ca> Message-ID: <436A4CC8.40805@pixar.com> Thanks for your reply. > Out of curiosity, why don't you just let python do the type dispatching > for you ? It seems strange to work in a hybrid python/C++ world and then > use a tool that adds dynamic (i.e. runtime-) type dispatching to C++. I can see where you're coming from, but unfortunately this is in a large existing C++ system which was not originally written to be used with Python and already makes use this any-like object. Alex From Oystein.Lekang at idi.ntnu.no Thu Nov 3 19:17:44 2005 From: Oystein.Lekang at idi.ntnu.no (=?ISO-8859-1?Q?=D8ystein_Lekang?=) Date: Thu, 3 Nov 2005 19:17:44 +0100 (MET) Subject: [C++-sig] using boost.python to have access to boost::dynamic_bitset Message-ID: I am in need of somthing like dynamic_bitset in python, and am currently searching for the best way to achieve this. So Im wondering how much work it would be to use boost.python to make dynamic_bitset accessable to python, and whether it can be done by me. (myself not beeing to versed in c++) I've had a brief look at swig, pyrex and pyinline, but thought that since boost.python also is a part of boost, it might be the way to go. -- ?ystein Lekang From dave at boost-consulting.com Thu Nov 3 23:35:00 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 03 Nov 2005 17:35:00 -0500 Subject: [C++-sig] Something like boost::any ... custom conversions? References: <43693C1F.9090101@pixar.com> Message-ID: Alex Mohr writes: > Suppose I have a type that is much like boost::any. If I have an > instance of this in python (say holding an int), then I want to be able > to call wrapped c++ code which takes arguments of held types (say > foo(int)) by passing my any-like object directly. > > That is, I want my any-like object to try to convert to the desired c++ > type by checking to see if it's holding the desired c++ type. You can do it for specific held types just by registering the appropriate from_python converters: > Can anyone point me in a general direction of where to look to do this > sort of thing? I've tried looking at the conversion information in the > reference manual, and I've looked at container_conversions.h, but I have > to admit that things are still muddy for me. > > The lvalue_from_pytype stuff seems like it might be in the right > direction, but I don't really want lvalue conversion. I only care about > passing these things as rvalues. In general, if you can get ahold of an lvalue, it's usually a good idea to do it anyway. The bigger issue is that you don't have the Python type object associated with your any-like class at compile time. But yeah, it's in the right direction. I suggest you look at http://news.gmane.org/find-root.php?message_id=%3c1026918209.17167.2.camel%40hunsmac.mit.edu%3e and follow the links there. It's probably about time to document this stuff for real and pull it out of the detail:: namespaces. -- Dave Abrahams Boost Consulting www.boost-consulting.com From cramissor at yahoo.com Thu Nov 3 23:39:19 2005 From: cramissor at yahoo.com (Marc Rossi) Date: Thu, 3 Nov 2005 14:39:19 -0800 (PST) Subject: [C++-sig] boost package import error Message-ID: <20051103223919.49677.qmail@web34109.mail.mud.yahoo.com> I'm running into import problems trying to create a package that is similiar in layout to the one in the docs described here: http://www.boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.creating_packages So my package layout is as follows: xyzzy/ __init__.py research/ __init__.py _research.so stats.pyc My __init__.py file contains 2 lines: from stats import * from _research import * With the directory containing 'xyzzy' on my PYTHONPATH, the following occurs: Python 2.4.2 (#2, Nov 3 2005, 11:35:03) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import frfr.research Traceback (most recent call last): File "", line 1, in ? File "xyzzy/research/__init__.py", line 2, in ? from _research import * ImportError: No module named _research Running python with the -vv switch shows python does indeed look at _research.so but does not load it. However if I put the directory containing _research.so on my PYTHONPATH the following command is successful: >>> import _research Thanks for any help you can offer, Marc __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From seefeld at sympatico.ca Fri Nov 4 00:07:24 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Thu, 03 Nov 2005 18:07:24 -0500 Subject: [C++-sig] boost package import error In-Reply-To: <20051103223919.49677.qmail@web34109.mail.mud.yahoo.com> References: <20051103223919.49677.qmail@web34109.mail.mud.yahoo.com> Message-ID: <436A982C.1030905@sympatico.ca> Marc Rossi wrote: > Running python with the -vv switch shows python does > indeed look at _research.so but does not load it. > > However if I put the directory containing _research.so > on my PYTHONPATH the following command is successful: > > >>> import _research This is not related to C++ (or boost): As described in http://docs.python.org/ref/import.html, the '*' wildcard only applies to public names, if not specified otherwise via __all__. Rename '_research' to 'research_impl' (for example) and you will be fine. Regards, Stefan From ricardokirkner at gmail.com Fri Nov 4 18:39:07 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Fri, 4 Nov 2005 14:39:07 -0300 Subject: [C++-sig] boost.python error Message-ID: <5e44108d0511040939s504be27bv2ac8b98feecfe4c8@mail.gmail.com> Hi: I just wrote a small wrapper for a class, using pyste (boost.python). I am just trying to figure out how this works, before I get on wrapping the whole real library. I did run pyste succesfully (which generated a .cpp file) , and I also did run bjam successfully, which generated the .so library. However, when I try to import the newly generated library in python, I get the following error: ImportError: ./opal.so: undefined symbol: _ZTVN5boost6python7objects21py_function_impl_baseE Can anyone tell me why is this error being produced (and how to fix it)? Does this mean that the .so didnt linked to the boost library? Thank you, Ricardo Kirkner -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Fri Nov 4 20:15:55 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 4 Nov 2005 11:15:55 -0800 (PST) Subject: [C++-sig] boost.python error In-Reply-To: <5e44108d0511040939s504be27bv2ac8b98feecfe4c8@mail.gmail.com> Message-ID: <20051104191555.47536.qmail@web31513.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > ImportError: ./opal.so: undefined symbol: > _ZTVN5boost6python7objects21py_function_impl_baseE > > Can anyone tell me why is this error being produced (and how to fix it)? > Does this mean that the .so didnt linked to the boost library? I suspect that you have to point LD_LIBRARY_PATH to the directory with with libboost_python.so. I don't use bjam, therefore I cannot help with the details, but maybe you can get it going via "find . -name libboost_python.so" and then "setenv LD_LIBRARY_PATH :$LD_LIBRARY_PATH". HTH, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From ricardokirkner at gmail.com Fri Nov 4 21:50:20 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Fri, 4 Nov 2005 17:50:20 -0300 Subject: [C++-sig] boost.python error In-Reply-To: <20051104191555.47536.qmail@web31513.mail.mud.yahoo.com> References: <5e44108d0511040939s504be27bv2ac8b98feecfe4c8@mail.gmail.com> <20051104191555.47536.qmail@web31513.mail.mud.yahoo.com> Message-ID: <5e44108d0511041250j1dd19632j687ddebc91a35ca1@mail.gmail.com> Hi: could you please share with me some example of how you compile/link your libraries, not using bjam? Maybe that will help me out. Thank you, Ricardo Kirkner On 11/4/05, Ralf W. Grosse-Kunstleve wrote: > > --- Ricardo Kirkner wrote: > > ImportError: ./opal.so: undefined symbol: > > _ZTVN5boost6python7objects21py_function_impl_baseE > > > > Can anyone tell me why is this error being produced (and how to fix it)? > > Does this mean that the .so didnt linked to the boost library? > > I suspect that you have to point LD_LIBRARY_PATH to the directory with > with > libboost_python.so. I don't use bjam, therefore I cannot help with the > details, > but maybe you can get it going via "find . -name libboost_python.so" and > then > "setenv LD_LIBRARY_PATH :$LD_LIBRARY_PATH". > > HTH, > Ralf > > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Sat Nov 5 00:11:37 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 4 Nov 2005 15:11:37 -0800 (PST) Subject: [C++-sig] boost.python error In-Reply-To: <5e44108d0511041250j1dd19632j687ddebc91a35ca1@mail.gmail.com> Message-ID: <20051104231137.86525.qmail@web31512.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > could you please share with me some example of how you compile/link your > libraries, not using bjam? Look at any of the "build_log" pages here to see the actual commands: http://cci.lbl.gov/cctbx_build/show_error_summary.cgi?build_tag=2005_10_21_1046 Everything is open source: http://cci.lbl.gov/cctbx_build/ To get the commands for your particular machine, get a source bundle, run "perl cctbx_bundle.selfx", copy and paste the commands for compiling and linking libboost_python.so (near the beginning) and throw away the rest (rm -rf). Note that you will always have to worry about LD_LIBRARY_PATH; this is how you tell dlopen (used by Python) where to find your custom shared libraries. Cheers, Ralf __________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs From dave at boost-consulting.com Sat Nov 5 13:33:28 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 05 Nov 2005 07:33:28 -0500 Subject: [C++-sig] boost.python error References: <5e44108d0511041250j1dd19632j687ddebc91a35ca1@mail.gmail.com> <20051104231137.86525.qmail@web31512.mail.mud.yahoo.com> Message-ID: "Ralf W. Grosse-Kunstleve" writes: > Note that you will always have to worry about LD_LIBRARY_PATH; this is how you > tell dlopen (used by Python) where to find your custom shared libraries. Unless you use bjam to run Python as a test case. It sets up LD_LIBRARY_PATH for you ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Sat Nov 5 15:30:49 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sat, 05 Nov 2005 09:30:49 -0500 Subject: [C++-sig] boost.python error In-Reply-To: <20051104231137.86525.qmail@web31512.mail.mud.yahoo.com> References: <20051104231137.86525.qmail@web31512.mail.mud.yahoo.com> Message-ID: <436CC219.6020304@sympatico.ca> Ralf W. Grosse-Kunstleve wrote: > Note that you will always have to worry about LD_LIBRARY_PATH; this is how you > tell dlopen (used by Python) where to find your custom shared libraries. just a little nit-picking: The library being searched for here (libboost_python.so) isn't dlopened, only the depending python module is. Python has its own way to figure out from where to load its modules, and that doesn't involve LD_LIBRARY_PATH. However, if those modules depend on other DSOs, the dynamic loader (ld.so on my system) kicks in, and *then* you may need LD_LIBRARY_PATH to add non-default places to look in. Regards, Stefan From ricardokirkner at gmail.com Sun Nov 6 03:44:09 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Sat, 5 Nov 2005 23:44:09 -0300 Subject: [C++-sig] boost.python error In-Reply-To: <436CC219.6020304@sympatico.ca> References: <20051104231137.86525.qmail@web31512.mail.mud.yahoo.com> <436CC219.6020304@sympatico.ca> Message-ID: <5e44108d0511051844rdaafb4fxe4e6fd971056afb8@mail.gmail.com> Hi: I tried to compile my module several ways. I managed to get pass the undefined symbol error, by compiling the module directly (not using bjam). However, now I am getting the following error: ImportError: dynamic module does not define init function (initopal) I believe that the problem with bjam might be a Jamfile/Jamrules configuration error. (I could correctly compile the hello world example) Please, if anyone knows a little more about this, give me a hand :-) Regards, Ricardo Kirkner On 11/5/05, Stefan Seefeld wrote: > Ralf W. Grosse-Kunstleve wrote: > > > Note that you will always have to worry about LD_LIBRARY_PATH; this is how you > > tell dlopen (used by Python) where to find your custom shared libraries. > > just a little nit-picking: > > The library being searched for here (libboost_python.so) isn't dlopened, only > the depending python module is. Python has its own way to figure out from > where to load its modules, and that doesn't involve LD_LIBRARY_PATH. > However, if those modules depend on other DSOs, the dynamic loader (ld.so > on my system) kicks in, and *then* you may need LD_LIBRARY_PATH to add > non-default places to look in. > > Regards, > Stefan > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From rwgk at yahoo.com Sun Nov 6 16:50:49 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 6 Nov 2005 07:50:49 -0800 (PST) Subject: [C++-sig] boost.python error In-Reply-To: <436CC219.6020304@sympatico.ca> Message-ID: <20051106155049.18362.qmail@web31502.mail.mud.yahoo.com> --- Stefan Seefeld wrote: > Ralf W. Grosse-Kunstleve wrote: > > > Note that you will always have to worry about LD_LIBRARY_PATH; this is how > you > > tell dlopen (used by Python) where to find your custom shared libraries. > > just a little nit-picking: > > The library being searched for here (libboost_python.so) isn't dlopened, only > the depending python module is. Python has its own way to figure out from > where to load its modules, and that doesn't involve LD_LIBRARY_PATH. > However, if those modules depend on other DSOs, the dynamic loader (ld.so > on my system) kicks in, and *then* you may need LD_LIBRARY_PATH to add > non-default places to look in. Thanks for the clarification; I agree. I noticed that the Linux man page for dlopen mentions LD_LIBRARY_PATH right at the beginning. Therefore I was thinking the dynamic loader uses dlopen eventually, just like Python does. Or is there another mechanism? Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From rwgk at yahoo.com Sun Nov 6 16:54:21 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 6 Nov 2005 07:54:21 -0800 (PST) Subject: [C++-sig] boost.python error In-Reply-To: <5e44108d0511051844rdaafb4fxe4e6fd971056afb8@mail.gmail.com> Message-ID: <20051106155421.96407.qmail@web31509.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > ImportError: dynamic module does not define init function (initopal) If you want to enable "import opal" you need to write BOOST_PYTHON_MODULE(opal) in your Boost.Python extension. Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From ricardokirkner at gmail.com Sun Nov 6 17:13:15 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Sun, 6 Nov 2005 13:13:15 -0300 Subject: [C++-sig] boost.python error In-Reply-To: <20051106155421.96407.qmail@web31509.mail.mud.yahoo.com> References: <5e44108d0511051844rdaafb4fxe4e6fd971056afb8@mail.gmail.com> <20051106155421.96407.qmail@web31509.mail.mud.yahoo.com> Message-ID: <5e44108d0511060813w1e42b226jab48e624bf79442a@mail.gmail.com> I give you the code returned by pyste (which I am using to build the wrapper). Maybe you can tell me whats wrong with it. I also include the original source (OpalMath.h) I also post my Jamfile and Jamrules files. When I build with bjam, I get an error telling me ImportError: ./OpalMath.so: undefined symbol: _ZTVN5boost6python7objects21py_function_impl_baseE when I build using g++ directly I get the error ImportError: dynamic module does not define init function (initOpalMath) To build using g++ I use g++ -c -Wall -fPIC -I/usr/include/boost -I/usr/include/python2.3 -Isrc -o OpalMath.o OpalMath.cpp g++ -shared -fPIC -Wl --no-undefined --warn-once -L/usr/lib -lpython2.3 -lboost_python -DBOOST_PYTHON_DYNAMIC_MODULE -o OpalMath.so OpalMath.o I hope this info can tell you something about why I am not succeeding in building this very small wrapper... Thanks in advance Ricardo Kirkner On 11/6/05, Ralf W. Grosse-Kunstleve wrote: > --- Ricardo Kirkner wrote: > > ImportError: dynamic module does not define init function (initopal) > > If you want to enable "import opal" you need to write > > BOOST_PYTHON_MODULE(opal) > > in your Boost.Python extension. > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -------------- next part -------------- A non-text attachment was scrubbed... Name: OpalMath.cpp Type: text/x-c++src Size: 934 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: OpalMath.h Type: text/x-chdr Size: 3640 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Jamfile Type: application/octet-stream Size: 421 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Jamrules Type: application/octet-stream Size: 1580 bytes Desc: not available URL: From seefeld at sympatico.ca Sun Nov 6 17:12:10 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Sun, 06 Nov 2005 11:12:10 -0500 Subject: [C++-sig] boost.python error In-Reply-To: <20051106155049.18362.qmail@web31502.mail.mud.yahoo.com> References: <20051106155049.18362.qmail@web31502.mail.mud.yahoo.com> Message-ID: <436E2B5A.5080708@sympatico.ca> Ralf W. Grosse-Kunstleve wrote: > Thanks for the clarification; I agree. > I noticed that the Linux man page for dlopen mentions LD_LIBRARY_PATH right at > the beginning. Therefore I was thinking the dynamic loader uses dlopen > eventually, just like Python does. Or is there another mechanism? dlopen uses LD_LIBRARY_PATH only if the path doesn't contain '/', which is not the case for python imports (i.e. python's import function makes sure the path either starts with '/' or './'). As for ld.so using dlopen, I was under the impression that dlopen is merely a means for users (i.e. developers) to access the dynamic loader, not the other way around. I'm not familiar enough with the details concerning symbol resolution and initialization, which may be different for both cases. Regards, Stefan From s_sourceforge at nedprod.com Sun Nov 6 18:55:28 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 06 Nov 2005 17:55:28 -0000 Subject: [C++-sig] Patch implementing void * support Message-ID: <436E4390.14657.548C6F9@localhost> The enclosed patch adds void * support to Boost.Python by making void an opaque type. Code that uses void * "just works" with this patch with no further effort required. Also enclosed is a testcase and the docs have been modified. Ran full testsuite on msvc7.1 and msvc6 - everything works. I don't have GCC to hand ATM, but apart from maybe a missing typename specifier I can't see anything which would fault. Cheers, Niall -------------- next part -------------- Only in boost: bin diff -aur boost_1_33_0/boost/python/converter/registered.hpp boost/boost/python/converter/registered.hpp --- boost_1_33_0/boost/python/converter/registered.hpp 2005-05-18 02:34:36.000000000 +0100 +++ boost/boost/python/converter/registered.hpp 2005-11-06 15:18:14.000000000 +0000 @@ -77,15 +77,35 @@ } template - registration const& - registry_lookup(T&(*)()) + inline registration const& + registry_lookup2(T&(*)()) { detail::register_shared_ptr1((T*)0); return registry::lookup(type_id()); } template - registration const& registered_base::converters = detail::registry_lookup((T(*)())0); + inline registration const& + registry_lookup1() + { + return registry_lookup2((T(*)())0); + } + + template <> + inline registration const& +#ifdef BOOST_NO_CV_VOID_SPECIALIZATIONS + registry_lookup1() +#else + registry_lookup1() +#endif + { + detail::register_shared_ptr1((void*)0); + return registry::lookup(type_id()); + } + + template + registration const& registered_base::converters = detail::registry_lookup1(); + } }}} // namespace boost::python::converter diff -aur boost_1_33_0/boost/python/lvalue_from_pytype.hpp boost/boost/python/lvalue_from_pytype.hpp --- boost_1_33_0/boost/python/lvalue_from_pytype.hpp 2004-08-20 12:09:16.000000000 +0100 +++ boost/boost/python/lvalue_from_pytype.hpp 2005-11-06 16:53:14.000000000 +0000 @@ -15,12 +15,25 @@ namespace detail { + struct voidptrholder; // Used to indicate a void * is being extracted + + template + inline type_info extractor_type_id2() + { + return type_id(); + } + template <> + inline type_info extractor_type_id2() + { + return type_id(); + } + // Given a pointer-to-function of 1 parameter returning a reference // type, return the type_id of the function's return type. template inline type_info extractor_type_id(T&(*)(U)) { - return type_id(); + return extractor_type_id2(); } // A function generator whose static execute() function is an lvalue diff -aur boost_1_33_0/boost/python/opaque_pointer_converter.hpp boost/boost/python/opaque_pointer_converter.hpp --- boost_1_33_0/boost/python/opaque_pointer_converter.hpp 2004-08-20 12:09:16.000000000 +0100 +++ boost/boost/python/opaque_pointer_converter.hpp 2005-11-06 17:16:25.000000000 +0000 @@ -15,6 +15,7 @@ # include # include # include +# include // opaque_pointer_converter -- // @@ -54,6 +55,15 @@ , detail::opaque_pointer_converter_requires_a_pointer_type >::type ptr_type; + typedef typename ::boost::remove_pointer::type noptr_type; + typedef typename mpl::if_c< + ::boost::is_void::value, + detail::voidptrholder, + typename noptr_type + >::type fixed_type; + + typedef typename ::boost::add_reference::type ref_type; + private: struct instance; @@ -84,10 +94,10 @@ return (result); } - static typename ::boost::remove_pointer::type& + static typename ref_type execute(instance &p_) { - return *p_.x; + return *(typename fixed_type *) p_.x; } private: @@ -132,4 +142,8 @@ } \ }} # endif + +// Declare void as an opaque type for automatic void * usage +BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void) + # endif // OPAQUE_POINTER_CONVERTER_HPP_ Only in boost/libs/python/build/VisualStudio: Debug Only in boost_1_33_0/libs/python/build/VisualStudio: boost_python.dsp Only in boost_1_33_0/libs/python/build/VisualStudio: boost_python.dsw Only in boost/libs/python/build/VisualStudio: boost_python.ncb Only in boost/libs/python/build/VisualStudio: boost_python.sln Only in boost/libs/python/build/VisualStudio: boost_python.suo Only in boost/libs/python/build/VisualStudio: boost_python.vcproj Only in boost/libs/python/build: bin-stage diff -aur boost_1_33_0/libs/python/doc/v2/faq.html boost/libs/python/doc/v2/faq.html --- boost_1_33_0/libs/python/doc/v2/faq.html 2004-11-28 03:54:58.000000000 +0000 +++ boost/libs/python/doc/v2/faq.html 2005-11-06 17:17:31.000000000 +0000 @@ -67,8 +67,6 @@ >error C2064: term does not evaluate to a function taking 2 arguments -
How do I handle void * conversion?
-
How can I automatically convert my custom string type to and from a Python string?
@@ -694,29 +692,6 @@

(The bug has been reported to Microsoft.)


-

How do I handle void * conversion?

- Niall Douglas provides these notes:

- For several reasons Boost.Python does not support void * as - an argument or as a return value. However, it is possible to wrap - functions with void * arguments or return values using - thin wrappers and the opaque pointer facility. E.g.: -

// Declare the following in each translation unit
-struct void_ {};
-BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(void_);
-
-void *foo(int par1, void *par2);
-
-void_ *foo_wrapper(int par1, void_ *par2)
-{
-    return (void_ *) foo(par1, par2);
-}
-...
-BOOST_PYTHON_MODULE(bar)
-{
-    def("foo", &foo_wrapper);
-}
- -

How can I automatically convert my custom string type to and from a Python string?

Ralf W. Grosse-Kunstleve provides these diff -aur boost_1_33_0/libs/python/test/Jamfile boost/libs/python/test/Jamfile --- boost_1_33_0/libs/python/test/Jamfile 2005-07-07 15:00:30.000000000 +0100 +++ boost/libs/python/test/Jamfile 2005-11-06 15:28:29.000000000 +0000 @@ -151,6 +151,7 @@ [ bpl-test extract ] [ bpl-test opaque ] +[ bpl-test voidptr ] [ bpl-test pickle1 ] [ bpl-test pickle2 ] Only in boost/libs/python/test: bjam.exe Only in boost/libs/python/test: hello.txt Only in boost/libs/python/test: voidptr Only in boost/libs/python/test: voidptr.cpp Only in boost/libs/python/test: voidptr.py Only in boost/tools/build/jam_src: bin.ntx86 Only in boost/tools/build/jam_src: bootstrap Only in boost/tools/build/jam_src: builtins.obj Only in boost/tools/build/jam_src: class.obj Only in boost/tools/build/jam_src: command.obj Only in boost/tools/build/jam_src: compile.obj Only in boost/tools/build/jam_src: execnt.obj Only in boost/tools/build/jam_src: execunix.obj Only in boost/tools/build/jam_src: execvms.obj Only in boost/tools/build/jam_src: expand.obj Only in boost/tools/build/jam_src: filent.obj Only in boost/tools/build/jam_src: fileos2.obj Only in boost/tools/build/jam_src: filesys.obj Only in boost/tools/build/jam_src: fileunix.obj Only in boost/tools/build/jam_src: filevms.obj Only in boost/tools/build/jam_src: glob.obj Only in boost/tools/build/jam_src: hash.obj Only in boost/tools/build/jam_src: hcache.obj Only in boost/tools/build/jam_src: hdrmacro.obj Only in boost/tools/build/jam_src: headers.obj Only in boost/tools/build/jam_src: jam.obj Only in boost/tools/build/jam_src: jambase.obj Only in boost/tools/build/jam_src: jamgram.obj Only in boost/tools/build/jam_src: lists.obj Only in boost/tools/build/jam_src: make.obj Only in boost/tools/build/jam_src: make1.obj Only in boost/tools/build/jam_src: modules.obj Only in boost/tools/build/jam_src: native.obj Only in boost/tools/build/jam_src: newstr.obj Only in boost/tools/build/jam_src: option.obj Only in boost/tools/build/jam_src: order.obj Only in boost/tools/build/jam_src: parse.obj Only in boost/tools/build/jam_src: path.obj Only in boost/tools/build/jam_src: pathunix.obj Only in boost/tools/build/jam_src: pathvms.obj Only in boost/tools/build/jam_src: property-set.obj Only in boost/tools/build/jam_src: pwd.obj Only in boost/tools/build/jam_src: regex.obj Only in boost/tools/build/jam_src: regexp.obj Only in boost/tools/build/jam_src: rules.obj Only in boost/tools/build/jam_src: scan.obj Only in boost/tools/build/jam_src: search.obj Only in boost/tools/build/jam_src: sequence.obj Only in boost/tools/build/jam_src: set.obj Only in boost/tools/build/jam_src: strings.obj Only in boost/tools/build/jam_src: subst.obj Only in boost/tools/build/jam_src: timestamp.obj Only in boost/tools/build/jam_src: variable.obj Only in boost/tools/build/jam_src: vc70.pdb Only in boost/tools/build/jam_src: w32_getreg.obj -------------- next part -------------- # Copyright Niall Douglas 2005. # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) """ >>> from voidptr_ext import * Check for correct conversion >>> use(get()) Check that None is converted to a NULL void pointer >>> useany(get()) 1 >>> useany(None) 0 Check that we don't lose type information by converting NULL opaque pointers to None >>> assert getnull() is None >>> useany(getnull()) 0 Check that there is no conversion from integers ... >>> try: use(0) ... except TypeError: pass ... else: print 'expected a TypeError' ... and from strings to opaque objects >>> try: use("") ... except TypeError: pass ... else: print 'expected a TypeError' """ def run(args = None): import sys import doctest if args is not None: sys.argv = args return doctest.testmod(sys.modules.get(__name__)) if __name__ == '__main__': print "running..." import sys status = run()[0] if (status == 0): print "Done." sys.exit(status) -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: voidptr.cpp Date: 6 Nov 2005, 17:38 Size: 892 bytes. Type: Program-source -------------- next part -------------- A non-text attachment was scrubbed... Name: voidptr.cpp Type: application/octet-stream Size: 892 bytes Desc: not available URL: From roman.yakovenko at gmail.com Mon Nov 7 06:11:19 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 7 Nov 2005 07:11:19 +0200 Subject: [C++-sig] Patch implementing void * support In-Reply-To: <436E4390.14657.548C6F9@localhost> References: <436E4390.14657.548C6F9@localhost> Message-ID: <7465b6170511062111v3efd7dd4v49d5bb3ff5c72b75@mail.gmail.com> On 11/6/05, Niall Douglas wrote: > The enclosed patch adds void * support to Boost.Python by making void > an opaque type. Code that uses void * "just works" with this patch > with no further effort required. Cool. I will try your patch today on GCC. Roman Yakovenko From meine at kogs1.informatik.uni-hamburg.de Mon Nov 7 14:06:30 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Mon, 7 Nov 2005 14:06:30 +0100 Subject: [C++-sig] boost.python error In-Reply-To: <5e44108d0511060813w1e42b226jab48e624bf79442a@mail.gmail.com> References: <5e44108d0511051844rdaafb4fxe4e6fd971056afb8@mail.gmail.com> <20051106155421.96407.qmail@web31509.mail.mud.yahoo.com> <5e44108d0511060813w1e42b226jab48e624bf79442a@mail.gmail.com> Message-ID: <200511071406.30853.meine@kogs.informatik.uni-hamburg.de> On Sunday 06 November 2005 17:13, Ricardo Kirkner wrote: > ImportError: dynamic module does not define init function (initOpalMath) You could check for that in the source (remember the mentioned macro) and in the .o file with "nm". > To build using g++ I use > > g++ -c -Wall -fPIC -I/usr/include/boost -I/usr/include/python2.3 -Isrc > -o OpalMath.o OpalMath.cpp > g++ -shared -fPIC -Wl --no-undefined --warn-once -L/usr/lib > -lpython2.3 -lboost_python -DBOOST_PYTHON_DYNAMIC_MODULE -o > OpalMath.so OpalMath.o Note that -DBOOST_PYTHON_DYNAMIC_MODULE defines a preprocessor symbol. That's a noop when linking. (Probably you wanted to add that within the "g++ -c ..." line.) -- Ciao, / / /--/ / / ANS From ricardokirkner at gmail.com Mon Nov 7 14:28:00 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Mon, 7 Nov 2005 10:28:00 -0300 Subject: [C++-sig] boost.python error In-Reply-To: <200511071406.30853.meine@kogs.informatik.uni-hamburg.de> References: <5e44108d0511051844rdaafb4fxe4e6fd971056afb8@mail.gmail.com> <20051106155421.96407.qmail@web31509.mail.mud.yahoo.com> <5e44108d0511060813w1e42b226jab48e624bf79442a@mail.gmail.com> <200511071406.30853.meine@kogs.informatik.uni-hamburg.de> Message-ID: <5e44108d0511070528w31feecb2nbd0e34d79e14a0ca@mail.gmail.com> Thank you all for your help.. I finally managed to get the library to compile. I don't quite know what it was, but I am sure it had something to do with Jamfile/Jamrules/boost-build.jam files configuration. Regards, Ricardo Kirkner On 11/7/05, Hans Meine wrote: > On Sunday 06 November 2005 17:13, Ricardo Kirkner wrote: > > ImportError: dynamic module does not define init function (initOpalMath) > You could check for that in the source (remember the mentioned macro) and in > the .o file with "nm". > > > To build using g++ I use > > > > g++ -c -Wall -fPIC -I/usr/include/boost -I/usr/include/python2.3 -Isrc > > -o OpalMath.o OpalMath.cpp > > g++ -shared -fPIC -Wl --no-undefined --warn-once -L/usr/lib > > -lpython2.3 -lboost_python -DBOOST_PYTHON_DYNAMIC_MODULE -o > > OpalMath.so OpalMath.o > Note that -DBOOST_PYTHON_DYNAMIC_MODULE defines a preprocessor symbol. That's > a noop when linking. (Probably you wanted to add that within the "g++ > -c ..." line.) > > -- > Ciao, / / > /--/ > / / ANS > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From ricardokirkner at gmail.com Mon Nov 7 14:30:43 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Mon, 7 Nov 2005 10:30:43 -0300 Subject: [C++-sig] call policies Message-ID: <5e44108d0511070530r34b4b022wc25cb52f6b3dac3a@mail.gmail.com> Hello again: this time I have a question regarding call policies. I have a function that returns a double * which actually is an array of doubles. I am required to provide a policy for this functions, however I cannot find out which one would apply here (from how well I understand each posibility). Can anyone please enlighten me? Thank you Ricardo Kirkner From bray at sent.com Mon Nov 7 15:54:25 2005 From: bray at sent.com (Brian Ray) Date: Mon, 7 Nov 2005 08:54:25 -0600 Subject: [C++-sig] Patch implementing void * support In-Reply-To: <436E4390.14657.548C6F9@localhost> References: <436E4390.14657.548C6F9@localhost> Message-ID: <2CCF1296-D7BC-4124-83CB-A9B652919C7F@sent.com> I wish someone can tell me in what cases this is useful. I am sure it *is* helpful but I am trying to imagine another more extensive use case. Or, is this something more useful to Python Boost itself and not users of Python Boost. On Nov 6, 2005, at 11:55 AM, Niall Douglas wrote: > The enclosed patch adds void * support to Boost.Python by making void > an opaque type. Code that uses void * "just works" with this patch > with no further effort required. > > Also enclosed is a testcase and the docs have been modified. > > Ran full testsuite on msvc7.1 and msvc6 - everything works. I don't > have GCC to hand ATM, but apart from maybe a missing typename > specifier I can't see anything which would fault. > > Cheers, > Niall > From s_sourceforge at nedprod.com Mon Nov 7 16:29:37 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 07 Nov 2005 15:29:37 -0000 Subject: [C++-sig] Patch implementing void * support In-Reply-To: <2CCF1296-D7BC-4124-83CB-A9B652919C7F@sent.com> References: <436E4390.14657.548C6F9@localhost> Message-ID: <436F72E1.8296.9E99B51@localhost> On 7 Nov 2005 at 8:54, Brian Ray wrote: > I wish someone can tell me in what cases this is useful. I am sure it > *is* helpful but I am trying to imagine another more extensive use > case. Or, is this something more useful to Python Boost itself and > not users of Python Boost. A lot of GUI toolkit C++ code has message handlers of the form: virtual int Widget::handle(MsgType msg, void *data) ... where MsgType specifies what *data is. For almost all cases, the python bindings will call the C++ implementation and just pass the void * unchanged. Where an override is made, you can write separate little accessor functions to restore type info to data so python can access it. This idiom is especially popular in C code too. Cheers, Niall From etaurel at cells.es Mon Nov 7 18:11:19 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Mon, 07 Nov 2005 18:11:19 +0100 Subject: [C++-sig] Problem using the ptr() function In-Reply-To: Message-ID: <0IPL008KCH3D2Q@cells-s02.cells.es> Hello everybody, As requested by Dave, I have reduced my example as far as I can. Sorry for the very, very long response time.... I recall my problem: I have a C++ class called Device. In the Python world, I create a class inheriting from this C++ class (called MyDevice) and I create one python method in this new class which is called "a_new_method". This python method receives one parameter of a type for which I have installed Boost converter. The type is called "MyStrArray" The Python code creates one instance of the MyDevice class and call its C++ method called "execute_device_method". This C++ method callback the new "a_new_method" python code with the help of the Boost call_method() function. If, when calling back the new Python method, I am using the Boost ptr() Function, I have a run-time error: Traceback (most recent call last): File "main.py", line 13, in ? d.execute_device_method() TypeError: No Python class registered for C++ class std::vector > If I don't use the Boost ptr() function, everything works fine and the "a_new_method" Python method is executed correctly. I have added to this file two files which are the Python and the C++ code. Thank's for your help Sincerely Emmanuel Taurel (etaurel at cells.es) -------------- next part -------------- A non-text attachment was scrubbed... Name: main.py Type: application/octet-stream Size: 299 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: py_ds.cpp Type: application/octet-stream Size: 3036 bytes Desc: not available URL: From rwgk at yahoo.com Mon Nov 7 20:11:16 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 7 Nov 2005 11:11:16 -0800 (PST) Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511070530r34b4b022wc25cb52f6b3dac3a@mail.gmail.com> Message-ID: <20051107191116.45638.qmail@web31515.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > this time I have a question regarding call policies. I have a function > that returns a double * which actually is an array of doubles. > > I am required to provide a policy for this functions, however I cannot > find out which one would apply here (from how well I understand each > posibility). > > Can anyone please enlighten me? I don't think call policies will help you here. More fundamental considerations are required. The Python scripting level is supposed to provide a safe environment. According to the Python spirit is should be impossible to provoke a segmentation fault from the scripting level, or to access uninitialized memory. Of course you can undermine this via C/C++, but Boost.Python doesn't support grossly unsafe practices. In your particular case, you have to tell Python the size of the double* array, and you have to take care all elements are initialized. There are several alternatives to achieve this. A simple alternative is to write a "thin wrapper" which copies the double* array to a new Python list of floats. It goes like this (all untested): your.hpp: class yours { public: unsigned number_of_values() const; double* values() const; }; Boost.Python extension: #include boost::python::list values_as_list(yours const& self) { boost::python::list result; for(unsigned i=0;i("yours") def("values", values_as_list) ; } Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From ricardokirkner at gmail.com Tue Nov 8 00:06:19 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Mon, 7 Nov 2005 20:06:19 -0300 Subject: [C++-sig] call policies In-Reply-To: <20051107191116.45638.qmail@web31515.mail.mud.yahoo.com> References: <5e44108d0511070530r34b4b022wc25cb52f6b3dac3a@mail.gmail.com> <20051107191116.45638.qmail@web31515.mail.mud.yahoo.com> Message-ID: <5e44108d0511071506r55a4cdeav2aad8bf13f8e9a8d@mail.gmail.com> Hi: Thank you, this worked... however, pyste is still complaining about my method (the one that returned a double*) returns a pointer, and has no policy defined -- although this method now uses a wrapper which does not return a pointer but a tuple... On the other hand, I have read that the operator << should be replaced by the str function. However, 1. pyste isn't doing it.. (might be a thing with pyste) 2. when I replace that operator with .def( str( self ) ), compilation fails with no matching function for call to 'boost::python::api::object::visit(boost::python::class_&) const' any ideas? thank you On 11/7/05, Ralf W. Grosse-Kunstleve wrote: > --- Ricardo Kirkner wrote: > > > this time I have a question regarding call policies. I have a function > > that returns a double * which actually is an array of doubles. > > > > I am required to provide a policy for this functions, however I cannot > > find out which one would apply here (from how well I understand each > > posibility). > > > > Can anyone please enlighten me? > > I don't think call policies will help you here. More fundamental > considerations are required. > > The Python scripting level is supposed to provide a safe environment. > According to the Python spirit is should be impossible to provoke a > segmentation fault from the scripting level, or to access uninitialized > memory. Of course you can undermine this via C/C++, but Boost.Python > doesn't support grossly unsafe practices. > > In your particular case, you have to tell Python the size of the > double* array, and you have to take care all elements are initialized. > There are several alternatives to achieve this. A simple alternative is > to write a "thin wrapper" which copies the double* array to a new > Python list of floats. It goes like this (all untested): > > your.hpp: > > class yours > { > public: > unsigned > number_of_values() const; > > double* > values() const; > }; > > Boost.Python extension: > > #include > > boost::python::list > values_as_list(yours const& self) > { > boost::python::list result; > for(unsigned i=0;i result.append(self.values()[i]); > } > return result; > } > > BOOST_PYTHON_MODULE(your_choice) > { > using namespace boost::python; > class_("yours") > def("values", values_as_list) > ; > } > > Cheers, > Ralf > > > > > __________________________________ > Yahoo! FareChase: Search multiple travel sites in one click. > http://farechase.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From rwgk at yahoo.com Tue Nov 8 00:37:36 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 7 Nov 2005 15:37:36 -0800 (PST) Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511071506r55a4cdeav2aad8bf13f8e9a8d@mail.gmail.com> Message-ID: <20051107233736.37268.qmail@web31503.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > Thank you, this worked... however, pyste is still complaining about my > method (the one that returned a double*) returns a pointer, and has no > policy defined -- although this method now uses a wrapper which does > not return a pointer but a tuple... > > On the other hand, I have read that the operator << should be replaced > by the str function. However, > > 1. pyste isn't doing it.. (might be a thing with pyste) Sorry, I never used Pyste. I hope someone else can help. > 2. when I replace that operator with .def( str( self ) ), compilation fails > with IIRC some compilers have issues with the name lookup. You could try .def(self_ns::str(self)) I believe. __________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs From ricardokirkner at gmail.com Tue Nov 8 00:42:21 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Mon, 7 Nov 2005 20:42:21 -0300 Subject: [C++-sig] call policies In-Reply-To: <20051107233736.37268.qmail@web31503.mail.mud.yahoo.com> References: <5e44108d0511071506r55a4cdeav2aad8bf13f8e9a8d@mail.gmail.com> <20051107233736.37268.qmail@web31503.mail.mud.yahoo.com> Message-ID: <5e44108d0511071542o55ab6776pab8cb479b99cb84a@mail.gmail.com> Ok... thanks for the reply... How will boost.python figure out that the corresponding method for .def(self_ns::str(self)) should be (for example) std::ostream& operator<< (in the c++ code) ? I will try to skip pyste, and code directly in boost, as to have less code levels to deal with... ricardo On 11/7/05, Ralf W. Grosse-Kunstleve wrote: > --- Ricardo Kirkner wrote: > > Thank you, this worked... however, pyste is still complaining about my > > method (the one that returned a double*) returns a pointer, and has no > > policy defined -- although this method now uses a wrapper which does > > not return a pointer but a tuple... > > > > On the other hand, I have read that the operator << should be replaced > > by the str function. However, > > > > 1. pyste isn't doing it.. (might be a thing with pyste) > > Sorry, I never used Pyste. I hope someone else can help. > > > 2. when I replace that operator with .def( str( self ) ), compilation fails > > with > > IIRC some compilers have issues with the name lookup. You could try > > .def(self_ns::str(self)) > > I believe. > > > > > __________________________________ > Start your day with Yahoo! - Make it your home page! > http://www.yahoo.com/r/hs > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From rwgk at yahoo.com Tue Nov 8 03:45:51 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 7 Nov 2005 18:45:51 -0800 (PST) Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511071542o55ab6776pab8cb479b99cb84a@mail.gmail.com> Message-ID: <20051108024551.62158.qmail@web31509.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > Ok... thanks for the reply... > > How will boost.python figure out that the corresponding method for > > .def(self_ns::str(self)) > > should be (for example) > > std::ostream& operator<< (in the c++ code) Only David knows *how* Boost.Python does it, but this test proves that it does exactly what you are looking for: boost/libs/python/test/operators.cpp Note that you can always provide your own custom string method via .def("__str__", &yours::method) or .def("__str__", another_thin_wrapper) BTW: I find the test source code extremely useful as a reference. It is worth spending 30 minutes looking through all the .cpp files to get an overview. Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From dave at boost-consulting.com Tue Nov 8 15:53:37 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 08 Nov 2005 09:53:37 -0500 Subject: [C++-sig] Problem using the ptr() function References: <0IPL008KCH3D2Q@cells-s02.cells.es> Message-ID: Emmanuel Taurel writes: > As requested by Dave, I have reduced my example as far as I can. Your example can still be reduced a *lot* further. You could start by taking out all the use of std::cout. I doubt you need a loop in a_new_method. Next time, please remove *all* unnecessary code and get it down to the bare minimum required to exhibit the behavior you don't expect. Anyway, this time the problem is pretty straightforward. Basically, ptr(p) will only work when the type of *p has been exported with class_. In that case, Python ends up with an object of some Python type corresponding to the C++ type of *p, containing a copy of p. You are converting MyStrArray to and from a Python list instead of wrapping it as a class. There's no way that modifications to a regular python list will be able to automatically affect *p. In the past it has been requested that we support "write-back" converters that let you convert, e.g., a MyStrArray to a Python list, and then, when the call completes, convert the list back to a MyStrArray. We don't support that yet, but since you're actually doing the call from Python to C++, it's easy for you to fake it: python::list send_msa_(send_msa); // convert to a Python list call_method(dev_ptr->m_self.get(),"a_new_method", send_msa_); send_msa = extract(send_msa_); BTW, something about class DeviceWrap : public Device, public wrapper { public: DeviceWrap(PyObject *self):Device(),m_self(borrowed(self)) {}; DeviceWrap(PyObject *self, const string &na):Device(na),m_self(borrowed(self)) {}; handle<> m_self; }; looks very wrong. If you're using wrapper<...> there's almost never cause for an initial self argument, and storing it in a handle<> is almost guaranteed to result in a leak or a reference counting error. I would unconditionally drop handle<>, and either try to make wrapper work by itself, using get_override to get ahold of a_new_method, or drop wrapper store a raw PyObject* in lieu of handle<>, specializing has_back_reference for Device. In this case the latter approach might be better, by allowing you to get rid of the artificial derived class and the dangerous downcast. Good luck, Dave -- Dave Abrahams Boost Consulting www.boost-consulting.com From skottmckay at gmail.com Tue Nov 8 17:09:25 2005 From: skottmckay at gmail.com (Scott McKay) Date: Tue, 8 Nov 2005 09:09:25 -0700 Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511071506r55a4cdeav2aad8bf13f8e9a8d@mail.gmail.com> References: <5e44108d0511070530r34b4b022wc25cb52f6b3dac3a@mail.gmail.com> <20051107191116.45638.qmail@web31515.mail.mud.yahoo.com> <5e44108d0511071506r55a4cdeav2aad8bf13f8e9a8d@mail.gmail.com> Message-ID: <51d017870511080809wbf485aj3f502200ac959ad8@mail.gmail.com> Pyste doesn't appear to cancel warnings if wrappers are defined for a method. It should be simple to add though. S On 11/7/05, Ricardo Kirkner wrote: > > Hi: > > Thank you, this worked... however, pyste is still complaining about my > method (the one that returned a double*) returns a pointer, and has no > policy defined -- although this method now uses a wrapper which does > not return a pointer but a tuple... > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ricardokirkner at gmail.com Tue Nov 8 21:44:38 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Tue, 8 Nov 2005 17:44:38 -0300 Subject: [C++-sig] call policies In-Reply-To: <20051108024551.62158.qmail@web31509.mail.mud.yahoo.com> References: <5e44108d0511071542o55ab6776pab8cb479b99cb84a@mail.gmail.com> <20051108024551.62158.qmail@web31509.mail.mud.yahoo.com> Message-ID: <5e44108d0511081244w1e151676n1607d67c0239f353@mail.gmail.com> Hi: I am doing great now... I am coding right in boost.python, without recurring to pyste. However I have found a situation that makes me doubt. Being mData defined as real mData[3]; and having these methods as member functions of a class inline real * getData() { return mData; } inline const real * getData()const { return mData; } How should I wrap them? I was thinking of defining a wrapper that would return a list built from the elements of mData, but... how would using a wrapper cope with this overloaded function? Should I only define it once, and ignore the second override? (for example the one with const?) I have looked at the tutorial, but the part of overriding only handles the case where the function itself doesn't return a pointer or a reference... More or less the same thing is happening with the [] operator... the code (c++) would return a real & while I could return a real, and using a wrapper, but this would prevent the returned item from being modified (as opposed to the c++ version, where a reference can be used to modify the object). Any thoughts are appreciated... Thanks again... Ricardo pd: I promise that as I continue to learn this wrapping_up_a_library thing I will stop making basic questions and start making really interesting ones :-P On 11/7/05, Ralf W. Grosse-Kunstleve wrote: > --- Ricardo Kirkner wrote: > > > Ok... thanks for the reply... > > > > How will boost.python figure out that the corresponding method for > > > > .def(self_ns::str(self)) > > > > should be (for example) > > > > std::ostream& operator<< (in the c++ code) > > Only David knows *how* Boost.Python does it, but this test proves that it does > exactly what you are looking for: > > boost/libs/python/test/operators.cpp > > Note that you can always provide your own custom string method via > > .def("__str__", &yours::method) > > or > > .def("__str__", another_thin_wrapper) > > BTW: I find the test source code extremely useful as a reference. It is worth > spending 30 minutes looking through all the .cpp files to get an overview. > > Cheers, > Ralf > > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From rwgk at yahoo.com Tue Nov 8 23:15:16 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 8 Nov 2005 14:15:16 -0800 (PST) Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511081244w1e151676n1607d67c0239f353@mail.gmail.com> Message-ID: <20051108221516.38309.qmail@web31507.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > real mData[3]; > > and having these methods as member functions of a class > > inline real * getData() > { > return mData; > } > > inline const real * getData()const > { > return mData; > } > > How should I wrap them? I was thinking of defining a wrapper that > would return a list built from the elements of mData, but... how would > using a wrapper cope with this overloaded function? Should I only > define it once, and ignore the second override? (for example the one > with const?) You can keep your C++ interface if you want. C++ const-ness doesn't map directly to Python, but it isn't in the way. Your idea with the wrapper returning a new list seems reasonable: boost::python::list getData_as_list(T const& self) { //... } then .def("getData", getData_as_list) This will use the "const" overload. The Python interface cannot map directly to the C++ interface when it comes to resetting data. I'd try this: void setData_from_list(T& self, boost::python::list const& new_data) { double* d = self.getData(); // will use the non-const overload //... loop over new_data, d[i] = boost::python::extract(new_data[i])(); } I am not sure about the exact details; I hope you can work it out. Finally: def("setData", setData_from_list) BTW: your problems remind me of my early days with Boost.Python. I moved away from using raw pointers entirely. Instead I wrote a library with a family of useful array types, including types with and without dynamic memory allocation. A general purpose "container_conversions.h" header provides mappings from C++ arrays to Python tuples and vice versa. The mappings for a C++ type can be defined with just one line. See the Boost.Python FAQ for some pointers. If you want to use Boost.Python at a larger scale you may want to know about this approach. Sadly I never found the time to document my libraries, but I think the code you'll find is still useful as a source of ideas, and I'll answer questions here. Cheers, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From ricardokirkner at gmail.com Wed Nov 9 13:49:18 2005 From: ricardokirkner at gmail.com (Ricardo Kirkner) Date: Wed, 9 Nov 2005 09:49:18 -0300 Subject: [C++-sig] call policies In-Reply-To: <20051108221516.38309.qmail@web31507.mail.mud.yahoo.com> References: <5e44108d0511081244w1e151676n1607d67c0239f353@mail.gmail.com> <20051108221516.38309.qmail@web31507.mail.mud.yahoo.com> Message-ID: <5e44108d0511090449t4bcdbc24q35db09ece1d979e5@mail.gmail.com> Thank you for the info... I will look further into it to see if I can use it to solve my problems.. Unfortunately I cannot avoid using pointers, since I am trying to write a wrapper for a library (which wasn't written by me) which uses them.... I will have to manage to get around them somehow... Thanks for the suggestions, though... Regards, Ricardo Kirkner On 11/8/05, Ralf W. Grosse-Kunstleve wrote: > --- Ricardo Kirkner wrote: > > real mData[3]; > > > > and having these methods as member functions of a class > > > > inline real * getData() > > { > > return mData; > > } > > > > inline const real * getData()const > > { > > return mData; > > } > > > > How should I wrap them? I was thinking of defining a wrapper that > > would return a list built from the elements of mData, but... how would > > using a wrapper cope with this overloaded function? Should I only > > define it once, and ignore the second override? (for example the one > > with const?) > > You can keep your C++ interface if you want. C++ const-ness doesn't map > directly to Python, but it isn't in the way. > > Your idea with the wrapper returning a new list seems reasonable: > > boost::python::list > getData_as_list(T const& self) > { > //... > } > > then > > .def("getData", getData_as_list) > > This will use the "const" overload. > > The Python interface cannot map directly to the C++ interface when it comes > to resetting data. I'd try this: > > void > setData_from_list(T& self, boost::python::list const& new_data) > { > double* d = self.getData(); // will use the non-const overload > //... loop over new_data, d[i] = > boost::python::extract(new_data[i])(); > } > > I am not sure about the exact details; I hope you can work it out. > Finally: > > def("setData", setData_from_list) > > BTW: your problems remind me of my early days with Boost.Python. I moved away > from using raw pointers entirely. Instead I wrote a library with a family of > useful array types, including types with and without dynamic memory allocation. > A general purpose "container_conversions.h" header provides mappings from C++ > arrays to Python tuples and vice versa. The mappings for a C++ type can be > defined with just one line. See the Boost.Python FAQ for some pointers. If you > want to use Boost.Python at a larger scale you may want to know about this > approach. Sadly I never found the time to document my libraries, but I think > the code you'll find is still useful as a source of ideas, and I'll answer > questions here. > > Cheers, > Ralf > > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From rwgk at yahoo.com Wed Nov 9 18:47:27 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 9 Nov 2005 09:47:27 -0800 (PST) Subject: [C++-sig] call policies In-Reply-To: <5e44108d0511090449t4bcdbc24q35db09ece1d979e5@mail.gmail.com> Message-ID: <20051109174727.43001.qmail@web31501.mail.mud.yahoo.com> --- Ricardo Kirkner wrote: > Thank you for the info... I will look further into it to see if I can > use it to solve my problems.. > > Unfortunately I cannot avoid using pointers, since I am trying to > write a wrapper for a library (which wasn't written by me) which uses > them.... > > I will have to manage to get around them somehow... In case the library you are wrapping is large: A few months ago I did some quick experiments (http://cci.lbl.gov/gltbx/) wrapping the OpenGL library, which uses raw pointers extensively. I wrote a simple Python script that generates the Boost.Python bindings. This is supported by some hand-written wrapper support code. I found this combination to be a very workable approach. Cheers, Ralf __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com From amohr at pixar.com Thu Nov 10 03:12:21 2005 From: amohr at pixar.com (Alex Mohr) Date: Wed, 09 Nov 2005 18:12:21 -0800 Subject: [C++-sig] enum strangeness... Message-ID: <4372AC85.8070107@pixar.com> I noticed something today about enums that I've wrapped with boost.python. Here's a small example. #include using namespace boost::python; struct Foo { enum Bar { Baz }; }; BOOST_PYTHON_MODULE(Mod) { scope fooScope = class_("Foo"); enum_("Bar") .value("Baz", Foo::Baz) .export_values(); } Now, in Python I can refer to the enum values by saying 'Mod.Foo.Baz' which is what I expect, but it seems to recur in a strange way. I can also say: Mod.Foo.Baz.Baz.Baz.Baz.Baz.Baz.Baz.Baz for as long as I like. This seems relatively benign, but strange. Is it expected? Thanks, Alex From korg at csse.unimelb.edu.au Thu Nov 10 06:14:11 2005 From: korg at csse.unimelb.edu.au (Cameron Blackwood) Date: Thu, 10 Nov 2005 16:14:11 +1100 Subject: [C++-sig] solaris-intel sem deadlock problem... :-/ Message-ID: <20051110051412.61AF96D617@kali.csse.unimelb.edu.au> Any ideas welcome.... im out of ideas... :-/ Summary: -------- Semaphore code hangs when call from python module but not from c/c++. Kill me.... Background: ----------- Im working on a project that is a massive c++ piece of work that offers a single object with useful methods. Its a database and it starts 3 other processes and uses shared memory and semaphores to communicate. The c++ interface is the native one (and its kinda big at ~30M exe's). It has a C interface which creates a dll of c++ code and wraps each method call in a c function. There is a python wrapper that wraps the c interface. Problem: -------- It works fine on linux-x86, linux-ppc64 and we're just porting to solaris-intel but we've hit a problem. The startup code for the c++ object does some forking and sem work and it works fine for the c++ interface and the c interface but the python module just hangs in the semaphore semget loop. The constructor for the c++ object is called with the same args via python or c (so its not that). We're using boost for config passing, but the boost config values are the same. The c interface works (so its not the dll). It could be some solaris issue, but the c and c++ interfaces work fine... its just the python interface. :-( Has anyone got _any_ ideas? Or am I in for a big chunk of c++ semaphore debugging? :-/ (refer to kill me comment ;) cheers, cam -- / Cameron Blackwood korg at csse.unimelb.edu.au \ [ Research Programmer, Aditi Project +61 3 8344-1315 ] \ University of Melbourne / From ndbecker2 at gmail.com Thu Nov 10 14:14:17 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 10 Nov 2005 08:14:17 -0500 Subject: [C++-sig] swig? Message-ID: I noticed that recent versions of swig have quite significantly advanced the support for c++. I wonder if anyone has experience they can share, regarding a comparison of boost::python with a recent swig. I have been using boost::python for some time, but am interested in considering swig, because in my present environment, it would be easier for me to deploy code using swig. From dave at boost-consulting.com Thu Nov 10 17:08:49 2005 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 10 Nov 2005 11:08:49 -0500 Subject: [C++-sig] enum strangeness... References: <4372AC85.8070107@pixar.com> Message-ID: Alex Mohr writes: > I noticed something today about enums that I've wrapped with > boost.python. Here's a small example. > > #include > using namespace boost::python; > > struct Foo { > enum Bar { Baz }; > }; > > BOOST_PYTHON_MODULE(Mod) { > scope fooScope = class_("Foo"); > enum_("Bar") > .value("Baz", Foo::Baz) > .export_values(); > } > > Now, in Python I can refer to the enum values by saying 'Mod.Foo.Baz' > which is what I expect, but it seems to recur in a strange way. I can > also say: > > Mod.Foo.Baz.Baz.Baz.Baz.Baz.Baz.Baz.Baz > > for as long as I like. This seems relatively benign, but strange. Is > it expected? Yeah, an enum's values are members of its type, and you can access members of a type through its instances. No surprise. -- Dave Abrahams Boost Consulting www.boost-consulting.com From petrucio at hoplon.com Thu Nov 10 18:48:23 2005 From: petrucio at hoplon.com (Petrucio) Date: Thu, 10 Nov 2005 14:48:23 -0300 Subject: [C++-sig] swig? In-Reply-To: References: Message-ID: <6.0.2.0.1.20051110143038.01b44cf8@mail.hoplon.com> In my experience, the compilation of the SWIG wrappers is much, much faster than compilation of the boost.python wrappers. The source of errors in compilation is also easier to track down, since there's little or no templates used in SWIG wrappers. SWIG is also easier to set up and use, you usually need much less declarations of what you want to export, even less than when using Pyste. It also has a lot of pre-built typemaps that save you a lot of time depending on what you want to export, for instance when dealing with pointer to basic types, SWIG has an easy solution for that in a typemap, in contrast to exporting those using boost.python, wich is not something you look forward to. In the other hand, boost.python is more robust. I lack the memory to give you specific examples, but there's some stupid things that SWIG does that will blow your mind. Boost.python is also more 'purist', in some sense. But since practicality beats purity, I'm more of a SWIG guy. I made a few performance tests, and expected boost.python to be a clear favorite here, but there were not much diference between the two, if I remember correctly. I made a lot of other comparisons between the two, but the results are not in this computer. I'll send them some other day, if I remember to get them. --- Fabio 'Petrucio' Stange - Game Programmer Hoplon Infotainment - www.taikodom.com At 10:14 10/11/2005, you wrote: >I noticed that recent versions of swig have quite significantly advanced the >support for c++. I wonder if anyone has experience they can share, >regarding a comparison of boost::python with a recent swig. > >I have been using boost::python for some time, but am interested in >considering swig, because in my present environment, it would be easier for >me to deploy code using swig. > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From tomas at liquid.se Thu Nov 10 18:05:39 2005 From: tomas at liquid.se (Tomas) Date: Thu, 10 Nov 2005 18:05:39 +0100 Subject: [C++-sig] swig? References: <6.0.2.0.1.20051110143038.01b44cf8@mail.hoplon.com> Message-ID: <001301c5e619$00d7f110$0200a8c0@liquid.se> Is it in SWIG possible to have smart pointers that holds objects of exported classes? /Tomas ----- Original Message ----- From: "Petrucio" To: "Development of Python/C++ integration" Sent: Thursday, November 10, 2005 6:48 PM Subject: Re: [C++-sig] swig? > In my experience, the compilation of the SWIG wrappers is much, much faster > than compilation of the boost.python wrappers. The source of errors in > compilation is also easier to track down, since there's little or no > templates used in SWIG wrappers. > > SWIG is also easier to set up and use, you usually need much less > declarations of what you want to export, even less than when using Pyste. > > It also has a lot of pre-built typemaps that save you a lot of time > depending on what you want to export, for instance when dealing with > pointer to basic types, SWIG has an easy solution for that in a typemap, in > contrast to exporting those using boost.python, wich is not something you > look forward to. > > In the other hand, boost.python is more robust. I lack the memory to give > you specific examples, but there's some stupid things that SWIG does that > will blow your mind. Boost.python is also more 'purist', in some sense. But > since practicality beats purity, I'm more of a SWIG guy. > > I made a few performance tests, and expected boost.python to be a clear > favorite here, but there were not much diference between the two, if I > remember correctly. > > I made a lot of other comparisons between the two, but the results are not > in this computer. I'll send them some other day, if I remember to get them. > > --- > Fabio 'Petrucio' Stange - Game Programmer > Hoplon Infotainment - www.taikodom.com > > > At 10:14 10/11/2005, you wrote: > >I noticed that recent versions of swig have quite significantly advanced the > >support for c++. I wonder if anyone has experience they can share, > >regarding a comparison of boost::python with a recent swig. > > > >I have been using boost::python for some time, but am interested in > >considering swig, because in my present environment, it would be easier for > >me to deploy code using swig. > > > >_______________________________________________ > >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 petrucio at hoplon.com Thu Nov 10 20:20:44 2005 From: petrucio at hoplon.com (Petrucio) Date: Thu, 10 Nov 2005 16:20:44 -0300 Subject: [C++-sig] swig? In-Reply-To: <001301c5e619$00d7f110$0200a8c0@liquid.se> References: <6.0.2.0.1.20051110143038.01b44cf8@mail.hoplon.com> <001301c5e619$00d7f110$0200a8c0@liquid.se> Message-ID: <6.0.2.0.1.20051110161854.01b5b560@mail.hoplon.com> Not sure, since I don't usually use smart pointers. See http://www.swig.org/Doc1.3/Python.html#Python_nn27 At 14:05 10/11/2005, you wrote: >Is it in SWIG possible to have smart pointers that holds objects of exported >classes? > >/Tomas > >----- Original Message ----- >From: "Petrucio" >To: "Development of Python/C++ integration" >Sent: Thursday, November 10, 2005 6:48 PM >Subject: Re: [C++-sig] swig? > > > > In my experience, the compilation of the SWIG wrappers is much, much >faster > > than compilation of the boost.python wrappers. The source of errors in > > compilation is also easier to track down, since there's little or no > > templates used in SWIG wrappers. > > > > SWIG is also easier to set up and use, you usually need much less > > declarations of what you want to export, even less than when using Pyste. > > > > It also has a lot of pre-built typemaps that save you a lot of time > > depending on what you want to export, for instance when dealing with > > pointer to basic types, SWIG has an easy solution for that in a typemap, >in > > contrast to exporting those using boost.python, wich is not something you > > look forward to. > > > > In the other hand, boost.python is more robust. I lack the memory to give > > you specific examples, but there's some stupid things that SWIG does that > > will blow your mind. Boost.python is also more 'purist', in some sense. >But > > since practicality beats purity, I'm more of a SWIG guy. > > > > I made a few performance tests, and expected boost.python to be a clear > > favorite here, but there were not much diference between the two, if I > > remember correctly. > > > > I made a lot of other comparisons between the two, but the results are not > > in this computer. I'll send them some other day, if I remember to get >them. > > > > --- > > Fabio 'Petrucio' Stange - Game Programmer > > Hoplon Infotainment - www.taikodom.com > > > > > > At 10:14 10/11/2005, you wrote: > > >I noticed that recent versions of swig have quite significantly advanced >the > > >support for c++. I wonder if anyone has experience they can share, > > >regarding a comparison of boost::python with a recent swig. > > > > > >I have been using boost::python for some time, but am interested in > > >considering swig, because in my present environment, it would be easier >for > > >me to deploy code using swig. > > > > > >_______________________________________________ > > >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 > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From grant at grantgoodyear.org Tue Nov 15 00:10:25 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Mon, 14 Nov 2005 17:10:25 -0600 Subject: [C++-sig] pyste generation of getitem/setitem .def's Message-ID: <20051114231025.GD7228@bmb24.uth.tmc.edu> I recently hacked up my boost.python interface file to add __getitem__ and __setitem__ methods: class_< EMAN::EMData >("EMData", init< >()) .def(init< const EMAN::EMData& >()) .def("__getitem__", &emdata_getitem) .def("__setitem__", &emdata_setitem) I was generating the interface file using pyste, Include("emdata_wrapitems.h") # *item wrappers declared here EMData = Class("EMAN::EMData", "emdata.h") but I'm not sure how to get pyste to add the getitem/setitem .def's for me. I'm sure there's a simple trick that's more elegant than sedding the file, but I'm not sure what it is. There's "declaration_code" and "module_code"; is there a "class_code" or something similar? Thanks, Grant -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org From jusylves at videotron.ca Tue Nov 15 01:59:03 2005 From: jusylves at videotron.ca (Julien Sylvestre) Date: Mon, 14 Nov 2005 19:59:03 -0500 Subject: [C++-sig] boost.python: modifying class getattr Message-ID: <437932D7.7000402@videotron.ca> Hello all, I'm trying to access the type structure for a c++ class exposed to Python using boost.python, so that I can have ob_type->tp_getattro point to a custom function instead of PyObject_GenericGetAttr (for those who wonder why, it's a performance issue: with my current project, PyObject_GenericGetAttr is always called first, fails to find the requested attribute, and then __getattr__ is called on the wrapped object, which returns the attribute. I get an extra PyString_FromFormatV for each access to an attribute value, and this slows down my code by ~20%) If I write: object Foo_ = class_("Foo", init< >()) .def("__getattr__", &Foo::Foo_getattr) .def("__setattr__", &Foo::Foo_setattr) ..., is there a way to modify the type object associated with Foo_ instances so that instead of calling PyObject_GenericGetAttr when an attribute is requested, Python calls a function PyObject * Foo_GetAttr(PyObject *obj, PyObject *name) ? Thanks, Julien. From jan at langernetz.de Tue Nov 15 12:22:33 2005 From: jan at langernetz.de (Jan Langer) Date: Tue, 15 Nov 2005 12:22:33 +0100 Subject: [C++-sig] [Boost.Python] Solaris / gcc2.95.2 wchar.h problems Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I read that this newsgroup is suitable for Boost.Python problems. I wanted to compile Boost 1.33.0 and I ran into problems with Boost.Python. My system is Solaris 5.7 with gcc 2.95.2. The Python version is 2.4.1. When compling the file inheritance.cpp it includes integer_traits.hpp which exits with an error in line 116 because WCHAR_MIN and WCHAR_MAX are not defined. However, my wchar.h include file defines those two macros. I couldn't find what was going wrong, but moving the include of integer_traits.hpp in inheritance.cpp to the top of the list of include files solves the problem. But this results in the warning below. - ----- gcc-C++-action ../../../bin/boost/libs/python/build/libboost_python.a/gcc/debug/inheritance.o In file included from /data/tmp/laja/boost_1_33_0/boost/python/detail/wrap_python.hpp:30, from /data/tmp/laja/boost_1_33_0/boost/python/detail/prefix.hpp:13, from /data/tmp/laja/boost_1_33_0/boost/python/type_id.hpp:8, from /data/tmp/laja/boost_1_33_0/boost/python/object/inheritance.hpp:8, from /data/tmp/laja/boost_1_33_0/libs/python/build/../src/object/inheritance.cpp:6: /home/4all/packages/python/2.4.1/include/python2.4/pyconfig.h:820: warning: `_FILE_OFFSET_BITS' redefined /usr/include/sys/feature_tests.h:96: warning: this is the location of the previous definition - ------ If someone is interested in this problem, I could provide more details. Jan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (SunOS) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDecT4yJOS3PG4wcwRAnRIAJ9LFKa6LWrmlDVrWL7GOu0po9bC9QCgoGG0 fWim8v7NG4Eg7uhoIVcyct4= =OC/Y -----END PGP SIGNATURE----- From grant at grantgoodyear.org Tue Nov 15 17:20:50 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Tue, 15 Nov 2005 10:20:50 -0600 Subject: [C++-sig] pyste generation of getitem/setitem .def's In-Reply-To: <20051114231025.GD7228@bmb24.uth.tmc.edu> References: <20051114231025.GD7228@bmb24.uth.tmc.edu> Message-ID: <20051115162050.GE7228@bmb24.uth.tmc.edu> Okay, more searching of the archives brought me an answer. I'll attach a complete, short, and silly example for the next person who runs into this problem. My thanks to whomever provided the "Vector2d" example from which I liberally stole. -g2boojum- -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org -------------- next part -------------- class Vector2d { public: Vector2d():x(0.0),y(0.0) {} Vector2d(const double xval, const double yval): x(xval),y(yval) {} ~Vector2d() {} double& operator[](const int i); protected: double x, y; }; -------------- next part -------------- #include "foo.h" double& Vector2d::operator[](const int i) { return i==0? x : y; } -------------- next part -------------- #include "foo.h" #include #ifndef FOO_WRAP_H_ #define FOO_WRAP_H_ using boost::python::object; object vec2dget(object self, object key); void vec2dset(object self, object key, object val); #endif // FOO_WRAP_H_ -------------- next part -------------- #include "foo_wrap.h" #include "foo.h" #ifndef FOO_H_ #define FOO_H_ using namespace boost::python; object vec2dget(object self, object key) { int i = extract(key); Vector2d& s = extract(self); return object(s[i]); } void vec2dset(object self, object key, object val) { Vector2d& s = extract(self); int i = extract(key); double v = extract(val); s[i] = v; } #endif // FOO_H -------------- next part -------------- Include("foo_wrap.h") Vector2d = Class("Vector2d", "foo_wrap.h") add_method(Vector2d, "vec2dget") rename(Vector2d.vec2dget, "__getitem__") add_method(Vector2d, "vec2dset") rename(Vector2d.vec2dset, "__setitem__") -------------- next part -------------- // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Module ====================================================================== BOOST_PYTHON_MODULE(libpyfoo) { class_< Vector2d >("Vector2d", init< >()) .def(init< const Vector2d& >()) .def(init< const double, const double >()) .def("__getitem__", &vec2dget) .def("__setitem__", &vec2dset) ; } From hans_meine at gmx.net Tue Nov 15 18:33:28 2005 From: hans_meine at gmx.net (Hans Meine) Date: Tue, 15 Nov 2005 18:33:28 +0100 Subject: [C++-sig] boost.python: modifying class getattr In-Reply-To: <437932D7.7000402@videotron.ca> References: <437932D7.7000402@videotron.ca> Message-ID: <200511151833.29352.hans_meine@gmx.net> On Tuesday 15 November 2005 01:59, Julien Sylvestre wrote: > If I write: > object Foo_ = class_("Foo", init< >()) > .def("__getattr__", &Foo::Foo_getattr) > .def("__setattr__", &Foo::Foo_setattr) > ..., > > is there a way to modify the type object associated with Foo_ instances > so that instead of calling PyObject_GenericGetAttr when an attribute is > requested, Python calls a function > PyObject *Foo_GetAttr(PyObject *obj, PyObject *name) Ah, that would be cool; I would be looking for an analogous way to speed up __getitem__ making it comparable to that of a Python list.. Ciao, / / /--/ / / ANS From etaurel at cells.es Wed Nov 16 16:34:37 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Wed, 16 Nov 2005 16:34:37 +0100 Subject: [C++-sig] Specific exception classes Message-ID: <0IQ2000QD0MDLE@cells-s02.cells.es> Hello everybody. I am using BPL to wrap a C++ library and I would like to define my own exception. Therefore, I have written one exception translator that I have registered with the "register_exception_translator". My exception translator looks like this (DevFailed is the name of the C++ exception class) void translator_dev_failed(const DevFailed &the_ex) { PyObject *py_exc = PyErr_NewException("PyTangoDs.DevFailed",NULL,NULL); PyErr_SetString(py_exc,the_ex.errors[0].desc.in()); } In Python, I have: from PyTangoDs import * try: ... except DevFailed,e: print 'Received a DevFailed exception:',e except: print 'An unforeseen exception occured....' The python interpreter complains that it does not know the DevFailed name with this error : Traceback (most recent call last): File "main.py", line 19, in ? except DevFailed,e: NameError: name 'DevFailed' is not defined My question is : How is it possible to have your own exception ? Thank's for your answer Sincerely Emmanuel Taurel (etaurel at cells.es) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Wed Nov 16 18:37:30 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 16 Nov 2005 12:37:30 -0500 Subject: [C++-sig] boost.python: modifying class getattr References: <437932D7.7000402@videotron.ca> Message-ID: Julien Sylvestre writes: > Hello all, > I'm trying to access the type structure for a c++ class exposed to > Python using boost.python, so that I can have ob_type->tp_getattro point > to a custom function instead of PyObject_GenericGetAttr (for those who > wonder why, it's a performance issue: with my current project, > PyObject_GenericGetAttr is always called first, fails to find the > requested attribute, and then __getattr__ is called on the wrapped > object, which returns the attribute. I get an extra PyString_FromFormatV > for each access to an attribute value, and this slows down my code by ~20%) > > If I write: > object Foo_ = class_("Foo", init< >()) > .def("__getattr__", &Foo::Foo_getattr) > .def("__setattr__", &Foo::Foo_setattr) > ..., > > is there a way to modify the type object associated with Foo_ instances > so that instead of calling PyObject_GenericGetAttr when an attribute is > requested, Python calls a function > PyObject * > Foo_GetAttr(PyObject *obj, PyObject *name) > ? PyTypeObject* Foo_t = (PyTypeObject*)Foo_.ptr(); Foo_t->tp_getattro = Foo_GetAttr; HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Nov 16 18:42:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 16 Nov 2005 12:42:35 -0500 Subject: [C++-sig] [Boost.Python] Solaris / gcc2.95.2 wchar.h problems References: Message-ID: Jan Langer writes: > Hello, > I read that this newsgroup is suitable for Boost.Python problems. > > I wanted to compile Boost 1.33.0 and I ran into problems with > Boost.Python. My system is Solaris 5.7 with gcc 2.95.2. The Python > version is 2.4.1. When compling the file inheritance.cpp it includes > integer_traits.hpp which exits with an error in line 116 because > WCHAR_MIN and WCHAR_MAX are not defined. You should take this up with the maintainer of the relevant part of integer_traits.hpp. cvs annotate shows it to be John Maddock. 1.20 (johnmadd 21-Oct-02): // These are an implementation detail and not part of the interface 1.20 (johnmadd 21-Oct-02): #include 1.26 (johnmadd 17-Dec-04): // we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it, 1.26 (johnmadd 17-Dec-04): // and some may have but not ... 1.26 (johnmadd 17-Dec-04): #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun)) 1.20 (johnmadd 21-Oct-02): #include 1.20 (johnmadd 21-Oct-02): #endif > However, my wchar.h include > file defines those two macros. I couldn't find what was going wrong, but > moving the include of integer_traits.hpp in inheritance.cpp to the top > of the list of include files solves the problem. You can't do that. Translation units that use Python.h have to start with a Python header, and as a consequence translation units that use Boost.Python have to start with a Boost.Python header. Otherwise all heck breaks loose. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dgregor at cs.indiana.edu Wed Nov 16 20:23:24 2005 From: dgregor at cs.indiana.edu (Doug Gregor) Date: Wed, 16 Nov 2005 14:23:24 -0500 Subject: [C++-sig] Python help() not showing imported Boost.Python-wrapped classes Message-ID: Python's interactive help is not showing classes exported using Boost.Python. For instance, I have a module "_support" that uses Boost.Python like this: BOOST_PYTHON_MODULE(_support) { using boost::python::class_; using boost::python::enum_; using boost::python::init; class_("Point2D"); class_("Point3D"); enum_("Color"); def("distance", &point_2d_distance); } Now, that gets pulled into a package "bgl" that has this in its __init__.py: from _support import * If I run help(bgl), something odd happens. Under the CLASSES heading, the "Color" enum gets documented but Point2D and Point3D do not. Under the FUNCTIONS heading, "distance" gets documented. \ If I run help(bgl._support), I get Point2D and Point3D documented (in the CLASSES section, of course) but neither "Color" nor "distance". Ideally, the _support module would be invisible to the user, and all of these classes and functions would show up when one uses help(bgl). Is this possible? Cheers, Doug From dave at boost-consulting.com Wed Nov 16 23:25:44 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 16 Nov 2005 17:25:44 -0500 Subject: [C++-sig] Python help() not showing imported Boost.Python-wrapped classes References: Message-ID: Doug Gregor writes: > Python's interactive help is not showing classes exported using > Boost.Python. For instance, I have a module "_support" that uses > Boost.Python like this: > > BOOST_PYTHON_MODULE(_support) > { > using boost::python::class_; > using boost::python::enum_; > using boost::python::init; > > class_("Point2D"); > class_("Point3D"); > enum_("Color"); > def("distance", &point_2d_distance); > } > > Now, that gets pulled into a package "bgl" that has this in its > __init__.py: > > from _support import * > > If I run help(bgl), something odd happens. Under the CLASSES heading, > the "Color" enum gets documented but Point2D and Point3D do not. Under > the FUNCTIONS heading, "distance" gets documented. \ > > If I run help(bgl._support), I get Point2D and Point3D documented (in > the CLASSES section, of course) but neither "Color" nor "distance". > > Ideally, the _support module would be invisible to the user, and all of > these classes and functions would show up when one uses help(bgl). Is > this possible? >>> help(help) Help on _Helper in module site object: class _Helper(__builtin__.object) | Define the built-in 'help'. | This is a wrapper around pydoc.help (with a twist). http://www.python.org/doc/current/lib/module-pydoc.html Getting pydoc to show the right things for Boost.Python has been an ongoing struggle for some of us. The cues pydoc takes from the attributes in a module that it uses to decide what to document (and how) are arcane and not well-understood. I'd be happy if someone wanted to take on the project of figuring out what was needed to make everything come out right. -- Dave Abrahams Boost Consulting www.boost-consulting.com From amohr at pixar.com Thu Nov 17 03:36:35 2005 From: amohr at pixar.com (Alex Mohr) Date: Wed, 16 Nov 2005 18:36:35 -0800 Subject: [C++-sig] Something like boost::any ... custom conversions? In-Reply-To: References: <43693C1F.9090101@pixar.com> Message-ID: <437BECB3.7010207@pixar.com> So I'm back working on this now -- trying to register custom covnersions for my any-like object. > You can do it for specific held types just by registering the > appropriate from_python converters: Cool -- that's all I want to do... > I suggest you look at > http://news.gmane.org/find-root.php?message_id=%3c1026918209.17167.2.camel%40hunsmac.mit.edu%3e > and follow the links there. It's probably about time to document this > stuff for real and pull it out of the detail:: namespaces. Thanks for the links. I feel like I have a good general understanding of what needs doing. The problem is I don't know how to tell whether the PyObject * that is passed to convertible() is pointing to (a wrapper of) my any-like object, and if it is, how to get it out. I think this is what you were referring to when you said that the bigger issue is that I don't have the Python type object associated with my any-like class at compile time, correct? If anybody has any hints for doing that, I'd greatly appreciate it. Thanks, Alex From amohr at pixar.com Thu Nov 17 19:22:20 2005 From: amohr at pixar.com (Alex Mohr) Date: Thu, 17 Nov 2005 10:22:20 -0800 Subject: [C++-sig] Something like boost::any ... custom conversions? In-Reply-To: References: <43693C1F.9090101@pixar.com> Message-ID: <437CCA5C.5040902@pixar.com> > You can do it for specific held types just by registering the > appropriate from_python converters: Actually, I'm trying something like the code below now and it seems to be working so far. I haven't tested extensively yet. I'll have to register on the order of 100 converters like this and I'm wondering how much it might affect performance. Is this a reasonable approach? Is there a better way? Is there some gap in my understanding? Any comments are greatly appreciated. Alex // In this code, MyAny is a boost::any like object which has methods // isHolding() and get() // using namespace boost::python; template static void *convertible(PyObject *obj_ptr) { extract getAny(obj_ptr); if (getAny.check()) { MyAny a = getAny(); if (a.isHolding()) return obj_ptr; } return 0; } template static void construct(PyObject *obj_ptr, converter::rvalue_from_python_stage1_data *data) { MyAny a = extract(obj_ptr); if (!a.isHolding()) // throw an exception: type error. void *storage = ((converter::rvalue_from_python_storage*)data) ->storage.bytes; new (storage) T(a.get()); data->convertible = storage; } // Then I register converters like this converter::registry::push_back(convertible, construct, boost::python::type_id()); From meine at kogs1.informatik.uni-hamburg.de Thu Nov 17 19:43:48 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Thu, 17 Nov 2005 19:43:48 +0100 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) In-Reply-To: References: <200508220002.07595.hans_meine@gmx.net> Message-ID: <200511171943.48729.meine@kogs.informatik.uni-hamburg.de> Hi! I want to pick up the discussion again. Today, I discussed the problem (defining an __init__ which takes an arbitrary number of arguments) again with Ullrich K?the, and thanks to his stamina when digging through the depths of boost::python, we now have a working solution. On Monday 22 August 2005 02:47, David Abrahams wrote: > > I am trying to do something like > > > > python::class_("PythonVector", python::no_init) > > .def("__init__", python::raw_function(&createVector, 1)); > > > > But this gives the vector as first element of the args tuple to > > createVector(). > > What's wrong with that? We could not find out what to do with args[0] or what it actually contains. It's an object which is said to be of type "PythonVector" in error messages, but one cannot extract<> anything from it, and we could not find any other use for it. (See also my messages from the 22th of August) After unsuccessfully trying to work out how the callable objects created by make_constructor initialize this "self" argument, Ullrich's final idea was to just pass this argument from our raw constructor function to another one created by make_constructor. The rest of the arguments are passed as (sliced-off) tuple to a factory function (similar to what Ralf proposed back then). Attached, you find the our new make_constructor implementation in the .hpp file, and a small testcase in the .cpp. (Compile into rawconstructor.so) Use like this from Python: import rawconstructor -- Ciao, / / /--/ / / ANS -------------- next part -------------- A non-text attachment was scrubbed... Name: raw_constructor.hpp Type: text/x-c++hdr Size: 1243 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: raw_constructor.cpp Type: text/x-c++src Size: 1124 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: raw_constructor.py Type: application/x-python Size: 130 bytes Desc: not available URL: From luvangel1002 at gmail.com Fri Nov 18 07:06:48 2005 From: luvangel1002 at gmail.com (Petya Vasileva) Date: Fri, 18 Nov 2005 00:06:48 -0600 Subject: [C++-sig] (no subject) Message-ID: <39d50a260511172206y114f2298id9dfaf1a3d17ff0c@mail.gmail.com> hey, i am trying to run this program, but it's not letting me. Would you help me, please! Thank you!!! //This program reads in a customer's name and time * //they were in a parking garage. It then calculates* //and prints out the average payment of all the * //people, the payment each person owes, and the * //change each person gets back. It also calculates* //and prints out anyone that is under the average * //payment. * //************************************************** # include # include # include using namespace std; //**************************************************** // Stubs or prototypes of functions double AveragePayment(); void Initialize(int & iNumCustomers, int & iNumUnderAverage); void Titles(ofstream & OutputFile); void ReadName(ifstream& InputFile, char strNm[]); int ReadMinutes(ifstream & InputFile); int Payment(int iMinutes); void ChangeDue (int iPayment, int & iNumQuarters, int & iNumDimes, int & iNumNickels, int & iNumPennies); void PrintIt (ofstream & OutputFile, char strNm[], int iNumMin, intiPayment, int iNumQuarters, int iNumDimes, int iNumNickels, int iNumPennies); void UnderAverage(int iPayment, double dAveragePayment, int &iNumCustomers, int & iNumUnderAverage, ofstream &ofPaymentFile); void PrintAverage(double dAveragePayment, int iNumCustomers, intiNumUnderAverage, ofstream &OutputFile); void FreezeScreen(); //**************************************************** void main() { char strNm[20];//Customer name int iNumMin; //Number of minutes the customer was in the garage int iNumQuarters; int iNumDimes; int iNumNickels; int iNumPennies; int iNumCustomers; int iNumUnderAverage; //int iNumUnderAverage; double dAveragePayment; //Average amount paid for parking int iPayment; //Payment due double iChangeDue; //Change due to the customer double dPercentCust; //Percent of customers under the average ifstream InputFile; //Input file name ofstream OutputFile; //Output file name AveragePayment(); InputFile.open("ASS9.txt"); Initialize (iNumCustomers, iNumUnderAverage); if (! InputFile) { cout << "Error in opening file" << endl; cout << endl; FreezeScreen(); return; } OutputFile.open("Output.txt"); Titles(OutputFile); while(! InputFile.eof()) { ReadName(InputFile, strNm); ReadMinutes(InputFile); Payment(iNumMin); ChangeDue (iPayment, iNumQuarters, iNumDimes, iNumNickels, iNumPennies); PrintIt (OutputFile, strNm, iNumMin, iPayment, iNumQuarters, iNumDimes, iNumNickels, iNumPennies); UnderAverage(iPayment, dAveragePayment, iNumCustomers, iNumUnderAverage, OutputFile); PrintAverage(dAveragePayment, iNumCustomers, iNumUnderAverage, OutputFile); } InputFile.close(); OutputFile.close(); FreezeScreen(); } //**************************************************** //This function freezes the screen and stops the program. void FreezeScreen() { fflush(stdin); cout << "Hit enter to continue"; getchar(); } //**************************************************** //This function returns the average amount paid by customers //to park in the garage. double AveragePayment() { ifstream InputFile; char strNm[20]; int iNumCustomers; int iNumMin; int iPayment; double dAveragePayment; InputFile.open("ASS9.txt"); if (InputFile.fail()) { cout << "Error Opening Input File" << endl; FreezeScreen(); return -1; } else { while (! InputFile.eof()) { InputFile.getline(strNm, 20); Payment(iNumMin); iNumCustomers++; } } InputFile.close(); dAveragePayment = iPayment / iNumCustomers; return dAveragePayment; } //**************************************************** //This function initializes all the variables void Initialize(int & iNumCustomers, int & iNumUnderAverage) { int iCntr = 0; int iNumMin = 0; //Number of minutes the customer was in the garage int iNumQuarters = 0; int iNumDimes = 0; int iNumNickels = 0; int iNumPennies = 0; double dAveragePayment = 0; //Average amount paid for parking double dPayment = 0; //Payment due int iChangeDue = 0; //Change due to the customer double dPercentCust = 0; //int iNumCustomers = 0; //int iNumUnderAverage = 0; //return iNumCustomers, iNumUnderAverage; } //**************************************************** //This function prints a title for the table in the output file. void Titles(ofstream & OutputFile) { OutputFile << setw(30) << "Parking Garage Payment" << endl; } //**************************************************** //This function reads in the name of the customer from the input file void ReadName(ifstream & InputFile, char strNm[20]) { InputFile.getline(strNm, 20); } //**************************************************** //This function reads in the number of minutes the customer was in the //garage. int ReadMinutes(ifstream & InputFile) { int iNumMin; InputFile >> iNumMin; return iNumMin; } //**************************************************** int Payment(int iNumMin) { int iPayment; if(iNumMin <= 60) { iPayment = 50; } else { iPayment = (iNumMin - 60)* 1; } if(iPayment >= 1000) { iPayment = 1000; } return iPayment; } //**************************************************** void ChangeDue (int iPayment, int & iNumQuarters, int & iNumDimes, int & iNumNickels, int & iNumPennies) { int iChangeDue; iChangeDue = 1000 - iPayment; iNumQuarters = iChangeDue % 25; iNumDimes = iNumQuarters % 10; iNumNickels = iNumDimes % 5; iNumPennies = iNumNickels % 1; //return iChangeDue, iNumQuarters, iNumDimes, iNumNickels, iNumPennies; } //**************************************************** void PrintIt (ofstream & OutputFile, char strNm[], int iNumMin, intiPayment, int iNumQuarters, int iNumDimes, int iNumNickels, int iNumPennies) { OutputFile << setw(7) << strNm << setw(15)<< iNumMin << setw(21)<< iPayment << setw(20)<< iNumQuarters << setw(20)<< iNumDimes << setw(21)<< iNumNickels << setw(20)<< iNumPennies << endl; } //**************************************************** void UnderAverage(int iPayment, double dAveragePayment, int &iNumCustomers, int & iNumUnderAverage, ofstream &OutputFile) { double dPercentCust; while (iPayment < dAveragePayment) { OutputFile << "Under Average"; iNumUnderAverage ++; } dPercentCust = iNumUnderAverage/iNumCustomers; //return iNumUnderAverage, iNumCustomers, dPercentCust; } //*************************************************** void PrintAverage(double dAveragePayment, int iNumCustomers, intiNumUnderAverage, ofstream &OutputFile) { double dAveAmtPaid; double dPercentCust; OutputFile << "The average payment was: " << dAveAmtPaid << "." << endl; OutputFile << "The percent of customers that are under the average is: " << dPercentCust << "." << endl; } //*************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans_meine at gmx.net Fri Nov 18 09:02:51 2005 From: hans_meine at gmx.net (Hans Meine) Date: Fri, 18 Nov 2005 09:02:51 +0100 Subject: [C++-sig] Limits of implicitly_convertible? Message-ID: <200511180903.02598.hans_meine@gmx.net> Hi! I could not get implicitly_convertible() to work *at all*, so I tried the example from the documentation. (BTW: My compiler told me that operator int() had to be const, that should probably be fixed in the docs.) That simple example worked, but when I changed the constructor to take a list instead of an int, it ceased working. Attached you'll find a minimal testcase. -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: implicit.cpp Type: text/x-c++src Size: 412 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: implicit.py Type: application/x-python Size: 86 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: From noam.seker at intel.com Sat Nov 19 00:19:22 2005 From: noam.seker at intel.com (Seker, Noam) Date: Sat, 19 Nov 2005 01:19:22 +0200 Subject: [C++-sig] porting Qt 3.3.x to python Message-ID: <6230DAB319ED764C98371CCE53E263CE081D3302@hasmsx403.ger.corp.intel.com> Hi, Is there an available boost/python package for Qt 3.3.x? thanks Noam Seker-Gafni phone: +972 - 4 - 865 5260 inet: 8 - 465 5260 email: noam.seker at intel.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jan at langernetz.de Sun Nov 20 13:19:50 2005 From: jan at langernetz.de (Jan Langer) Date: Sun, 20 Nov 2005 13:19:50 +0100 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem Message-ID: Hello, I ran into a problem with Boost.Python exporting a std::map. I used the following code below. I use Boost 1.33.0 and everything compiles fine. ------------ #include #include using namespace boost::python; typedef std::map map_t; struct A { map_t data; std::string str; }; BOOST_PYTHON_MODULE(test) { class_ ("test_map") .def (map_indexing_suite ()); class_ ("A") .def_readonly ("data", &A::data) .def_readwrite ("str", &A::str); } ------------- Then I run Python and try to use the module: ------------ laja at bridge:python> python Python 2.4.1 (#1, Sep 2 2005, 09:48:20) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. \>>> import test \>>> a = test.A() \>>> a.str="text" \>>> a.str 'text' \>>> a.data[0]="text2" \>>> a.data[0] Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i0 ----------- I played around for a while but I find no solution. Regards, Jan From jan at langernetz.de Fri Nov 18 18:42:18 2005 From: jan at langernetz.de (Jan Langer) Date: Fri, 18 Nov 2005 18:42:18 +0100 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I ran into a problem with Boost.Python exporting a std::map. I used the following code below. I use Boost 1.33.0 and everything compiles fine. >>>>>>>>>>> #include #include using namespace boost::python; typedef std::map map_t; struct A { map_t data; std::string str; }; BOOST_PYTHON_MODULE(test) { class_ ("test_map") .def (map_indexing_suite ()); class_ ("A") .def_readonly ("data", &A::data) .def_readwrite ("str", &A::str); } <<<<<<<<<<<< Then I run Python and try to use the module: >>>>>>>>>>>> laja at bridge:python> python Python 2.4.1 (#1, Sep 2 2005, 09:48:20) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import test >>> a = test.A() >>> a.str="text" >>> a.str 'text' >>> a.data[0]="text2" >>> a.data[0] Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i0 <<<<<<<<<<<< I played around for a while but I find no solution. Regards, Jan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (SunOS) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDfhJ5yJOS3PG4wcwRAihcAJsFhjuOtOykJlyC9JKsg1yobwOsKgCgxQa5 l6GQlwbGXfjizZ3BVVo81Io= =Jebw -----END PGP SIGNATURE----- From djowel at gmail.com Mon Nov 21 04:54:29 2005 From: djowel at gmail.com (Joel de Guzman) Date: Mon, 21 Nov 2005 11:54:29 +0800 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem In-Reply-To: References: Message-ID: <438144F5.2020805@boost-consulting.com> Jan Langer wrote: > Hello, > I ran into a problem with Boost.Python exporting a std::map. I used the > following code below. I use Boost 1.33.0 and everything compiles fine. > Have you tried setting NoProxy template parameter to true? class_ ("test_map") Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From djowel at gmail.com Mon Nov 21 05:54:22 2005 From: djowel at gmail.com (Joel de Guzman) Date: Mon, 21 Nov 2005 12:54:22 +0800 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem In-Reply-To: <438144F5.2020805@boost-consulting.com> References: <438144F5.2020805@boost-consulting.com> Message-ID: <438152FE.9090704@boost-consulting.com> Joel de Guzman wrote: > Jan Langer wrote: > >>Hello, >>I ran into a problem with Boost.Python exporting a std::map. I used the >>following code below. I use Boost 1.33.0 and everything compiles fine. >> > > > Have you tried setting NoProxy template parameter to true? > > class_ ("test_map") This is the same issue as discussed in: http://mail.python.org/pipermail/c++-sig/2004-March/007029.html I've just added a fix for this that regards std::string and std::complex as no-proxy types. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From duranlef at iro.umontreal.ca Mon Nov 21 18:04:50 2005 From: duranlef at iro.umontreal.ca (=?ISO-8859-1?Q?Fran=E7ois_Duranleau?=) Date: Mon, 21 Nov 2005 12:04:50 -0500 (EST) Subject: [C++-sig] porting Qt 3.3.x to python In-Reply-To: <6230DAB319ED764C98371CCE53E263CE081D3302@hasmsx403.ger.corp.intel.com> References: <6230DAB319ED764C98371CCE53E263CE081D3302@hasmsx403.ger.corp.intel.com> Message-ID: On Sat, 19 Nov 2005, Seker, Noam wrote: > Hi, > Is there an available boost/python package for Qt 3.3.x? > thanks Here you go: http://www.riverbankcomputing.co.uk/pyqt/ -- Fran?ois Duranleau LIGUM, Universit? de Montr?al "[...] consider McDonalds -- it is fast, cheap, and used by millions. However, it also contributes to obesity, heart disease, and (arguably) deforestation." - Prof. Gene Spafford, in email about Windows supplanting other operating systems in Universities From n_habili at hotmail.com Tue Nov 22 04:20:52 2005 From: n_habili at hotmail.com (Nariman Habili) Date: Tue, 22 Nov 2005 03:20:52 +0000 Subject: [C++-sig] SciPy Core Message-ID: I'm wondering whether the boost python numeric wrappers will be updated to scipy core? Thanks. From noam.seker at intel.com Tue Nov 22 08:23:45 2005 From: noam.seker at intel.com (Seker, Noam) Date: Tue, 22 Nov 2005 09:23:45 +0200 Subject: [C++-sig] porting Qt 3.3.x to python Message-ID: <6230DAB319ED764C98371CCE53E263CE082284BB@hasmsx403.ger.corp.intel.com> Thanks. PyQt package is built with SIP. I tried to use PyQt objects from a code wrapped with boost/python but, at least in my na?ve example, same object (name) in boost and in PyQt have different 'signature'. Is there a way to bridge between the 2 python wrappers? Can I tell boost to use qt objects from PyQt instead of generating it's own version of them? -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Fran?ois Duranleau Sent: Monday, November 21, 2005 7:05 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] porting Qt 3.3.x to python On Sat, 19 Nov 2005, Seker, Noam wrote: > Hi, > Is there an available boost/python package for Qt 3.3.x? > thanks Here you go: http://www.riverbankcomputing.co.uk/pyqt/ -- Fran?ois Duranleau LIGUM, Universit? de Montr?al "[...] consider McDonalds -- it is fast, cheap, and used by millions. However, it also contributes to obesity, heart disease, and (arguably) deforestation." - Prof. Gene Spafford, in email about Windows supplanting other operating systems in Universities From etaurel at cells.es Tue Nov 22 12:31:37 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Tue, 22 Nov 2005 12:31:37 +0100 Subject: [C++-sig] returning reference to enum Message-ID: <0IQC008YYTDH63@cells-s02.cells.es> Hello everybody, I have a very simple example where I try to wrap a C++ class. In this class there is a method which returns a reference to an internal variable which is an enumeration. I try to wrap this method with the return_internal_reference Call Policy but I have a compiler error. First here is my little C++ file ---------------------------------------------------------------------------- ------------ #include using namespace boost::python; enum DispLevel { OPERATOR = 0, EXPERT }; class MyClass { public: MyClass() {} ~MyClass() {} void set_enum(DispLevel dl) {disp=dl;} DispLevel &get_enum() {return disp;} protected: DispLevel disp; }; BOOST_PYTHON_MODULE(PyTangoDs) { enum_("DispLevel") .value("OPERATOR",OPERATOR) .value("EXPERT",EXPERT) ; class_("MyClass") .def("set_enum",&MyClass::set_enum) .def("get_enum",&MyClass::get_enum,return_internal_reference<>()) ; } The error I get from the compiler is : ---------------------------------------------------------------------------- --------------------------------------------------------- gcc-C++-action bin/enum/PyTangoDs.so/gcc/debug/shared-linkable-true/py_ds.o /home/etaurel/src/boost_1_33_0/boost/python/object/make_instance.hpp: In static member function `static PyObject* boost::python::objects::make_instance_impl::execute(Arg&) [with Arg = DispLevel*, T = DispLevel, Holder = boost::python::objects::pointer_holder, Derived = boost::python::objects::make_ptr_instance >]': /home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:96: instantiated from `static PyObject* boost::python::detail::make_reference_holder::execute(T*) [with T = DispLevel]' /home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:60: instantiated from `PyObject* boost::python::to_python_indirect::execute(const U&, mpl_::bool_) const [with U = DispLevel, T = DispLevel&, MakeHolder = boost::python::detail::make_reference_holder]' /home/etaurel/src/boost_1_33_0/boost/python/to_python_indirect.hpp:37: instantiated from `PyObject* boost::python::to_python_indirect::operator()(const U&) const [with U = DispLevel, T = DispLevel&, MakeHolder = boost::python::detail::make_reference_holder]' /home/etaurel/src/boost_1_33_0/boost/python/detail/invoke.hpp:88: instantiated from `PyObject* boost::python::detail::invoke(boost::python::detail::invoke_tag_, const RC&, F&, TC&) [with RC = boost::python::to_python_indirect, F = DispLevel&(MyClass::*)(), TC = boost::python::arg_from_python]' /home/etaurel/src/boost_1_33_0/boost/python/detail/caller.hpp:199: instantiated from `PyObject* boost::python::detail::caller_arity<1>::impl::operator()(PyObject*, PyObject*) [with F = DispLevel&(MyClass::*)(), Policies = boost::python::return_internal_reference<1, boost::python::default_call_policies>, Sig = boost::mpl::vector2]' /home/etaurel/src/boost_1_33_0/boost/python/object/py_function.hpp:38: instantiated from `PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject *, PyObject*) [with Caller = boost::python::detail::caller, boost::mpl::vector2 >]' /home/etaurel/src/boost_1_33_0/boost/detail/call_traits.hpp:83: instantiated from here /home/etaurel/src/boost_1_33_0/boost/python/object/make_instance.hpp:24: error: incomplete type `boost::STATIC_ASSERTION_FAILURE' does not have member `value' ---------------------------------------------------------------------------- ----------------------------------------------------------- Any idea welcome. Thank's very much in advance Emmanuel Taurel (etaurel at cells.es) -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Tue Nov 22 12:44:13 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 22 Nov 2005 13:44:13 +0200 Subject: [C++-sig] returning reference to enum In-Reply-To: <0IQC008YYTDH63@cells-s02.cells.es> References: <0IQC008YYTDH63@cells-s02.cells.es> Message-ID: <7465b6170511220344v6260f4eet9f3d9284e15ca80@mail.gmail.com> On 11/22/05, Emmanuel Taurel wrote: > Hello everybody, > > I have a very simple example where I try to wrap a C++ class. In this class > there is a method which returns a reference to an internal variable which is > an enumeration. I try to wrap this method with the return_internal_reference > Call Policy but I have a compiler error. > > Any idea welcome. Thank's very much in advance If you can change the class, then change it to return that enum value by value. In this case you don't need to specify call policies. If you can not to change it, then return_value_policy< copy_non_const_reference > will do the job. > > > Emmanuel Taurel (etaurel at cells.es) > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > From jan at langernetz.de Tue Nov 22 14:07:06 2005 From: jan at langernetz.de (Jan Langer) Date: Tue, 22 Nov 2005 14:07:06 +0100 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem In-Reply-To: <438152FE.9090704@boost-consulting.com> References: <438144F5.2020805@boost-consulting.com> <438152FE.9090704@boost-consulting.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Joel de Guzman wrote: >>>I ran into a problem with Boost.Python exporting a std::map. I used the >>>following code below. I use Boost 1.33.0 and everything compiles fine. >> >>Have you tried setting NoProxy template parameter to true? >> >> class_ ("test_map") > > This is the same issue as discussed in: > http://mail.python.org/pipermail/c++-sig/2004-March/007029.html > > I've just added a fix for this that regards std::string and > std::complex as no-proxy types. Hello, I tried setting NoProxy to true and it worked in the example I posted. However my real example is a little more complicated. I copied the relevant part below: struct domain {}; struct graph { typedef std::map > domains_t; domains_t domains_; }; class_ > ("domain"); // objects::class_value_wrapper , // objects::make_ptr_instance , domain> > > (); class_ ("domains_map") .def (map_indexing_suite ()); class_ ("graph") .def_readonly ("domains", &graph::domains_); This code (used in a module called pdg) can be compiled and imported in Python: import pdg g = pdg.graph () for el in g.domains: print el.key(), dom = el.data() But the last line gives an error: TypeError: No Python class registered for C++ class Q25boostt10shared_ptr1ZQ23pdg6domain If I comment out the three lines with class_value_wrapper (I saw something like that in the examples) and remove shared_ptr from the class_ definition of domain, I get the same error. I hope that makes my problem clearer. Regards, Jan Langer -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (SunOS) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDgxf5yJOS3PG4wcwRAjrgAJ9obR9b3g/YA21d4qr8yLH3pMx2SwCgpCQY eXHTX+NCzzMWSpRdHdgLoIk= =vFO5 -----END PGP SIGNATURE----- From etaurel at cells.es Tue Nov 22 14:18:00 2005 From: etaurel at cells.es (Emmanuel Taurel) Date: Tue, 22 Nov 2005 14:18:00 +0100 Subject: [C++-sig] returning reference to enum In-Reply-To: <7465b6170511220344v6260f4eet9f3d9284e15ca80@mail.gmail.com> Message-ID: <0IQC008BUYAS63@cells-s02.cells.es> Hello, I can't change the class therefore, as suggested I have used the copy_non_const_reference ResultConverterGenerator. It works fine. Thank's for the tip but in this case, my enum is copied in a new Python object. Is this correct ? A last question for my understanding. Why using return_internal_reference works fine when returning a reference to an already wrapped class (like in the return_internal_reference documentation example) and it does not when returning an enumeration ? Thank's for your answer Emmanuel Taurel (etaurel at cells.es) -----Original Message----- From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On Behalf Of Roman Yakovenko Sent: Tuesday, November 22, 2005 12:44 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] returning reference to enum On 11/22/05, Emmanuel Taurel wrote: > Hello everybody, > > I have a very simple example where I try to wrap a C++ class. In this class > there is a method which returns a reference to an internal variable which is > an enumeration. I try to wrap this method with the return_internal_reference > Call Policy but I have a compiler error. > > Any idea welcome. Thank's very much in advance If you can change the class, then change it to return that enum value by value. In this case you don't need to specify call policies. If you can not to change it, then return_value_policy< copy_non_const_reference > will do the job. > > > Emmanuel Taurel (etaurel at cells.es) > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From rwgk at yahoo.com Tue Nov 22 18:03:34 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 22 Nov 2005 09:03:34 -0800 (PST) Subject: [C++-sig] porting Qt 3.3.x to python In-Reply-To: <6230DAB319ED764C98371CCE53E263CE082284BB@hasmsx403.ger.corp.intel.com> Message-ID: <20051122170334.15526.qmail@web31504.mail.mud.yahoo.com> --- "Seker, Noam" wrote: > Thanks. > PyQt package is built with SIP. I tried to use PyQt objects from a code > wrapped with boost/python but, at least in my na?ve example, same object > (name) in boost and in PyQt have different 'signature'. > Is there a way to bridge between the 2 python wrappers? I am not aware of interfaces between SIP-generated wrappers and Boost.Python. > Can I tell boost to use qt objects from PyQt instead of generating it's own > version of them? That's probably something you'd have to figure out yourself. A few months ago someone asked a similar question regarding SWIG. It was surprisingly easy to support passing SWIG-wrapped objects to Boost.Python wrapped functions: http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/swig_arg.hpp?view=markup http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/swig_args_ext.cpp?view=markup If you are lucky, maybe something similar works for SIP. You'd have to find out how the SIP wrapping mechanism works. HTH, Ralf __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com From mjkeyes at sbcglobal.net Wed Nov 23 05:39:25 2005 From: mjkeyes at sbcglobal.net (Matt) Date: Tue, 22 Nov 2005 22:39:25 -0600 Subject: [C++-sig] Any word on when Py_Finalize will be implemented in boost::python yet? Message-ID: Just curious. From pth at suse.de Fri Nov 25 18:16:15 2005 From: pth at suse.de (Philipp Thomas) Date: Fri, 25 Nov 2005 18:16:15 +0100 Subject: [C++-sig] type-punning in boost python code. Message-ID: <20051125171615.GE7473@paradies.suse.de> our gcc 4.1 also analyses C++ code for violation of the C/C++ aliasing rules (mainline doesn't do so yet). For the code in boost 1.33.1 I get warning: dereferencing type-punned pointer will break strict-aliasing rules for the following files: /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/long.cpp: 12,19, 26 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/dict.cpp: 32 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/tuple.cpp:12 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/str.cpp: 12 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/object/class.cpp:543, 553 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/list.cpp: 15 as our package build system treats this warning as an error, I will use -fno-strict-aliasing for gcc as I'm not familiar with that code and I want to get the package built. For boost you should also consider either using said gcc switch or fix the code to not break strict-aliasing rules. I'd recommend doing the latter as switching off aliasing analysis will inhibit some optimisations. Philipp From djowel at gmail.com Sat Nov 26 17:26:34 2005 From: djowel at gmail.com (Joel de Guzman) Date: Sun, 27 Nov 2005 00:26:34 +0800 Subject: [C++-sig] [Boost.Python] map_indexing_suite problem In-Reply-To: References: <438144F5.2020805@boost-consulting.com> <438152FE.9090704@boost-consulting.com> Message-ID: <43888CBA.9070907@boost-consulting.com> Jan Langer wrote: > Hello, > I tried setting NoProxy to true and it worked in the example I posted. > However my real example is a little more complicated. I copied the > relevant part below: [snips] > > TypeError: No Python class registered for C++ class > Q25boostt10shared_ptr1ZQ23pdg6domain Ok it is a bug. It's fixed now in the CVS. I updated map_indexing_suite.cpp/py to prove the fix. All tests are passing. Hope that helps. Thanks for the report. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From dave at boost-consulting.com Sat Nov 26 22:59:02 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 26 Nov 2005 16:59:02 -0500 Subject: [C++-sig] Any word on when Py_Finalize will be implemented in boost::python yet? References: Message-ID: "Matt" writes: > Just curious. No word. It could be done by an ambitious volunteer (or hired professional) in a few days, though. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Sun Nov 27 11:08:45 2005 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sun, 27 Nov 2005 10:08:45 -0000 Subject: [C++-sig] Patch implementing void * support In-Reply-To: <436E4390.14657.548C6F9@localhost> Message-ID: <438985AD.32440.B7578@s_sourceforge.nedprod.com> Attached is a slightly fixed version of the patch. When is this patch going to be applied? On 6 Nov 2005 at 17:55, Niall Douglas wrote: > The enclosed patch adds void * support to Boost.Python by making void > an opaque type. Code that uses void * "just works" with this patch > with no further effort required. > > Also enclosed is a testcase and the docs have been modified. > > Ran full testsuite on msvc7.1 and msvc6 - everything works. I don't > have GCC to hand ATM, but apart from maybe a missing typename > specifier I can't see anything which would fault. I understand from Roman that I have too many typenames in there, but other than this trivial fix the patch works perfectly on GCC. Cheers, Niall -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: voidptrpatch2.diff Date: 27 Nov 2005, 10:05 Size: 4781 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: voidptrpatch2.diff Type: application/octet-stream Size: 4780 bytes Desc: not available URL: -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: voidptr.cpp Date: 6 Nov 2005, 17:38 Size: 892 bytes. Type: Program-source -------------- next part -------------- A non-text attachment was scrubbed... Name: voidptr.cpp Type: application/octet-stream Size: 891 bytes Desc: not available URL: -------------- next part -------------- The following section of this message contains a file attachment prepared for transmission using the Internet MIME message format. If you are using Pegasus Mail, or any other MIME-compliant system, you should be able to save it or view it from within your mailer. If you cannot, please ask your system administrator for assistance. ---- File information ----------- File: voidptr.py Date: 6 Nov 2005, 17:24 Size: 1114 bytes. Type: Unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: voidptr.py Type: application/octet-stream Size: 1114 bytes Desc: not available URL: From roman.yakovenko at gmail.com Sun Nov 27 11:34:54 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 27 Nov 2005 12:34:54 +0200 Subject: [C++-sig] Patch implementing void * support In-Reply-To: <438985AD.32440.B7578@s_sourceforge.nedprod.com> References: <436E4390.14657.548C6F9@localhost> <438985AD.32440.B7578@s_sourceforge.nedprod.com> Message-ID: <7465b6170511270234o748fcc97lc644075b95d613b9@mail.gmail.com> On 11/27/05, Niall Douglas wrote: > Attached is a slightly fixed version of the patch. When is this patch > going to be applied? > > I understand from Roman that I have too many typenames in there, but > other than this trivial fix the patch works perfectly on GCC. Small mistake: you don't have to declare void as an opaque type for automatic void * usage You don't need those lines ( at least on GCC 3.3 ): + +// Declare void as an opaque type for automatic void * usage +namespace boost { namespace python { + template<> + inline type_info type_id(BOOST_PYTHON_EXPLICIT_TT_DEF(void)) + { + return type_info (typeid (void *)); + } + template<> + inline type_info type_id( + BOOST_PYTHON_EXPLICIT_TT_DEF(const volatile void)) + { + return type_info (typeid (void *)); + } +}} > Cheers, > Niall Roman Yakovenko. From Yves_Secretan at inrs-ete.uquebec.ca Mon Nov 28 17:46:58 2005 From: Yves_Secretan at inrs-ete.uquebec.ca (Yves Secretan) Date: Mon, 28 Nov 2005 11:46:58 -0500 Subject: [C++-sig] iterator over list and sequences Message-ID: Hello all, In search for a simple way to iterate in C++ over a boost::python::list, I only found a discussion about how nice it would be to have one ( http://mail.python.org/pipermail/c++-sig/2003-March/003528.html). So I wrote a set of C++ iterators and ended up with a syntax a little more complex than what was originally proposed by David Abrahams, but maybe I missed something. typedef value_iterator iter_type; for (iter_type i = begin(lst); i != end(); ++i) { whatever(*i); } The tests provided have been run with gcc 3.3 mingw, visual c++ 7.0 and Intel 7.1 on WindowsXP (Boost 1.33.0, Python 2.4). Is there any interest? --------------------------------------------------------------- Yves Secretan, Professeur INRS-ETE 490, rue de la Couronne Qu?bec, Qu?bec G1K 9A9 CANADA tel: (418) 654 38 48 fax: (418) 654 26 00 e-mail: Yves_Secretan at ete.inrs.ca --------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: sequence_iterator.txt URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_sequence_iterator.cpp Type: application/octet-stream Size: 4187 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: sequence_iterator.hpp Type: application/octet-stream Size: 7325 bytes Desc: not available URL: From tippetts at lanl.gov Tue Nov 29 02:15:47 2005 From: tippetts at lanl.gov (Trevor Tippetts) Date: Mon, 28 Nov 2005 18:15:47 -0700 Subject: [C++-sig] boost.python and std::valarray Message-ID: <1133226947.4218.8.camel@localhost> I'm relatively new (and very impressed) user of boost.python. I do have a question, however. When I try to access members typed in c++ as std::valarray<> in python, I get errors like this: No Python class registered for C++ class std::valarray After searching through list archives and online docs and wikis, I have come to the conclusion that pyste and boost.python do not have a built-in wrapper for std::valarray<> and std::vector<> types. Is that a correct assumption? I found some examples people have given for wrapping std::vector<>, but not for std::valarray<>. Does anyone know of a good example implementation to which the rest of us could refer? Thanks, Trevor -- After due consideration, this message was judged by Trevor Tippetts not to contain technical or programmatic information and therefore does not require classification review. -- Trevor Tippetts Los Alamos National Laboratory -- ESA-WR T080 Los Alamos NM 87545 505-667-9009 From eric at boost-consulting.com Tue Nov 29 05:48:36 2005 From: eric at boost-consulting.com (Eric Niebler) Date: Mon, 28 Nov 2005 20:48:36 -0800 Subject: [C++-sig] iterator over list and sequences In-Reply-To: References: Message-ID: <438BDDA4.3020507@boost-consulting.com> Yves Secretan wrote: > > In search for a simple way to iterate in C++ over a boost::python::list, > I only found a discussion about how nice it would be to have one > (http://mail.python.org/pipermail/c++-sig/2003-March/003528.html). So I > wrote a set of C++ iterators and ended up with a syntax a little more > complex than what was originally proposed by David Abrahams, but maybe I > missed something. > We've already got one. :-) I wrote a STL iterator for python sequences. It is an input iterator over any iterable python object, not just lists. It has not yet been part of an official Boost release, but you can find it in Boost main CVS at boost/python/stl_iterator.hpp. It'll be part of the next major release. Hope that helps, -- Eric Niebler Boost Consulting www.boost-consulting.com From roman.yakovenko at gmail.com Tue Nov 29 06:27:03 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Nov 2005 07:27:03 +0200 Subject: [C++-sig] boost.python and std::valarray In-Reply-To: <1133226947.4218.8.camel@localhost> References: <1133226947.4218.8.camel@localhost> Message-ID: <7465b6170511282127k3e18c53flca5bf1064364b79e@mail.gmail.com> On 11/29/05, Trevor Tippetts wrote: > I'm relatively new (and very impressed) user of boost.python. I do have > a question, however. When I try to access members typed in c++ as > std::valarray<> in python, I get errors like this: > > No Python class registered for C++ class std::valarray > > After searching through list archives and online docs and wikis, I have > come to the conclusion that pyste and boost.python do not have a > built-in wrapper for std::valarray<> and std::vector<> types. Is that a > correct assumption? Partial, boost.python have this: http://boost.org/libs/python/doc/v2/indexing.html Also you can write ( and contribute ) template class similar to indexing_suite::Container that will expose std::valarray to python. An other valid approach, is to copy std::valarray to boost::python::list and return it. See http://boost.org/libs/python/pyste/doc/wrappers.html > I found some examples people have given for wrapping std::vector<>, but > not for std::valarray<>. Does anyone know of a good example > implementation to which the rest of us could refer? > > Thanks, > Trevor From roman.yakovenko at gmail.com Tue Nov 29 09:47:26 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 29 Nov 2005 10:47:26 +0200 Subject: [C++-sig] [Announce] pyplusplus 0.6.0 Message-ID: <7465b6170511290047u65ff91b4sc704950062fc3f88@mail.gmail.com> Hi. I would like announce of new version of pyplusplus (0.5). What is pyplusplus? pyplusplus is an object-oriented framework for creating a code generator for boost.python library. You can find pyplusplus here: http://www.language-binding.net/ You can download pyplusplus from http://sourceforge.net/project/showfiles.php?group_id=118209. Changes: 1. Code repository has been introduced. This repository contains classes and functions that will help users to export different C++ classes and declarations. Right now this repository contains two classes: array_1_t const_array_1_t Those classes helps to export static, single dimension arrays. As you can guess static, single dimension arrays are now supported. 2. Code generation has been improved. 3. Code generation speed has been improved. 4. If you have Niall Douglas void* patch, then you can enjoy from automatically set call policies. 5. Bit fields can be accessed ( get\\set ) from Python. 6. Creating custom code creater example has been added. 7. To Pyste comparison has been wrote. 8. Using this version it is possible to export most of TnFOX Python bindings. Roman Yakovenko From jan at langernetz.de Tue Nov 29 12:20:05 2005 From: jan at langernetz.de (Jan Langer) Date: Tue, 29 Nov 2005 12:20:05 +0100 Subject: [C++-sig] [Boost.Python] exporting GMP numbers to Python Message-ID: Hello, I have a c++ library I want to use as a python module. This works quite nice now (thanks to Joel's bugfix). However, some functions of the library return arbitrary precision numbers (GMP) and I need to access them in Python. I found a working GMP Python wrapper in the GMPY module, but I have simply no idea how use it for my purpose. Maybe someone has a link or something similar for me. Jan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: From meine at kogs1.informatik.uni-hamburg.de Tue Nov 29 15:30:20 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Tue, 29 Nov 2005 15:30:20 +0100 Subject: [C++-sig] [Boost.Python] exporting GMP numbers to Python In-Reply-To: References: Message-ID: <200511291530.21987.meine@kogs.informatik.uni-hamburg.de> On Tuesday 29 November 2005 12:20, Jan Langer wrote: > I found a working GMP Python wrapper in the GMPY module, but I have > simply no idea how use it for my purpose. Short answer: You can either export GMP numbers yourself with Boost::Python, or try to find out how to/from-python conversion is done with the wrapper you found. In the latter case, export boost::python wrappers returning/accepting boost::python::object's and do the conversion manually. -- Ciao, / / /--/ / / ANS From meine at kogs1.informatik.uni-hamburg.de Tue Nov 29 15:35:36 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Tue, 29 Nov 2005 15:35:36 +0100 Subject: [C++-sig] porting Qt 3.3.x to python In-Reply-To: <20051122170334.15526.qmail@web31504.mail.mud.yahoo.com> References: <20051122170334.15526.qmail@web31504.mail.mud.yahoo.com> Message-ID: <200511291535.37200.meine@kogs.informatik.uni-hamburg.de> On Tuesday 22 November 2005 18:03, Ralf W. Grosse-Kunstleve wrote: > > Can I tell boost to use qt objects from PyQt instead of generating it's > > own version of them? > > That's probably something you'd have to figure out yourself. A few months > ago someone asked a similar question regarding SWIG. It was surprisingly > easy to support passing SWIG-wrapped objects to Boost.Python wrapped > functions: > > http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/swig_arg.hpp?view >=markup > > http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/swig_args_ext.cpp >?view=markup > > If you are lucky, maybe something similar works for SIP. You'd have to find > out how the SIP wrapping mechanism works. Yes, it is possible; for example I did it with code fragments like these (this is also a hint for Jan Langer how such a thing could look like): #include // my SIP module was called vigraqt PyObject *getViewer() { return sipMapCppToSelfSubClass( somehowGetViewer(), sipClass_QImageViewer); } BOOST_PYTHON_MODULE_INIT(sipbridge) { def("viewer", &getViewer); } -- Ciao, / / /--/ / / ANS From dave at boost-consulting.com Wed Nov 30 13:18:20 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 30 Nov 2005 07:18:20 -0500 Subject: [C++-sig] [Boost.Python] exporting GMP numbers to Python References: <200511291530.21987.meine@kogs.informatik.uni-hamburg.de> Message-ID: Hans Meine writes: > On Tuesday 29 November 2005 12:20, Jan Langer wrote: >> I found a working GMP Python wrapper in the GMPY module, but I have >> simply no idea how use it for my purpose. > > Short answer: > You can either export GMP numbers yourself with Boost::Python, or try to find > out how to/from-python conversion is done with the wrapper you found. In the > latter case, export boost::python wrappers returning/accepting > boost::python::object's and do the conversion manually. It's also possible to register custom from_/to_python converters that will automatically convert the GMP numbers using the wrapper from the other extension. http://mail.python.org/pipermail/c++-sig/2002-May/001211.html http://www.boost.org/libs/python/doc/v2/to_python_converter.html -- Dave Abrahams Boost Consulting www.boost-consulting.com