From hessiess at hessiess.com Sun May 3 03:34:14 2009 From: hessiess at hessiess.com (hessiess at hessiess.com) Date: Sun, 3 May 2009 02:34:14 +0100 (BST) Subject: [C++-sig] Wrapping functions that return a raw pointer Message-ID: How can I wrap a function which returns a raw pointer? for example the following generates tonnes of errors on compile: struct test { int *get() { return new int(1); } }; BOOST_PYTHON_MODULE(test) { using namespace boost::python; class_("test") .def("get", &test::get); } Thanks From diepen at astron.nl Sun May 3 16:36:28 2009 From: diepen at astron.nl (Ger van Diepen) Date: Sun, 03 May 2009 16:36:28 +0200 Subject: [C++-sig] numpy.int32 -> double? Message-ID: <49FDC80C020000A900007D11@server7.nfra.nl> We also had problems with passing numpy scalars to C++ using Boost (1.35 and before). Sometimes it succeeded, sometimes it failed depending on the data type and if your are on a 32-bit or 64-bit system. AFAIK Boost does not handle numpy scalar data types, so you have to do the conversion yourself. We've written such conversion functions (see pyrap.googlecode.com). Cheers, Ger van Diepen >>> Bruce Sherwood 04/28/09 7:52 PM >>> I'm not sure this is the right forum for my question; it's quite possible that this is a numpy question. VPython (vpython.org) is the name of Python plus the 3D Visual module, which is mostly written in C++ and connected to Python using the Boost libraries. Visual imports numpy. When I build Visual for Python 2.6 and numpy 1.3.0, I get a failure on something that works on Python 2.5 with numpy 1.2.1. There is a vector(double,double,double) class in Visual which now fails if handed numpy.int32 arguments (works fine with numpy.float64 arguments). I was using Boost 1.35 with Python 2.5 and am using Boost 1.38 with Python 2.6. Any ideas or suggestions? Thanks. Bruce Sherwood From renatox at gmail.com Sun May 3 21:27:10 2009 From: renatox at gmail.com (Renato Araujo) Date: Sun, 3 May 2009 16:27:10 -0300 Subject: [C++-sig] Wrapping functions that return a raw pointer In-Reply-To: References: Message-ID: <95291a80905031227v417de992ja262d0bbd93c3b0f@mail.gmail.com> take a look in this documentation about return police and ResultConverterGenerator. http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/reference.html#models_of_call_policies For this specific case you can use this one: http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/manage_new_object.html BR On Sat, May 2, 2009 at 10:34 PM, wrote: > How can I wrap a function which returns a raw pointer? for example the > following generates tonnes of errors on compile: > > struct test > { > ? ?int *get() > ? ?{ > ? ? ? ?return new int(1); > ? ?} > }; > > BOOST_PYTHON_MODULE(test) > { > ? ?using namespace boost::python; > > ? ?class_("test") > ? ? ? ?.def("get", &test::get); > } > > Thanks > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Renato Araujo Oliveira Filho From pcc482719 at gmail.com Mon May 4 17:43:48 2009 From: pcc482719 at gmail.com (Peter C. Chapin) Date: Mon, 4 May 2009 15:43:48 +0000 (UTC) Subject: [C++-sig] Building Boost.Python against Stackless Python Message-ID: Hello! I'm interested in building the Boost/Python integration support using Boost 1.38, Visual C++ v9 (2008 version), and Stackless Python 2.6.1. I'm on a Windows XP machine. Currently the build fails with an error about not being able to find stackless.h as included from C:\Python26\include\Python.h. In fact, stackless.h is in C:\Python26\include\Stackless. I assume I need to inform the Boost build system to search this additional include directory. However, I'm not clear on how to do that (I'm new to Boost). I searched the archive of this group and found a posting from August of 2008 on exactly this issue. However, there was no reply. I'm hoping I'll be a bit luckier. :-) Thanks for any advice you can give. Peter From rogeeff at gmail.com Tue May 5 08:59:45 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Tue, 5 May 2009 06:59:45 +0000 (UTC) Subject: [C++-sig] how to deep copy boost python object Message-ID: This looks like trivial question from FAQ, but I can seem to fond the answer. Any pointers? Genandiy From sipickles at googlemail.com Tue May 5 11:29:09 2009 From: sipickles at googlemail.com (Simon Pickles) Date: Tue, 05 May 2009 10:29:09 +0100 Subject: [C++-sig] Extended python system needs access to cPickle in c++ Message-ID: <4A0006E5.4070602@googlemail.com> Hi, I have an app with a python core, then c++ extension modules. I'd like to be able to use cPickle to pack structures, especially boost::python::tuples, in c++. Is there a way I can expose a python module in the c++ extensions? I thought about passing a module as an arg to a c++ function, as a boost::python::object: // cModule void DoStuff(object pickleModule) { tuple t = make_tuple("Spam",42); object pickleDumps = pickleModule.attr("dumps"); object s = pickleDumps(t); // Send s to other process } # python import cModule import cPickle cModule.DoStuff(cPickle) # Am I barking up the wrong tree? Many thanks Simon From hessiess at hessiess.com Tue May 5 11:54:08 2009 From: hessiess at hessiess.com (hessiess at hessiess.com) Date: Tue, 5 May 2009 10:54:08 +0100 (BST) Subject: [C++-sig] Wrapping functions that return a raw pointer In-Reply-To: <95291a80905031227v417de992ja262d0bbd93c3b0f@mail.gmail.com> References: <95291a80905031227v417de992ja262d0bbd93c3b0f@mail.gmail.com> Message-ID: <1ba66d9635e00804969a0a1181d35011.squirrel@www.hessiess.dyndns.org> Thanks > take a look in this documentation about return police and > ResultConverterGenerator. > > > http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/reference.html#models_of_call_policies > > For this specific case you can use this one: > http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/manage_new_object.html > > > BR > > On Sat, May 2, 2009 at 10:34 PM, wrote: >> How can I wrap a function which returns a raw pointer? for example the >> following generates tonnes of errors on compile: >> >> struct test >> { >> ? ?int *get() >> ? ?{ >> ? ? ? ?return new int(1); >> ? ?} >> }; >> >> BOOST_PYTHON_MODULE(test) >> { >> ? ?using namespace boost::python; >> >> ? ?class_("test") >> ? ? ? ?.def("get", &test::get); >> } >> >> Thanks >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > > -- > Renato Araujo Oliveira Filho > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From ndbecker2 at gmail.com Tue May 5 13:08:10 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 05 May 2009 07:08:10 -0400 Subject: [C++-sig] how to deep copy boost python object References: Message-ID: Gennadiy Rozental wrote: > This looks like trivial question from FAQ, but I can seem to fond the > answer. > > Any pointers? > > Genandiy Maybe overide __copy__? From wladwig at wdtinc.com Tue May 5 16:53:28 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Tue, 5 May 2009 09:53:28 -0500 Subject: [C++-sig] Extended python system needs access to cPickle in c++ In-Reply-To: <4A0006E5.4070602@googlemail.com> References: <4A0006E5.4070602@googlemail.com> Message-ID: <765CBD9053EA2B438625895F30D1856F02262A53B9@storm.wdtinc.com> You can import python modules in C++ using the import function. See here: http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/import.html You can also make your C++ extension classes 'pickleable' using boost python's pickle suite: http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/pickle.html Bill -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Simon Pickles Sent: Tuesday, May 05, 2009 4:29 AM To: cplusplus-sig at python.org Subject: [C++-sig] Extended python system needs access to cPickle in c++ Hi, I have an app with a python core, then c++ extension modules. I'd like to be able to use cPickle to pack structures, especially boost::python::tuples, in c++. Is there a way I can expose a python module in the c++ extensions? I thought about passing a module as an arg to a c++ function, as a boost::python::object: // cModule void DoStuff(object pickleModule) { tuple t = make_tuple("Spam",42); object pickleDumps = pickleModule.attr("dumps"); object s = pickleDumps(t); // Send s to other process } # python import cModule import cPickle cModule.DoStuff(cPickle) # Am I barking up the wrong tree? Many thanks Simon _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From rogeeff at gmail.com Tue May 5 22:39:28 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Tue, 5 May 2009 20:39:28 +0000 (UTC) Subject: [C++-sig] how to deep copy boost python object References: Message-ID: Neal Becker gmail.com> writes: > > Gennadiy Rozental wrote: > > > This looks like trivial question from FAQ, but I can seem to fond the > > answer. > > > > Any pointers? > > > > Genandiy > > Maybe overide __copy__? How is it involved? Here is an example: bp::object o = foo(); // Here i want to make deep copy of o // bp::object o_copy = o is not correct // what I need is something like: bp::object o_copy = bp::deep_copy( o ) Gennadiy From jeremykie at gmail.com Wed May 6 19:23:56 2009 From: jeremykie at gmail.com (Jeremy Kie) Date: Wed, 6 May 2009 11:23:56 -0600 Subject: [C++-sig] wrapping objects which inherit from std::map Message-ID: Hi, I have the following: class foo : public std::map { } BOOST_PYTHON_MODULE(foo_ext) { using namespace boost::python; class_>("foo"); } The compiler complains that template arguments 1 and 2 are invalid. I'm certain my syntax is the problem. Can't anyone shed some light and help me correct my syntax? Thanks, Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed May 6 19:29:59 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 06 May 2009 13:29:59 -0400 Subject: [C++-sig] wrapping objects which inherit from std::map In-Reply-To: References: Message-ID: <4A01C917.3090800@sympatico.ca> Jeremy Kie wrote: > Hi, > > I have the following: > > class foo : public std::map { > } You lack a semicolon here. (I also don't think it's a good idea to derive from standard containers, but that is an entirely different subject). > > BOOST_PYTHON_MODULE(foo_ext) > { > using namespace boost::python; > class_>("foo"); There are three errors here, let's start with the simplest: You use '>>' in this line, which is a single token. You need to insert a whitespace there to make it two tokens, e.g. '> >'. Next, you use 'std::map' where you ought to use a type (such as 'std::map'. Finally, you only can declare bases that are themselves already exported to python via class_, so you need to start by exporting the base type std::map prior to 'foo'. Hope this helps, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jeremykie at gmail.com Wed May 6 19:44:18 2009 From: jeremykie at gmail.com (Jeremy Kie) Date: Wed, 6 May 2009 11:44:18 -0600 Subject: [C++-sig] wrapping objects which inherit from std::map In-Reply-To: <4A01C917.3090800@sympatico.ca> References: <4A01C917.3090800@sympatico.ca> Message-ID: Thanks for the direction Stefan. Apologies for the typos. What I was missing was the declaration of the "std::map" prior to my foo declaration. Yes, I agree with you regarding derivation from standard containers. My portion of the project is written in python, I'm trying to work with libraries written by another member of the team. With the addition of the "std::map" declaration, my compiler errors disappeared. Thanks, Jeremy On Wed, May 6, 2009 at 11:29 AM, Stefan Seefeld wrote: > Jeremy Kie wrote: > >> Hi, >> >> I have the following: >> >> class foo : public std::map { >> } >> > > You lack a semicolon here. (I also don't think it's a good idea to derive > from standard containers, but that is an entirely different subject). > > >> BOOST_PYTHON_MODULE(foo_ext) >> { >> using namespace boost::python; >> class_>("foo"); >> > > There are three errors here, let's start with the simplest: > > You use '>>' in this line, which is a single token. You need to insert a > whitespace there to make it two tokens, e.g. '> >'. > Next, you use 'std::map' where you ought to use a type (such as > 'std::map'. > Finally, you only can declare bases that are themselves already exported to > python via class_, so you need to start by exporting the base type > std::map prior to 'foo'. > > Hope this helps, > Stefan > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From seefeld at sympatico.ca Wed May 6 19:56:26 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Wed, 06 May 2009 13:56:26 -0400 Subject: [C++-sig] wrapping objects which inherit from std::map In-Reply-To: References: <4A01C917.3090800@sympatico.ca> Message-ID: <4A01CF4A.7080502@sympatico.ca> Jeremy Kie wrote: > > With the addition of the "std::map" declaration, my compiler errors > disappeared. That is very curious, as Python only discovers whether the base class has been exported or not at runtime. Thus it can't possibly result in a compiler error. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From jeremykie at gmail.com Wed May 6 20:02:23 2009 From: jeremykie at gmail.com (Jeremy Kie) Date: Wed, 6 May 2009 12:02:23 -0600 Subject: [C++-sig] wrapping objects which inherit from std::map In-Reply-To: <4A01CF4A.7080502@sympatico.ca> References: <4A01C917.3090800@sympatico.ca> <4A01CF4A.7080502@sympatico.ca> Message-ID: I think you are right. I removed the declaration of the std::map and it compiled without any errors. The problem must have been related to the missing template types. regards, Jeremy On Wed, May 6, 2009 at 11:56 AM, Stefan Seefeld wrote: > Jeremy Kie wrote: > >> >> With the addition of the "std::map" declaration, my compiler errors >> disappeared. >> > > That is very curious, as Python only discovers whether the base class has > been exported or not at runtime. Thus it can't possibly result in a compiler > error. > > Regards, > > Stefan > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeremykie at gmail.com Thu May 7 00:10:22 2009 From: jeremykie at gmail.com (Jeremy Kie) Date: Wed, 6 May 2009 16:10:22 -0600 Subject: [C++-sig] boost python class inherits boost::asio::ip::tcp::socket Message-ID: Hello, The library I am attempting to extend Python to contains a class which inherits from boost::asio::ip::tcp::socket. class tcp_client_socket : public boost::asio::ip::tcp::socket { // class members and functions go here... }; My question is whether or not it is a good idea to wrap this. My naive approach would be to something like: BOOST_PYTHON_MODULE(tcp_client_socket_ext) { using namespace boost::python; class_ >("tcp_client_socket"); } I did an initial compile and received many compiler errors. If anyone has done this before, what is the correct way to wrap such an object. Any help is greatly appreciated. Regards, -Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From eudoxos at arcig.cz Thu May 7 19:21:21 2009 From: eudoxos at arcig.cz (=?windows-1252?Q?V=E1clav_=8Amilauer?=) Date: Thu, 07 May 2009 19:21:21 +0200 Subject: [C++-sig] hijacking getattr/setattr Message-ID: <4A031891.1070700@arcig.cz> Hello, I have wrapper c++ classes that are exposed to python that wrap "real" c++ classes with data. Wrapper classes have some attributes that .def'ed and .add_property'd in the glue code. Wrapped classes have also attributes that are registered by name (for serialization purposes) and I can retrieve them. To be able to get both wrapper attributes and attributes of the wrapped class, I use getitem/setitem for the latter ones. That makes the python code a bit ugly and difficult to read: b=O.bodies[44] b.geom['radius']=5 ## .geom returns wrapped class holding geometry attributes, is .add_property'ed b.phys['mass']=8 ## .phys returns wrapped class holding physical attributes, is .add_property'ed print b['id'] ## get an attribute that exists as such in the wrapped class I would like to unify both approaches so that if I say b.id, the pyBody object (wrapping a shared_ptr object) will first look if the attribute 'id' is within attributes of the wrapper class; return it if it is, look in the wrapped object attributes if it is not; return the wrapped object attribute of that name if it exists, otherwise throw. (The same for b.geom.radius, b.phys.mass) I simulated that with pure python code (attached), but it is not clear to me how to put this in boost::python. Can I get some pointers? I can overrider __getattr__ and __setattr__ of the wrapper class, but I don't know how to simulate the default behavior of getattr/setattr, once the key wasn't found in the wrapped class, for example. Thanks, Vaclav From eudoxos at arcig.cz Thu May 7 23:38:59 2009 From: eudoxos at arcig.cz (=?UTF-8?Q?V=C3=A1clav_=C5=A0milauer?=) Date: Thu, 07 May 2009 23:38:59 +0200 Subject: [C++-sig] hijacking getattr/setattr In-Reply-To: <4A031891.1070700@arcig.cz> References: <4A031891.1070700@arcig.cz> Message-ID: <1241732339.4433.1.camel@flux> Forgotten attachment (sorry): python hijack. -------------- next part -------------- A non-text attachment was scrubbed... Name: a.py Type: text/x-python Size: 1276 bytes Desc: not available URL: From rwgk at yahoo.com Sun May 10 05:13:37 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 9 May 2009 20:13:37 -0700 (PDT) Subject: [C++-sig] how to deep copy boost python object In-Reply-To: References: Message-ID: <377808.11921.qm@web111416.mail.gq1.yahoo.com> A comprehensive approach is to make the object picklable. As a side-effect, copy.deepcopy() will also work. http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/pickle.html (In many cases - in my experience - making an object picklable is very simple.) ----- Original Message ---- From: Gennadiy Rozental To: cplusplus-sig at python.org Sent: Monday, May 4, 2009 11:59:45 PM Subject: [C++-sig] how to deep copy boost python object This looks like trivial question from FAQ, but I can seem to fond the answer. Any pointers? Genandiy From security at BankofAmerica.com Fri May 8 16:44:59 2009 From: security at BankofAmerica.com (security at BankofAmerica.com) Date: Fri, 08 May 2009 10:44:59 -0400 Subject: [C++-sig] Online Banking Alert Message-ID: An HTML attachment was scrubbed... URL: From rogeeff at gmail.com Mon May 11 07:46:32 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Mon, 11 May 2009 05:46:32 +0000 (UTC) Subject: [C++-sig] how to deep copy boost python object References: <377808.11921.qm@web111416.mail.gq1.yahoo.com> Message-ID: Ralf W. Grosse-Kunstleve yahoo.com> writes: > > > A comprehensive approach is to make the object picklable. > As a side-effect, copy.deepcopy() will also work. 1. Are you saying that copy.deepcopy does not work without object being picklable? What will happend if I try to use it for non picklable object? 2. What if object IS picklable. How will invoke deepcopy operation on bp::object? Gennadiy From Matthew.Scouten at tradingtechnologies.com Mon May 11 18:31:41 2009 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Mon, 11 May 2009 11:31:41 -0500 Subject: [C++-sig] how to deep copy boost python object In-Reply-To: References: <377808.11921.qm@web111416.mail.gq1.yahoo.com> Message-ID: <32490DFF7774554A85D65D23A9F0F9380AAB7A38@chiex01> If you make an object pickleable, you get deepcopy for free, because the deepcopy function will use a pickle-unpickle cycle as a fall back if it cannot find any other way to copy. This has the disadvantage that you must come up with a sensible pickled representation, and you pay for a round trip through a string. This is especially annoying since all c++ objects are already deepcopyable by default: just use a call copy-ctor. There is another way to tell python how to deepcopy an object: give it a __deepcopy__ function (and a __copy__ function). This is some code I got from Hans Meine a while back: #define PYTHON_ERROR(TYPE, REASON) \ { \ PyErr_SetString(TYPE, REASON); \ throw bp::error_already_set(); \ } template inline PyObject * managingPyObject(T *p) { return typename bp::manage_new_object::apply::type()(p); } template bp::object generic__copy__(bp::object copyable) { Copyable *newCopyable(new Copyable(bp::extract(copyable))); bp::object result(bp::detail::new_reference(managingPyObject(newCopyable))); bp::extract(result.attr("__dict__"))().update( copyable.attr("__dict__")); return result; } template bp::object generic__deepcopy__(bp::object copyable, bp::dict memo) { bp::object copyMod = bp::import("copy"); bp::object deepcopy = copyMod.attr("deepcopy"); Copyable *newCopyable(new Copyable(bp::extract(copyable))); bp::object result(bp::detail::new_reference(managingPyObject(newCopyable))); // HACK: copyableId shall be the same as the result of id(copyable) in Python - // please tell me that there is a better way! (and which ;-p) int copyableId = (int)(copyable.ptr()); memo[copyableId] = result; bp::extract(result.attr("__dict__"))().update( deepcopy(bp::extract(copyable.attr("__dict__"))(), memo)); return result; } To use it: class_(foo) .def("__copy__", &generic__copy__< foo >) .def("__deepcopy__", &generic__deepcopy__< foo >) .def(init< const foo & >()) This has the advantage that you can use it on any existing class that has a sensible cctor. -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of Gennadiy Rozental Sent: Monday, May 11, 2009 12:47 AM To: cplusplus-sig at python.org Subject: Re: [C++-sig] how to deep copy boost python object Ralf W. Grosse-Kunstleve yahoo.com> writes: > > > A comprehensive approach is to make the object picklable. > As a side-effect, copy.deepcopy() will also work. 1. Are you saying that copy.deepcopy does not work without object being picklable? What will happend if I try to use it for non picklable object? 2. What if object IS picklable. How will invoke deepcopy operation on bp::object? Gennadiy _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From bruce.sherwood at gmail.com Wed May 13 03:38:43 2009 From: bruce.sherwood at gmail.com (Bruce Sherwood) Date: Tue, 12 May 2009 19:38:43 -0600 Subject: [C++-sig] Manual converter numpy.int32 -> double Message-ID: Some time ago I wrote that I was having trouble installing a manual converter to handle numpy.int32 -> double, something that used to work automatically but no longer does. I got crucial help from David Scherer (the original creator of VPython). Just in case someone might be interested, here is a routine that works. struct double_from_int { double_from_int() { py::converter::registry::push_back( &convertible, &construct, py::type_id()); } static void* convertible( PyObject* obj) { PyObject* newobj = PyNumber_Float(obj); if (!PyString_Check(obj) && newobj) { Py_DECREF(newobj); return obj; } else { if (newobj) { Py_DECREF(newobj); } PyErr_Clear(); return 0; } } static void construct( PyObject* _obj, py::converter::rvalue_from_python_stage1_data* data) { PyObject* newobj = PyNumber_Float(_obj); //void* storage = ( // (py::converter::rvalue_from_python_storage*) // data)->storage.bytes; //*(double*)(storage) = py::extract(newobj); double* storage = (double*)( (py::converter::rvalue_from_python_storage*) data)->storage.bytes; *storage = py::extract(newobj); Py_DECREF(newobj); data->convertible = storage; } }; Bruce Sherwood -------------- next part -------------- An HTML attachment was scrubbed... URL: From bmiller at soe.sony.com Wed May 13 23:43:27 2009 From: bmiller at soe.sony.com (Brandon) Date: Wed, 13 May 2009 21:43:27 +0000 (UTC) Subject: [C++-sig] [boost::python] Exposing a pointer to a vector to Python. Message-ID: All, I'm currently exposing much of our C++ API to Python and have had much success with everything up to here. I'm running into issues trying to expose a pointer to a vector which holds pointers to instances of a class. The question is: is there more I have to do to export a pointer to a vector of a class type we've defined? Or is there something simpler that I'm not seeing? I've tried exposing a pointer to a vector, but that didn't turn out well. I was getting value_type undefined errors and could not find any postings on them. Perhaps that way was correct but I didn't not have the whole piece in place. Thanks in advance! CODE: (all of my code and sample types replace our actual data types) ------------------------------------------------------------------------- C++ ------- class sample { public: std::vector *vec; }; class_ >("std_vector_Derived") .def(vector_indexing_suite()) ; class_("sample") .def_readwrite("vec", &sample::vec) ; Python -------- inst = EXPOSED_MODULE.EXPOSED_FUNCT( ) #EXPOSED_MODULE/FUNCT are replacements for the real name... #inst is an instance of "sample" returned from a exposed c++ function after it was populated it with data. print inst.vec[0] #Assume vector was populated from C++ side and verified to be populated in C++. #Problem occurs here because of type... STDERR (PYTHON) --------------- TypeError: No to_python(by-value) converter found for C++ type: class std::vector > * From hansroessler at yahoo.de Thu May 14 15:15:30 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Thu, 14 May 2009 06:15:30 -0700 (PDT) Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python Message-ID: <130401.91415.qm@web24608.mail.ird.yahoo.com> Hello, how can I wrap the following overloaded operator+ using boost.python? The code as is fails with >... >pytest.cpp: In function ?void init_module_pytest()?: >pytest.cpp:19: error: expected primary-expression before ?(? token >... If I try ".def(self+B())" instead of ".def(self+other())", the error is >... >pytest.cpp: In function ?void init_module_pytest()?: >pytest.cpp:17: error: no matching function for call to ?B::B()? >... best wishes Hans pytest.cpp: #include using namespace boost::python; class A{ public: }; class B{ public: B(int i){}; }; int operator+(const A& a,const B& b){return 42;}; BOOST_PYTHON_MODULE(pytest) { class_("A") .def(self+other()) //.def(self+B()) //line 17 ; class_("B",init) //line 19 ; } From magnus at clara.is Thu May 14 20:41:02 2009 From: magnus at clara.is (=?ISO-8859-1?Q?Magn=FAs_Bergur_Magn=FAsson?=) Date: Thu, 14 May 2009 18:41:02 +0000 Subject: [C++-sig] Question regarding importing libraries to weave Message-ID: <20504a380905141141j4ac4793ej306603590deb21d@mail.gmail.com> Hello, My name is Magnus and I am working as a software developer for a company in Iceland. We use weave inline with python to boost our processing capacity. However there is one factor that is limiting us. We cannot figure out how to import libraries to Weave such as just or , what is the right procedure for that? Also, what is the most effective tool for text processing in python? We have been using weave inline and moving char by char but is there a more effective way and could string.h speed things up? Regards, Magnus Magnusson -------------- next part -------------- An HTML attachment was scrubbed... URL: From pbloom at crystald.com Thu May 14 23:01:18 2009 From: pbloom at crystald.com (Philip Bloom) Date: Thu, 14 May 2009 14:01:18 -0700 Subject: [C++-sig] Trouble with custom container class Message-ID: <2DEFEB25B65B1D4C962D79E3CCBAFC7F06E883FF@mpkexc01.eidos.com> Hello, I'm having some issues with retrieving objects from a custom container class. The objects in the container are otherwise wrapped objects (PythonDTPNodeHandle *) that the python wrapper knows how to convert, but what I get back from the container with __getitem__ seems to not know how to convert it. I suspect that I'm doing something wrong on what I'm feeding Py++ and thus the generated wrapping is bad, but I don't see anything wrong with the final wrapping for getitem or operator[]. I've no idea why it wouldn't be able to convert, for this specific usage. Any advise/help would be well welcome. I've included the whole wrapper at the bottom. Example use: Node=Test.getRootNode() #Returns a PythonDTPNodeHandle * object, which is converted into a PythonDTPNodeHandle refrence in python. #print Node - Which is wrapped fine, converting naturally. array=test.getCDCArray() #Returns the container object. This is a wrapped cdc::array * object. #help(array) - Verified Python sees it as cdcArray(super), the container object print "Array has: %s elements"%array.size() # Array is empty node.GetItemChildren(array) #Function call passed the Array. The function expects a cdc::array * object. print "Array has: %s elements"%array.size() # Array has 125 elements. print array[0] #Causes error anode=array.__getitem__(0) #Causes error. Output: Array has: 0 elements Array has: 125 elements Traceback (most recent call last): File "D:\stgame\cdc\tools\cdcPython\DTPXMLNode\example.py", line 43, in print array[0] TypeError: No to_python (by-value) converter found for C++ type: class PythonDTPNodeHandle * The getitem wrapped: { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::PythonDTPNodeHandle * & ( exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) ; super_exposer.def( "__getitem__" , __getitem___function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] ) , ( bp::arg("i") ) , bp::return_internal_reference< >() ); } My Python Wrapper: // This file has been generated by Py++. //CDC DTP Autogenerated Python Interface #include "boost/python.hpp" #include "pythondtpscriptinterfacewrapper.h" #include "cdcsys/array.h" namespace bp = boost::python; struct PythonDTPInterface_wrapper : PythonDTPInterface, bp::wrapper< PythonDTPInterface > { PythonDTPInterface_wrapper(PythonDTPInterface const & arg ) : PythonDTPInterface( arg ) , bp::wrapper< PythonDTPInterface >(){ // copy constructor } PythonDTPInterface_wrapper(char const * szGameRoot ) : PythonDTPInterface( szGameRoot ) , bp::wrapper< PythonDTPInterface >(){ // constructor } PythonDTPInterface_wrapper(char const * szGameRoot, char const * datFile, char const * dtpFile ) : PythonDTPInterface( szGameRoot, datFile, dtpFile ) , bp::wrapper< PythonDTPInterface >(){ // constructor } virtual void NotifyDATFileChanged( char const * pDATItemPath ) { if( bp::override func_NotifyDATFileChanged = this->get_override( "NotifyDATFileChanged" ) ) func_NotifyDATFileChanged( pDATItemPath ); else this->PythonDTPInterface::NotifyDATFileChanged( pDATItemPath ); } void default_NotifyDATFileChanged( char const * pDATItemPath ) { PythonDTPInterface::NotifyDATFileChanged( pDATItemPath ); } }; BOOST_PYTHON_MODULE(DTPScriptInterface){ { //::PythonDTPInterface typedef bp::class_< PythonDTPInterface_wrapper > PythonDTPInterface_exposer_t; PythonDTPInterface_exposer_t PythonDTPInterface_exposer = PythonDTPInterface_exposer_t( "PythonDTPInterface", bp::init< char const * >(( bp::arg("szGameRoot") )) ); bp::scope PythonDTPInterface_scope( PythonDTPInterface_exposer ); bp::implicitly_convertible< char const *, PythonDTPInterface >(); PythonDTPInterface_exposer.def( bp::init< char const *, char const *, char const * >(( bp::arg("szGameRoot"), bp::arg("datFile"), bp::arg("dtpFile") )) ); { //::PythonDTPInterface::DumbTestFunction typedef int ( ::PythonDTPInterface::*DumbTestFunction_function_type )( ) ; PythonDTPInterface_exposer.def( "DumbTestFunction" , DumbTestFunction_function_type( &::PythonDTPInterface::DumbTestFunction ) ); } { //::PythonDTPInterface::GetRootNode typedef ::PythonDTPNodeHandle * ( ::PythonDTPInterface::*GetRootNode_function_type )( ) ; PythonDTPInterface_exposer.def( "GetRootNode" , GetRootNode_function_type( &::PythonDTPInterface::GetRootNode ) , bp::return_value_policy< bp::manage_new_object >() ); } { //::PythonDTPInterface::NotifyDATFileChanged typedef void ( ::PythonDTPInterface::*NotifyDATFileChanged_function_type )( char const * ) ; typedef void ( PythonDTPInterface_wrapper::*default_NotifyDATFileChanged_function_type )( char const * ) ; PythonDTPInterface_exposer.def( "NotifyDATFileChanged" , NotifyDATFileChanged_function_type(&::PythonDTPInterface::NotifyDATFileC hanged) , default_NotifyDATFileChanged_function_type(&PythonDTPInterface_wrapper:: default_NotifyDATFileChanged) , ( bp::arg("pDATItemPath") ) ); } { //::PythonDTPInterface::OpenDATFile typedef bool ( ::PythonDTPInterface::*OpenDATFile_function_type )( char const *,char const *,bool ) ; PythonDTPInterface_exposer.def( "OpenDATFile" , OpenDATFile_function_type( &::PythonDTPInterface::OpenDATFile ) , ( bp::arg("datFilenameAndPath"), bp::arg("dtpFilenameAndPath"), bp::arg("bSavePrevious")=(bool)(true) ) ); } { //::PythonDTPInterface::Release typedef void ( ::PythonDTPInterface::*Release_function_type )( ) ; PythonDTPInterface_exposer.def( "Release" , Release_function_type( &::PythonDTPInterface::Release ) ); } { //::PythonDTPInterface::SaveDATFile typedef void ( ::PythonDTPInterface::*SaveDATFile_function_type )( ) ; PythonDTPInterface_exposer.def( "SaveDATFile" , SaveDATFile_function_type( &::PythonDTPInterface::SaveDATFile ) ); } { //::PythonDTPInterface::getCDCArray typedef ::cdc::Array< PythonDTPNodeHandle* > * ( ::PythonDTPInterface::*getCDCArray_function_type )( ) ; PythonDTPInterface_exposer.def( "getCDCArray" , getCDCArray_function_type( &::PythonDTPInterface::getCDCArray ) , bp::return_value_policy< bp::manage_new_object >() ); } { //::PythonDTPInterface::instantiate typedef void ( ::PythonDTPInterface::*instantiate_function_type )( ) ; PythonDTPInterface_exposer.def( "instantiate" , instantiate_function_type( &::PythonDTPInterface::instantiate ) ); } } bp::class_< PythonDTPNodeHandle, boost::noncopyable >( "PythonDTPNodeHandle", bp::no_init ) .def( "AddChild" , (::PythonDTPNodeHandle * ( ::PythonDTPNodeHandle::* )( char const * ) )( &::PythonDTPNodeHandle::AddChild ) , ( bp::arg("szName") ) , bp::return_value_policy< bp::manage_new_object >() ) .def( "DumbNodeTestFunction" , (int ( ::PythonDTPNodeHandle::* )( ) )( &::PythonDTPNodeHandle::DumbNodeTestFunction ) ) .def( "GetChild" , (::PythonDTPNodeHandle * ( ::PythonDTPNodeHandle::* )( char const * ) )( &::PythonDTPNodeHandle::GetChild ) , ( bp::arg("szName") ) , bp::return_value_policy< bp::manage_new_object >() ) .def( "GetItemChildren" , (void ( ::PythonDTPNodeHandle::* )( ::cdc::Array< PythonDTPNodeHandle* > * ) )( &::PythonDTPNodeHandle::GetItemChildren ) , ( bp::arg("pAllItemChildren") ) ) .def( "GetName" , (char const * ( ::PythonDTPNodeHandle::* )( ) )( &::PythonDTPNodeHandle::GetName ) ) .def( "GetTagName" , (char const * ( ::PythonDTPNodeHandle::* )( ) )( &::PythonDTPNodeHandle::GetTagName ) ) .def( "GetValue" , (char const * ( ::PythonDTPNodeHandle::* )( ) )( &::PythonDTPNodeHandle::GetValue ) ) .def( "Release" , (void ( ::PythonDTPNodeHandle::* )( ) )( &::PythonDTPNodeHandle::Release ) ) .def( "RemoveChild" , (bool ( ::PythonDTPNodeHandle::* )( char const * ) )( &::PythonDTPNodeHandle::RemoveChild ) , ( bp::arg("szName") ) ) .def( "SetName" , (bool ( ::PythonDTPNodeHandle::* )( char const * ) )( &::PythonDTPNodeHandle::SetName ) , ( bp::arg("szNewName") ) ) .def( "SetValue" , (bool ( ::PythonDTPNodeHandle::* )( char const * ) )( &::PythonDTPNodeHandle::SetValue ) , ( bp::arg("szNewValue") ) ); { //::cdc::ArrayImpl< PythonDTPNodeHandle* > typedef bp::class_< cdc::ArrayImpl< PythonDTPNodeHandle* > > super_exposer_t; super_exposer_t super_exposer = super_exposer_t( "super", bp::init< cdc::MemTag >(( bp::arg("tag") )) ); bp::scope super_scope( super_exposer ); bp::implicitly_convertible< cdc::MemTag, cdc::ArrayImpl< PythonDTPNodeHandle* > >(); super_exposer.def( bp::init< cdc::ArrayImpl< PythonDTPNodeHandle* > const & >(( bp::arg("x") )) ); { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::capacity typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::cdc::uint32 ( exported_class_t::*capacity_function_type )( ) const; super_exposer.def( "capacity" , capacity_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::capacity ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::clear typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*clear_function_type )( ) ; super_exposer.def( "clear" , clear_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::clear ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::empty typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef bool ( exported_class_t::*empty_function_type )( ) const; super_exposer.def( "empty" , empty_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::empty ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator= typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::cdc::ArrayImpl< PythonDTPNodeHandle* > & ( exported_class_t::*assign_function_type )( ::cdc::ArrayImpl< PythonDTPNodeHandle* > const & ) ; super_exposer.def( "assign" , assign_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator= ) , ( bp::arg("x") ) , bp::return_self< >() ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::PythonDTPNodeHandle * & ( exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) ; super_exposer.def( "__getitem__" , __getitem___function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] ) , ( bp::arg("i") ) , bp::return_internal_reference< >() ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::PythonDTPNodeHandle * const & ( exported_class_t::*__getitem___function_type )( ::cdc::uint32 ) const; super_exposer.def( "__getitem__" , __getitem___function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::operator[] ) , ( bp::arg("i") ) , bp::return_value_policy< bp::copy_const_reference >() ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::pop_back typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*pop_back_function_type )( ) ; super_exposer.def( "pop_back" , pop_back_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::pop_back ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::push_back typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*push_back_function_type )( ::PythonDTPNodeHandle * const & ) ; super_exposer.def( "push_back" , push_back_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::push_back ) , ( bp::arg("val") ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::reserve typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*reserve_function_type )( ::cdc::uint32 ) ; super_exposer.def( "reserve" , reserve_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::reserve ) , ( bp::arg("n") ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::shrink_to_size typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*shrink_to_size_function_type )( ) ; super_exposer.def( "shrink_to_size" , shrink_to_size_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::shrink_to_size ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::size typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef ::cdc::uint32 ( exported_class_t::*size_function_type )( ) const; super_exposer.def( "size" , size_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::size ) ); } { //::cdc::ArrayImpl< PythonDTPNodeHandle* >::swap typedef cdc::ArrayImpl< PythonDTPNodeHandle* > exported_class_t; typedef void ( exported_class_t::*swap_function_type )( ::cdc::ArrayImpl< PythonDTPNodeHandle* > & ) ; super_exposer.def( "swap" , swap_function_type( &::cdc::ArrayImpl< PythonDTPNodeHandle* >::swap ) , ( bp::arg("x") ) ); } } { //::cdc::Array< PythonDTPNodeHandle* > typedef bp::class_< cdc::Array< PythonDTPNodeHandle* >, bp::bases< cdc::ArrayImpl< PythonDTPNodeHandle* > > > cdcArray_exposer_t; cdcArray_exposer_t cdcArray_exposer = cdcArray_exposer_t( "cdcArray", bp::init< cdc::MemTag >(( bp::arg("tag") )) ); bp::scope cdcArray_scope( cdcArray_exposer ); bp::implicitly_convertible< cdc::MemTag, cdc::Array< PythonDTPNodeHandle* > >(); } } ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From walter at mathematik.hu-berlin.de Fri May 15 11:02:23 2009 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Fri, 15 May 2009 11:02:23 +0200 Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python In-Reply-To: <130401.91415.qm@web24608.mail.ird.yahoo.com> References: <130401.91415.qm@web24608.mail.ird.yahoo.com> Message-ID: <4A0D2F9F.4000208@mathematik.hu-berlin.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hans Roessler schrieb: Hello Hans, in my experience .def(self+other) often didn't quite do what I expected. You could try something like that: int int__add__A_B(const A &lhs, const B &rhs){ return operator+(A,B); } .def("__add__", &int__add__A_B) i.e. first define a non-overloaded function int_add__A_B and then bind it to __add__ (which is the Python operator+ function). regards, Sebastian > Hello, > how can I wrap the following overloaded operator+ using boost.python? > The code as is fails with >> ... >> pytest.cpp: In function ?void init_module_pytest()?: >> pytest.cpp:19: error: expected primary-expression before ?(? token >> ... > If I try ".def(self+B())" instead of ".def(self+other())", the error is >> ... >> pytest.cpp: In function ?void init_module_pytest()?: >> pytest.cpp:17: error: no matching function for call to ?B::B()? >> ... > > best wishes > Hans > > > pytest.cpp: > > #include > using namespace boost::python; > > class A{ > public: > }; > class B{ > public: > B(int i){}; > }; > > int operator+(const A& a,const B& b){return 42;}; > > BOOST_PYTHON_MODULE(pytest) > { > class_("A") > .def(self+other()) //.def(self+B()) //line 17 > ; > class_("B",init) //line 19 > ; > } > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFKDS+f9PBA5IG0h0ARAnfLAJ9rGkoAUY9c2FUgJTIcWx+AFN1akACdHg7s MAVRLstiqwAtaf9RmDsLXko= =b8b/ -----END PGP SIGNATURE----- From sipickles at googlemail.com Fri May 15 17:40:10 2009 From: sipickles at googlemail.com (Simon Pickles) Date: Fri, 15 May 2009 16:40:10 +0100 Subject: [C++-sig] Trouble reinstalling boost Message-ID: <4A0D8CDA.7080606@googlemail.com> Hi, I had a nice build system set up on my VM ubuntu 8.10 server until I broke the VM. :) After rebuild the VM I am obviously reinstalling all the packages. Boost Python is causing me trouble. I built it from svn using bjam, boost 1_40_0. I can compile my python extension without error but when I run it the python code that uses it, I get: ImportError: libboost_python-gcc43-d-1_40.so.1.40.0: cannot open shared object file: No such file or directory I have this file on my system, and have copied it to /usr/local/lib simon at fenixurth:~/WorkingCopies/server/extended$ locate libboost_python-gcc43-d-1_40.so.1.40.0 /home/simon/source/boost/bin.v2/libs/python/build/gcc-4.3.2/debug/libboost_python-gcc43-d-1_40.so.1.40.0 /home/simon/source/boost/stage/lib/libboost_python-gcc43-d-1_40.so.1.40.0 /home/simon/WorkingCopies/server/extended/libboost_python-gcc43-d-1_40.so.1.40.0 /usr/local/lib/libboost_python-gcc43-d-1_40.so.1.40.0 Why is this not found? Thanks Simon From vdeleo at dsf.unica.it Fri May 15 22:05:38 2009 From: vdeleo at dsf.unica.it (Vincenzo De Leo) Date: Fri, 15 May 2009 22:05:38 +0200 Subject: [C++-sig] Trouble reinstalling boost In-Reply-To: <4A0D8CDA.7080606@googlemail.com> References: <4A0D8CDA.7080606@googlemail.com> Message-ID: Hi,maybe you have to do "ldconfig" before using the shared library. Vincenzo On Fri, May 15, 2009 at 5:40 PM, Simon Pickles wrote: > Hi, > > I had a nice build system set up on my VM ubuntu 8.10 server until I broke > the VM. :) After rebuild the VM I am obviously reinstalling all the > packages. > > Boost Python is causing me trouble. I built it from svn using bjam, boost > 1_40_0. I can compile my python extension without error but when I run it > the python code that uses it, I get: > > ImportError: libboost_python-gcc43-d-1_40.so.1.40.0: cannot open shared > object file: No such file or directory > > I have this file on my system, and have copied it to /usr/local/lib > > simon at fenixurth:~/WorkingCopies/server/extended$ locate > libboost_python-gcc43-d-1_40.so.1.40.0 > > /home/simon/source/boost/bin.v2/libs/python/build/gcc-4.3.2/debug/libboost_python-gcc43-d-1_40.so.1.40.0 > /home/simon/source/boost/stage/lib/libboost_python-gcc43-d-1_40.so.1.40.0 > > /home/simon/WorkingCopies/server/extended/libboost_python-gcc43-d-1_40.so.1.40.0 > /usr/local/lib/libboost_python-gcc43-d-1_40.so.1.40.0 > > > Why is this not found? > > Thanks > > Simon > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists_ravi at lavabit.com Sat May 16 03:08:08 2009 From: lists_ravi at lavabit.com (Ravi) Date: Fri, 15 May 2009 21:08:08 -0400 Subject: [C++-sig] Question regarding importing libraries to weave In-Reply-To: <20504a380905141141j4ac4793ej306603590deb21d@mail.gmail.com> References: <20504a380905141141j4ac4793ej306603590deb21d@mail.gmail.com> Message-ID: <200905152108.11885.lists_ravi@lavabit.com> On Thursday 14 May 2009 2:41:02 pm Magn?s Bergur Magn?sson wrote: > My name is Magnus and I am working as a software developer for a company in > Iceland. We use weave inline with python to boost our processing capacity. > However there is one factor that is limiting us. We cannot figure out how > to import libraries to Weave such as just or , what is > the right procedure for that? Also, what is the most effective tool for > text processing in python? We have been using weave inline and moving char > by char but is there a more effective way and could string.h speed things > up? This is not a boost.python question; I doubt we have very many users of weave here. You may have better luck asking on the numpy lists (numpy- discussion at scipy.org). Regards, Ravi From hansroessler at yahoo.de Sat May 16 11:48:36 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Sat, 16 May 2009 02:48:36 -0700 (PDT) Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python In-Reply-To: <4A0D2F9F.4000208@mathematik.hu-berlin.de> References: <130401.91415.qm@web24608.mail.ird.yahoo.com> <4A0D2F9F.4000208@mathematik.hu-berlin.de> Message-ID: <467728.69018.qm@web24610.mail.ird.yahoo.com> Thank you for suggesting the workaround. But I would like to understand _why_ the operator overloading doesn't work the Boost.Python way in my example (or what I have done wrong). It can be quite tedious to write a wrapper like __add__ for each operator and pair of classes, and I thought the ".def(self other)" syntax was implemented for exactly this purpose? Hans ----- Urspr?ngliche Mail ---- > Von: Sebastian Walter > An: Development of Python/C++ integration > Gesendet: Freitag, den 15. Mai 2009, 11:02:23 Uhr > Betreff: Re: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hans Roessler schrieb: > > Hello Hans, > > in my experience .def(self+other) often didn't quite do what I expected. > You could try something like that: > > int int__add__A_B(const A &lhs, const B &rhs){ > return operator+(A,B); > } > > .def("__add__", &int__add__A_B) > > > i.e. first define a non-overloaded function int_add__A_B and then bind it to > __add__ (which is the Python operator+ function). > > regards, > Sebastian > > > > Hello, > > how can I wrap the following overloaded operator+ using boost.python? > > The code as is fails with > >> ... > >> pytest.cpp: In function ?void init_module_pytest()?: > >> pytest.cpp:19: error: expected primary-expression before ?(? token > >> ... > > If I try ".def(self+B())" instead of ".def(self+other())", the error is > >> ... > >> pytest.cpp: In function ?void init_module_pytest()?: > >> pytest.cpp:17: error: no matching function for call to ?B::B()? > >> ... > > > > best wishes > > Hans > > > > > > pytest.cpp: > > > > #include > > using namespace boost::python; > > > > class A{ > > public: > > }; > > class B{ > > public: > > B(int i){}; > > }; > > > > int operator+(const A& a,const B& b){return 42;}; > > > > BOOST_PYTHON_MODULE(pytest) > > { > > class_("A") > > .def(self+other()) //.def(self+B()) //line 17 > > ; > > class_("B",init) //line 19 > > ; > > } > > > > > > > > _______________________________________________ > > Cplusplus-sig mailing list > > Cplusplus-sig at python.org > > http://mail.python.org/mailman/listinfo/cplusplus-sig > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.4-svn0 (GNU/Linux) > Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org > > iD8DBQFKDS+f9PBA5IG0h0ARAnfLAJ9rGkoAUY9c2FUgJTIcWx+AFN1akACdHg7s > MAVRLstiqwAtaf9RmDsLXko= > =b8b/ > -----END PGP SIGNATURE----- > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From roman.yakovenko at gmail.com Sun May 17 07:32:59 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 17 May 2009 08:32:59 +0300 Subject: [C++-sig] Trouble with custom container class In-Reply-To: <2DEFEB25B65B1D4C962D79E3CCBAFC7F06E883FF@mpkexc01.eidos.com> References: <2DEFEB25B65B1D4C962D79E3CCBAFC7F06E883FF@mpkexc01.eidos.com> Message-ID: <7465b6170905162232g73f616eds74a2d25bc8b87e72@mail.gmail.com> On Fri, May 15, 2009 at 12:01 AM, Philip Bloom wrote: > Hello, Hello. > I?m having some issues with retrieving objects from a custom container > class.? The objects in the container are otherwise wrapped objects > (PythonDTPNodeHandle *) that the python wrapper knows how to convert, but > what I get back from the container with __getitem__ seems to not know how to > convert it.? ??I suspect that I?m doing something wrong on what I?m feeding > Py++ and thus the generated wrapping is bad, but I don?t see anything wrong > with the final wrapping for getitem or operator[].? I?ve no idea why it > wouldn?t be able to convert, for this specific usage.? Any advise/help would > be well welcome.? I?ve included the whole wrapper at the bottom. Too much information. Can you create stand-alone, small and complete test case, that shows your problem? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From walter at mathematik.hu-berlin.de Mon May 18 10:17:24 2009 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Mon, 18 May 2009 10:17:24 +0200 Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python In-Reply-To: <467728.69018.qm@web24610.mail.ird.yahoo.com> References: <130401.91415.qm@web24608.mail.ird.yahoo.com> <4A0D2F9F.4000208@mathematik.hu-berlin.de> <467728.69018.qm@web24610.mail.ird.yahoo.com> Message-ID: <4A111994.9010508@mathematik.hu-berlin.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That, you will have to ask the devs. The question is however: what is quicker: wrapping 20 functions manually with copy/paste or trying to understand boost::python resp. wait for an answer from the devs. It is my impression, that you have to know a lot about boost::python to understand why something does not work as it should. If someone knows the answer, I'd be also be interested, of course ;) Hans Roessler schrieb: > Thank you for suggesting the workaround. But I would like to understand _why_ the operator overloading doesn't work the Boost.Python way in my example (or what I have done wrong). > It can be quite tedious to write a wrapper like __add__ for each operator and pair of classes, and I thought the ".def(self other)" syntax was implemented for exactly this purpose? > > Hans > > > > ----- Urspr?ngliche Mail ---- >> Von: Sebastian Walter >> An: Development of Python/C++ integration >> Gesendet: Freitag, den 15. Mai 2009, 11:02:23 Uhr >> Betreff: Re: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python >> > Hans Roessler schrieb: > > Hello Hans, > > in my experience .def(self+other) often didn't quite do what I expected. > You could try something like that: > > int int__add__A_B(const A &lhs, const B &rhs){ > return operator+(A,B); > } > > .def("__add__", &int__add__A_B) > > > i.e. first define a non-overloaded function int_add__A_B and then bind it to > __add__ (which is the Python operator+ function). > > regards, > Sebastian > > >>>> Hello, >>>> how can I wrap the following overloaded operator+ using boost.python? >>>> The code as is fails with >>>>> ... >>>>> pytest.cpp: In function void init_module_pytest(): >>>>> pytest.cpp:19: error: expected primary-expression before ( token >>>>> ... >>>> If I try ".def(self+B())" instead of ".def(self+other())", the error is >>>>> ... >>>>> pytest.cpp: In function void init_module_pytest(): >>>>> pytest.cpp:17: error: no matching function for call to B::B() >>>>> ... >>>> best wishes >>>> Hans >>>> >>>> >>>> pytest.cpp: >>>> >>>> #include >>>> using namespace boost::python; >>>> >>>> class A{ >>>> public: >>>> }; >>>> class B{ >>>> public: >>>> B(int i){}; >>>> }; >>>> >>>> int operator+(const A& a,const B& b){return 42;}; >>>> >>>> BOOST_PYTHON_MODULE(pytest) >>>> { >>>> class_("A") >>>> .def(self+other()) //.def(self+B()) //line 17 >>>> ; >>>> class_("B",init) //line 19 >>>> ; >>>> } >>>> >>>> >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFKERmU9PBA5IG0h0ARAgFMAKCDx+DGod3m8c+nE4auuR0+dZjtIQCeIXHf S6X++I+Ilw74MqtKzvYWiCo= =dcH2 -----END PGP SIGNATURE----- From roman.yakovenko at gmail.com Tue May 19 12:33:58 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 19 May 2009 13:33:58 +0300 Subject: [C++-sig] pygccxml and multidimensional arrays In-Reply-To: <7465b6170904231123x7c7fbb73j9b95aee05786c757@mail.gmail.com> References: <5A2986C73A1DCC4EB5CC1C22D82700090FD12E26@emss02m11.us.lmco.com> <7465b6170904152204q5e0381cdmb6643e3bc5de918b@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FDAB895@emss02m11.us.lmco.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF26840@emss02m11.us.lmco.com> <7465b6170904231011xf63c219ge7f398e70ff1bfbd@mail.gmail.com> <5A2986C73A1DCC4EB5CC1C22D82700090FF61E05@emss02m11.us.lmco.com> <7465b6170904231121o17cee0acm47d847328c3d1dce@mail.gmail.com> <7465b6170904231123x7c7fbb73j9b95aee05786c757@mail.gmail.com> Message-ID: <7465b6170905190333p6c1262b4hd63899b902a81179@mail.gmail.com> On Thu, Apr 23, 2009 at 9:23 PM, Roman Yakovenko wrote: > On Thu, Apr 23, 2009 at 9:21 PM, Roman Yakovenko > wrote: >> On Thu, Apr 23, 2009 at 8:17 PM, Davidson, Josh wrote: >>> I'm using information provided by pygccxml to generate Construct objects >>> (http://construct.wikispaces.com/) that are capable of reading and >>> writing to data structures stored in shared memory. ?Right now, I just >>> manually reverse the indices any time I detect an array type before I >>> generate a Construct. >> >> Okey. > > Sorry, I forgot to add, can you open bug on SourceForge project page? Josh, I think the bug is fixed now: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=1735 Can you verify this? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From james at goldwater.org.uk Tue May 19 14:40:06 2009 From: james at goldwater.org.uk (james at goldwater.org.uk) Date: Tue, 19 May 2009 13:40:06 +0100 Subject: [C++-sig] py++ and indexing_v2 Message-ID: <20090519124005.GN25013@eccehomo.vm.bytemark.co.uk> When I use py++ (1.0.0) with indexing_suite_version = 2 to wrap std::set etc, it generates code which doesn't compile out of the box. The code from the boost sandbox puts various definitions in the boost::python::indexing_v2 namespace, and the header files in boost/python/suite/indexing_v2. However, py++ generates code that assumes that the sandbox code is in the boost trunk namespace (bp::indexing) and filestructure (boost/python/suite/indexing). It's easy to either fix-up the generated code, or edit the sandbox code and merge it into trunk, but I'd rather keep to published code rather than commit the project to our own version of boost or add another step to the code generation. Is there a way of telling py++ to use the different namespace and directory? Or am I misunderstanding some things? Thanks for any help James. -- Ring the bells that still can ring... Forget your perfect offering. There is a crack in everything That's how the light gets in. From wladwig at wdtinc.com Tue May 19 17:34:49 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Tue, 19 May 2009 10:34:49 -0500 Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python In-Reply-To: <130401.91415.qm@web24608.mail.ird.yahoo.com> References: <130401.91415.qm@web24608.mail.ird.yahoo.com> Message-ID: <765CBD9053EA2B438625895F30D1856F0226436168@storm.wdtinc.com> It looks to me like you're missing a '()' next to your 'init<>' in the class wrapper for B. Try changing this: class_("B",init) //line 19 ; to this: class_("B",init()) //line 19 ; The only operator that has given me problems is the << operator. I've had pretty good success with the others. Regards, Bill -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler Sent: Thursday, May 14, 2009 8:16 AM To: cplusplus-sig at python.org Subject: [C++-sig] operator+(A, B) without B::B() default constructor in boost.python Hello, how can I wrap the following overloaded operator+ using boost.python? The code as is fails with >... >pytest.cpp: In function 'void init_module_pytest()': >pytest.cpp:19: error: expected primary-expression before '(' token >... If I try ".def(self+B())" instead of ".def(self+other())", the error is >... >pytest.cpp: In function 'void init_module_pytest()': >pytest.cpp:17: error: no matching function for call to 'B::B()' >... best wishes Hans pytest.cpp: #include using namespace boost::python; class A{ public: }; class B{ public: B(int i){}; }; int operator+(const A& a,const B& b){return 42;}; BOOST_PYTHON_MODULE(pytest) { class_("A") .def(self+other()) //.def(self+B()) //line 17 ; class_("B",init) //line 19 ; } _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From roman.yakovenko at gmail.com Tue May 19 20:24:27 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 19 May 2009 21:24:27 +0300 Subject: [C++-sig] py++ and indexing_v2 In-Reply-To: <20090519124005.GN25013@eccehomo.vm.bytemark.co.uk> References: <20090519124005.GN25013@eccehomo.vm.bytemark.co.uk> Message-ID: <7465b6170905191124l54b4d151h72a4a5e6b869e315@mail.gmail.com> On Tue, May 19, 2009 at 3:40 PM, wrote: > When I use py++ (1.0.0) with indexing_suite_version = 2 to wrap std::set etc, it generates code which doesn't compile out of the box. ?The code from the boost sandbox puts various definitions in the boost::python::indexing_v2 namespace, and the header files in boost/python/suite/indexing_v2. > > However, py++ generates code that assumes that the sandbox code is in the boost trunk namespace (bp::indexing) and filestructure (boost/python/suite/indexing). ?It's easy to either fix-up the generated code, or edit the sandbox code and merge it into trunk, but I'd rather keep to published code rather than commit the project to our own version of boost or add another step to the code generation. > > Is there a way of telling py++ to use the different namespace and directory? Not exactly. I suggest you to use current SVN version. It is pretty stable. I hope to release it pretty soon. The main reason is describe here: http://language-binding.net/pyplusplus/documentation/containers.html#indexing-suite-version-2-installation The short version: Indexing Suite V2 was reworked and now you don't need to patch Boost libraries and Py++ does all the work. > Or am I misunderstanding some things? No, the Py++ you use, assumes that you installed indexing suite V2 to the location you specified. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From terencebbr at gmail.com Wed May 20 05:15:47 2009 From: terencebbr at gmail.com (terence tan) Date: Wed, 20 May 2009 11:15:47 +0800 Subject: [C++-sig] XXX undefined error throw by python, Exception caused by get_override? Safe to ignor or cause for concern? Message-ID: <85c908b70905192015k5321a120q44e283b72f801c2c@mail.gmail.com> I am implementing a interface between my C++ class and a python class that requires the ability for the python class to have a Initialize/Update method called from C++ but still call the default methods of the original C++ class I am integrating. If no such methods are defined in the python class then the default C++ methods are called. So I approach it by writing a wrapper. Right now python is throw an exception XXX undefined error saying that the Initialize(or Update method) is undefined. I believe it is the get_override method. Am I approaching this the wrong way? The Initialize and Update function are virtual. struct BaseGameWrap : BaseGame, wrapper { void Initialize() { if (override Initialize = this->get_override("Initialize")) { BaseGame::Initialize(); #ifdef WIN32 return call(Initialize.ptr()); #else return Initialize(); #endif } // This supresses a XXX undefined error thrown by // by get_override when Initialize is not found. Unless a better way // is found to handle this. PyErr_Clear(); return BaseGame::Initialize(); } }; void exportBaseGame() { class_>("BaseGame") .def("Run",&BaseGame::Run) .def("GetComponents",&BaseGame::GetComponents,return_value_policy()) .def("Exit",&BaseGame::Exit); ; } Terence -------------- next part -------------- An HTML attachment was scrubbed... URL: From hansroessler at yahoo.de Thu May 21 15:39:58 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Thu, 21 May 2009 06:39:58 -0700 (PDT) Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS Message-ID: <759109.42277.qm@web24605.mail.ird.yahoo.com> Hello, I try to wrap a class with a function info([int arg]) that takes either zero or one argument (exact colde below). For some reason I can't get BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work. The examples at http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading and http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec only show the situation where either - the *member* function has up to three arguments with default values assigned or - three *free* functions have one to three arguments. I don't find an example where a class has several *member* functions with the same name, that take a variable number of (non-default!) arguments. My attempt below gives the error "pytest.cpp:17: error: no matching function for call to ?boost::python::class_::def(const char [5], , A_info_overloads)?" Do I have to replace the ".def("info",&A::info, ..." with something like ".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section in the tutorial? If yes, how must this function signature look like? It doesn't work like this. Hope someone can help Hans === pytest.py === #include #include using namespace boost::python; class A{ public: void info() {printf("This is an A\n");} void info(int arg) {printf("Unnecessary arg.\n");} }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1) BOOST_PYTHON_MODULE(test) { class_("A") .def("info",&A::info,A_info_overloads()) //line 17 ; } From wladwig at wdtinc.com Thu May 21 18:30:46 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Thu, 21 May 2009 11:30:46 -0500 Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS In-Reply-To: <759109.42277.qm@web24605.mail.ird.yahoo.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> Message-ID: <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> I haven't tried this myself, but I think all you need to do to wrap the member function is this: .def("info", (void(A::*)(int))0, A_info_overloads()); Hope this helps, Bill -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler Sent: Thursday, May 21, 2009 8:40 AM To: cplusplus-sig at python.org Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS Hello, I try to wrap a class with a function info([int arg]) that takes either zero or one argument (exact colde below). For some reason I can't get BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work. The examples at http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading and http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec only show the situation where either - the *member* function has up to three arguments with default values assigned or - three *free* functions have one to three arguments. I don't find an example where a class has several *member* functions with the same name, that take a variable number of (non-default!) arguments. My attempt below gives the error "pytest.cpp:17: error: no matching function for call to 'boost::python::class_::def(const char [5], , A_info_overloads)'" Do I have to replace the ".def("info",&A::info, ..." with something like ".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section in the tutorial? If yes, how must this function signature look like? It doesn't work like this. Hope someone can help Hans === pytest.py === #include #include using namespace boost::python; class A{ public: void info() {printf("This is an A\n");} void info(int arg) {printf("Unnecessary arg.\n");} }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1) BOOST_PYTHON_MODULE(test) { class_("A") .def("info",&A::info,A_info_overloads()) //line 17 ; } _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From Matthew.Scouten at tradingtechnologies.com Thu May 21 18:45:58 2009 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Thu, 21 May 2009 11:45:58 -0500 Subject: [C++-sig] variable argument numberand BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS In-Reply-To: <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> Message-ID: <32490DFF7774554A85D65D23A9F0F9380AC0994B@chiex01> Well I think that's probably the 'proper' way to do things, but I usually use the stupid-but-obvious ways. Overloaded functions: Class A { void info_1(int i){//Do Stuff} void info_2(){//Do Stuff} } class_("A") .def("info",&A::info_1) .def("info",&A::info_2) Boost::python will sort out which to call. If bp can't correctly distinguish the types, there may be surprises. (bool vs. int) Functions with defaults: Class A { void info(int i = 0){//Do Stuff} } class_("A") .def("info", &A::info, (arg('i') = 0) ) -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py thon.org] On Behalf Of William Ladwig Sent: Thursday, May 21, 2009 11:31 AM To: Development of Python/C++ integration Subject: Re: [C++-sig] variable argument numberand BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS I haven't tried this myself, but I think all you need to do to wrap the member function is this: .def("info", (void(A::*)(int))0, A_info_overloads()); Hope this helps, Bill -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler Sent: Thursday, May 21, 2009 8:40 AM To: cplusplus-sig at python.org Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS Hello, I try to wrap a class with a function info([int arg]) that takes either zero or one argument (exact colde below). For some reason I can't get BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS to work. The examples at http://www.boost.org/doc/libs/1_39_0/libs/python/doc/tutorial/doc/html/p ython/functions.html#python.overloading and http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/overloads.html#B OOST_PYTHON_FUNCTION_OVERLOADS-spec only show the situation where either - the *member* function has up to three arguments with default values assigned or - three *free* functions have one to three arguments. I don't find an example where a class has several *member* functions with the same name, that take a variable number of (non-default!) arguments. My attempt below gives the error "pytest.cpp:17: error: no matching function for call to 'boost::python::class_::def(const char [5], , A_info_overloads)'" Do I have to replace the ".def("info",&A::info, ..." with something like ".def("foo", (void(*)(int,int))0, ..." as shown in the Auto-Overloading section in the tutorial? If yes, how must this function signature look like? It doesn't work like this. Hope someone can help Hans === pytest.py === #include #include using namespace boost::python; class A{ public: void info() {printf("This is an A\n");} void info(int arg) {printf("Unnecessary arg.\n");} }; BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(A_info_overloads, info, 0,1) BOOST_PYTHON_MODULE(test) { class_("A") .def("info",&A::info,A_info_overloads()) //line 17 ; } _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From hansroessler at yahoo.de Thu May 21 23:00:25 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Thu, 21 May 2009 14:00:25 -0700 (PDT) Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS In-Reply-To: <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> Message-ID: <289047.3550.qm@web24606.mail.ird.yahoo.com> Thanks, ".def("info", (void(A::*)(int))0, A_info_overloads());" does it. Could somebody explain what the meaning of this "(void(A::*)(int))0" construct is? Is it a function pointer? Why the 0? (Just now I am fine with the proposed solution, but if I even understand it, you will read fewer stupid question from me in this list ;-) Hans ----- Urspr?ngliche Mail ---- > Von: William Ladwig > An: Development of Python/C++ integration > Gesendet: Donnerstag, den 21. Mai 2009, 18:30:46 Uhr > Betreff: Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS > > I haven't tried this myself, but I think all you need to do to wrap the member > function is this: > > .def("info", (void(A::*)(int))0, A_info_overloads()); > > Hope this helps, > Bill From hansroessler at yahoo.de Thu May 21 23:08:03 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Thu, 21 May 2009 14:08:03 -0700 (PDT) Subject: [C++-sig] iterate a boost::python::list In-Reply-To: <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> Message-ID: <940734.2985.qm@web24607.mail.ird.yahoo.com> How can I iterate in C++ over a boost::python::list? According to http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/list.html it has no begin() and end() functions. Neither a size() function that would allow to call pop(size()-1). Neither an isEmpty() function that would allow to call pop(0) until the list is empty. I'm sure I'm missing something trivial. Can somebody help me? Thanks Hans From wladwig at wdtinc.com Thu May 21 23:32:08 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Thu, 21 May 2009 16:32:08 -0500 Subject: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS In-Reply-To: <289047.3550.qm@web24606.mail.ird.yahoo.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> <289047.3550.qm@web24606.mail.ird.yahoo.com> Message-ID: <765CBD9053EA2B438625895F30D1856F022643666D@storm.wdtinc.com> It's making a NULL pointer to a member function of A with an integer argument and a void return type. I'm not sure what's going on under the hood with why the NULL is required, but I suspect that it has something to do with the fact that void info(); void info(int i); require two function pointers, but void info(int i=0) can only use one function pointer. I suspect that they're trying to handle both cases with the same interface. I'm just guessing though, so I could be wrong about this. Regards, Bill -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler Sent: Thursday, May 21, 2009 4:00 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS Thanks, ".def("info", (void(A::*)(int))0, A_info_overloads());" does it. Could somebody explain what the meaning of this "(void(A::*)(int))0" construct is? Is it a function pointer? Why the 0? (Just now I am fine with the proposed solution, but if I even understand it, you will read fewer stupid question from me in this list ;-) Hans ----- Urspr?ngliche Mail ---- > Von: William Ladwig > An: Development of Python/C++ integration > Gesendet: Donnerstag, den 21. Mai 2009, 18:30:46 Uhr > Betreff: Re: [C++-sig] variable argument number and BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS > > I haven't tried this myself, but I think all you need to do to wrap the member > function is this: > > .def("info", (void(A::*)(int))0, A_info_overloads()); > > Hope this helps, > Bill _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From rwgk at yahoo.com Fri May 22 00:45:09 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 21 May 2009 15:45:09 -0700 (PDT) Subject: [C++-sig] iterate a boost::python::list In-Reply-To: <940734.2985.qm@web24607.mail.ird.yahoo.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> <940734.2985.qm@web24607.mail.ird.yahoo.com> Message-ID: <998525.34120.qm@web111403.mail.gq1.yahoo.com> It should work like this (untested): boost::python::ssize_t n = boost::python::len(your_list); for(boost::python::ssize_t i=0;i To: Development of Python/C++ integration Sent: Thursday, May 21, 2009 2:08:03 PM Subject: [C++-sig] iterate a boost::python::list How can I iterate in C++ over a boost::python::list? According to http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/list.html it has no begin() and end() functions. Neither a size() function that would allow to call pop(size()-1). Neither an isEmpty() function that would allow to call pop(0) until the list is empty. I'm sure I'm missing something trivial. Can somebody help me? Thanks Hans From andrea.bedini at gmail.com Fri May 22 11:50:56 2009 From: andrea.bedini at gmail.com (Andrea Bedini) Date: Fri, 22 May 2009 11:50:56 +0200 Subject: [C++-sig] iterate a boost::python::list In-Reply-To: <940734.2985.qm@web24607.mail.ird.yahoo.com> References: <759109.42277.qm@web24605.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F022643655E@storm.wdtinc.com> <940734.2985.qm@web24607.mail.ird.yahoo.com> Message-ID: On Thu, May 21, 2009 at 11:08 PM, Hans Roessler wrote: > > How can I iterate in C++ over a boost::python::list? you can use stl_input_iterator: stl_input_iterator begin(o), end; gives you a pair of stl compatible iterators assuming you can extract type T from objects obtained by iterating over o. see http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/stl_iterator.html -- Andrea Bedini -------------- next part -------------- An HTML attachment was scrubbed... URL: From zookog at gmail.com Mon May 25 01:24:06 2009 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Sun, 24 May 2009 17:24:06 -0600 Subject: [C++-sig] RTTI across shared library boundaries Message-ID: Dear cplusplus-sig Folks: I'm the maintainer of pycryptopp [1], a library whose main but not sole user is Tahoe-LAFS [2]. I've recently stumbled across the problem of RTTI crossing shared library boundaries, which seems to be a well-known problem e.g. [3] but without, as far as I can tell, a well-known solution. Pycryptopp is mostly just Python wrappers for the Crypto++ library [4]. The current status is the pycryptopp builds and passes all of its unit tests [*, **] by building Python modules such as aes.so and rsa.so from a combination of Crypto++ object files and pycryptopp object files. However, we're in the process of getting pycryptopp and Tahoe-LAFS included in Debian and Fedora, and those two Linux distributions have a policy that code which re-uses a separate library has to dynamically link to the distribution-provided library instead of bundling a copy of that library. This is so that the distribution maintainers can easily control the combination of libraries included in their distribution -- for example if they want to upgrade Crypto++ or apply a patch to Crypto++ (such as a security patch), they need do so only for the one copy of the shared library, and not for each package which uses it. So, I changed the pycryptopp setup.py so that if you pass the option "--disable-embedded-cryptopp" to the "build" command it will stop using its own internal copy of Crypto++ and instead simply link to -lcryptopp. Now the trouble starts. An exception thrown by libcryptopp.so cannot be caught by its specific type (CryptoPP::InvalidKeyLength) in aes.so. Investigating this leads me to the well-known problem of RTTI comparison across shared library boundaries, and the potential work-around of using the RTLD_GLOBAL in dlopen(). Trying that work-around makes this problem go away, but then if I load more than one .so which dynamically links to libcryptopp.so, the second and later ones that get loaded are messed up in a way that quickly leads to a crash (see the valgrind-generated stack trace in [5] to see what I mean). There is another problem with the same root cause, which is that Crypto++ uses RTTI for a named-argument feature, see [6] for details. I'm now considering a few ways forward: 1. Persuade Debian and Fedora to accept pycryptopp and Tahoe-LAFS using Crypto++ code compiled directly into the pycryptopp .so files instead of dynamically linked. 2. Refactor pycryptopp so that there is only one .so file, named for example _pycryptopp.so, which is dynamically linked to libcryptopp.so, and the separate modules for aes, sha256, rsa, ecdsa, etc. would each import a subset of the Python names defined by _pycryptopp.so, and then use RTLD_GLOBAL to load _pycryptopp.so. This would, I think, solve all currently known issues, but it does mean for example that if anybody ever imports both pycryptopp and another Python module that links to libcryptopp.so into the same Python process that one of them will be screwed up and the process will quickly crash. 3. Resign myself to working-around the lack of portable RTTI crossing shared library boundaries in the pycryptopp source code. Brian Warner has already submitted patches for pycryptopp (see [6]) to work-around the two known problems by (a) not catching CryptoPP::InvalidKeyLength exception by its specific type and instead catching any type of exception, and (b) not providing the hex-encoding feature which happens to exercise Crypto++'s named-arguments feature. I could accept those two patches and resign myself to a fate of being unable to safely use some ill-understood subset of the Crypto++ API. 4. Figure out how to build an aes.so that has the relevant RTTI symbols marked as "these must be satisfied by some other dynamic library". I'm not sure if this is possible, but it seems to how things are done on Windows. I read this page from the gcc wiki [7] and experimented quite a bit with it. When I started, using "nm" on libcryptopp.so would show this: $ nm -C /usr/local/lib/libcryptopp.so | grep "typeinfo for CryptoPP::InvalidKeyLength" 00000000008747b0 V typeinfo for CryptoPP::InvalidKeyLength And on my aes.so, it would show this: $ nm -C ./pycryptopp/cipher/_aes.so | grep "typeinfo for CryptoPP::InvalidKeyLength" 0000000000214cf0 V typeinfo for CryptoPP::InvalidKeyLength After extensive exploration of the new gcc visibility features, I finally managed to build an aes.so like this: $ nm -C ./pycryptopp/cipher/aes.so | grep "typeinfo for CryptoPP::InvalidKeyLength" 0000000000214cf0 d typeinfo for CryptoPP::InvalidKeyLength Oops! In other words, I managed to make the typeinfo symbol private to aes.so instead of dynamic, thus guaranteeing that the exception won't be caught even if I *do* specify RTLD_GLOBAL. It sort of seems like gcc offers the rough equivalent of Microsoft's "dllexport" attribute, but not the rough equivalent of Microsoft's "dllimport" attribute -- something that would, for example, force the symbol to appear as "U" -- undefined -- in the .so's symbol table so that the symbol's value would *have* to be provided by another DSO (in this case libcryptopp.so) at load-time. On the other hand, maybe if I changed the libcryptopp.so so that the symbol was marked as non-weak, such as "T", instead of its current type of weak -- "V" -- then maybe the loader would have rewritten the value of the weak-symbol in aes.so and the exception would have been caught. I don't see how to do that, either. Okay, here's the question: do you know of any alternative besides these four, and if not, which of these four do you recommend? Thank you very much. Regards, Zooko Wilcox-O'Hearn [*] Actually it fails one of the unit tests consistently on Mac OS 10.5/Intel, but not on Mac OS 10.4 or on any of the other platforms. The failure *does* have something to do with RTTI since it is a failure to downcast, but other than that I don't have any reason to believe that it is related to the rest of this message, and I haven't investigated it yet. See the pycryptopp buildbot on Mac OS 10.5: http://allmydata.org/buildbot-pycryptopp/builders/mac-i386-osx-10.5-faust [**] Oh, and there's a mysterious problem on ARMv5 CPU in which a memory buffer seems to be shifted by one byte, also probably unrelated: http://allmydata.org/buildbot-pycryptopp/builders/zandr-linkstation [1] http://allmydata.org/trac/pycryptopp [2] http://allmydata.org/trac/tahoe [3] http://mail.python.org/pipermail/python-dev/2002-May/024075.html [4] http://cryptopp.com [5] http://groups.google.com/group/cryptopp-users/browse_thread/thread/eb815f228db50380 [6] http://allmydata.org/trac/pycryptopp/ticket/9 [7] http://gcc.gnu.org/wiki/Visibility --- store your data: $10/month -- http://allmydata.com/?tracking=zsig I am available for work -- http://zooko.com/r?sum?.html From hansroessler at yahoo.de Mon May 25 16:08:47 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Mon, 25 May 2009 07:08:47 -0700 (PDT) Subject: [C++-sig] wrapping operator= Message-ID: <831751.9082.qm@web24613.mail.ird.yahoo.com> Hello! I want to wrap with boost.python a C++ class "DataCube" which has overloaded the operator=. The constructor DataCube::DataCube(double x) allocates huge amounts of memory and fills it with x's. The DataCube::operator=(double x) just overwrites the already allocated memory with x's. Now in C++ these commands first allocate memory, which is filled with 0.'s, and then overwrite the memory with 42.'s: >DataCube data(0.) >data=42. In Python these commands first build the DataCube as desired, but then set data=42. (now data is a float), where the reference to the DataCube is lost: >data=DataCube(0.) >data=42. I have circumvented this by replacing the second line with > data.assign(42.) with a function assign which is defined appropriately, but I would prefer to use the same assignment as in C++. Finally the question: Can I define the DataCube class in Python, so that the data variable above will behave as in C++, when I write "data=42." ? In other words, is there any possibility in Python that "x=y" does NOT make x a reference to y? Thank you Hans From wladwig at wdtinc.com Mon May 25 18:54:53 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Mon, 25 May 2009 11:54:53 -0500 Subject: [C++-sig] wrapping operator= In-Reply-To: <831751.9082.qm@web24613.mail.ird.yahoo.com> References: <831751.9082.qm@web24613.mail.ird.yahoo.com> Message-ID: <765CBD9053EA2B438625895F30D1856F0226274C69@storm.wdtinc.com> Generally how that situation is handled on the Python side is to use the container emulation API, so that assigning all values would look like this to a user of your class: data[:] = 42. To do this, you just need to write a small c++ wrapper to expose the __setitem__(self, key, value) function, which accepts (or extracts) a slice object for the key and then calls your class operator= function. Or, you could just stick with the assign function that you created, which may be better if your class isn't supposed to look like a container. This may actually be less error prone. Here is the Python container emulation documentation: http://docs.python.org/reference/datamodel.html#emulating-container-types Other people may have better suggestions. Regards, Bill ________________________________________ From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler [hansroessler at yahoo.de] Sent: Monday, May 25, 2009 9:08 AM To: cplusplus-sig at python.org Subject: [C++-sig] wrapping operator= Hello! I want to wrap with boost.python a C++ class "DataCube" which has overloaded the operator=. The constructor DataCube::DataCube(double x) allocates huge amounts of memory and fills it with x's. The DataCube::operator=(double x) just overwrites the already allocated memory with x's. Now in C++ these commands first allocate memory, which is filled with 0.'s, and then overwrite the memory with 42.'s: >DataCube data(0.) >data=42. In Python these commands first build the DataCube as desired, but then set data=42. (now data is a float), where the reference to the DataCube is lost: >data=DataCube(0.) >data=42. I have circumvented this by replacing the second line with > data.assign(42.) with a function assign which is defined appropriately, but I would prefer to use the same assignment as in C++. Finally the question: Can I define the DataCube class in Python, so that the data variable above will behave as in C++, when I write "data=42." ? In other words, is there any possibility in Python that "x=y" does NOT make x a reference to y? Thank you Hans _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From hansroessler at yahoo.de Mon May 25 19:20:55 2009 From: hansroessler at yahoo.de (Hans Roessler) Date: Mon, 25 May 2009 10:20:55 -0700 (PDT) Subject: [C++-sig] wrapping operator= In-Reply-To: <765CBD9053EA2B438625895F30D1856F0226274C69@storm.wdtinc.com> References: <831751.9082.qm@web24613.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F0226274C69@storm.wdtinc.com> Message-ID: <76345.81452.qm@web24610.mail.ird.yahoo.com> Thank you, William. The __setitem__ emulation is definitely a better idea than the assign function, as the class is actually a container type. But still I am looking for a way to allow the simple "data=42." syntax with the same result, because it would best copy the C++ syntax. Hans ----- Urspr?ngliche Mail ---- > Von: William Ladwig > An: Development of Python/C++ integration > Gesendet: Montag, den 25. Mai 2009, 18:54:53 Uhr > Betreff: Re: [C++-sig] wrapping operator= > > Generally how that situation is handled on the Python side is to use the > container emulation API, so that assigning all values would look like this to a > user of your class: > > data[:] = 42. > > To do this, you just need to write a small c++ wrapper to expose the > __setitem__(self, key, value) function, which accepts (or extracts) a slice > object for the key and then calls your class operator= function. Or, you could > just stick with the assign function that you created, which may be better if > your class isn't supposed to look like a container. This may actually be less > error prone. > > Here is the Python container emulation documentation: > > http://docs.python.org/reference/datamodel.html#emulating-container-types > > Other people may have better suggestions. > > Regards, > Bill > > ________________________________________ > From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org > [cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Hans Roessler > [hansroessler at yahoo.de] > Sent: Monday, May 25, 2009 9:08 AM > To: cplusplus-sig at python.org > Subject: [C++-sig] wrapping operator= > > Hello! > I want to wrap with boost.python a C++ class "DataCube" which has overloaded the > operator=. > > The constructor DataCube::DataCube(double x) allocates huge amounts of memory > and fills it with x's. > The DataCube::operator=(double x) just overwrites the already allocated memory > with x's. > > Now in C++ these commands first allocate memory, which is filled with 0.'s, and > then overwrite the memory with 42.'s: > >DataCube data(0.) > >data=42. > > In Python these commands first build the DataCube as desired, but then set > data=42. (now data is a float), where the reference to the DataCube is lost: > >data=DataCube(0.) > >data=42. > > I have circumvented this by replacing the second line with > > data.assign(42.) > with a function assign which is defined appropriately, but I would prefer to use > the same assignment as in C++. > > Finally the question: > Can I define the DataCube class in Python, so that the data variable above will > behave as in C++, when I write "data=42." ? > In other words, is there any possibility in Python that "x=y" does NOT make x a > reference to y? > > Thank you > Hans > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From seefeld at sympatico.ca Mon May 25 19:58:17 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 25 May 2009 13:58:17 -0400 Subject: [C++-sig] wrapping operator= In-Reply-To: <76345.81452.qm@web24610.mail.ird.yahoo.com> References: <831751.9082.qm@web24613.mail.ird.yahoo.com> <765CBD9053EA2B438625895F30D1856F0226274C69@storm.wdtinc.com> <76345.81452.qm@web24610.mail.ird.yahoo.com> Message-ID: <4A1ADC39.6050204@sympatico.ca> Hans Roessler wrote: > But still I am looking for a way to allow the simple "data=42." syntax with the same result, because it would best copy the C++ syntax. > Would it, really ? I think it would be extremely confusing, if it would work. But it doesn't. "a = b" doesn't assign to an object, but to a variable. Variables in Python have reference semantics, so you'd simply reassign the name to a different object. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From zookog at gmail.com Wed May 27 17:42:48 2009 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Wed, 27 May 2009 09:42:48 -0600 Subject: [C++-sig] that problem with comparing types across DLLs Message-ID: (Note that several individuals, plus tahoe-dev at allmydata.org and cplusplus-sig at python.org are Cc:'ed. This is appropriate because this is fundamentally a "cross project" issue and we need to talk to each other until we understand what the other developers are planning. Unfortunately, you're likely to have problems following-up to the mailing lists if you aren't subscribed to them.) On May 27, 2009, at 1:01 AM, Matthias Klose wrote: > > Well, maybe nobody did ask, because it's policy for distributions to build > against shared libs? If there needs something to be fixed in the library > package, you only have to take care of the library packages, not all packages > which are linked against the static library (of course you would have to find > out which these packages are). Plus you usually cannot link a python extension > against a static lib because the static lib is built without -fPIC. Thanks, Matthias, and thanks to Ruben for the earlier answers about Fedora. It looks like option #1 from this list is right out: http://mail.python.org/pipermail/cplusplus-sig/2009-May/014531.html (Option #1 was to persuade distributions to support Crypto++ as a static library.) The option that would be technically the most general would be to figure out how to annotate and compile Crypto++ as a shared lib that has visible only the symbols that it needs to have visible, and then use the RTLD_GLOBAL flag to dlopen() to make sure multiple .so's which each depend on libcryptopp.so will get those symbols unified at load-time so that cross-shared-library RTTI will work. That is what Niall Douglas recommends and has done successfully in the past. However, I've already spent a couple of days trying to learn how to do this and I haven't succeeded yet. I'm not even sure that it is possible. Wei Dai, the author of Crypto++, has also tried in the past to build such a shared lib of Crypto++ for Unix in the past, and he too gave up. That also means that he does not currently support using Crypto++ as a shared library, which makes me uncomfortable, but I guess that's the Linux distributions' problem more than mine. I think that leaves option #2 from that list: refactor pycryptopp so that it contains only a single shared library, and use RTLD_GLOBAL to unify the symbols that are visible in the _pycryptopp.so with the symbols in the the libcryptopp.so. I think this is doable and that it will solve all known problems for pycryptopp and Tahoe. I think this does mean that if in the future there is a different Python module than pycryptopp which is dynamically linked to libcryptopp.so, that anyone who imports both pycryptopp and that other Python module into their Python interpreter will get a seg fault. However, I suppose this too is someone else's problem than mine. So unless anyone else has a better suggestion, I'm going to proceed with strategy #2. I'll probably also continue to support the current linking strategy of linking pycryptopp statically against libcryptopp.a, as a build-time option for pycryptopp. Therefore people who have chosen the static-link-to-Crypto++ build-time option (which excludes users of the Fedora, Debian, or Ubuntu packages of pycryptopp) will be able to also import another Python module which links to Crypto++. Thanks, folks! Regards, Zooko From zookog at gmail.com Wed May 27 21:52:54 2009 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Wed, 27 May 2009 13:52:54 -0600 Subject: [C++-sig] that problem with comparing types across DLLs In-Reply-To: <4A1D9269.16781.6A4D1E9@s_sourceforge.nedprod.com> References: <4A1D9269.16781.6A4D1E9@s_sourceforge.nedprod.com> Message-ID: On Wed, May 27, 2009 at 12:20 PM, Niall Douglas wrote: > > If it turns out that GCC is incapable of emitting the correct symbol > visibility declarations for a particular library, then an issue > should be filed with GCC's bugtracker. They have been most responsive > in the past with corner cases so I don't see it as an issue. Thanks for the encouragement on that front. I'll keep in mind that gcc developers are responsive about these issues. That helps. > I am afraid I simply don't get this. Crypto++ seems to have a build > option for Windows as a DLL. If it does then it ports very easily > indeed to GCC symbol visibility. The only possible problem could be > if he used a lot of dllexported non-class based static variables > which you shouldn't in object orientatation. As Wei Dai explained in this thread: http://groups.google.com/group/cryptopp-users/browse_thread/thread/eb815f228db50380 He implemented the "CRYPTOPP_DLL" build of Crypto++ only because it was a requirement for FIPS validation, and it doesn't include a lot of the functionality of the library -- only that subset of the functionality which was being validated. Also, he attempted to port the same shared-lib build to Unix and failed and gave up. I don't know whether Crypto++ dllexports a lot of non-class-based static variables. It is a very big library with a big API and I don't have a good understanding of its scope. > If I'm reading between the lines here correctly, are you saying that > your libcrypto++ uses vX.XX of a libaes library but you want that to > interoperate which any other shared library which uses vY.YY of the > same libaes library? Obviously should APIs move out of step you get > all sorts of pernicious bugs. Wei Dai is the author of Crypto++, and I'm the author of pycryptopp. Pycryptopp is merely a few Python wrappers for certain Crypto++ features, plus a few small utilities that I need. The current build system of pycryptopp generates a module named aes.so, one named ecdsa.so, one named rsa.so and one named sha256.so. Each of these requires different functionality from Crypto++. The current build system links aes.so with the Crypto++ object files which are built from the Crypto++ .cpp files. This works, but it is not allowed to deploy as an official Debian or Fedora package when built like this. If I instead link aes.so with "-lcryptopp" and use the Debian- or Fedora- provided libcryptopp.so at load-time (using the default Python behavior of RTLD_LOCAL), it fails, because RTTI symbols are not merged at load-time, so an exception of type InvalidKeyLength, thrown from libcryptopp.so will not be caught by the handler in aes.so which attempts to catch exceptions of that type, because the RTTI symbol for InvalidKeyLength in libcryptopp.so has a different value than the RTTI symbol for InvalidKeyLength in aes.so. If I then set the RTLD_GLOBAL flag, then loading aes.so (which dynamically depends on libcryptopp.so) works, and the exception handler can catch exceptions of the specific type. But, if I then load both aes.so and rsa.so into the same Python interpreter, it seg faults. Here is the valgrind stack trace of that event: http://groups.google.com/group/cryptopp-users/attach/1a5553410c6976e5/crash.txt?part=2 So I am now engaged in refactoring pycryptopp so that instead of separate aes.so and rsa.so (and so on), there is instead a single _pycryptopp.so which provides all of the functionality, and then there is an aes.py and an rsa.py which import the appropriate names from _pycryptopp and leave out the other names. The problem with this strategy, I think, is that if someone were to load _pycryptopp.so using RTLD_GLOBAL, and then someone else were to load libcryptopp.so into the same Python interpreter, it would seg fault. But maybe nobody will ever want to do that. Thanks for you help! Regards, Zooko From wjoergensen at yahoo.com Thu May 28 22:32:30 2009 From: wjoergensen at yahoo.com (Werner Joergensen) Date: Thu, 28 May 2009 13:32:30 -0700 (PDT) Subject: [C++-sig] libboost_python-gcc43-mt.so or without "mt"? Message-ID: <364933.85799.qm@web111810.mail.gq1.yahoo.com> Dear list participants, I have installed boost including the python lib using the boostrap.sh installation script, and now I have the following libraries under /lib (linux system): libboost_python-gcc43-mt-1_39.a libboost_python-gcc43-mt-1_39.so libboost_python-gcc43-mt-1_39.so.1.39.0 libboost_python-gcc43-mt.a libboost_python-gcc43-mt.so However when I build a python extension module with bjam, and when I import the newly built module in python, the problem is: $ ipython In [1]: import myModule ImportError: libboost_python-gcc43-1_39.so.1.39.0: cannot open shared object file: No such file or directory Of course, I can copy and rename the mt-libraries to the expected library name. But is there a possibility to build the python extension so that the exististing libboost_python-gcc43-mt.so will be linked instead of some other name? Can I configure which libboost_python will be used somewhere in boost-build.jam or user-config.jam or Jamroot? Thanks Werner From boliguayo1942 at hotmail.com Fri May 29 05:55:06 2009 From: boliguayo1942 at hotmail.com (=?iso-8859-1?Q?Juan_Manuel_Martinez_Caama=F1o?=) Date: Fri, 29 May 2009 00:55:06 -0300 Subject: [C++-sig] problems building a pyd under vc++ with distutils Message-ID: I'm under vc++ 9.0 and I'm having problem when trying to build a simple *.pyd... (using distutils) When I build the dll from the IDE it produces a DLL (not a *.pyd) and no compiler or linker errors. But when I use distutils it just output a lot of errors... I can't find the problem... /*-----------------pydll.cpp:------------------*/ #include #include using namespace boost::python; __declspec(dllexport) std::string greet() { return "Hello Python"; }; BOOST_PYTHON_MODULE(hello) { def("greet", greet); } -------------------------------------------------------------- #setup.py from distutils.core import setup, Extension module1 = Extension('hello', sources = ["pydll.cpp"]) setup (name = 'pydll', version = '1.0', description = 'This is a demo package', ext_modules = [module1]) ------------------------------------------------------------- (under visual studio 2008, python 2.6, boost 1.38.0) Thank you Juan -------------- next part -------------- An HTML attachment was scrubbed... URL: From wjoergensen at yahoo.com Fri May 29 12:20:56 2009 From: wjoergensen at yahoo.com (Werner Joergensen) Date: Fri, 29 May 2009 03:20:56 -0700 (PDT) Subject: [C++-sig] [Py++] incomplete type and forward declaration Message-ID: <573306.52699.qm@web111809.mail.gq1.yahoo.com> How can I process such a file classA.hpp using a code generator like http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/generate_code.py.html? ----------8<---- classA.hpp ------ class B; class A{ public: B& dontCareAboutB(){ /*return C::getB();*/ }; void doSomething(){}; }; ----------8<---------- This class compiles fine with just "g++ -c classA.hpp", but applying the pyplusplus code generator followed by bjam throws several errors: ... /opt/boost_1_39_0/boost/python/type_id.hpp:89: error: invalid use of incomplete type ?struct B? ./classA.hpp:1: error: forward declaration of ?struct B? ... If I replace the first line with "class B{}", making B a comple, empty class, this example succeeds. But then I run into more troubles if I add the actual definition of the real class B from another header file to the python module. Does a solution with pyplusplus exist, where I don't need to modify the classA.hpp header file? Thanks Werner From hessiess at hessiess.com Fri May 29 18:56:37 2009 From: hessiess at hessiess.com (hessiess at hessiess.com) Date: Fri, 29 May 2009 17:56:37 +0100 (BST) Subject: [C++-sig] Derived classes problem Message-ID: I am trying to create a python wrapper for the quad-ren graphics engine, which relies heavily on derived classes. The problem is that I cannot create derived classes in python and pass them to the C++ objects without getting the following error: Traceback (most recent call last): File "test.py", line 79, in quad3.set_event_receiver(event) Boost.Python.ArgumentError: Python argument types in qr_scene_node.set_event_receiver(qr_quad, ev_receiver) did not match C++ signature: set_event_receiver(qr_scene_node {lvalue}, qr_event_receiver*) ==================================================================== C++ ==================================================================== #include #include using namespace boost::python; struct qr_scene_node_w : qr_scene_node, wrapper { void on_register() { this->get_override("on_register")(); } void on_render() { this->get_override("on_render")(); } void on_drop() { this->get_override("on_drop")(); } }; struct qr_event_receiver_w : qr_event_receiver, wrapper { bool on_event(qr_event *event, qr_scene_node *node, float time_delta) { this->get_override("on_event")(); } }; BOOST_PYTHON_MODULE(qrpy) { class_("vector2d_i") .def(init()) .def_readwrite("X", &vector2d_i::X) .def_readwrite("Y", &vector2d_i::Y); class_("vector2d_f") .def(init()) .def_readwrite("X", &vector2d_f::X) .def_readwrite("Y", &vector2d_f::Y); class_("qr_resource_manager"); class_("qr_renderer") .def(init()) .def("get_resource_manager", &qr_renderer::get_resource_manager, return_value_policy()) .def("run", &qr_renderer::run) .def("drop", &qr_renderer::drop) .def("set_total_layers", &qr_renderer::set_total_layers) .def("set_window_title", &qr_renderer::set_window_title) .def("get_time_delta", &qr_renderer::get_time_delta) .def("get_ticks", &qr_renderer::get_ticks) .def("get_fps", &qr_renderer::get_fps) .def("set_camera_location", &qr_renderer::set_camera_location) .def("get_camera_location", &qr_renderer::get_camera_location) .def("get_pix_size", &qr_renderer::get_pix_size) .def("set_bg_sprite", &qr_renderer::set_bg_sprite) .def("get_bg_sprite", &qr_renderer::get_bg_sprite, return_value_policy()); class_("qr_scene_node", no_init) .def("register_node", &qr_scene_node_w::register_node) .def("drop", &qr_scene_node_w::drop) .def("set_location", &qr_scene_node_w::set_location) .def("get_location", &qr_scene_node_w::get_location) .def("set_size", &qr_scene_node_w::set_size) .def("get_size", &qr_scene_node_w::get_size) .def("set_rotation", &qr_scene_node_w::set_rotation) .def("get_rotation", &qr_scene_node_w::get_rotation) .def("set_layer", &qr_scene_node_w::set_layer) .def("get_layer", &qr_scene_node_w::get_layer) .def("set_sprite", &qr_scene_node_w::set_sprite) .def("get_sprite", &qr_scene_node_w::get_sprite, return_value_policy()) .def("set_event_receiver", &qr_scene_node_w::set_event_receiver) .def("get_event_receiver", &qr_scene_node_w::get_event_receiver, return_value_policy()) .def("set_frame", &qr_scene_node_w::set_frame) .def("get_frame", &qr_scene_node_w::get_frame) .def("add_polygon", &qr_scene_node_w::add_polygon) .def("clear_mesh", &qr_scene_node_w::clear_mesh) .def("on_register", &qr_scene_node_w::on_register) .def("on_render", &qr_scene_node_w::on_render) .def("on_drop", &qr_scene_node_w::on_drop); class_("qr_event_receiver", no_init) .def("on_event", &qr_event_receiver_w::on_event); class_ >("qr_quad") .def(init()); } ==================================================================== Python ==================================================================== import qrpy false = bool(0) true = bool(1) #create renderer + get resource manager renderer = qrpy.qr_renderer(qrpy.vector2d_i(4, 3), 10, false, qrpy.vector2d_i(0, 0)) res_man = renderer.get_resource_manager() #event receiver class ev_receiver(qrpy.qr_event_receiver): def __init__(self): return def on_event(self, event, node, time_delta): print event event = ev_receiver() quad = qrpy.qr_quad(res_man, 0) quad.set_event_receiver(event) #error From ndbecker2 at gmail.com Fri May 29 20:27:55 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 29 May 2009 14:27:55 -0400 Subject: [C++-sig] libboost_python-gcc43-mt.so or without "mt"? References: <364933.85799.qm@web111810.mail.gq1.yahoo.com> Message-ID: Werner Joergensen wrote: > > Dear list participants, > > I have installed boost including the python lib using the boostrap.sh > installation script, and now I have the following libraries under /lib > (linux system): libboost_python-gcc43-mt-1_39.a > libboost_python-gcc43-mt-1_39.so libboost_python-gcc43-mt-1_39.so.1.39.0 > libboost_python-gcc43-mt.a > libboost_python-gcc43-mt.so > > However when I build a python extension module with bjam, and when I > import the newly built module in python, the problem is: > $ ipython > In [1]: import myModule > ImportError: libboost_python-gcc43-1_39.so.1.39.0: cannot open shared > object file: No such file or directory > > Of course, I can copy and rename the mt-libraries to the expected library > name. But is there a possibility to build the python extension so that the > exististing libboost_python-gcc43-mt.so will be linked instead of some > other name? Can I configure which libboost_python will be used somewhere > in boost-build.jam or user-config.jam or Jamroot? > > Thanks > Werner Here's what I do 1. Get updated 1.39 from svn (the --layout=tagged option was just added, at my request). Then, I use: bjam -sICU_PATH=/usr -sEXPAT_INCLUDE=/usr -sEXPAT_LIBPATH=/usr/lib64 -- layout=tagged threading=single,multi stage You will then have (sorry for ugly formatting): -rw-rw-r-- 1 nbecker nbecker 161294 2009-05-18 15:17 libboost_date_time.a -rw-rw-r-- 1 nbecker nbecker 161294 2009-05-18 15:17 libboost_date_time- mt.a lrwxrwxrwx 1 nbecker nbecker 31 2009-05-18 15:17 libboost_date_time- mt.so -> libboost_date_time-mt.so.1.40.0 -rwxrwxr-x 1 nbecker nbecker 76680 2009-05-18 15:17 libboost_date_time- mt.so.1.40.0 lrwxrwxrwx 1 nbecker nbecker 28 2009-05-18 15:17 libboost_date_time.so -> libboost_date_time.so.1.40.0 -rwxrwxr-x 1 nbecker nbecker 76648 2009-05-18 15:17 libboost_date_time.so.1.40.0 ... From wjoergensen at yahoo.com Sat May 30 22:53:07 2009 From: wjoergensen at yahoo.com (Werner Joergensen) Date: Sat, 30 May 2009 13:53:07 -0700 (PDT) Subject: [C++-sig] [Py++] wrapping boost python types fails Message-ID: <999875.14484.qm@web111808.mail.gq1.yahoo.com> I narrowed down a failure with pyplusplus to this short example: ---------8<---- test.hpp ----- #include "boost/python.hpp" --------->8--------- ---------8<---- generator.py ----- import os from pyplusplus import module_builder mb = module_builder.module_builder_t( files=["test.hpp"], include_paths=["/usr/include/python2.6"] ) mb.build_code_creator( module_name='testmodule' ) mb.code_creator.user_defined_directories.append( os.path.abspath('.') ) mb.split_module("split") mb.write_module( os.path.join( os.path.abspath('.'), 'generated.cpp' ) ) --------->8--------- Running "python generator.py" gives these errors: ---------8<---- output ----- ... pygccxml.parser.source_reader.gccxml_runtime_error_t: Error occured while running GCC-XML: In file included from /usr/local/include/boost-1_39/boost/python.hpp:60, from test.hpp:1: /usr/local/include/boost-1_39/boost/type.hpp:14: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See for instructions. --------->8--------- I need to use the python objects like list, str, tuple in my python extension modules. So can you help me to get the example running? I tried it on two different systems, one with gcc 4.2.4 and one with gcc 4.3.3. Other relevant packages are: gccxml 0.9 (cvs from 2008-05-30), boost 1.39.0, pygccxml 1.0, pyplusplus 1.0. Can you tell me which combination of these packages can compile the short example? Thanks Werner From roman.yakovenko at gmail.com Sun May 31 06:27:43 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 31 May 2009 07:27:43 +0300 Subject: [C++-sig] [Py++] incomplete type and forward declaration In-Reply-To: <573306.52699.qm@web111809.mail.gq1.yahoo.com> References: <573306.52699.qm@web111809.mail.gq1.yahoo.com> Message-ID: <7465b6170905302127u332ce2cenbd9ae4469d173bd4@mail.gmail.com> On Fri, May 29, 2009 at 1:20 PM, Werner Joergensen wrote: > > How can I process such a file classA.hpp using a code generator like http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/generate_code.py.html? > > ----------8<---- classA.hpp ------ > class B; > > class A{ > public: > ?B& dontCareAboutB(){ /*return C::getB();*/ }; > ?void doSomething(){}; > }; > ----------8<---------- > > This class compiles fine with just "g++ -c classA.hpp", but applying the pyplusplus code generator followed by bjam throws several errors: > ... > /opt/boost_1_39_0/boost/python/type_id.hpp:89: error: invalid use of incomplete type ?struct B? > ./classA.hpp:1: error: forward declaration of ?struct B? > ... > > If I replace the first line with "class B{}", making B a comple, empty class, this example succeeds. But then I run into more troubles if I add the actual definition of the real class B from another header file to the python module. > > Does a solution with pyplusplus exist, where I don't need to modify the classA.hpp header file? I think, the solution exists. First of all you should understand, that Boost.Python really needs to know( see definition ) of class B. So you will have to include it "before" the generated code. What you can do is to add the "B" header file to class A generate code: http://language-binding.net/pyplusplus/documentation/inserting_code.html#header-files HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sun May 31 06:30:17 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 31 May 2009 07:30:17 +0300 Subject: [C++-sig] [Py++] wrapping boost python types fails In-Reply-To: <999875.14484.qm@web111808.mail.gq1.yahoo.com> References: <999875.14484.qm@web111808.mail.gq1.yahoo.com> Message-ID: <7465b6170905302130h7d11a3a8pf70120bc435e8513@mail.gmail.com> On Sat, May 30, 2009 at 11:53 PM, Werner Joergensen wrote: > > I narrowed down a failure with pyplusplus to this short example: > > ---------8<---- test.hpp ----- > #include "boost/python.hpp" > --------->8--------- > > ---------8<---- generator.py ----- > import os > from pyplusplus import module_builder > mb = module_builder.module_builder_t( > ? ?files=["test.hpp"], > ? ? ? ?include_paths=["/usr/include/python2.6"] > ? ?) > > mb.build_code_creator( module_name='testmodule' ) > mb.code_creator.user_defined_directories.append( os.path.abspath('.') ) > mb.split_module("split") > mb.write_module( os.path.join( os.path.abspath('.'), 'generated.cpp' ) ) > --------->8--------- > > Running "python generator.py" gives these errors: > ---------8<---- output ----- > ... > pygccxml.parser.source_reader.gccxml_runtime_error_t: Error occured while running GCC-XML: In file included from /usr/local/include/boost-1_39/boost/python.hpp:60, > ? ? ? ? ? ? ? ? from test.hpp:1: > /usr/local/include/boost-1_39/boost/type.hpp:14: internal compiler error: Segmentation fault > Please submit a full bug report, > with preprocessed source if appropriate. > See for instructions. > --------->8--------- > > I need to use the python objects like list, str, tuple in my python extension modules. So can you help me to get the example running? I tried it on two different systems, one with gcc 4.2.4 and one with gcc 4.3.3. Other relevant packages are: gccxml 0.9 (cvs from 2008-05-30), boost 1.39.0, pygccxml 1.0, pyplusplus 1.0. Can you tell me which combination of these packages can compile the short example? Unfortunately, gccxml is not able to parse code, which includes "boost/python.hpp" header file. You will have to find someway to exclude it from compilation. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From wjoergensen at yahoo.com Sun May 31 20:30:07 2009 From: wjoergensen at yahoo.com (Werner Joergensen) Date: Sun, 31 May 2009 11:30:07 -0700 (PDT) Subject: [C++-sig] [Py++] wrapping boost python types fails In-Reply-To: <7465b6170905302130h7d11a3a8pf70120bc435e8513@mail.gmail.com> References: <999875.14484.qm@web111808.mail.gq1.yahoo.com> <7465b6170905302130h7d11a3a8pf70120bc435e8513@mail.gmail.com> Message-ID: <298398.3395.qm@web111810.mail.gq1.yahoo.com> >> I need to use the python objects like list, str, tuple in my python extension modules. So can you help me to get the example running? I tried it on two different systems, one with gcc 4.2.4 >>and one with gcc 4.3.3. Other relevant packages are: gccxml 0.9 (cvs from 2008-05-30), boost 1.39.0, pygccxml 1.0, pyplusplus 1.0. Can you tell me which combination of these packages >>can compile the short example? >Unfortunately, gccxml is not able to parse code, which includes >"boost/python.hpp" header file. You will have to find someway to >exclude it from compilation. Good to know. But do you have an explanation, why gccxml is unable? Is there any chance I could work on a solution, or have experienced developers already given up? Do you have some references of other attempts to solve the problem? For a workaround: It is no problem to exclude the offending code from compilation. But then how can I wrap classes that expect for example a python list as input? Thanks Werner From roman.yakovenko at gmail.com Sun May 31 20:41:26 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sun, 31 May 2009 21:41:26 +0300 Subject: [C++-sig] [Py++] wrapping boost python types fails In-Reply-To: <298398.3395.qm@web111810.mail.gq1.yahoo.com> References: <999875.14484.qm@web111808.mail.gq1.yahoo.com> <7465b6170905302130h7d11a3a8pf70120bc435e8513@mail.gmail.com> <298398.3395.qm@web111810.mail.gq1.yahoo.com> Message-ID: <7465b6170905311141y332ac035ic2dcc6e79b5c3e89@mail.gmail.com> On Sun, May 31, 2009 at 9:30 PM, Werner Joergensen wrote: > >>> I need to use the python objects like list, str, tuple in my python extension modules. So can you help me to get the example running? I tried it on two different systems, one with gcc 4.2.4 > >>>and one with gcc 4.3.3. Other relevant packages are: gccxml 0.9 (cvs from 2008-05-30), boost 1.39.0, pygccxml 1.0, pyplusplus 1.0. Can you tell me which combination of these packages >>>can compile the short example? > >>Unfortunately, gccxml is not able to parse code, which includes >>"boost/python.hpp" header file. You will have to find someway to >>exclude it from compilation. > > Good to know. But do you have an explanation, why gccxml is unable? Yes - Boost.Python is the art of template and preprocessor meta programming. I guess, GCCXML fails to dump those template instantiations. > Is there any chance I could work on a solution, or have experienced developers already given up? If you have experience with gcc code base, than I guess you will be able to solve the problem. In any case, gccxml mailing list is a better place to discuss this bug ( http://www.gccxml.org/mailman/listinfo/gccxml ) > Do you have some references of other attempts to solve the problem? No > For a workaround: It is no problem to exclude the offending code from compilation. But then how can I wrap classes that expect for example a python list as input? Py++ doesn't support this use case, for the reason above. If you have a lot of code, that uses Boost.Python classes, than we can work together to patch Py++, otherwise you can use the following functionality: http://www.language-binding.net/pyplusplus/documentation/inserting_code.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/