From seefeld at sympatico.ca Mon Aug 1 10:20:49 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 01 Aug 2005 10:20:49 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EA9C27.7080406@esss.com.br> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> Message-ID: <42EDDB61.3010604@sympatico.ca> Nicodemus wrote: > That's the problem mentioned by Petrucio in another thread: standard > headers and even boost itself upset GCCXML on Windows. Could anybody with gccxml and windows experience detail the problem a bit ? While I plan to look into a new synopsis-based pyste frontend, I don't quite understand the problem, as the compiler emulation code synopsis uses was to a certain degree inspired by gccxml, and so I would assume that gccxml does the right thing, no matter the platform. Thanks, Stefan From nicodemus at esss.com.br Mon Aug 1 14:42:41 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 01 Aug 2005 09:42:41 -0300 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EDDB61.3010604@sympatico.ca> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> Message-ID: <42EE18C1.7040901@esss.com.br> Stefan Seefeld wrote: >Could anybody with gccxml and windows experience detail the problem a bit ? >While I plan to look into a new synopsis-based pyste frontend, I don't quite >understand the problem, as the compiler emulation code synopsis uses was >to a certain degree inspired by gccxml, and so I would assume that gccxml >does the right thing, no matter the platform. > > I will quote Brad King, the creator of GCCXML, from the gccxml list in a thread regarding this problem (hope he does not mind): "As I said the GCC parser cannot always handle the results of preprocessing as if using VC7.1. In the case of system headers the GCC-XML installation copies and patches them to fix the problems. In this case all the VC-specific hacks in boost are confusing GCC-XML." Hopefully Brad can shed some more light in a possible workaround. :) Best Regards, Nicodemus. From seefeld at sympatico.ca Mon Aug 1 14:59:14 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 01 Aug 2005 14:59:14 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EE18C1.7040901@esss.com.br> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> Message-ID: <42EE1CA2.7030808@sympatico.ca> Nicodemus wrote: > I will quote Brad King, the creator of GCCXML, from the gccxml list in a > thread regarding this problem (hope he does not mind): > > "As I said the GCC parser cannot always handle the results of > preprocessing as if using VC7.1. In the case of system headers the > GCC-XML installation copies and patches them to fix the problems. In > this case all the VC-specific hacks in boost are confusing GCC-XML." > > Hopefully Brad can shed some more light in a possible workaround. :) I can indeed see the problem if you preprocess for CV++ and are then exposed to non-standard extensions during the parsing. While gcc packages contain system headers / wrappers to solve this, the above suggests that gccxml itself does not, i.e. it is assuming a sane and sufficiently standard-conformant development environment. Is that right ? I did adjust the synopsis parser to handle some of the VC++ specific extensions, and I expect boost in general to be parsable with it, even on windows (though I only checked with boost.python and its dependencies). I'll look into a synopsis-frontend for pyste, though I can't make any promise as to when I'll get to it, sorry. Regards, Stefan PS: Needless to say: Any help is of course highly appreciated ! From brad.king at kitware.com Mon Aug 1 15:39:09 2005 From: brad.king at kitware.com (Brad King) Date: Mon, 01 Aug 2005 09:39:09 -0400 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EE18C1.7040901@esss.com.br> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> Message-ID: <42EE25FD.8070906@kitware.com> Nicodemus wrote: > Stefan Seefeld wrote: > >> Could anybody with gccxml and windows experience detail the problem a >> bit ? >> While I plan to look into a new synopsis-based pyste frontend, I don't >> quite >> understand the problem, as the compiler emulation code synopsis uses was >> to a certain degree inspired by gccxml, and so I would assume that gccxml >> does the right thing, no matter the platform. >> >> > > I will quote Brad King, the creator of GCCXML, from the gccxml list in a > thread regarding this problem (hope he does not mind): > > "As I said the GCC parser cannot always handle the results of > preprocessing as if using VC7.1. In the case of system headers the > GCC-XML installation copies and patches them to fix the problems. In > this case all the VC-specific hacks in boost are confusing GCC-XML." > > Hopefully Brad can shed some more light in a possible workaround. :) The easiest way to deal with this is to think of GCC-XML as yet another compiler. Just like code has #ifdef directives to deal with differences between compilers it can also test for the definition of __GCCXML__. This macro is the only way to tell apart GCC-XML from the simulated compiler at preprocessing time. You can use it in cases when the intended work-around is for the parser and not the standard library: #if defined(_MSC_VER) && _MSC_VER < 1300 // MSVC 6 extension syntax #else // Standard syntax #endif might become #if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(__GCCXML__) // MSVC 6 extension syntax #else // Standard syntax #endif -Brad From roman.yakovenko at gmail.com Tue Aug 2 07:54:14 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Aug 2005 07:54:14 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EDDB61.3010604@sympatico.ca> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> Message-ID: <7465b61705080122543f9a0b61@mail.gmail.com> On 8/1/05, Stefan Seefeld wrote: > Nicodemus wrote: > > > That's the problem mentioned by Petrucio in another thread: standard > > headers and even boost itself upset GCCXML on Windows. > > Could anybody with gccxml and windows experience detail the problem a bit ? > While I plan to look into a new synopsis-based pyste frontend, I don't quite > understand the problem, as the compiler emulation code synopsis uses was > to a certain degree inspired by gccxml, and so I would assume that gccxml > does the right thing, no matter the platform. It is very simple to reproduce the problem. Take for example boost.filesystem library. This is cross-platform library. Also it could be compiled under cygwin. But still you can't parse it with GCC-XML. I can send you the output of such compilation. > > Thanks, > Stefan Roman Yakovenko From seefeld at sympatico.ca Tue Aug 2 09:07:50 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Aug 2005 09:07:50 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <7465b61705080122543f9a0b61@mail.gmail.com> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <7465b61705080122543f9a0b61@mail.gmail.com> Message-ID: <42EF1BC6.3060005@sympatico.ca> Hi Roman, Roman Yakovenko wrote: >>Could anybody with gccxml and windows experience detail the problem a bit ? >>While I plan to look into a new synopsis-based pyste frontend, I don't quite >>understand the problem, as the compiler emulation code synopsis uses was >>to a certain degree inspired by gccxml, and so I would assume that gccxml >>does the right thing, no matter the platform. > > > It is very simple to reproduce the problem. Take for example boost.filesystem > library. This is cross-platform library. Also it could be compiled under cygwin. > But still you can't parse it with GCC-XML. I can send you the output > of such compilation. Sorry for not being clear. I don't doubt that it is easily reproducible, but as I'm rarely booting my laptop into windows and I don't have gccxml installed on that platform I thought someone could send a precise description of the failure so we wouldn't need to speculate about its exact cause. Thanks, Stefan From roman.yakovenko at gmail.com Tue Aug 2 09:54:51 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Aug 2005 09:54:51 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EF1BC6.3060005@sympatico.ca> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <7465b61705080122543f9a0b61@mail.gmail.com> <42EF1BC6.3060005@sympatico.ca> Message-ID: <7465b61705080200543c664e4@mail.gmail.com> On 8/2/05, Stefan Seefeld wrote: > Hi Roman, > > > Sorry for not being clear. I don't doubt that it is easily reproducible, but > as I'm rarely booting my laptop into windows and I don't have gccxml installed > on that platform I thought someone could send a precise description of the > failure so we wouldn't need to speculate about its exact cause. I will send you compilation output tomorrow. The Brad King is right, source code should be ported to GCCXML compiler. This is the main problem. > Thanks, > Stefan > Roman Yakovenko From roman.yakovenko at gmail.com Tue Aug 2 10:02:36 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 2 Aug 2005 10:02:36 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <42EE1CA2.7030808@sympatico.ca> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> Message-ID: <7465b61705080201027ffd5184@mail.gmail.com> On 8/1/05, Stefan Seefeld wrote: > I'll look into a synopsis-frontend for pyste, though I can't make > any promise as to when I'll get to it, sorry. > > Regards, > Stefan > > PS: Needless to say: Any help is of course highly appreciated ! I am interested in this project. I'd like to add an other back-end to my project - pygccxml. pyplusplus is based on it. Could you provide small example or introduction how you build front-end based on synopsis? Thanks Roman Yakovenko. From seefeld at sympatico.ca Tue Aug 2 10:09:52 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Aug 2005 10:09:52 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <7465b61705080200543c664e4@mail.gmail.com> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <7465b61705080122543f9a0b61@mail.gmail.com> <42EF1BC6.3060005@sympatico.ca> <7465b61705080200543c664e4@mail.gmail.com> Message-ID: <42EF2A50.5020907@sympatico.ca> Roman Yakovenko wrote: > The Brad King is right, > source code should be ported to GCCXML compiler. This is the main > problem. I don't agree with that. From a user's perspective, gccxml itself is not a compiler, but a compiler emulator. Users want to 'see' the code as it is seen by a particular compiler (such as gcc or VC++), for whatever reason. It is one thing to say that the emulator doesn't support any particular compiler, but another that the emulator just turned into a compiler which the user (i.e. library developer) has to special-case for. But we are getting way off-topic. May be we should continue on the synopsis list ? Regards, Stefan From seefeld at sympatico.ca Tue Aug 2 10:13:25 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Aug 2005 10:13:25 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: <7465b61705080201027ffd5184@mail.gmail.com> References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> <7465b61705080201027ffd5184@mail.gmail.com> Message-ID: <42EF2B25.5040902@sympatico.ca> [Please let's move this discussion to the synopsis list.] Roman Yakovenko wrote: >>PS: Needless to say: Any help is of course highly appreciated ! > > > I am interested in this project. I'd like to add an other back-end to > my project - > pygccxml. pyplusplus is based on it. Could you provide small example or > introduction how you build front-end based on synopsis? I'm not sure yet, as I don't know how much information is needed, and thus, what representations to use for the code generation. Parse Tree and Type Repository, or AST ? Regards, Stefan From dave at boost-consulting.com Tue Aug 2 12:53:18 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 02 Aug 2005 06:53:18 -0400 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> Message-ID: Stefan Seefeld writes: > Nicodemus wrote: > >> I will quote Brad King, the creator of GCCXML, from the gccxml list in a >> thread regarding this problem (hope he does not mind): >> >> "As I said the GCC parser cannot always handle the results of >> preprocessing as if using VC7.1. In the case of system headers the >> GCC-XML installation copies and patches them to fix the problems. In >> this case all the VC-specific hacks in boost are confusing GCC-XML." >> >> Hopefully Brad can shed some more light in a possible workaround. :) > > I can indeed see the problem if you preprocess for CV++ and are then > exposed to non-standard extensions during the parsing. Yeah, but why would you do that when you could preprocess for GCC? -- Dave Abrahams Boost Consulting www.boost-consulting.com From doliwa at temf.tu-darmstadt.de Tue Aug 2 13:06:35 2005 From: doliwa at temf.tu-darmstadt.de (Burkhard Doliwa) Date: Tue, 02 Aug 2005 13:06:35 +0200 Subject: [C++-sig] polymorphic object handling Message-ID: <42EF53BB.8010201@temf.tu-darmstadt.de> Hi all, I have a problem wrapping a factory function to python. I have two abstract base classes A,B, with some child classes A<-A1,A2,A3 B<-B1,B2,B3 every child class is either able to clone itself or to return an instance of the corresponding "parallel class", i.e. A* A1::cloneA() const yields an A1 B* A1::cloneB() const yields an B1 A* B2::cloneA() const yields an A2 B* B2::cloneB() const yields an B2 and so forth. The factory function object factoryA(const A&, bool isA) { return isA? object(A.cloneA()) : object(A.cloneB()); } only returns python objects of the base class types, not the derived classes, i.e. >>> a1=A1() >>> factory(a1,True) result= A object (NOT an A1 object) How could I create the correct derived class in such a conditional factory function (like the return_value_policy() case)? Thanks, Burkhard From seefeld at sympatico.ca Tue Aug 2 13:07:09 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Tue, 02 Aug 2005 13:07:09 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> Message-ID: <42EF53DD.8090407@sympatico.ca> David Abrahams wrote: > Stefan Seefeld writes: > > >>Nicodemus wrote: >> >> >>>I will quote Brad King, the creator of GCCXML, from the gccxml list in a >>>thread regarding this problem (hope he does not mind): >>> >>>"As I said the GCC parser cannot always handle the results of >>>preprocessing as if using VC7.1. In the case of system headers the >>>GCC-XML installation copies and patches them to fix the problems. In >>>this case all the VC-specific hacks in boost are confusing GCC-XML." >>> >>>Hopefully Brad can shed some more light in a possible workaround. :) >> >>I can indeed see the problem if you preprocess for CV++ and are then >>exposed to non-standard extensions during the parsing. > > > Yeah, but why would you do that when you could preprocess for GCC? Because that would require a separate gcc to be installed first ? (The gccxml tarball I unpacked on my linux box doesn't appear to contain anything related to a complete development environment such as system headers.) Regards, Stefan From ahrivera at yahoo.com Tue Aug 2 20:18:20 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 2 Aug 2005 11:18:20 -0700 (PDT) Subject: [C++-sig] to_python / from_python guidance? Message-ID: <20050802181821.99329.qmail@web30703.mail.mud.yahoo.com> Hi, I'm trying to expose a class that uses a third party library: gmtl. The gmtl library has already bindings for python. I want to be able to do this: struct Test { gmtl::Vec3d x; gmtl::Point3d y; Test() : x(0,0,0),y(0,0,0) {} Test(const Test &other) : x(other.x), y(other.y){} Test& operator=(const Test& other) { if (this==&other) return *this; x = other.x; y = other.y; } }; Im exposing the class like this: class_< Test >("Test", init< >()) .def(init< const Test& >()) .def_readwrite("x", &Test::x) .def_readwrite("y", &Test::y) ; But this fails: >>> import gmtl >>> from PyStatATA import * >>> test = Test() >>> test.x = gmtl.Vec3d(0,0,1) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in None.None(Test, Vec3d) did not match C++ signature: None(struct Test {lvalue}, class gmtl::Vec) >>> test.y = gmtl.Point3d(0,0,1) Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in None.None(Test, Point3d) did not match C++ signature: None(struct Test {lvalue}, class gmtl::Point) >>> my = test.y Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class class gmtl::Point >>> mx = test.x Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class class gmtl::Vec >From my understanding, to solve this I need to define the to and from python converters. But the examples assume I have headers to the python type of gmtl::Vec3d and gmtl::Point3d. In my case, I don't have that. What is the best approach to solve this? Thanks, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From Paul_Kunz at slac.stanford.edu Tue Aug 2 21:50:54 2005 From: Paul_Kunz at slac.stanford.edu (Paul F. Kunz) Date: Tue, 2 Aug 2005 12:50:54 -0700 Subject: [C++-sig] Trying to clone (again) Message-ID: <200508021950.j72JosxV015588@libra3.slac.stanford.edu> I'm trying to clone a Python object from C++. The Python class inherits from an exposed C++ base class. To avoid the dangling pointer problem, I keep a Python reference to the created Python object like this... from hippo import FunctionBase # Define a class in Python that is derived from C++ base class _clones = [] class Linear ( FunctionBase ) : def __init__ ( self ) : FunctionBase.__init__( self ) self.initialize () def clone ( self ) : _clones.append ( Linear () ) return _clones[-1] Then in the C++ wrapper class, I have FunctionBase * FunctionWrap:: clone () const // overrides FunctionBase::clone() { #ifndef HAVE_OLD_PYTHON PyGILState_STATE state = PyGILState_Ensure (); object py_result; if (override clone = this->get_override("clone")) { try { // The Python class author overrode clone; do // whatever she says py_result = clone(); } catch ( error_already_set & e ) { PyErr_Print (); handle_exception (); PyGILState_Release ( state ); return 0; } } else { The Python implemented clone() member function is called but I get the following error message on return ... TypeError: No registered converter was able to extract a C++ reference to type boost::python::api::object from this Python object of type Linear Any suggestions? From dave at boost-consulting.com Wed Aug 3 05:39:50 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 02 Aug 2005 23:39:50 -0400 Subject: [C++-sig] Trying to clone (again) References: <200508021950.j72JosxV015588@libra3.slac.stanford.edu> Message-ID: "Paul F. Kunz" writes: > FunctionBase * > FunctionWrap:: > clone () const // overrides FunctionBase::clone() > { > #ifndef HAVE_OLD_PYTHON > PyGILState_STATE state = PyGILState_Ensure (); > object py_result; > if (override clone = this->get_override("clone")) { > try { > // The Python class author overrode clone; do > // whatever she says > py_result = clone(); The result of invoking an override is not meant to be used this way, but you might be able to force it by doing: py_result = boost::implicit_cast(clone()); What compiler are you using, incidentally? -- Dave Abrahams Boost Consulting www.boost-consulting.com From sheig222 at gmail.com Wed Aug 3 08:44:30 2005 From: sheig222 at gmail.com (Ira) Date: Wed, 3 Aug 2005 09:44:30 +0300 Subject: [C++-sig] return_arg Message-ID: Hi, Say I have a C++ class exposed to python. The C++ code creates an instance of said class and I want to retrieve it from python code. What would be the correct way for python code to 'get' the reference? Regardless can someone please elaborate on the the whole "param passing & return value" subject. It might be me but I had a hard time with return_arg<> (I don't get what arg_pos is suppose to mean), and the example discusses only return_self What I *tried* to do is: MyClass* pMyClass; main() { pMyClass = new MyClass; } MyClass* GetMyClass() { return pMyClass; } BOOST_PYTHON_MODULE(mymod) { class_..... def ("GetMyClass", GetMyClass); } This didn't compile with "C2027 use of unspecified type boost::python::detail::specify_a_return_value_to_wrap_functions_returning with T=result_t". I tried messing around with the def, adding return_arg<> but nothing did the trick for me. Cheers, Ira From paghera at qualcomm.com Wed Aug 3 10:21:13 2005 From: paghera at qualcomm.com (Aghera, Parixit) Date: Wed, 3 Aug 2005 01:21:13 -0700 Subject: [C++-sig] Pyste Modification for operator[]: is there any python function to know whether a C++ type is a class or basic data type? Message-ID: <3D478B510F292F42A70D606C42144D58A9EAD1@NAEX06.na.qualcomm.com> Hi All, I have a C++ library which I want to export to python using pyste. There are several sequence class in C++ library which overloads [] operator and that is the only way to access an element in sequence. Current pyste implementation (Release version 1_32_0) doesn't handle operator [], so I modified ClassExporter.py to generate the .defs for __getitem__ and __setitem__ in the pyste generated .cpp. Following the template function for getitem and pyste modification. It seems that for C++ struct/class I have to return the element by reference and for other C++ types (basic/enums) I need to return the element by value. I learnt this by experiments and from boost/python/suite/indexing/vector_indexing_suite.hpp . Now the problem I run into here is this. I need to add return_internal_reference< 1 > in generated .def in case when getitem function return element by reference. Now in python I don't know a way to figure out whether IndexOp_PysteWrapper_getitem function will return element by reference or by value, since I don't know if the return type of operator[] is a C++ class/structure or basic data type. Any solution/hints for solution to this problem would be a great help. Template Function: template typename boost::mpl::if_,T&,T>::type IndexOp_PysteWrapper_getitem(TAO_Unbounded_Sequence& seq, int index) { if (index < 0) { index = seq.length() + index; // negative index } if (index >= seq.length()) { PyErr_SetString(PyExc_IndexError, "index out of range"); throw_error_already_set(); } return seq[index]; } Pyste Modification: Added folloing function for handling index operator in ClassExporter. This function is called when operator[] is found in the class being exported. Depending on return type of the operator[] (is it const or not), I determine whether setitem and getitem should be supported. def HandleIndexOperator(operator): if operator.result.const: self.Add('inside', '.def("__getitem__", &IndexOp_PysteWrapper_getitem<%s>)' % (operator.result.name)) else: self.Add('inside', '.def("__setitem__", &IndexOp_PysteWrapper_setitem<%s>)' % (operator.result.name)) Thanks, Parixit From pierre.barbier at cirad.fr Wed Aug 3 11:35:22 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Wed, 03 Aug 2005 11:35:22 +0200 Subject: [C++-sig] to_python / from_python guidance? In-Reply-To: <20050802181821.99329.qmail@web30703.mail.mud.yahoo.com> References: <20050802181821.99329.qmail@web30703.mail.mud.yahoo.com> Message-ID: <42F08FDA.5020606@cirad.fr> Well, at first it is worth noting gtml Python library was made with Boost.Python ! Because it should simplify things a lot ! At least, what's written here suggest that : http://www.vrjuggler.org/pyjuggler/1.0/python.programmer.reference/gmtl.html If you use another Python extension for gtml, let us know ! The converters should be defined by Boost.Python itself. Also, verify the gmtl Python extension is linked against the same library as your C++ code ... because it should work, and your error looks like some multi-symbol error to me. Pierre Alexis H. Rivera-Rios a ?crit : > Hi, > > I'm trying to expose a class that uses a third party > library: gmtl. The gmtl library has already bindings > for python. I want to be able to do this: > > struct Test > { > gmtl::Vec3d x; > gmtl::Point3d y; > Test() > : x(0,0,0),y(0,0,0) {} > Test(const Test &other) > : x(other.x), > y(other.y){} > > Test& operator=(const Test& other) > { > if (this==&other) > return *this; > > x = other.x; > y = other.y; > } > }; > > Im exposing the class like this: > > class_< Test >("Test", init< >()) > .def(init< const Test& >()) > .def_readwrite("x", &Test::x) > .def_readwrite("y", &Test::y) > ; > > But this fails: > >>>>import gmtl >>>>from PyStatATA import * >>>>test = Test() >>>>test.x = gmtl.Vec3d(0,0,1) > > Traceback (most recent call last): > File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > None.None(Test, Vec3d) > did not match C++ signature: > None(struct Test {lvalue}, class > gmtl::Vec) > >>>>test.y = gmtl.Point3d(0,0,1) > > Traceback (most recent call last): > File "", line 1, in ? > Boost.Python.ArgumentError: Python argument types in > None.None(Test, Point3d) > did not match C++ signature: > None(struct Test {lvalue}, class > gmtl::Point) > >>>>my = test.y > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No Python class registered for C++ class > class gmtl::Point > >>>>mx = test.x > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No Python class registered for C++ class > class gmtl::Vec > >>From my understanding, to solve this I need to define > the to and from python converters. But the examples > assume I have headers to the python type of > gmtl::Vec3d and gmtl::Point3d. In my case, I don't > have that. > > What is the best approach to solve this? > > Thanks, > Alexis > > Programming Tutorial: > In Python: To do this, do this > In Perl: To do this, do this or this or this or this... > In C: To do this, do this, but be careful > In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From roman.yakovenko at gmail.com Wed Aug 3 14:15:16 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 3 Aug 2005 15:15:16 +0300 Subject: [C++-sig] Pyste Modification for operator[]: is there any python function to know whether a C++ type is a class or basic data type? In-Reply-To: <3D478B510F292F42A70D606C42144D58A9EAD1@NAEX06.na.qualcomm.com> References: <3D478B510F292F42A70D606C42144D58A9EAD1@NAEX06.na.qualcomm.com> Message-ID: <7465b61705080305154bc617b@mail.gmail.com> On 8/3/05, Aghera, Parixit wrote: > Hi All, > > I have a C++ library which I want to export to python using > pyste. There are several sequence class in C++ library which overloads > [] operator and that is the only way to access an element in sequence. > Current pyste implementation (Release version 1_32_0) doesn't handle > operator [], so I modified ClassExporter.py to generate the .defs for > __getitem__ and __setitem__ in the pyste generated .cpp. Following the > template function for getitem and pyste modification. It seems that for > C++ struct/class I have to return the element by reference and for other > C++ types (basic/enums) I need to return the element by value. I learnt > this by experiments and from > boost/python/suite/indexing/vector_indexing_suite.hpp . > > Now the problem I run into here is this. I need to add > return_internal_reference< 1 > in generated .def in case when getitem > function return element by reference. Now in python I don't know a way > to figure out whether IndexOp_PysteWrapper_getitem function will return > element by reference or by value, since I don't know if the return type > of operator[] is a C++ class/structure or basic data type. > > Any solution/hints for solution to this problem would be a great > help. I think that right now such function does not exist in Pyste. There are 2 ways to do the job. Pyste has class hierarchy called Exporters, with base class Exporter. Instance of this class keeps referenced to declaration. You should find your function, operator[], in the declarations list and then to examine the return type. Also I think you will have to give access to your new function in pyste scripts. See pyste.py CreateContext function for hints. Of course there is an other, simpler way to complete the task - to use pyplusplus code generator. pyplusplus gives you access to functionality very similar to boost.type_traits library. Also it gives you an convenient way to add custom code to generated code. See http://pygccxml.sourceforge.net/. Hope, this was helpful. > Thanks, > Parixit Roman Yakovenko From dave at boost-consulting.com Wed Aug 3 15:54:16 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 03 Aug 2005 09:54:16 -0400 Subject: [C++-sig] return_arg References: Message-ID: "Ira" writes: > What I *tried* to do is: > > MyClass* pMyClass; > > main() > { > pMyClass = new MyClass; > } > > MyClass* GetMyClass() > { > return pMyClass; > } > > BOOST_PYTHON_MODULE(mymod) > { > class_..... > > def ("GetMyClass", GetMyClass); > } > > This didn't compile with "C2027 use of unspecified type > boost::python::detail::specify_a_return_value_to_wrap_functions_returning > with T=result_t". You need to specify a return value policy when returning pointers and references from functions, because otherwise Boost.Python doesn't know how/whether to manage the lifetime of the thing referred to. In this case, reference_existing_object looks like the right policy. Since GetMyClass has no arguments, return_arg certainly can't be the right choice! HTH, Dave P.S. Next time I suggest you copy/paste your actual code and the actual error message. It was specify_a_return_value_policy_to_wrap_functions_returning ^^^^^^^ -- Dave Abrahams Boost Consulting www.boost-consulting.com From Paul_Kunz at slac.stanford.edu Wed Aug 3 16:30:58 2005 From: Paul_Kunz at slac.stanford.edu (Paul F. Kunz) Date: Wed, 3 Aug 2005 07:30:58 -0700 Subject: [C++-sig] Trying to clone (again) In-Reply-To: (message from David Abrahams on Tue, 02 Aug 2005 23:39:50 -0400) References: <200508021950.j72JosxV015588@libra3.slac.stanford.edu> Message-ID: <200508031430.j73EUwuR020146@libra3.slac.stanford.edu> >>>>> On Tue, 02 Aug 2005 23:39:50 -0400, David Abrahams said: > The result of invoking an override is not meant to be used this way, > but you might be able to force it by doing: > py_result = boost::implicit_cast(clone()); Tried that and didn't get an error at runtime. However, the very next call to the object unsigned int FunctionWrap:: dimensions () const { unsigned int dims = 0; if ( override member = this -> get_override ( "dimensions" ) ) { dims = member(); } else { // didn't override it dims = FunctionBase::dimensions (); } return dims; } leads to Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1222050896 (LWP 14423)] PyErr_Restore (type=0xb75a671c, value=0xb74827b8, traceback=0x0) at Python/errors.c:33 (gdb) up #1 0x080ceb80 in PyErr_Format (exception=0xb75a671c, format=0xb75a671c "\006") at Python/errors.c:51 (gdb) #2 0x0807f3a0 in PyObject_GenericGetAttr (obj=0xb756c464, name=0xb7532cc8) at Objects/object.c:1303 (gdb) #3 0x0807ec79 in PyObject_GetAttrString (v=0xb756c464, name=0x7d1ae5 "dimensions") at Objects/object.c:1016 (gdb) #4 0x009ebcf9 in boost::python::detail::wrapper_base::get_override () from /usr/local/lib/libboost_python-gcc-1_32.so.1.32.0 (gdb) #5 0x00736447 in FunctionWrap::dimensions (this=0x94c7f40) at /usr/local/include/boost-1_32/boost/python/wrapper.hpp:29 Current language: auto; currently c++ (gdb) The object does *not* have "dimension" member function. If I give it one, I get the same error. By the way, the rest of the code in the clone() method of FunctionWrap executed without errors, namely FunctionWrap* result = extract(py_result); // Make the C++ result control the destiny of the Python result. result->invert_ownership = py_result; PyGILState_Release ( state ); return result; } > What compiler are you using, incidentally? gcc 4.0.1 and gcc 3.2.3 From dave at boost-consulting.com Wed Aug 3 17:01:41 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 03 Aug 2005 11:01:41 -0400 Subject: [C++-sig] Trying to clone (again) References: <200508021950.j72JosxV015588@libra3.slac.stanford.edu> <200508031430.j73EUwuR020146@libra3.slac.stanford.edu> Message-ID: "Paul F. Kunz" writes: >>>>>> On Tue, 02 Aug 2005 23:39:50 -0400, David Abrahams said: > > >> The result of invoking an override is not meant to be used this way, >> but you might be able to force it by doing: > >> py_result = boost::implicit_cast(clone()); > > Tried that and didn't get an error at runtime. However, the very > next call to the object > > unsigned int > FunctionWrap:: > dimensions () const > { > unsigned int dims = 0; > > if ( override member = this -> get_override ( "dimensions" ) ) { > dims = member(); > } > else { // didn't override it > dims = FunctionBase::dimensions (); > } > return dims; > } > > leads to > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread -1222050896 (LWP 14423)] > PyErr_Restore (type=0xb75a671c, value=0xb74827b8, traceback=0x0) > at Python/errors.c:33 > (gdb) up > #1 0x080ceb80 in PyErr_Format (exception=0xb75a671c, > format=0xb75a671c "\006") at Python/errors.c:51 > (gdb) > #2 0x0807f3a0 in PyObject_GenericGetAttr (obj=0xb756c464, name=0xb7532cc8) > at Objects/object.c:1303 > (gdb) > #3 0x0807ec79 in PyObject_GetAttrString (v=0xb756c464, > name=0x7d1ae5 "dimensions") at Objects/object.c:1016 > (gdb) > #4 0x009ebcf9 in boost::python::detail::wrapper_base::get_override () > from /usr/local/lib/libboost_python-gcc-1_32.so.1.32.0 > (gdb) > #5 0x00736447 in FunctionWrap::dimensions (this=0x94c7f40) > at /usr/local/include/boost-1_32/boost/python/wrapper.hpp:29 > Current language: auto; currently c++ > (gdb) I'm pretty sure that's an unrelated problem, and something you did is corrupting memory somewhere. > The object does *not* have "dimension" member function. That's not relevant. > If I give it one, I get the same error. By the way, the rest of the > code in the clone() method of FunctionWrap executed without errors, > namely > > FunctionWrap* result = extract(py_result); > > // Make the C++ result control the destiny of the Python result. > result->invert_ownership = py_result; > PyGILState_Release ( state ); I"m not sure about this invert_ownership business. Are you sure you're not allowing your Python object to be destroyed prematurely? -- Dave Abrahams Boost Consulting www.boost-consulting.com From Paul_Kunz at slac.stanford.edu Wed Aug 3 18:12:29 2005 From: Paul_Kunz at slac.stanford.edu (Paul F. Kunz) Date: Wed, 3 Aug 2005 09:12:29 -0700 Subject: [C++-sig] Trying to clone (again) In-Reply-To: (message from David Abrahams on Wed, 03 Aug 2005 11:01:41 -0400) References: <200508021950.j72JosxV015588@libra3.slac.stanford.edu> <200508031430.j73EUwuR020146@libra3.slac.stanford.edu> Message-ID: <200508031612.j73GCTTk020732@libra3.slac.stanford.edu> >>>>> On Wed, 03 Aug 2005 11:01:41 -0400, David Abrahams said: > I'm pretty sure that's an unrelated problem, and something you did > is corrupting memory somewhere. Thanks for the tip. I found that a function object created not by clone method also has the same problem. This used to work, so indeed I have some other problem. > I"m not sure about this invert_ownership business. Are you sure > you're not allowing your Python object to be destroyed prematurely? Pretty sure. The C++ code just create a new instance and is about to use it. Thanks again. From rwgk at yahoo.com Wed Aug 3 19:10:21 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 3 Aug 2005 10:10:21 -0700 (PDT) Subject: [C++-sig] Trying to clone (again) In-Reply-To: <200508031612.j73GCTTk020732@libra3.slac.stanford.edu> Message-ID: <20050803171021.58322.qmail@web31509.mail.mud.yahoo.com> --- "Paul F. Kunz" wrote: > >>>>> On Wed, 03 Aug 2005 11:01:41 -0400, David Abrahams > said: > > > > I'm pretty sure that's an unrelated problem, and something you did > > is corrupting memory somewhere. > > Thanks for the tip. I found that a function object created not by > clone method also has the same problem. This used to work, so indeed I have > some other problem. Anytime I see a Segfault or Abort my standard response is to run valgrind. It is an extremely simple and powerful way of pinpointing the problem. http://www.valgrind.org/ Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From Paul_Kunz at slac.stanford.edu Wed Aug 3 20:15:28 2005 From: Paul_Kunz at slac.stanford.edu (Paul F. Kunz) Date: Wed, 3 Aug 2005 11:15:28 -0700 Subject: [C++-sig] Trying to clone (again) In-Reply-To: <20050803171021.58322.qmail@web31509.mail.mud.yahoo.com> (rwgk@yahoo.com) References: <20050803171021.58322.qmail@web31509.mail.mud.yahoo.com> Message-ID: <200508031815.j73IFSJW021312@libra3.slac.stanford.edu> >>>>> On Wed, 3 Aug 2005 10:10:21 -0700 (PDT), "Ralf W. Grosse-Kunstleve" said: > --- "Paul F. Kunz" wrote: >> >>>>> On Wed, 03 Aug 2005 11:01:41 -0400, David Abrahams >> said: >> >> >> > I'm pretty sure that's an unrelated problem, and something you >> did > is corrupting memory somewhere. >> Dave, you were right. I was doing something very stupid somewhere else. The object was not being destroyed. > Anytime I see a Segfault or Abort my standard response is to run > valgrind. It is an extremely simple and powerful way of pinpointing > the problem. Thanks for the tip, Ralf. From ahrivera at yahoo.com Wed Aug 3 21:34:25 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Wed, 3 Aug 2005 12:34:25 -0700 (PDT) Subject: [C++-sig] to_python / from_python guidance? Message-ID: <20050803193425.562.qmail@web30711.mail.mud.yahoo.com> I'm using the one that can be downloaded from: Generic Graphic Toolkit http://ggt.sourceforge.net/ Is this the same one? Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From pierre.barbier at cirad.fr Thu Aug 4 11:20:17 2005 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Thu, 04 Aug 2005 11:20:17 +0200 Subject: [C++-sig] to_python / from_python guidance? In-Reply-To: <20050803193425.562.qmail@web30711.mail.mud.yahoo.com> References: <20050803193425.562.qmail@web30711.mail.mud.yahoo.com> Message-ID: <42F1DDD1.6060103@cirad.fr> Well, I don't know if it is really the same, but looking at the code of the Python library (here: http://cvs.sourceforge.net/viewcvs.py/ggt/GGT/modules/GMTL/python/ ) they do use Boost.Python ! They even seems to use (or have used ?) pyste. Pierre Alexis H. Rivera-Rios a ?crit : > I'm using the one that can be downloaded from: > > Generic Graphic Toolkit > http://ggt.sourceforge.net/ > > Is this the same one? > > Alexis > > Programming Tutorial: > In Python: To do this, do this > In Perl: To do this, do this or this or this or this... > In C: To do this, do this, but be careful > In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this > > > > ____________________________________________________ > Start your day with Yahoo! - make it your home page > http://www.yahoo.com/r/hs > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From sheig222 at gmail.com Thu Aug 4 14:59:29 2005 From: sheig222 at gmail.com (Ira Holtzer) Date: Thu, 4 Aug 2005 15:59:29 +0300 Subject: [C++-sig] return_arg References: Message-ID: <004601c598f4$838857c0$a7ffa8c0@randomlogic.com> > You need to specify a return value policy when returning pointers and > references from functions, because otherwise Boost.Python doesn't know > how/whether to manage the lifetime of the thing referred to. In this > case, reference_existing_object looks like the right policy. Since > GetMyClass has no arguments, return_arg certainly can't be the right > choice! Can you please point me to where I can find an in-depth discussion of return value policies? Are the 6 models under boost::python docs' ConverterGenerator all I can use/need? > P.S. Next time I suggest you copy/paste your actual code and the actual > error message. It was > specify_a_return_value_policy_to_wrap_functions_returning Lol, sorry about that. The secret police here at where I work restrict us from doing *very dangerous* stuff like downloading MP3's, zip files with source code in them, installing winamp... Ohh and also posting to newsgroups. I have to use a different 'dirty' workstation to post here so I can't simply copy/paste. I'll make an effort to be more accurate in the future. Cheers, Ira From sheig222 at gmail.com Thu Aug 4 15:02:04 2005 From: sheig222 at gmail.com (Ira Holtzer) Date: Thu, 4 Aug 2005 16:02:04 +0300 Subject: [C++-sig] return_arg References: Message-ID: <004d01c598f4$c2151190$a7ffa8c0@randomlogic.com> > You need to specify a return value policy when returning pointers and > references from functions, because otherwise Boost.Python doesn't know > how/whether to manage the lifetime of the thing referred to. In this > case, reference_existing_object looks like the right policy. Since > GetMyClass has no arguments, return_arg certainly can't be the right > choice! Can you please point me to where I can find an in-depth discussion of return value policies? Are the 6 models under boost::python docs' ConverterGenerator all I can use/need? > P.S. Next time I suggest you copy/paste your actual code and the actual > error message. It was > specify_a_return_value_policy_to_wrap_functions_returning Lol, sorry about that. The secret police psychos here at where I work restrict us from performing *very dangerous* actions like downloading MP3's, zip files with source code in them, installing winamp... Ohh and also posting to newsgroups. I have to use a different 'dirty' workstation to post here so I can't simply copy/paste. I'll make an effort to be more accurate in the future. Cheers, Ira From michael.knecht at nanotechsoftware.de Fri Aug 5 14:08:18 2005 From: michael.knecht at nanotechsoftware.de (Dr. Michael Knecht) Date: Fri, 05 Aug 2005 14:08:18 +0200 Subject: [C++-sig] Possible bug for return_internal_reference with shared_ptr Message-ID: <1123243698.7682.24.camel@atom.nanotechsoftware.de> Hallo, i am using internal reference with shared pointers to handle borrowed references. Here the code: begin cpp-------------------- #include #include using namespace boost; using namespace python; class B { public: B() : _a(0) {} void set(const int & a) { _a = a; } const int & get() const { return _a; } private: int _a; }; typedef shared_ptr ptr_type; class A { public: A() : _a(new B()) {} void set(const ptr_type & a) { _a = a; } const ptr_type & get1() const { return _a; } const ptr_type & get2() const { return _a; } private: ptr_type _a; }; BOOST_PYTHON_MODULE(ptr_test) { class_ >("A") .def("set", &A::set) .def("get1", &A::get1, return_value_policy()) .def("get2", &A::get2, return_internal_reference<>()) ; class_ >("B") .def("set", &B::set) .def("get", &B::get, return_value_policy()) ; } end cpp --------------------- begin python --------- from ptr_test import * a = A() b1 = a.get1() print b1.get() b2 = a.get2() print b2.get() end python -------------------- If I execute the python script I get the following error message: TypeError: No Python class registered for C++ class boost::shared_ptr begin out -------------------- 0 Traceback (most recent call last): File "test.py", line 8, in ? b2 = a.get2() TypeError: No Python class registered for C++ class boost::shared_ptr end out ----------------------- So return_value_policy is working and return_internal_reference<> not! Any ideas why boost/python can not handle this? I think to handle internal references is importend for containers and iterators. From ericjardim at gmail.com Fri Aug 5 15:33:26 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 5 Aug 2005 10:33:26 -0300 Subject: [C++-sig] How do I wrap virtual methods Message-ID: <432ec6c505080506332d1e970c@mail.gmail.com> Hi, I am wrapping a library, and everything is going well. But now I am trying to wrap some virtual methods. After that a strange behavior is happening (I am using boost 1.32). I am using Pyste to wrap a "scratch code" for me, and I then manually insert some wrapped functions/classes/enums to the definitive source. (This approach might be strange, but it is good for me. It helps me learning Boost.Pythonconstructs, and it's a way to control errors for each step.) The error consist basically of a wrapped virtual method of the "QObject" class being called *without* it being reimplemented in Python. Of course it was reimplemented in C++, when the "QObject_Wrapper" class was created. Pyste is generating the "QObject_Wrapper" with the overloaded constructors, a "PyObject* py_self" reference to the Python object, everything explicit! On the other hand, I saw on the tutorial that you should use a construct like: struct BaseWrap : Base, wrapper { int f() { if (override f = this->get_override("f")) return f(); // note* return Base::f(); } int default_f() { return this->Base::f(); } }; // *note: on MSVC use // return call(f.ptr()); I think that this will solve the problem, because it tests if there is a overriden method. I am still confused if wrapper<...> will create the apropriate contructors. So what do "wrapper<..>" really do? Another thing that I noticed is that I have to reimplement virtual methods on every derived class. This is an accumulative task. Am I right? So, what is the right and safe way to wrap virtual methods? Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 5 17:41:17 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 11:41:17 -0400 Subject: [C++-sig] return_arg References: <004601c598f4$838857c0$a7ffa8c0@randomlogic.com> Message-ID: "Ira Holtzer" writes: >> You need to specify a return value policy when returning pointers and >> references from functions, because otherwise Boost.Python doesn't know >> how/whether to manage the lifetime of the thing referred to. In this >> case, reference_existing_object looks like the right policy. Since >> GetMyClass has no arguments, return_arg certainly can't be the right >> choice! > > Can you please point me to where I can find an in-depth discussion of return > value policies? http://www.boost.org/libs/python/doc/v2/ResultConverter.html#ResultConverterGenerator > Are the 6 models under boost::python docs' ConverterGenerator all I can > use/need? You can write your own as long as it conforms to the requirements for ResultConverterGenerator. >> P.S. Next time I suggest you copy/paste your actual code and the actual >> error message. It was >> specify_a_return_value_policy_to_wrap_functions_returning > > Lol, sorry about that. The secret police here at where I work restrict us > from doing *very dangerous* stuff like downloading MP3's, zip files with > source code in them, installing winamp... Ohh and also posting to > newsgroups. I have to use a different 'dirty' workstation to post here so I > can't simply copy/paste. Nice. You might try the GMane web interface to its newsgroup for this mailing list next time; you should be able to paste into that. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Aug 5 17:57:47 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 11:57:47 -0400 Subject: [C++-sig] How do I wrap virtual methods References: <432ec6c505080506332d1e970c@mail.gmail.com> Message-ID: Eric Jardim writes: > I saw on the tutorial that you should use a construct like: > > struct BaseWrap : Base, wrapper > { > int f() > { > if (override f = this->get_override("f")) > return f(); // note* > return Base::f(); > } > > int default_f() { return this->Base::f(); } Does the tutorial really recommend that default_f? I can't imagine why. That's just wrong; you don't need it and it's a bad idea to use it. [Joel, can you please fix this ASAP, and the use of default_f further down?] > }; > > // *note: on MSVC use > // return call(f.ptr()); > > I think that this will solve the problem, because it tests if there is a > overriden method. I am still confused if wrapper<...> will create the > apropriate contructors. wrappeer<...> doesn't create any constructors by itself. > So what do "wrapper<..>" really do? Exactly what's described in http://www.boost.org/libs/python/doc/v2/wrapper.html#wrapper-spec > Another thing that I noticed is that I have to reimplement virtual methods > on every derived class. This is an accumulative task. Am I right? I don't know what you mean. > So, what is the right and safe way to wrap virtual methods? Everything the tutorial says, aside from the definition and use of default_f, seems to be right. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Aug 5 17:59:11 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 11:59:11 -0400 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> <42EF53DD.8090407@sympatico.ca> Message-ID: Stefan Seefeld writes: > David Abrahams wrote: >> Stefan Seefeld writes: >> >> >>>Nicodemus wrote: >>> >>> >>>>I will quote Brad King, the creator of GCCXML, from the gccxml list in a >>>>thread regarding this problem (hope he does not mind): >>>> >>>>"As I said the GCC parser cannot always handle the results of >>>>preprocessing as if using VC7.1. In the case of system headers the >>>>GCC-XML installation copies and patches them to fix the problems. In >>>>this case all the VC-specific hacks in boost are confusing GCC-XML." >>>> >>>>Hopefully Brad can shed some more light in a possible workaround. :) >>> >>>I can indeed see the problem if you preprocess for CV++ and are then >>>exposed to non-standard extensions during the parsing. >> >> >> Yeah, but why would you do that when you could preprocess for GCC? > > Because that would require a separate gcc to be installed first ? > > (The gccxml tarball I unpacked on my linux box doesn't appear to > contain anything related to a complete development environment > such as system headers.) Well, that doesn't seem like it ought to be a significant obstacle. It seems unreasonable to expect GCCXML to process nonstandard MSVC constructs correctly. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Aug 5 17:51:32 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 11:51:32 -0400 Subject: [C++-sig] Possible bug for return_internal_reference with shared_ptr References: <1123243698.7682.24.camel@atom.nanotechsoftware.de> Message-ID: "Dr. Michael Knecht" writes: > Hallo, > > i am using internal reference with shared pointers to handle borrowed > references. I *really* think you don't want to do that. > Here the code: > > begin cpp-------------------- > #include > #include > > using namespace boost; > using namespace python; > > class B { > public: > B() : _a(0) {} > void set(const int & a) { _a = a; } > const int & get() const { return _a; } > private: > int _a; > }; > > typedef shared_ptr ptr_type; > > class A { > public: > A() : _a(new B()) {} > void set(const ptr_type & a) { _a = a; } > const ptr_type & get1() const { return _a; } > const ptr_type & get2() const { return _a; } > private: > ptr_type _a; > }; > > BOOST_PYTHON_MODULE(ptr_test) > { > class_ >("A") > .def("set", &A::set) > .def("get1", &A::get1, > return_value_policy()) > .def("get2", &A::get2, return_internal_reference<>()) > ; > class_ >("B") > .def("set", &B::set) > .def("get", &B::get, > return_value_policy()) > ; > } > end cpp --------------------- > > begin python --------- > from ptr_test import * > > a = A() > > b1 = a.get1() > print b1.get() > > b2 = a.get2() > print b2.get() > end python -------------------- > > If I execute the python script I get the following error message: > > TypeError: No Python class registered for C++ class boost::shared_ptr > > begin out -------------------- > 0 > Traceback (most recent call last): > File "test.py", line 8, in ? > b2 = a.get2() > TypeError: No Python class registered for C++ class boost::shared_ptr > end out ----------------------- > > So return_value_policy is working As it should. > and return_internal_reference<> not! > > Any ideas why boost/python can not handle this? I think to handle > internal references is importend for containers and iterators. Because return_internal_reference doesn't do what you think. It builds an instance of the Python class corresponding to the type referenced, and holding a pointer to the thing referenced (a shared_ptr in this case) and maintaining the lifetime of the first argument in order to keep the thing pointed to alive. You didn't (and shouldn't) register a class corresponding to shared_ptr; you just used shared_ptr to hold the value of a class corresponding to B. It might be nice if Boost.Python would let you get away with no return_value_policy in these cases, but I have some doubts about allowing return_internal_reference for shared_ptr. It would be wasteful at best because it isn't really important to keep the first argument to the wrapped function alive at all; the shared_ptr is enough to keep the B object it references alive. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Fri Aug 5 19:18:27 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 5 Aug 2005 14:18:27 -0300 Subject: [C++-sig] How do I wrap virtual methods In-Reply-To: References: <432ec6c505080506332d1e970c@mail.gmail.com> Message-ID: <432ec6c5050805101828d6103b@mail.gmail.com> 2005/8/5, David Abrahams : > > Does the tutorial really recommend that default_f? I can't imagine > why. That's just wrong; you don't need it and it's a bad idea to use > it. [Joel, can you please fix this ASAP, and the use of default_f > further down?] Beside the tutorial, Pyste itself generate "default_..." methods. > Another thing that I noticed is that I have to reimplement virtual methods > > on every derived class. This is an accumulative task. Am I right? > > I don't know what you mean. Suppose you have class A, B and C. C is derived from B, and B derived from A (A <- B <- C). Suppose you have a virtual method "f" (pure or not) defined on the A class scope. Suppose that you want to expose this method, so user can, in Python, extend some class (A, B or C) If you want to extend class A, in Python, that's Ok. When you create a new A class in Python, you are actually creating a A_Wrapper object. But if you want to extend B or C, they don't know about the A_Wrapper. So, you must create B_Wrapper, C_Wrapper and re-expose "f" on both. Hope to make it clear now. Is this right, or not. Everything the tutorial says, aside from the definition and use of > default_f, seems to be right. > It looks like the docs use the "default_..." functions too: http://www.boost.org/libs/python/doc/v2/wrapper.html I still don't understand: should I use the "defaul_..." function (in a different way) or not use it? Let's see a real (correct) example, please. Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericjardim at gmail.com Fri Aug 5 19:47:51 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 5 Aug 2005 14:47:51 -0300 Subject: [C++-sig] How do I wrap virtual methods In-Reply-To: References: <432ec6c505080506332d1e970c@mail.gmail.com> Message-ID: <432ec6c5050805104740d29682@mail.gmail.com> 2005/8/5, David Abrahams : > > > So, what is the right and safe way to wrap virtual methods? > Everything the tutorial says, aside from the definition and use of > default_f, seems to be right. > I have more doubts. 1 - using the wrapper<...> approach, the tutorial suggests me that I should expose my class like this: class_("Base") .def("f", &Base::f, &BaseWrap::default_f) ; But what if some "Base" object where create, not by the Python code. As I exposed "BaseWrap", "Base" was not actually exposed. Will it be a problem? 2 - How do I expose the constructors of the "Base" class on the "BaseWrap" class? Should I define it again? Should I define the PyObject* as the first parameter, or treat it as a normal class? The solution I think will work: I think that I will have to create 2 kind of objects. The normal "QObject" wrapper, whithout the virtual functions overriden, and a "QCustomObject", class that will never be created by C++ classes. If the user wants to reimplement any virtual function, he should use this class. If what I say is wrong, or a bad idea, just tell me. [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 5 19:41:00 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 13:41:00 -0400 Subject: [C++-sig] How do I wrap virtual methods References: <432ec6c505080506332d1e970c@mail.gmail.com> <432ec6c5050805101828d6103b@mail.gmail.com> Message-ID: Eric Jardim writes: > 2005/8/5, David Abrahams : >> >> Does the tutorial really recommend that default_f? I can't imagine >> why. That's just wrong; you don't need it and it's a bad idea to use >> it. [Joel, can you please fix this ASAP, and the use of default_f >> further down?] My mistake; I was just mis-remembering. Please see: http://mail.python.org/pipermail/c++-sig/2004-July/007844.html [And my apologies to Joel] > Beside the tutorial, Pyste itself generate "default_..." methods. That is correct. >> Another thing that I noticed is that I have to reimplement virtual methods >> > on every derived class. This is an accumulative task. Am I right? >> >> I don't know what you mean. > > > Suppose you have class A, B and C. C is derived from B, and B derived from A > (A <- B <- C). Suppose you have a virtual method "f" (pure or not) defined > on the A class scope. Suppose that you want to expose this method, so user > can, in Python, extend some class (A, B or C) > > If you want to extend class A, in Python, that's Ok. When you create a new A p > class in Python, you are actually creating a A_Wrapper object. But if you > want to extend B or C, they don't know about the A_Wrapper. So, you must > create B_Wrapper, C_Wrapper and re-expose "f" on both. > > Hope to make it clear now. Is this right, or not. If you want to derive from B or C in Python and override "f" such that when C++ calls it, the Python implementation is invoked, that's correct. > I still don't understand: should I use the "defaul_..." function (in a > different way) or not use it? Use it. > Let's see a real (correct) example, please. You can always know that the examples in libs/python/test are correct. See libs/python/test/polymorphism2.cpp/.py -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Fri Aug 5 20:10:40 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 5 Aug 2005 15:10:40 -0300 Subject: [C++-sig] How do I wrap virtual methods (solved) Message-ID: <432ec6c5050805111018da58a8@mail.gmail.com> Hi all, I changed the wrapping approach to the wrapper<...>, and with some ajustments it worked. I will display the code (just the essential part) below: struct QObject_Wrapper: QObject, wrapper { // notice that I have overloaded constructors // so I have to redefine them QObject_Wrapper(): QObject() { } QObject_Wrapper(QObject* parent): QObject(parent) { } bool event(QEvent* p0) { if (override event = this->get_override("event")) { // here is the trick. "event" is a Python object // not a real C++ funcion return event( ptr( p0 ) ); } return QObject::event(p0); } bool default_event(QEvent* p0) { return this->QObject::event(p0); } }; void export_QObject() { class_, boost::noncopyable> ("QObject") // constructor with no parent .def(init<>()) // constructor with QObject parent .def(init( args("parent") ) [with_custodian_and_ward<1,2>()] ) .def("event", &QObject::event, &QObject_Wrapper::default_event) ; } So, it solved the problem. The only thing that I am concerned about, is how does it know to convert native "QObject" to the "QObject_Wrapper". Well its working well anyway. BTW, Pyste must be updated for that wrapper<...> use. Thanks everybody. I am enjoying Boost.Python more everyday :) [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 5 20:45:05 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 14:45:05 -0400 Subject: [C++-sig] How do I wrap virtual methods (solved) References: <432ec6c5050805111018da58a8@mail.gmail.com> Message-ID: Eric Jardim writes: > The only thing that I am concerned about, is how > does it know to convert native "QObject" to the "QObject_Wrapper". It doesn't. QObject_Wrapper is only needed when the virtual function might be overridden in Python. By the time you have a native QObject, all of its class' virtual functions are already determined. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Fri Aug 5 22:25:20 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 5 Aug 2005 17:25:20 -0300 Subject: [C++-sig] How do I wrap virtual methods (solved) In-Reply-To: References: <432ec6c5050805111018da58a8@mail.gmail.com> Message-ID: <432ec6c505080513257c1838a4@mail.gmail.com> 2005/8/5, David Abrahams : > > It doesn't. QObject_Wrapper is only needed when the virtual function > might be overridden in Python. By the time you have a native QObject, > all of its class' virtual functions are already determined. > Sure, but how does Boost.Python knows that I am exposing QObject? I am exposing a derived class of it (QObject_wrapper). Someway, it knows that, implicitly, QObject must me exposed too. I created a function for test this: QObject* factory(QObject* parent) { return new QObject(parent); } And later: def("factory", factory, return_value_policy >()); But how does it will manage this, is I am holding shared pointer to an QObject_Wrapper? class_, boost::noncopyable> ("QObject") I tried to change the pointer to a boost::shared_ptr but it did't worked. But somehow, it is working with the wrapper pointer. There may be some "magic" behing the templates :) And the good news is that there is no need to create the QCustomObject class :) Thanks again, [Eric Jardim] Boost.Python new fan! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Fri Aug 5 23:05:27 2005 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 05 Aug 2005 17:05:27 -0400 Subject: [C++-sig] How do I wrap virtual methods (solved) References: <432ec6c5050805111018da58a8@mail.gmail.com> <432ec6c505080513257c1838a4@mail.gmail.com> Message-ID: Eric Jardim writes: > 2005/8/5, David Abrahams : >> >> It doesn't. QObject_Wrapper is only needed when the virtual function >> might be overridden in Python. By the time you have a native QObject, >> all of its class' virtual functions are already determined. >> > > Sure, but how does Boost.Python knows that I am exposing QObject? I am > exposing a derived class of it (QObject_wrapper). Someway, it knows that, > implicitly, QObject must me exposed too. It knows that QObject_wrapper is derived from wrapper. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Sat Aug 6 07:00:46 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sat, 6 Aug 2005 02:00:46 -0300 Subject: [C++-sig] How to wrap protected virtual methods Message-ID: <432ec6c5050805220061d772fa@mail.gmail.com> Hi, again... I finally managed to wrap public virtual functions correctly. Everything is fine and I eliminated all of the "segfaults" caused by bad chosen return value policies. But I have another challenge: wrapping protected virtual methods. I know that virtual methods cannot be called outside the class. They might be visible only by its class scope and its derived classes. But imagine now (thinking hybrid) that you may want to derive this C++ class (with a protected method) in Python. Then, it should be something like this: ======= C++ ========= class QWidget: { ... protected: void mouseEvent(QEvent* event) { ... } }; ====== Python ====== class MyWidget(QWidget): def __init__(self, ...): QWidget(self, ...) def mouseEvent(self, event): # ... do something QWidget.mouseEvent(self, event) # call the default after or: def mouseEvent(self, event): QWidget.mouseEvent(self, event) # call the default before # ... do something or worse: def mouseEvent(self, event): # ... do something # do not call the default I tried the same approach we discussed today on this list. But it didnt worked, because the compiler complainted when I tried to pass a pointer of a protected method. So, is there any way to do this, as naturally as possible? I though 2 solutions for this problem: 1 - One is wrapping the "default_mouseEvent" on the wrapped class with a different name. I think it should work, but the user must know that he should call a different name for the same function. It may confuse the user. 2 - The other way is a "hack". I can create a static semaphor inside the method, so I realise if it is the first (or not) time it is being called. If it is called the first time, I try to call the Python overriden version. If it is called twice or more, I call the default implementation. This way, the user can use the same function for different behaviors. The second approach seems to be dangerous. I am afraid of loosing the semaphor control (eg: if an exception is thrown). Well, is there a more simple and secure way of doing this? Thanks, [Eric Jardim] P.S. Sorry for bothering you all with so many questions in just a single day -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericjardim at gmail.com Sat Aug 6 15:15:17 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sat, 6 Aug 2005 10:15:17 -0300 Subject: [C++-sig] How to wrap protected virtual methods In-Reply-To: <432ec6c5050805220061d772fa@mail.gmail.com> References: <432ec6c5050805220061d772fa@mail.gmail.com> Message-ID: <432ec6c5050806061520dd3351@mail.gmail.com> Hi, everyone... I think I solved this "problem". Actually, I think that there is no problem. I worked so much last night that I couldn't see the simple solution. class QWidget_Wrapper: QWidget, wrapper { void mousePressEvent(QMouseEvent* p0) { if (override mousePressEvent = this->get_override("mousePressEvent")) { mousePressEvent( ptr( p0 ) ); } else { QWidget::mousePressEvent(p0); } } void default_mousePressEvent(QMouseEvent* p0) { QWidget::mousePressEvent(p0); } ... }; // and do .def("mousePressEvent", &QWidget::mousePressEvent, &QWidget_Wrapper::default_mousePressEvent) // instead of .def("mousePressEvent", &QWidget_Wrapper::default_mousePressEvent) So, solved another issue. But I think this should be noticed on some place of the docs or the tutorial itself. [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From faheem at email.unc.edu Sat Aug 6 19:10:30 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Sat, 6 Aug 2005 17:10:30 +0000 (UTC) Subject: [C++-sig] wrapping virtual function returning void Message-ID: Hi, Consider wrapping a class containg a virtual function returning void. The current method, which appears below for convenience, and is copied verbatim from the tutorial, seems to expect that the virtual function returns something. In other words, changing f to return void would break the code. Is this the case, or am I missing something? Please CC me on any reply. Thanks. Faheem. ********************************************************************* #include using namespace boost::python; struct Base { virtual ~Base() {} virtual int f() { return 0; } }; struct BaseWrap : Base, wrapper { int f() { if (override f = this->get_override("f")) return f(); // *note* return Base::f(); } int default_f() { return this->Base::f(); } }; BOOST_PYTHON_MODULE(hello) { class_("Base") .def("f", &Base::f, &BaseWrap::default_f) ; } ********************************************************************** From ericjardim at gmail.com Sun Aug 7 02:42:15 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sat, 6 Aug 2005 21:42:15 -0300 Subject: [C++-sig] wrapping virtual function returning void In-Reply-To: References: Message-ID: <432ec6c505080617421c3ac425@mail.gmail.com> That's easy! struct BaseWrap : Base, wrapper { void f() { if (override f = this->get_override("f")) f(); else Base::f(); } void default_f() { Base::f(); } }; Did not hurt, did it? :) [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From faheem at email.unc.edu Sun Aug 7 04:38:25 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Sat, 6 Aug 2005 22:38:25 -0400 (EDT) Subject: [C++-sig] wrapping virtual function returning void In-Reply-To: <432ec6c505080617421c3ac425@mail.gmail.com> References: <432ec6c505080617421c3ac425@mail.gmail.com> Message-ID: On Sat, 6 Aug 2005, Eric Jardim wrote: > That's easy! > > struct BaseWrap : Base, wrapper > { > void f() > { > if (override f = this->get_override("f")) > f(); > else > Base::f(); > } > > void default_f() { Base::f(); } > }; That's interesting. So, for pure virtual functions, it would look like the version below? I don't understand what this wrapper is doing, so that makes it more difficult for me to make these deductions. According to the documentation, it overrides the base class in Python. I assume this is related to the derived class wrappers in Python knowing of their derived relationship to the base class wrapper, but I'm pretty fuzzy on the details. If some kind person wants to try to explain it, I'm all ears. Faheeem. ************************************************************************* #include using namespace boost::python; struct Base { virtual ~Base() {} virtual void f() = 0; }; struct BaseWrap : Base, wrapper { void f() { this->get_override("f")(); } }; BOOST_PYTHON_MODULE(hello) { boost::python::class_("Base") .def("f", boost::python::pure_virtual(&Base::f)) ; } From ericjardim at gmail.com Sun Aug 7 14:52:02 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sun, 7 Aug 2005 09:52:02 -0300 Subject: [C++-sig] wrapping virtual function returning void In-Reply-To: References: <432ec6c505080617421c3ac425@mail.gmail.com> Message-ID: <432ec6c5050807055236e2cd66@mail.gmail.com> 2005/8/6, Faheem Mitha : > > That's interesting. So, for pure virtual functions, it would look like the > version below? Sure! I don't understand what this wrapper is doing, so that makes it more > difficult for me to make these deductions. The wrapper<...> is doing goog things. Before the existence of wrapper<...>, when someone wanted to create derived wrapper class, they should expose a "PyObject* self" (which is a low-level pointer for the Boost.Pythonhigh-level users) as the first argument of every constructor. Now, with wrapper<...>, it is incapsulating the "PyObject* self" and you don't even have to know it exists. Besides, it creates this get_override function, that helps you if an virtual method was overriden in Python. According to the documentation, it overrides the base class in Python. I > assume this is related to the derived class wrappers in Python knowing of > their derived relationship to the base class wrapper, but I'm pretty fuzzy > on the details. That's the good point of the incapsulation. While it works, you don't have to care about the details :) [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Sun Aug 7 14:57:09 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 07 Aug 2005 08:57:09 -0400 Subject: [C++-sig] How to wrap protected virtual methods References: <432ec6c5050805220061d772fa@mail.gmail.com> <432ec6c5050806061520dd3351@mail.gmail.com> Message-ID: Eric Jardim writes: > // and do > .def("mousePressEvent", &QWidget::mousePressEvent, > &QWidget_Wrapper::default_mousePressEvent) > > // instead of > .def("mousePressEvent", &QWidget_Wrapper::default_mousePressEvent) > > So, solved another issue. But I think this should be noticed on some place > of the docs or the tutorial itself. I honestly don't think this is a problem that anyone else has. It probably doesn't make sense to document mistakes like passing the wrong arguments to a function until it becomes a common occurrence. After all, there are so many functions other than "def" that you could make that mistake with! -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Aug 7 15:00:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 07 Aug 2005 09:00:35 -0400 Subject: [C++-sig] wrapping virtual function returning void References: <432ec6c505080617421c3ac425@mail.gmail.com> Message-ID: Faheem Mitha writes: > On Sat, 6 Aug 2005, Eric Jardim wrote: > >> That's easy! >> >> struct BaseWrap : Base, wrapper >> { >> void f() >> { >> if (override f = this->get_override("f")) >> f(); >> else >> Base::f(); >> } >> >> void default_f() { Base::f(); } >> }; > > That's interesting. So, for pure virtual functions, it would look like the > version below? > > I don't understand what this wrapper is doing, so that makes it more > difficult for me to make these deductions. > > According to the documentation, it overrides the base class in > Python. I'm pretty sure the documentation only ever talks about overriding functions and methods, not classes. What do you really mean to say? > I assume this is related to the derived class wrappers in Python > knowing of their derived relationship to the base class wrapper, but > I'm pretty fuzzy on the details. > > If some kind person wants to try to explain it, I'm all ears. I'm sorry, I don't understand the question yet. -- Dave Abrahams Boost Consulting www.boost-consulting.com From faheem at email.unc.edu Sun Aug 7 19:00:43 2005 From: faheem at email.unc.edu (Faheem Mitha) Date: Sun, 7 Aug 2005 13:00:43 -0400 (EDT) Subject: [C++-sig] wrapping virtual function returning void In-Reply-To: <432ec6c5050807055236e2cd66@mail.gmail.com> References: <432ec6c505080617421c3ac425@mail.gmail.com> <432ec6c5050807055236e2cd66@mail.gmail.com> Message-ID: On Sun, 7 Aug 2005, Eric Jardim wrote: > The wrapper<...> is doing goog things. Before the existence of wrapper<...>, > when someone wanted to create derived wrapper class, they should expose a > "PyObject* self" (which is a low-level pointer for the > Boost.Pythonhigh-level users) as the first argument of every > constructor. > > Now, with wrapper<...>, it is incapsulating the "PyObject* self" and you > don't even have to know it exists. Besides, it creates this get_override > function, that helps you if an virtual method was overriden in Python. Yes, but what does it mean to say that a virtual method is overriden in Python, exactly? >> According to the documentation, it overrides the base class in Python. >> assume this is related to the derived class wrappers in Python knowing >> of their derived relationship to the base class wrapper, but I'm pretty >> fuzzy on the details. > That's the good point of the incapsulation. While it works, you don't have > to care about the details :) Details are good. :-) Faheem. From dave at boost-consulting.com Sun Aug 7 20:02:12 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 07 Aug 2005 14:02:12 -0400 Subject: [C++-sig] wrapping virtual function returning void References: <432ec6c505080617421c3ac425@mail.gmail.com> <432ec6c5050807055236e2cd66@mail.gmail.com> Message-ID: Faheem Mitha writes: > On Sun, 7 Aug 2005, Eric Jardim wrote: > >> The wrapper<...> is doing goog things. Before the existence of wrapper<...>, >> when someone wanted to create derived wrapper class, they should expose a >> "PyObject* self" (which is a low-level pointer for the >> Boost.Pythonhigh-level users) as the first argument of every >> constructor. >> >> Now, with wrapper<...>, it is incapsulating the "PyObject* self" and you >> don't even have to know it exists. Besides, it creates this get_override >> function, that helps you if an virtual method was overriden in Python. > > Yes, but what does it mean to say that a virtual method is overriden in > Python, exactly? Ah, good question. It means we provide the /illusion/ that it is overridden in Python. When you write class Foo_Wrapper : Foo, wrapper { ... void f() { if (override f = get_override("f")) f(); else this->default_f(); } }; You're actually overriding f with a C++ member function that implements the illusion. It says: if the Python object corresponding to this C++ object has an attribute called "f", invoke it. Otherwise, invoke the C++ "f" member function that you would have invoked had this C++ override never been written. >From the Python programmer's point-of-view, he can derive classes from the wrapped class and implement an "f" method that will be called whenever, from point-of-view of the the C++ programmer who wrote Foo, someone calls the Foo::f on the wrapped object. Make sense? >> That's the good point of the incapsulation. While it works, you don't have >> to care about the details :) > > Details are good. :-) Faheem. Trust me; you don't wanna know ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com From martin at v.loewis.de Sun Aug 7 23:11:56 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 07 Aug 2005 23:11:56 +0200 Subject: [C++-sig] [Python-Dev] GCC version compatibility In-Reply-To: <200507172321.31665.anthony@interlink.com.au> References: <200507171601.23780.anthony@interlink.com.au> <20050717100609.GB3581@lap200.cdc.informatik.tu-darmstadt.de> <200507172321.31665.anthony@interlink.com.au> Message-ID: <42F6791C.3030602@v.loewis.de> Anthony Baxter wrote: > I should probably add that I'm not flagging that I think there's a problem > here. I'm mostly urging caution - I hate having to cut brown-paper-bag > releases . If possible, can the folks on c++-sig try this patch > out and put their results in the patch discussion? If you're keen, you > could try jumping onto HP's testdrive systems (http://www.testdrive.hp.com/). >>From what I recall, they have a bunch of systems with non-gcc C++ compilers, > including the DEC^WDigital^Compaq^WHP one on the alphas, and the HP C++ > compiler on the HP/UX boxes[1]. I've looked at the patch, and it looks fairly safe, so I committed it. Regards, Martin From cludwig at cdc.informatik.tu-darmstadt.de Mon Aug 8 09:07:13 2005 From: cludwig at cdc.informatik.tu-darmstadt.de (Christoph Ludwig) Date: Mon, 8 Aug 2005 09:07:13 +0200 Subject: [C++-sig] [Python-Dev] GCC version compatibility In-Reply-To: <42F6791C.3030602@v.loewis.de> References: <200507171601.23780.anthony@interlink.com.au> <20050717100609.GB3581@lap200.cdc.informatik.tu-darmstadt.de> <200507172321.31665.anthony@interlink.com.au> <42F6791C.3030602@v.loewis.de> Message-ID: <20050808070712.GB3570@lap200.cdc.informatik.tu-darmstadt.de> On Sun, Aug 07, 2005 at 11:11:56PM +0200, "Martin v. L?wis" wrote: > I've looked at the patch, and it looks fairly safe, so I committed it. Thanks. I did not forget my promise to look into a more comprehensive approach to the C++ build issues. But I first need to better understand the potential impact on distutils. And, foremost, I need to finish my thesis whence my spare time projects go very slowly. Regards Christoph -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html From seefeld at sympatico.ca Mon Aug 8 09:30:12 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 08 Aug 2005 09:30:12 +0200 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc In-Reply-To: References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> <42EF53DD.8090407@sympatico.ca> Message-ID: <42F70A04.3030505@sympatico.ca> David Abrahams wrote: > Stefan Seefeld writes: >>>Yeah, but why would you do that when you could preprocess for GCC? >> >>Because that would require a separate gcc to be installed first ? >> >>(The gccxml tarball I unpacked on my linux box doesn't appear to >> contain anything related to a complete development environment >> such as system headers.) > > > Well, that doesn't seem like it ought to be a significant obstacle. > It seems unreasonable to expect GCCXML to process nonstandard MSVC > constructs correctly. May be. The problem is that developers have a particular platform with a system compiler, and they want to process code that is written in and for that environment. So the only two options for a windows developer are a) to install a second compiler that is more standard compliant or b) to change the processing tool to understand the MSVC-specific constructs. Right ? And if, in particular, they want to 'look' at the code from the system compiler's perspective, they don't have a choice but to pursue option b). Regards, Stefan From dave at boost-consulting.com Mon Aug 8 14:04:06 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 08 Aug 2005 08:04:06 -0400 Subject: [C++-sig] pyste, gccxml and boost ublas, random number generator etc References: <20050729192409.21308.qmail@web30701.mail.mud.yahoo.com> <42EA9C27.7080406@esss.com.br> <42EDDB61.3010604@sympatico.ca> <42EE18C1.7040901@esss.com.br> <42EE1CA2.7030808@sympatico.ca> <42EF53DD.8090407@sympatico.ca> <42F70A04.3030505@sympatico.ca> Message-ID: Stefan Seefeld writes: > David Abrahams wrote: >> Stefan Seefeld writes: > >>>>Yeah, but why would you do that when you could preprocess for GCC? >>> >>>Because that would require a separate gcc to be installed first ? >>> >>>(The gccxml tarball I unpacked on my linux box doesn't appear to >>> contain anything related to a complete development environment >>> such as system headers.) >> >> >> Well, that doesn't seem like it ought to be a significant obstacle. >> It seems unreasonable to expect GCCXML to process nonstandard MSVC >> constructs correctly. > > May be. The problem is that developers have a particular platform > with a system compiler, and they want to process code that is written > in and for that environment. > So the only two options for a windows developer are a) to install a second > compiler that is more standard compliant Won't necessarily help. Even a perfectly compliant compiler can include nonstandard extensions. > or b) to change the processing tool to understand the MSVC-specific > constructs. Right ? c) Use #ifdefs where necessary to make their code "portable" to the processing tool. > And if, in particular, they want to 'look' at the code from the > system compiler's perspective, they don't have a choice but to > pursue option b). Yeah I guess so. But how important is that? -- Dave Abrahams Boost Consulting www.boost-consulting.com From Masoud.Mohammadian at canberra.edu.au Tue Aug 9 04:56:53 2005 From: Masoud.Mohammadian at canberra.edu.au (Mohammadian, Masoud) Date: Tue, 9 Aug 2005 12:56:53 +1000 Subject: [C++-sig] CFP: IEEE in cooperated International Conference on Computational Intelligence for Modelling, Control and Automation Message-ID: <088D96D6E422174EAABF7B27D94F3EE702D47014@hera.ucstaff.win.canberra.edu.au> CFP: IEEE in cooperated International Conference on Computational Intelligence for Modelling, Control and Automation CALL FOR PAPERS International Conference on Computational Intelligence for Modelling, Control and Automation 28 - 30 November 2005 Vienna, Austria http://www.ise.canberra.edu.au/conferences/cimca05/ In co-operation with: IEEE Computational Intelligence Society Conference Proceedings will be published as books by IEEE in USA Sponsored by: European Society for Fuzzy Logic and Technology - EUFLAT International Association for Fuzzy Set in Management and Economy - SIGEF Japan Society for Fuzzy Theory and Intelligent Informatics - SOFT Taiwan Fuzzy Systems Association - TFSA World Wide Web Business Intelligence - W3BI Hungarian Fuzzy Association - HFA University of Canberra Jointly with International Conference on Intelligent Agents, Web Technologies and Internet Commerce http://www.ise.canberra.edu.au/conferences/iawtic05/ Honorary Chair: Lotfi A. Zadeh, University of California, USA Stephen Grossberg, Boston University, USA The international conference on computational intelligence for modelling, control and automation will be held in Vienna, Austria on 28 to 30 November 2005. The conference provides a medium for the exchange of ideas between theoreticians and practitioners to address the important issues in computational intelligence, modelling, control and automation. The conference will consist of both plenary sessions and contributory sessions, focusing on theory, implementation and applications of computational intelligence techniques to modelling, control and automation. For contributory sessions, papers (4 pages or more) are being solicited. Several well-known keynote speakers will address the conference. Conference Proceedings will be published as books by IEEE (The Institute of Electrical and Electronic Engineering) in USA and will be index world wide. All papers will be peer reviewed by at least two reviewers. Topics of the conference include, but are not limited to, the following areas: Modern and Advanced Control Strategies: Neural Networks Control, Fuzzy Logic Control, Genetic Algorithms and Evolutionary Control, Model-Predictive Control, Adaptive and Optimal Control, Intelligent Control Systems, Robotics and Automation, Fault Diagnosis, Intelligent agents, Industrial Automations Hybrid Systems: Fuzzy Evolutionary Systems, Fuzzy Expert Systems, Fuzzy Neural Systems, Neural Genetic Systems, Neural-Fuzzy-Genetic Systems, Hybrid Systems for Optimisation Data Analysis, Prediction and Model Identification: Signal Processing, Prediction and Time Series Analysis, System Identification, Data Fusion and Mining, Knowledge Discovery, Intelligent Information Systems, Image Processing, and Image Understanding, Parallel Computing applications in Identification & Control, Pattern Recognition, Clustering and Classification Decision Making and Information Retrieval: Case-Based Reasoning, Decision Analysis, Intelligent Databases & Information Retrieval, Dynamic Systems Modelling, Decision Support Systems, Multi-criteria Decision Making, Qualitative and Approximate-Reasoning Paper Submission Papers will be selected based on their originality, significance, correctness, and clarity of presentation. Papers (4 pages or more) should be submitted to the following e-mail or the following address: CIMCA'2005 Secretariat School of Information Sciences and Engineering University of Canberra, Canberra, 2616, ACT, Australia E-mail: cimca at canberra.edu.au Electronic submission of papers (either by E-mail or through conference website) is preferred. Draft papers should present original work, which has not been published or being reviewed for other conferences. Important Dates 31 August 2005 Submission of draft papers 30 September 2005 Notification of acceptance 21 October 2005 Deadline for camera-ready copies of accepted papers 28-30 November 2005 Conference sessions Special Sessions and Tutorials Special sessions and tutorials will be organised at the conference. The conference is calling for special sessions and tutorial proposals. All special session proposals should be sent to the conference chair (by email to: masoud.mohammadian at canberra.edu.au) on or before 5th of August 2005. CIMCA'05 will also include a special poster session devoted to recent work and work-in-progress. Abstracts are solicited for this session. Abstracts (3 pages limit) may be submitted up to 30 days before the conference date. Visits and social events Sightseeing visits will be arranged for the delegates and guests. A separate program will be arranged for companions during the conference. Further Information For further information either contact cimca at ise.canberra.edu.au or see the conference homepage at: http://www.ise.canberra.edu.au/conferences/cimca05/default.htm Organising Committee Chair: Masoud Mohammadian, University of Canberra, Australia International Program Committee: H. Adeli, The Ohio State University, USA W. Pedrycz, University of Manitoba, Canada A. Agah, The University of Kansas, USA T. Fukuda, Nagoya University, Japan J. Bezdek, University of West Florida, USA R. C. Eberhart, Purdue University, USA F. Herrera, University of Granada, Spain T. Furuhashi, Nagoya University, Japan A. Agah, The University of Kansas, US E. Andr?, Universit?t Augsburg, Germany A. Kandel, University of South Florida, USA J. P. Bigus, IBM T. J. Watson Research Center, USA J. Liu, Hong Kong Baptist University, Hong Kong A. Namatame, National Defense Academy, Japan K. Sycara, Carnegie Mellon University, USA B. Kosko, University of Southern California, USA T. Baeck, Informatic Centrum Dortmund, Germany K. Hirota, Tokyo Institute of Technology, Japan E. Oja, Helsinki University of Technology, Finland H. R. Berenji, NASA Ames Research Center, USA H. Liljenstrom, Royal Institute of Technology, Sweden A. Bulsari, AB Nonlinear Solutions OY, Finland J. Fernandez de Ca?ete, University of Malaga, Spain W. Duch, Nicholas Copernicus University, Poland E. Tulunay, Middle East Technical University, Turkey C. Kuroda, Tokyo Institute of Technology, Japan T. Yamakawa, Kyushu Institute of Technology, Japan J. Liu, Hong Kong Baptist University, Hong Kong A. Namatame, National Defense Academy, Japan A. Aamodt, Norwegian University of Science & Technology, Norway International Liaison: Canada and USA Liaison: Robert John, De Montfort University, UK Nasser Jazdi, Institut f?r Automatisierungs- und Softwaretechnik, Germany Europe Liaison: Dr. Eng. Djamel Khadraoui, Centre de Recherche Public, Luxembourg Frank Zimmer, SES ASTRA, Luxembourg Asia Liaison: Renzo Gobbin, University of Canberra, Australia R. Amin Sarker, ADFA, Australia Local Arrangements and Public Relation: Zohreh Pahlavani, AVIP, Austria C Meier, Australia Publicity: C. Meier, Australia Zohreh Pahlavani, AVIP, Austria Publication: Masoud Mohammadian, Australia In cooperation with: IEEE Computational Intelligence Society Conference Proceedings will be published as books by IEEE in USA University of Canberra, (Masoud Mohammadian) Universidad Carlos III de Madrid, (Jos?-Luis Fern?ndez-Villaca?as Mart?n) University of Guelph, (Simon X. Yang) -------------- next part -------------- An HTML attachment was scrubbed... URL: From Masoud.Mohammadian at canberra.edu.au Tue Aug 9 05:37:33 2005 From: Masoud.Mohammadian at canberra.edu.au (Mohammadian, Masoud) Date: Tue, 9 Aug 2005 13:37:33 +1000 Subject: [C++-sig] CFP: IEEE in cooperated International Conference on Intelligent Agents, Web Technologies and Internet Commerce Message-ID: <088D96D6E422174EAABF7B27D94F3EE702D4702A@hera.ucstaff.win.canberra.edu.au> CFP: IEEE in cooperated International Conference on Intelligent Agents, Web Technologies and Internet Commerce CALL FOR PAPERS International Conference on Intelligent Agents, Web Technologies and Internet Commerce http://www.ise.canberra.edu.au/conferences/iawtic05/ Jointly with International Conference on Computational Intelligence for Modelling, Control and Automation 28 - 30 November 2005 Vienna, Austria http://www.ise.canberra.edu.au/conferences/cimca05/ In co-operation with IEEE the conference Proceedings will be published as books by IEEE in USA International Conference on Intelligent Agents, Web Technology and Internet Commerce - IAWTIC'2005 provides a medium for researchers and practitioners to exchange and explore the issues and opportunities in the area of intelligent agent, web technologies and Internet commerce. The conference will consist of both plenary sessions and contributory sessions, focusing on theory, implementation and applications of intelligent agents, web technologies and Internet commerce. Conference Proceedings will be published as books by IEEE (The Institute of Electrical and Electronic Engineering) in USA and will be index world wide. All papers will be peer reviewed by at least two reviewers. Conference Topics Include (but not limited to): Intelligent Agents ^^^^^^^^^^^^^^^^^^ Knowledge Management Intelligent Business Agents Agent Architectures Environments and Languages Adaptation and learning for agents Human and agent interaction Interface agents Mobile agents Virtual agent-based marketplaces Agents and uncertainty The privacy issues for agents Automated shopping and trading agents Agent-oriented services Social implications for agent Conceptual modelling and design of Ontologies for agents Agents and e-commerce Legal aspects of agents in e-commerce Performance measurement of e-commerce agents Rational information agents and electronic commerce Auction and negotiation for e-commerce agents Web Technologies ^^^^^^^^^^^^^^^^ Web data mining and information retrieval Agent-based trade-and mediating services Teaching on Web Virtual trading institutions Internet Commerce ^^^^^^^^^^^^^^^^^ E-commerce applications of Knowledge Representation Reasoning Techniques Electronic Payment Systems Internet Marketing Intranets and Extranets Electronic Payment Systems Electronic Data Interchange Supply Chain Management Electronic Payment Systems Internet-based Electronic Commerce Virtual Communities/Community Networks Logistics Issues for Electronic Commerce Business Reengineering Issues for Electronic Commerce Government Electronic Procurement and Service Delivery Legal, Auditing or Security Issues for Electronic Commerce Requirements Engineering Approaches for Electronic Commerce Knowledge Discovery, Intelligent Information Systems Knowledge Clustering Classification Call for papers Papers will be selected based on their originality, significance, correctness, and clarity of presentation. Papers (4 pages or more) should be submitted to the following e-mail or postal address: E-mail submission of draft papers to: iawtic at canberra.edu.au Postal Submission of draft papers to: IAWTIC'2003 Secretariat School of Information Sciences and Engineering, University of Canberra, ACT, Canberra, 2616, Australia Papers should present original work, which has not been published or being reviewed for other conferences. Papers should be written in English. The name and affiliation of authors should be omitted on the paper. A separate page must be included with each paper, containing, the names, affiliations, postal address and e-mail addresses of authors as well as the address of contact author. E-mail submission of draft papers are encouraged. Important Dates 31 August 2005 Submission of draft papers 30 September 2005 Notification of acceptance 21 October 2005 Deadline for camera-ready copies of accepted papers 28-30 November 2005 Conference sessions International Programme Committee A. Agah, The University of Kansas, USA J. P. Bigus, IBM T.J. Watson Research Center, USA E. Andr?, Universit?t Augsburg, Germany Katia Sycara, Carnegie Mellon University, USA H. Adeli, The Ohio State University, USA B. Kosko, University of Southern California, USA A. Kandel, University of South Florida, USA T. Fukuda, Nagoya University, Japan T. Baeck, Informatic Centrum Dortmund, Germany J.Bezdek, University of West Florida, USA M. Mohammadian University of Canberra, Australia K. Hirota, Tokyo Institute of Technology, Japan G. Dorffner, University of Vienna, Austria E. Oja, Helsinki University of Technology, Finland W. Pedrycz, University of Manitoba, Canada H. R. Berenji, NASA Ames Research Center, USA R. C. Eberhart, Purdue University,USA T. Shibata, MITI, Ministry of International Trade and Industry, Japan H. Liljenstrom, Royal Institute of Technology, Sweden A. Y. Zomaya, University of Western Australia, Australia F. Herrera, University of Granada, Spain A Jafari, Indiana University Purdue University Indianapolis, IUPUI, USA A. Bulsari, AB Nonlinear Solutions OY, Finland B. Bignall, Monash University, Australia J. D. Pinter, Dalhousie University, Canada V. Piuri, Politecnico di Milano, Italy T. Furuhashi, Nagoya University, Japan A. Aamodt, Norwegian University of Science and Technology, Norway J. Fernandez de Ca?ete, University of Malaga, Spain W. Duch, Nicholas Copernicus,University, Poland E. Tulunay, Middle East Technical University, Turkey L. Guan, University of Sydney, Australia C. Kuroda, Tokyo Institute of Technology, Japan T. Yamakawa, Kyushu Institute of Technology, Japan J. Liu, Hong Kong Baptist University, Hong Kong A. Namatame, National Defense Academy, Japan -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Tue Aug 9 20:32:27 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 09 Aug 2005 14:32:27 -0400 Subject: [C++-sig] polymorphic object handling References: <42EF53BB.8010201@temf.tu-darmstadt.de> Message-ID: Burkhard Doliwa writes: > Hi all, > > I have a problem wrapping a factory function to python. I have two > abstract base classes A,B, with some child classes > > A<-A1,A2,A3 > B<-B1,B2,B3 > > every child class is either able to clone itself or to return an > instance of the corresponding "parallel class", i.e. > > A* A1::cloneA() const yields an A1 > B* A1::cloneB() const yields an B1 > > A* B2::cloneA() const yields an A2 > B* B2::cloneB() const yields an B2 > > and so forth. The factory function > > object factoryA(const A&, bool isA) { > return isA? object(A.cloneA()) : object(A.cloneB()); > } > > only returns python objects of the base class types, not the derived > classes, i.e. > > >>> a1=A1() > >>> factory(a1,True) > result= A object (NOT an A1 object) > > How could I create the correct derived class in such a conditional > factory function (like the return_value_policy() case)? You might consider: template T* owned(T* x) { return x; } object factoryA(const A&, bool isA) { return isA? make_function( &owned, return_value_policy() )(ptr(A.cloneA())) : make_function( &owned, return_value_policy() )(ptr(A.cloneB())) ; } However, a more principled approach would have the cloneX functions return an auto_ptr and then do register_ptr_to_python >() Then you can leave factoryA as it was. -- Dave Abrahams Boost Consulting www.boost-consulting.com From ahrivera at yahoo.com Wed Aug 10 01:58:30 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 9 Aug 2005 16:58:30 -0700 (PDT) Subject: [C++-sig] to_python / from_python guidance? Message-ID: <20050809235830.42110.qmail@web30702.mail.mud.yahoo.com> Pierre, I figured out the problem. The problem was exactly what you said. I didn't need the Vrjuggler libraries since I already had the python bindings from the ggt code. What happened was that in building the python bindings, the release version of python boost was used and I was compiling my code in debug mode using the debug version of python boost. I linked my code againts the release version of python boost and it worked as expected. Thanks, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From skottmckay at gmail.com Wed Aug 10 04:35:02 2005 From: skottmckay at gmail.com (Scott McKay) Date: Tue, 9 Aug 2005 20:35:02 -0600 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite Message-ID: <51d01787050809193534085538@mail.gmail.com> Is there a way to set the policy for the vector_indexing_suite to not create a copy of the vector itself (not the internal elements) in python? I have a vector being held by the vector indexing suite defined like... class_< std::vector< smart_ptr > > ( "vector_X" ) .def( vector_indexing_suite< std::vector< smart_ptr > >() ) ; I then have a python extension of a c++ class, which has a method that takes a reference to std::vector< smart_ptr > and populates it by calling the c++ parent class. If I do something like the following... class TestExtendedFactory( x.BasicFactory ): def __init__( self ): super( TestExtendedFactory, self ).__init__() def generate( self, vectorOfSmartPtrXs ): # first generate with our parent super( TestExtendedFactor, self ).generate( vectorOfSmartPtrXs ) ... the entries added by the call to BasicFactory.generate() show up just fine in python, but don't make it back to the original c++ caller of TestExtendedFactory.generate as it is using a copy of the vector not the original one. Thanks Scott From roman.yakovenko at gmail.com Wed Aug 10 09:16:44 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 10 Aug 2005 10:16:44 +0300 Subject: [C++-sig] [Announce] py++ new version available In-Reply-To: <7465b61705071203464a827d2a@mail.gmail.com> References: <7465b61705071203464a827d2a@mail.gmail.com> Message-ID: <7465b617050810001674a091a6@mail.gmail.com> I would like to announce a new version of py++. What is py++? py++ is a framework of components for creating a C++ code generator for boost.python. Code generation with the py++ framework is a very flexible and highly configurable process. You can find an explanation about py++ at: http://pygccxml.sourceforge.net/pyplusplus/py++.html Status: First of all, this project is under active development. Second py++ now has almost all futures that Pyste has and adds a few more. py++ can export the following declarations: enums ( named and unnamed ) member variables global variables operators ( partially ) free functions member functions classes virtual functions could be overridden from Python For big project py++ introduces new functionality: creating multiple files. It creates 2 files per one exported top level class. py++ 0.0.2 depends on pygccxml 0.6.5 Installation instructions: For pygccxml there is a setup.py file, so installation should be a simple task. For py++ there is no setup yet. py++ is a regular python package, so place it somewhere and add its location to sys.path. Ideas, comments, suggestions or help are welcomed. Roman Yakovenko From oleg_python at yahoo.de Wed Aug 10 12:55:40 2005 From: oleg_python at yahoo.de (Oleg Novychny) Date: Wed, 10 Aug 2005 12:55:40 +0200 (CEST) Subject: [C++-sig] Python interpreter crashes after trying to callback a python function with PyObject_CallObject from a dll Message-ID: <20050810105540.25274.qmail@web25709.mail.ukl.yahoo.com> Hello guys, I?m still implementing my callback to python from my dll and the python interpreter crashes I have no idea atm why I use the calldll module for calling my c++-dll from my module calldllsound.py: import calldll import struct class CallSoundDLL: def __init__(self, library): self.library = library def myGetResults(a): print a #just for debugging calldll.call_foreign_function (self.addrGet,'llllll','i',(self.ulHz.address(), self.dNoise.address(), self.bAudio.address(),self.bCrackFlag.address(), self.dSNR.address(), self.bBeep.address())) def mySetCallback(self): calldll.call_foreign_function (self.addrCall,'O','',(self.myGetResults,)) def start(self): # --------------------------------------------------------------------------------------------- # Get the handle of the dll and the address of the function # --------------------------------------------------------------------------------------------- #Get the handle of the Dll handle = calldll.load_library (self.library) #Get the address of the functions self.addrStart = calldll.get_proc_address (handle, 'StartProcessing') self.addrEnd = calldll.get_proc_address (handle, 'EndProcessing') self.addrGet = calldll.get_proc_address (handle, 'GetResults') self.addrCall = calldll.get_proc_address (handle, 'my_set_callback') # --------------------------------------------------------------------------------------------- # Initialization # --------------------------------------------------------------------------------------------- self.ulHz = calldll.membuf(4) #unsigned long* self.dNoise = calldll.membuf(8) #double* self.bAudio = calldll.membuf(4) #int* self.bCrackFlag = calldll.membuf(4) #int* self.dSNR = calldll.membuf(8) #double* self.bBeep = calldll.membuf(4) #int* # --------------------------------------------------------------------------------------------- # Function calling # --------------------------------------------------------------------------------------------- args = (1,1,1,1,1,1000) calldll.call_foreign_function (self.addrStart,'iiiiik','i',args) So I?m starting my dll on such a way: >>> import calldllsound >>> obj = calldllsound.CallSoundDLL("soundproclib.dll") >>> obj.start() It works without any problems. But after the following command crashes the python interpreter...: >>> obj.mySetCallback() Here is my_set_callback function from my dll, which have to be called in the python function mySetCallback: static PyObject *my_callback = NULL; PyMODINIT_FUNC my_set_callback(PyObject *args) { PyObject *temp = args; Py_XINCREF(temp); /* Add a reference to new callback */ Py_XDECREF(my_callback); /* Dispose of previous callback */ my_callback = temp; /* Remember new callback */ Py_INCREF(Py_None); bPyCallBackFlag = true; }; and here is the part of my code from the same c++-file where I?m trying to call my python-function myGetResults: if (bPyCallBackFlag) { /* Time to call the callback */ ppyobjArgList = Py_BuildValue("(i)",123); //just for debugging // Here crashes the python interpreter, I found it out with // error logging: ppyobjResult = PyObject_CallObject(my_callback, ppyobjArgList); Py_DECREF(ppyobjResult); } Have anybody any idea why it doesn?t work? Thank you very much Oleg --------------------------------- Gesendet von Yahoo! Mail - Jetzt mit 1GB kostenlosem Speicher -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at arrowtheory.com Wed Aug 10 23:21:22 2005 From: simon at arrowtheory.com (Simon Burton) Date: Wed, 10 Aug 2005 22:21:22 +0100 Subject: [C++-sig] Python interpreter crashes after trying to callback a python function with PyObject_CallObject from a dll In-Reply-To: <20050810105540.25274.qmail@web25709.mail.ukl.yahoo.com> References: <20050810105540.25274.qmail@web25709.mail.ukl.yahoo.com> Message-ID: <20050810222122.61e3a8d4.simon@arrowtheory.com> On Wed, 10 Aug 2005 12:55:40 +0200 (CEST) Oleg Novychny wrote: > > Have anybody any idea why it doesn_t work? > > Thank you very much > Oleg Maybe you haven't acquired the GIL ? Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com From dave at boost-consulting.com Wed Aug 10 19:30:36 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 10 Aug 2005 13:30:36 -0400 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite References: <51d01787050809193534085538@mail.gmail.com> Message-ID: Scott McKay writes: > Is there a way to set the policy for the vector_indexing_suite to not > create a copy of the vector itself (not the internal elements) in > python? > > I have a vector being held by the vector indexing suite defined like... > > class_< std::vector< smart_ptr > > ( "vector_X" ) > .def( vector_indexing_suite< std::vector< smart_ptr > >() ) > ; > > I then have a python extension of a c++ class, which has a method that > takes a reference to std::vector< smart_ptr > and populates it by > calling the c++ parent class. > > If I do something like the following... > > class TestExtendedFactory( x.BasicFactory ): > def __init__( self ): > super( TestExtendedFactory, self ).__init__() > > def generate( self, vectorOfSmartPtrXs ): > # first generate with our parent > super( TestExtendedFactor, self ).generate( vectorOfSmartPtrXs ) > ... > > the entries added by the call to BasicFactory.generate() show up just > fine in python, but don't make it back to the original c++ caller of > TestExtendedFactory.generate as it is using a copy of the vector not > the original one. You've left out a lot of detail, but if you want to pass something from C++ to Python by reference, you need to wrap it in boost::ref( ) Otherwise, Boost.Python will take the safe route and pass it by value. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Wed Aug 10 21:26:20 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Wed, 10 Aug 2005 16:26:20 -0300 Subject: [C++-sig] Transfer of ownership Message-ID: <432ec6c5050810122649a976b1@mail.gmail.com> Hi, all... This is a simple question. I was reading the docs where it says about the "transfer of ownership" of a C++ object pointer. I am dealing exacly this situation, where the "with_custodian_and_ward" policy is not enough to prevent Python objects to delete C++ couterparts. The only hack is to hold references, but it is not a complete solution. So, I read the FAQ entry where it explain how to deal with this issue: http://www.boost.org/libs/python/doc/v2/faq.html#ownership But there, it speaks about using an "std::auto_ptr". On the other side, I am using "boost::shared_ptr" to hold my objects. I really do not know the difference between them, but I imagine they provide similar funcionality. So I will split my question in 3 parts: - Is it possible to take the ownership with "boost::shared_ptr", or do I have to change my held types to "std::auto_ptr"? - Is there any difference in practice, using boost's or std's smart pointers? I just use them for holding Boost.Python extensions. - As those functions with smart pointers do not exists, I suppose that I will have to write wrappers like: void b_insert(B& b, std::auto_ptr a) { b.insert(a.get()); a.release(); } Is there any special reason for this to be a non-const reference to "b"? Could it be a const reference or a const/non-const pointer to "b"? Is there any implications? Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhammond at skippinet.com.au Thu Aug 11 00:45:59 2005 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 11 Aug 2005 08:45:59 +1000 Subject: [C++-sig] [python-win32] Python interpreter crashes after trying to callbacka python function with PyObject_CallObject from a dll In-Reply-To: <20050810105540.25274.qmail@web25709.mail.ukl.yahoo.com> Message-ID: > static PyObject *my_callback = NULL; > PyMODINIT_FUNC my_set_callback(PyObject *args) > { > PyObject *temp = args; > Py_XINCREF(temp); /* Add a reference to new callback */ > Py_XDECREF(my_callback); /* Dispose of previous callback */ > my_callback = temp; /* Remember new callback */ > Py_INCREF(Py_None); > bPyCallBackFlag = true; > }; That looks suspect: * PyMODINIT_FUNC is probably not what you want - this is not a "module init" function. * The first arg is always "self", with "args" being a second arg. * You Py_INCREF(Py_None), but don't return it. I'm surprised that compiles. Let's say "args" was NULL (as it probably will be - recall it is supposed to be "self", which generally *will* be NULL. It should be obvious how that would crash your code. Also, note that even if you get the correct "args" pointer to that function, it will be a tuple. Hence all code you will find uses PyArg_ParseTuple to get the individual items out. Your callback will be the first item in the tuple. > ppyobjResult = PyObject_CallObject(my_callback, ppyobjArgList); This will fail for that reason - my_callback will *not* be a callable object. I don't think either of the mailing lists you have sent this to are appropriate - the problems are not releated to win32, not are they related to C++. You really just need to look over the documentation on writing extension modules. Mark. From skottmckay at gmail.com Thu Aug 11 03:03:12 2005 From: skottmckay at gmail.com (Scott McKay) Date: Wed, 10 Aug 2005 19:03:12 -0600 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite In-Reply-To: References: <51d01787050809193534085538@mail.gmail.com> Message-ID: <51d01787050810180311b1d0ad@mail.gmail.com> > You've left out a lot of detail, but if you want to pass something > from C++ to Python by reference, you need to wrap it in boost::ref( ) > Otherwise, Boost.Python will take the safe route and pass it by value. Sorry - was trying to keep it to the essential details. I tried adding the boost:ref() call and that corrects the copy and provides a reference to the vector in the python code, however it fails when exiting from the python class' (TestExtendedFactory) generate method with 'TypeError: No registered converter was able to extract a C++ reference to type Factory from this Python object of type TestExtendedFactory' Do I need to register a custom converter, or is there some other call I'm missing to connect the python object with its base class' converters? Thanks for you help so far. S Here's a fuller picture: --- boost python code, largely created by Pyste --- Abstract base class for the Factory struct Factory_Wrapper: Factory, wrapper< Factory > { Factory_Wrapper(const Factory& p0): Factory(p0) {} Factory_Wrapper(): Factory() {} Factory& generate(std::vector>& p0) { boost::ref( p0 ); if (override f = this->get_override("generate")) return call< Factory& >( f.ptr(), p0); return Factory::generate(p0); } Factory& default_generate(std::vector>& p0) { return Factory::generate(p0); } }; void Export_SourceFactory() { class_< Factory_Wrapper, smart_ptr< Factory_Wrapper > >("Factory", init< >()) .def("generate", &Factory::generate, &Factory_Wrapper::default_generate, return_self<>()) .def(init< const Factory& >()) ; implicitly_convertible< smart_ptr< Factory_Wrapper >, smart_ptr< Factory > >(); } --- Basic version of the factory - implemented in C++ struct BasicFactory_Wrapper: BasicFactory, wrapper< BasicFactory > { BasicFactory_Wrapper(const BasicFactory& p0): BasicFactory(p0) {} BasicFactory_Wrapper(DocId p0, const Profile& p1): BasicFactory(p0, p1) {} Factory& generate(std::vector>& p0) { boost::ref( p0 ); if (override f = this->get_override("generate")) return call< Factory& >( f.ptr(), p0); return BasicFactory::generate(p0); } Factory& default_generate(std::vector>& p0) { return BasicFactory::generate(p0); } }; --- Class to export the basic factory void Export_BasicFactory() { class_< BasicFactory_Wrapper, smart_ptr< BasicFactory_Wrapper > >("BasicFactory", init< >()) .def("generate", (Factory& (BasicFactory::*)(std::vector>&) )&BasicFactory::generate, (Factory& (BasicFactory_Wrapper::*)(std::vector>&))&BasicFactory_Wrapper::default_generate, return_self<>()) .def(init< const BasicFactory& >()) ; implicitly_convertible< smart_ptr< BasicFactory_Wrapper >, smart_ptr< BasicFactory > >(); implicitly_convertible< smart_ptr< BasicFactory >, smart_ptr< Factory > >(); } In the C++ code the section that calls Factory->generate holds the Factory in a smart_ptr, FWIW. The python code goes like... class TestExtendedFactory( s.BasicFactory ): "Example showing how to provide your own snippet factor for initial snippet selection" def __init__( self ): # call init of parent to setup smart pointers correctly super( TestExtendedFactory, self ).__init__() def generate( self, vectorOfSmartPtrs ): # call BasicFactory's generate super( TestExtendedFactory, self ).generate( vectorOfSmartPtrs ) From pythondeveloper at gmail.com Thu Aug 11 19:49:08 2005 From: pythondeveloper at gmail.com (Scott Kaplan) Date: Thu, 11 Aug 2005 13:49:08 -0400 Subject: [C++-sig] Is there a good Python C/C++ IDE? Message-ID: <86afeadf05081110495776a14b@mail.gmail.com> Being new to Python, I was wondering if anyone knows of a good IDE that would let me develop Python and add extensions in C/C++, with the capability of debugging those extensions. This will be on a Mac. It looks like the standard download comes with PyObjC, however I want to extend Python to handle my C/C++ extensions not the other way around + I don't want to have to learn any ObjectiveC / ObjC syntax. Thanks, From Hubert.Holin at meteo.fr Fri Aug 12 15:00:37 2005 From: Hubert.Holin at meteo.fr (Hubert Holin) Date: Fri, 12 Aug 2005 15:00:37 +0200 Subject: [C++-sig] Is there a good Python C/C++ IDE? In-Reply-To: References: Message-ID: <183D565B-0F6F-4FC1-9CA0-E0B975102723@meteo.fr> [Xposted and followups to pythonmac list which is perhaps more appropriate] Somewhere in the E.U., le 12/08/2005 Bonjour On 12 ao?t 2005, at 12:00, c++-sig-request at python.org wrote: > Date: Thu, 11 Aug 2005 13:49:08 -0400 > From: Scott Kaplan > Subject: [C++-sig] Is there a good Python C/C++ IDE? > To: Development of Python/C++ integration > Message-ID: <86afeadf05081110495776a14b at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Being new to Python, I was wondering if anyone knows of a good IDE > that would let me develop Python and add extensions in C/C++, with the > capability of debugging those extensions. > > This will be on a Mac. > > It looks like the standard download comes with PyObjC, however I want > to extend Python to handle my C/C++ extensions not the other way > around + I don't want to have to learn any ObjectiveC / ObjC syntax. > > Thanks, Well, if you do not want to create GUIs, but do want to use one, it is possible to use XCode (2.1, though the last few previous versions would presumably also work). More precisely, you can launch the command-line Python from within XCode with a chosen script as argument (and any other arguments you may care about), and of course you can do the C++ programming within that environment. I have not actually tried to have a custom Python extension used in such a setting, but it is in my current work plan. You can even use the free (and excellent) TextWrangler as the code editor (for C++ and Python). The debugging of the extension can then be done using XCode's front-end to GDB. For debugging of Python scripts proper, however, the (free) PythonIDE is preferable, though (which leads to: development of scripts within PythonIDE, extension coding and integration in XCode). You are, as well, not restricted to using the Apple-supplied version of Python. As an example, I installed Bob Ippolito's "Official Unofficial" Python 2.4.1. I then created an XCode project (***empty project***) "Python via XCode", added a target "Invoked Snake" (of type aggregate), and to it added a custom executable "Python 2.4.1 (Official Unofficial)", setting its properties as "Executable path: / Library/Frameworks/Python.framework/Versions/2.4/bin/python" and with an argument ""/Users/hubertholin/Documents/Scratch/Python via Xcode/ test.py"" (adding quotes around path arguments is safer... note the whitespaces). Clicking on the "Build and Go" icon then invoked python with my test script as argument. The creation of extensions should be straightforward from the Boost.Python documentation (so far, I have only tried embedding, not extension, which is on my to-do list). I am still trying to refine the process to something I like, though. As far as Objective-C and Objective-C++ are concerned, I only see them as something of an inconvenience, much as in the same way that Apple's system documentation had long been geared towards Pascal rather than C. PyObjC goes a long way to ease our suffering, though there are some rough spots still (and the Python Carbon bindings need a full overhaul). It should be said that Interface Builder is superb, though, and in the absence of a NIB to whatever- portable-package Python will understand (like there appears to be for PERL), if one wants GUIs, then building them in IB, using PyObjC as the glue (using documentation written for ObjC) and extending with C+ + is a possible road. At least that's the road I am taking, and if anybody's interested I'll report back if it actually leads somewhere :-) . Bon courage Hubert Holin From jbrandmeyer at earthlink.net Fri Aug 12 17:45:04 2005 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 12 Aug 2005 11:45:04 -0400 Subject: [C++-sig] Is there a good Python C/C++ IDE? In-Reply-To: <86afeadf05081110495776a14b@mail.gmail.com> References: <86afeadf05081110495776a14b@mail.gmail.com> Message-ID: <1123861504.9027.8.camel@localhost.localdomain> On Thu, 2005-08-11 at 13:49 -0400, Scott Kaplan wrote: > Being new to Python, I was wondering if anyone knows of a good IDE > that would let me develop Python and add extensions in C/C++, with the > capability of debugging those extensions. > > This will be on a Mac. I use Eclipse with the PyDev and CDT extensions for C, C++, and Python code editing and browsing, and use Scons for the build driver. I haven't managed to get the cdt's gdb plugin to work with a Python extension module, but otherwise it has worked well for me. The best part is that the combination has the advantage of working on Linux, OSX, and Windows, (and others) so you get to use basically the same toolset on all three platforms. HTH, -Jonathan From ahrivera at yahoo.com Fri Aug 12 20:23:39 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Fri, 12 Aug 2005 11:23:39 -0700 (PDT) Subject: [C++-sig] how do I instantiate templates in pyste with types defined in different files? Message-ID: <20050812182339.30598.qmail@web30711.mail.mud.yahoo.com> Hi, I'm trying to do something like the following. Let say I have a file test.h that contains the following code: template class Test { A a; B b; }; Now I want to export an instanciate this template class using the types Astruct1, Astruct2 defined in atruct1.h and astruct2.h respectively. In pyste, I write this: Test = Template("Test","test.h") Test(["Astruct1","Astruct2","Test1") When I try to compile this I get an error because the temporary file that is generated only includes test.h and it doens't now where the other types come from. What is the best way to handle this? Is there a way to specify additional include files when I try to instantiate this code? Or should I write code that does the appropriate instanciation and then export that? Thanks, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From skottmckay at gmail.com Fri Aug 12 21:01:22 2005 From: skottmckay at gmail.com (Scott McKay) Date: Fri, 12 Aug 2005 13:01:22 -0600 Subject: [C++-sig] how do I instantiate templates in pyste with types defined in different files? In-Reply-To: <20050812182339.30598.qmail@web30711.mail.mud.yahoo.com> References: <20050812182339.30598.qmail@web30711.mail.mud.yahoo.com> Message-ID: <51d017870508121201360e85c5@mail.gmail.com> Include( "filename.h" ) On 8/12/05, Alexis H. Rivera-Rios wrote: > Hi, > > I'm trying to do something like the following. Let > say I have a file test.h that contains the following > code: > > template > class Test > { > A a; > B b; > }; > > Now I want to export an instanciate this template > class using the types Astruct1, Astruct2 defined in > atruct1.h and astruct2.h respectively. > > In pyste, I write this: > > Test = Template("Test","test.h") > Test(["Astruct1","Astruct2","Test1") > > When I try to compile this I get an error because the > temporary file that is generated only includes test.h > and it doens't now where the other types come from. > What is the best way to handle this? > > Is there a way to specify additional include files > when I try to instantiate this code? Or should I > write code that does the appropriate instanciation and > then export that? > > Thanks, > Alexis > > > > > > Programming Tutorial: > In Python: To do this, do this > In Perl: To do this, do this or this or this or this... > In C: To do this, do this, but be careful > In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From ericjardim at gmail.com Fri Aug 12 22:06:19 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 12 Aug 2005 17:06:19 -0300 Subject: [C++-sig] Post-constructor action Message-ID: <432ec6c505081213064698f51f@mail.gmail.com> Hi, Anybody knows how do I get the Python object of a newly created object of a Boost.Python extension class object, just after the call of the constructor, before the pointer return to Python? I was thinking how to do it, but I am a bit confused. I suppose those I could use customized call policies, but I am not sure neither know how to do it. Another thing that I saw interesting is this "make_constructor" function. I could use factory functions, but I'll loose my Python constructor. Does anybody have any idea of how to deal with it? Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.j.murphy at sageserpent.com Sat Aug 13 15:06:00 2005 From: g.j.murphy at sageserpent.com (Gerard Murphy) Date: Sat, 13 Aug 2005 14:06:00 +0100 Subject: [C++-sig] Mapping an entire data structure over to a single Python instance. (Newbie question) Message-ID: <000001c5a007$c9c0d400$0301a8c0@desktop1> Hello, I'm evaluating the potential use of the Boost.Python facilities. I've looked though the tutorial and *some* of the detailed API documentation available from www.boost.org, and so far it all looks very promising. However... I have a rather strange use planned for the C++ to Python interface that isn't covered by the tutorial. The detailed API documentation doesn't seem to answer my question either; so I'd like to put it to the mailing list, as I'm sure that this idea has already occurred to somebody in the past. *** Background *** What I'd like to do is map an entire data structure over to a single Python instance, so that individual properties of the Python object would correspond to parts of the data structure. To add spice to this, the data structure is in a sense weakly typed: different parts of it are composed out of very different C++ types. The data structure is dynamically built (otherwise there wouldn't be in issue as I could map a C-style structure or getter/setter class over to a Python class using the techniques described in the tutorial). I'll make this a little bit more concrete:- 1. I have what is effectively a weakly typed wrapper around a set of different C++ types using external polymorphism:- class AbstractValue { public: ~virtual AbstractValue(); }; template class ConcreteValue: public AbstractValue { public: // Use compiler-generated destructor. ConcreteValue(const StrongType &valueRepresentation): _valueRepresentation(valueRepresentation) StrongType _valueRepresentation; }; Instances of these make their way into a map:- typedef std::map > DataStructure; 2. Various things in the system populate these maps in different ways, so that from one map instance to another, not only do the associated values change, but so do the number of associations, the keys and the actual types of the associated values. However, lots of these maps share the same common structure in terms of numbers of associations, keys and associated types. These could be thought of as instances of several classes, where each class captures the commonality of structure. These classes effectively come into being as the system runs: they cannot be defined at compile time as conventional C++ classes. No, I can't just write the entire system in Smalltalk (or Python for that matter) ... :-) 3. I'd like to expose these conceptual classes to Python, mapping over these instances of 'DataStructure' mentioned above to Python objects - but with the Python class changing depending on what instance of 'DataStructure' is being mapped. The classes of the Python objects would be dynamically created by construction of a 'class_' object:- // Somewhere this line will be repeatedly executed... boost::python::class_ classObject(name); I'm assuming that although the class_ object will be destroyed at each repetition, the corresponding Python class lives on afterwards. It isn't a problem if this is not the case, as I could always manage these objects in a long-lived container or on the heap or whatever. What I intend to do is to dynamically add properties to 'classObject' that use the name of the property to fetch the appropriate associated value from the map. This would be done once per repetition, so that each repetition would create a brand new Python class. To be a bit more specific, I want to call 'classObject.add_property()' with an application of boost::bind to a template function instantiation that takes a name, looks up the associated value in the map, dynamically casts to the template type parameter and returns the value. I can ask an exemplar map to walk itself so that on behalf of a set of maps sharing the same common structure, it will populate a single class object with the appropriate properties. *** Now for the questions *** OK, that's what I want to do ... but can I do the following first:- i) Can I construct more than one instance of 'class_' using lots of different names as arguments at each construction call? I get the impression from the documentation that each template instantiation of 'class_ ' for a given X might well be a singleton class in terms of usage - only one constructed instance per class template instantiation, if you know what I mean! ii) If I *can* have lots of instances of 'class_', how does the framework know how to map instances of 'DataStructure' to the appropriate Python class - this seems to be implicitly done rather than explictly done. What I'm driving at here is taking an *existing* instance of DataStructure and wrapping it up as a 'boost::python::object' whose Python type is one of these dynamically constructed classes. This is in contrast to using the 'class_' object to create the instance of 'boost::python::object' - I would definitely like to avoid doing this if possible, although I appreciate that it is usually the obvious way to go. NOTE: I'm assuming that the properties can be defined using *any* function object that would take an instance of 'DataStructure' and return an appropriately typed value - I am planning on using 'boost::bind' and an appropriate trampoline template function to do this. In the meantime, I'll have a longer trawl through the API documentation and perhaps the implementation source, but I'd appreciate any help from old hands to shorten the process. Many thanks in advance, Gerard From g.j.murphy at sageserpent.com Sat Aug 13 15:06:33 2005 From: g.j.murphy at sageserpent.com (Gerard Murphy) Date: Sat, 13 Aug 2005 14:06:33 +0100 Subject: [C++-sig] Mapping an entire data structure over to a single Python instance. (Newbie question) Message-ID: <000101c5a007$d773e880$0301a8c0@desktop1> Hello, I'm evaluating the potential use of the Boost.Python facilities. I've looked though the tutorial and *some* of the detailed API documentation available from www.boost.org, and so far it all looks very promising. However... I have a rather strange use planned for the C++ to Python interface that isn't covered by the tutorial. The detailed API documentation doesn't seem to answer my question either; so I'd like to put it to the mailing list, as I'm sure that this idea has already occurred to somebody in the past. *** Background *** What I'd like to do is map an entire data structure over to a single Python instance, so that individual properties of the Python object would correspond to parts of the data structure. To add spice to this, the data structure is in a sense weakly typed: different parts of it are composed out of very different C++ types. The data structure is dynamically built (otherwise there wouldn't be in issue as I could map a C-style structure or getter/setter class over to a Python class using the techniques described in the tutorial). I'll make this a little bit more concrete:- 1. I have what is effectively a weakly typed wrapper around a set of different C++ types using external polymorphism:- class AbstractValue { public: ~virtual AbstractValue(); }; template class ConcreteValue: public AbstractValue { public: // Use compiler-generated destructor. ConcreteValue(const StrongType &valueRepresentation): _valueRepresentation(valueRepresentation) StrongType _valueRepresentation; }; Instances of these make their way into a map:- typedef std::map > DataStructure; 2. Various things in the system populate these maps in different ways, so that from one map instance to another, not only do the associated values change, but so do the number of associations, the keys and the actual types of the associated values. However, lots of these maps share the same common structure in terms of numbers of associations, keys and associated types. These could be thought of as instances of several classes, where each class captures the commonality of structure. These classes effectively come into being as the system runs: they cannot be defined at compile time as conventional C++ classes. No, I can't just write the entire system in Smalltalk (or Python for that matter) ... :-) 3. I'd like to expose these conceptual classes to Python, mapping over these instances of 'DataStructure' mentioned above to Python objects - but with the Python class changing depending on what instance of 'DataStructure' is being mapped. The classes of the Python objects would be dynamically created by construction of a 'class_' object:- // Somewhere this line will be repeatedly executed... boost::python::class_ classObject(name); I'm assuming that although the class_ object will be destroyed at each repetition, the corresponding Python class lives on afterwards. It isn't a problem if this is not the case, as I could always manage these objects in a long-lived container or on the heap or whatever. What I intend to do is to dynamically add properties to 'classObject' that use the name of the property to fetch the appropriate associated value from the map. This would be done once per repetition, so that each repetition would create a brand new Python class. To be a bit more specific, I want to call 'classObject.add_property()' with an application of boost::bind to a template function instantiation that takes a name, looks up the associated value in the map, dynamically casts to the template type parameter and returns the value. I can ask an exemplar map to walk itself so that on behalf of a set of maps sharing the same common structure, it will populate a single class object with the appropriate properties. *** Now for the questions *** OK, that's what I want to do ... but can I do the following first:- i) Can I construct more than one instance of 'class_' using lots of different names as arguments at each construction call? I get the impression from the documentation that each template instantiation of 'class_ ' for a given X might well be a singleton class in terms of usage - only one constructed instance per class template instantiation, if you know what I mean! ii) If I *can* have lots of instances of 'class_', how does the framework know how to map instances of 'DataStructure' to the appropriate Python class - this seems to be implicitly done rather than explictly done. What I'm driving at here is taking an *existing* instance of DataStructure and wrapping it up as a 'boost::python::object' whose Python type is one of these dynamically constructed classes. This is in contrast to using the 'class_' object to create the instance of 'boost::python::object' - I would definitely like to avoid doing this if possible, although I appreciate that it is usually the obvious way to go. NOTE: I'm assuming that the properties can be defined using *any* function object that would take an instance of 'DataStructure' and return an appropriately typed value - I am planning on using 'boost::bind' and an appropriate trampoline template function to do this. In the meantime, I'll have a longer trawl through the API documentation and perhaps the implementation source, but I'd appreciate any help from old hands to shorten the process. Many thanks in advance, Gerard From roman.yakovenko at gmail.com Sun Aug 14 08:21:18 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 14 Aug 2005 09:21:18 +0300 Subject: [C++-sig] [Announce] py++ has GUI now In-Reply-To: <7465b617050810001674a091a6@mail.gmail.com> References: <7465b61705071203464a827d2a@mail.gmail.com> <7465b617050810001674a091a6@mail.gmail.com> Message-ID: <7465b6170508132321789d2a8d@mail.gmail.com> Hi. py++ has now small and simple GUI. What is py++? py++ is a framework of components for creating a C++ code generator for boost.python. Code generation with the py++ framework is a very flexible and highly configurable process. You can find an explanation about py++ at: http://pygccxml.sourceforge.net/pyplusplus/py++.html py++ GUI is packed to be standalone application. Right now, only MS windows version exists. You can download program from here http://sourceforge.net/project/showfiles.php?group_id=118209 Roman From dave at boost-consulting.com Sun Aug 14 21:36:46 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 14 Aug 2005 15:36:46 -0400 Subject: [C++-sig] Mapping an entire data structure over to a single Python instance. (Newbie question) References: <000001c5a007$c9c0d400$0301a8c0@desktop1> Message-ID: "Gerard Murphy" writes: > 3. I'd like to expose these conceptual classes to Python, mapping over > these instances of 'DataStructure' mentioned above to Python objects - > but with the Python class changing depending on what instance of > 'DataStructure' is being mapped. Is that an important feature of the system? > The classes of the Python objects would be dynamically created by > construction of a 'class_' object:- > > > > > // Somewhere this line will be repeatedly executed... > > boost::python::class_ classObject(name); No, that won't work. What you can do is use Python's metaclass API. http://gnosis.cx/publish/programming/metaclass_1.html Export your C++ DataStructure class once. object data_structure = class_( ... ) ... ; Then get its metaclass: object meta = object( handle<>( borrowed(data_structure.ptr()->ob_type) ) ); Now you can manufacture distinct subclasses on-the-fly: object new_subclass = meta( "name-of-subclass", python::make_tuple(data_structure), dict()); > I'm assuming that although the class_ object will be destroyed at each > repetition, the corresponding Python class lives on afterwards. It isn't a > problem if this is not the case, as I could always manage these objects in a > long-lived container or on the heap or whatever. > > > What I intend to do is to dynamically add properties to 'classObject' > that use the name of the property to fetch the appropriate associated > value from the map. This would be done once per repetition, so that each > repetition would create a brand new Python class. I suggest you don't do that either. It would be better to implement a __getattr__ method in your exported DataStructure. object getattr(DataStructure& ds, std::string name) { return object( ...lookup name in ds... ); } object data_structure = class_( ... ) .def("__getattr__", getattr) ; For this you'll need to export class_ and class_ > for each ConcreteValue you are using. > To be a bit more specific, I want to call 'classObject.add_property()' with > an application of boost::bind to a template function instantiation that > takes a name, looks up the associated value in the map, dynamically > casts to the template type parameter and returns the value. > > I can ask an exemplar map to walk itself so that on behalf of a set of maps > sharing the same common structure, it will populate a single class > object with the appropriate properties. Doing it with add_property is going to be a bear. Why would you want to do that? > *** Now for the questions *** > > OK, that's what I want to do ... but can I do the following first:- > > i) Can I construct more than one instance of 'class_' > using lots of different names as arguments at each construction > call? Nope HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Aug 15 04:52:10 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 14 Aug 2005 22:52:10 -0400 Subject: [C++-sig] Post-constructor action References: <432ec6c505081213064698f51f@mail.gmail.com> Message-ID: Eric Jardim writes: > Hi, > > Anybody knows how do I get the Python object of a newly created object of a > Boost.Python extension class object, just after the call of the constructor, > before the pointer return to Python? Your best bet? Use old-style polymorphism support: struct WrappedFoo : Foo { WrappedFoo(PyObject* self, ) { } }; class_("Foo") ... ; > I was thinking how to do it, but I am a bit confused. I suppose > those I could use customized call policies, but I am not sure > neither know how to do it. Me neither ;-) > Another thing that I saw interesting is this "make_constructor" function. You could, but that would be the complicated approach. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From g.j.murphy at sageserpent.com Mon Aug 15 10:34:07 2005 From: g.j.murphy at sageserpent.com (g.j.murphy at sageserpent.com) Date: Mon, 15 Aug 2005 09:34:07 +0100 Subject: [C++-sig] Mapping an entire data structure over to a single Python instance. (Newbie question) Message-ID: <200508151008.j7FA85m27624@myserverworld.com> "Dave Abrahams" writes: > "Gerard Murphy" writes: > > > 3. I'd like to expose these conceptual classes to Python, mapping over > > these instances of 'DataStructure' mentioned above to Python objects - > > but with the Python class changing depending on what instance of > > 'DataStructure' is being mapped. > > Is that an important feature of the system? It's a 'very nice to have' - but I could fallback to just treating all maps as being, well, dictionaries in Python. :-) Something I didn't mention in the original post is that I would like to add certain methods onto certain of these classes, and that the client code on the Python side would know in advance what set of methods the instances would be expected to possess: these objects would be passed over to Python in sets where each member of the set would respond to the same set of method calls. In effect I'm saying that if objects 'A' and 'B' both possess the attributes 'foo' and 'bar', then they would acquire a method 'doSomethingImportantInvolvingFooAndBar'. Object 'C' on the other hand that possesses property 'baz' acquires another method, say 'shutdownReactorAfterInternalDialogueWithBaz'. ;-) 'A' and 'B' would be passed together to one Python function, 'C' would be passed to another. All three of these objects might have other attributes that could be optionally accessible on the Python side, but are not vital for the correct operation of the system. > > > The classes of the Python objects would be dynamically created by > > construction of a 'class_' object:- > > > > > > > > > > // Somewhere this line will be repeatedly executed... > > > > boost::python::class_ classObject(name); > > No, that won't work. > > What you can do is use Python's metaclass API. > http://gnosis.cx/publish/programming/metaclass_1.html > > Export your C++ DataStructure class once. > > > object data_structure > = class_( ... ) > ... > ; > > > Then get its metaclass: > > object meta = object( > handle<>( > borrowed(data_structure.ptr()->ob_type) > ) > ); > > Now you can manufacture distinct subclasses on-the-fly: > > object new_subclass = meta( > "name-of-subclass", python::make_tuple(data_structure), > dict()); > Excellent! > > > I'm assuming that although the class_ object will be destroyed at each > > repetition, the corresponding Python class lives on afterwards. It isn't a > > problem if this is not the case, as I could always manage these objects in a > > long-lived container or on the heap or whatever. > > > > > > What I intend to do is to dynamically add properties to 'classObject' > > that use the name of the property to fetch the appropriate associated > > value from the map. This would be done once per repetition, so that each > > repetition would create a brand new Python class. > > I suggest you don't do that either. It would be better to implement a > __getattr__ method in your exported DataStructure. > > object getattr(DataStructure& ds, std::string name) > { > return object( ...lookup name in ds... ); > } > > object data_structure > = class_( ... ) > .def("__getattr__", getattr) > ; > > For this you'll need to export class_ and > class_ > for each ConcreteValue you are using. Ah - yes, that's much better. > > > To be a bit more specific, I want to call 'classObject.add_property()' with > > an application of boost::bind to a template function instantiation that > > takes a name, looks up the associated value in the map, dynamically > > casts to the template type parameter and returns the value. > > > > I can ask an exemplar map to walk itself so that on behalf of a set of maps > > sharing the same common structure, it will populate a single class > > object with the appropriate properties. > > Doing it with add_property is going to be a bear. Why would you want > to do that? As a Python novice, I had automatically assumed that properties were the only form of abstraction available on instance variable access (I had C# in mind). Now that you've introduced me to '__getattr__' and the like, I've seen the light. :-) > > > *** Now for the questions *** > > > > OK, that's what I want to do ... but can I do the following first:- > > > > i) Can I construct more than one instance of 'class_' > > using lots of different names as arguments at each construction > > call? > > Nope > No problem, that's now obsolete in the light of using the metaclass object to produce more classes. Many thanks, Gerard From dave at boost-consulting.com Mon Aug 15 16:36:46 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 15 Aug 2005 10:36:46 -0400 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite References: <51d01787050809193534085538@mail.gmail.com> <51d01787050810180311b1d0ad@mail.gmail.com> Message-ID: Scott McKay writes: >> You've left out a lot of detail, but if you want to pass something >> from C++ to Python by reference, you need to wrap it in boost::ref( ) >> Otherwise, Boost.Python will take the safe route and pass it by value. > > Sorry - was trying to keep it to the essential details. > > I tried adding the boost:ref() call and that corrects the copy and > provides a reference to the vector in the python code, however it > fails when exiting from the python class' (TestExtendedFactory) > generate method Actually it's exiting the call( ... ) where we have the problem. > with > > 'TypeError: No registered converter was able to extract a C++ > reference to type Factory from this Python object of type > TestExtendedFactory' >From the code you posted it seems pretty straightforward to me. The Python generate() call is creating a Python TestExtendedFactory object, which is derived from the Python wrapper for BasicFactory, so it contains a C++ BasicFactory. Does it contain a C++ Factory object? not unless BasicFactory is derived from Factory and, from Boost.Python's POV, not unless its class_ names Factory as one of its bases<...>. You didn't show the declaration of BasicFactory, so it's hard to say much about it. > Do I need to register a custom converter, or is there some other call > I'm missing to connect the python object with its base class' > converters? > > Thanks for you help so far. > > S > > Here's a fuller picture: > > --- boost python code, largely created by Pyste > > --- Abstract base class for the Factory > > struct Factory_Wrapper: Factory, wrapper< Factory > > { > Factory_Wrapper(const Factory& p0): > Factory(p0) {} > > Factory_Wrapper(): > Factory() {} > > Factory& generate(std::vector>& p0) { P.S. is this actually the code you compiled? All compilers I know of will choke on the appearance of ">>" above without an intervening space. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Mon Aug 15 16:43:30 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 15 Aug 2005 10:43:30 -0400 Subject: [C++-sig] Transfer of ownership References: <432ec6c5050810122649a976b1@mail.gmail.com> Message-ID: Eric Jardim writes: > Hi, all... > > This is a simple question. I was reading the docs where it says about the > "transfer of ownership" of a C++ object pointer. I am dealing exacly this > situation, where the "with_custodian_and_ward" policy is not enough to > prevent Python objects to delete C++ couterparts. The only hack is to hold > references, but it is not a complete solution. > > So, I read the FAQ entry where it explain how to deal with this issue: > http://www.boost.org/libs/python/doc/v2/faq.html#ownership > > But there, it speaks about using an "std::auto_ptr". On the other side, I am > using "boost::shared_ptr" to hold my objects. I really do not know the > difference between them, but I imagine they provide similar > funcionality. Yes, similar, but auto_ptr provides exclusive, as opposed to shared, ownership semantics. When an auto_ptr is copied or assigned, the source loses ownership and the destination acquires it. > So I will split my question in 3 parts: > - Is it possible to take the ownership with "boost::shared_ptr", Not if you mean to substitute it in the example in the FAQ, no. > or do I have to change my held types to "std::auto_ptr"? That's a completely separate question. No, you don't need to change your held types. > - Is there any difference in practice, using boost's or std's smart > pointers? Yes, there are lots of differences. However you haven't been very specific about what you're interested in; you'd have to read the documentation for each of them to grasp all of the differences. > I just use them for holding Boost.Python extensions. > - As those functions with smart pointers do not exists, I suppose > that I will have to write wrappers like: > > void b_insert(B& b, std::auto_ptr a) > { > b.insert(a.get()); > a.release(); > } > > Is there any special reason for this to be a non-const reference to > "b"? Yes, all free functions that are going to be wrapped as class methods should take a non-const reference as their first argument. > Could it be a const reference That would allow an implicit conversion from some other type to B to take place when calling the method, since const references can bind to rvalues > or a const/non-const pointer to "b"? That would allow None to be passed as the first argument, resulting in a NULL pointer. -- Dave Abrahams Boost Consulting www.boost-consulting.com From pythondeveloper at gmail.com Mon Aug 15 17:15:21 2005 From: pythondeveloper at gmail.com (Scott Kaplan) Date: Mon, 15 Aug 2005 11:15:21 -0400 Subject: [C++-sig] Is there a good Python C/C++ IDE? In-Reply-To: <1123861504.9027.8.camel@localhost.localdomain> References: <86afeadf05081110495776a14b@mail.gmail.com> <1123861504.9027.8.camel@localhost.localdomain> Message-ID: <86afeadf050815081570c7c876@mail.gmail.com> Jonathan, I think that this is exactly what I was looking for. Thanks. On 8/12/05, Jonathan Brandmeyer wrote: > On Thu, 2005-08-11 at 13:49 -0400, Scott Kaplan wrote: > > Being new to Python, I was wondering if anyone knows of a good IDE > > that would let me develop Python and add extensions in C/C++, with the > > capability of debugging those extensions. > > > > This will be on a Mac. > > I use Eclipse with the PyDev and CDT extensions for C, C++, and Python > code editing and browsing, and use Scons for the build driver. I > haven't managed to get the cdt's gdb plugin to work with a Python > extension module, but otherwise it has worked well for me. The best > part is that the combination has the advantage of working on Linux, OSX, > and Windows, (and others) so you get to use basically the same toolset > on all three platforms. > > HTH, > -Jonathan > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From ahrivera at yahoo.com Mon Aug 15 23:35:52 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Mon, 15 Aug 2005 14:35:52 -0700 (PDT) Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class Message-ID: <20050815213552.19129.qmail@web30710.mail.mud.yahoo.com> Hi, I have the following classes: class Entity { public: /// type of trajectory pointer typedef boost::shared_ptr TrajectoryPtr; /// constructor Entity() : trajectory(), state() {} /// destructor virtual ~Entity() {} /// sets the position void SetPosition(const gmtl::Point3d &pos) { state.position = pos; } /// returns the position gmtl::Point3d GetPosition() const { return state.position; } //.... other methods here... /// delegates to the Trajectory object /// the updating the state virtual void UpdateState(double ellapsedTime=1) { if (trajectory.get()) { Trajectory *t = trajectory.get(); t->UpdateState(state,ellapsedTime); } } private: EntityState state; ///< entity's physical state TrajectoryPtr trajectory; /// copy constructor disabled Entity(const Entity& ); /// assignment disabled Entity& operator=(const Entity &); }; class Trajectory { /// disabled copy constructor Trajectory(const Trajectory &); /// disabled assignment Trajectory& operator=(const Trajectory&); public: /// constructor Trajectory() {} /// destructor virtual ~Trajectory(){} /// updates the state of the entity virtual void UpdateState(EntityState& state, double ellapsedTime) const = 0; }; I exposed the class using pyste and in python I'm derived a class from it. class HackedT(Trajectory): def UpdateState(self, entitystate, ellapsedTime): entitystate.position = gmtl.Point3d(-1,-1,-1) The problem is that when I do this in python: target = Entity() target.SetPosition(gmtl.Point3d(10,10,0)) target.SetTrajectory(hackedT) target.UpdateState(1) result = target.GetPosition() print result[0] print result[1] print result[2] I expect the result to be (-1,-1,-1) but instead its coming out to be the original value. However, if I use trajectories defined in C++ the new values come out correct. Is this a bug in Boost Python or do I have to specify some policy or something to make this work? Any help will be greatly appreciated, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Tue Aug 16 00:00:21 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 15 Aug 2005 18:00:21 -0400 Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class References: <20050815213552.19129.qmail@web30710.mail.mud.yahoo.com> Message-ID: "Alexis H. Rivera-Rios" writes: > Is this a bug in Boost Python or do I have to specify > some policy or something to make this work? There's way too much in your example for me to have time to analyze it. Why don't you reduce it to the absolute minumum required to produce the behavior that confuses you? -- Dave Abrahams Boost Consulting www.boost-consulting.com From ahrivera at yahoo.com Tue Aug 16 00:56:06 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Mon, 15 Aug 2005 15:56:06 -0700 (PDT) Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class Message-ID: <20050815225606.80178.qmail@web30706.mail.mud.yahoo.com> Abraham, The idea is that I have a class Entity that contains a pointer to a strategy object that implements the Trajectory interface. The Trajectory interface modifies the Entity's state in UpdateState(). The entity class delegates the update of its state to the Trajectory strategy. The problem is that in python, when I implement the Trajectory interface and pass the object to the Entity class, the call to Trajectory.UpdateState doesn't seem to work correctly. It gets executed but the state is not updated. (I guess it has to do with the fact that I'm passing the object as a reference). However, if I call UpdateState directly from the python object that implements Trajectory interface it works fine. (ie. it changes the content of the object) If this is still too much let me know and I'll try to reproduce the error with simpler classes. But here is the code. class Entity { /// specify a trajectory strategy /// which is a shared pointer to a Trajectory object specified below SetTrajectory(const TrajectoryPtr &T) { trajectory = T; } /// delegates to the Trajectory strategy /// the updating the state virtual void UpdateState(double ellapsedTime=1) { t->UpdateState(state,ellapsedTime); } private: EntityState state; ///< object to be modified TrajectoryPtr trajectory; /// this is a shared pointer }; class Trajectory /// interface that i want to inherit in python { public: /// note it takes the state as a reference virtual void UpdateState(EntityState& state, double ellapsedTime) const = 0; }; I exposed the class using pyste and in python I'm derived a class from it. class HackedT(Trajectory): def UpdateState(self, entitystate, ellapsedTime): entitystate.position = gmtl.Point3d(-1,-1,-1) The problem is that when I do this in python: target = Entity() target.SetTrajectory(hackedT) target.UpdateState() # enventually calls the HackedT's UpdateState, which modifies the state print target.GetPosition() I expect the result to be (-1,-1,-1) but instead its coming out to be the original value (10,10,0). However, if I use Trajectory objects created from C++ then the state is modified. Also, if I call the function directly it modifies the state. s = EntityState() ## by default s.position = (0,0,0) hackedT.UpdateState(s,1) print s.position ## returns (-1,-1,-1) Is this a bug in Boost Python or do I have to specify some policy or something to make this work? Let me know if you need additional information. Again, any help will be greatly appreciated, (Hope it's better summarized) Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From ahrivera at yahoo.com Tue Aug 16 03:08:40 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Mon, 15 Aug 2005 18:08:40 -0700 (PDT) Subject: [C++-sig] how do I instantiate templates in pyste with types defined in different files? Message-ID: <20050816010840.51545.qmail@web30701.mail.mud.yahoo.com> That doesn't do it. My template declaration is in one file. The actual types are in another. There is no way for me to tell pyste where the actual types are when I try to instantiate the class. For example, Class("A","a.h") Class("B","b.h") Test = Template("Test","test.h") Test("A","testA") Test("B","testB") <-- these didn't work because when the pyste code generator tries to instantiate the class, it doesn't include the a.h or b.h because there is no mechanism to tell it how to do so. This didn't work either: Include("a.h") Test("A","testA") I tried declaring the class as a typedef: ---- somefile.h ---- #include "test.h" #include "a.h" typedef Test TestA Then in pyste Class("TestA","somefile.h") Pyste doesn't complain, but doesn't generate any functions or constructors or anything. It would generate something like this: class_, boost::noncopyable >("TestA", no_init) ; Any ideas? Or ways around this? Thanks, Alexis > template > class Test > { > A a; > B b; > }; > > Now I want to export an instanciate this template > class using the types Astruct1, Astruct2 defined in > atruct1.h and astruct2.h respectively. > > In pyste, I write this: > > Test = Template("Test","test.h") > Test(["Astruct1","Astruct2","Test1") Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Tue Aug 16 04:35:45 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 15 Aug 2005 22:35:45 -0400 Subject: [C++-sig] boost.python iterators References: Message-ID: Dirk, you're in the wrong mailing list/newsgroup. Try the Python C++ sig (where followups are directed). Dirk Steenpass writes: > Dear all, > > I am looking for a way to create a python savvy iterator by wrapping > a container that provides begin and end member functions taking > arguments. Taking arguments, hmm. > The reference manual entry on boost::python::range left me unsure whether > the appended code would compile (it does not). > > The sentence: > > "The first form creates a Python callable object which, when invoked, converts > its argument to a Target object x, and creates a Python iterator which > traverses [bind(start,_1)(x), bind(finish,_1)(x)), applying NextPolicies to the > iterator's next() function." > > suggested to me that a single argument, i.e., the target reference is passed to > the accessor functions. Correct. > This would imply that the accessor takes exactly one argument. (???) Correct. > However, the subsequent explanations about the deduction of Target left me with > the impression that accessor functions and accessor member function pointers > may take several arguments. I understand. I think the text is misleading. I should delete "arguments..." > Any help is appreciated, Your problem is that you're forgetting the implicit "this" argument. In Python that corresponds to the initial explicit "self." Probably your simplest solution would be something like: python::object Elements(A& a, A::SizeType n) { return python::range( boost::bind(&A::begin, _1, n) , boost::bind(&A::end, _1, n) )(boost::ref(a)); } Then wrap that. We create a new Python function object on the fly each time and invoke it. The bind expressions just bind n into the accessors so that they take only a single argument. HTH, > dirk > > //--- A [n] example ----------------------------------------------------------- > // Does not compile with gcc 3.3.6 and gcc 4.0.2 > > #include > > #include > > using namespace std; > using namespace boost::python; > > class A > { > public: > typedef std::vector VecInt; > typedef VecInt::iterator Iter; > typedef VecInt::size_type SizeType; > > public: > A(): vec_(100, 23) {} > > Iter Begin(SizeType ignored) { return vec_.begin(); } > Iter End(SizeType ignored) { return vec_.end(); } > > private: > VecInt vec_; > }; > > BOOST_PYTHON_MODULE(A) > { > class_("A") > .def("Elements", range(&A::Begin, &A::End)) > ; > } > > // Just allowing standalone compilation. > int main(void) > { > return 0; > } -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Aug 16 04:40:29 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 15 Aug 2005 22:40:29 -0400 Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class References: <20050815225606.80178.qmail@web30706.mail.mud.yahoo.com> Message-ID: "Alexis H. Rivera-Rios" writes: > If this is still too much let me know and I'll try to > reproduce the error with simpler classes. But here is > the code. Sorry, this seems like more to me. It's denser and has more exposition. Also the line breaks make it hard to read. Please post a minimal, complete, compilable example that demonstrates the problem, with no comments other than one that shows where you are expecting a different result than you're getting. Please post your code as an enclosure so it doesn't get line-wrapped into oblivion. I'll try to help. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Tue Aug 16 15:05:47 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 16 Aug 2005 09:05:47 -0400 Subject: [C++-sig] boost.python iterators References: Message-ID: Dirk Steenpass writes: > Yep, that is neat and works. Though the default_call_policies cannot be > used as the wrapped iterator returns by reference. That is not a foregone conclusion, but it may be true in your case. -- Dave Abrahams Boost Consulting www.boost-consulting.com From nico_ml at mgdesign.org Tue Aug 16 15:37:37 2005 From: nico_ml at mgdesign.org (Nicolas Lelong) Date: Tue, 16 Aug 2005 15:37:37 +0200 Subject: [C++-sig] exporting __stdcall methods References: <20050308143928.36875.qmail@web31510.mail.mud.yahoo.com><422DCDCD.8090803@paniq.org> <42334D12.2020608@paniq.org><005101c52759$ee9cc030$37ce4e51@MIKESPC01> <42337D6E.2010505@paniq.org><024f01c52a4b$5caa5df0$0dc66b51@fuji><110901c5678f$814a1f70$de00a8c0@nico> Message-ID: <015601c5a267$ab1af910$de00a8c0@nico> Hi Dave, sorry I linger in responding, I'm only getting back to business after some holidays :) > I think it would be great to support these other calling conventions. glad you see some interest in this too! > Your patch looks good, but I'm quite surprised that it's so small. Is > that really all that's required to implement full stdcall/fastcall > support? hm, as I did this some time ago already, I took some time to test it a little more. I extensively used the patch with stdcall "C" functions, but I investigated some more by tweaking the "polymorphism" test. I seems to work all right for regular functions and member functions. I noticed a "limitation" though : if a pure virtual member function is exported with a given default implementation, this default implement _must_ the same calling convention as the pure virtual function. I'm not sure that this is annoying, perhaps this can be corrected : the problem comes from the 'not_a_derived_class_member' call in 'class.hpp' (line 146 in boost 1.33 release) - see attached file 'func_sig_def_impl_fail.cpp'. I attach the tweaked 'polymorphism' files. I also added the support for __cdecl member functions, and changed the macros to enable the functionality to match more closely what is found in type traits lib, so I attach a patch for signature.hpp (not widely different from the previous one) and config.hpp. I'm open to any thoughts or directions you could give me to integrate properly this patch into BPL. Cheers, Nicolas. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_fastcall.py URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_stdcall.cpp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_stdcall.py URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_cdecl.cpp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_cdecl.py URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_fastcall.cpp URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: polymorphism_func_sig_def_impl_fail.cpp URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Jamfile Type: application/octet-stream Size: 2574 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.hpp.patch Type: application/octet-stream Size: 2729 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: config.hpp.patch Type: application/octet-stream Size: 846 bytes Desc: not available URL: From ahrivera at yahoo.com Tue Aug 16 18:58:01 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 16 Aug 2005 09:58:01 -0700 (PDT) Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class Message-ID: <20050816165801.9404.qmail@web30705.mail.mud.yahoo.com> David, Here is an example (excuse the formatting, because I don't know how to change it from yahoo mail) struct Data { int a; double b; }; class B { public: virtual void Update(Data& a, int ellapsedTime) = 0; ~B() {} }; class D : public B { virtual void Update(Data& a, int ellapsedTime) { a.a = 10; a.b = -9; } }; #include class C { public: void SetBptr(boost::shared_ptr newB) { Bptr = newB; } void Update(int ellapsedTime) { if (Bptr.get()) { B *ptr = Bptr.get(); ptr->Update(d,ellapsedTime); } } int GetData_a() const { return d.a; } double GetData_b() const { return d.b; } private: Data d; boost::shared_ptr Bptr; }; The pyste code: Class("Data","test.h") B = Class("B","test.h") use_shared_ptr(B) Class("C","test.h") D = Class("D","test.h") final(D.Update) An example of the error: >>> from PysteError import * >>> c = C() >>> d = D() >>> c.SetBptr(d) >>> c.Update(1) >>> print c.GetData_a() 10 >>> print c.GetData_b() -9.0 >>> class E(B): ... def Update(self,data,val): ... data.a = -8; ... data.b = -1; ... >>> e = E() >>> c.SetBptr(e) >>> c.Update(1) >>> print c.GetData_a() 10 >>> print c.GetData_b() -9.0 >>> cc = C() >>> cc.SetBptr(e) >>> cc.Update(1) >>> print cc.GetData_a() 6488163 >>> print cc.GetData_b() 6.95352557184e-308 Hope this is clearer now ;) Thanks for you help, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From ahrivera at yahoo.com Tue Aug 16 20:51:54 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 16 Aug 2005 11:51:54 -0700 (PDT) Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class Message-ID: <20050816185154.91985.qmail@web30703.mail.mud.yahoo.com> David, Im sending the email again, since I don't remember if I have send it or not. Please forgive the formatting since I don't know how to control that with yahoo mail. struct Data { int a; double b; }; class B { public: virtual void Update(Data& a, int ellapsedTime) = 0; ~B() {} }; class D : public B { virtual void Update(Data& a, int ellapsedTime) { a.a = 10; a.b = -9; } }; #include class C { public: void SetBptr(boost::shared_ptr newB) { Bptr = newB; } void Update(int ellapsedTime) { if (Bptr.get()) { B *ptr = Bptr.get(); ptr->Update(d,ellapsedTime); } } int GetData_a() const { return d.a; } double GetData_b() const { return d.b; } private: Data d; boost::shared_ptr Bptr; }; Here is the pyste script Class("Data","test.h") B = Class("B","test.h") use_shared_ptr(B) Class("C","test.h") D = Class("D","test.h") final(D.Update) Here is an example of the error: (test 1) works as expected >>> from PysteError import * >>> c = C() >>> d = D() >>> c.SetBptr(d) >>> c.Update(1) >>> print c.GetData_a() 10 >>> print c.GetData_b() -9.0 (test 2) fails when called from C >>> class E(B): ... def Update(self,data,val): ... data.a = 999 ... data.b = 100 ... >>> e = E() >>> cc = C() >>> cc.SetBptr(e) >>> cc.Update(1) >>> print cc.GetData_a() 6488163 >>> print cc.GetData_b() 6.95352557184e-308 (test 3) but it works when called directly >>> data = Data() >>> e.Update(data,1) >>> print data.a 999 >>> print data.b 100.0 >>> Hope this illustrates the problem better, Thanks, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From dave at boost-consulting.com Tue Aug 16 21:44:41 2005 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 16 Aug 2005 15:44:41 -0400 Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class References: <20050816185154.91985.qmail@web30703.mail.mud.yahoo.com> Message-ID: "Alexis H. Rivera-Rios" writes: > David, > > Im sending the email again, since I don't remember if > I have send it or not. Please forgive the formatting > since I don't know how to control that with yahoo > mail. THe formatting is okay, but... > Here is the pyste script > > Class("Data","test.h") > B = Class("B","test.h") > use_shared_ptr(B) > > Class("C","test.h") > > D = Class("D","test.h") > final(D.Update) Sorry, but I don't know Jack about pyste, so please show me the code it generates instead. > Here is an example of the error: > > (test 1) works as expected And please don't show me anything that works as expected. That's just a distraction from the problem. > (test 2) fails when called from C >>>> class E(B): > ... def Update(self,data,val): > ... data.a = 999 > ... data.b = 100 > ... >>>> e = E() >>>> cc = C() >>>> cc.SetBptr(e) >>>> cc.Update(1) >>>> print cc.GetData_a() > 6488163 >>>> print cc.GetData_b() > 6.95352557184e-308 Please show me the result you were expecting, like I asked you to. I'm guessing it was 999 and 100.0 ?? > Hope this illustrates the problem better, Sorta. This example could be smaller, couldn't it? Do you really need two data members to show it? I really mean it: if you pare it down to the absolute minimum you'll probably find the problem yourself. -- Dave Abrahams Boost Consulting www.boost-consulting.com From steenpaz at sdf-eu.org Tue Aug 16 22:26:49 2005 From: steenpaz at sdf-eu.org (Dirk Steenpass) Date: Tue, 16 Aug 2005 22:26:49 +0200 Subject: [C++-sig] boost.python iterators References: Message-ID: On Tue, 16 Aug 2005 09:05:47 -0400, David Abrahams wrote: > Dirk Steenpass writes: > >> Yep, that is neat and works. Though the default_call_policies cannot be >> used as the wrapped iterator returns by reference. > > That is not a foregone conclusion, but it may be true in your case. I try to be more precise: the default_call_policies will work for wrapped iterators that return non-pointer types, char const*, and PyObject* by value. Or putting it differently, functions that return references (aka automatically dereferenced pointer types) are not accepted by default_call_policies. Thus the following snippet is not supposed to compile (and does not do so): //------------------------------------------- // default_call_policies #include class Coo { public: Coo(int x): c_(x) {} int const& get_c() const { return c_; } private: int c_; }; using namespace boost::python; BOOST_PYTHON_MODULE(coo) { class_("Coo", init()) // Fails because of bad call policy. .def("get_c", &Coo::get_c, default_call_policies()) ; } int main(void) { return 0; } //------------------------------------------- I'm rather tenacious on the topic because the behavior of another call policy, namely return_internal_reference, keeps confusing me; most likely because I miss some important point about call policies in general. The following snippet illustrates that return_internal_reference can be used for a simple user defined type but not for the fundamental int. I am probably making a fool of myself, but I do not see why this is so. I am using boost-1.33.0. As usual, looking for enlightenment, dirk //------------------------------------------ // return_internal_reference #include struct C { C(int x): c_(x) {} int c_; }; class B { public: B(int x) : b_(x), c_(x) {} int const& get_b() const { return b_; } C const& get_c() const { return c_; } private: int b_; C c_; }; using namespace boost::python; BOOST_PYTHON_MODULE(b) { class_("B", init()) // Fundamental type, cannot be returned // by reference this way. .def("get_b", &B::get_b, return_internal_reference<>()) // User defined type: compiles fine. .def("get_c", &B::get_c, return_internal_reference<>()) ; } int main(void) { return 0; } From steenpaz at sdf-eu.org Tue Aug 16 14:42:07 2005 From: steenpaz at sdf-eu.org (Dirk Steenpass) Date: Tue, 16 Aug 2005 14:42:07 +0200 Subject: [C++-sig] boost.python iterators References: Message-ID: On Mon, 15 Aug 2005 22:35:45 -0400, David Abrahams wrote: > > Dirk, you're in the wrong mailing list/newsgroup. Try the Python C++ > sig (where followups are directed). Sorry. [snip] > Probably your simplest solution would be something like: > > python::object Elements(A& a, A::SizeType n) > { > return > python::range( > boost::bind(&A::begin, _1, n) > , boost::bind(&A::end, _1, n) > )(boost::ref(a)); > } > > Then wrap that. We create a new Python function object on the fly > each time and invoke it. The bind expressions just bind n into the > accessors so that they take only a single argument. > > HTH, > Yep, that is neat and works. Though the default_call_policies cannot be used as the wrapped iterator returns by reference. Thx, dirk [snip] -- Dirk Steenpass From ahrivera at yahoo.com Wed Aug 17 00:47:49 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 16 Aug 2005 15:47:49 -0700 (PDT) Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class Message-ID: <20050816224749.14967.qmail@web30715.mail.mud.yahoo.com> David, Here's a simpler version: struct Data { int a; }; class B { public: virtual void Update(Data& a) = 0; ~B() {} }; class D : public B { virtual void Update(Data& a) { a.a = 10; } }; class C { public: void SetBptr(B* newB) { Bptr = newB; } void Update() { // this doesn't seem to work correctly if Bptr is a python object Bptr->Update(d); } int GetData_a() const { return d.a; } private: Data d; B* Bptr; }; here is the generated code from pyste: // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include "test.h" // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace { struct B_Wrapper: B { B_Wrapper(PyObject* py_self_, const B& p0): B(p0), py_self(py_self_) {} B_Wrapper(PyObject* py_self_): B(), py_self(py_self_) {} void Update(Data& p0) { call_method< void >(py_self, "Update", p0); } PyObject* py_self; }; }// namespace // Module ====================================================================== BOOST_PYTHON_MODULE(PysteError) { class_< Data >("Data", init< >()) .def(init< const Data& >()) .def_readwrite("a", &Data::a) ; scope* B_scope = new scope( class_< B, boost::noncopyable, B_Wrapper >("B", init< >()) .def("Update", pure_virtual(&B::Update)) ); register_ptr_to_python< boost::shared_ptr< B > >(); delete B_scope; class_< C >("C", init< >()) .def(init< const C& >()) .def("SetBptr", &C::SetBptr, with_custodian_and_ward< 1, 2 >()) .def("Update", &C::Update) .def("GetData_a", &C::GetData_a) ; class_< D, bases< B > >("D", init< >()) .def(init< const D& >()) ; } Here is the test code: Expected 10 (good) >>> from PysteError import * >>> c = C() >>> d = D() >>> c.SetBptr(d) >>> c.Update() >>> print c.GetData_a() 10 Expected -1 (bad) >>> class E(B): ... def Update(self,data): ... data.a = -1 ... >>> e = E() >>> cc = C() >>> cc.SetBptr(e) >>> cc.Update() >>> print cc.GetData_a() 0 Expected -1 (good) >>> data = Data() >>> e.Update(data) >>> print data.a -1 Hope this exposes the problem better. I honestly don't have any idea why this doesn't work. Not even a clue where to start looking for a bug. Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Wed Aug 17 15:38:35 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 09:38:35 -0400 Subject: [C++-sig] problem chaning object state using a python class that inherits from c++ class References: <20050816224749.14967.qmail@web30715.mail.mud.yahoo.com> Message-ID: "Alexis H. Rivera-Rios" writes: > David, > > Here's a simpler version: Thanks. In this case the problem is very simple: > namespace { > > struct B_Wrapper: B > { > B_Wrapper(PyObject* py_self_, const B& p0): > B(p0), py_self(py_self_) {} > > B_Wrapper(PyObject* py_self_): > B(), py_self(py_self_) {} > > void Update(Data& p0) { > call_method< void >(py_self, "Update", p0); ^^ Here, p0 is passed by value. If you want it to be passed by reference you need to pass boost::ref(p0) instead. Pyste is doing a couple of insane things here, neither of which contributes to your problem: 1. It's using old-style polymorphism support instead of the facilities of boost/python/wrapper.hpp and... > } > > PyObject* py_self; > }; > > > }// namespace > > > // Module > ====================================================================== > BOOST_PYTHON_MODULE(PysteError) > { > class_< Data >("Data", init< >()) > .def(init< const Data& >()) > .def_readwrite("a", &Data::a) > ; > > scope* B_scope = new scope( ... 2. This! I was very surprised to see it. There's no need for a scope here to begin with, and scopes should almost never be allocated dynamically! { scope B_scope = class_< B, boost::noncopyable, B_Wrapper >("B", init< >()) .def("Update", pure_virtual(&B::Update)); register_ptr_to_python< boost::shared_ptr< B > >(); } would have been more appropriate *if* a scope were needed. But it isn't! HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com From ult at mundane.org Wed Aug 17 16:24:21 2005 From: ult at mundane.org (Ult Mundane) Date: Wed, 17 Aug 2005 10:24:21 -0400 Subject: [C++-sig] Boost.Python.function.__signatures__ Message-ID: <43034895.3080705@mundane.org> Ralf, I'm using your function signatures patch, thank you very much, it is excellent and a huge timesaver for documenting exported C++ interfaces. I wonder if you've made any updates since you posted it last month. Is your patch checked into CVS somewhere? I'm looking into making two changes: 1. At the moment, parameters which are classes exported to Python are reported with their C++ names, not their Python names (i.e., if you export the class with a different name, the docstring doesn't match the name you use in Python). Glancing over the Boost.Python code, this is over my head at the moment; is this something that seems reasonable/doable to you? 2. Parameters which are built-in C++ types are reported as single-letter names (e.g., i = int, v = void, b = boolean, x = long long, j = size_t, etc.). In your example below, it shows the real C++ type names. I wonder what's different about my configuration. Any comments or suggestions are welcome. Thanks, Ult Ralf W. Grosse-Kunstleve wrote: > --- Nick Rasmussen wrote: >> > - I guess currently the docstrings are static. They'd have to become >> dynamic. >> > This seems to be a bigger project. I think we'd need a volunteer. >> >> I'm not sure what you mean by dynamic, > > It turns out my guess was wrong. Sorry. > > I looked some more and here is the result: > > http://cci.lbl.gov/~rwgk/boost_python/doc_signatures/function.hpp_2005_07_20_1909_diff > http://cci.lbl.gov/~rwgk/boost_python/doc_signatures/function.hpp_2005_07_20_1909 > > http://cci.lbl.gov/~rwgk/boost_python/doc_signatures/function.cpp_2005_07_20_1909_diff > http://cci.lbl.gov/~rwgk/boost_python/doc_signatures/function.cpp_2005_07_20_1909 > > Summary: > > - I've removed my __signatures__ method. > > - I've patched the getter for __doc__ to *always* append the list of > signatures. E.g.: > >>>> help(rational.lcm) > > Help on built-in function lcm: > > lcm(...) > C++ signature: > lcm(int, int) -> int > >>>> help(rational.int().numerator) > > Help on method numerator: > > numerator(...) method of boost_rational_ext.int instance > C++ signature: > numerator(boost::rational {lvalue}) -> int > > > This looks like *the* solution to me. Thanks a lot for your brilliant idea, > Nick! > > Personally I don't think we need the facilities to disable appending the > signatures. Are there other opinions? > > Dave, could you please briefly review my patch? It is still very simple: > forward class list in function.hpp + list signatures(bool > show_return_type=false) const; declaration; in function.cpp I've move some code > from the body of argument_error() to the new signatures() function and I've > patched the body of function_get_doc() to append the result of signatures(). > > Cheers, > Ralf > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > > From dirgesh.patel at hp.com Wed Aug 17 18:33:12 2005 From: dirgesh.patel at hp.com (Dirgesh Patel) Date: Wed, 17 Aug 2005 09:33:12 -0700 Subject: [C++-sig] Boost function call error Message-ID: I have made a .cpp file with boost_python_module inside it and a function call. which looks a little like this: def("copy", copy, imageMorph_copy() [return_value_policy()] ); with a overloading operator which looks a little like this: BOOST_PYTHON_FUNCTION_OVERLOADS(imageMorph_copy, copy, 1, 7) the overloader is correct in terms of syntax because i have other functions i am using in same syntax and it works..just fails on this one. here is the error i get: ../python/imageMorph_boost.cpp: In function `void init_module_imageMorph()': ../python/imageMorph_boost.cpp:107: error: no matching function for call to `def(const char[5], , boost::python::detail::overloads_proxy, imageMorph_copy>)' Any suggestions? i have tried to update my GCC to the latest and greatest. Thanks From allenb at vrsource.org Wed Aug 17 21:10:39 2005 From: allenb at vrsource.org (Allen Bierbaum) Date: Wed, 17 Aug 2005 14:10:39 -0500 Subject: [C++-sig] Boost.Python at runtime Message-ID: <43038BAF.1050304@vrsource.org> Has anyone every used or even tried to use Boost.Python to dynamically create python types at runtime (instead of the standard compile time method)? I am working on an very large extensible C++ class library that has a reflective interface that I can extend as much as I need. So instead of trying to create an enormous wrapper at compile time (that would be quickly out of date) I have been investigating the possibility of dynamically creating the python class/type wrappers on demand. So for example if I discovered at run-time that I wanted a wrapper for a class Hello I would: - Ask Hello's reflective interface for information about the class and it's bases - Create an associated boost.python class object - For each method Hello reports - add method to the wrapper class using signature and method info from Hello I would also need to handle registering associated smart pointers, etc. The details are definitely complex, but before I get to far into it I was wondering if anyone had done anything similar or had tried and could tell me how it went or if it is impossible with the current system. Thanks, Allen From skottmckay at gmail.com Wed Aug 17 21:27:35 2005 From: skottmckay at gmail.com (Scott McKay) Date: Wed, 17 Aug 2005 13:27:35 -0600 Subject: [C++-sig] how do I instantiate templates in pyste with types defined in different files? In-Reply-To: <20050816010840.51545.qmail@web30701.mail.mud.yahoo.com> References: <20050816010840.51545.qmail@web30701.mail.mud.yahoo.com> Message-ID: <51d017870508171227634e88c5@mail.gmail.com> I believe I've made it work previously by creating a new header file that #includes the template header, and the types you wish to instantiate that template for. In that case your original setup should work, but instead of using test.h for the template, use the header which is just made up of #includes. From dave at boost-consulting.com Wed Aug 17 23:00:05 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 17:00:05 -0400 Subject: [C++-sig] Boost.Python.function.__signatures__ References: <43034895.3080705@mundane.org> Message-ID: Ult Mundane writes: > 2. Parameters which are built-in C++ types are reported as > single-letter names (e.g., i = int, v = void, b = boolean, x > = long long, j = size_t, etc.). In your example below, it > shows the real C++ type names. I wonder what's different > about my configuration. Looks like either Ralf isn't using __cxa_demangle (see libs/python/src/converter/type_id.cpp) or your version of GCC is < 3.1. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Aug 17 23:04:23 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 17:04:23 -0400 Subject: [C++-sig] Boost function call error References: Message-ID: "Dirgesh Patel" writes: > I have made a .cpp file with boost_python_module inside it and a function > call. which looks a little like this: > > def("copy", copy, imageMorph_copy() ^^^^ My guess is that this is ambiguous and needs to be cast to a particular function pointer type, or better yet assigned to a function pointer of the correct type before passing it. See http://mail.python.org/pipermail/c++-sig/2004-December/008389.html > [return_value_policy()] ); > > with a overloading operator which looks a little like this: > > BOOST_PYTHON_FUNCTION_OVERLOADS(imageMorph_copy, copy, 1, 7) > > the overloader is correct in terms of syntax because i have other functions > i am using in same syntax and it works..just fails on this one. > > here is the error i get: > > ../python/imageMorph_boost.cpp: In function `void init_module_imageMorph()': > ../python/imageMorph_boost.cpp:107: error: no matching function for call to > `def(const char[5], , > boost::python::detail::overloads_proxy boost::python::default_call_policies>, imageMorph_copy>)' > > Any suggestions? i have tried to update my GCC to the latest and greatest. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Wed Aug 17 23:09:57 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 17:09:57 -0400 Subject: [C++-sig] Boost.Python at runtime References: <43038BAF.1050304@vrsource.org> Message-ID: Allen Bierbaum writes: > Has anyone every used or even tried to use Boost.Python to dynamically > create python types at runtime (instead of the standard compile time > method)? > > I am working on an very large extensible C++ class library that has a > reflective interface that I can extend as much as I need. So instead of > trying to create an enormous wrapper at compile time (that would be > quickly out of date) I have been investigating the possibility of > dynamically creating the python class/type wrappers on demand. > > So for example if I discovered at run-time that I wanted a wrapper for a > class Hello I would: > > - Ask Hello's reflective interface for information about the class and > it's bases > - Create an associated boost.python class object > - For each method Hello reports > - add method to the wrapper class using signature and method info > from Hello > > I would also need to handle registering associated smart pointers, etc. > The details are definitely complex, but before I get to far into it I > was wondering if anyone had done anything similar or had tried and could > tell me how it went or if it is impossible with the current system. Boost.Python is not exactly designed to do that, and what you're asking isn't possible to do in portable C++ without knowing all of the classes and member function signatures that you might want to wrap at compile-time anyway. However, see http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2781474 You can of course generate Boost.Python wrapping code dynamically and compile it into extension modules that are then loaded into your running Python program :) -- Dave Abrahams Boost Consulting www.boost-consulting.com From allenb at vrsource.org Wed Aug 17 23:45:37 2005 From: allenb at vrsource.org (Allen Bierbaum) Date: Wed, 17 Aug 2005 16:45:37 -0500 Subject: [C++-sig] Boost.Python at runtime In-Reply-To: References: <43038BAF.1050304@vrsource.org> Message-ID: <4303B001.6090207@vrsource.org> David Abrahams wrote: >Allen Bierbaum writes: > > > >>Has anyone every used or even tried to use Boost.Python to dynamically >>create python types at runtime (instead of the standard compile time >>method)? >> >>I am working on an very large extensible C++ class library that has a >>reflective interface that I can extend as much as I need. So instead of >>trying to create an enormous wrapper at compile time (that would be >>quickly out of date) I have been investigating the possibility of >>dynamically creating the python class/type wrappers on demand. >> >>So for example if I discovered at run-time that I wanted a wrapper for a >>class Hello I would: >> >>- Ask Hello's reflective interface for information about the class and >>it's bases >>- Create an associated boost.python class object >>- For each method Hello reports >> - add method to the wrapper class using signature and method info >>from Hello >> >>I would also need to handle registering associated smart pointers, etc. >>The details are definitely complex, but before I get to far into it I >>was wondering if anyone had done anything similar or had tried and could >>tell me how it went or if it is impossible with the current system. >> >> > >Boost.Python is not exactly designed to do that, > That is what I have come to suspect after looking into the depths of the code. It seems that behind the scenes everything to setup the class and methods ends up as standard run-time calls but the specific methods called and parameters passed are all based on compile time logic. So it does look like this would be difficult and most likely impossible without extensions to the code base to support it. Is this an area that anyone else has ever asked about or have you ever toyed with the idea of having run-time capabilities? >and what you're >asking isn't possible to do in portable C++ without knowing all of the >classes and member function signatures that you might want to wrap at >compile-time anyway. > > I could be wrong, but I think I will have all this anyway (or be able to get it) through a reflective interface in the library. Basically each run-time class can return a type descriptor object that can return as much information as necessary. I don't pretend to know C++ as well as you though, so maybe I am missing something. Is there some information or knowledge that would be needed that could not be stored and then looked up later at run-time when registering a wrapper? >However, see >http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2781474 > > I may be missing something here. I see how this is related, but I think what I want to do is quite different. I effectively want to do exactly what I could do at compile time with the current code but instead delay the creation so I do it on demand (to save compile time, library size and make the code work with new C++ object types that are introduced and dynamic extensions to the library). >You can of course generate Boost.Python wrapping code dynamically and >compile it into extension modules that are then loaded into your >running Python program :) > > > That would be fun but I think my users would wonder a little why the CPU and disk are churning so much at startup. :) Thanks, Allen From ult at mundane.org Wed Aug 17 23:55:34 2005 From: ult at mundane.org (Ult Mundane) Date: Wed, 17 Aug 2005 17:55:34 -0400 Subject: [C++-sig] Boost.Python.function.__signatures__ In-Reply-To: References: <43034895.3080705@mundane.org> Message-ID: <4303B256.30502@mundane.org> Thanks Dave, I was just looking at this. I'm using GCC 3.3.5, and it is going through __cxa_demangle using type_id.cpp, but __cxa_demangle returns -2, which means that it's not a mangled name to begin with. Googling offers a lot of confusion about what the correct behavior is for demangling builtin types. According to this post a while back on this list, it works in gcc 3.3 but not in gcc 3.4: http://mail.python.org/pipermail/c++-sig/2004-May/007391.html To fix it, inside gcc_demangle, I added a switch statement to translate single-character types if __cxa_demangle fails. This solves the problem. Code snippet attached for anybody who's interested. It goes in type_id.cpp inside the gcc_demangle function. It's based on the information provided here: http://www.codesourcery.com/cxx-abi/abi.html Ult David Abrahams wrote: > Ult Mundane writes: > >> 2. Parameters which are built-in C++ types are reported as >> single-letter names (e.g., i = int, v = void, b = boolean, x >> = long long, j = size_t, etc.). In your example below, it >> shows the real C++ type names. I wonder what's different >> about my configuration. > > Looks like either Ralf isn't using __cxa_demangle (see > libs/python/src/converter/type_id.cpp) or your version of GCC is < > 3.1. > -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: dirty_no_good_demangler.txt URL: From rwgk at yahoo.com Thu Aug 18 00:44:09 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 17 Aug 2005 15:44:09 -0700 (PDT) Subject: [C++-sig] Boost.Python.function.__signatures__ In-Reply-To: Message-ID: <20050817224409.84926.qmail@web31506.mail.mud.yahoo.com> --- David Abrahams wrote: > Ult Mundane writes: > > > 2. Parameters which are built-in C++ types are reported as > > single-letter names (e.g., i = int, v = void, b = boolean, x > > = long long, j = size_t, etc.). In your example below, it > > shows the real C++ type names. I wonder what's different > > about my configuration. > > Looks like either Ralf isn't using __cxa_demangle (see > libs/python/src/converter/type_id.cpp) I do use the demangler all the time. > or your version of GCC is < > 3.1. gcc 3.4 has a bug. 3.3 was fine, I think 4.0 is fine too (not sure, no time to double-check because I am out of town). Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From rwgk at yahoo.com Thu Aug 18 00:57:09 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 17 Aug 2005 15:57:09 -0700 (PDT) Subject: [C++-sig] Boost.Python.function.__signatures__ In-Reply-To: <4303B256.30502@mundane.org> Message-ID: <20050817225709.27292.qmail@web31515.mail.mud.yahoo.com> > // The __cxa_demangle function is supposed to translate > // builtin types from their one-character mangled names, > // but it doesn't in gcc 3.3.5. Oh, I am surprised. I thought only 3.4 has the problem. I'd love to see Ult's patch in the CVS, with proper #ifdef's for gcc 3.4 (all versions, to my knowledge) and whatever other gcc's are affected. I've been annoyed by the gcc bug for quite some time. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From dave at boost-consulting.com Thu Aug 18 01:00:25 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 19:00:25 -0400 Subject: [C++-sig] Boost.Python.function.__signatures__ References: <43034895.3080705@mundane.org> <4303B256.30502@mundane.org> Message-ID: Ult Mundane writes: > #define DIRTY_NO_GOOD_DEMANGLER 1 That's hilarious! Do you give us permission to use the code in Boost.Python under the Boost Software License version 1.0? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Aug 18 01:07:13 2005 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 17 Aug 2005 19:07:13 -0400 Subject: [C++-sig] Boost.Python at runtime References: <43038BAF.1050304@vrsource.org> <4303B001.6090207@vrsource.org> Message-ID: Allen Bierbaum writes: > David Abrahams wrote: > >>Allen Bierbaum writes: >> > Is this an area that anyone else has ever asked about or have you ever > toyed with the idea of having run-time capabilities? We have about as many run-time capabilities as are possible in Boost.Python. >>and what you're asking isn't possible to do in portable C++ without >>knowing all of the classes and member function signatures that you >>might want to wrap at compile-time anyway. ^^^^^^^^^^^^^^^ > I could be wrong, but I think I will have all this anyway (or be able to > get it) through a reflective interface in the library. Basically each > run-time class Too late. The information is needed at compile-time, as I said. > can return a type descriptor object that can return as > much information as necessary. I don't pretend to know C++ as well as > you though, so maybe I am missing something. Is there some information > or knowledge that would be needed that could not be stored and then > looked up later at run-time when registering a wrapper? It doesn't matter if it can be looked up at run-time, because it needs to be available at compile-time. >>However, see >>http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2781474 >> >> > I may be missing something here. I see how this is related, but I > think what I want to do is quite different. Yes, what you want to do includes generating function call wrappers. > I effectively want to do exactly what I could do at compile time > with the current code but instead delay the creation so I do it on > demand I understand that. >>You can of course generate Boost.Python wrapping code dynamically and >>compile it into extension modules that are then loaded into your >>running Python program :) >> > That would be fun but I think my users would wonder a little why the CPU > and disk are churning so much at startup. :) You would cache the results, so you only have to pay once. There's a successful system that does it that way: it allows you to embed C++ code directly in your Python and have it compiled on the fly, so I know some people can tolerate it. Of course, if you're going to generate code anyway I'd probably generate traditional Python/C API code rather than Boost.Python stuff, since it will compile faster. -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Thu Aug 18 01:16:29 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 17 Aug 2005 16:16:29 -0700 (PDT) Subject: [C++-sig] Boost.Python.function.__signatures__ In-Reply-To: <43034895.3080705@mundane.org> Message-ID: <20050817231629.41241.qmail@web31512.mail.mud.yahoo.com> --- Ult Mundane wrote: > Ralf, > > I'm using your function signatures patch, thank you very > much, it is excellent and a huge timesaver for documenting > exported C++ interfaces. > > I wonder if you've made any updates since you posted it last > month. Is your patch checked into CVS somewhere? No, sorry, several things: - I was waiting for the boost release (done now, but...) - I am on the road now for three weeks (and this silly wireless keeps knocking me off the network...) - Nikolay Mladenov was working on a more sophisticated version: Nikolay, are you still working on this? Do you have an ETA? > I'm looking into making two changes: > > 1. At the moment, parameters which are classes exported to > Python are reported with their C++ names, not their Python > names (i.e., if you export the class with a different name, > the docstring doesn't match the name you use in Python). > Glancing over the Boost.Python code, this is over my head at > the moment; is this something that seems reasonable/doable > to you? This was on Nikolay's list, I believe. I am not sure though I like it. One the one hand the signatures with the full C++ types tend to be long, on the other hand they are precise. I don't know how to best resolve this. ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs From ult at mundane.org Thu Aug 18 04:58:48 2005 From: ult at mundane.org (Ult Mundane) Date: Wed, 17 Aug 2005 22:58:48 -0400 Subject: [C++-sig] Boost.Python.function.__signatures__ In-Reply-To: References: <43034895.3080705@mundane.org> <4303B256.30502@mundane.org> Message-ID: <4303F968.3090107@mundane.org> :-) Yes of course. Ult David Abrahams wrote: > Ult Mundane writes: > >> #define DIRTY_NO_GOOD_DEMANGLER 1 > > That's hilarious! Do you give us permission to use the code in > Boost.Python under the Boost Software License version 1.0? > From steenpaz at sdf-eu.org Thu Aug 18 14:10:54 2005 From: steenpaz at sdf-eu.org (Dirk Steenpass) Date: Thu, 18 Aug 2005 14:10:54 +0200 Subject: [C++-sig] boost.python iterators References: Message-ID: [snip] > The following snippet illustrates that return_internal_reference can be > used for a simple user defined type but not for the fundamental int. [snip] Probably, because it makes no sense to return an immutable object by reference... (fool, indeed ;-). cheers, dirk From ericjardim at gmail.com Thu Aug 18 15:22:41 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Thu, 18 Aug 2005 10:22:41 -0300 Subject: [C++-sig] Strange behavior when split modules Message-ID: <432ec6c505081806226636b4f1@mail.gmail.com> Hi all, While wrapping the Qt4 code, I decided to split my single "Qt.so" module in many modules (that by now are: Namespace, Core and Gui), and I am using a package called Qt, that do some essential Python initializations on "__init__.py". Everything was Ok while spliting the modules, and it compiled Ok, and most of my tests ran Ok. But a strange thing is happening! There is a method called "parent" defined on the "QObject" class that returns the object's parent (or None if not it exists) that is another "QObject". As this is just a reference to a known object, I am using the "return_value_policy" policy. The "QObject" class is defined on the "Core" module. On the other hand. I have a lot of classes defined on the "Gui" module, that are children (direct or indirect) of QObject. One of them, for example, is the "QWidget" class. When I call "parent" from a "QWidget" object it return an object with a different Python object, and I loose it's reference because the refcount of that especific new Python object is lost. I also noted that this behavior happend with other methods that return "non-new" objects. All I have to say is that when modules were together in one this problem didn't occur. To be sure of that, I just moved the QWidget class (and QPaintDevice, that is another base class of QWidget) to the "Core" module, and everything worked again. So, am I not allowed to defined derived classes in different modules, or am I doing something wrong? By now, it is not a problem defining everything in a single module, but if someone may want to write extension of the python-qt4 library, that would be a problem. By the way, the project can be downloaded from: http://developer.berlios.de/projects/python-qt4/ Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From smartel at real.com Thu Aug 18 21:07:55 2005 From: smartel at real.com (Saikat Chakrabarti) Date: Thu, 18 Aug 2005 12:07:55 -0700 Subject: [C++-sig] Converting from Python integer to C++ by reference Message-ID: Hello, I am attempting to expose a class in C++ with a method that takes a reference to an integer. Thus, a simple version of what I have is as follows: class C { public: void SetMe(int& i); } and SetMe is implemented as follows: void C::SetMe(int& i) { i = 5; } and my goal is to be able to call this method from Python with an integer and have the value of that integer in Python set. Thus, in Python, I would like to do: c = C() i = 0 c.SetMe(i) and have i's value be 5. However, when I do this, I get an exception on line 292 of arg_from_python.hpp (at the end of the constructor for reference_arg_from_python) that simply says I have an access violation. If I get rid of the reference and made SetMe simply declared as "void SetMe(int i)", the code works fine. Also, if I change int to long (as I believe Python integers are actually C++ long types), but keep the reference (thus, having void SetMe(long& i), it gives me the same error. It seems like I am doing something fundamentally wrong. How should I fix this problem? Thanks, Saikat Chakrabarti From greg.landrum at gmail.com Thu Aug 18 22:32:13 2005 From: greg.landrum at gmail.com (Greg Landrum) Date: Thu, 18 Aug 2005 13:32:13 -0700 Subject: [C++-sig] Converting from Python integer to C++ by reference In-Reply-To: References: Message-ID: <60825b0f0508181332256b0f22@mail.gmail.com> On 8/18/05, Saikat Chakrabarti wrote: > Hello, > I am attempting to expose a class in C++ with a method that takes a > reference to an integer. Thus, a simple version of what I have is as > follows: > > class C > { > public: > void SetMe(int& i); > } > > and SetMe is implemented as follows: > > void C::SetMe(int& i) > { > i = 5; > } > > and my goal is to be able to call this method from Python with an > integer and have the value of that integer in Python set. Thus, in > Python, I would like to do: > > c = C() > i = 0 > c.SetMe(i) > > and have i's value be 5. However, when I do this, I get an exception on > line 292 of arg_from_python.hpp (at the end of the constructor for > reference_arg_from_python) that simply says I have an access violation. > If I get rid of the reference and made SetMe simply declared as "void > SetMe(int i)", the code works fine. Also, if I change int to long (as I > believe Python integers are actually C++ long types), but keep the > reference (thus, having void SetMe(long& i), it gives me the same error. > It seems like I am doing something fundamentally wrong. How should I > fix this problem? I believe that the fundamental problem here is that because integers are not mutable objects in Python, there's no concept of a "reference to an int" as far as Python is concerned. For example, if you were to attempt to write your example in Python, you'd get the same behavior: >>> class C: ... def SetMe(self,i): ... i = 5 ... >>> c = C() >>> i = 0 >>> c.SetMe(i) >>> i 0 One way to simulate modifying the integer would be to return the result, something like: >>> class C: ... def SetMe(self,i): ... i = 5 ... return i ... >>> c = C() >>> i = 0 >>> i=c.SetMe(i) >>> i 5 -greg From seefeld at sympatico.ca Fri Aug 19 12:45:39 2005 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 19 Aug 2005 12:45:39 +0200 Subject: [C++-sig] exec test failure Message-ID: <4305B853.3070207@sympatico.ca> I submitted a new test that runs the new 'exec' and 'exec_file' functions. I tested it locally (obviously), but now I see it fail (http://engineering.meta-comm.com/boost-regression/CVS-HEAD/developer/python.html). The error is always the same 'RuntimeError: exec.py : no such file', which I don't understand. The file is checked into the libs/python/test/ directory. Could somebody with more insight into the boost.build logic and Jamfile syntax please help ? Thanks, Stefan From skottmckay at gmail.com Fri Aug 19 23:45:36 2005 From: skottmckay at gmail.com (Scott McKay) Date: Fri, 19 Aug 2005 15:45:36 -0600 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite In-Reply-To: References: <51d01787050809193534085538@mail.gmail.com> <51d01787050810180311b1d0ad@mail.gmail.com> Message-ID: <51d01787050819144518e8b1ce@mail.gmail.com> > The > Python generate() call is creating a Python TestExtendedFactory > object, which is derived from the Python wrapper for BasicFactory, so > it contains a C++ BasicFactory. Does it contain a C++ Factory object? > not unless BasicFactory is derived from Factory and, from > Boost.Python's POV, not unless its class_ names Factory as one of its > bases<...>. You didn't show the declaration of BasicFactory, so it's > hard to say much about it. A lack of bases was indeed the problem. I generated the source with a patched and updated version of Pyste that has new-style polymorphism and handles wrapped classes that have holders, and had an incorrect test that resulted in the bases not being included. Thanks! That has led me to a question on what is required in terms of implicit conversion calls to handle classes in the same hierarchy that are wrapped with wrapper<> and held by smart pointers. I can't seem to find a combination to allow derivation from both Factory and BasicFactory. If I have a python class that derives from Factory, held by a smart pointer, I need the implicit conversion defined below in Factory.cpp for it to work. If I have a python class that derives from BasicFactory (which itself derives from Factory), also held by a smart pointer, I need the implicit conversions in BasicFactory for that to work. However if I have both, a python class derived from BasicFactory will segfault. My guess is that that's because there's two converters between classes in the same hierarchy to a smart_ptr, and it's looping in trying to resolve that. Am I doing something wrong in how I'm setting up the implicit conversions? Or should only the base class have the holder specificied, with derived classes getting it automatically (although I tried this and couldn't make it work)? As a side note the Factory and BasicFactory classes are exported in separate modules. I'm not sure that that's relevant though. Below is the boost python code for Factory/BasicFactory, the C++ for the example Runner class to show how the factory is used, and python to show the usage. I've also added some gdb output to show the loop and the initial entry into it. Apologies if this is too verbose. Thanks in advance for any help. Scott ------ Factory.cpp namespace { struct Factory_Wrapper: Factory, wrapper< Factory > { Factory_Wrapper(const Factory& p0): Factory(p0) {} Factory_Wrapper(): Factory() {} Factory& generate(SourceGroup& p0) { if (override f = this->get_override("generate")) return call< Factory& >( f.ptr(), boost::ref(p0)); return Factory::generate(boost::ref(p0)); } Factory& default_generate(SourceGroup& p0) { return Factory::generate(boost::ref(p0)); } }; }// namespace void Export_Factory() { class_< Factory_Wrapper, smart_ptr< Factory_Wrapper > >("Factory", init< >()) .def("generate", &Factory::generate, &Factory_Wrapper::default_generate, return_self<>()) .def(init< const Factory& >()) ; implicitly_convertible< smart_ptr< Factory_Wrapper >, smart_ptr< Factory > >(); implicitly_convertible< smart_ptr< Factory >, smart_ptr< Factory_Wrapper > >(); } ---- BasicFactory namespace { struct BasicFactory_Wrapper: BasicFactory, wrapper< BasicFactory > { BasicFactory_Wrapper(const BasicFactory& p0): BasicFactory(p0) {} BasicFactory_Wrapper(): BasicFactory() {} Factory& generate(SourceGroup& p0) { if (override f = this->get_override("generate")) return call< Factory& >( f.ptr(), boost::ref(p0)); return BasicFactory::generate(boost::ref(p0)); } Factory& default_generate(SourceGroup& p0) { return BasicFactory::generate(boost::ref(p0)); } }; }// namespace void Export_BasicFactory() { class_< BasicFactory_Wrapper, bases< Factory > , smart_ptr< BasicFactory_Wrapper > >("BasicFactory", init< >()) .def("generate", (Factory& (BasicFactory::*)(SourceGroup&) )&BasicFactory::generate, (Factory& (BasicFactory_Wrapper::*)(SourceGroup&))&BasicFactory_Wrapper::default_generate, return_self<>()) .def(init< const BasicFactory& >()) ; implicitly_convertible< smart_ptr< BasicFactory_Wrapper >, smart_ptr< Factory > >(); implicitly_convertible< smart_ptr< Factory >, smart_ptr< BasicFactory_Wrapper > >(); } ----- Dummy class to show how we use it: class Runner { SourceGroup _docs; smart_ptr _factory; public: Runner() {} void setFactory( const smart_ptr &factory ) { _factory = factory; } void run() { _factory->generate( _docs ); std::cout << "Generated: " << _docs.size() << " docs.\n"; } }; ------- Python usage example: class TestExtendedFactory( X.BasicFactory ): def __init__( self ): # call init of parent to setup smart pointers correctly super( TestExtendedFactory, self ).__init__() def generate( self, output ): super( TestExtendedFactory, self ).generate( output ) return self def main(): runner = X.Runner() myFactory = TestExtendedFactory() runner.setFactory( myFactory ) runner.run() #3564 0x0e3aaa10 in boost::python::converter::extract_rvalue >::operator() (this=0xdfe34180) at extract.hpp:175 #3565 0x0e3aa381 in boost::python::converter::implicit, smart_ptr<(anonymous namespace)::Factory_Wrapper> >::construct (obj=0xe1c25a4, data=0xdfe34234) at implicit.hpp:33 #3566 0x0e3b9f51 in boost::python::converter::rvalue_from_python_stage2 (source=0xe1c25a4, data=@0xdfe34234, converters=@0x81a3cd0) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/converter/from_python.cpp:112 #3567 0x0e3aa8b2 in boost::python::converter::extract_rvalue >::operator() (this=0xdfe34230) at extract.hpp:175 #3568 0x0e3aa1cd in boost::python::converter::implicit, smart_ptr >::construct (obj=0xe1c25a4, data=0xdfe342e4) at implicit.hpp:33 #3569 0x0e3b9f51 in boost::python::converter::rvalue_from_python_stage2 (source=0xe1c25a4, data=@0xdfe342e4, converters=@0x81a3be0) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/converter/from_python.cpp:112 #3570 0x0e3aaa10 in boost::python::converter::extract_rvalue >::operator() (this=0xdfe342e0) at extract.hpp:175 #3571 0x0e3aa381 in boost::python::converter::implicit, smart_ptr<(anonymous namespace)::Factory_Wrapper> >::construct (obj=0xe1c25a4, data=0xdfe34394) at implicit.hpp:33 #3572 0x0e3b9f51 in boost::python::converter::rvalue_from_python_stage2 (source=0xe1c25a4, data=@0xdfe34394, converters=@0x81a3cd0) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/converter/from_python.cpp:112 #3573 0x0e3aa8b2 in boost::python::converter::extract_rvalue >::operator() (this=0xdfe34390) at extract.hpp:175 #3574 0x0e3aa1cd in boost::python::converter::implicit, smart_ptr >::construct (obj=0xe1c25a4, data=0xdfe34444) at implicit.hpp:33 #3575 0x0e3b9f51 in boost::python::converter::rvalue_from_python_stage2 (source=0xe1c25a4, data=@0xdfe34444, converters=@0x81a3be0) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/converter/from_python.cpp:112 .... #35422 0x0e3aa8b2 in boost::python::converter::extract_rvalue >::operator() (this=0xdfffc570) at extract.hpp:175 #35423 0x0e3aa1cd in boost::python::converter::implicit, smart_ptr >::construct (obj=0xe1c2644, data=0xdfffc630) at implicit.hpp:33 #35424 0x0e3b9a93 in boost::python::converter::arg_rvalue_from_python const&>::operator() (this=0xdfffc630) at arg_from_python.hpp:321 #35425 0x0e3b9705 in boost::python::detail::invoke const&), boost::python::arg_from_python, boost::python::arg_from_python const&> > (f=@0x81a576c, tc=@0xdfffc648, ac0=@0xdfffc630) at invoke.hpp:94 #35426 0x0e3b9258 in boost::python::detail::caller_arity<2u>::impl const&), boost::python::default_call_policies, boost::mpl::vector3 const&> >::operator() (this=0x81a576c, args_=0xe1bff8c) at caller.hpp:199 #35427 0x0e3b8d5e in boost::python::objects::caller_py_function_impl const&), boost::python::default_call_policies, boost::mpl::vector3 const&> > >::operator() (this=0x81a5768, args=0xe1bff8c, kw=0x0) at py_function.hpp:38 #35428 0x0e3c2df5 in boost::python::objects::py_function::operator() (this=0x81a5780, args=0xe1bff8c, kw=0x0) at py_function.hpp:139 #35429 0x0e3c189c in boost::python::objects::function::call (this=0x81a5778, args=0xe1bff8c, keywords=0x0) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/object/function.cpp:212 #35430 0x0e3c4bae in boost::python::objects::(anonymous namespace)::bind_return::operator() (this=0xdfffc830) at boost/build-1.32.0/boost_1_32_0/libs/python/build/../src/object/function.cpp:505 From ericjardim at gmail.com Sat Aug 20 00:03:38 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 19 Aug 2005 19:03:38 -0300 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite In-Reply-To: <51d01787050819144518e8b1ce@mail.gmail.com> References: <51d01787050809193534085538@mail.gmail.com> <51d01787050810180311b1d0ad@mail.gmail.com> <51d01787050819144518e8b1ce@mail.gmail.com> Message-ID: <432ec6c505081915036616344a@mail.gmail.com> 2005/8/19, Scott McKay : > > implicitly_convertible< smart_ptr< Factory_Wrapper >, smart_ptr< > Factory > >(); > implicitly_convertible< smart_ptr< Factory >, smart_ptr< > Factory_Wrapper > >(); > } Sorry about my ignorance. Why do you define those implicitly convertble pointers? [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From skottmckay at gmail.com Sat Aug 20 02:36:31 2005 From: skottmckay at gmail.com (Scott McKay) Date: Fri, 19 Aug 2005 18:36:31 -0600 Subject: [C++-sig] preventing a copy of the vector when using the vector_indexing_suite In-Reply-To: <432ec6c505081915036616344a@mail.gmail.com> References: <51d01787050809193534085538@mail.gmail.com> <51d01787050810180311b1d0ad@mail.gmail.com> <51d01787050819144518e8b1ce@mail.gmail.com> <432ec6c505081915036616344a@mail.gmail.com> Message-ID: <51d0178705081917367d28ca7f@mail.gmail.com> > Sorry about my ignorance. Why do you define those implicitly convertble > pointers? It's required to make smart pointers work correctly to convert between classes in the same hierarchy I believe. There may be a cleaner implicit way to make them work, but this is the approach I took after reading through old postings, faqs and various boost::python/pyste doco. From ericjardim at gmail.com Sat Aug 20 04:46:55 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Fri, 19 Aug 2005 23:46:55 -0300 Subject: [C++-sig] Strange behavior when split modules In-Reply-To: <432ec6c505081806226636b4f1@mail.gmail.com> References: <432ec6c505081806226636b4f1@mail.gmail.com> Message-ID: <432ec6c50508191946ca9c548@mail.gmail.com> Hi, folks... Does anybody had this same problem? I'll make a simple "dummy" class example to reproduce the error. If it is really a bug, this will be a problem for people who may want to handle extensions of a C++ library also in C++, that should also be wrapped to Python. If derived classes remain in different modules, some things get strange. I suppose that it have something related to some local pointer registry. I'll test it and send the case to you. Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericjardim at gmail.com Sat Aug 20 09:31:42 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sat, 20 Aug 2005 04:31:42 -0300 Subject: [C++-sig] Cross-module inheritance Message-ID: <432ec6c50508200031e2aa68b@mail.gmail.com> Hi again, I searched google and discovered that the problem is real. Cross-module inheritance and some other things do not work with boost.python (I don't know why). Some old posts show it: http://lists.boost.org/Archives/boost/2001/07/14520.php http://lists.boost.org/Archives/boost/2001/07/14491.php And recent posts show that some guys resolved the problem (partially): http://mail.python.org/pipermail/c++-sig/2005-April/008829.html http://mail.python.org/pipermail/c++-sig/2005-April/008835.html Doing: import sys, dl sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL) But, I am afraid this is not a portable solution. 1 - Could anyone tell me if, at least, this solution is portable among gcc compilation, even on Windows? 2 - Does anyone suggest me to use this trick now, or should I stay with the "single-module", and wait for this issue to be solved (is it possible, given boost.python current state?) 3 - Is there any other workaround? It looks like SWIG can do it (am I right?) 4 - Should I give up everything? ( hope not ;) Thanks, [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob_barb_eaton at yahoo.com Sun Aug 21 05:49:27 2005 From: bob_barb_eaton at yahoo.com (Bob Eaton) Date: Sun, 21 Aug 2005 09:19:27 +0530 Subject: [C++-sig] Embedded Python: how to enumerate function names? Message-ID: In my embedded Python C++ code, I have a PyObject* to the module and its dictionary. From either of these, is there a way to enumerate the methods/functions defined in that file? I know I can at least get the function names with (((PyFunctionObject *)func) -> func_name), but I'm not clear on how to get the PyFunctionObject pointer to begin with. Is it the Keys or Values or Items of the dictionary? Also, once I have the function pointer, can I enumerate its parameters and return type? And finally, what's the difference between a Function and a Method? Any help will be greatly appreciated. Bob From roman.yakovenko at gmail.com Sun Aug 21 08:33:41 2005 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 21 Aug 2005 09:33:41 +0300 Subject: [C++-sig] small error within implicitly_convertible example Message-ID: <7465b617050820233359e2729d@mail.gmail.com> Hi. There is an error, while compiling example: http://boost.org/libs/python/doc/v2/implicit.html. I've got errors on compilers: gcc 3.3 ( from debian 3.1 ) and on msvc 7.1 ( win XP ). The error caused by the fact that X::operator int() defined as non const. Adding const to the definition fix the problem. Roman From dave at boost-consulting.com Sun Aug 21 17:25:29 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Aug 2005 11:25:29 -0400 Subject: [C++-sig] Cross-module inheritance References: <432ec6c50508200031e2aa68b@mail.gmail.com> Message-ID: Eric Jardim writes: > Hi again, > > I searched google and discovered that the problem is > real. Cross-module inheritance and some other things do not work > with boost.python (I don't know why). It certainly does work; you just have to follow some rules when you build your extensions to make sure their RTTI info is properly shared. > Some old posts show it: > http://lists.boost.org/Archives/boost/2001/07/14520.php > http://lists.boost.org/Archives/boost/2001/07/14491.php That was for Boost.Python v1. You are (I hope) using the improved Boost.Python v2 > And recent posts show that some guys resolved the problem (partially): > http://mail.python.org/pipermail/c++-sig/2005-April/008829.html > http://mail.python.org/pipermail/c++-sig/2005-April/008835.html > > Doing: > > import sys, dl > sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL) This is the brute-force method. A more delicate and portable approach is to stick the common base class in a shared library that is linked to by all the extension modules that derive from it. > But, I am afraid this is not a portable solution. > > 1 - Could anyone tell me if, at least, this solution is portable among gcc > compilation, even on Windows? No, the Windows dynamic linking system is different. However, the approach I suggested above works fine. > 2 - Does anyone suggest me to use this trick now, or should I stay with the > "single-module", and wait for this issue to be solved (is it possible, given > boost.python current state?) There is no "solving it" further; it has nothing to do with the state of Boost.Python. It has to do with the way shared libraries and run-time type information work on your platform. > 3 - Is there any other workaround? It looks like SWIG can do it (am I > right?) > 4 - Should I give up everything? ( hope not ;) It's a little early for that yet. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Aug 21 17:18:56 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Aug 2005 11:18:56 -0400 Subject: [C++-sig] small error within implicitly_convertible example References: <7465b617050820233359e2729d@mail.gmail.com> Message-ID: Roman Yakovenko writes: > Hi. There is an error, while compiling example: > http://boost.org/libs/python/doc/v2/implicit.html. > > I've got errors on compilers: gcc 3.3 ( from debian 3.1 ) and on msvc > 7.1 ( win XP ). > > The error caused by the fact that X::operator int() defined as non const. > Adding const to the definition fix the problem. > > Roman Thanks, Roman! Fixed in CVS. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Aug 21 17:20:06 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Aug 2005 11:20:06 -0400 Subject: [C++-sig] Embedded Python: how to enumerate function names? References: Message-ID: "Bob Eaton" writes: > In my embedded Python C++ code, I have a PyObject* to the module and its > dictionary. From either of these, is there a way to enumerate the > methods/functions defined in that file? > > I know I can at least get the function names with (((PyFunctionObject > *)func) -> func_name), but I'm not clear on how to get the PyFunctionObject > pointer to begin with. Is it the Keys or Values or Items of the dictionary? > > Also, once I have the function pointer, can I enumerate its parameters and > return type? > > And finally, what's the difference between a Function and a Method? > > Any help will be greatly appreciated. This is not really a C++ specific question. I don't mind you asking here, but you will probably get better answers on the regular python-list. -- Dave Abrahams Boost Consulting www.boost-consulting.com From hans_meine at gmx.net Mon Aug 22 00:02:07 2005 From: hans_meine at gmx.net (Hans Meine) Date: Mon, 22 Aug 2005 00:02:07 +0200 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) Message-ID: <200508220002.07595.hans_meine@gmx.net> Hi! I guess I am not the first one trying to do this, but the closest discussion I could find did not solve this topic: http://mail.python.org/pipermail/c++-sig/2005-June/008959.html I am trying to do something like python::class_("PythonVector", python::no_init) .def("__init__", python::raw_function(&createVector, 1)); But this gives the vector as first element of the args tuple to createVector(). Now, my createVector looks like this: MyVector createVector(const python::tuple &args, const python::dict &) { int size = python::len(args); MyVector result(size); for(int i=0; i(args[i])(); return result; } Is there a way to combine the functionality of raw_function and make_constructor? (I even tried staticmethod("__init__") ;-) ) -- Ciao, / / .o. /--/ ..o / / ANS ooo From dave at boost-consulting.com Mon Aug 22 02:47:00 2005 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 21 Aug 2005 20:47:00 -0400 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) References: <200508220002.07595.hans_meine@gmx.net> Message-ID: Hans Meine writes: > Hi! > > I guess I am not the first one trying to do this, but the closest discussion I > could find did not solve this topic: > http://mail.python.org/pipermail/c++-sig/2005-June/008959.html > > I am trying to do something like > > python::class_("PythonVector", python::no_init) > .def("__init__", python::raw_function(&createVector, 1)); > > But this gives the vector as first element of the args tuple to > createVector(). What's wrong with that? -- Dave Abrahams Boost Consulting www.boost-consulting.com From ericjardim at gmail.com Mon Aug 22 03:37:04 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Sun, 21 Aug 2005 22:37:04 -0300 Subject: [C++-sig] Cross-module inheritance In-Reply-To: References: <432ec6c50508200031e2aa68b@mail.gmail.com> Message-ID: <432ec6c5050821183739f48269@mail.gmail.com> 2005/8/21, David Abrahams : > > It certainly does work; you just have to follow some rules when you > build your extensions to make sure their RTTI info is properly shared. Fine. Is there any example/docs of it? That was for Boost.Python v1. You are (I hope) using the improved > Boost.Python v2 Sure, I am using the newest (v2 1.33) :) This is the brute-force method. A more delicate and portable approach > is to stick the common base class in a shared library that is linked > to by all the extension modules that derive from it. I imagined that. But how should I do this? This base class is now on a shared library. You mean that the wrapper class (QObject_Wrapper) or the exposed class(class_("Qobject")) should be in a separed shared library? Anyway, Python modules are shared librarys anyway. But I think they don't see each other (modules). No, the Windows dynamic linking system is different. However, the > approach I suggested above works fine. Hmm, good. I really need someone to test things for me on Windows. I don't have a copy of it, besides it is "wild territory" for me. > 4 - Should I give up everything? ( hope not ;) > It's a little early for that yet. > Ok, let's get back to work :) [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From hans_meine at gmx.net Mon Aug 22 14:20:26 2005 From: hans_meine at gmx.net (Hans Meine) Date: Mon, 22 Aug 2005 14:20:26 +0200 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) In-Reply-To: References: <200508220002.07595.hans_meine@gmx.net> Message-ID: <200508221420.26883.hans_meine@gmx.net> Hi again, and thanks for your answer! On Monday 22 August 2005 02:47, David Abrahams wrote: > > I am trying to do something like > > > > python::class_("PythonVector", python::no_init) > > .def("__init__", python::raw_function(&createVector, 1)); > > > > But this gives the vector as first element of the args tuple to > > createVector(). > > What's wrong with that? Err, I was always trying to wrap some kind of factory functions. You mean I should write initialization functions instead of constructing ones? Hmm, I tried that, but again have problems: My first try was to have an initialization function like this: void initVectorValue(const python::tuple &args, const python::dict &) { MyVector &result((python::extract(args[0])())); int size = python::len(args) - 1; result.resize(size); for(int i=0; i(args[i + 1])(); } and export that with .def("__init__", raw_function(&initVectorValue, 2)) However, that would not compile with either 1.31.0 or 1.32.0, I got errors like | /software/boost-1.32.0/include/boost-1_32/boost/python/raw_function.hpp: In | member function `PyObject* | boost::python::detail::raw_dispatcher::operator()(PyObject*, PyObject*) | [with F = void (*)(const boost::python::tuple&, const boost::python::dict&)] | ': | /software/boost-1.32.0/include/boost-1_32/boost/python/object/py_function.hpp:92: instantiated from `PyObject* boost::python::objects::full_py_function_impl::operator() (PyObject*, PyObject*) [with Caller = boost::python::detail::raw_dispatcher, Sig = boost::mpl::vector1]' | /software/boost-1.32.0/include/boost-1_32/boost/mpl/if.hpp:67: instantiated from here | /software/boost-1.32.0/include/boost-1_32/boost/python/raw_function.hpp:29: error: invalid | use of void expression I tried changing the return type of my function to MyVector &, but then trying to construct PythonVector objects results in: | TypeError: No registered converter was able to extract a C++ reference to | type vigra::PythonVector from this Python object of type PythonVector BTW: vigra::PythonVector is MyVector above, which I exported to python simply with python::class_("PythonVector", python::no_init).def(... I am currently compiling 1.33.0 in order not to blame myself in that respect. Ideally, I'd like to wrap factory functions like the createVector() I originally posted. Then, one would not need default constructible classes whose default constructed objects can be brought to the correct state. (E.g. MyVector should be of fixed, but variable size that can be set in the constructor.) For now, I would be happy with a C++ resize(), but I need a workaround for the raw_function constructor. The real motivation is that I want to pickle my vector objects, and AFAICS I need the constructor for this. So far, I just exported the beforementioned createVector() factor function as a module function to python and used that for creating my objects, but how should pickle know that? Ciao, / / /--/ / / ANS From dave at boost-consulting.com Mon Aug 22 14:22:17 2005 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 22 Aug 2005 08:22:17 -0400 Subject: [C++-sig] Cross-module inheritance References: <432ec6c50508200031e2aa68b@mail.gmail.com> <432ec6c5050821183739f48269@mail.gmail.com> Message-ID: Eric Jardim writes: > 2005/8/21, David Abrahams : >> >> It certainly does work; you just have to follow some rules when you >> build your extensions to make sure their RTTI info is properly shared. > > > Fine. Is there any example/docs of it? Now that I look, I'm afraid not. > That was for Boost.Python v1. You are (I hope) using the improved >> Boost.Python v2 > > > Sure, I am using the newest (v2 1.33) :) > > This is the brute-force method. A more delicate and portable approach >> is to stick the common base class in a shared library that is linked >> to by all the extension modules that derive from it. > > > I imagined that. But how should I do this? This base class is now on a > shared library. A separate one from both the extension modules? Are both extension modules linked to that shared library? > You mean that the wrapper class (QObject_Wrapper) or the > exposed class(class_("Qobject")) should be in a separed > shared library? No. > Anyway, Python modules are shared librarys anyway. But I think they > don't see each other (modules). Yes, that's part of why you put the base class in a common shared library. Both extension modules need to see its RTTI information. If that doesn't work for you, have a look at this thread: http://gcc.gnu.org/ml/gcc/2002-05/msg01970.html This is a pretty murky area for the Gnu loader, unfortunately. -- Dave Abrahams Boost Consulting www.boost-consulting.com From hans_meine at gmx.net Mon Aug 22 15:11:02 2005 From: hans_meine at gmx.net (Hans Meine) Date: Mon, 22 Aug 2005 15:11:02 +0200 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) In-Reply-To: <200508221420.26883.hans_meine@gmx.net> References: <200508220002.07595.hans_meine@gmx.net> <200508221420.26883.hans_meine@gmx.net> Message-ID: <200508221511.03488.hans_meine@gmx.net> On Monday 22 August 2005 14:20, Hans Meine wrote: > I am currently compiling 1.33.0 in order not to blame myself in that > respect. OK, just FYI, I tried your proposed initVectorValue() approach with 1.33.0, too - both with void and MyVector& as return types, with the same results. I am looking forward to further pointers. :-/ > For now, I would be happy with a C++ resize(), but I need a workaround for > the raw_function constructor. The real motivation is that I want to pickle > my vector objects, and AFAICS I need the constructor for this. So far, I > just exported the beforementioned createVector() factor function as a > module function to python and used that for creating my objects, but how > should pickle know that? Ciao, / / /--/ / / ANS From ericjardim at gmail.com Mon Aug 22 15:13:15 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Mon, 22 Aug 2005 10:13:15 -0300 Subject: [C++-sig] Cross-module inheritance In-Reply-To: References: <432ec6c50508200031e2aa68b@mail.gmail.com> <432ec6c5050821183739f48269@mail.gmail.com> Message-ID: <432ec6c5050822061327383169@mail.gmail.com> 2005/8/22, David Abrahams : > > Now that I look, I'm afraid not. A separate one from both the extension modules? Are both extension > modules linked to that shared library? Sure. It is the Qt library. No. Hmm, now I am confused. Yes, that's part of why you put the base class in a common shared > library. Both extension modules need to see its RTTI information. > If that doesn't work for you, have a look at this thread: > http://gcc.gnu.org/ml/gcc/2002-05/msg01970.html Well, Qt libraries are seen by all modules. The modules itself that don't see each other. This is a pretty murky area for the Gnu loader, unfortunately. > Well, if it is only a g++ problem on the Gnu system, I can use the "setdlopenflags" workaround. I just have not tested on other systems like Windows. Looks like that it will work there. [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From meine at kogs1.informatik.uni-hamburg.de Mon Aug 22 15:33:51 2005 From: meine at kogs1.informatik.uni-hamburg.de (Hans Meine) Date: Mon, 22 Aug 2005 15:33:51 +0200 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) In-Reply-To: References: <200508220002.07595.hans_meine@gmx.net> Message-ID: <200508221533.52389.meine@kogs.informatik.uni-hamburg.de> Hi again! On Monday 22 August 2005 02:47, David Abrahams wrote: > > I am trying to do something like > > > > python::class_("PythonVector", python::no_init) > > .def("__init__", python::raw_function(&createVector, 1)); > > > > But this gives the vector as first element of the args tuple to > > createVector(). > > What's wrong with that? I tried some more ways (e.g. returning None), and found out that it's MyVector &result((python::extract(args[0])())); which is not working. Your question indicates that it should be possible to initialize the object given as first parameter. If so, how should I do that? I need access to the contained C++ object, or do I have to export internal functions to python in order to set the state of the "self"-object? -- Ciao, / / /--/ / / ANS From chenu at tiscali.fr Mon Aug 22 16:40:34 2005 From: chenu at tiscali.fr (=?iso-8859-1?Q?chenu@tiscali.fr?=) Date: Mon, 22 Aug 2005 16:40:34 +0200 Subject: [C++-sig] =?iso-8859-1?q?Ublas_=26_python?= Message-ID: Hello, I'm looking for an example on ublas (vector & matrix) integration towards python; Could you provide some info or sample code. Thanks Marc ************************ ADSL JUSQU'A 8 MEGA + 3 MOIS DE TELEPHONE GRATUIT ************************ L'ultra haut d?bit ? 15EUR/mois seulement ! Et vous t?l?phonez gratuitement en France vers les postes fixes, hors num?ros sp?ciaux pendant 3 mois. Pour profiter de cette offre exceptionnelle, cliquez ici : http://register.tiscali.fr/adsl/ (voir conditions sur le site) From hans_meine at gmx.net Mon Aug 22 18:05:20 2005 From: hans_meine at gmx.net (Hans Meine) Date: Mon, 22 Aug 2005 18:05:20 +0200 Subject: [C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function) In-Reply-To: <200508221533.52389.meine@kogs.informatik.uni-hamburg.de> References: <200508220002.07595.hans_meine@gmx.net> <200508221533.52389.meine@kogs.informatik.uni-hamburg.de> Message-ID: <200508221805.20808.hans_meine@gmx.net> On Monday 22 August 2005 15:33, Hans Meine wrote: > > > But this gives the vector as first element of the args tuple to > > > createVector(). > > > > What's wrong with that? > > I tried some more ways (e.g. returning None), and found out that it's > > MyVector &result((python::extract(args[0])())); > > which is not working. Your question indicates that it should be possible > to initialize the object given as first parameter. If so, how should I do > that? I need access to the contained C++ object, or do I have to export > internal functions to python in order to set the state of the > "self"-object? Actually, I don't understand what kind of object I get in args[0]. Obviously, this corresponds to the "self"-argument of python __init__ functions. Naively, I would expect that it carries some kind of default-constructed C++ object (which I would like to prevent in the first place, but anyhow). But I fail to either extract<>() something useful from it, or manipulate the object through a TypeWrapper - e.g. I exported the vector's resize() function to python and do python::object result(args[0]); result.attr("resize")(size); However, I always get the same error messages - that I cannot do with a "PythonVector" what I am trying to do (extraction/call methods) because a "vigra::PythonVector" is expected, which is exactly the class wrapped with class_ as "PythonVector": | ArgumentError: Python argument types in | PythonVector.resize(PythonVector, int) | did not match C++ signature: | resize(vigra::PythonVector {lvalue}, unsigned) Maybe the "self"-object passed to the constructor is incomplete in some way? Ciao, / / /--/ / / ANS From ericjardim at gmail.com Mon Aug 22 19:53:13 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Mon, 22 Aug 2005 14:53:13 -0300 Subject: [C++-sig] Stupid question Message-ID: <432ec6c5050822105379ffc6e3@mail.gmail.com> Hi, C++ "double"s are mapped to which type in Python? [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From petrucio at hoplon.com Mon Aug 22 20:04:57 2005 From: petrucio at hoplon.com (Petrucio) Date: Mon, 22 Aug 2005 15:04:57 -0300 Subject: [C++-sig] Stupid question In-Reply-To: <432ec6c5050822105379ffc6e3@mail.gmail.com> References: <432ec6c5050822105379ffc6e3@mail.gmail.com> Message-ID: <6.0.2.0.1.20050822150240.01d9b7b0@mail.hoplon.com> Floats are always double precision in Python (so I hear), so C++ doubles and floats are mapped to Python floats. At 14:53 22/8/2005, you wrote: >Hi, >C++ "double"s are mapped to which type in Python? > >[Eric Jardim] >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From nicodemus at esss.com.br Mon Aug 22 20:07:32 2005 From: nicodemus at esss.com.br (Nicodemus) Date: Mon, 22 Aug 2005 15:07:32 -0300 Subject: [C++-sig] Stupid question In-Reply-To: <432ec6c5050822105379ffc6e3@mail.gmail.com> References: <432ec6c5050822105379ffc6e3@mail.gmail.com> Message-ID: <430A1464.2070607@esss.com.br> Hey Eric, They're mapped as Python floats. Python floats have the internal representation as doubles. HTH, Eric Jardim wrote: > Hi, > C++ "double"s are mapped to which type in Python? > > [Eric Jardim] > >------------------------------------------------------------------------ > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig > > From ericjardim at gmail.com Mon Aug 22 20:09:50 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Mon, 22 Aug 2005 15:09:50 -0300 Subject: [C++-sig] Stupid question In-Reply-To: <430A1464.2070607@esss.com.br> References: <432ec6c5050822105379ffc6e3@mail.gmail.com> <430A1464.2070607@esss.com.br> Message-ID: <432ec6c5050822110971dbff62@mail.gmail.com> 2005/8/22, Nicodemus : > > They're mapped as Python floats. Python floats have the internal > representation as doubles. > Fine, now I can sleep again :) [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant at grantgoodyear.org Mon Aug 22 23:53:37 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Mon, 22 Aug 2005 16:53:37 -0500 Subject: [C++-sig] Return policy for operator() Message-ID: <20050822215337.GB18440@bmb24.uth.tmc.edu> I have an image object that overloads operator() to handle array subscripting of the object's image data by returning a float&. How do I set the return policy for operator() in pyste? I've attached some test fragments in case anybody wants to play along at home. Thanks, Grant Goodyear -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org -------------- next part -------------- class mymat { int nx; int ny; float* data; public: mymat(int nx_, int ny_) : nx(nx_), ny(ny_) { data = new float[nx*ny]; data[0] = 1.0f; } ~mymat() { delete [] data; } inline float& operator()(const int ix, const int iy) { return *(data + ix + iy*nx); } }; -------------- next part -------------- Include("matobj.h") mymat = Class("mymat", "matobj.h") -------------- next part -------------- // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include // Using ======================================================================= using namespace boost::python; // Module ====================================================================== BOOST_PYTHON_MODULE(libpymatobj) { class_< mymat >("mymat", init< const mymat& >()) .def(init< int, int >()) .def("__call__", &mymat::operator ()) ; } From ericjardim at gmail.com Tue Aug 23 00:17:49 2005 From: ericjardim at gmail.com (Eric Jardim) Date: Mon, 22 Aug 2005 19:17:49 -0300 Subject: [C++-sig] Return policy for operator() In-Reply-To: <20050822215337.GB18440@bmb24.uth.tmc.edu> References: <20050822215337.GB18440@bmb24.uth.tmc.edu> Message-ID: <432ec6c5050822151779e4134e@mail.gmail.com> 2005/8/22, Grant Goodyear : > > I have an image object that overloads operator() to handle array > subscripting of the object's image data by returning a float&. How do I > set the return policy for operator() in pyste? > I think "return_value_policy()" will work. It is just a "float". [Eric Jardim] -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant at grantgoodyear.org Tue Aug 23 00:32:41 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Mon, 22 Aug 2005 17:32:41 -0500 Subject: [C++-sig] Return policy for operator() In-Reply-To: <432ec6c5050822151779e4134e@mail.gmail.com> References: <20050822215337.GB18440@bmb24.uth.tmc.edu> <432ec6c5050822151779e4134e@mail.gmail.com> Message-ID: <20050822223241.GC18440@bmb24.uth.tmc.edu> Eric Jardim wrote: [Mon Aug 22 2005, 05:17:49PM CDT] > 2005/8/22, Grant Goodyear : > > I think "return_value_policy()" will work. > > It is just a "float". Actually, I'm trying to ask an even dumber question. Normally I would set a return policy with a line such as: set_policy(MyMethodName,return_value_policy(copy_non_const_reference)) but when overloading operator() I'm not sure what 'MyMethodName' should be.... Thanks, Grant -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org From skottmckay at gmail.com Tue Aug 23 00:39:35 2005 From: skottmckay at gmail.com (Scott McKay) Date: Mon, 22 Aug 2005 16:39:35 -0600 Subject: [C++-sig] Return policy for operator() In-Reply-To: <20050822223241.GC18440@bmb24.uth.tmc.edu> References: <20050822215337.GB18440@bmb24.uth.tmc.edu> <432ec6c5050822151779e4134e@mail.gmail.com> <20050822223241.GC18440@bmb24.uth.tmc.edu> Message-ID: <51d01787050822153914fe8b18@mail.gmail.com> http://boost.org/libs/python/pyste/doc/renaming_and_excluding.html has some examples of the Pyste syntax for operators (I assume you're doing it in Pyste from the syntax of your question). From ndbecker2 at gmail.com Tue Aug 23 00:29:11 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 22 Aug 2005 18:29:11 -0400 Subject: [C++-sig] Ublas & python References: Message-ID: chenu at tiscali.fr wrote: > Hello, > > I'm looking for an example on ublas (vector & matrix) integration towards > python; > > Could you provide some info or sample code. Here is what I am using. Quite a bit of it is borrowed from other authors. I am only using vector for now, not matrix. Any feedback welcomed. -------------- next part -------------- A non-text attachment was scrubbed... Name: python_helpers.hpp Type: text/x-csrc Size: 606 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: uvector.cc Type: text/x-c++src Size: 17297 bytes Desc: not available URL: From ndbecker2 at gmail.com Tue Aug 23 00:30:51 2005 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 22 Aug 2005 18:30:51 -0400 Subject: [C++-sig] Ublas & python References: Message-ID: chenu at tiscali.fr wrote: > Hello, > > I'm looking for an example on ublas (vector & matrix) integration towards > python; > Oh, missed a couple of pieces: -------------- next part -------------- A non-text attachment was scrubbed... Name: c_to_r.hpp Type: text/x-c++src Size: 2452 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: r_to_c.hpp Type: text/x-c++src Size: 4458 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: strided_iterator.hpp Type: text/x-c++src Size: 1684 bytes Desc: not available URL: From grant at grantgoodyear.org Tue Aug 23 02:37:24 2005 From: grant at grantgoodyear.org (Grant Goodyear) Date: Mon, 22 Aug 2005 19:37:24 -0500 Subject: [C++-sig] Return policy for operator() In-Reply-To: <51d01787050822153914fe8b18@mail.gmail.com> References: <20050822215337.GB18440@bmb24.uth.tmc.edu> <432ec6c5050822151779e4134e@mail.gmail.com> <20050822223241.GC18440@bmb24.uth.tmc.edu> <51d01787050822153914fe8b18@mail.gmail.com> Message-ID: <20050823003724.GH7600@dst.grantgoodyear.org> Scott McKay wrote: [Mon Aug 22 2005, 05:39:35PM CDT] > http://boost.org/libs/python/pyste/doc/renaming_and_excluding.html has > some examples of the Pyste syntax for operators (I assume you're doing > it in Pyste from the syntax of your question). Cool, that worked perfectly. Thanks! -Grant- -- Grant Goodyear web: http://www.grantgoodyear.org e-mail: grant at grantgoodyear.org From ahrivera at yahoo.com Tue Aug 23 22:04:25 2005 From: ahrivera at yahoo.com (Alexis H. Rivera-Rios) Date: Tue, 23 Aug 2005 13:04:25 -0700 (PDT) Subject: [C++-sig] using a python object that implements a c++ interface in c++ Message-ID: <20050823200425.56850.qmail@web30703.mail.mud.yahoo.com> Hi, I'm trying to use python to create objects that implement a given interface and passing them to c++ functions. This is what I have: --- test.h --- template class MyFactory { public: virtual ~MyFactory() {} virtual A* CreateA() const = 0; }; struct Data { int x; }; The boost::python code: // Boost Includes ============================================================== #include #include // Includes ==================================================================== #include "test.h" // Using ======================================================================= using namespace boost::python; // Declarations ================================================================ namespace { typedef MyFactory Factory1; struct Factory1Wrap : MyFactory, wrapper > { Data* CreateA() const { //return this->get_override("CreateMissile")(); return call< Data* >(this->get_override("CreateA").ptr()); } }; }// namespace // Module ====================================================================== BOOST_PYTHON_MODULE(PysteError) { class_< Data >("Data", init< >()) .def(init< const Data& >()) .def_readwrite("x", &Data::x) ; class_< Factory1Wrap, boost::noncopyable >("Factory1", init< >()) .def("CreateA", pure_virtual(&Factory1::CreateA), return_value_policy () ) ; } The python implementation of the interface: import PysteError class PyFactory(PysteError.Factory1): def __init__(self): pass def CreateA(self): d = PysteError.Data() d.x = 1; return d factory = PyFactory(); The C++ code that tries to get the python object: // Boost Includes ============================================================== #include #include #include #include "test.h" using namespace boost::python; int main (void) { std::string fileName = "test.py"; std::string loadModule = "execfile('"+fileName+"')"; std::string factoryName = "factory"; object factory; Py_Initialize( ); try { object main_module(( handle<>(borrowed(PyImport_AddModule("__main__" ))))); object main_namespace = main_module.attr("__dict__"); handle<> ignored((PyRun_String( loadModule.c_str() , Py_single_input , main_namespace.ptr() , main_namespace.ptr()) )); factory = main_namespace["factory"]; //// IT FAILS HERE //// const MyFactory &ptr = extract< MyFactory >(factory); std::auto_ptr d (ptr.CreateA()); } catch(error_already_set) { PyErr_Print(); } Py_Finalize(); } I get the following error: TypeError: No registered converter was able to produce a C++ rvalue of type class MyFactory from this Python object of type PyFactory Can anybody please explain what does the error mean? What is the correct way to do this? Thanks, Alexis Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From allenb at vrsource.org Tue Aug 23 23:35:59 2005 From: allenb at vrsource.org (Allen Bierbaum) Date: Tue, 23 Aug 2005 16:35:59 -0500 Subject: [C++-sig] Boost.Python visibility fix for GCC 4.0 Message-ID: <430B96BF.3090506@vrsource.org> It looks like the current version of Boost.Python has a small bug when using the visibility options of gcc 4.0 (i.e. -fvisibility=hidden). I have attached a patch that will fix the problem. It looks like when the code was originally added to test for the GCC version it didn't take into account non 3.x version numbers. This patch should take care of that. Note: This bug rears its head by hiding the extern C initmodule() when you compile a Boost.Python module with "-fvisibility=hidden". Thus the module fails to import into python because the symbol is not found. Hopefully this should fix things up for everyone. -Allen -------------- next part -------------- A non-text attachment was scrubbed... Name: gcc4_visibility.patch Type: text/x-patch Size: 1722 bytes Desc: not available URL: From rwgk at yahoo.com Wed Aug 24 12:17:14 2005 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 24 Aug 2005 03:17:14 -0700 (PDT) Subject: [C++-sig] using a python object that implements a c++ interface in c++ In-Reply-To: <20050823200425.56850.qmail@web30703.mail.mud.yahoo.com> Message-ID: <20050824101714.64371.qmail@web31504.mail.mud.yahoo.com> --- "Alexis H. Rivera-Rios" wrote: > The python implementation of the interface: > import PysteError > class PyFactory(PysteError.Factory1): > def __init__(self): > pass I am not sure this is it, but you can try it in a second: Add PysteError.Factory1.__init__(self) to the constructor above. Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From Stephen.Henry at elixent.com Wed Aug 24 17:28:02 2005 From: Stephen.Henry at elixent.com (Stephen Henry) Date: Wed, 24 Aug 2005 11:28:02 -0400 Subject: [C++-sig] boost.build help Message-ID: Hi all, I'm attempting to get my head around Boost.build and using it to build my project. I've run into some trouble and was hoping that their was someone out their that could help me: I have a directory that looks like the following: root | --- inc | --- src in root I have a "project-root.jam" file containing "path-constant BOOST_ROOT : /home/henrys/boost". In src I have a Jamfile.v2 with the following: import python ; if [ python.configured ] { python-extension dfa : dfa.cpp : ${BOOST_ROOT} ../inc