From progettodex at gmail.com Fri Feb 1 08:59:05 2008 From: progettodex at gmail.com (progetto dex) Date: Fri, 1 Feb 2008 08:59:05 +0100 Subject: [C++-sig] missing to_python converter for wchar_t In-Reply-To: <7465b6170801311120r4a8c5141y3fb09cc3e1af25df@mail.gmail.com> References: <54f22e040801310843n59a56a5cx4e2768d2cdea0a28@mail.gmail.com> <7465b6170801311120r4a8c5141y3fb09cc3e1af25df@mail.gmail.com> Message-ID: <54f22e040801312359k7c4cc849yd7de628ad875d968@mail.gmail.com> Thanks for the response, but the trick did not work on the sample code. Anyway, I cannot change the original interface I'm wrapping since it's a third party library. Regards, Dex 2008/1/31, Roman Yakovenko : > > 2008/1/31 progetto dex : > > Hi all, > > it seems that I'm facing a well-known problem (I've found some messages > > dated 2006 or earlier), but maybe in the near past something has > changed... > > > > I'm wrapping a third party API that uses "const wchar_t* const" > arguments, > > and Python says that a converter is missing. > > Before creating a layer to convert from/to std::wstring, I post a > stripped > > down example. First, the C++ stuff: > > > > // C++ > > #include > > > > using namespace boost::python; > > > > class Receiver > > { > > public: > > virtual void Receive(const wchar_t* const message) { } > > }; > > > > class Sender > > { > > Receiver& receiver; > > > > public: > > Sender(Receiver& r) : receiver(r) { } > > void Send() { receiver.Receive(L"test message"); } > > }; > > > > struct PyReceiver : Receiver > > { > > PyObject* self; > > PyReceiver(PyObject* s) : self(s) { } > > > > void Receive(const wchar_t* const message) > > { return call_method(self, "Receive", message); } > > > > void Receive_default(const wchar_t* const message) > > { return this->Receiver::Receive(message); } > > }; > > > > BOOST_PYTHON_MODULE(MyModule) > > { > > class_("Receiver") > > .def("Receive", &Receiver::Receive, > &PyReceiver::Receive_default) > > ; > > > > class_("Sender", init()) > > .def("Send", &Sender::Send) > > ; > > } > > > > Now, a trivial Python test case: > > > > #python > > import MyModule > > > > class Receiver(MyModule.Receiver): > > def Receive (self, msg): > > print "MSG: " + msg > > > > r = Receiver() > > s = MyModule.Sender(r) > > s.Send() > > > > If I supply a to_python wchar_t converter, only the first letter of the > > message is printed. > > I'm I missing something? > > Untested: I think that replacing "const wchar_t* const" with "const > wchar_t* " should work. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > _______________________________________________ > 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 rogerdahl at dahlsys.com Sat Feb 2 04:29:54 2008 From: rogerdahl at dahlsys.com (Roger Dahl) Date: Fri, 01 Feb 2008 20:29:54 -0700 Subject: [C++-sig] directly modifying objects contained in vector exposed with vector_indexing_suite Message-ID: Hello everyone, I'm having a problem with vector_indexing_suite and thought I'd see if anyone could tell me if what I'm trying to do should work... I have exposed a vector with vector_indexing_suite and a function that returns a reference to vector to Python and I'm trying to update the members of obj from Python. I can do: obj = get_vec()[0] And I can then successfully modify obj: obj.text = 'test' However, if I try to modify the object in the vector: get_vec()[0].text = 'test' It doesn't "take". After assignment, if I display the value: print get_vec()[0].text It just prints the value that "text" had before. I have tried some variations like passing true for the vector_indexing_suite NoProxy parameter and having the get_vec function use return_value_policy. I have also tried to modify obj in two steps: obj = get_vec()[0] obj.text = 'test' get_vec()[0] = obj But this also fails silently. Any pointers would be much appreciated. Thank you, Roger From matthew.scouten at gmail.com Tue Feb 5 21:41:58 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Tue, 5 Feb 2008 14:41:58 -0600 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error Message-ID: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> So I have a vector of foo that I exposed with the indexing suite, and I need to deepcopy it. I get a Boost.Python.ArgumentError exception when I try to iterate across the result later. >>> from BusyBox import * >>> foo >>> vecfoo >>> vf = vecfoo() >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> vf.append(foo()) >>> for f in vf: ... f.__repr__() ... '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' >>> import copy >>> vf2 = copy.deepcopy(vf) >>> for f in vf2: ... f.__repr__() ... Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in vecfoo.__iter__(vecfoo) did not match C++ signature: __iter__(struct boost::python::back_reference > &>) >>> here is my c++ code: struct foo { foo(){} ; foo(int init_x, int init_y){x=init_x;y=init_y;}; int x; int y; bool operator==(const foo &rhs) const; }; bool foo::operator==(const foo &rhs) const {return (this == &rhs);} struct foo_wrapper : foo , wrapper { foo_wrapper(); foo_wrapper(const foo& f); foo_wrapper(int init_x, int init_y); static bool eq(const foo& lhs, const foo &rhs); }; foo_wraper::foo_wrapper(const foo& exch): foo(exch), wrapper(){} foo_wrapper::foo_wrapper(): foo(), wrapper(){} foo_wrapper::foo_wrapper(int init_x, int init_y) : foo(init_x,init_y), wrapper(){} bool foo_wrapper::eq(const foo& lhs, const foo &rhs) {return (lhs == rhs);} Later: class_("foo") .def(init<>()) .def(init()) .def_readwrite("x", &foo::x ) .def_readonly ("y", &foo::y ) .def("__eq__", &foo_wrapper::eq) ; class_ > ("vecfoo") .def(vector_indexing_suite< std::vector, true >() ); -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Feb 6 08:42:43 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 6 Feb 2008 09:42:43 +0200 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error In-Reply-To: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> References: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> Message-ID: <7465b6170802052342w5e23bd1ma28926dfc8e3e229@mail.gmail.com> 2008/2/5 Matthew Scouten : > So I have a vector of foo that I exposed with the indexing suite, and I need > to deepcopy it. I get a Boost.Python.ArgumentError exception when I try to > iterate across the result later. > I tried your example using indexing suite 2 and it gave me nice & very helpful error message: RuntimeError: Pickling of "deepcopy.items_t" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html) Take a look on the URL. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From meine at informatik.uni-hamburg.de Wed Feb 6 09:44:44 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Wed, 6 Feb 2008 09:44:44 +0100 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error In-Reply-To: <7465b6170802052342w5e23bd1ma28926dfc8e3e229@mail.gmail.com> References: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> <7465b6170802052342w5e23bd1ma28926dfc8e3e229@mail.gmail.com> Message-ID: <200802060944.44790.meine@informatik.uni-hamburg.de> Am Mittwoch, 06. Februar 2008 08:42:43 schrieb Roman Yakovenko: > 2008/2/5 Matthew Scouten : > > So I have a vector of foo that I exposed with the indexing suite, and I > > need to deepcopy it. I get a Boost.Python.ArgumentError exception when I > > try to iterate across the result later. > > I tried your example using indexing suite 2 and it gave me nice & very > helpful error message: > > RuntimeError: Pickling of "deepcopy.items_t" instances is not enabled > (http://www.boost.org/libs/python/doc/v2/pickle.html) > > Take a look on the URL. Also have a look in the archives for the "How about class_<...>.enable_copy() ?" thread, if you want explicit __deepcopy__ instead of using the pickle protocol. -- Ciao, / / /--/ / / ANS From andrea at ray-t.net Wed Feb 6 17:11:31 2008 From: andrea at ray-t.net (Andrea Interguglielmi) Date: Wed, 6 Feb 2008 16:11:31 +0000 Subject: [C++-sig] boost.python in Os X Leopard Message-ID: <792a93450802060811h754c8182sf669c4a4a0a2ff0a@mail.gmail.com> Hi there, I'm having a hard time trying to compile the quickstart test of boost.python, and I was wondering if there are people out there who managed to compile it under leopard (it seems to be going fine in Tiger). -------------- next part -------------- An HTML attachment was scrubbed... URL: From matthew.scouten at gmail.com Thu Feb 7 20:23:54 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Thu, 7 Feb 2008 13:23:54 -0600 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error In-Reply-To: <200802060944.44790.meine@informatik.uni-hamburg.de> References: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> <7465b6170802052342w5e23bd1ma28926dfc8e3e229@mail.gmail.com> <200802060944.44790.meine@informatik.uni-hamburg.de> Message-ID: <3dc9bcf00802071123g34b7435cid0d2a7b6822f7ffb@mail.gmail.com> Some Questions: This Indexing Suite 2: What is it and how do I use that instead of the normal indexing suite? even better error msgs will help. The pickle protocol method looks like too much work, given that some of these objects have dozens of data members that need to be copied. Implementing an explicit __deepcopy__ for every class could be a lot of work , and I do not understand what that memo argument is doing. I had hoped that BP would just know what to do. After all, all the classes in question have perfectly good copy ctors. I take it that 'class_<...>.enable_copy()' and the other ideas in that thread were never implemented? On Feb 6, 2008 2:44 AM, Hans Meine wrote: > Am Mittwoch, 06. Februar 2008 08:42:43 schrieb Roman Yakovenko: > > 2008/2/5 Matthew Scouten : > > > So I have a vector of foo that I exposed with the indexing suite, and > I > > > need to deepcopy it. I get a Boost.Python.ArgumentError exception when > I > > > try to iterate across the result later. > > > > I tried your example using indexing suite 2 and it gave me nice & very > > helpful error message: > > > > RuntimeError: Pickling of "deepcopy.items_t" instances is not enabled > > (http://www.boost.org/libs/python/doc/v2/pickle.html) > > > > Take a look on the URL. > > Also have a look in the archives for the "How about > class_<...>.enable_copy() ?" thread, if you want explicit __deepcopy__ > instead of using the pickle protocol. > > -- > Ciao, / / > /--/ > / / ANS > _______________________________________________ > 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 meine at informatik.uni-hamburg.de Fri Feb 8 10:23:24 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Fri, 8 Feb 2008 10:23:24 +0100 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error In-Reply-To: <3dc9bcf00802071123g34b7435cid0d2a7b6822f7ffb@mail.gmail.com> References: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> <200802060944.44790.meine@informatik.uni-hamburg.de> <3dc9bcf00802071123g34b7435cid0d2a7b6822f7ffb@mail.gmail.com> Message-ID: <200802081023.24740.meine@informatik.uni-hamburg.de> Am Donnerstag, 07. Februar 2008 20:23:54 schrieb Matthew Scouten: > Implementing an explicit __deepcopy__ for every class could be a lot of > work , and I do not understand what that memo argument is doing. You can use my implementation. > I had hoped that BP would just know what to do. After all, all the classes > in question have perfectly good copy ctors. I take it that > 'class_<...>.enable_copy()' and the other ideas in that thread were never > implemented? Yes, I have sent code that contains the implementation (in that thread, 2007-10-17 10:25), only: 1) The API is not class_<...>.enable_copy() 2) It was not integrated into the BPL (yet) AFAICS, David agreed in principle that this would be good to have in boost::python, and he even suggested to have that by default for not-noncopyable classes. If there is agreement on that, I will have a look at that in ca. 2 weeks; maybe I can propose a patch. -- Ciao, / / /--/ / / ANS From ndbecker2 at gmail.com Fri Feb 8 17:26:46 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 08 Feb 2008 11:26:46 -0500 Subject: [C++-sig] need help with numpy converter Message-ID: numpy is a bit tricky. The python type object is not a compile time constant. The value has to be filled in at runtime. I've gotten pretty far using these: namespace boost { namespace python { template<> struct base_type_traits { typedef PyObject type; }; }} namespace boost { namespace python { namespace converter { template<> struct pyobject_traits : public pyobject_traits {}; }}} But when I do (o is an object wrapping a PyArrayObject) return bp::handle (bp::borrowed (o.ptr()) I get an infinite recursion in upcast. It's trying to upcase a PyObject to a PyArrayObject (I think). This is really hard to debug. Any ideas? (I'm pretty sure that just adding a C-style cast would fix the above, but I'd rather understand the problem better and the recommended solution) From matthew.scouten at gmail.com Fri Feb 8 18:09:19 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Fri, 8 Feb 2008 11:09:19 -0600 Subject: [C++-sig] copy.deepcopy of a vector, and the resulting error In-Reply-To: <200802081023.24740.meine@informatik.uni-hamburg.de> References: <3dc9bcf00802051241u57058ce2g7938786aaa46530c@mail.gmail.com> <200802060944.44790.meine@informatik.uni-hamburg.de> <3dc9bcf00802071123g34b7435cid0d2a7b6822f7ffb@mail.gmail.com> <200802081023.24740.meine@informatik.uni-hamburg.de> Message-ID: <3dc9bcf00802080909u41b5ff97i51e2f90830874671@mail.gmail.com> If you are looking for agreement, you have mine. This seems like an obvious good idea to me. Ideally, the person using my library should not have to know what language I used to write it. Lacking deepcopy is an unacceptable speed bump. But I do have a few more questions, 1) This would be in the cvs only at first (I assume), so: 2) Will the latest cvs BP still be compatible with boost 1.34.1, or will I need latest cvs for all of boost? I need latest cvs for all of boost, that is a killer. I would love to see this in BP, it will save me a lot of work. On Feb 8, 2008 3:23 AM, Hans Meine wrote: > Am Donnerstag, 07. Februar 2008 20:23:54 schrieb Matthew Scouten: > > Implementing an explicit __deepcopy__ for every class could be a lot of > > work , and I do not understand what that memo argument is doing. > > You can use my implementation. > > > I had hoped that BP would just know what to do. After all, all the > classes > > in question have perfectly good copy ctors. I take it that > > 'class_<...>.enable_copy()' and the other ideas in that thread were > never > > implemented? > > Yes, I have sent code that contains the implementation (in that thread, > 2007-10-17 10:25), only: > 1) The API is not class_<...>.enable_copy() > 2) It was not integrated into the BPL (yet) > > AFAICS, David agreed in principle that this would be good to have in > boost::python, and he even suggested to have that by default for > not-noncopyable classes. > > If there is agreement on that, I will have a look at that in ca. 2 weeks; > maybe I can propose a patch. > > -- > Ciao, / / > /--/ > / / ANS > _______________________________________________ > 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 Fri Feb 8 23:51:27 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Fri, 8 Feb 2008 14:51:27 -0800 (PST) Subject: [C++-sig] boost.python in Os X Leopard Message-ID: <930863.10129.qm@web31112.mail.mud.yahoo.com> >I'm having a hard time trying to compile the quickstart test of boost.python, and I was > wondering if there are people out there who managed to compile it under leopard Yes, but using a scons-based build system and the latest boost svn. Ralf -------------- next part -------------- An HTML attachment was scrubbed... URL: From trimblej at gmail.com Sun Feb 10 07:10:13 2008 From: trimblej at gmail.com (John Trimble) Date: Sat, 9 Feb 2008 23:10:13 -0700 Subject: [C++-sig] [Boost.Python] Why a bad_weak_ptr exception with get_shared_from_this? Message-ID: <442c6e420802092210k5922fc52g5124561875cbd6ca@mail.gmail.com> I'm having a slight issue when using get_shared_from_this() in a member function when that function also gets as a parameter a shared_ptr to itself. I've simplified my issue down to this short example (complete sources also attached): --------------------------- namespace test{ using namespace boost; using namespace boost::python; class A : public enable_shared_from_this { public: virtual void attempt() { shared_ptr ptr = shared_from_this(); } virtual void attempt_with_self(shared_ptr a) { shared_ptr ptr = shared_from_this(); } }; shared_ptr make_A_instance() { shared_ptr p(new A()); return p; } } // namespace test BOOST_PYTHON_MODULE(test_module) { using namespace boost; using namespace boost::python; register_ptr_to_python< shared_ptr >(); class_("A", no_init) .def("attempt", &test::A::attempt) .def("attempt_with_self", &test::A::attempt_with_self) .def("__init__", make_constructor(&test::make_A_instance)); ; } --------------------------- I'm using a custom constructor which always wraps new instances of A in a shared_ptr, so the weak_ptr in any instance of A should always be initialized. Upon testing this code I get the following result: ------------------------------------------------- >>> a = A() >>> a.attempt() >>> a = A() >>> a.attempt_with_self(a) >>> a.attempt() Traceback (most recent call last): File "test_error.py", line 12, in ? a.attempt() # bad_weak_ptr exception RuntimeError: tr1::bad_weak_ptr --------------------------- The bad_weak_ptr exception originates on the following line from A.attempt(): shared_ptr ptr = shared_from_this(); Somehow my weak_ptr reference is getting invalidated by the attempt_with_self(...) call. I tried doing this purely in C++ without a problem: --------------------------- shared_ptr p = make_A_instance(); p->attempt_with_self(p); p->attempt(); --------------------------- I'm guessing that the conversion to python of the shared_ptr returned by make_A_instance() is where the problem originates, but I don't quite understand all the magic involved in that process to know how to get around this issue. Any suggestions on how I might get this working would be greatly appreciated. I imagine people do this kind of thing regularly, so I'm probably missing some simple detail. I apologize if this is a rather n00b question, but I've looked through the docs and the mailing list and haven't found anything about this specific issue. Thanks, - John Trimble -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: module_test.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_error.py Type: text/x-python Size: 240 bytes Desc: not available URL: From RaoulGough at yahoo.co.uk Sun Feb 10 17:42:11 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sun, 10 Feb 2008 16:42:11 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline Message-ID: <47AF2963.4060100@yahoo.co.uk> A few years ago I worked on a new implementation of container indexing support in Boost.Python, which never made it onto the Boost mainline. I seem to remember that Dave had some reservations about the amount of detailed documentation on the way the implementation worked, but haven't dredged up any old emails on this point. Since then, I haven't had much time to look at this, so the code has always remained on the indexing_v2 branch. Nevertheless, I understand that some people are using this code successfully, including pygccxml*, so I was wondering if it would now be appropriate to merge this code onto the mainline. I didn't keep up with the CVS to SVN conversion, so I'm not sure how hard this would be to get done. Any opinions or advice on getting this started? -- Cheers, Raoul. * http://mail.python.org/pipermail/c++-sig/2007-December/013124.html http://mail.python.org/pipermail/c++-sig/2007-July/012569.html http://www.language-binding.net/pyplusplus/documentation/containers.html From chad at imvu.com Mon Feb 11 02:14:45 2008 From: chad at imvu.com (Chad Austin) Date: Sun, 10 Feb 2008 17:14:45 -0800 Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Message-ID: <369001ee0802101714p5d234f2n1eaef7845bfa9c61@mail.gmail.com> Hi all, A month ago or so we discovered a bug in Boost.Python that manifests when using enable_shared_from_this. Here is a test case that demonstrates the bug: #include #include using namespace boost; using namespace boost::python; class Test; typedef shared_ptr TestPtr; class Test : public enable_shared_from_this { public: static TestPtr construct() { return TestPtr(new Test); } void act() { TestPtr kungFuDeathGrip(shared_from_this()); } void take(TestPtr t) { } }; void Export_test() { class_("Test") .def("construct", &Test::construct) .staticmethod("construct") .def("act", &Test::act) .def("take", &Test::take) ; } And here is the Python: x = Test.construct() x.take(x) x.act() The bug (as I understand it) is that the shared_ptr_from_python converter creates a new shared_ptr for the Test instance to pass it into C++. This new shared_ptr has a nop deleter, except that it keeps the Python object alive as long as the new shared_ptr is alive. The problem here is that creating a shared_ptr to an object of type T when T is enable_shared_from_this resets the weak pointer inside of enable_shared_from_this. (See shared_ptr's constructors for the details of the implementation.) A fix that passes the test above and has worked for us is to change shared_ptr's constructor to accept a dont_enable_shared_from_this argument and pass that in from the shared_ptr_from_python converter. The patch is attached (against boost 1.33, but the bug didn't look fixed in 1.34 either). Cheers, Chad p.s. I have seen other people with this problem as well. Googling for bad_weak_ptr turns up several results. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: enable_shared_from_this_boost_python.patch Type: application/octet-stream Size: 1285 bytes Desc: not available URL: From rwgk at yahoo.com Mon Feb 11 02:19:24 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sun, 10 Feb 2008 17:19:24 -0800 (PST) Subject: [C++-sig] Merging indexing_v2 to mainline Message-ID: <826847.10185.qm@web31102.mail.mud.yahoo.com> Hi Raoul, Nice to hear from you! Is indexing_v2 fully backward compatible with the current indexing suite? If not, is it technically feasible to change indexing_v2 so that it can co-exist with the current indexing suite? After so many years, I fear too many things will break if indexing_v2 isn't fully backward compatible. But it would be very nice if it were generally available. Ralf From roman.yakovenko at gmail.com Mon Feb 11 07:17:49 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Mon, 11 Feb 2008 08:17:49 +0200 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <47AF2963.4060100@yahoo.co.uk> References: <47AF2963.4060100@yahoo.co.uk> Message-ID: <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> On Feb 10, 2008 6:42 PM, Raoul Gough wrote: > A few years ago I worked on a new implementation of container indexing > support in Boost.Python, which never made it onto the Boost mainline. I > seem to remember that Dave had some reservations about the amount of > detailed documentation on the way the implementation worked, but haven't > dredged up any old emails on this point. > > Since then, I haven't had much time to look at this, so the code has > always remained on the indexing_v2 branch. Nevertheless, I understand > that some people are using this code successfully, including pygccxml*, > so I was wondering if it would now be appropriate to merge this code > onto the mainline. Good morning. I would like to take this chance and to say thank you - indexing suite v2 is very cool piece of software. I was even able to fix and add new features to it. Thank you! By the way, PyOgre, one of the largest user of py++, is using the new indexing suite for year and we didn't find any problem with it. > I didn't keep up with the CVS to SVN conversion, so I'm not sure how > hard this would be to get done. Any opinions or advice on getting this > started? Your suite is already in SVN: http://svn.boost.org/trac/boost/browser/sandbox-tags/indexing_20030918 http://svn.boost.org/trac/boost/browser/sandbox-tags/indexing_v2 Py++ object has "indexing suite v2" source code in its source tree too. Basically it contains few bug fixes and new features. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From trimblej at gmail.com Mon Feb 11 08:52:53 2008 From: trimblej at gmail.com (John Trimble) Date: Mon, 11 Feb 2008 00:52:53 -0700 Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this In-Reply-To: <369001ee0802101714p5d234f2n1eaef7845bfa9c61@mail.gmail.com> References: <369001ee0802101714p5d234f2n1eaef7845bfa9c61@mail.gmail.com> Message-ID: <442c6e420802102352q580589e5t9ef0b6041c55f58c@mail.gmail.com> It worked! That problem had been driving me crazy for the past 2 days. I don't know why I couldn't find the answer via Google. Perhaps its because of all the brain damage from my Java programming. Thank you so much. - John 2008/2/10 Chad Austin : > Hi all, > > A month ago or so we discovered a bug in Boost.Python that manifests when > using enable_shared_from_this. Here is a test case that demonstrates the > bug: > > > #include > #include > > using namespace boost; > using namespace boost::python; > > class Test; > typedef shared_ptr TestPtr; > > class Test : public enable_shared_from_this { > public: > static TestPtr construct() { > return TestPtr(new Test); > } > > void act() { > TestPtr kungFuDeathGrip(shared_from_this()); > } > > void take(TestPtr t) { > } > }; > > void Export_test() { > class_("Test") > .def("construct", &Test::construct) > .staticmethod("construct") > > .def("act", &Test::act) > .def("take", &Test::take) > ; > } > > And here is the Python: > > x = Test.construct() > x.take(x) > x.act() > > The bug (as I understand it) is that the shared_ptr_from_python converter > creates a new shared_ptr for the Test instance to pass it into C++. This > new shared_ptr has a nop deleter, except that it keeps the Python object > alive as long as the new shared_ptr is alive. The problem here is that > creating a shared_ptr to an object of type T when T is > enable_shared_from_this resets the weak pointer inside of > enable_shared_from_this. (See shared_ptr's constructors for the details > of the implementation.) A fix that passes the test above and has worked for > us is to change shared_ptr's constructor to accept a > dont_enable_shared_from_this argument and pass that in from the > shared_ptr_from_python converter. The patch is attached (against boost > 1.33, but the bug didn't look fixed in 1.34 either). > > Cheers, > Chad > > p.s. I have seen other people with this problem as well. Googling for > bad_weak_ptr turns up several results. > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From andrea at ray-t.net Mon Feb 11 13:34:58 2008 From: andrea at ray-t.net (Andrea Interguglielmi) Date: Mon, 11 Feb 2008 12:34:58 +0000 Subject: [C++-sig] boost.python in Os X Leopard In-Reply-To: <930863.10129.qm@web31112.mail.mud.yahoo.com> References: <930863.10129.qm@web31112.mail.mud.yahoo.com> Message-ID: <792a93450802110434y45e1438csa49a087ee85c0c5f@mail.gmail.com> I was trying with scons as well, but I started having lot of unresolved symbols, all to do with python. I'll post my SConstruct as soon as I have the time. On Fri, Feb 8, 2008 at 10:51 PM, Ralf W. Grosse-Kunstleve wrote: > >I'm having a hard time trying to compile the quickstart test of > boost.python, and I was > > wondering if there are people out there who managed to compile it under > leopard > > Yes, but using a scons-based build system and the latest boost svn. > Ralf > -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Mon Feb 11 15:02:18 2008 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Mon, 11 Feb 2008 14:02:18 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <47AF2963.4060100@yahoo.co.uk> References: <47AF2963.4060100@yahoo.co.uk> Message-ID: I would be very keen to have this in the mainline either as a backwardly compatible replacement for the existing indexing suite or as an independent alternative implementation alongside it. Personally I do not know if backward compatibility is possible. Thanks for the useful work, John. Raoul Gough wrote: > A few years ago I worked on a new implementation of container indexing > support in Boost.Python, which never made it onto the Boost mainline. I > seem to remember that Dave had some reservations about the amount of > detailed documentation on the way the implementation worked, but haven't > dredged up any old emails on this point. > > Since then, I haven't had much time to look at this, so the code has > always remained on the indexing_v2 branch. Nevertheless, I understand > that some people are using this code successfully, including pygccxml*, > so I was wondering if it would now be appropriate to merge this code > onto the mainline. > > I didn't keep up with the CVS to SVN conversion, so I'm not sure how > hard this would be to get done. Any opinions or advice on getting this > started? > From jannes80 at hotmail.de Mon Feb 11 15:09:38 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Mon, 11 Feb 2008 15:09:38 +0100 Subject: [C++-sig] Adding custom C API functionality to boost.python modules Message-ID: Hello,sorry if this is an obvious thing to do, but how can i access Python C API from boost.python. Say i want to add the following code to a boost.python module://C API Function: static PyObject* foo(PyObject *self, PyObject *args){ /*some code */};//C API Method table:static PyMethodDef mod_methods[] = { {"py_foo",foo,METH_VARARGS,foo_doc},{NULL,NULL} };//init:void init(){ PyInitModule3("modulename", mod_methods, mod_doc);}--------------------------------------------------------------------------------------The remaining module code is written as usual:#include "boost/python.hpp"BOOST_PYTHON_MODULE(modulename){/* usual boost.python stuff */};Thanks _________________________________________________________________ Importieren Sie ganz einfach Ihre E-Mail Adressen in den Messenger! http://messenger.live.de/community/neuekontakte_adressimport.html From jannes80 at hotmail.de Mon Feb 11 15:31:18 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Mon, 11 Feb 2008 15:31:18 +0100 Subject: [C++-sig] Adding custom C API functionality to boost.python modules Message-ID: oops, something went wrong with formating. Next try: Hello, sorry if this is an obvious thing to do, but how can i access Python C API from boost.python. Say i want to add the following code to a boost.python module: //C API Function: static PyObject* foo(PyObject *self, PyObject *args){ /*some code */}; //C API Method table: static PyMethodDef mod_methods[] = { {"py_foo",foo,METH_VARARGS,foo_doc},{NULL,NULL} }; //init: void init(){ PyInitModule3("modulename", mod_methods,mod_doc); } -------------------------------------------------------------------------------------- The remaining module code is written as usual: #include "boost/python.hpp" BOOST_PYTHON_MODULE(modulename){ /* usual boost.python stuff */ }; Thanks _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From seefeld at sympatico.ca Mon Feb 11 15:42:02 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 11 Feb 2008 09:42:02 -0500 Subject: [C++-sig] Adding custom C API functionality to boost.python modules In-Reply-To: References: Message-ID: <47B05EBA.4040108@sympatico.ca> Marcus Jannes wrote: > sorry if this is an obvious thing to do, but how can i access Python C API from boost.python. Have you actually tried it ? It should Just Work. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Mon Feb 11 16:08:18 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Mon, 11 Feb 2008 16:08:18 +0100 Subject: [C++-sig] Adding custom C API functionality to boost.python modules In-Reply-To: <47B05EBA.4040108@sympatico.ca> References: <47B05EBA.4040108@sympatico.ca> Message-ID: Well, i can declare/define the function, but how does the boost.python module know of it? Speaking of the part where you call Py_InitModule3(...) in the C API ---------------------------------------- > Date: Mon, 11 Feb 2008 09:42:02 -0500 > From: seefeld at sympatico.ca > To: c++-sig at python.org > Subject: Re: [C++-sig] Adding custom C API functionality to boost.python modules > > Marcus Jannes wrote: > >> sorry if this is an obvious thing to do, but how can i access Python C API from boost.python. > > Have you actually tried it ? It should Just Work. > > Regards, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Kostenlose Windows Live Services in einem Komplettpaket. Gleich downloaden! http://get.live.com/ From seefeld at sympatico.ca Mon Feb 11 16:27:30 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 11 Feb 2008 10:27:30 -0500 Subject: [C++-sig] Adding custom C API functionality to boost.python modules In-Reply-To: References: <47B05EBA.4040108@sympatico.ca> Message-ID: <47B06962.1020009@sympatico.ca> Marcus Jannes wrote: > Well, i can declare/define the function, but how does the boost.python module know of it? > Speaking of the part where you call Py_InitModule3(...) in the C API I'm not sure what you are trying to achieve, and how this relates to boost.python (other than the question whether you can mix the boost.python with the Python C API). With boost.python you call BOOST_PYTHON_MODULE(your_module_name) { ... } While with Python's C API you would define extern "C" void inityour_module_name() { ... } You should use one of the two, not both. (Actually, I don't see any reason to use the C API to expose the extension module; there are good reasons to use boost.python instead. However, the bodies of the two blocks above may contain any mix of the two APIs as you want. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Mon Feb 11 16:41:10 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Mon, 11 Feb 2008 16:41:10 +0100 Subject: [C++-sig] Adding custom C API functionality to boost.python modules In-Reply-To: <47B06962.1020009@sympatico.ca> References: <47B05EBA.4040108@sympatico.ca> <47B06962.1020009@sympatico.ca> Message-ID: I just put the Py_InitModule3() function at the end of the BOOST_PYTHON_MODULE definitions, which seems to compile fine, not sure if it will work runtime though.Thanks alot anyway> Date: Mon, 11 Feb 2008 10:27:30 -0500> From: seefeld at sympatico.ca> To: c++-sig at python.org> Subject: Re: [C++-sig] Adding custom C API functionality to boost.python modules> > Marcus Jannes wrote:> > Well, i can declare/define the function, but how does the boost.python module know of it? > > Speaking of the part where you call Py_InitModule3(...) in the C API> > I'm not sure what you are trying to achieve, and how this relates to > boost.python (other than the question whether you can mix the > boost.python with the Python C API).> > With boost.python you call> > BOOST_PYTHON_MODULE(your_module_name)> {> ...> }> > While with Python's C API you would define> > extern "C" void inityour_module_name()> {> ...> }> > You should use one of the two, not both. (Actually, I don't see any > reason to use the C API to expose the extension module; there are good > reasons to use boost.python instead.> However, the bodies of the two blocks above may contain any mix of the > two APIs as you want.> > HTH,> Stefan> > -- > > ...ich hab' noch einen Koffer in Berlin...> _______________________________________________> C++-sig mailing list> C++-sig at python.org> http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Kostenlose Windows Live Services in einem Komplettpaket. Gleich downloaden! http://get.live.com/ From meine at informatik.uni-hamburg.de Mon Feb 11 16:52:44 2008 From: meine at informatik.uni-hamburg.de (Hans Meine) Date: Mon, 11 Feb 2008 16:52:44 +0100 Subject: [C++-sig] =?iso-8859-1?q?Adding_custom_C_API_functionality=09to?= =?iso-8859-1?q?=09boost=2Epython=09modules?= In-Reply-To: References: <47B06962.1020009@sympatico.ca> Message-ID: <200802111652.45081.meine@informatik.uni-hamburg.de> Am Montag, 11. Februar 2008 16:41:10 schrieb Marcus Jannes: > I just put the Py_InitModule3() function at the end of the > BOOST_PYTHON_MODULE definitions, which seems to compile fine, not sure if > it will work runtime though. You know that you can just use bp::def("myfunc", &myfunc_impl_using_C_api); to export your functions with the BPL, right? -- Ciao, / / /--/ / / ANS From jannes80 at hotmail.de Mon Feb 11 17:18:07 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Mon, 11 Feb 2008 17:18:07 +0100 Subject: [C++-sig] Adding custom C API functionality to boost.python modules In-Reply-To: <200802111652.45081.meine@informatik.uni-hamburg.de> References: <47B06962.1020009@sympatico.ca> <200802111652.45081.meine@informatik.uni-hamburg.de> Message-ID: Yes, but i am trying to wrap a function which takes a function pointer which isn't possible according to the boost.python faq. I am working on something suggested in the book: "Python scripting for computational science", where a C API approach is used. ---------------------------------------- > From: meine at informatik.uni-hamburg.de > To: c++-sig at python.org > Date: Mon, 11 Feb 2008 16:52:44 +0100 > Subject: Re: [C++-sig] Adding custom C API functionality to boost.python modules > > Am Montag, 11. Februar 2008 16:41:10 schrieb Marcus Jannes: >> I just put the Py_InitModule3() function at the end of the >> BOOST_PYTHON_MODULE definitions, which seems to compile fine, not sure if >> it will work runtime though. > > You know that you can just use > bp::def("myfunc", &myfunc_impl_using_C_api); > to export your functions with the BPL, right? > > -- > Ciao, / / > /--/ > / / ANS > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Windows Live Fotogalerie: So einfach organisieren Sie Ihre Fotos! http://get.live.com/photogallery/overview From rwgk at yahoo.com Tue Feb 12 00:55:06 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 11 Feb 2008 15:55:06 -0800 (PST) Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Message-ID: <917255.25494.qm@web31113.mail.mud.yahoo.com> Thanks for the patch! I'd love to check this in for you, but for the change in shared_ptr.hpp you'll need Peter Dimov's approval, and the shared_ptr documentation would have to be updated. Also, your reproducer should be turned into a unit test (in boost/libs/python/test). Is there any chance that the shared_ptr patch could somehow be avoided? Ralf ----- Original Message ---- From: Chad Austin To: c++-sig at python.org Sent: Sunday, February 10, 2008 5:14:45 PM Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Hi all, A month ago or so we discovered a bug in Boost.Python that manifests when using enable_shared_from_this. Here is a test case that demonstrates the bug: #include #include using namespace boost; using namespace boost::python; class Test; typedef shared_ptr TestPtr; class Test : public enable_shared_from_this { public: static TestPtr construct() { return TestPtr(new Test); } void act() { TestPtr kungFuDeathGrip(shared_from_this()); } void take(TestPtr t) { } }; void Export_test() { class_("Test") .def("construct", &Test::construct) .staticmethod("construct") .def("act", &Test::act) .def("take", &Test::take) ; } And here is the Python: x = Test.construct() x.take(x) x.act() The bug (as I understand it) is that the shared_ptr_from_python converter creates a new shared_ptr for the Test instance to pass it into C++. This new shared_ptr has a nop deleter, except that it keeps the Python object alive as long as the new shared_ptr is alive. The problem here is that creating a shared_ptr to an object of type T when T is enable_shared_from_this resets the weak pointer inside of enable_shared_from_this. (See shared_ptr's constructors for the details of the implementation.) A fix that passes the test above and has worked for us is to change shared_ptr's constructor to accept a dont_enable_shared_from_this argument and pass that in from the shared_ptr_from_python converter. The patch is attached (against boost 1.33, but the bug didn't look fixed in 1.34 either). Cheers, Chad p.s. I have seen other people with this problem as well. Googling for bad_weak_ptr turns up several results. -----Inline Attachment Follows----- _______________________________________________ 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 chad at imvu.com Tue Feb 12 07:10:31 2008 From: chad at imvu.com (Chad Austin) Date: Mon, 11 Feb 2008 22:10:31 -0800 Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this In-Reply-To: <917255.25494.qm@web31113.mail.mud.yahoo.com> References: <917255.25494.qm@web31113.mail.mud.yahoo.com> Message-ID: <369001ee0802112210v59bae14doa586979fca3b48a7@mail.gmail.com> There probably is a way to prevent boost.python from creating shared_ptrs with a null deleter like it does, but it would require far more knowledge than I have. :) I agree that it would be a better fix, though. On 2/11/08, Ralf W. Grosse-Kunstleve wrote: > > > > Thanks for the patch! I'd love to check this in for you, but for the > change in shared_ptr.hpp you'll need Peter Dimov's approval, and the > shared_ptr documentation would have to be updated. Also, your reproducer > should be turned into a unit test (in boost/libs/python/test). > > Is there any chance that the shared_ptr patch could somehow be avoided? > > Ralf > > > > ----- Original Message ---- > From: Chad Austin > To: c++-sig at python.org > Sent: Sunday, February 10, 2008 5:14:45 PM > Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this > > Hi all, > > A month ago or so we discovered a bug in Boost.Python that manifests when using enable_shared_from_this. Here is a test case that demonstrates the bug: > > > #include > #include > > using namespace boost; > using namespace boost::python; > > class Test; > typedef shared_ptr TestPtr; > > class Test : public enable_shared_from_this { > public: > static TestPtr construct() { > return TestPtr(new Test); > } > > void act() { > TestPtr kungFuDeathGrip(shared_from_this()); > } > > void take(TestPtr t) { > } > }; > > void Export_test() { > class_("Test") > .def("construct", &Test::construct) > .staticmethod("construct") > > .def("act", &Test::act) > .def("take", &Test::take) > ; > } > > And here is the Python: > > x = Test.construct() > x.take(x) > x.act() > > The bug (as I understand it) is that the shared_ptr_from_python converter creates a new shared_ptr for the Test instance to pass it into C++. This new shared_ptr has a nop deleter, except that it keeps the Python object alive as long as the new shared_ptr is alive. The problem here is that creating a shared_ptr to an object of type T when T is enable_shared_from_this resets the weak pointer inside of enable_shared_from_this. (See shared_ptr's constructors for the details of the implementation.) A fix that passes the test above and has worked for us is to change shared_ptr's constructor to accept a dont_enable_shared_from_this argument and pass that in from the shared_ptr_from_python converter. The patch is attached (against boost 1.33, but the bug didn't look fixed in 1.34 either). > > Cheers, > Chad > > p.s. I have seen other people with this problem as well. Googling for bad_weak_ptr turns up several results. > > > > -----Inline Attachment Follows----- > > _______________________________________________ > 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 oschweitzer at mac.com Tue Feb 12 12:30:29 2008 From: oschweitzer at mac.com (Oliver Schweitzer) Date: Tue, 12 Feb 2008 12:30:29 +0100 Subject: [C++-sig] Best practices for C++ project preparation Message-ID: Hi, I'm using Py++ to Boost.Python-wrap several medium-scale projects/ libraries. So far I'm having a good time doing this, learning a lot about advanced C++, Boost and Python in the process. A key to Py++ is reading the available documentation carefully, there is a lot in it. Great stuff. My questions: Call policies: There is the odd "deeper" problem popping up, but most of my current work at wrapping classes seems to come from having to explicitly prescribe Call Policies for several dozen classes. Is there a way to adapt design/implementation on the C++ to "help" Py++ at guessing a good call policy? Granularity of Wrapper projects: Having several dozen classes to wrap/ expose, what is your experience with organizing wrapper projects/ libraries? Close to the source C++ project/namespaces? How many Headers/Classes into one Module/Module-Builder? Working exclusive or inclusive, i.e. exposing only carefully selected classes/members or try to expose all and everything? One goal is having not ever to touch the Py++-generated code, just work in Python and the wrappee lib. I think that's enough for one mail, Best regards, Oliver From jannes80 at hotmail.de Tue Feb 12 13:24:23 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 12 Feb 2008 13:24:23 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back Message-ID: Hi again, i know the following code should work: double pycall(double d){ PyObject *py_obj; double c_result; py_obj = Py_BuildValue("d",d); c_result = PyFloat_AS_DOUBLE(py_obj); return c_result; }; But how can i use a boost.python exposed class with it (i.e.: ExpClass): c_class pycall(c_class c){ PyObject *py_obj; c_class c_result; py_obj = PyBuildValue("O",c); //does not work! Provide converter function with "O&" argument ? c_result = SomeConverterToC(py_obj); //??? return c_result; }; BOOST_PYTHON_MODULE(MyModule){ {//::ExpClass typedef bp::class_< ExpClass> ExpClass_exposer_t; ExpClass_exposer_t ExpClass_exposer = ExpClass_exposer_t( "PyExpClass" ); bp::scope ExpClass_scope( ExpClass_exposer ); //constructors: ExpClass_exposer.def( bp::init<>() ); //default constructor ExpClass_exposer.def( bp::init< ExpClass const &>(( bp::arg("r") )) ); //copy-constructor } }; Thanks again for any help. _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From jannes80 at hotmail.de Tue Feb 12 13:33:09 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 12 Feb 2008 13:33:09 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: References: Message-ID: It should read ExpClass not c_class here of course: ExpClass pycall(ExpClass c){ PyObject *py_obj; ExpClass c_result; py_obj = PyBuildValue("O",c); //does not work! Provide converter function with "O&" argument ? c_result = SomeConverterToC(py_obj); //??? return c_result; }; _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From seefeld at sympatico.ca Tue Feb 12 13:45:23 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 12 Feb 2008 07:45:23 -0500 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: References: Message-ID: <47B194E3.4030204@sympatico.ca> Marcus Jannes wrote: > It should read ExpClass not c_class here of course: > > ExpClass pycall(ExpClass c){ > PyObject *py_obj; > ExpClass c_result; > py_obj = PyBuildValue("O",c); //does not work! Provide converter function with "O&" argument ? > c_result = SomeConverterToC(py_obj); //??? > return c_result; What are you trying to do here ? What is 'c' ? There shouldn't be any need to use PyObject raw pointers at all. Assuming 'ExpClass' has already been exported, the following should Just Work: ExpClass a = ...; bp::object o(a); //<--- now holds a copy of 'a' ... ExpClass b = bp::extract(o); //<--- attempts to extract an // ExpClass from 'o' > }; Just declare 'pycall' in your module: bp::def("pycall", pycall); HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Tue Feb 12 14:09:47 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 12 Feb 2008 14:09:47 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: <47B194E3.4030204@sympatico.ca> References: <47B194E3.4030204@sympatico.ca> Message-ID: > What are you trying to do here ? What is 'c' ? There shouldn't be any > need to use PyObject raw pointers at all. Assuming 'ExpClass' has > already been exported, the following should Just Work: > > ExpClass a = ...; > bp::object o(a); //<--- now holds a copy of 'a' > ... > ExpClass b = bp::extract(o); //<--- attempts to extract an > // ExpClass from 'o' > >> }; Thank you, this seems to go into the right direction, but i need the PyObject pointer for a function like: PyEval_CallObject(); if i use it with the code above: PyEval_CallObject(_pyfunc_ptr, &o); i get this error: cannot convert ?boost::python::api::object*? to ?PyObject*? for argument ?2? _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From seefeld at sympatico.ca Tue Feb 12 14:27:05 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 12 Feb 2008 08:27:05 -0500 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: References: <47B194E3.4030204@sympatico.ca> Message-ID: <47B19EA9.8070102@sympatico.ca> Marcus Jannes wrote: > >> What are you trying to do here ? What is 'c' ? There shouldn't be any >> need to use PyObject raw pointers at all. Assuming 'ExpClass' has >> already been exported, the following should Just Work: >> >> ExpClass a = ...; >> bp::object o(a); //<--- now holds a copy of 'a' >> ... >> ExpClass b = bp::extract(o); //<--- attempts to extract an >> // ExpClass from 'o' >> >>> }; > > Thank you, this seems to go into the right direction, but i need the PyObject pointer for a function like: > PyEval_CallObject(); Why ? Have you studied the boost.python documentation at all ? It offers everything you need to call a python object from within C++ code, without having to touch the Python C API. (But to answer your question: python::object has a 'ptr()' member function that returns a raw pointer, if you *really* need it.) HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Tue Feb 12 14:50:08 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 12 Feb 2008 14:50:08 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: <47B19EA9.8070102@sympatico.ca> References: <47B194E3.4030204@sympatico.ca> <47B19EA9.8070102@sympatico.ca> Message-ID: Thank you, i think this is exactly what i need. Regarding your question why i want to use it in this way: It is because i want to convert Python function objects to C++ function pointers which get passed to a another function and this seems to be the way to do it. The boost.python FAQ (see: http://www.boost.org/libs/python/doc/v2/faq.html ) states that it isnt possible, unless i misunderstood it. So i am trying it in C API. Now i should be able to :-). If there is any better way to do it, i would be happy to know. ---------------------------------------- > Date: Tue, 12 Feb 2008 08:27:05 -0500 > From: seefeld at sympatico.ca > To: c++-sig at python.org > Subject: Re: [C++-sig] Convert C++ Class to exposed class and back > > Marcus Jannes wrote: >> >>> What are you trying to do here ? What is 'c' ? There shouldn't be any >>> need to use PyObject raw pointers at all. Assuming 'ExpClass' has >>> already been exported, the following should Just Work: >>> >>> ExpClass a = ...; >>> bp::object o(a); //<--- now holds a copy of 'a' >>> ... >>> ExpClass b = bp::extract(o); //<--- attempts to extract an >>> // ExpClass from 'o' >>> >>>> }; >> >> Thank you, this seems to go into the right direction, but i need the PyObject pointer for a function like: >> PyEval_CallObject(); > > Why ? Have you studied the boost.python documentation at all ? It offers > everything you need to call a python object from within C++ code, > without having to touch the Python C API. > > (But to answer your question: python::object has a 'ptr()' member > function that returns a raw pointer, if you *really* need it.) > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From roman.yakovenko at gmail.com Tue Feb 12 14:52:43 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 12 Feb 2008 15:52:43 +0200 Subject: [C++-sig] Best practices for C++ project preparation In-Reply-To: References: Message-ID: <7465b6170802120552y7ff2d04ewd372b5e8138e0784@mail.gmail.com> On Feb 12, 2008 1:30 PM, Oliver Schweitzer wrote: > Hi, > > I'm using Py++ to Boost.Python-wrap several medium-scale projects/ > libraries. So far I'm having a good time doing this, learning a lot > about advanced C++, Boost and Python in the process. A key to Py++ is > reading the available documentation carefully, there is a lot in it. > Great stuff. Thank you! > My questions: > > Call policies: There is the odd "deeper" problem popping up, but most > of my current work at wrapping classes seems to come from having to > explicitly prescribe Call Policies for several dozen classes. Is there > a way to adapt design/implementation on the C++ to "help" Py++ at > guessing a good call policy? Any coding convetion should be good enough. Ogre project, for example, has a lot of functions which return "pointer" to some object. Almost all of them return reference to existing object. Python-Ogre code for setting call policies: def Set_DefaultCall_Policies( mb ): mem_funs = mb.calldefs () mem_funs.create_with_signature = True #Generated code will not compile on for mem_fun in mem_funs: if mem_fun.call_policies: continue if not mem_fun.call_policies and (declarations.is_reference (mem_fun.return_type) or declarations.is_pointer (mem_fun.return_type) ): mem_fun.call_policies = call_policies.return_value_policy( call_policies.reference_existing_object ) Another idea is to change the source code: * You can add gccxml attributes to the code: http://gccxml.org/HTML/Running.html * You can embed call policies within the code and parse it. Every declaration has location information ( full file name and line number ). Some comment, near the function, could solve the problem. Also be aware of call policies defaults: http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#defaults > Granularity of Wrapper projects: Having several dozen classes to wrap/ > expose, what is your experience with organizing wrapper projects/ > libraries? Close to the source C++ project/namespaces? There is no policy here. Do what ever you think is best. By the way new version of Py++ contains very good support for multi-module development: http://language-binding.net/pyplusplus/documentation/multi_module_development.html > How many Headers/Classes into one Module/Module-Builder? Take a look on this document: http://language-binding.net/pyplusplus/documentation/split_module.html . The new version of Py++ supports 4 different "split module" strategies: * single file * multiple files * fixed set of multiple files * multiple files, where single class code is split to few files I believe you will find "the only one". >Working exclusive or inclusive, i.e. exposing only carefully selected classes/members or > try to expose all and everything? Both :-): exclude everything, and than include declarations from specific namespaces. Thus when you add "implementation details" you will not have to change the script code. > One goal is having not ever to touch the Py++-generated code, just work in Python and the wrappee lib. It should be possible. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From seefeld at sympatico.ca Tue Feb 12 15:07:22 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 12 Feb 2008 09:07:22 -0500 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: References: <47B194E3.4030204@sympatico.ca> <47B19EA9.8070102@sympatico.ca> Message-ID: <47B1A81A.1060301@sympatico.ca> Marcus Jannes wrote: > Thank you, i think this is exactly what i need. Regarding your question why i want to use it in this way: > It is because i want to convert Python function objects to C++ function pointers which get passed to a another function and this seems to be the way to do it. The boost.python FAQ (see: http://www.boost.org/libs/python/doc/v2/faq.html ) states that it isnt possible, unless i misunderstood it. So i am trying it in C API. Now i should be able to :-). If there is any better way to do it, i would be happy to know. I think you misunderstood. The problem is not with the API, but with the underlying object model: As Dave notes in the FAQ, a (C, C++) function pointer is not an object, and thus has no state to carry around. Unless your function takes not only a function pointer but also some closure argument (which would then carry that state), you are out of luck. In contrast, if you do get to pass a closure argument, you can pass a python (callable) there, and then implement the function whose pointer you pass such that it simply invokes that callable. In either case, the problem is the same, no matter whether you try to solve it with Python's C API or boost.python. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Tue Feb 12 20:07:36 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 12 Feb 2008 20:07:36 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: <47B1A81A.1060301@sympatico.ca> References: <47B194E3.4030204@sympatico.ca> <47B19EA9.8070102@sympatico.ca> <47B1A81A.1060301@sympatico.ca> Message-ID: Okay, let me explain in detail then: I got an existing c++ library where there is a class DerivType which i want exposed to python. There is a function i also want exposed void fEval( ddf_FctPtr f, interval, interval&) where the first parameter is a function pointer which is typedef'ed: typedef DerivType (*ddf_FctPtr)(const DerivType&); I want to do this in python (argument and return type should be of class DerivType): def f(x): x_temp = DerivType(x) return x_temp*x_temp fEval(f,interval1,interval2) Now the wrapper should look something like this: PyObject* _pyfunc_ptr = NULL; DerivType _pycall(const DerivType& d){ DerivType c_result; //build Python data from C++ data: bp::object o(d); result = PyEval_CallObject(_pyfunc_ptr, o.ptr()); c_result = bp::extract(result);//http://www.boost.org/libs/python/doc/v2/extract.html return c_result; }; static PyObject *eval(PyObject *self, PyObject *args){ PyObject *ddf_function; if (!PyArg_ParseTuple(args,"O" ,&ddf_function)) { return NULL; } if(!PyCallable_Check(ddf_function)){ PyErr_Format(PyExc_TypeError,"ddf_function is not callable function"); return NULL; } _pyfunc_ptr = ddf_function; //cache new callback interval i1(10); interval i2; //just for testing fEval(_pycall,i1,i2); return Py_BuildValue(""); }; Well, i still couldn't get this to work at runtime yet. I am not sure if it is even possible, but i got an example from a book where there is a similar case using double data instead of a class (DerivType) and it seems like doing the trick. If this can be done with boost.python instead of C API or you got any other comments please let me know. ---------------------------------------- > Date: Tue, 12 Feb 2008 09:07:22 -0500 > From: seefeld at sympatico.ca > To: c++-sig at python.org > Subject: Re: [C++-sig] Convert C++ Class to exposed class and back > > Marcus Jannes wrote: >> Thank you, i think this is exactly what i need. Regarding your question why i want to use it in this way: >> It is because i want to convert Python function objects to C++ function pointers which get passed to a another function and this seems to be the way to do it. The boost.python FAQ (see: http://www.boost.org/libs/python/doc/v2/faq.html ) states that it isnt possible, unless i misunderstood it. So i am trying it in C API. Now i should be able to :-). If there is any better way to do it, i would be happy to know. > > I think you misunderstood. The problem is not with the API, but with the > underlying object model: As Dave notes in the FAQ, a (C, C++) function > pointer is not an object, and thus has no state to carry around. > Unless your function takes not only a function pointer but also some > closure argument (which would then carry that state), you are out of luck. > > In contrast, if you do get to pass a closure argument, you can pass a > python (callable) there, and then implement the function whose pointer > you pass such that it simply invokes that callable. > > In either case, the problem is the same, no matter whether you try to > solve it with Python's C API or boost.python. > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Kostenlose Messenger Emoticons! Hier downloaden! http://messenger.live.de/mein/ From seefeld at sympatico.ca Tue Feb 12 20:44:00 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 12 Feb 2008 14:44:00 -0500 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: References: <47B194E3.4030204@sympatico.ca> <47B19EA9.8070102@sympatico.ca> <47B1A81A.1060301@sympatico.ca> Message-ID: <47B1F700.6060704@sympatico.ca> Marcus Jannes wrote: > Okay, let me explain in detail then: [...] > Well, i still couldn't get this to work at runtime yet. I am not sure if it is even possible, but i got an example from a book where there is a similar case using double data instead of a class (DerivType) and it seems like doing the trick. If this can be done with boost.python instead of C API or you got any other comments please let me know. Again, it can't be done any less (or more) in boost.python than it can be done with the C API. You still face the same question (which David points out in the FAQ, as you noted): you need to pass some state that needs to be remembered, close to the function (pointer). If the execution of that function is synchronous, i.e. if your C++ library does not intend to store the function pointer and call it later, you may get away by setting some static data during the upcall. However, this won't work if the execution is deferred, as you may call fEval from within python multiple times, each time overriding the closure data set in the previous call. Here is how it *might* work: // remember the current python function bp::object current_callable; // implement suitable ddf_FctPtr that executes // the current python function DerivType call(DerivType const &argument) { bp::object retn = current_callable(argument); return bp::extract(retn); } // The function to be called in Python. The return value is returned directly, not passed back by-reference. DerivType py_fEval(bp::object function, DerivType const &argument) { DerivType retn; current_callable = function; // assume 'call' won't be stored beyond this call, and so we can // be sure 'current_callable' doesn't change its value. fEval(call, argument, retn); return retn; } Now you only need to export 'py_fEval' as 'fEval' to python and you should be all set. Remember: this trick only works if the function pointer won't be retained and called asynchronously, as then 'current_callable' may long have assumed a different value. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From RaoulGough at yahoo.co.uk Tue Feb 12 23:57:20 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Tue, 12 Feb 2008 22:57:20 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <826847.10185.qm@web31102.mail.mud.yahoo.com> References: <826847.10185.qm@web31102.mail.mud.yahoo.com> Message-ID: <47B22450.5060404@yahoo.co.uk> Ralf W. Grosse-Kunstleve wrote: > Hi Raoul, > Nice to hear from you! > Is indexing_v2 fully backward compatible with the current indexing suite? > If not, is it technically feasible to change indexing_v2 so that > it can co-exist with the current indexing suite? > After so many years, I fear too many things will break if indexing_v2 > isn't fully backward compatible. But it would be very nice if it were > generally available. > Ralf > Hi Ralf, thanks for your reply! I think having the two suites co-exist would be the easiest for now. IIRC, there was some discussion back then on replacing the original suite, but you're probably right that it's too late to consider that now. It might also be possible (in theory anyway) to reimplement the original suite on top of the new one, since it was supposed to provide a super-set of functionality. Definitely one thing at a time though! I wonder if Joel de Guzman is still reading this list? -- Cheers, Raoul. From newsuser at stacom-software.de Wed Feb 13 11:05:47 2008 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Wed, 13 Feb 2008 11:05:47 +0100 Subject: [C++-sig] bosst.python Event object wrapped with bp::object() Message-ID: Hello everybody, I Use a C++ thread that is called from the python sides to provoke some activities. The calls set some booleans in the thread object and return. To synchrThreadClassonize the execution in the thread, the idea of me is, to give a Python Event() object as bp::object to the C++ thread, that calls the python "set" attribute after the related activity has finished. Maybe this code is clearer: Python: thread = wrapper.ThreadClass() event = Event() thread.methode(event) event.wait() C++: ThreadClass::methode(bp::object event) { this->myEvent = event ... methodeCalled = true ... } ThreadClass::threadLoop() { ... if (methodeCalled) { ... this->myEvent.attr("set")(); } } The application crashes. If I comment out event.wait() it doesn't crash. Any suggestions or experiances? Thanks a lot Alexander From jlisee at gmail.com Wed Feb 13 18:38:14 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Wed, 13 Feb 2008 17:38:14 +0000 (UTC) Subject: [C++-sig] Python Packages from embedded interpreter References: <5148624c0801131703t5c32a2a7u417b468e2f9a107@mail.gmail.com> Message-ID: I accomplish something similar that I think will solve your problem as well. I have a vehicle package, which has vehicle.MyClass, and vehicle.device.MyClass. The way I expose this is by creating two wrapper modules: _vehicle and _vehicle_device. I then have my source laid out like so: vehicle/ __init__.py (does "from _vehicle import *") device.py (does "from _vehicle_device import *") So I would follow the same strategy for you. Create a "sourcemod" and a "sourcemod_console" wrapper modules. Then you could do something like this in the namespace you run your programs: namespace bp = boost::python // Import sourcemod into the namespace main_namespace["sourcemod"] = bp::import("sourcemod"); // Setup sourcemod.console to equal sourcemod_console bp::setattr(main_namespace["sourcemod"], "console", bp::import("sourcemod_console")) I hope that helps. -Joseph Lisee From rwgk at yahoo.com Wed Feb 13 21:27:13 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 13 Feb 2008 12:27:13 -0800 (PST) Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Message-ID: <502180.14222.qm@web31102.mail.mud.yahoo.com> Hi Chad, Could you at least ask Peter Dimov if he thinks the dont_enable_shared_from_this patch could be generally useful? Maybe he's OK adding it, then it wouldn't be a big deal fixing Boost.Python, which would probably prevent a lot of confusion and lost time in the future. http://www.boost.org/people/peter_dimov.htm p-d-i-m-o-v-at-m-m-l-t-d-dot-n-e-t Ralf ----- Original Message ---- From: Chad Austin To: Development of Python/C++ integration Sent: Monday, February 11, 2008 10:10:31 PM Subject: Re: [C++-sig] Bug and patch for boost.python with enable_shared_from_this There probably is a way to prevent boost.python from creating shared_ptrs with a null deleter like it does, but it would require far more knowledge than I have. :) I agree that it would be a better fix, though. On 2/11/08, Ralf W. Grosse-Kunstleve wrote: > > > > Thanks for the patch! I'd love to check this in for you, but for the > change in shared_ptr.hpp you'll need Peter Dimov's approval, and the > shared_ptr documentation would have to be updated. Also, your reproducer > should be turned into a unit test (in boost/libs/python/test). > > Is there any chance that the shared_ptr patch could somehow be avoided? > > Ralf > > > > ----- Original Message ---- > From: Chad Austin > To: c++-sig at python.org > Sent: Sunday, February 10, 2008 5:14:45 PM > Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this > > Hi all, > > A month ago or so we discovered a bug in Boost.Python that manifests when using enable_shared_from_this. Here is a test case that demonstrates the bug: > > > #include > #include > > using namespace boost; > using namespace boost::python; > > class Test; > typedef shared_ptr TestPtr; > > class Test : public enable_shared_from_this { > public: > static TestPtr construct() { > return TestPtr(new Test); > } > > void act() { > TestPtr kungFuDeathGrip(shared_from_this()); > } > > void take(TestPtr t) { > } > }; > > void Export_test() { > class_("Test") > .def("construct", &Test::construct) > .staticmethod("construct") > > .def("act", &Test::act) > .def("take", &Test::take) > ; > } > > And here is the Python: > > x = Test.construct() > x.take(x) > x.act() > > The bug (as I understand it) is that the shared_ptr_from_python converter creates a new shared_ptr for the Test instance to pass it into C++. This new shared_ptr has a nop deleter, except that it keeps the Python object alive as long as the new shared_ptr is alive. The problem here is that creating a shared_ptr to an object of type T when T is enable_shared_from_this resets the weak pointer inside of enable_shared_from_this. (See shared_ptr's constructors for the details of the implementation.) A fix that passes the test above and has worked for us is to change shared_ptr's constructor to accept a dont_enable_shared_from_this argument and pass that in from the shared_ptr_from_python converter. The patch is attached (against boost 1.33, but the bug didn't look fixed in 1.34 either). > > Cheers, > Chad > > p.s. I have seen other people with this problem as well. Googling for bad_weak_ptr turns up several results. From jannes80 at hotmail.de Thu Feb 14 17:07:48 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Thu, 14 Feb 2008 17:07:48 +0100 Subject: [C++-sig] Convert C++ Class to exposed class and back In-Reply-To: <47B1F700.6060704@sympatico.ca> References: <47B194E3.4030204@sympatico.ca> <47B19EA9.8070102@sympatico.ca> <47B1A81A.1060301@sympatico.ca> <47B1F700.6060704@sympatico.ca> Message-ID: I got it working with my previous C API approach, there were just some bugs like not passing a tuple to the PyEval_CallObject function. Indeed the function pointer does not need to be stored for further use. I might try your suggestion at a later point too, thanks for your help, much appreciated. I think the Boost Python FAQ could be extended in this matter, it isn't that clear or its my lack of english ;-) > Again, it can't be done any less (or more) in boost.python than it can > be done with the C API. You still face the same question (which David > points out in the FAQ, as you noted): you need to pass some state that > needs to be remembered, close to the function (pointer). > > If the execution of that function is synchronous, i.e. if your C++ > library does not intend to store the function pointer and call it later, > you may get away by setting some static data during the upcall. > > However, this won't work if the execution is deferred, as you may call > fEval from within python multiple times, each time overriding the > closure data set in the previous call. > > Here is how it *might* work: > > > // remember the current python function > bp::object current_callable; > > // implement suitable ddf_FctPtr that executes > // the current python function > DerivType call(DerivType const &argument) > { > bp::object retn = current_callable(argument); > return bp::extract(retn); > } > > // The function to be called in Python. The return value is returned > directly, not passed back by-reference. > DerivType py_fEval(bp::object function, DerivType const &argument) > { > DerivType retn; > current_callable = function; > // assume 'call' won't be stored beyond this call, and so we can > // be sure 'current_callable' doesn't change its value. > fEval(call, argument, retn); > return retn; > } > > > Now you only need to export 'py_fEval' as 'fEval' to python and you > should be all set. Remember: this trick only works if the function > pointer won't be retained and called asynchronously, as then > 'current_callable' may long have assumed a different value. > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Neu: Internet Explorer 7 optimiert f?r MSN! http://optimize.de.msn.com/default.aspx?mkt=de-de From RaoulGough at yahoo.co.uk Sat Feb 16 18:18:20 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Sat, 16 Feb 2008 17:18:20 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> Message-ID: <47B71ADC.1030401@yahoo.co.uk> [resending, as it never seemed to appear. apologies if you already have this] Roman Yakovenko wrote: > On Feb 10, 2008 6:42 PM, Raoul Gough wrote: > >> A few years ago I worked on a new implementation of container indexing >> support in Boost.Python, which never made it onto the Boost mainline. I >> seem to remember that Dave had some reservations about the amount of >> detailed documentation on the way the implementation worked, but haven't >> dredged up any old emails on this point. >> >> Since then, I haven't had much time to look at this, so the code has >> always remained on the indexing_v2 branch. Nevertheless, I understand >> that some people are using this code successfully, including pygccxml*, >> so I was wondering if it would now be appropriate to merge this code >> onto the mainline. >> > > Good morning. > > I would like to take this chance and to say thank you - indexing suite > v2 is very cool piece of software. I was even able to fix and add new > features to it. > Hi Roman, Thanks for your comments, and for using the code in the first place! I heard that there were some emails on this list recently about indexing_v2, which is what got me interested again. > Thank you! > > By the way, PyOgre, one of the largest user of py++, is using the new > indexing suite for year and we didn't find any problem with it. > > >> I didn't keep up with the CVS to SVN conversion, so I'm not sure how >> hard this would be to get done. Any opinions or advice on getting this >> started? >> > > Your suite is already in SVN: > http://svn.boost.org/trac/boost/browser/sandbox-tags/indexing_20030918 > http://svn.boost.org/trac/boost/browser/sandbox-tags/indexing_v2 > Ah, OK. I'm kind of new to SVN, but this looks like an earlier sandbox version of the code, before I got it onto a branch in the main repository in CVS. After that I did a lot of work on compiler compatibility, helped by some generous support from Ralf Grosse-Kunstleve, and Dave of course. I see that the branch got "deleted" from SVN back in August 2007 (see http://lists.boost.org/Archives/boost/2007/08/125791.php) but you can still find the most recent version of my indexing code here: http://svn.boost.org/trac/boost/browser/branches/indexing_v2?rev=38549 > Py++ object has "indexing suite v2" source code in its source tree > too. Basically it contains few bug fixes and new features. > > This sounds interesting - I've downloaded Py++-0.9.5.zip from https://sourceforge.net/project/showfiles.php?group_id=118209 and can see the indexing suite code in there alright. Does this work with the latest versions of Boost, or do you need to use the version (1_31_0) that indexing_v2 was originally developed with? -- Cheers, Raoul. From roman.yakovenko at gmail.com Sat Feb 16 21:46:35 2008 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 16 Feb 2008 22:46:35 +0200 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <47B71ADC.1030401@yahoo.co.uk> References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> <47B71ADC.1030401@yahoo.co.uk> Message-ID: <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> On Feb 16, 2008 7:18 PM, Raoul Gough wrote: > Hi Roman, > > Thanks for your comments, and for using the code in the first place! You are kidding, right? Without it the life was much harder :-) > I heard that there were some emails on this list recently about > indexing_v2, which is what got me interested again. indexing_v2 suite could be a very valuable addition to the library. > This sounds interesting - I've downloaded Py++-0.9.5.zip from > https://sourceforge.net/project/showfiles.php?group_id=118209 and can > see the indexing suite code in there alright. Does this work with the > latest versions of Boost Yes. I am using 1.33 & 1.34 and it is fine. > or do you need to use the version (1_31_0) > that indexing_v2 was originally developed with? No, you don't need. Today library works pretty well with VC 2005 and gcc 4.0 and 4.1. It works on Windows, Linux and MAC. Gustavo Carneiro also made it work on 64 bit system, with Python 2.5 P.S. May be you can submit the new suite for review. In this case I can help with writing tests. I am sure, I will need some guideline from you. P.S 2. Can you upload somewhere the images from the documentation. The images in the label could not be opened for some reason. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From rogeeff at gmail.com Mon Feb 18 19:24:55 2008 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Mon, 18 Feb 2008 13:24:55 -0500 Subject: [C++-sig] Logging library review is finished. Really. Message-ID: Phew! That's was quite interresting discussion. Thanks again to everyone participated. Due to large number of huge reviews and some number of enourmous, I'll need some time to mull over it to make a decision. Gennadiy From RaoulGough at yahoo.co.uk Mon Feb 18 23:13:08 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Mon, 18 Feb 2008 22:13:08 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> <47B71ADC.1030401@yahoo.co.uk> <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> Message-ID: <47BA02F4.803@yahoo.co.uk> Roman Yakovenko wrote: > On Feb 16, 2008 7:18 PM, Raoul Gough wrote: [snip] >> Does this work with the latest versions of Boost >> > > Yes. I am using 1.33 & 1.34 and it is fine. > > Hey, that's good news. I was a bit worried that some incompatible changes might have broken the code in the mean time (since it was never integrated into the official build). >> or do you need to use the version (1_31_0) >> that indexing_v2 was originally developed with? >> > > No, you don't need. Today library works pretty well with VC 2005 and > gcc 4.0 and 4.1. > It works on Windows, Linux and MAC. Gustavo Carneiro also made it work > on 64 bit system, > with Python 2.5 > > P.S. May be you can submit the new suite for review. In this case I > can help with writing tests. > I am sure, I will need some guideline from you. > Sounds good to me! I'm only going to get a small amount of time to work on this in the next month or so, and I've got to get my local build working on my new system. After that I should be able to spend a bit more time on this and get something ready for review. Any help along the way would be appreciated! > P.S 2. Can you upload somewhere the images from the documentation. The > images in the label could not be opened > for some reason. > The diagrams are in SVN as .PNG files, so you should be able to see them if you do the right svn operations on a working copy of the repository, but I guess they're not going to work via the SVN web interface. Anyway, for convenience I've uploaded the docco onto my website for now (unchanged from back in 2004): http://home.clara.net/raoulgough/boost/containers.html I've also found the original Visio sources for the diagrams in an archive of mine, but don't have a working copy of Visio any more (I've migrated to Mac). I'll see what I can do about turning these into .svg files or some other open standard. Any suggested formats? -- Cheers, Raoul. From ndbecker2 at gmail.com Tue Feb 19 04:20:23 2008 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 18 Feb 2008 22:20:23 -0500 Subject: [C++-sig] Merging indexing_v2 to mainline References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> <47B71ADC.1030401@yahoo.co.uk> <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> <47BA02F4.803@yahoo.co.uk> Message-ID: Raoul Gough wrote: > > I've also found the original Visio sources for the diagrams in an > archive of mine, but don't have a working copy of Visio any more (I've > migrated to Mac). I'll see what I can do about turning these into .svg > files or some other open standard. Any suggested formats? > I have visio on a virtual machine. Not sure what I can convert it to, unless you'd like pdf. From walter at mathematik.hu-berlin.de Tue Feb 19 11:48:44 2008 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Tue, 19 Feb 2008 11:48:44 +0100 (CET) Subject: [C++-sig] pass float from python to c++ as reference Message-ID: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> Hello, I need to pass a float from Python to C++ as a reference. What is the best way to do that? I can't find it in the unit tests: boost_1_34_1/libs/python/test/test_builtin_converters.cpp /* by_reference.cpp */ #include void by_reference(double &x){ x = 23.; } BOOST_PYTHON_MODULE(mymodule) { using namespace boost::python; def("by_reference", by_reference); } /* by_reference.py */ import mymodule x = 1. print x mymodule.by_reference(x) print x /* output */ >>Traceback (most recent call last): >> File "./test.py", line 7, in >> mymodule.by_reference(x) >>Boost.Python.ArgumentError: Python argument types in >> mymodule.by_reference(float) >>did not match C++ signature: >> by_reference(double {lvalue}) thanks in advance, Sebastian Walter From seefeld at sympatico.ca Tue Feb 19 12:39:22 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 19 Feb 2008 06:39:22 -0500 Subject: [C++-sig] pass float from python to c++ as reference In-Reply-To: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> References: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> Message-ID: <47BABFEA.6010907@sympatico.ca> Sebastian Walter wrote: > Hello, > I need to pass a float from Python to C++ as a reference. What is the best > way to do that? You can't. You can't even do that within Python, as floats are immutable. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From gjcarneiro at gmail.com Tue Feb 19 12:58:49 2008 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 19 Feb 2008 11:58:49 +0000 Subject: [C++-sig] pass float from python to c++ as reference In-Reply-To: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> References: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> Message-ID: On 19/02/2008, Sebastian Walter wrote: > > Hello, > I need to pass a float from Python to C++ as a reference. What is the best > way to do that? I can't find it in the unit tests: > boost_1_34_1/libs/python/test/test_builtin_converters.cpp > > > /* by_reference.cpp */ > #include > > void by_reference(double &x){ > x = 23.; > } I do not know anything boost::python specific, but generally the way to handle references in language bindings is: 1- You tell the language bindings the "direction" of the parameter in question. Direction can be in/out/inout. 2- The wrapper needs convert an input float parameter, before calling the C++ function, if direction is in or inout; 3- The wrapper needs to return the float parameter to the caller (either as a single value or in a tuple), when returning, if direction is inout or out. So it may be true that BP does not support this (I saw Stefan's email), but it is not true that it cannot be supported (pybindgen does it). In your example: void by_reference(double &x){ x = 23.; } Could be mapped into python as: x = by_reference (); -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From jannes80 at hotmail.de Tue Feb 19 14:33:57 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 19 Feb 2008 14:33:57 +0100 Subject: [C++-sig] How to check if object is of specific type? Message-ID: Hello, I want to do something similar to the PyObject_TypeCheck() in boost.python. How can i check the type of an object that is passed to a function? I tried: myClass dummy; bp::object py_dummy(dummy); PyTypeObject* myType = (PyTypeObject*)py_dummy.ptr(); PyObject_TypeCheck(objToCheck, myType); //objToCheck is a PyObject* but it always returns false. _________________________________________________________________ Windows Live Fotogalerie: So einfach organisieren Sie Ihre Fotos! http://get.live.com/photogallery/overview From seefeld at sympatico.ca Tue Feb 19 15:25:27 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 19 Feb 2008 09:25:27 -0500 Subject: [C++-sig] How to check if object is of specific type? In-Reply-To: References: Message-ID: <47BAE6D7.8060304@sympatico.ca> Marcus Jannes wrote: > Hello, > > I want to do something similar to the PyObject_TypeCheck() in boost.python. How can i check the type of an object that is passed to a function? object o = ...; extract e(o); if (e.check()) { expected_type a = e(); // now use 'a' } HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jannes80 at hotmail.de Tue Feb 19 16:05:19 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Tue, 19 Feb 2008 16:05:19 +0100 Subject: [C++-sig] How to check if object is of specific type? In-Reply-To: <47BAE6D7.8060304@sympatico.ca> References: <47BAE6D7.8060304@sympatico.ca> Message-ID: Thank you, exactly what i needed :-) ---------------------------------------- > Date: Tue, 19 Feb 2008 09:25:27 -0500 > From: seefeld at sympatico.ca > To: c++-sig at python.org > Subject: Re: [C++-sig] How to check if object is of specific type? > > Marcus Jannes wrote: >> Hello, >> >> I want to do something similar to the PyObject_TypeCheck() in boost.python. How can i check the type of an object that is passed to a function? > > object o = ...; > extract e(o); > if (e.check()) > { > expected_type a = e(); > // now use 'a' > } > > HTH, > Stefan > > -- > > ...ich hab' noch einen Koffer in Berlin... > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig _________________________________________________________________ Neu: Internet Explorer 7 optimiert f?r MSN! http://optimize.de.msn.com/default.aspx?mkt=de-de From matthew.scouten at gmail.com Tue Feb 19 16:41:58 2008 From: matthew.scouten at gmail.com (Matthew Scouten) Date: Tue, 19 Feb 2008 09:41:58 -0600 Subject: [C++-sig] pass float from python to c++ as reference In-Reply-To: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> References: <25095.141.20.54.120.1203418124.squirrel@webmail.mathematik.hu-berlin.de> Message-ID: <3dc9bcf00802190741q40165369yd14d8747cbd5fee8@mail.gmail.com> You can do something like this, if you do not mind cluttering up the interface on the python side: struct DoubleByReference { public: inline DoubleByReference(){;} inline DoubleByReference(double num):value_(num) {;} inline DoubleByReference(const DoubleByReference & rhs) {value_ = rhs.value_;} inline double* address() {return &value_;} inline double& ref() {return value_;} double get_value() {return value_;} void set_value(double value) {value_ = value;} private: double value_; }; class_("DoubleByReference") .def(init<>()) .def(init()) .add_property("value", &IntByReference::get_value, &IntByReference::set_value) ; void by_reference_wrapper(DoubleByReference &x){ by_reference(x.ref()); Like I said, it's not pretty, but it works. On Feb 19, 2008 4:48 AM, Sebastian Walter wrote: > Hello, > I need to pass a float from Python to C++ as a reference. What is the best > way to do that? I can't find it in the unit tests: > boost_1_34_1/libs/python/test/test_builtin_converters.cpp > > > /* by_reference.cpp */ > #include > > void by_reference(double &x){ > x = 23.; > } > BOOST_PYTHON_MODULE(mymodule) > { > using namespace boost::python; > def("by_reference", by_reference); > } > > > > /* by_reference.py */ > import mymodule > > x = 1. > print x > mymodule.by_reference(x) > print x > > /* output */ > >>Traceback (most recent call last): > >> File "./test.py", line 7, in > >> mymodule.by_reference(x) > >>Boost.Python.ArgumentError: Python argument types in > >> mymodule.by_reference(float) > >>did not match C++ signature: > >> by_reference(double {lvalue}) > > > > thanks in advance, > Sebastian Walter > > _______________________________________________ > 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 jannes80 at hotmail.de Wed Feb 20 14:41:57 2008 From: jannes80 at hotmail.de (Marcus Jannes) Date: Wed, 20 Feb 2008 14:41:57 +0100 Subject: [C++-sig] Check number of arguments of a function object ? Message-ID: Hi again, if i have a callable function object (PyObject*), how can i check the number of arguments this object has? PyArg_ParseTuple does not seem to accomplish this. def f(x): <- 1 argument def f(x,y): <- 2 arguments I want to make sure only functions with one argument get processed. _________________________________________________________________ Windows Live Fotogalerie: So einfach organisieren Sie Ihre Fotos! http://get.live.com/photogallery/overview From seefeld at sympatico.ca Wed Feb 20 15:31:10 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 20 Feb 2008 09:31:10 -0500 Subject: [C++-sig] Check number of arguments of a function object ? In-Reply-To: References: Message-ID: <47BC39AE.2010300@sympatico.ca> Marcus Jannes wrote: > Hi again, > > if i have a callable function object (PyObject*), how can i check the number of arguments this object has? > PyArg_ParseTuple does not seem to accomplish this. (You keep asking questions about the Python C API. There must be other lists about that. This list is about Python <-> C++ integration, and in particular, boost.python. Please do yourself a favor and try using that.) > def f(x): <- 1 argument > def f(x,y): <- 2 arguments What you mean here is 'parameter', not 'argument'. (A function parameter is part of the function's definition, while and argument is what gets passed to a function call.) Also, what about def f(x, y=None): pass ? The function has two parameters, but it is valid to call it with either one or two arguments. Further, inside the function implementation (no matter whether Python, C, or C++), you don't know whether an argument was actually passed or is a default value. > I want to make sure only functions with one argument get processed. Can you rephrase that ? Do you mean 'function calls' instead of 'functions' ? And what do you mean by 'get processed' ? In particular, what should happen when there are multiple arguments ? Should they get ignored ? An exception raised ? You may be interested into http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading but it isn't clear from your description whether that is what you are after. HTH, Stefan -- ...ich hab' noch einen Koffer in Berlin... From claudius.kehrhahn at gmx.de Thu Feb 21 22:58:28 2008 From: claudius.kehrhahn at gmx.de (Claudius Kehrhahn) Date: Thu, 21 Feb 2008 22:58:28 +0100 Subject: [C++-sig] boost.python and MinGW3.4.2 with eclipse Message-ID: <47BDF404.30507@gmx.de> I am a newbie to python, MinGW and eclipse. My background: I have a lot experience in c++ with Visual Studio and embedded programming with other compilers. So, learning python is no really problem. I installed the MinGW 3.4.2 package, python 2.5, boost_1_34_1 and eclipse 3.3 with cdt 4.x. I set a lot of constants for the path's to lib and include directories, compiled the boost libraries/dlls with mingw. Then I started the tutorial of boost with the regex example. I had no problems with bjam as well with the following commands g++ -I P:\Programme\boost_1_34_1 example.cpp -o example -L P:\Programme\boost_1_34_1\lib\ -lboost_regex-mgw34-mt-d-1_34_1 and g++ -I P:\Programme\boost_1_34_1 example.cpp -o example P:\Programme\boost_1_34_1\lib\libboost_regex-mgw34-mt-d-1_34_1 but when I compiled and linked the example with eclipse I got the output: **** Internal Builder is used for build **** g++ -IP:\Programme\boost_1_34_1 -O0 -c -fmessage-length=0 -oexample.o ..\example.cpp g++ P:\Programme\boost_1_34_1\lib\libboost_regex-mgw34-mt-d-1_34_1.a -oTest_boost_libs.exe example.o example.o(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7_j[boost::basic_regex > >::assign(char const*, char const*, unsigned int)]+0x22):example.cpp: undefined reference to `boost::basic_regex > >::do_assign(char const*, char const*, unsigned int)' collect2: ld returned 1 exit status Build error occurred, build is stopped Furthermore I got lot of problems when I try to compile the python tutorial 'hello.cpp'. I got massive compiler errors for the headerfiles in ..\boost\python\ Can anyone give me any hint how to continue? Thanks in advance. Claudius From raoulgough at yahoo.co.uk Thu Feb 21 23:25:12 2008 From: raoulgough at yahoo.co.uk (Raoul Gough) Date: Thu, 21 Feb 2008 22:25:12 +0000 (GMT) Subject: [C++-sig] boost.python and MinGW3.4.2 with eclipse In-Reply-To: <47BDF404.30507@gmx.de> Message-ID: <354517.1346.qm@web25503.mail.ukl.yahoo.com> [I think this is probably off-topic on this list - the c++-sig is for Python/C++ integration, not boost topics in general] --- Claudius Kehrhahn wrote: [snip] > Then I started the tutorial of boost with the regex example. I had no > > problems with bjam as well with the following commands > > g++ -I P:\Programme\boost_1_34_1 example.cpp -o example -L > P:\Programme\boost_1_34_1\lib\ -lboost_regex-mgw34-mt-d-1_34_1 > and > g++ -I P:\Programme\boost_1_34_1 example.cpp -o example > P:\Programme\boost_1_34_1\lib\libboost_regex-mgw34-mt-d-1_34_1 > > but when I compiled and linked the example with eclipse I got the > output: > > **** Internal Builder is used for build **** > g++ -IP:\Programme\boost_1_34_1 -O0 -c -fmessage-length=0 -oexample.o > > ..\example.cpp > g++ P:\Programme\boost_1_34_1\lib\libboost_regex-mgw34-mt-d-1_34_1.a > -oTest_boost_libs.exe example.o This link command won't work because the arguments are in the wrong order. You need to put the objects with unresolved symbols first, so the linker knows what symbols it's looking for when it processes the library archive*. No idea why Eclipse would be getting this wrong. * Actually there's another way to do it by wrapping linker arguments in ( and ) but you only need to do that if there are circular dependencies between archives, which you never want anyway. > > > Furthermore I got lot of problems when I try to compile the python > tutorial 'hello.cpp'. I got massive compiler errors for the > headerfiles > in ..\boost\python\ > > Can anyone give me any hint how to continue? Don't know, but you'd be better off asking on one of the general boost mailing lists than here. -- Cheers, Raoul. ___________________________________________________________ Rise to the challenge for Sport Relief with Yahoo! For Good http://uk.promotions.yahoo.com/forgood/ From RaoulGough at yahoo.co.uk Thu Feb 21 22:32:32 2008 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 21 Feb 2008 21:32:32 +0000 Subject: [C++-sig] Merging indexing_v2 to mainline In-Reply-To: References: <47AF2963.4060100@yahoo.co.uk> <7465b6170802102217k5d0af871hade1985d4a9ac18e@mail.gmail.com> <47B71ADC.1030401@yahoo.co.uk> <7465b6170802161246r3214ff85h245866930dc201db@mail.gmail.com> <47BA02F4.803@yahoo.co.uk> Message-ID: <47BDEDF0.6080905@yahoo.co.uk> [resending, apologies if you've seen this already. Must be something wrong with my mail agent] Neal Becker wrote: > Raoul Gough wrote: > >> I've also found the original Visio sources for the diagrams in an >> archive of mine, but don't have a working copy of Visio any more (I've >> migrated to Mac). I'll see what I can do about turning these into .svg >> files or some other open standard. Any suggested formats? >> >> > I have visio on a virtual machine. Not sure what I can convert it to, > unless you'd like pdf. > > Hi Neal, if you're offering to do the conversion for me, that would be quite a help! I'd be able to edit the diagrams as .svg files (Scalable Vector Graphics) using Inkscape, and I believe Visio can export in this format. I've uploaded the original .vsd file here: http://home.clara.net/raoulgough/boost/suite_overview.vsd If you get a chance, could you email me back a converted .svg file (or files) from this? -- Cheers, Raoul. From swiftcoder at gmail.com Sun Feb 24 13:41:15 2008 From: swiftcoder at gmail.com (Tristam MacDonald) Date: Sun, 24 Feb 2008 07:41:15 -0500 Subject: [C++-sig] Boost Python and ctypes Message-ID: I am trying to bridge two libraries, one a C library bound into python using ctypes, and the other a C++ library using Boost Python. In the C++ library, I have a class similar to the following, with a member function that returns a pointer to an internal buffer. struct Test { float data[16]; float *get_data() {return data;} } I have wrapped this in a seeming logical way: BOOST_MODULE(test) { class_("Test") .def("get_data", &Test::get_data, return_value_policy(); } Which suffices to retrieve a "float *" instance from Python. However, I need to pass this pointer to a ctypes-bound function: void some_function(float *); I can call this function from python without any trouble, using a ctypes created buffer: buffer = (c_float * 16) some_function(buffer) However, when I attempt to pass the result of get_data() into this function, ctypes causes an error because Boost Python's "float *" type does not match ctypes' POINTER(c_float) type.?Equally, ctypes' cast() function doesn't work to coerce the pointer type, because it doesn't recognise the "float *" type either. Does anyone have a workaround to coerce these types (which each contain the same underlying pointer) together? Thanks in advance for any suggestions, - Tristam From jlisee at gmail.com Tue Feb 26 20:34:24 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Tue, 26 Feb 2008 19:34:24 +0000 (UTC) Subject: [C++-sig] Boost Python and ctypes References: Message-ID: I don't know how to integrate this into Boost.Python in a clean way, but here is a litter terminal example that can help: >>> array = (ctypes.c_int * 3)(1,2,3) >>> addr = ctypes.addressof(array) >>> arrayPtr = ctypes.cast(addr, ctypes.POINTER((ctypes.c_int))) >>> array[0] 1 >>> arrayPtr[0] 1 So basically if you can get a long value into python representing the address of your float array you are good to go. This is done in Python-Ogre by just wrapping a manual cast function: unsigned long castToAddress(float* ptr) { return (unsigned long)ptr; } A more permanent way to do this would be to change your wrapper to execute this code with Boost.Python's C++ python API interface (not tested): bp::object convertFloat(float* ptr) { bp::object ctypes = bp::import("ctypes"); bp::long addr((unsigned addr)ptr); bp::object pointerType(ctypes["POINTER"](ctypes["c_float"])); return ctypes["cast"](addr, pointerType); } I believe you can do this by specifying a manual to python convert for the "float*" type. Hope that helps, Joseph Lisee From jlisee at gmail.com Tue Feb 26 21:42:47 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Tue, 26 Feb 2008 20:42:47 +0000 (UTC) Subject: [C++-sig] Check number of arguments of a function object ? References: Message-ID: Marcus, This is not tested but this should do what you want, python example first: >>> def func(a): ... pass ... >>> func.func_code.co_argcount 1 >>> def func(a,b): ... pass ... >>> func.func_code.co_argcount 2 Some (untested) code to do this in Boost.Python: bool hasTwoArgs(bp::object callable) { try { int argCount = bp::extract(callable["func_code"]["co_argcount"]); if (2 != argCount) return false; } catch (bp::error_already_set e) { // Catch mallformed function objects return false; } return true; } -Joseph Lisee From swiftcoder at gmail.com Tue Feb 26 21:49:41 2008 From: swiftcoder at gmail.com (Tristam MacDonald) Date: Tue, 26 Feb 2008 15:49:41 -0500 Subject: [C++-sig] Boost Python and ctypes In-Reply-To: References: Message-ID: <8bdb0d630802261249i436be153qc4266d6ba4b8b11d@mail.gmail.com> Thank you for the prompt answer - that accomplishes exactly what I was trying to do! I haven't had a lot of luck tracking down the hooks to add a manual conversion for 'float *' into the types registry, do you have any reference for that handy? - Tristam On 26/02/2008, Joseph Lisee wrote: > > I don't know how to integrate this into Boost.Python in a clean way, but > here > is a litter terminal example that can help: > > >>> array = (ctypes.c_int * 3)(1,2,3) > >>> addr = ctypes.addressof(array) > >>> arrayPtr = ctypes.cast(addr, ctypes.POINTER((ctypes.c_int))) > >>> array[0] > 1 > >>> arrayPtr[0] > 1 > > So basically if you can get a long value into python representing the > address > of your float array you are good to go. This is done in Python-Ogre by > just > wrapping a manual cast function: > > unsigned long castToAddress(float* ptr) > { > return (unsigned long)ptr; > } > > A more permanent way to do this would be to change your wrapper to execute > this code with Boost.Python's C++ python API interface (not tested): > > bp::object convertFloat(float* ptr) > { > bp::object ctypes = bp::import("ctypes"); > > bp::long addr((unsigned addr)ptr); > bp::object pointerType(ctypes["POINTER"](ctypes["c_float"])); > > return ctypes["cast"](addr, pointerType); > } > > I believe you can do this by specifying a manual to python convert for the > "float*" type. > > Hope that helps, > Joseph Lisee > > _______________________________________________ > 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 jlisee at gmail.com Tue Feb 26 22:09:24 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Tue, 26 Feb 2008 21:09:24 +0000 (UTC) Subject: [C++-sig] Boost Python and ctypes References: <8bdb0d630802261249i436be153qc4266d6ba4b8b11d@mail.gmail.com> Message-ID: > Thank you for the prompt answer - that accomplishes exactly what I was trying to do! > I haven't had a lot of luck tracking down the hooks to add a manual conversion for 'float *' into the types registry, do you have any reference for that handy? > > - Tristam No problem, I think this is what you are looking for: http://www.boost.org/libs/python/doc/v2/to_python_converter.html -Joseph Lisee From jlisee at gmail.com Tue Feb 26 22:42:24 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Tue, 26 Feb 2008 21:42:24 +0000 (UTC) Subject: [C++-sig] Check number of arguments of a function object ? References: Message-ID: And responding to my self, So I wanted to get this done for my project and I am sharing the code. This is a functor class with checks the argument count. Its for an event system and it has been tested. The following is public domain: /// ------------------------ EventFunctor.h ----------------------------- /// /** Wraps a called python object, so it can handle events * * Then given python object is checked to make sure its calledable and has * the proper number of arguments on functor creation. */ class EventFunctor { public: EventFunctor(boost::python::object pyObject); void operator()(EventPtr event); /** The callable python object which is called to handle the event */ boost::python::object pyFunction; }; /// ----------------------- EventFunctor.cpp ---------------------------- /// #include #include "EventFunctor.h" namespace bp = boost::python; EventFunctor::EventFunctor(bp::object pyObject) : pyFunction(pyObject) { bool bad = false; // Check to make sure its a callable object if (0 == PyObject_HasAttrString(pyObject.ptr(), "__call__")) { // If not, lets throw an exception to warn the user PyErr_SetString(PyExc_TypeError, "Handler must be a callable object"); bad = true; } else { int expectedArgs = 1; // Handle function objects vs. functions // * Free python functions have a 'func_code' attributes // * For python function objects, their __call__ method has func_code bp::object func_code; if (0 == PyObject_HasAttrString(pyObject.ptr(), "func_code")) { // Function object, need to increment count for 'self' expectedArgs += 1; func_code = pyObject.attr("__call__").attr("func_code"); } else { func_code = pyObject.attr("func_code"); // Handle instancemethod type callable if (0 != PyObject_HasAttrString(pyObject.ptr(), "im_self")) expectedArgs += 1; } int argCount = bp::extract(func_code.attr("co_argcount")); // 0x4 in the flags means we have a function signature with *args int flags = bp::extract(func_code.attr("co_flags")); // To many arguments if (argCount > expectedArgs) { PyErr_SetString(PyExc_TypeError, "Handler has to many args, expected 1"); bad = true; } // To few arguments and no "*args" in signature else if ((argCount < expectedArgs) && !(flags & 4)) { PyErr_SetString(PyExc_TypeError, "Handler has too few args, expected 1"); bad = true; } } if (bad) bp::throw_error_already_set(); } void EventFunctor::operator()(EventPtr event) { pyFunction(event); } -Joseph Lisee From swiftcoder at gmail.com Tue Feb 26 23:05:05 2008 From: swiftcoder at gmail.com (Tristam MacDonald) Date: Tue, 26 Feb 2008 17:05:05 -0500 Subject: [C++-sig] Boost Python and ctypes In-Reply-To: References: <8bdb0d630802261249i436be153qc4266d6ba4b8b11d@mail.gmail.com> Message-ID: <8bdb0d630802261405r25137512o5e0c6c0caa6f723d@mail.gmail.com> Now we are into the dizzying world of template error messages :) So I have a class Matrix, which exposes a pointer to float, and a conversion operator to POINTER(c_float): struct Matrix { int test(); float *ptr(); }; struct ctypes_float_ptr { static PyObject *convert(float *ptr) { object ctypes = import("ctypes"); long_ addr((unsigned)ptr); object pointerType(ctypes["POINTER"](ctypes["c_float"])); return ctypes["cast"](addr, pointerType).ptr(); } }; BOOST_PYTHON_MODULE(math) { to_python_converter(); class_("Matrix") .def("test", &Matrix::test) // this compiles fine .def("ptr", &Matrix::ptr) // error here ; } And the error is as follows: src/math.cpp:146: error: no matching function for call to 'boost::python::class_::def(const char [4], )' Any pointers on where to go from here? On 26/02/2008, Joseph Lisee wrote: > > > Thank you for the prompt answer - that accomplishes exactly what I was > trying > to do! > > I haven't had a lot of luck tracking down the hooks to add a manual > conversion > for 'float *' into the types registry, do you have any reference for that > handy? > > > > - Tristam > > > No problem, I think this is what you are looking for: > http://www.boost.org/libs/python/doc/v2/to_python_converter.html > > > -Joseph Lisee > > > _______________________________________________ > 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 jlisee at gmail.com Wed Feb 27 23:22:51 2008 From: jlisee at gmail.com (Joseph Lisee) Date: Wed, 27 Feb 2008 22:22:51 +0000 (UTC) Subject: [C++-sig] bosst.python Event object wrapped with bp::object() References: Message-ID: Alexander Eisenhuth stacom-software.de> writes: > ThreadClass::threadLoop() > { > ... > if (methodeCalled) { > ... > this->myEvent.attr("set")(); > } > > } You can't do this. The Python C API (and therefore Boost.Python's) is not thread safe. If threadloop is running in another thread along side the one the Python interpreter is running in, accessing a Python object at the same time will result in a crash. You should wrap a C++ class, which has a set member that can be accessed from Python. That way in C++ you can do: "this->myEvent.set();" Then later in python you can access the value. -Joe From walter at mathematik.hu-berlin.de Thu Feb 28 13:26:24 2008 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Thu, 28 Feb 2008 13:26:24 +0100 Subject: [C++-sig] boost.python: when does python call c++ destructors? Message-ID: <200802281326.24585.walter@mathematik.hu-berlin.de> Hello, I have compiled a python module with boost.python that exposes the functionality of a c++ class that has a constructor and destructor and an overloaded operator*. The complete c++ code and wrapper can be found at the bottom of this email: But at first the python script that gives me headaches: /* test.py */ /*-----------*/ #!/usr/bin/env python import myclass a = myclass.asdf() b = myclass.asdf() c = a * b d = a * c /* output of test.py */ /*-----------------------*/ wronski(walter):~/workspace/code_tests/boost_python> ./test.py called constructor with loc: 0 called constructor with loc: 1 called operator* with locs: (0,1) called constructor with loc: 2 called destructor with loc: 2 ?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! called operator* with locs: (0,2) called constructor with loc: 2 called destructor with loc: 2 called destructor with loc: 0 called destructor with loc: 2 called destructor with loc: 1 called destructor with loc: 2 The problem that I don't understand: a*b calls the constructor of a temporary object that is assigned loc=2 and then directly after that the destructor is called! ...? I expected the new temporary object to get assigned to the name c! What bugs me even more is that there are 4 constructor calls but 6!! destructor calls! How can this happen? Is there something im overlooking? Is this intended behavior of Python/Boost.Python ? How could I avoid it? thanks in advance, Sebastian Walter The corresponding boost.python wrapper and c++ code: /* mainclass.hpp */ /*----------------------*/ #ifndef MAINCLASS_HPP #define MAINCLASS_HPP #include #include using namespace std; class asdf{ public: int loc; asdf(); ~asdf(); friend const asdf operator*(const asdf &lhs, const asdf &rhs); }; #endif /* mainclass.cpp */ /*----------------------*/ #include "mainclass.hpp" int global_int=0; asdf::asdf(){ loc = global_int; cout<<"called constructor with loc:\t"<("asdf") .def(self * self) ; } From e.tadeu at gmail.com Thu Feb 28 20:45:32 2008 From: e.tadeu at gmail.com (Edson Tadeu) Date: Thu, 28 Feb 2008 16:45:32 -0300 Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this In-Reply-To: <502180.14222.qm@web31102.mail.mud.yahoo.com> References: <502180.14222.qm@web31102.mail.mud.yahoo.com> Message-ID: Any news on this issue? Will this patch get into Boost 1.35? Thanks, Edson On Wed, Feb 13, 2008 at 5:27 PM, Ralf W. Grosse-Kunstleve wrote: > Hi Chad, > > Could you at least ask Peter Dimov if he thinks the > dont_enable_shared_from_this patch could be generally useful? > Maybe he's OK adding it, then it wouldn't be a big deal > fixing Boost.Python, which would probably prevent a lot of > confusion and lost time in the future. > > http://www.boost.org/people/peter_dimov.htm > p-d-i-m-o-v-at-m-m-l-t-d-dot-n-e-t > > Ralf > > ----- Original Message ---- > From: Chad Austin > To: Development of Python/C++ integration > Sent: Monday, February 11, 2008 10:10:31 PM > Subject: Re: [C++-sig] Bug and patch for boost.python with > enable_shared_from_this > > There probably is a way to prevent boost.python from creating > shared_ptrs with a null deleter like it does, but it would require far > more knowledge than I have. :) > > I agree that it would be a better fix, though. > > On 2/11/08, Ralf W. Grosse-Kunstleve wrote: > > > > > > > > Thanks for the patch! I'd love to check this in for you, but for the > > change in shared_ptr.hpp you'll need Peter Dimov's approval, and the > > shared_ptr documentation would have to be updated. Also, your reproducer > > should be turned into a unit test (in boost/libs/python/test). > > > > Is there any chance that the shared_ptr patch could somehow be avoided? > > > > Ralf > > > > > > > > ----- Original Message ---- > > From: Chad Austin > > To: c++-sig at python.org > > Sent: Sunday, February 10, 2008 5:14:45 PM > > Subject: [C++-sig] Bug and patch for boost.python with > enable_shared_from_this > > > > Hi all, > > > > A month ago or so we discovered a bug in Boost.Python that manifests > when using enable_shared_from_this. Here is a test case that demonstrates > the bug: > > > > ... > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at yahoo.com Thu Feb 28 22:20:02 2008 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 28 Feb 2008 13:20:02 -0800 (PST) Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Message-ID: <229148.259.qm@web31108.mail.mud.yahoo.com> No news that I'm aware of. I'd be happy to check in patches, but someone else has to take the lead in communicating with Peter, and updating the unit tests. Ralf ----- Original Message ---- From: Edson Tadeu To: Development of Python/C++ integration Sent: Thursday, February 28, 2008 11:45:32 AM Subject: Re: [C++-sig] Bug and patch for boost.python with enable_shared_from_this Any news on this issue? Will this patch get into Boost 1.35? Thanks, Edson On Wed, Feb 13, 2008 at 5:27 PM, Ralf W. Grosse-Kunstleve wrote: Hi Chad, Could you at least ask Peter Dimov if he thinks the dont_enable_shared_from_this patch could be generally useful? Maybe he's OK adding it, then it wouldn't be a big deal fixing Boost.Python, which would probably prevent a lot of confusion and lost time in the future. http://www.boost.org/people/peter_dimov.htm p-d-i-m-o-v-at-m-m-l-t-d-dot-n-e-t Ralf ----- Original Message ---- From: Chad Austin To: Development of Python/C++ integration Sent: Monday, February 11, 2008 10:10:31 PM Subject: Re: [C++-sig] Bug and patch for boost.python with enable_shared_from_this There probably is a way to prevent boost.python from creating shared_ptrs with a null deleter like it does, but it would require far more knowledge than I have. :) I agree that it would be a better fix, though. On 2/11/08, Ralf W. Grosse-Kunstleve wrote: > > > > Thanks for the patch! I'd love to check this in for you, but for the > change in shared_ptr.hpp you'll need Peter Dimov's approval, and the > shared_ptr documentation would have to be updated. Also, your reproducer > should be turned into a unit test (in boost/libs/python/test). > > Is there any chance that the shared_ptr patch could somehow be avoided? > > Ralf > > > > ----- Original Message ---- > From: Chad Austin > To: c++-sig at python.org > Sent: Sunday, February 10, 2008 5:14:45 PM > Subject: [C++-sig] Bug and patch for boost.python with enable_shared_from_this > > Hi all, > > A month ago or so we discovered a bug in Boost.Python that manifests when using enable_shared_from_this. Here is a test case that demonstrates the bug: > > ... -----Inline Attachment Follows----- _______________________________________________ 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 j.reid at mail.cryst.bbk.ac.uk Fri Feb 29 14:43:41 2008 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 29 Feb 2008 13:43:41 +0000 Subject: [C++-sig] Raoul Gough's container suite with svn boost-trunkboost.python? In-Reply-To: <470E72FE.48A19C6D@sitius.com> References: <470E72FE.48A19C6D@sitius.com> Message-ID: Nikolay Mladenov wrote: > I found it, > > the postcall_override template needs to have the following line > > typedef typename Policy::extract_return_type extract_return_type; > Do you mean I should insert that line as follows? namespace detail { template struct postcall_override { // This class overrides the Policy's postcall function and // result_conveter to handle the list returned from get_slice. // The Policy's result_converter is removed, since it gets // applied within get_slice. Our postcall override applies the // original postcall to each element of the Python list returned // from get_slice. typedef typename Policy::extract_return_type extract_return_type; typedef boost::python::default_result_converter result_converter; typedef typename Policy::argument_package argument_package; postcall_override (Policy const &p); bool precall (PyObject *args); PyObject* postcall (PyObject *args, PyObject *result); private: Policy m_base; }; } In my version of boost/python/suite/indexing/slice_handler.hpp this is inserted on line 63. If I do this I get the following error: /alma/home/john/software/boost/boost-trunk/boost/python/suite/indexing/slice_handler.hpp:63: error: 'typename boost::python::return_value_policy::extract_return_type' names 'template struct boost::python::default_call_policies::extract_return_type', which is not a type Any help appreciated, John. From walter at mathematik.hu-berlin.de Fri Feb 29 15:11:08 2008 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Fri, 29 Feb 2008 15:11:08 +0100 Subject: [C++-sig] boost.python: when does python call c++ destructors? In-Reply-To: <200802281326.24585.walter@mathematik.hu-berlin.de> References: <200802281326.24585.walter@mathematik.hu-berlin.de> Message-ID: <200802291511.08404.walter@mathematik.hu-berlin.de> Ok, I figured out what I have been missing. Actually it are two things 1) C++ automatically defines a standard copy constructor when it is not manually defined. 2)In Python the expression "c = a*b" first computes a*b where a temporary object tmp is created. But instead of using this tmp object and give it the name c, Python does the following: The copy constructor with tmp as argument is called and this new copy is "given the name" c. So, since the standard copy constructor does not increase global_int nor does it cout the "called constructor" string, this led to the unexpected behavior that I couldn't explain. If I add and wrap the copy constructor: asdf::asdf(const asdf& a) { loc = global_int; cout << "called copy constructor with loc:\t" << loc << endl; global_int++; } i get the correct result. wronski(walter):~/workspace/code_tests/boost_python> ./test.py called constructor with loc: 0 called constructor with loc: 1 called operator* with locs: (0,1) called constructor with loc: 2 called copy constructor with loc: 3 called destructor with loc: 2 called operator* with locs: (0,3) called constructor with loc: 3 called copy constructor with loc: 4 called destructor with loc: 3 end called destructor with loc: 0 called destructor with loc: 3 called destructor with loc: 1 called destructor with loc: 4 On Thursday, 28. February 2008 13:26:24 Sebastian Walter wrote: > Hello, > I have compiled a python module with boost.python that exposes the > functionality of a c++ class that has a constructor and destructor and an > overloaded operator*. The complete c++ code and wrapper can be found at the > bottom of this email: > > But at first the python script that gives me headaches: > > /* test.py */ > /*-----------*/ > #!/usr/bin/env python > import myclass > > a = myclass.asdf() > b = myclass.asdf() > > c = a * b > d = a * c > > /* output of test.py */ > /*-----------------------*/ > wronski(walter):~/workspace/code_tests/boost_python> ./test.py > called constructor with loc: 0 > called constructor with loc: 1 > called operator* with locs: (0,1) > called constructor with loc: 2 > called destructor with loc: 2 ?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > called operator* with locs: (0,2) > called constructor with loc: 2 > called destructor with loc: 2 > called destructor with loc: 0 > called destructor with loc: 2 > called destructor with loc: 1 > called destructor with loc: 2 > > The problem that I don't understand: > a*b calls the constructor of a temporary object that is assigned loc=2 > and then directly after that the destructor is called! ...? > I expected the new temporary object to get assigned to the name c! > > What bugs me even more is that there are 4 constructor calls but 6!! > destructor calls! How can this happen? > > Is there something im overlooking? Is this intended behavior of > Python/Boost.Python ? > How could I avoid it? > > > thanks in advance, > > Sebastian Walter > > > > > The corresponding boost.python wrapper and c++ code: > > /* mainclass.hpp */ > /*----------------------*/ > #ifndef MAINCLASS_HPP > #define MAINCLASS_HPP > > #include > #include > using namespace std; > > class asdf{ > public: > int loc; > asdf(); > ~asdf(); > friend const asdf operator*(const asdf &lhs, const asdf &rhs); > }; > #endif > > /* mainclass.cpp */ > /*----------------------*/ > #include "mainclass.hpp" > > int global_int=0; > > asdf::asdf(){ > loc = global_int; > cout<<"called constructor with loc:\t"< global_int++; > } > > asdf::~asdf(){ > cout<<"called destructor with loc:\t"< global_int--; > } > > const asdf operator*(const asdf &lhs, const asdf &rhs){ > cout<<"called operator* with > locs:\t"<<"("< } > > > /* wrapper.cpp */ > /*------------------*/ > #include "boost/python.hpp" > #include "mainclass.hpp" > > BOOST_PYTHON_MODULE(myclass) > { > using namespace boost::python; > class_("asdf") > .def(self * self) > ; > } > > > > > > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From seefeld at sympatico.ca Fri Feb 29 15:16:48 2008 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 29 Feb 2008 09:16:48 -0500 Subject: [C++-sig] boost.python: when does python call c++ destructors? In-Reply-To: <200802291511.08404.walter@mathematik.hu-berlin.de> References: <200802281326.24585.walter@mathematik.hu-berlin.de> <200802291511.08404.walter@mathematik.hu-berlin.de> Message-ID: <47C813D0.3070103@sympatico.ca> Sebastian Walter wrote: > Ok, I figured out what I have been missing. Actually it are two things > > 1) C++ automatically defines a standard copy constructor when it is not > manually defined. Right. > 2)In Python the expression "c = a*b" first computes a*b where a temporary > object tmp is created. But instead of using this tmp object and give it the > name c, Python does the following: > The copy constructor with tmp as argument is called and this new copy > is "given the name" c. This is not quite accurate. Python doesn't know about temporaries and copy-construction, as it always uses references. It is your own definition of operator* that requires the temporary. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin...