From jbrandmeyer at earthlink.net Mon Nov 1 04:18:35 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Sun, 31 Oct 2004 22:18:35 -0500 Subject: [C++-sig] MEMBER_FUNCTION_OVERLOADS doesn't honor virtualness Message-ID: <1099279115.7972.8.camel@illuvatar> The subject says it all. Attached is a test case. Thanks, -Jonathan Brandmeyer -------------- next part -------------- A non-text attachment was scrubbed... Name: idontwork.cpp Type: text/x-c++src Size: 583 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: idontwork.py Type: application/x-python Size: 90 bytes Desc: not available URL: From dave at boost-consulting.com Mon Nov 1 05:10:32 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 31 Oct 2004 23:10:32 -0500 Subject: [C++-sig] Re: MEMBER_FUNCTION_OVERLOADS doesn't honor virtualness References: <1099279115.7972.8.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > The subject says it all. Attached is a test case. > > Thanks, > -Jonathan Brandmeyer > > > > #include > #include > > class base > { > public: > virtual void print_me(unsigned int i = 0) > { std::cout << "base: " << i << "\n"; } > }; > > class derived : public base > { > public: > void print_me( unsigned int i) > { std::cout << "derived: " << i << "\n"; } > }; > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( print_me, base::print_me, 0, 1) This won't compile without an ampersand-------------^ > BOOST_PYTHON_MODULE( idontwork) > { > using namespace boost::python; > class_("base") > .def( "print_me", &base::print_me, print_me()) > ; > > class_ >("derived") > ; > } > > > from idontwork import * > x = base() > y = derived() > > x.print_me() > y.print_me() > y.print_me(1) What result are you expecting from this? Can you rewrite the example so that it asserts when you don't get the expected result. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From jbrandmeyer at earthlink.net Mon Nov 1 12:07:30 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Mon, 01 Nov 2004 06:07:30 -0500 Subject: [C++-sig] Re: MEMBER_FUNCTION_OVERLOADS doesn't honor virtualness In-Reply-To: References: <1099279115.7972.8.camel@illuvatar> Message-ID: <1099307250.9270.11.camel@illuvatar> On Sun, 2004-10-31 at 23:10 -0500, David Abrahams wrote: > Jonathan Brandmeyer writes: > > > The subject says it all. Attached is a test case. > > > > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( print_me, base::print_me, 0, 1) > This won't compile without an ampersand-------------^ Are you sure? For me (GCC 3.3.4), it doesn't compile with the address-of operator. Tests in libs/python/test/keywords.cpp and libs/python/test/args.cpp do not use the ampersand. > What result are you expecting from this? Can you rewrite the example > so that it asserts when you don't get the expected result. Sure. I have attached a replacement for the Python file. The problem is that derived.print_me() prints "base: " some_number, when I expect to get "derived: " some_number. -Jonathan -------------- next part -------------- A non-text attachment was scrubbed... Name: idontwork.py Type: application/x-python Size: 433 bytes Desc: not available URL: From dave at boost-consulting.com Mon Nov 1 15:10:15 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 01 Nov 2004 09:10:15 -0500 Subject: [C++-sig] Re: MEMBER_FUNCTION_OVERLOADS doesn't honor virtualness References: <1099279115.7972.8.camel@illuvatar> <1099307250.9270.11.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Sun, 2004-10-31 at 23:10 -0500, David Abrahams wrote: >> Jonathan Brandmeyer writes: >> >> > The subject says it all. Attached is a test case. >> > > >> > BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( print_me, base::print_me, 0, 1) >> This won't compile without an ampersand-------------^ > > Are you sure? For me (GCC 3.3.4), it doesn't compile with the > address-of operator. Tests in libs/python/test/keywords.cpp and > libs/python/test/args.cpp do not use the ampersand. > >> What result are you expecting from this? Can you rewrite the example >> so that it asserts when you don't get the expected result. > > Sure. I have attached a replacement for the Python file. That test doesn't work; you can't expect C++ stream I/O to be seen by Python. Try the enclosed. > The problem > is that derived.print_me() prints "base: " some_number, when I expect to > get "derived: " some_number. Just drop the base:: qualification from BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS and you'll be fine. -------------- next part -------------- A non-text attachment was scrubbed... Name: theTest.cpp Type: text/x-cplusplus Size: 628 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: theTest.py Type: application/octet-stream Size: 447 bytes Desc: not available URL: -------------- next part -------------- -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From ldfwyn at 163.com Mon Nov 1 16:41:00 2004 From: ldfwyn at 163.com (Li Dongfeng) Date: Mon, 1 Nov 2004 10:41:0 -0500 Subject: [C++-sig] Re: regarding your post entitled " Numeric--factory function" onBoost.Python Message-ID: <20041101154122.E18EC1E4002@bag.python.org> Hi Faheem, > boost::python::numeric::array arr(dim1,dim2); --------------------------------------^^^^^^^^^ The problem with you code is the array constructor function usage. That function cannot be called with two integers. See the numarray (or Numeric) docs for correct usage. I tested some solution but cannot reach an elegant one. An elegant solution should use the numarray(or Numeric) API directly to access the array contents in C++. But I have only got a make-shift solution: use the boost::python indexing suite. After you have used the indexing suite to map C++ vector to Python sequence type, you can use a C++ vector as a python sequence in C++ to initialize a numarray.array. To map a C++ std::vector to a Python sequence type named ``DoubleVec'', just make this boost.python extension: ------------------------ #include #include #include #include #include #include #include BOOST_PYTHON_MODULE(_numpyext) { class_ >("DoubleVec") .def(vector_indexing_suite >()); } --------------- Then in a C++ extension module, use: --------------- // std::vector conversion to numarray.array numeric::array vec2array_double(std::vector x){ return numeric::array(x, "Float64"); } BOOST_PYTHON_MODULE(_numpyext) { def("_cppvec2array", &vec2array_double); } --------------- this really works, the ``x'' in the numeric::array function call is recognized by the numarray module constructor function ``array'' as a python sequence of type ``DoubleVec''. This function is meant to return a array in python, so in python we can wrap this function up: ------------------- from _numpyext import _cppvec2array def cpp2nar(x, shape=None): """Convert a C++ vector to a numarray.array. If shp is provided then reshape.""" xar = _cppvec2array(x) if shape is not None: xar.setshape(shape) return xar def nar2cpp(x, totype=None): """Convert a numarray.array to a 1D C++ std::vector. xar should be a double type numarray.array """ xv = DoubleVec() xv[:] = x.flat xv.shape = x.shape ## C++ vector may not have a shape attribute, ## but we attach it in python. ## In C++ although we only use the data as one-dim, ## but when converting back to python we can ## use the shape infomation. ## return value is a C++ vector return xv -------------------------- We also give a conversion utility to convert numarray.array to C++ vector. Below is a simple test with C++ extension and python wrapper: ---------------------------- // A test that vector indexing works. std::vector test_log(std::vector& x){ std::vector::iterator it; for(it = x.begin(); it < x.end(); it++) *it = log(*it); return x; } BOOST_PYTHON_MODULE(_testnum) { def("test_log", test_log); } --------------------- -------------------- def test(): x = array([1, 4, 10.5, 100.0], shape=(2,2), type="Float64") print x xx = nar2cpp(x, totype="Float64") ## converted to C++ vector yy = test_log(xx) ## done in C++ vector y = cpp2nar(yy, shape=x.shape) ## back to numarray.array print y return ---------------------------- These code are not complete, they are simplified. The includes and imports are omitted. You should modify as you need. I have not use the module in production use. I can send you the comple code files if you like. Cheers, ????????Li Dongfeng ????????ldfwyn at 163.com ??????????2004-11-01 ======= 2004-10-30 01:55:00 ======= >Dear Li Dongfeng, > >I saw your post on >http://mail.python.org/pipermail/c++-sig/2004-August/007857.html I'm >trying to do very similar things. Did you meet with any success with your >efforts? In particular, I've had difficulty in creating a numeric array in >C++ and passing it back to python. I get the impression that these factory >functions have something to do with it, but I am not clear. Are these >supposed to be used as constructors for arrays? Can you provide an >example? > >A function like the following compiles without problems, but bombs when I >try to use it. Can you help me? > >Thanks in advance. Faheem Mitha. > >**************************************************************************** >// Convert (C++) numeric matrix to (Python) Numarray numeric array. >boost::python::object cppmat2pynumarr(Array2D A) >{ > int i, j; > int dim1 = A.dim1(); > int dim2 = A.dim2(); > > boost::python::numeric::array arr(dim1,dim2); > for(i=0; i for(j=0; j arr[make_tuple(i,j)] = A[i][j]; > return arr; >} From chris at niekel.net Tue Nov 2 10:43:05 2004 From: chris at niekel.net (Chris Niekel) Date: Tue, 2 Nov 2004 10:43:05 +0100 Subject: [C++-sig] got stuck starting with boost.python Message-ID: <20041102094305.GP1252@kira.niekel.net> Hi, I just started with boost.python, and I'm already stuck. The C++ classes provide a 'readonly' view of the objects, and the user of these classes can't create the objects, they're created and destroyed by some friend-class (say, Manager). So, there's a class Entity { protected: Entity(); ~Entity(); std::string getId(); ... }; class Manager { public: std::map getEntityMap(); ... } First problem was that the Entity destructor had to be public. So I changed that in the headerfile Q1: is there a better way to fix that? I've translated the getEntityMap into a getEntities, using a new function that creates a boost::python::list and walks through the map, adding the elements. That works now. What I want to do next is: class_("Entity", no_init) .def_readonly("id", &Entity::getId) ; That gives me a weird errors: /usr/people1/smf/include/boost-1_31/boost/python/data_members.hpp:285: conversion from `boost::is_member_pointer' to non-scalar type `boost::mpl::bool_' requested which I don't understand. So working around the problem, I .def("id", &Entity::getId) That also gives an error: boost/python/detail/invoke.hpp:89: no match for call to `(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (const std::basic_string, std::allocator >&)' Also beyond my comprehension. If I do: .def("id", &Entity::getId, return_internal_reference<>()) it compiles, but I get the runtime exception: TypeError: No Python class registered for C++ class std::string. So I've now created an extra method in the Entity: const char* getIdCStr() which returns the id.c_str(). That sorta works. I can do in python: for i in getEntities(): print i.id() With .add_property("id", &Entity::getIdCStr) it works as I want it. Q2: This requires me to add methods to the Entity class (there are several std::string attributes I need). Is there a more elegant way to solve this? Hope anyone can help me. I worked through the tutorial, but after jumping to my own code, I noticed quite some bumps in my road. Regards, Chris Niekel -- I've been down so long, if I'd cheer up, I'd still be depressed. - Lisa Simpson, Moanin' Lisa Blues. From dave at boost-consulting.com Tue Nov 2 16:18:31 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 02 Nov 2004 10:18:31 -0500 Subject: [C++-sig] Re: got stuck starting with boost.python References: <20041102094305.GP1252@kira.niekel.net> Message-ID: Chris Niekel writes: > Hi, > > I just started with boost.python, and I'm already stuck. > The C++ classes provide a 'readonly' view of the objects, and the user of > these classes can't create the objects, they're created and destroyed by some > friend-class (say, Manager). > > So, there's a class Entity > { > protected: > Entity(); > ~Entity(); > > std::string getId(); > ... > }; > > class Manager > { > public: > std::map getEntityMap(); > ... > } > > First problem was that the Entity destructor had to be public. > So I changed that in the headerfile > Q1: is there a better way to fix that? Use boost::noncopyable when wrapping Entity. > I've translated the getEntityMap into a getEntities, using a new function > that creates a boost::python::list and walks through the map, adding the > elements. That works now. > > What I want to do next is: > > class_("Entity", no_init) > .def_readonly("id", &Entity::getId) > ; > > That gives me a weird errors: > /usr/people1/smf/include/boost-1_31/boost/python/data_members.hpp:285: > conversion > from `boost::is_member_pointer std::string&(Entity::*)() > const>' to non-scalar type `boost::mpl::bool_' requested def_readonly only works on pointers-to-data-members. Try ^^^^ .add_property("id", &Entity::getId) you may yet need to use a return value policy as in: .add_property( "id" , make_function( &Entity::getId , return_value_policy())) > which I don't understand. So working around the problem, I > .def("id", &Entity::getId) > That also gives an error: > boost/python/detail/invoke.hpp:89: no match > for call to `(const > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning std::string&>) (const std::basic_string std::char_traits, > std::allocator >&)' > > Also beyond my comprehension. As the message says, you have to "specify a return value policy to wrap functions returning const std::string&." I suggest you use return_value_policy > If I do: > .def("id", &Entity::getId, return_internal_reference<>()) > it compiles, but I get the runtime exception: > TypeError: No Python class registered for C++ class std::string. Right. You're not wrapping std::string with a class_<...> (and you don't want to) so Boost.Python has no way of creating a python object that refers to the referenced std::string. > So I've now created an extra method in the Entity: const char* > getIdCStr() which returns the id.c_str(). That sorta works. > I can do in python: for i in getEntities(): print i.id() > > With .add_property("id", &Entity::getIdCStr) it works as I want it. Why didn't you use add_property in the first place? I ask because it speaks to a deficiency in the documentation. > Q2: This requires me to add methods to the Entity class (there are > several std::string attributes I need). Is there a more elegant way > to solve this? A free function taking an initial X& parameter always works just as well as a member function of X. HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From john at arbash-meinel.com Tue Nov 2 23:52:09 2004 From: john at arbash-meinel.com (John A Meinel) Date: Tue, 02 Nov 2004 16:52:09 -0600 Subject: [C++-sig] Custom Exception objects Message-ID: <41880F99.20609@arbash-meinel.com> I was wondering how to handle custom exception objects using boost::python. I know about doing this: static void translateConfigError(ConfigError const &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); } register_exception_translator(&translateConfigError); However, as far as I know, this only lets you translate a C++ exception class into a standard Python exception class. Since I have already wrapped ConfigError as a boost::python class, is it possible to do something more like: static void translateConfigError(ConfigError const &e) { PyErr_SetString(my_python_exception, e.what()); } where my_python_exception was somehow related to ConfigError? It is nice that I can at least generate KeyError, or ValueError, SyntaxError, etc, but it would be nice if I could generate ConfigError. John =:-> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 253 bytes Desc: OpenPGP digital signature URL: From mrovner at propel.com Wed Nov 3 00:16:35 2004 From: mrovner at propel.com (Mike Rovner) Date: Tue, 02 Nov 2004 15:16:35 -0800 Subject: [C++-sig] Re: Custom Exception objects In-Reply-To: <41880F99.20609@arbash-meinel.com> References: <41880F99.20609@arbash-meinel.com> Message-ID: John A Meinel wrote: > I was wondering how to handle custom exception objects using boost::python. > Since I have already wrapped ConfigError as a boost::python class, is it > possible to do something more like: suppose you have object my_python_exception = class_("ConfigError", init) ... ; > static void translateConfigError(ConfigError const &e) { > PyErr_SetString(my_python_exception, e.what()); > } than above statement will be perfectly valid HTH, Mike From blanding at localnet.com Wed Nov 3 01:15:41 2004 From: blanding at localnet.com (Doug Blanding) Date: Tue, 2 Nov 2004 19:15:41 -0500 Subject: [C++-sig] help running boost-python tutorials Message-ID: <200411021915.41602.blanding@localnet.com> I have downloaded boost_1_31_0 and have successfully gone through all of the steps of the installation, but when I try to run the tutorial examples, I get the following error when I try to import the extension module into python: ImportError: libboost_python.so.1.31.0: cannot open shared object file: No such file or directory I have Python2.2 on RH9 linux. I installed bjam as an rpm. I set the following environment variables: export PYTHON_ROOT=/usr export PYTHON_VERSION=2.2 Then I compiled boost using: bjam -sTOOLS=gcc stage Next, I cd to file: /dnld/boost_1_31_0/libs/python/example and ran the command: [doug at maven example]$ bjam -sTOOLS=gcc test ...patience... ...found 2025 targets... ...updating 40 targets... MkDir1 bin/boost ... etc. ... execute-test bin/example/test1.test/gcc/debug/test1.run **passed** bin/example/test1.test/gcc/debug/test1.test gcc-C++-action bin/example/getting_started2.so/gcc/debug/shared-linkable-true/getting_started2.o gcc-Link-action bin/example/getting_started2.so/gcc/debug/shared-linkable-true/getting_started2.so Chmod1 bin/example/getting_started2.so/gcc/debug/shared-linkable-true/getting_started2.so execute-test bin/example/test2.test/gcc/debug/test2.run **passed** bin/example/test2.test/gcc/debug/test2.test ...updated 40 targets... I then get the import error when I try to import getting_started1 or getting_started2. ImportError: libboost_python.so.1.31.0: cannot open shared object file: No such file or directory I have tried copying the files libboost_python.so.1.31.0 and libboost_python.so into various places so they can be found by python, but without success. Can you tell me what I'm doing wrong? Doug Blanding From mrovner at propel.com Wed Nov 3 01:38:23 2004 From: mrovner at propel.com (Mike Rovner) Date: Tue, 02 Nov 2004 16:38:23 -0800 Subject: [C++-sig] Re: help running boost-python tutorials In-Reply-To: <200411021915.41602.blanding@localnet.com> References: <200411021915.41602.blanding@localnet.com> Message-ID: Doug Blanding wrote: > ImportError: libboost_python.so.1.31.0: cannot open shared object file: No > such file or directory > > I have tried copying the files libboost_python.so.1.31.0 and > libboost_python.so into various places so they can be found by python, but > without success. > > Can you tell me what I'm doing wrong? > Doug Blanding did you try ldconfig after install/copy? HTH, Mike From faheem at email.unc.edu Wed Nov 3 02:29:19 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Tue, 2 Nov 2004 20:29:19 -0500 (EST) Subject: [C++-sig] Re: regarding your post entitled " Numeric--factory function" onBoost.Python In-Reply-To: <20041101154122.E18EC1E4002@bag.python.org> References: <20041101154122.E18EC1E4002@bag.python.org> Message-ID: Hi Li, Thanks for your helpful reply. Sorry you had difficulties posting to my address. If you continue to have problems, please let me know and I will report it. On Mon, 1 Nov 2004, Li Dongfeng wrote: > Hi Faheem, > >> boost::python::numeric::array arr(dim1,dim2); > --------------------------------------^^^^^^^^^ > The problem with you code is the array constructor function usage. > That function cannot be called with two integers. See the numarray > (or Numeric) docs for correct usage. Well, it was not intended to be working code, just an example of what I had in mind. > I tested some solution but cannot reach an elegant one. > An elegant solution should use the numarray(or Numeric) API > directly to access the array contents in C++. > But I have only got a make-shift solution: use the boost::python > indexing suite. After you have used the indexing suite to map C++ vector > to Python sequence type, you can use a C++ vector as a python sequence > in C++ to initialize a numarray.array. > > To map a C++ std::vector to a Python sequence type named > ``DoubleVec'', just make this boost.python extension: > > ------------------------ > #include > #include > #include > #include > #include > #include > #include > BOOST_PYTHON_MODULE(_numpyext) > { > class_ >("DoubleVec") > .def(vector_indexing_suite >()); > } > --------------- > > Then in a C++ extension module, use: > > --------------- > // std::vector conversion to numarray.array > numeric::array vec2array_double(std::vector x){ > return numeric::array(x, "Float64"); > } > BOOST_PYTHON_MODULE(_numpyext) > { > def("_cppvec2array", &vec2array_double); > } > --------------- > > this really works, the ``x'' in the numeric::array function call > is recognized by the numarray module constructor function ``array'' > as a python sequence of type ``DoubleVec''. I don't see why, if the second argument is supposed to be a list, why you can't just create a Boost::python::list in C++, and then pass it in as a argument. Isn't that equivalent? Eg. //Convert (C++) numeric matrix to (Python) Numarray numeric array. boost::python::object cppmat2pynumarr(Array2D A) { int i, j; int dim1 = A.dim1(); int dim2 = A.dim2(); boost::python::list lst; for(i=0; i A) { int i, j; int dim1 = A.dim1(); int dim2 = A.dim2(); vector vec; for(i=0; i x) { boost::python::tuple foo = make_tuple(2,2); return boost::python::numeric::array(x, "Float64", foo); } ***************************************************************** This compiles without complaint, but does not reshape the array. Furthermore, I am unclear on a fundamental point. What *is* the constructor of the Numeric array in C++? From the documentation at http://www.boost.org/libs/python/doc/v2/numeric.html I thought that these were C++ functions called factory. The documentation says "These functions map to the underlying array type's array() function family. They are not called "array" because of the C++ limitation that you can't define a member function with the same name as its enclosing class." I'm not sure what this means. How are you supposed to call them? Does numeric::array call these functions? I could not find any relevant examples. There are examples in the examples directory in numpy.cc, but I am not sure what to make of ************************************************************************ object new_array() { return numeric::array( make_tuple( make_tuple(1,2,3) , make_tuple(4,5,6) , make_tuple(7,8,9) ) ); } ************************************************************************* This works, but how do I generalise it to do what I want, and which constructor does this belong to? and ************************************************************************* void exercise_numarray(numeric::array& y, object check) { ... check(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(1,2,1))); ... ************************************************************************* What is that y doing, if this is a constructor? Looks more like a member function. I've tried variations on this too, but get errors at runtime. So you can see I am quite confused. Thanks again. Faheem. From faheem at email.unc.edu Wed Nov 3 05:18:48 2004 From: faheem at email.unc.edu (Faheem Mitha) Date: Tue, 2 Nov 2004 23:18:48 -0500 (EST) Subject: [C++-sig] Re: regarding your post entitled " Numeric--factory function" onBoost.Python In-Reply-To: References: <20041101154122.E18EC1E4002@bag.python.org> Message-ID: On Tue, 2 Nov 2004, Faheem Mitha wrote: > > Hi Li, > > Thanks for your helpful reply. [snip] Hi Li, I solved it! (I think). I was using a function that converted a matrix to a list of lists, where each list corresponded to a row of the matrix. Just looking at the example below (in my earlier mail) ************************************************************************ object new_array() { return numeric::array( make_tuple( make_tuple(1,2,3) , make_tuple(4,5,6) , make_tuple(7,8,9) ) ); } ************************************************************************* made me realise that wrapping the final return result (list of lists) in a numeric::array might work, since apparently the constructor accepted this kind of syntax. Well, apparently it does, though I don't understand why. I don't see this constructor documented anywhere. Also, I don't understand why my previous attempts don't work. See function below. If you can enlighten me about any of this, please do so. Thanks. Faheem. ************************************************************************* // Convert (C++) numeric matrix to (Python) list. boost::python::object cppmat2pynumarr(Array2D A) { int i, j; int dim1 = A.dim1(); int dim2 = A.dim2(); boost::python::list lst; boost::python::list rowlst; // Copy matrix to python list for(i=0; i I have a member function which returns an object and I'm trying to define a call policy for that member function which will: 1. cause the returned object to be managed: return_value_policy() its a new object and needs to be managed. 2. register that the returned object holds a reference to the originating object (but not visa-versa) but I can't work out how to combine the two. I need 1. above because the returned object is new and needs to be managed. I need 2. above because this returned object has references BACK to the object who's member function supplies it. So the returned object can be destroyed without the original being effected, but destruction of the original MUST wait until the returned object is gone. Some code which hopes to capture this ... --------------------------------------------------------------------- class Orig; class Fresh { public: Fresh(Orig* o) : o_(o) {} Orig* o_; }; class Orig { public: Fresh* newFresh() { return new Fresh(this); } }; --------------------------------------------------------------------- class_("Orig", no_init) .def("newFresh", &Orig::newFresh, XXXXX) ; --------------------------------------------------------------------- What should XXXXX be?? Help greatly appreciated. I can't work this out from the tutorial and test harness code. -- Mike From domma at procoders.net Thu Nov 4 11:28:28 2004 From: domma at procoders.net (Achim Domma (Procoders)) Date: Thu, 04 Nov 2004 11:28:28 +0100 Subject: [C++-sig] python extension and bjam stage Message-ID: <418A044C.2030909@procoders.net> Hi, I cannot figure out how to use the stage rule with boost.python. Could somebody give me an example? regards, Achim From dave at boost-consulting.com Thu Nov 4 15:01:17 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 04 Nov 2004 09:01:17 -0500 Subject: [C++-sig] Re: Call Policy Question References: Message-ID: Mike Thompson writes: > I have a member function which returns an object and I'm trying to > define a call policy for that member function which will: > 1. cause the returned object to be managed: > return_value_policy() > its a new object and needs to be managed. > > 2. register that the returned object holds a > reference to the originating object (but not visa-versa) > > but I can't work out how to combine the two. > > I need 1. above because the returned object is new and needs to be managed. > > I need 2. above because this returned object has references BACK > to the object who's member function supplies it. > > So the returned object can be destroyed without the original being > effected, but destruction of the original MUST wait until the returned > object is gone. return_value_policy< manage_new_object , with_custodian_and_ward<0, 1> > should work. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From achim.domma at syynx.de Thu Nov 4 16:15:34 2004 From: achim.domma at syynx.de (Achim Domma) Date: Thu, 04 Nov 2004 16:15:34 +0100 Subject: [C++-sig] Pyste Error Message-ID: <418A4796.70004@syynx.de> Hi, could somebody explain to me, what could cause the error below? I have no idea what's going wrong. regards, Achim Traceback (most recent call last): File "/usr/bin/pyste.py", line 4, in ? pyste.main() File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 418, in main status = Begin() File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 257, in Begin return GenerateCode(parser, module, out, interfaces, multiple) File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 363, in GenerateCode exports.extend(order[interface]) KeyError: 'pyste_files/DrawablePushClipPath.pyste' From john at johnmeinel.com Sat Nov 6 15:51:19 2004 From: john at johnmeinel.com (John A Meinel) Date: Sat, 06 Nov 2004 08:51:19 -0600 Subject: [C++-sig] Re: Custom Exception objects In-Reply-To: References: <41880F99.20609@arbash-meinel.com> Message-ID: <418CE4E7.3080804@johnmeinel.com> Mike Rovner wrote: > John A Meinel wrote: > >> I was wondering how to handle custom exception objects using >> boost::python. > > >> Since I have already wrapped ConfigError as a boost::python class, is >> it possible to do something more like: > > > suppose you have > > object my_python_exception = > class_("ConfigError", init) > ... > ; > >> static void translateConfigError(ConfigError const &e) { >> PyErr_SetString(my_python_exception, e.what()); >> } > > > than above statement will be perfectly valid > > HTH, > Mike > So am I right in saying I need something like this: static object my_custom_exc; static void translateCustomError(CustomError const &e) { PyErr_SetString(my_custom_exc, e.what()); } void exportCustom() { my_custom_exc = class_ , >("CustomError") .def("what", &CustomError::what) ; register_exception_translator(&translateCustomError); } Basically, the object has to be a global since the translate function needs access to it. John =:-> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 253 bytes Desc: OpenPGP digital signature URL: From nicodemus at esss.com.br Sun Nov 7 06:38:49 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Sun, 07 Nov 2004 02:38:49 -0300 Subject: [C++-sig] Pyste Error In-Reply-To: <418A4796.70004@syynx.de> References: <418A4796.70004@syynx.de> Message-ID: <418DB4E9.4080108@esss.com.br> Hi Achim, Can you post a small example that reproduces this error? It would be very helpful! Regards, Bruno. Achim Domma wrote: > Hi, > > could somebody explain to me, what could cause the error below? I have > no idea what's going wrong. > > regards, > Achim > > > Traceback (most recent call last): > File "/usr/bin/pyste.py", line 4, in ? > pyste.main() > File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 418, in > main > status = Begin() > File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 257, in > Begin > return GenerateCode(parser, module, out, interfaces, multiple) > File "/usr/lib/python2.3/site-packages/Pyste/pyste.py", line 363, in > GenerateCode > exports.extend(order[interface]) > KeyError: 'pyste_files/DrawablePushClipPath.pyste' > > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From jdhunter at ace.bsd.uchicago.edu Mon Nov 8 16:27:25 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 08 Nov 2004 09:27:25 -0600 Subject: [C++-sig] typedef'd unnamed enum / pyste Message-ID: I am using boost_python 1.31.0 with pyste and gccxml-0.6.0, and am trying to wrap an enum defined like typedef unsigned char cover_type; //----cover_type enum { cover_shift = 8, //----cover_shift cover_size = 1 << cover_shift, //----cover_size cover_mask = cover_size - 1, //----cover_mask cover_none = 0, //----cover_none cover_full = cover_mask //----cover_full }; How does one wrap an enum like this in pyste? If I try the naive, Enum("agg::cover_type", "agg_basics.h") I get an exception in pyste, included below -- the enum object appears to not have the values attribute. FYI, other functions that I need to wrap will pass cover_type args as well as cover_type arrays. Thanks for any help, I've read though some of the archives on how to handle unnamed enums, but wasn't able to grok the answers to figure out what I should do. JDH peds-pc311:~/python/projects/aggboost> pyste.py -I/usr/local/include/agg --module=bagg --out=src/basics.cpp pyste/basics.pyste gccxml -I "/tmp" -I "/usr/local/include/agg" /tmp/tmpBsdOix.h -fxml=/tmp/tmpDRjYOM.xml /tmp/tmpDRjYOM.xml Traceback (most recent call last): File "/usr/local/bin/pyste.py", line 4, in ? pyste.main() File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 405, in main status = Begin() File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 244, in Begin return GenerateCode(parser, module, out, interfaces, multiple) File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 372, in GenerateCode export.GenerateCode(codeunit, exported_names) File "/usr/local/lib/python2.3/site-packages/Pyste/Exporter.py", line 50, in GenerateCode self.Export(codeunit, exported_names) File "/usr/local/lib/python2.3/site-packages/Pyste/EnumExporter.py", line 44, in Export for name in self.enum.values: AttributeError: 'Typedef' object has no attribute 'values' [2] - Done sudo emacs -q /usr/local/lib/python2.3/site-packages/Pyste/EnumExporter.py From jdhunter at ace.bsd.uchicago.edu Mon Nov 8 16:58:49 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 08 Nov 2004 09:58:49 -0600 Subject: [C++-sig] pyste and template functions Message-ID: I am using pyste to wrap a template function. I have used Template successfully to wrap a templated class, but this does not appear to support template functions (at least I didn't see anything in the docs). I can manually do it with module_code module_code('def("intersect_rectangles", &agg::intersect_rectangles);'); module_code('def("intersect_rectangles_d", &agg::intersect_rectangles);'); Is there a way to do this directly in pyste? Thanks! JDH boost_python 1.31.0 with pyste and gccxml-0.6.0 From jdhunter at ace.bsd.uchicago.edu Mon Nov 8 18:46:19 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 08 Nov 2004 11:46:19 -0600 Subject: [C++-sig] pyste + wrapping + overloads Message-ID: I am trying to wrap a class method in pyste that has a signature void path_storage::add_poly(const double* vertices, unsigned num, bool solid_path, unsigned end_flags) vertices is a length 2*num array of x,y doubles x0, y0, x1, y1, .... I am using the following wrapper void add_poly_wrapper(agg::path_storage* ps, list vertices, bool solid_path = false, unsigned end_flags = agg::path_flags_none) { size_t N = extract(vertices.attr("length")()); double * pverts = new double[2*N]; for (size_t i=0; i(vertices[i]); *pverts++ = extract(xy[0]); *pverts++ = extract(xy[1]); } pverts -= 2*N; //rewind ps->add_poly(pverts, N, solid_path, end_flags); } The first problem I've encountered in pyste is that the standard way of specifying wrappers Include("path_storage_wrap.h") PS = Class("agg::path_storage", "agg_path_storage.h") set_wrapper(PS.add_poly, "add_poly_wrapper") doesn't work because there is no PS.add_poly, since pyste defines it with the overload macro BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(agg_path_storage_add_poly_overloads_2_4, add_poly, 2, 4) How does one specify wrappers for overloaded functions? I don't know enough about the overload macro internals to figure out how to proceed... Thanks, JDH boost_python 1.31.0 with pyste and gccxml-0.6.0 From mrovner at propel.com Mon Nov 8 19:09:36 2004 From: mrovner at propel.com (Mike Rovner) Date: Mon, 08 Nov 2004 10:09:36 -0800 Subject: [C++-sig] Re: Custom Exception objects In-Reply-To: <418CE4E7.3080804@johnmeinel.com> References: <41880F99.20609@arbash-meinel.com> <418CE4E7.3080804@johnmeinel.com> Message-ID: John A Meinel wrote: > Basically, the object has to be a global since the translate function > needs access to it. I'm not sure what are you asking. Let's return to basic. a. If you have C++ exception that you need to register_exception_translator. b. If you want to expose your exception, you wrap it in a class_. c. Scope rules are basically normal python rules: in order to use exception you need to have in in your local or global namespace. Combining all three you example is a possible implementation. Best, Mike From jdhunter at ace.bsd.uchicago.edu Mon Nov 8 23:08:25 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 08 Nov 2004 16:08:25 -0600 Subject: [C++-sig] pyste and operator* Message-ID: I have a class agg::path_storage which nests another class agg::path_storage::const_iterator that defines operator*(). When I run pyste on this file, I get a compile time error src/test.cpp: In function `void init_module_tagg()': src/test.cpp:22: error: no match for 'operator*' in '* boost::python::self_ns::self' error: command 'gcc' failed with exit status 1 The part of the boost generated code that is failing is the .def( *self ) line in class_< agg::path_storage::const_iterator >("const_iterator", init< >()) .def(init< const agg::path_storage::const_iterator& >()) .def( *self ) ; I tried removing operator* in pyste, but did not succeed. Here is my complete test.pyste file PS = Class("agg::path_storage", "test.h") CI = Class("agg::path_storage::const_iterator", "test.h") exclude(CI.operator['*']) and here is the minimal test.h example code that is failing namespace agg { struct vertex_type { double x, y; unsigned cmd; vertex_type() {} vertex_type(double x_, double y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {} }; class path_storage { public: class const_iterator { public: const_iterator() {} const vertex_type& operator*() const { return m_vertex; } private: vertex_type m_vertex; }; ~path_storage() {}; path_storage() {}; }; } Thanks, JDH boost_python 1.31.0 with pyste and gccxml-0.6.0 From jdhunter at ace.bsd.uchicago.edu Tue Nov 9 00:40:46 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 08 Nov 2004 17:40:46 -0600 Subject: [C++-sig] pyste and return reference problem Message-ID: I have found what looks like pyste bug. pyste wraps the following struct struct C { const C& func(double val) {return *this;} double func() {return 0.0;} }; as class_< C >("C", init< >()) .def(init< const C& >()) .def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >()) .def("func", (double (C::*)() )&C::func, return_value_policy< copy_const_reference >()) ; Note that (double (C::*)() )&C::func has a call policy of return_value_policy< copy_const_reference >()). If you reverse the order of the method definitions in C, ie struct C { double func() {return 0.0;} const C& func(double val) {return *this;} }; pyste gets it right class_< C >("C", init< >()) .def(init< const C& >()) .def("func", (double (C::*)() )&C::func) .def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >()) ; This leads me to a question related to one of my earlier questions: when wrapping overloaded functions as above, is there a way to differentially set the call policies in pyste for the different signatures. I know one can use as described in the docs set_policy(f, return_internal_reference()) set_policy(C.foo, return_value_policy(manage_new_object)) How does one do this for overloaded functions? Sorry for the deluge of mail! I'm going home now :-) JDH boost_python 1.31.0 with pyste and gccxml-0.6.0 From dholth at fastmail.fm Tue Nov 9 02:34:46 2004 From: dholth at fastmail.fm (Daniel Holth) Date: Mon, 08 Nov 2004 20:34:46 -0500 Subject: [C++-sig] Microsoft Visual C++ Toolkit 2003 (command line) boost.python Message-ID: <1099964086.5632.208244874@webmail.messagingengine.com> Can someone help me to compile boost.python with this freely downloadable Microsoft compiler, http://msdn.microsoft.com/visualc/vctoolkit2003/? I have not yet been able to get boost to find this compiler that installs itself in c:\Program Files\Microsoft Visual C++ Toolkit 2003\bin Thanks, Daniel From caustin at gmail.com Tue Nov 9 05:14:02 2004 From: caustin at gmail.com (Chad Austin) Date: Mon, 8 Nov 2004 22:14:02 -0600 Subject: [C++-sig] vector of shared_ptr ? Message-ID: <2096514e0411082014a1d1120@mail.gmail.com> I am trying to export a vector of smart pointers to Python using vector_indexing_suite. Here is a test case: // Begin C++ Code #include #include #include #include using namespace boost; using namespace boost::python; class A { }; typedef shared_ptr APtr; typedef std::vector AList; BOOST_PYTHON_MODULE(ptrvector) { class_("A") ; register_ptr_to_python(); class_("AList") .def(vector_indexing_suite()) ; } // End C++ Code I would expect the following test case to succeed: # Begin Python Code from ptrvector import * a = AList() a[:] = [A()] for b in a: print b # End Python Code However, I get an error: $ python test.py Traceback (most recent call last): File "test.py", line 4, in ? for b in a: TypeError: No Python class registered for C++ class boost::shared_ptr Is this a known bug? Is there anything I can do to work around or fix this? Thanks, Chad From roman.yakovenko at gmail.com Tue Nov 9 05:50:18 2004 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 9 Nov 2004 06:50:18 +0200 Subject: [C++-sig] typedef'd unnamed enum / pyste In-Reply-To: References: Message-ID: <7465b61704110820505e09c961@mail.gmail.com> On Mon, 08 Nov 2004 09:27:25 -0600, John Hunter wrote: > > I am using boost_python 1.31.0 with pyste and gccxml-0.6.0, and am > trying to wrap an enum defined like > > typedef unsigned char cover_type; //----cover_type Pyste is right cover_type is typedef to unsigned char. You try to expose it as enum ??? You made a mistake. > enum > { > cover_shift = 8, //----cover_shift > cover_size = 1 << cover_shift, //----cover_size > cover_mask = cover_size - 1, //----cover_mask > cover_none = 0, //----cover_none > cover_full = cover_mask //----cover_full > }; > > How does one wrap an enum like this in pyste? If I try the naive, > > Enum("agg::cover_type", "agg_basics.h") Enum( "cover_mask", "agg_basics.h" ) should work > > I get an exception in pyste, included below -- the enum object appears > to not have the values attribute. > > FYI, other functions that I need to wrap will pass cover_type args as > well as cover_type arrays. > > Thanks for any help, I've read though some of the archives on how to > handle unnamed enums, but wasn't able to grok the answers to figure > out what I should do. > > JDH > > peds-pc311:~/python/projects/aggboost> pyste.py -I/usr/local/include/agg --module=bagg --out=src/basics.cpp pyste/basics.pyste > gccxml -I "/tmp" -I "/usr/local/include/agg" /tmp/tmpBsdOix.h -fxml=/tmp/tmpDRjYOM.xml > /tmp/tmpDRjYOM.xml > Traceback (most recent call last): > File "/usr/local/bin/pyste.py", line 4, in ? > pyste.main() > File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 405, in main > status = Begin() > File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 244, in Begin > return GenerateCode(parser, module, out, interfaces, multiple) > File "/usr/local/lib/python2.3/site-packages/Pyste/pyste.py", line 372, in GenerateCode > export.GenerateCode(codeunit, exported_names) > File "/usr/local/lib/python2.3/site-packages/Pyste/Exporter.py", line 50, in GenerateCode > self.Export(codeunit, exported_names) > File "/usr/local/lib/python2.3/site-packages/Pyste/EnumExporter.py", line 44, in Export > for name in self.enum.values: > AttributeError: 'Typedef' object has no attribute 'values' > [2] - Done sudo emacs -q /usr/local/lib/python2.3/site-packages/Pyste/EnumExporter.py > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From roman.yakovenko at gmail.com Tue Nov 9 05:53:37 2004 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 9 Nov 2004 06:53:37 +0200 Subject: [C++-sig] pyste and template functions In-Reply-To: References: Message-ID: <7465b6170411082053b0531ab@mail.gmail.com> On Mon, 08 Nov 2004 09:58:49 -0600, John Hunter wrote: > > I am using pyste to wrap a template function. I have used Template > successfully to wrap a templated class, but this does not appear to > support template functions (at least I didn't see anything in the > docs). > > I can manually do it with module_code > > module_code('def("intersect_rectangles", &agg::intersect_rectangles);'); > module_code('def("intersect_rectangles_d", &agg::intersect_rectangles);'); My guess - this has nothing to do with Pyste, but with C++. I think you should have instantiate the function explicitly in code. only then you can expose it. But I could be wrong. > Is there a way to do this directly in pyste? > > Thanks! > JDH > > boost_python 1.31.0 with pyste and gccxml-0.6.0 > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From roman.yakovenko at gmail.com Tue Nov 9 05:56:59 2004 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 9 Nov 2004 06:56:59 +0200 Subject: [C++-sig] pyste and operator* In-Reply-To: References: Message-ID: <7465b61704110820565ab5edcf@mail.gmail.com> On Mon, 08 Nov 2004 16:08:25 -0600, John Hunter wrote: > > I have a class agg::path_storage which nests another class > agg::path_storage::const_iterator that defines operator*(). When I > run pyste on this file, I get a compile time error > > src/test.cpp: In function `void init_module_tagg()': > src/test.cpp:22: error: no match for 'operator*' in '* > boost::python::self_ns::self' > error: command 'gcc' failed with exit status 1 > > The part of the boost generated code that is failing is the .def( > *self ) line in > > class_< agg::path_storage::const_iterator >("const_iterator", init< >()) > .def(init< const agg::path_storage::const_iterator& >()) > .def( *self ) > ; > > I tried removing operator* in pyste, but did not succeed. Here is my > complete test.pyste file > > PS = Class("agg::path_storage", "test.h") > CI = Class("agg::path_storage::const_iterator", "test.h") > exclude(CI.operator['*']) > > and here is the minimal test.h example code that is failing > > namespace agg > { > struct vertex_type > { > double x, y; > unsigned cmd; > > vertex_type() {} > vertex_type(double x_, double y_, unsigned cmd_) : > x(x_), y(y_), cmd(cmd_) {} > }; > > class path_storage > { > public: > > class const_iterator > { > > public: > const_iterator() {} > const vertex_type& operator*() const { return m_vertex; } This operation is meaningless \doesn't exis in python. If you still want to expose it - expose it as regular function > > private: > vertex_type m_vertex; > }; > > ~path_storage() {}; > path_storage() {}; > > }; > } > > Thanks, > JDH > > boost_python 1.31.0 with pyste and gccxml-0.6.0 > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > From jdhunter at ace.bsd.uchicago.edu Tue Nov 9 15:55:46 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 09 Nov 2004 08:55:46 -0600 Subject: [C++-sig] pyste and operator* In-Reply-To: <7465b61704110820565ab5edcf@mail.gmail.com> (Roman Yakovenko's message of "Tue, 9 Nov 2004 06:56:59 +0200") References: <7465b61704110820565ab5edcf@mail.gmail.com> Message-ID: >>>>> "Roman" == Roman Yakovenko writes: John> I tried removing operator* in pyste, but did not succeed. Here John> is my complete test.pyste file John> John> public: const_iterator() {} const vertex_type& operator*() John> const { return m_vertex; } Roman> This operation is meaningless \doesn't exis in python. Right, which is why I tried to remove it with CI = Class("agg::path_storage::const_iterator", "test.h") exclude(CI.operator['*']) Unfortunately, pyste still generates the line .def( *self ) which is the problem I addressed in my OP. Thanks, JDH From dave at boost-consulting.com Tue Nov 9 16:25:43 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 09 Nov 2004 10:25:43 -0500 Subject: [C++-sig] Re: pyste and template functions References: <7465b6170411082053b0531ab@mail.gmail.com> Message-ID: Roman Yakovenko writes: > On Mon, 08 Nov 2004 09:58:49 -0600, John Hunter > wrote: >> >> I am using pyste to wrap a template function. I have used Template >> successfully to wrap a templated class, but this does not appear to >> support template functions (at least I didn't see anything in the >> docs). >> >> I can manually do it with module_code >> >> module_code('def("intersect_rectangles", &agg::intersect_rectangles);'); >> module_code('def("intersect_rectangles_d", &agg::intersect_rectangles);'); > > My guess - this has nothing to do with Pyste, but with C++. > I think you should have instantiate the function explicitly in code. > only then you can expose > it. But I could be wrong. That's wrong. You can't wrap a function template, though. You can only wrap a particular specialization of that function template. I'm not sure what you're doing that isn't working, though. You only showed what worked. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From dave at boost-consulting.com Tue Nov 9 16:29:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 09 Nov 2004 10:29:50 -0500 Subject: [C++-sig] Re: pyste and operator* References: <7465b61704110820565ab5edcf@mail.gmail.com> Message-ID: Roman Yakovenko writes: >> class const_iterator >> { >> >> public: >> const_iterator() {} >> const vertex_type& operator*() const { return m_vertex; } > > This operation is meaningless \doesn't exis in python. If you still > want to expose > it - expose it as regular function On the other hand there ought to be some way to get pyste to expose C++ iterators as Python iterators. See http://www.boost.org/libs/python/doc/v2/iterator.html -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From jdhunter at ace.bsd.uchicago.edu Tue Nov 9 16:38:59 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 09 Nov 2004 09:38:59 -0600 Subject: [C++-sig] typedef'd unnamed enum / pyste In-Reply-To: <7465b61704110820505e09c961@mail.gmail.com> (Roman Yakovenko's message of "Tue, 9 Nov 2004 06:50:18 +0200") References: <7465b61704110820505e09c961@mail.gmail.com> Message-ID: >>>>> "Roman" == Roman Yakovenko writes: >> >> typedef unsigned char cover_type; //----cover_type Roman> Pyste is right cover_type is typedef to unsigned char. You Roman> try to expose it as enum ??? You made a mistake. Yes, I'm a moron. Thanks! typedef unsigned char cover_type; //----cover_type enum { cover_shift = 8, //----cover_shift cover_size = 1 << cover_shift, //----cover_size cover_mask = cover_size - 1, //----cover_mask cover_none = 0, //----cover_none cover_full = cover_mask //----cover_full }; Roman> Enum( "cover_mask", "agg_basics.h" ) should work It doesn't. I was, however, able to do it manually with module_code(""" enum_("cover") .value("cover_shift", agg::cover_shift) .value("cover_size", agg::cover_size) .value("cover_mask", agg::cover_mask) .value("cover_none", agg::cover_none) .value("cover_full", agg::cover_full) ; """) but as always, I'm looking for the best pyste/boost::python way to do it, so any other suggestions on the best way to export unnamed enums in pyste welcome! Thanks, JDH From jdhunter at ace.bsd.uchicago.edu Tue Nov 9 16:47:46 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 09 Nov 2004 09:47:46 -0600 Subject: [C++-sig] Re: pyste and template functions In-Reply-To: (David Abrahams's message of "Tue, 09 Nov 2004 10:25:43 -0500") References: <7465b6170411082053b0531ab@mail.gmail.com> Message-ID: >>>>> "David" == David Abrahams writes: David> I'm not sure what you're doing that isn't working, though. David> You only showed what worked. Oops. I tried following the approach for template classes Intersect = Template("agg::intersect_rectangles", "agg_basics.h") Intersect("agg::rect", "intersect_rectangles") Intersect("agg::rect_d", "intersect_rectangles_d") where the signature for the template function intersect_rectangles is template inline Rect intersect_rectangles(const Rect& r1, const Rect& r2) pyste generates the following code (line number 321 marked for compiler error reference below) 321-> typedef agg::intersect_rectangles< agg::rect > intersect_rectangles; void __instantiate_intersect_rectangles() { sizeof(intersect_rectangles); } typedef agg::intersect_rectangles< agg::rect_d > intersect_rectangles_d; void __instantiate_intersect_rectangles_d() { sizeof(intersect_rectangles_d); } which causes gccxml to die with /tmp/tmpcfn9df.h:321: error: syntax error before `;' token /tmp/tmpcfn9df.h: In function `void __instantiate_intersect_rectangles()': /tmp/tmpcfn9df.h:323: error: ISO C++ forbids applying `sizeof' to an expression of function type where line 321 is indicated above. I assumed thusly that pyste either did not handle template functions or at least I didn't know how to handle them in pyste, so I reverted to the module_code I mentioned above. Thanks! JDH From jdhunter at ace.bsd.uchicago.edu Tue Nov 9 18:17:47 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 09 Nov 2004 11:17:47 -0600 Subject: [C++-sig] pyste instantiating templates Message-ID: I have a template class in someclass.h that is instantiated over sometype.h. someclass.h does not #include sometype.h. If I try the standard way of instantiating templates in pyste SomeTemplate = Template("SomeClass", "someclass.h") TemplateSometype = SomeTemplate("Sometype", "template_sometype") I get a gccxml error because SomeType is not known in someclass.h. It would be nice to be able to tell pyste in the tmp*.h files it generates to pass to gccxml, to include some additional headers. Is this possible? None of Include, declaration_code or module_code seem to fit the bill here, since I want to include code into the file that I am actually wrapping. I worked around it by creating a instantiate_someclass.h #include sometype.h #include someclass.h and then doing SomeTemplate = Template("SomeClass", "instantiate_someclass.h") TemplateSometype = SomeTemplate("Sometype", "template_sometype") JDH From abentley at panoramicfeedback.com Tue Nov 9 21:08:42 2004 From: abentley at panoramicfeedback.com (Aaron Bentley) Date: Tue, 9 Nov 2004 20:08:42 +0000 (UTC) Subject: [C++-sig] boost.Python/Jam with shared libraries Message-ID: Hi, I'm trying to add a python interface to some of the functionality in an existing app. I've managed to get a test version to compile, but the result doesn't work because shared libraries (both commonly-available and app-specific) in are required for our app. I've tried modifying the Jamfile as suggested in the wiki, adding library-dir and library-file directives, but I get /home/abentley/install/boost_1_31_0/tools/build/v1/boost-base.jam:1972: in expand-target-subvariants rule /home/abentley/programming/.libs/libpanutil.so unknown in module We're usin Autoconf in the rest of the project, and I must admit my approach to Makefile.am is mostly a cargo-cult mentality-- I wouldn't know the correct way to link shared objects by hand. Can anyone help? Aaron From grafik.list at redshift-software.com Tue Nov 9 22:52:52 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Tue, 09 Nov 2004 15:52:52 -0600 Subject: [C++-sig] boost.Python/Jam with shared libraries In-Reply-To: References: Message-ID: <41913C34.8090507@redshift-software.com> Aaron Bentley wrote: > I'm trying to add a python interface to some of the functionality in an existing > app. I've managed to get a test version to compile, but the result doesn't work > because shared libraries (both commonly-available and app-specific) in are > required for our app. > > I've tried modifying the Jamfile as suggested in the wiki, adding library-dir > and library-file directives, but I get Which Jamfile? > Can anyone help? Probably. But we would need more information. Like answering the above question. And providing the Jamfile you have. At least. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From grafik.list at redshift-software.com Tue Nov 9 22:57:32 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Tue, 09 Nov 2004 15:57:32 -0600 Subject: [C++-sig] Re: python extension and bjam stage In-Reply-To: <418A044C.2030909@procoders.net> References: <418A044C.2030909@procoders.net> Message-ID: <41913D4C.9080401@redshift-software.com> Achim Domma (Procoders) wrote: > I cannot figure out how to use the stage rule with boost.python. Could > somebody give me an example? I don't have a complete example, all you should need to do is add a reference to the extension into the sources section of the stage target: stage mystage : myextension ; -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From abentley at panoramicfeedback.com Tue Nov 9 23:14:58 2004 From: abentley at panoramicfeedback.com (Aaron Bentley) Date: Tue, 9 Nov 2004 22:14:58 +0000 (UTC) Subject: [C++-sig] Re: boost.Python/Jam with shared libraries References: <41913C34.8090507@redshift-software.com> Message-ID: Rene Rivera redshift-software.com> writes: > > Which Jamfile? > > > Can anyone help? > > Probably. But we would need more information. Like answering the above > question. And providing the Jamfile you have. At least. > Here's the Jamfile in question: # Copyright David Abrahams 2003. See accompanying LICENSE for terms # and conditions of use. # This is the top of our own project tree project-root ; # Declares the following targets: # # 1. an extension module called "getting_started1", which is # built from "getting_started1.cpp". Built by default # # 2. A test target called my-test.test which runs # test_getting_started1.py with the extension module above. Built # when out-of date, but only if invoked by name or if the global # "test" target is invoked. # # 3. A test target called my-test.run wihch runs the above test # unconditionally. Built only when invoked by name. # # To see verbose test output, add "-sPYTHON_TEST_ARGS=-v" to the bjam # command-line before the first target. # # Include definitions needed for Python modules import python ; # ----- getting_started2 ------- # Declare a Python extension called pfengine extension pfengine : # sources pfengine.cpp #libraries : # ../.libs /home/abentley/programming/.libs/libpanutil.so # libpantemplate.la # libpanpdfgen.la # libpancompile.la # libpanconsult.la # libpanelement.la # libpanlang.la # libpancore.la # libpanexport.la # libpanreport.la # libpancgi.la # libchart.la # libecommerce.la # requirements and dependencies for Boost.Python extensions