From dave at boost-consulting.com Fri Jan 2 19:16:24 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Jan 2004 13:16:24 -0500 Subject: [C++-sig] Re: Sharing Singleton instances across boost.python extension modules References: <20031008231316.40956.qmail@web41502.mail.yahoo.com> Message-ID: Joel Gerard writes: > Hi all, > > How do I share singleton instances across extension modules in Windows? For > instance, if I have an instance of a memory manager in one DLL, how do I use > the same memory manager in the other? > > I realise this is a big question, but any links, references etc would be > appreciated. Is it even possible? Sorry it took so long to answer this, Joel. I don't think you need to do anything special to "share singleton instances across extension modules". It should "just work"... depending what, precisely, you have in mind. If you could say a little more about what you need, that might help. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Jan 2 19:16:57 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 02 Jan 2004 13:16:57 -0500 Subject: [C++-sig] Re: class_<>::add_property() on CVS-HEAD References: <1067397479.30557.10.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > The following example demonstrates a method of using add_property that > works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). > The example posted is somewhat useless as-is, but demonstrates something > that I started using for properties with non-trivial accessors. > > Is there a replacement for this functionality? Should be fixed now. -- Dave Abrahams Boost Consulting www.boost-consulting.com From jbrandmeyer at earthlink.net Sat Jan 3 19:18:07 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Sat, 03 Jan 2004 13:18:07 -0500 Subject: [C++-sig] Re: class_<>::add_property() on CVS-HEAD In-Reply-To: References: <1067397479.30557.10.camel@illuvatar> Message-ID: <1073153886.32254.12.camel@illuvatar> On Fri, 2004-01-02 at 13:16, David Abrahams wrote: > Jonathan Brandmeyer writes: > > > The following example demonstrates a method of using add_property that > > works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). > > The example posted is somewhat useless as-is, but demonstrates something > > that I started using for properties with non-trivial accessors. > > > > Is there a replacement for this functionality? > > Should be fixed now. Works for me. Thanks, Jonathan Brandmeyer From luszczek1 at netscape.net Sun Jan 4 04:47:56 2004 From: luszczek1 at netscape.net (luszczek1 at netscape.net) Date: Sat, 03 Jan 2004 22:47:56 -0500 Subject: [C++-sig] Advanced (?) compiling, freezing, translating Python Message-ID: <312735AC.3841CC26.0331AA34@netscape.net> Hi, here's my problem: - I know it will take me 10 times as long to write a code in C than in Python - I need the speed of the C version - my program cannot depend/require on Python interpreter/libraries/modules Is there a way to write Python program that almost looks like (say) C and then transoform it into C. Transformation should be intelligent - I don't want dynamic objects with dictionaries of methods. I'm willing to provide type descriptions so when I say: myList = [0] * 100 I get in C: int *myList; myList = calloc(100, sizeof(int)); I'm aware of projects like Pyrex, Psyco, and Pypy but their scope is too broad: they are about Python in its entirety and dynamism. There was also discussion some time back about adding static typing to Python. This is not what I'm thinking about either. I gave C as an example, but what I meant was translating Python into another language with some additional guidance (command-line optons or "header files"). I believe that Python is rich enough to express most of semantics of most of languages. For example, C++ templates are included in Python by default: In Python: def sum(aList): v = 0 for e in aList: v += e In C++: template sum(Vector aList) {...} In case anybody would care, even primitive data types from C/C++ like float, short, etc. can be emulated in Python with array module. I don't see equivalence to C++ reference, value, and pointer semantics, but most folks can live without it. Does anything like this exist? Would anybody find it useful? With compiler module now in standard Python, it seems like an easy job. Or am I missing something? Peter __________________________________________________________________ New! Unlimited Access from the Netscape Internet Service. Beta test the new Netscape Internet Service for only $1.00 per month until 3/1/04. Sign up today at http://isp.netscape.com/register Act now to get a personalized email address! Netscape. Just the Net You Need. From jepler at unpythonic.net Sun Jan 4 05:01:28 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 3 Jan 2004 22:01:28 -0600 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python In-Reply-To: <312735AC.3841CC26.0331AA34@netscape.net> References: <312735AC.3841CC26.0331AA34@netscape.net> Message-ID: <20040104040128.GA18000@unpythonic.net> Here's one more link to add to the list of things that aren't what you're looking for: http://www.strout.net/python/ai/ (at the "python2c" heading) Jeff From jbrandmeyer at earthlink.net Sun Jan 4 06:04:40 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Sun, 04 Jan 2004 00:04:40 -0500 Subject: [C++-sig] object.slice() infinite recursion bug Message-ID: <1073192680.5886.15.camel@illuvatar> This simple test demonstrates a bug in Boost.Python that results in infinite recursion (and a subsequent crash) whenever you make a slice using slice_nil for the upper and lower bounds. I originally discovered it with the array class, but it also exists in the object class, so that is what I'm putting up here. This crash is exhibited with 1.30 and CVS HEAD using both Python 2.2 and Python 2.3 with GCC 3.3.2. -Jonathan Brandmeyer ------------------------------------recurse.cpp------ #include void test_slice_recursion( boost::python::object arr) { // Haven't really found the right combination of using declarations // to use _ directly, yet. using namespace boost::python; arr.slice(_,_) = 2.0; } BOOST_PYTHON_MODULE(recurse) { using boost::python::def; def( "recurse", &test_slice_recursion); } --------------------------------------recurse.py--- from recurse import recurse # Should throw an exception for a list, but I get # "segmentation fault" recurse( [1, 2, 3]) From dave at boost-consulting.com Sun Jan 4 14:11:42 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 04 Jan 2004 08:11:42 -0500 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python References: <312735AC.3841CC26.0331AA34@netscape.net> Message-ID: luszczek1 at netscape.net writes: > Hi, > > here's my problem: > > - I know it will take me 10 times as long to write a code in C than in > Python > - I need the speed of the C version > - my program cannot depend/require on Python > interpreter/libraries/modules > > Is there a way to write Python program that almost looks like (say) C > and then transoform it into C. Transformation should be intelligent - > I don't want dynamic objects with dictionaries of methods. I'm willing > to provide type descriptions so when I say: > myList = [0] * 100 > > I get in C: > int *myList; > myList = calloc(100, sizeof(int)); > > I'm aware of projects like Pyrex, Psyco, and Pypy but their scope is > too broad: they are about Python in its entirety and dynamism. I think you're underestimating the actual scope of what you're trying to describe... but anyway, here's another one you probably aren't interested in because it's too broad ;-) http://felix.sf.net -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sun Jan 4 14:42:19 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 04 Jan 2004 08:42:19 -0500 Subject: [C++-sig] Re: object.slice() infinite recursion bug References: <1073192680.5886.15.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > This simple test demonstrates a bug in Boost.Python that results in > infinite recursion (and a subsequent crash) whenever you make a slice > using slice_nil for the upper and lower bounds. > > I originally discovered it with the array class, but it also exists in > the object class, so that is what I'm putting up here. > > This crash is exhibited with 1.30 and CVS HEAD using both Python 2.2 and > Python 2.3 with GCC 3.3.2. Now fixed in CVS. Thanks for the report! -- Dave Abrahams Boost Consulting www.boost-consulting.com From nicodemus at esss.com.br Sun Jan 4 18:32:07 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Sun, 04 Jan 2004 14:32:07 -0300 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python In-Reply-To: <312735AC.3841CC26.0331AA34@netscape.net> References: <312735AC.3841CC26.0331AA34@netscape.net> Message-ID: <3FF84E17.1020205@esss.com.br> luszczek1 at netscape.net wrote: >I'm aware of projects like Pyrex, Psyco, and Pypy but their scope is >too broad: they are about Python in its entirety and dynamism. > > Have you really looked into Pyrex? Because it seems to have what you need: Although it can generate code that takes advantage of Python's dynamism, type declaration is possible, allowing it to generate direct C code... but I have never used, so I may be wrong. Regards, Nicodemus. From bob at redivi.com Sun Jan 4 17:48:12 2004 From: bob at redivi.com (Bob Ippolito) Date: Sun, 4 Jan 2004 11:48:12 -0500 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python In-Reply-To: <3FF84E17.1020205@esss.com.br> References: <312735AC.3841CC26.0331AA34@netscape.net> <3FF84E17.1020205@esss.com.br> Message-ID: On Jan 4, 2004, at 12:32 PM, Nicodemus wrote: > luszczek1 at netscape.net wrote: > >> I'm aware of projects like Pyrex, Psyco, and Pypy but their scope is >> too broad: they are about Python in its entirety and dynamism. > > Have you really looked into Pyrex? Because it seems to have what you > need: Although it can generate code that takes advantage of Python's > dynamism, type declaration is possible, allowing it to generate direct > C code... but I have never used, so I may be wrong. For whatever reason he says he can't depend on Python. I'm pretty sure that Pyrex (without modifications) won't produce "plain" C code, and definitely not executables. It will always produce Python modules, even if you manage to write Pyrex code that doesn't really use any Python features. Unless he's programming in some tiny embedded environment, I think his specifications are pretty bogus in the first place. The language he proposes would be neat to have, but I'd rather see effort go into PyPy or something; which could theoretically do what he asks someday from what I understand of their bootstrapping efforts. -bob -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2357 bytes Desc: not available URL: From nicodemus at esss.com.br Sun Jan 4 18:59:34 2004 From: nicodemus at esss.com.br (Nicodemus) Date: Sun, 04 Jan 2004 14:59:34 -0300 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python In-Reply-To: References: <312735AC.3841CC26.0331AA34@netscape.net> <3FF84E17.1020205@esss.com.br> Message-ID: <3FF85486.4010103@esss.com.br> Bob Ippolito wrote: > > On Jan 4, 2004, at 12:32 PM, Nicodemus wrote: > >> Have you really looked into Pyrex? Because it seems to have what you >> need: Although it can generate code that takes advantage of Python's >> dynamism, type declaration is possible, allowing it to generate >> direct C code... but I have never used, so I may be wrong. > > > For whatever reason he says he can't depend on Python. I'm pretty > sure that Pyrex (without modifications) won't produce "plain" C code, > and definitely not executables. It will always produce Python > modules, even if you manage to write Pyrex code that doesn't really > use any Python features. You are right. I guess one could kind of "hack" Pyrex (defining a main() function, for instance), but that would be some serious misuse of the tool. > Unless he's programming in some tiny embedded environment, I think his > specifications are pretty bogus in the first place. The language he > proposes would be neat to have, but I'd rather see effort go into PyPy > or something; which could theoretically do what he asks someday from > what I understand of their bootstrapping efforts. Yes, and they're using a modified version of Pyrex to generate the C code. This version probably could be used as a starting point for the OP, but not without further customization. Regards, Nicodemus. From luszczek1 at netscape.net Sun Jan 4 18:03:19 2004 From: luszczek1 at netscape.net (luszczek1 at netscape.net) Date: Sun, 04 Jan 2004 12:03:19 -0500 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python Message-ID: <575EF673.4E1C1E18.0331AA34@netscape.net> Nicodemus wrote: >luszczek1 at netscape.net wrote: > >>I'm aware of projects like Pyrex, Psyco, and Pypy but their scope is >>too broad: they are about Python in its entirety and dynamism. > >Have you really looked into Pyrex? Because it seems to have what you >need: Although it can generate code that takes advantage of Python's >dynamism, type declaration is possible, allowing it to generate direct C >code... but I have never used, so I may be wrong. Yes I have. I think the project is great. However, from my (admittedly twisted) persepective it has a few problems: 1. Pyrex code doesn't work in Python interpreter. This is a big drawback to me. I like Python and want to stick with it, I don't want to learn another language. 2. Pyrex brands itself as a tool for extensions. What if I want the entire program to be translated into C/C++/whatever? Probably it's possible, but it's not the main goal. 3. The generated code depends on Python runtime (the PyObject and friends) There exist similar projects that approach the problem from different perspective: - Cython - drop braces from your C code - Perthon - translate Python to Perl that is human readable It's not quite what I want. Peter __________________________________________________________________ New! Unlimited Access from the Netscape Internet Service. Beta test the new Netscape Internet Service for only $1.00 per month until 3/1/04. Sign up today at http://isp.netscape.com/register Act now to get a personalized email address! Netscape. Just the Net You Need. From luszczek1 at netscape.net Sun Jan 4 18:21:05 2004 From: luszczek1 at netscape.net (luszczek1 at netscape.net) Date: Sun, 04 Jan 2004 12:21:05 -0500 Subject: [C++-sig] Re: Advanced (?) compiling, freezing, translating Python Message-ID: <7A9AB764.5A11CAB5.0331AA34@netscape.net> >Unless he's programming in some tiny embedded environment, I think his >specifications are pretty bogus in the first place. The language he I would be glad to provide more detail on my suggestion. I don't which part of it is "bogus", though. I'm not suggesting another Python spin-off. We've seen enough already. What I'm proposing has to do (but is not limited to) programming style: - if you only use functions I guess you would like your work translated into C - if you only use single inheritance you probably would like to translate it to Java - if you want mulitple inheritance you go with C++ translation - if you change objects at runtime by adding methods and attributes you should probably stick with Python. >proposes would be neat to have, but I'd rather see effort go into PyPy >or something; which could theoretically do what he asks someday from >what I understand of their bootstrapping efforts. First sentence from the PyPy web page: The PyPy project aims at producing a simple runtime-system for the Python language. I was quite specific about runtime: I don't want it. Depending on your programming style you might not need it. Peter __________________________________________________________________ New! Unlimited Access from the Netscape Internet Service. Beta test the new Netscape Internet Service for only $1.00 per month until 3/1/04. Sign up today at http://isp.netscape.com/register Act now to get a personalized email address! Netscape. Just the Net You Need. From ripsnorta_1 at hotmail.com Mon Jan 5 00:45:51 2004 From: ripsnorta_1 at hotmail.com (John) Date: Sun, 4 Jan 2004 18:45:51 -0500 Subject: [C++-sig] extending with C++ and typeinfo question Message-ID: Hi, (I'm not sure this worked the first time. My apologies if it did.) I am attempting to implement a scripting language for my application by embedding the python interpreter and exposing an API to python. So far so good. My application is heavily event driven, I have developed a publish/subscribe style event manager to which classes subscribe to published events. Frex: class i_subscriber { void on_event(event* e, event_type* et) = 0; }; class x : public i_subscriber { x() { SUBSCRIBE(this, event_startup) } void on_event(event* e, event_type* et) { if (IS_EVENT(event_startup, et)) { .... } } } when a event_startup event is generated, the event manager scoots through all the subscribers for that particular event and calls the on_event handler which determines the event type and handles it appropriately. The system depends heavily on rtti to work. Now what I want to do is to expose this system to my Python scripts. I'd like to have a Python class subscribe to an event, and when that event is published, for the script to be notified and be able to handle it. Frex: class y(i_subscriber): # the subscriber interface has been exposed by boost.python def __init__(self): subscribe(self, event_startup) # subscribe is an exposed API def __del__(self): unsubscribe(self) # unsubscribe from all events def on_event(evt, evt_type): # handle the event here, but how do I determine what the # type is? y_inst = y() These are the areas I am having trouble getting my head around at the moment. The main application needs to register the Python class and know that it is_a subscriber. This means I need to transmit type information for both the subscriber and the event through the interpreter. When an event is published it's not known if the subscriber is c++ or python. If I call on_event on the subscriber interface for a python class is there some marshalling that I need to do? How do I transmit the type of a published event through the interpreter so that my on_event handler knows what event is being processed? I've been looking through the Python and Boost.Python documentation and so far I haven't seen what I need to do to get this working. I'm probably just missing something simple. Any pointers would be helpful. Of course I might be blowing against the wind here. That would be good to know too. :-) Has anyone here attempted to do this before? Are there any other web sites out there where this may have been attempted? Cheers John From s_sourceforge at nedprod.com Mon Jan 5 03:16:57 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Mon, 05 Jan 2004 02:16:57 -0000 Subject: [C++-sig] extending with C++ and typeinfo question In-Reply-To: Message-ID: <3FF8C919.4203.59FCF3F6@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 4 Jan 2004 at 18:45, John wrote: > These are the areas I am having trouble getting my head around at the > moment. I foresee the following problems: 1. RTTI can't know what types python derives from i_subscriber. You're going to need some other mechanism here (good reason why RTTI is not the right thing to use here - I personally decode RTTI into a string and use the string as a unique identifier - it's fast, portable and extendable). 2. Even if you get this working, C++ entering and exiting python is slow. You don't want to do it iteratively like you're doing it unless there's any other way. Can I suggest that you tag each event with a flag which when true means python has a handler installed? Then set the flag only when needed and use an alternative type deduction mechanism. > How do I transmit the type of a published event through the > interpreter so that my on_event handler knows what event is being > processed? RTTI really is a long unique string on any compiler I know of. Think of generating a long unique string from the python side and you're nearly done. Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBP/jJGcEcvDLFGKbPEQKrWACgnmn/XVO+s9t0jnNXf7vxsmX3r9UAoPEa zyxFTUzaomlA1weLzE+cq5lX =ba3M -----END PGP SIGNATURE----- From gilles.orazi at varianinc.com Mon Jan 5 17:42:57 2004 From: gilles.orazi at varianinc.com (Gilles Orazi) Date: Mon, 05 Jan 2004 17:42:57 +0100 Subject: [C++-sig] Function with an argument passed by reference Message-ID: <5.2.0.9.2.20040105173508.00b59678@begonia.varianinc.com> An HTML attachment was scrubbed... URL: From pierre.barbier at cirad.fr Mon Jan 5 17:52:52 2004 From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille) Date: Mon, 05 Jan 2004 17:52:52 +0100 Subject: [C++-sig] Function with an argument passed by reference In-Reply-To: <5.2.0.9.2.20040105173508.00b59678@begonia.varianinc.com> References: <5.2.0.9.2.20040105173508.00b59678@begonia.varianinc.com> Message-ID: <1073321572.664.6.camel@pbarbier> The problem is surely that you cannot have a reference on an integer in Python for number types are immutable. If "x" can be modified you should write a small wrapper that returns the new value of 'x' and take an integer without reference. Pierre Le lun 05/01/2004 ? 17:42, Gilles Orazi a ?crit : > Hello, > > I am trying to wrap a function declared like that: > void myFunc(int& x) ; > > If I wrap it like that: > .def("myFunc", myFunc); > my program compiles but when I call this function from Python I get an > error message: > "TypeError: bad argument type for built-in operation" > > I looked through the mailing list archive and the various boost.python > documentations but I did not found the answer. > > Thanks by advance for the help. > Regards, > > > Dr Gilles Orazi > Data Systems, R&D Software Engineer > Scientific Instruments > Varian JMBS S.A.S > 1 Rue Hector Berlioz > ZAC DES PLANS > F-38600 FONTAINE > FRANCE > > Tel: +33 4 76 53 35 80 > Fax: +33 4 76 53 35 89 > > gilles.orazi at varianinc.com > http://www.varianinc.com > > Inspiring Excellence" > > > ______________________________________________________________________ > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig -- Pierre Barbier de Reuille INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 From jbrandmeyer at earthlink.net Tue Jan 6 05:05:18 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Mon, 05 Jan 2004 23:05:18 -0500 Subject: [C++-sig] New slice implementation Message-ID: <1073361918.13426.31.camel@illuvatar> I have written a new implementation for free-standing slice objects. This allows you to create and query slice objects that include a step-size, as well as export a form of __getitem__ and/or __setitem__ that can receive slice arguments and tuples of slice arguments. Originally I needed this type for multidimensional slicing of Numeric arrays, but I decided to round out the type, boostify it, and pass it along. Dave, please let me know if there is anything you need me to do to make this meet your standards for acceptance into Boost.Python. I should be able to answer any questions you might have as early as late tomorrow night or Wednesday. -Jonathan Brandmeyer -------------- next part -------------- A non-text attachment was scrubbed... Name: slice.hpp Type: text/x-c-header Size: 8259 bytes Desc: URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: slice.cpp Type: text/x-c++ Size: 780 bytes Desc: URL: From RaoulGough at yahoo.co.uk Tue Jan 6 17:09:46 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Tue, 06 Jan 2004 16:09:46 +0000 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > I have written a new implementation for free-standing slice objects. > This allows you to create and query slice objects that include a > step-size, as well as export a form of __getitem__ and/or __setitem__ > that can receive slice arguments and tuples of slice arguments. Not sure how much overlap there is, but have you looked into the container indexing suite for existing __getitem__, __setitem__ and __delitem__ support? Joel's code is currently only in the CVS, but will be included in the 1.31 release of boost, AFAIK. It includes support for Python slices. -- Raoul Gough. export LESS='-X' From RaoulGough at yahoo.co.uk Wed Jan 7 13:08:30 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Wed, 07 Jan 2004 12:08:30 +0000 Subject: [C++-sig] Re: indexing_v2 status update References: Message-ID: David Abrahams writes: > Raoul Gough writes: [snip] >> Does mpl::set currently work? I seem to remember that you >> suggested using mpl::vector at the moment, which raised some doubt >> about this. > > see libs/mpl/test/set.cpp. You can try it yourself and find out. I've looked at the test cases, which I *think* I understand after looking at the preprocessor output. From what I can see, there are tests for empty and one-element sets only. If that really is the case, I don't find it very convincing. I'm tending towards the bitflag approach at the moment anyway. By the way, I've been wondering about what the container suite interface should look like after moving to feature sets instead of static boolean constants. I'm thinking along these lines: template< class Container, SOME_KIND_OF_SET features = supported_features, class Algorithms = algorithms > container_suite; where supported_features does the traits-like work of figuring out what the container can support. This would allow client code to override the features explicitly if something is not needed. Curiously, I think the Algorithms implementation doesn't need to know this information itself, since it is up to the container_suite to decide what Algorithms functions to instantiate. Another option would be to determine the supported features within the existing container_traits framework, and provide an optional features_to_disable parameter to the container_suite. Any thoughts or preferences on this front? -- Raoul Gough. export LESS='-X' From jbrandmeyer at earthlink.net Thu Jan 8 00:33:13 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Wed, 07 Jan 2004 18:33:13 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> Message-ID: <1073518393.1796.15.camel@illuvatar> On Tue, 2004-01-06 at 11:09, Raoul Gough wrote: > Jonathan Brandmeyer writes: > > > I have written a new implementation for free-standing slice objects. > > This allows you to create and query slice objects that include a > > step-size, as well as export a form of __getitem__ and/or __setitem__ > > that can receive slice arguments and tuples of slice arguments. > > Not sure how much overlap there is, It turns out that there isn't much. slice::get_indicies() overlaps with the indexing suite's slicing support, but in a different way such that it might be OK to keep, anyway. My object really just provides a object manager for PySliceObject, rather than provide a container of objects initialized by a slice (such as the indexing_suite does). > but have you looked into the > container indexing suite for existing __getitem__, __setitem__ and > __delitem__ support? Joel's code is currently only in the CVS, but > will be included in the 1.31 release of boost, AFAIK. It includes > support for Python slices. Well, I've looked at the indexing suite now, and there are several problems with its slice support. 1) Non-None values of step size are silently ignored. I wrote a patch for slice_helper<>::base_get_slice_data() to throw IndexError if step size is given. 2) Does not clip slice ranges to the max/min as appropriate for slices, instead it raises IndexError. (Patch fixes this) 3) Crashes when given slice indexes that run cross to each other (in STL parlance, stop is not reachable from start). I believe that the responsibility for handling this case is in the hands of the respective policies classes. Therefore, my patch targets vector_indexing_suite vice indexing_suite for these: foo = bar[-1:0] crashes, should return empty container. (Patched) del bar[-1:0] crashes, should be a no-op. (Patched) bar[-1:0] = foo crashes. It has weird insert()-like semantics in practice for lists, but I haven't seen it documented anywhere. (Patch throws IndexError in this case since performing a slice insertion to an empty slice should be an undefined operation). -Jonathan Brandmeyer ---crash_test.py--- # Uses the existing vector_indexing_suite_ext.cpp test modul from vector_indexing_suite_ext import * foo = FloatVec() # Weird initialization, why not supported by a constructor? foo[:] = [1,2,3,4,5,6] def print_vector(foo): s = '[ ' for x in foo: s += repr(x) + ' ' s += ']' print s # Should raise IndexError, or print backwards; actually prints the # original print_vector(foo[::-1]) # Should print the original, but instead raises IndexError print_vector(foo[-10:10]) # Should print an empty vector( "[ ]"); crashes print_vector(foo[-1:0]) # Should do nothing; crashes del foo[-1:0] # I think this should raise IndexError; crashes. foo[-1:0] = [7, 8, 9] -------------- next part -------------- A non-text attachment was scrubbed... Name: indexing_suite.diff Type: text/x-patch Size: 4008 bytes Desc: URL: From patrick at vrac.iastate.edu Thu Jan 8 05:44:01 2004 From: patrick at vrac.iastate.edu (Patrick Hartling) Date: Wed, 07 Jan 2004 22:44:01 -0600 Subject: [C++-sig] boost/python/detail/python22_fixed.h missing from Boost RC_1_31_0 installation Message-ID: <1073537041.1606.10.camel@dsl.80.187.networkiowa.com> I just made an installation of the Boost RC_1_31_0 branch, and I noticed that the file boost/python/detail/python22_fixed.h does not get installed. I followed the documented process for making an installation: bjam install --prefix=/foo/bar This was done from the top-level Boost source tree using sources checked out from about three hours ago (including a fresh bjam 3.1.9 compiled from the same sources). Sorry I don't have a patch to submit, but I don't know what to modify to fix this. -Patrick -- Patrick L. Hartling | Research Assistant, VRAC patrick at vrac.iastate.edu | 2274 Howe Hall Room 2624 http://www.137.org/patrick/ | http://www.vrac.iastate.edu/ PGP: http://wwwkeys.gpg.cz:11371/pks/lookup?op=get&search=0xEBF86398 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: From RaoulGough at yahoo.co.uk Thu Jan 8 13:22:04 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 08 Jan 2004 12:22:04 +0000 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Tue, 2004-01-06 at 11:09, Raoul Gough wrote: >> Jonathan Brandmeyer writes: >> >> > I have written a new implementation for free-standing slice objects. >> > This allows you to create and query slice objects that include a >> > step-size, as well as export a form of __getitem__ and/or __setitem__ >> > that can receive slice arguments and tuples of slice arguments. >> >> Not sure how much overlap there is, > > It turns out that there isn't much. slice::get_indicies() overlaps with > the indexing suite's slicing support, but in a different way such that > it might be OK to keep, anyway. My object really just provides a object > manager for PySliceObject, rather than provide a container of objects > initialized by a slice (such as the indexing_suite does). It sounds like the interfaces may be quite different, but isn't the functionality the same? Once you have a Python slice object, you can use this to access portions of a container via __getitem__ from the indexing suite. On the other hand, if the slice object is actually one of your python::slice objects, you could use its get_indices member function to access parts of a container as well. I guess the main difference is whether this is returned via a separate container, or via iterators into the existing container. Note the potential problems from the Python side, though, if the existing container disappears while those iterators still exist. BTW, wouldn't it be a good idea to have a slice constructor that takes a PySliceObject * as parameter? > >> but have you looked into the >> container indexing suite for existing __getitem__, __setitem__ and >> __delitem__ support? Joel's code is currently only in the CVS, but >> will be included in the 1.31 release of boost, AFAIK. It includes >> support for Python slices. > > Well, I've looked at the indexing suite now, and there are several > problems with its slice support. > > 1) Non-None values of step size are silently ignored. > I wrote a patch for slice_helper<>::base_get_slice_data() to throw > IndexError if step size is given. > > 2) Does not clip slice ranges to the max/min as appropriate for slices, > instead it raises IndexError. (Patch fixes this) > > 3) Crashes when given slice indexes that run cross to each other (in STL > parlance, stop is not reachable from start). I believe that the > responsibility for handling this case is in the hands of the respective > policies classes. Therefore, my patch targets vector_indexing_suite > vice indexing_suite for these: > foo = bar[-1:0] crashes, should return empty container. (Patched) > del bar[-1:0] crashes, should be a no-op. (Patched) > bar[-1:0] = foo crashes. It has weird insert()-like semantics in > practice for lists, but I haven't seen it documented > anywhere. (Patch throws IndexError in this case since performing > a slice insertion to an empty slice should be an undefined > operation). What I should probably also have said in my original message is that I'm working on a new version of the indexing suite. It certainly fixes some of the issues you've identified - have a look for indexing_v2 in the archives or see http://home.clara.net/raoulgough/boost/. There are actually a lot of different issues in providing sensible __getitem__ support for C++ containers (for example, take a look at the proxy support in Joel's suite, or the container_proxy wrapper in mine). Please not that I'm not trying to put you off contributing code! I just think it doesn't make sense to duplicate functionality, so you should probably be aware of the existing work taking place in this area. > > -Jonathan Brandmeyer > > ---crash_test.py--- > # Uses the existing vector_indexing_suite_ext.cpp test modul > from vector_indexing_suite_ext import * > foo = FloatVec() > # Weird initialization, why not supported by a constructor? That's a good question, but it isn't necessarily that easy to answer. At least, not if you want to use the container's iterator-based constructor template. e.g. std::vector has a constructor template vector(InputIterator f, InputIterator l, const Allocator& a = Allocator()) which would be the best one to use. I still haven't figured out the details of providing this. > foo[:] = [1,2,3,4,5,6] > def print_vector(foo): > s = '[ ' > for x in foo: > s += repr(x) + ' ' > s += ']' > print s An easier way: def print_vec(foo): print [x for x in foo] > > # Should raise IndexError, or print backwards; actually prints the > # original > print_vector(foo[::-1]) That would be because the step value is ignored, right? In any case, it's very useful to try this kind of test with a real Python list to see what "should" happen: >>> v = [1,2,3,4,5] >>> print v[::-1] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer Would have to look that one up in the Python reference to see if it's documented! The indexing_v2 suite prints [5,4,3,2] which also can't really be right. > > # Should print the original, but instead raises IndexError > print_vector(foo[-10:10]) This works in indexing_v2 > > # Should print an empty vector( "[ ]"); crashes > print_vector(foo[-1:0]) also works in v2 > > # Should do nothing; crashes > del foo[-1:0] Check. > > # I think this should raise IndexError; crashes. > foo[-1:0] = [7, 8, 9] With a real python list, it inserts 7, 8, 9 before the last element: >>> v = [1,2,3,4] >>> v[-1:0] = [7,8,9] >>> print v [1, 2, 3, 7, 8, 9, 4] This also works the same in v2. What I've done with the indexing_v2 suite is to try and make it perform exactly as a Python list (at least, when used with a std::vector or similar). Unfortunately, the v2 support won't make it into the next release (1.31) because I'm still messing around with some changes to it. -- Raoul Gough. export LESS='-X' From grafik.list at redshift-software.com Thu Jan 8 14:58:23 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 08 Jan 2004 07:58:23 -0600 Subject: [C++-sig] boost/python/detail/python22_fixed.h missing from Boost RC_1_31_0 installation In-Reply-To: <1073537041.1606.10.camel@dsl.80.187.networkiowa.com> References: <1073537041.1606.10.camel@dsl.80.187.networkiowa.com> Message-ID: <3FFD61FF.7040307@redshift-software.com> Patrick Hartling wrote: > I just made an installation of the Boost RC_1_31_0 branch, and I noticed > that the file boost/python/detail/python22_fixed.h does not get > installed. I followed the documented process for making an > installation: > > bjam install --prefix=/foo/bar > > This was done from the top-level Boost source tree using sources checked > out from about three hours ago (including a fresh bjam 3.1.9 compiled > from the same sources). Sorry I don't have a patch to submit, but I > don't know what to modify to fix this. I know what to change... I'll fix it tonight. And good catch on this one :-) The problem is the install code is not checking for *.h files in the includes only *.hpp files. Thanks, for noticing. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From dave at boost-consulting.com Thu Jan 8 15:42:30 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Jan 2004 09:42:30 -0500 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> Message-ID: Thanks for your submission, Jonathan! I can say right off that it looks like good code but it's missing tests and docs and I can't accept it without those. I haven't been ignoring it, but wanted to wait to wait for this little debate come to some conclusions... Raoul Gough writes: > Jonathan Brandmeyer writes: > >> On Tue, 2004-01-06 at 11:09, Raoul Gough wrote: >>> Jonathan Brandmeyer writes: >>> >>> > I have written a new implementation for free-standing slice objects. >>> > This allows you to create and query slice objects that include a >>> > step-size, as well as export a form of __getitem__ and/or __setitem__ >>> > that can receive slice arguments and tuples of slice arguments. >>> >>> Not sure how much overlap there is, >> >> It turns out that there isn't much. slice::get_indicies() overlaps with >> the indexing suite's slicing support, but in a different way such that >> it might be OK to keep, anyway. My object really just provides a object >> manager for PySliceObject, rather than provide a container of objects >> initialized by a slice (such as the indexing_suite does). > > It sounds like the interfaces may be quite different, but isn't the > functionality the same? Not exactly, IMO. > Once you have a Python slice object, you > can use this to access portions of a container via __getitem__ from > the indexing suite. Yeah, or any other Python object that supports slicing. > On the other hand, if the slice object is actually one > of your python::slice objects, you could use its get_indices member > function to access parts of a container as well. You don't need get_indices: >>> range(10)[slice(2,6)] [2, 3, 4, 5] >>> range(10)[slice(2,6,2)] [2, 4] Therefore: object slice262(object x) { return x[slice(2,6,2)] } Ought to work. But since there are no tests or examples I don't understand how get_indices is supposed to be used. > What I should probably also have said in my original message is that > I'm working on a new version of the indexing suite. It certainly fixes > some of the issues you've identified - have a look for indexing_v2 in > the archives or see http://home.clara.net/raoulgough/boost/. There are > actually a lot of different issues in providing sensible __getitem__ > support for C++ containers (for example, take a look at the proxy > support in Joel's suite, or the container_proxy wrapper in mine). > > Please not that I'm not trying to put you off contributing code! I > just think it doesn't make sense to duplicate functionality, so you > should probably be aware of the existing work taking place in this > area. Having a slice object seems highly valuable to me. I don't know if get_indices really belongs in it, but I'll need to hear more from Jonathan. I hope the two of you can put your heads together to integrate whatever overlapping work you may be pursuing. -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Thu Jan 8 15:48:13 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Jan 2004 09:48:13 -0500 Subject: [C++-sig] Re: indexing_v2 status update References: Message-ID: Raoul Gough writes: > David Abrahams writes: > >> Raoul Gough writes: > > [snip] >>> Does mpl::set currently work? I seem to remember that you >>> suggested using mpl::vector at the moment, which raised some doubt >>> about this. >> >> see libs/mpl/test/set.cpp. You can try it yourself and find out. > > I've looked at the test cases, which I *think* I understand after > looking at the preprocessor output. From what I can see, there are > tests for empty and one-element sets only. If that really is the case, > I don't find it very convincing. If zero one and two all work, then N works by induction. But anyway... > I'm tending towards the bitflag approach at the moment anyway. OK. > By the way, I've been wondering about what the container suite > interface should look like after moving to feature sets instead of > static boolean constants. I'm thinking along these lines: > > template< > class Container, > SOME_KIND_OF_SET features = supported_features, > class Algorithms = algorithms >> container_suite; > > where supported_features does the traits-like work of figuring out > what the container can support. This would allow client code to > override the features explicitly if something is not needed. > Curiously, I think the Algorithms implementation doesn't need to know > this information itself, since it is up to the container_suite to > decide what Algorithms functions to instantiate. > > Another option would be to determine the supported features within the > existing container_traits framework, and provide an optional > features_to_disable parameter to the container_suite. Any thoughts or > preferences on this front? Nope; so far it sounds great. -- Dave Abrahams Boost Consulting www.boost-consulting.com From RaoulGough at yahoo.co.uk Thu Jan 8 16:13:21 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 08 Jan 2004 15:13:21 +0000 Subject: [C++-sig] Re: indexing_v2 status update References: Message-ID: David Abrahams writes: > Raoul Gough writes: > >> David Abrahams writes: >> >>> Raoul Gough writes: >> >> [snip] >>>> Does mpl::set currently work? I seem to remember that you >>>> suggested using mpl::vector at the moment, which raised some doubt >>>> about this. >>> >>> see libs/mpl/test/set.cpp. You can try it yourself and find out. >> >> I've looked at the test cases, which I *think* I understand after >> looking at the preprocessor output. From what I can see, there are >> tests for empty and one-element sets only. If that really is the case, >> I don't find it very convincing. > > If zero one and two all work, then N works by induction. But anyway... Are we talking about a mathematical proof or testing strategy here :-) You would have to prove that for all i, correct(i) implies correct(i+1) and then go on to prove e.g. correct(0). Proving general things about code is hard though, so the i -> i+1 implication would be difficult. In this case, restricting the testing to 0 and 1 element sets completely ignores potential problems with ordering of elements. e.g. is set == set ??? > >> I'm tending towards the bitflag approach at the moment anyway. > > OK. > >> By the way, I've been wondering about what the container suite >> interface should look like after moving to feature sets instead of >> static boolean constants. I'm thinking along these lines: >> >> template< >> class Container, >> SOME_KIND_OF_SET features = supported_features, >> class Algorithms = algorithms >>> container_suite; >> >> where supported_features does the traits-like work of figuring out >> what the container can support. This would allow client code to >> override the features explicitly if something is not needed. >> Curiously, I think the Algorithms implementation doesn't need to know >> this information itself, since it is up to the container_suite to >> decide what Algorithms functions to instantiate. >> >> Another option would be to determine the supported features within the >> existing container_traits framework, and provide an optional >> features_to_disable parameter to the container_suite. Any thoughts or >> preferences on this front? > > Nope; so far it sounds great. OK, thanks! I think I'll go with the supported_features approach. -- Raoul Gough. export LESS='-X' From gilles.orazi at varianinc.com Thu Jan 8 16:25:04 2004 From: gilles.orazi at varianinc.com (Gilles Orazi) Date: Thu, 08 Jan 2004 16:25:04 +0100 Subject: [C++-sig] (no subject) Message-ID: <5.2.0.9.2.20040108162001.00b53b90@begonia.varianinc.com> An HTML attachment was scrubbed... URL: From RaoulGough at yahoo.co.uk Thu Jan 8 17:52:49 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 08 Jan 2004 16:52:49 +0000 Subject: [C++-sig] Re: (no subject) References: <5.2.0.9.2.20040108162001.00b53b90@begonia.varianinc.com> Message-ID: Gilles Orazi writes: > We have seen on the boost-consulting web site that there exists a file > called boost/python/indexing/indexing_suite.hpp that just fit our needs. > Unfortunately, we were unable to find it in our boost sources. It seems > that we have the lastest available version (1.30.2). > Where could we find this file ? > Thanks a lot by advance for your answer. I guess you mean boost/python/suite/indexing/indexing_suite.hpp ? This is due for the 1.31 release, but until then is available via CVS. Refer to http://www.boost.org/more/download.html#CVS for further information. ISTR there also an automatically-updated tarball somewhere. You might like to note that a newer version of the indexing suite under development, and may eventually replace the existing indexing suite (search for indexing_v2 in this list if you're interested). -- Raoul Gough. export LESS='-X' From dave at boost-consulting.com Thu Jan 8 18:41:32 2004 From: dave at boost-consulting.com (David Abrahams) Date: Thu, 08 Jan 2004 12:41:32 -0500 Subject: [C++-sig] Re: indexing_v2 status update References: Message-ID: Raoul Gough writes: >> If zero one and two all work, then N works by induction. But anyway... > > Are we talking about a mathematical proof or testing strategy here :-) > You would have to prove that for all i, correct(i) implies > correct(i+1) and then go on to prove e.g. correct(0). Proving general > things about code is hard though, so the i -> i+1 implication would be > difficult. In this case, restricting the testing to 0 and 1 element > sets completely ignores potential problems with ordering of elements. > > e.g. is set == set ??? I wasn't really serious ;-> -- Dave Abrahams Boost Consulting www.boost-consulting.com From RaoulGough at yahoo.co.uk Thu Jan 8 19:43:33 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Thu, 08 Jan 2004 18:43:33 +0000 Subject: [C++-sig] Re: indexing_v2 status update References: Message-ID: David Abrahams writes: > Raoul Gough writes: > >>> If zero one and two all work, then N works by induction. But anyway... >> >> Are we talking about a mathematical proof or testing strategy here :-) >> You would have to prove that for all i, correct(i) implies >> correct(i+1) and then go on to prove e.g. correct(0). Proving general >> things about code is hard though, so the i -> i+1 implication would be >> difficult. In this case, restricting the testing to 0 and 1 element >> sets completely ignores potential problems with ordering of elements. >> >> e.g. is set == set ??? > > I wasn't really serious ;-> I should have known, even without a smiley! -- Raoul Gough. export LESS='-X' From jbrandmeyer at earthlink.net Thu Jan 8 21:51:22 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Thu, 08 Jan 2004 15:51:22 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> Message-ID: <1073595081.19758.430.camel@illuvatar> On Thu, 2004-01-08 at 07:22, Raoul Gough wrote: > Jonathan Brandmeyer writes: > > > On Tue, 2004-01-06 at 11:09, Raoul Gough wrote: > >> Jonathan Brandmeyer writes: > >> > >> > I have written a new implementation for free-standing slice objects. > >> > This allows you to create and query slice objects that include a > >> > step-size, as well as export a form of __getitem__ and/or __setitem__ > >> > that can receive slice arguments and tuples of slice arguments. > >> > >> Not sure how much overlap there is, > > > > It turns out that there isn't much. slice::get_indicies() overlaps with > > the indexing suite's slicing support, but in a different way such that > > it might be OK to keep, anyway. My object really just provides a object > > manager for PySliceObject, rather than provide a container of objects > > initialized by a slice (such as the indexing_suite does). > > It sounds like the interfaces may be quite different, but isn't the > functionality the same? Once you have a Python slice object, you can > use this to access portions of a container via __getitem__ from the > indexing suite. On the other hand, if the slice object is actually one > of your python::slice objects, you could use its get_indices member > function to access parts of a container as well. I guess the main > difference is whether this is returned via a separate container, or > via iterators into the existing container. Note the potential problems > from the Python side, though, if the existing container disappears > while those iterators still exist. That bit about container lifetime is a very good point, but what I have in mind is performing modifying operations. That is, I want to be able to write a function that uses a Python slice object to address which elements of the container that I want to operate on, such as this: double partial_sum( std::vector* Foo, slice index) { slice::range > bounds; try { bounds = index.get_indicies( Foo->begin(), Foo->end()); } catch (std::invalid_argument) return 0.0; double ret = 0.0; while (bounds.start != bounds.stop) { ret += *bounds.start; std::advance( bounds.start, bounds.step); } ret += bounds.start; return ret; } > BTW, wouldn't it be a good idea to have a slice constructor that takes > a PySliceObject * as parameter? I try to avoid raw PyObject*'s whenever possible, but I think that the answer is "no". The reason is that you have no idea how to properly manage it. That is partially what the detail::new_reference<>, detail::borrowed_reference<>, and detail::new_non_null_reference<> are for, right?. Feel free to correct me if I'm wrong. > > ---crash_test.py--- > > # Uses the existing vector_indexing_suite_ext.cpp test modul > > from vector_indexing_suite_ext import * > > foo = FloatVec() > > # Weird initialization, why not supported by a constructor? > > That's a good question, but it isn't necessarily that easy to > answer. At least, not if you want to use the container's > iterator-based constructor template. e.g. std::vector has a > constructor I don't think you reasonably can use those iterator-based constructors unless you have a way of creating a [begin,end) pair of generic iterators descended from boost::python::object. Something that, when dereferenced, automatically calls extract. The 'begin' iterator would also have to trap for IndexErroror and StopIteration and compare equal to the 'end' iterator afterwords. I smell another code contribution coming in a day or so for something just like this. > template > vector(InputIterator f, InputIterator l, const Allocator& a = Allocator()) > > which would be the best one to use. I still haven't figured out the > details of providing this. Well, I don't know much about the metaprogramming guts of either suite, but I wrote this simple template to create a preallocated vector that I initialize with extract<>(), and exported it using "injected constructors" support: template boost::shared_ptr create_from_pysequence( object seq) { boost::shared_ptr ret( new Container(extract(seq.attr("__len__")()))); object seq_i = seq.attr("__iter__")(); for ( typename Container::iterator i = ret->begin(); i != ret->end(); ++i) { *i = extract< typename Container::value_type>( seq_i.attr("next")()); } return ret; } > An easier way: > > def print_vec(foo): > print [x for x in foo] Oooh. Nice. > > > > # Should raise IndexError, or print backwards; actually prints the > > # original > > print_vector(foo[::-1]) > > That would be because the step value is ignored, right? Yes. > In any case, > it's very useful to try this kind of test with a real Python list to > see what "should" happen: > > >>> v = [1,2,3,4,5] > >>> print v[::-1] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: sequence index must be integer > > Would have to look that one up in the Python reference to see if it's > documented! The indexing_v2 suite prints [5,4,3,2] which also can't > really be right. Try it with Python 2.3. In Python 2.2, slicing support was extended for builtin sequences to support __getitem__(slice(start,stop,step)), whereas in Python 2.2 you only have the __getslice__(start,stop) form. I think that the right way to handle negative step sizes (when you can choose the algorithm) is to use reverse iterators. The reason is that when provided a negative step, the stop value defaults to "one before the beginning" and the start value defaults to the last element. So long as you are using the [begin,end) ranges for iterators, the only way to make that work safely is with a reverse iterator and algorithm that carefully accounts for the effects of non-singular step size. > > > > # I think this should raise IndexError; crashes. > > foo[-1:0] = [7, 8, 9] > > With a real python list, it inserts 7, 8, 9 before the last element: > > >>> v = [1,2,3,4] > >>> v[-1:0] = [7,8,9] > >>> print v > [1, 2, 3, 7, 8, 9, 4] Yes, that is what happens: performing an insertion before the provided start value. However, I think that it should be an undefined operation since the expression is utter nonsense. I've looked at the source code for PyListObject, and I think that this behavior is the result of bounds limiting rather than real error checking. Furthermore if you try it with Numeric (the original source of rich slices), you will find that it is a no-op, which is what I would rather see in Boost now that I think a little more about it. See Python bug# 873305 at http://sourceforge.net/tracker/?group_id=5470 -Jonathan Brandmeyer From jbrandmeyer at earthlink.net Thu Jan 8 22:20:19 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Thu, 08 Jan 2004 16:20:19 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> Message-ID: <1073596819.19758.459.camel@illuvatar> On Thu, 2004-01-08 at 09:42, David Abrahams wrote: > Thanks for your submission, Jonathan! I can say right off that it > looks like good code but it's missing tests and docs and I can't > accept it without those. Here is a start. I think that this covers tests and examples. Also, there is another patch to make slice_nil work right for both object.slice() and freestanding slice objects. Basically I made slice_nil its own class, descended from object with only a default constructor. _ is a static const instantiation of slice_nil to serve as the shortcut. This makes slice_nil() an alias for PyNone as required for freestanding slices and differentiates it from object as required for object.slice(). I suppose I could have taken the same approach as the object.slice() implementation for separating out slice_nil, but that would have taken 12 different constructors. Even though the new semantics of slice_nil are wildly different, in practice I think that it should still be source compatable for its intended usage. The tests in object.cpp continue to work properly. WRT documentation, do you use some kind of semiautomatic doc generator or just plain html editing? Thanks, -Jonathan Brandmeyer -------------- next part -------------- A non-text attachment was scrubbed... Name: slice_patches.diff Type: text/x-patch Size: 1773 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: slice_test.cpp Type: text/x-c++ Size: 3036 bytes Desc: not available URL: From RaoulGough at yahoo.co.uk Fri Jan 9 02:55:32 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 09 Jan 2004 01:55:32 +0000 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Thu, 2004-01-08 at 07:22, Raoul Gough wrote: >> I guess the main difference is whether this is returned via a >> separate container, or via iterators into the existing >> container. Note the potential problems from the Python side, >> though, if the existing container disappears while those iterators >> still exist. > > That bit about container lifetime is a very good point, but what I > have in mind is performing modifying operations. That is, I want to > be able to write a function that uses a Python slice object to > address which elements of the container that I want to operate on, > such as this: > > double > partial_sum( std::vector* Foo, slice index) > { > slice::range > bounds; > try { > bounds = index.get_indicies( Foo->begin(), Foo->end()); > } catch (std::invalid_argument) > return 0.0; > double ret = 0.0; > while (bounds.start != bounds.stop) { > ret += *bounds.start; > std::advance( bounds.start, bounds.step); > } > ret += bounds.start; > return ret; > } Yes, I guess it makes a good deal of sense to use iterators in this case. However, how would you make use of them from Python code? >> BTW, wouldn't it be a good idea to have a slice constructor that takes >> a PySliceObject * as parameter? > > I try to avoid raw PyObject*'s whenever possible, but I think that the > answer is "no". The reason is that you have no idea how to properly > manage it. That is partially what the detail::new_reference<>, > detail::borrowed_reference<>, and detail::new_non_null_reference<> are > for, right?. Feel free to correct me if I'm wrong. I didn't necessarily mean a raw PySliceObject. All I'm getting at is, if you want to implement __getitem__ then you will end up with a PySliceObject created by the Python interpreter. AFAICS, you don't have a way of generating one of your slice objects from this. Am I missing something here? >>> part = v[1::4] calls v.__getitem__ with a PySliceObject (1, None, 4) Regarding the borrowed_reference and so on, I did things that way at first myself (I guess you just copied the existing code like I did?). Apparently the preferred (and documented) way of doing this kind of thing is via boost::python::handle instead. >> > ---crash_test.py--- >> > # Uses the existing vector_indexing_suite_ext.cpp test modul >> > from vector_indexing_suite_ext import * >> > foo = FloatVec() >> > # Weird initialization, why not supported by a constructor? >> >> That's a good question, but it isn't necessarily that easy to >> answer. At least, not if you want to use the container's >> iterator-based constructor template. e.g. std::vector has a >> constructor > > I don't think you reasonably can use those iterator-based constructors > unless you have a way of creating a [begin,end) pair of generic > iterators descended from boost::python::object. Something that, when > dereferenced, automatically calls extract. The 'begin' > iterator would also have to trap for IndexErroror and StopIteration and > compare equal to the 'end' iterator afterwords. I smell another code > contribution coming in a day or so for something just like this. That would be great! I never quite convinced myself that it could be done reliably - in particular, you have to convert one from-Python parameter to two iterators before calling the constructor. You have to know somehow when to do this, and when to convert the object to a single C++ parameter (e.g. constructing vector(5)). > >> template >> vector(InputIterator f, InputIterator l, const Allocator& a = Allocator()) >> >> which would be the best one to use. I still haven't figured out the >> details of providing this. > > Well, I don't know much about the metaprogramming guts of either suite, > but I wrote this simple template to create a preallocated vector that I > initialize with extract<>(), and exported it using "injected > constructors" support: > > template > boost::shared_ptr > create_from_pysequence( object seq) > { > boost::shared_ptr ret( > new Container(extract(seq.attr("__len__")()))); > object seq_i = seq.attr("__iter__")(); > for ( typename Container::iterator i = ret->begin(); i != ret->end(); > ++i) { > *i = extract< typename Container::value_type>( > seq_i.attr("next")()); > } > return ret; > } What does the constructor injection look like? > > >> An easier way: >> >> def print_vec(foo): >> print [x for x in foo] > > Oooh. Nice. > >> > >> > # Should raise IndexError, or print backwards; actually prints the >> > # original >> > print_vector(foo[::-1]) >> >> That would be because the step value is ignored, right? > > Yes. > >> In any case, >> it's very useful to try this kind of test with a real Python list to >> see what "should" happen: >> >> >>> v = [1,2,3,4,5] >> >>> print v[::-1] >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: sequence index must be integer >> >> Would have to look that one up in the Python reference to see if it's >> documented! The indexing_v2 suite prints [5,4,3,2] which also can't >> really be right. > > Try it with Python 2.3. In Python 2.2, slicing support was extended for > builtin sequences to support __getitem__(slice(start,stop,step)), > whereas in Python 2.2 you only have the __getslice__(start,stop) form. Ah, OK. Just tried it in 2.3 and got [5,4,3,2,1]. Must be an off-by-one error for the None case in my __getitem__. > > I think that the right way to handle negative step sizes (when you can > choose the algorithm) is to use reverse iterators. The reason is that > when provided a negative step, the stop value defaults to "one before > the beginning" and the start value defaults to the last element. So > long as you are using the [begin,end) ranges for iterators, the only way > to make that work safely is with a reverse iterator and algorithm that > carefully accounts for the effects of non-singular step size. I don't try to support slices unless the container has random access (and then there's no need for a reverse iterator). > >> > >> > # I think this should raise IndexError; crashes. >> > foo[-1:0] = [7, 8, 9] >> >> With a real python list, it inserts 7, 8, 9 before the last element: >> >> >>> v = [1,2,3,4] >> >>> v[-1:0] = [7,8,9] >> >>> print v >> [1, 2, 3, 7, 8, 9, 4] > > Yes, that is what happens: performing an insertion before the provided > start value. However, I think that it should be an undefined operation > since the expression is utter nonsense. I've looked at the source code > for PyListObject, and I think that this behavior is the result of bounds > limiting rather than real error checking. I don't understand this. Assigning something into an empty slice in a container always performs an insertion. More generally, assigning a longer list to a plain slice with fewer elements performs insertion. e.g. >>> l = [1,2,3,4] >>> l[3:0] = [7,8,9] >>> print l [1, 2, 3, 7, 8, 9, 4] so why shouldn't this be exactly the same (in this case) as >>> l[-1:0] = [7,8,9] > > Furthermore if you try it with Numeric (the original source of rich > slices), you will find that it is a no-op, which is what I would rather > see in Boost now that I think a little more about it. I haven't used Numeric before - is it documented somewhere? > > See Python bug# 873305 at http://sourceforge.net/tracker/?group_id=5470 I don't see any place to enter the bug number - how do I get to see bug 873305? -- Raoul Gough. export LESS='-X' From grafik.list at redshift-software.com Fri Jan 9 04:36:41 2004 From: grafik.list at redshift-software.com (Rene Rivera) Date: Thu, 08 Jan 2004 21:36:41 -0600 Subject: [C++-sig] boost/python/detail/python22_fixed.h missing from Boost RC_1_31_0 installation In-Reply-To: <3FFD61FF.7040307@redshift-software.com> References: <1073537041.1606.10.camel@dsl.80.187.networkiowa.com> <3FFD61FF.7040307@redshift-software.com> Message-ID: <3FFE21C9.1020903@redshift-software.com> Rene Rivera wrote: > Patrick Hartling wrote: > >> I just made an installation of the Boost RC_1_31_0 branch, and I noticed >> that the file boost/python/detail/python22_fixed.h does not get >> installed. > I know what to change... I'll fix it tonight. And good catch on this one > :-) The problem is the install code is not checking for *.h files in the > includes only *.hpp files. OK fixed now. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq From jbrandmeyer at earthlink.net Fri Jan 9 04:49:40 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Thu, 08 Jan 2004 22:49:40 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> Message-ID: <1073620180.19759.565.camel@illuvatar> On Thu, 2004-01-08 at 20:55, Raoul Gough wrote: > Jonathan Brandmeyer writes: > > > On Thu, 2004-01-08 at 07:22, Raoul Gough wrote: > > > > > double > > partial_sum( std::vector* Foo, slice index) > > { > > slice::range > bounds; > > try { > > bounds = index.get_indicies( Foo->begin(), Foo->end()); > > } catch (std::invalid_argument) > > return 0.0; > > double ret = 0.0; > > while (bounds.start != bounds.stop) { > > ret += *bounds.start; > > std::advance( bounds.start, bounds.step); > > } > > ret += bounds.start; > > return ret; > > } > > Yes, I guess it makes a good deal of sense to use iterators in this > case. However, how would you make use of them from Python code? The idea is that you don't make use of the iterators from Python (Python has no notion of an iterator pair, anyway), you use the slice object to define the portion of the container to act upon as a kind of replacement for iterator pairs. Based on this question and the one about raw PySliceObject*'s, I don't think I've explained myself enough. Here is the rest of a complete, working example that uses the existing vector_indexing_suite and the patches I've proposed. // Add in the code from the above example, plus slice.hpp, slice.cpp, // and the patches I sent for slice_nil.hpp and object_core.hpp // Also add in the injected constructor that I wrote below in the // last message #include #include #include #include BOOST_PYTHON_MODULE(vector_test) { using namespace boost::python; class_ >( "float_vector") .def( "__init__", make_constructor( create_from_pysequence >)) .def( vector_indexing_suite >()) .def( "partial_sum", &partial_sum) ; } ----end file---- And now, in Python you can do this: >>> x = float_vector( [1,2,3,4,5,6]) >>> x.partial_sum( slice(None,None)) 21 >>> x.partial_sum( slice(3,-1)) 9 >>> x[3:].partial_sum(slice(None,None)) 15 > >> BTW, wouldn't it be a good idea to have a slice constructor that takes > >> a PySliceObject * as parameter? > > > > I try to avoid raw PyObject*'s whenever possible, but I think that the > > answer is "no". The reason is that you have no idea how to properly > > manage it. That is partially what the detail::new_reference<>, > > detail::borrowed_reference<>, and detail::new_non_null_reference<> are > > for, right?. Feel free to correct me if I'm wrong. > > I didn't necessarily mean a raw PySliceObject. All I'm getting at is, > if you want to implement __getitem__ then you will end up with a > PySliceObject created by the Python interpreter. AFAICS, you don't > have a way of generating one of your slice objects from this. Am I > missing something here? > > >>> part = v[1::4] > > calls v.__getitem__ with a PySliceObject (1, None, 4) *I* won't end up with a PySliceObject created by the Python interpreter, I will end up with a boost::python::slice object manager that has been automatically converted by def() and/or class_::def() from the original PySliceObject. > >> > ---crash_test.py--- > >> > # Uses the existing vector_indexing_suite_ext.cpp test modul > >> > from vector_indexing_suite_ext import * > >> > foo = FloatVec() > >> > # Weird initialization, why not supported by a constructor? > >> > > Well, I don't know much about the metaprogramming guts of either suite, > > but I wrote this simple template to create a preallocated vector that I > > initialize with extract<>(), and exported it using "injected > > constructors" support: > > > > template > > boost::shared_ptr > > create_from_pysequence( object seq) > > { > > boost::shared_ptr ret( > > new Container(extract(seq.attr("__len__")()))); > > object seq_i = seq.attr("__iter__")(); > > for ( typename Container::iterator i = ret->begin(); i != ret->end(); > > ++i) { > > *i = extract< typename Container::value_type>( > > seq_i.attr("next")()); > > } > > return ret; > > } > > What does the constructor injection look like? See above, and look at boost/libs/python/test/injected.{cpp,py}. > Ah, OK. Just tried it in 2.3 and got [5,4,3,2,1]. Must be an > off-by-one error for the None case in my __getitem__. > > > > > I think that the right way to handle negative step sizes (when you can > > choose the algorithm) is to use reverse iterators. The reason is that > > when provided a negative step, the stop value defaults to "one before > > the beginning" and the start value defaults to the last element. So > > long as you are using the [begin,end) ranges for iterators, the only way > > to make that work safely is with a reverse iterator and algorithm that > > carefully accounts for the effects of non-singular step size. > I don't try to support slices unless the container has random access > (and then there's no need for a reverse iterator). Why not? There is no reason whatsoever not to support every container with bidirectional iterators. You can even slice on maps if you want to, although such a thing has been forbidden for python dict's. > > > >> > > >> > # I think this should raise IndexError; crashes. > >> > foo[-1:0] = [7, 8, 9] > >> > >> With a real python list, it inserts 7, 8, 9 before the last element: > >> > >> >>> v = [1,2,3,4] > >> >>> v[-1:0] = [7,8,9] > >> >>> print v > >> [1, 2, 3, 7, 8, 9, 4] > > > > Yes, that is what happens: performing an insertion before the provided > > start value. However, I think that it should be an undefined operation > > since the expression is utter nonsense. I've looked at the source code > > for PyListObject, and I think that this behavior is the result of bounds > > limiting rather than real error checking. > > I don't understand this. Assigning something into an empty slice in a > container always performs an insertion. More generally, assigning a > longer list to a plain slice with fewer elements performs insertion. > e.g. No, assigning any sequence to a slice by calling object.__setslice__(slice, sequence) replaces the old slice with the values of the new slice IF the slice uses either -1 or 1 (either implicitly or explicitly) for its step size. If the step size is non-singular, then the sizes of the slice and the sequence must be identical. > >>> l = [1,2,3,4] > >>> l[3:0] = [7,8,9] Think about what this expression means: Starting at the fourth element inclusive, and ending at the first element, exclusive with an increment of forward 1, delete elements and replace them with the elements of the list [7,8,9]. That's like starting off by calling std::list::delete(start, stop) with a 'stop' iterator that is not reachable from 'start'! The issue isn't that you are performing an insertion after a well-defined point in the sequence, it is that you are performing a replacement of an undefined section of the sequence. > I haven't used Numeric before - is it documented somewhere? See numpy.sourceforge.net and in Debian the python2.2-numeric, python2.3-numeric, and python-numeric-tutorial packages. > > > > See Python bug# 873305 at http://sourceforge.net/tracker/?group_id=5470 > > I don't see any place to enter the bug number - how do I get to see > bug 873305? Sorry, that was my fault. Try this one: http://sourceforge.net/tracker/index.php?func=detail&aid=873305&group_id=5470&atid=305470 -Jonathan Brandmeyer From patrick at vrac.iastate.edu Fri Jan 9 06:38:22 2004 From: patrick at vrac.iastate.edu (Patrick Hartling) Date: Thu, 08 Jan 2004 23:38:22 -0600 Subject: [C++-sig] boost/python/detail/python22_fixed.h missing from Boost RC_1_31_0 installation In-Reply-To: <3FFE21C9.1020903@redshift-software.com> References: <1073537041.1606.10.camel@dsl.80.187.networkiowa.com> <3FFD61FF.7040307@redshift-software.com> <3FFE21C9.1020903@redshift-software.com> Message-ID: <1073626702.2066.0.camel@dsl.80.187.networkiowa.com> On Thu, 2004-01-08 at 21:36, Rene Rivera wrote: > Rene Rivera wrote: > > > Patrick Hartling wrote: > > > >> I just made an installation of the Boost RC_1_31_0 branch, and I noticed > >> that the file boost/python/detail/python22_fixed.h does not get > >> installed. > > > I know what to change... I'll fix it tonight. And good catch on this one > > :-) The problem is the install code is not checking for *.h files in the > > includes only *.hpp files. > > > > OK fixed now. Thanks for the quick turnaround on this fix! -Patrick -- Patrick L. Hartling | Research Assistant, VRAC patrick at vrac.iastate.edu | 2274 Howe Hall Room 2624 http://www.137.org/patrick/ | http://www.vrac.iastate.edu/ PGP: http://wwwkeys.gpg.cz:11371/pks/lookup?op=get&search=0xEBF86398 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: This is a digitally signed message part URL: From gilles.orazi at varianinc.com Fri Jan 9 08:56:54 2004 From: gilles.orazi at varianinc.com (Gilles Orazi) Date: Fri, 09 Jan 2004 08:56:54 +0100 Subject: [C++-sig] Re: (no subject) In-Reply-To: References: <5.2.0.9.2.20040108162001.00b53b90@begonia.varianinc.com> Message-ID: <5.2.0.9.2.20040109085614.00b4ac00@begonia.varianinc.com> Thanks a lot ! Gilles. At 17:52 08/01/2004, you wrote: >Gilles Orazi writes: > > > We have seen on the boost-consulting web site that there exists a file > > called boost/python/indexing/indexing_suite.hpp that just fit our needs. > > Unfortunately, we were unable to find it in our boost sources. It seems > > that we have the lastest available version (1.30.2). > > Where could we find this file ? > > Thanks a lot by advance for your answer. > >I guess you mean boost/python/suite/indexing/indexing_suite.hpp ? This >is due for the 1.31 release, but until then is available via >CVS. Refer to http://www.boost.org/more/download.html#CVS for further >information. ISTR there also an automatically-updated tarball >somewhere. > >You might like to note that a newer version of the indexing suite >under development, and may eventually replace the existing indexing >suite (search for indexing_v2 in this list if you're interested). > >-- >Raoul Gough. >export LESS='-X' > > >_______________________________________________ >C++-sig mailing list >C++-sig at python.org >http://mail.python.org/mailman/listinfo/c++-sig From james.gunn at communisis-dm.co.uk Fri Jan 9 11:57:32 2004 From: james.gunn at communisis-dm.co.uk (James Gunn) Date: Fri, 9 Jan 2004 10:57:32 -0000 Subject: [C++-sig] Extending & embedding Python? Message-ID: <7A7AACCC920AD511BF510090273C2730022D4F09@CHORPCSRV001> *** Before acting on this e-mail or opening any attachment you are advised to read the disclaimer at the end of this e-mail *** Hi all, I've been trying to use boost::python to extend and embed Python into my app. The problem is that I have a C++ object that I want to instantiate and then pass into Python so that my scripts can update it. When the script has finished I need to get access to the current state of my C++ object. I almost had it working yesterday, however, when my script had finished running the state had not been updated...I think this is because instead of Python referencing the same C++ object it had created a new one. Is there a way around this? I've looked through the docs and the documentation but I'm a bit lost/stuck. You may wonder why I need to do this...basically I need an Observer/Observable setup. I need to be able to get progress information back from the Python script. Any help or pointers to docs will be appreciated. Thanks in advance. James Gunn Software Developer Communisis Chorleys Ltd Computer Bureau Manston Lane Crossgates Leeds LS15 8AH Tel: 0113 305 3001 Email: James.Gunn at communisis-dm.co.uk ********************************************************************** Please note: This e-mail and its attachments contain only the opinions of the sender and do not necessarily reflect the policy(s) of the communisis group in general. Employees of the communisis group are required not to make any defamatory statements and not to infringe or authorise any infringement of copyright or any other legal right by e-mail. Any such communication is therefore outside the scope of employment of the individual concerned. The communisis group will not accept any liability in respect of such a communication. Confidentiality: This e-mail and any attachments, together with their contents, are confidential unless otherwise explicitly stated in writing by the sender of this e-mail and are for the intended recipient only. If they have come to you in error you must not take any action in respect of them, which includes but is not limited to reproducing, sending or storing them, other than to notifying the sender immediately of the mistake, and deleting the e-mail, any attachments and any reproductions made by replying to it. Viruses: This e-mail and any attachments have been scanned for viruses but we cannot guarantee that they are virus free. The recipient should check this e-mail and any attachments for viruses. The communisis group accepts no responsibility for any damage caused by any virus transmitted by this e-mail or any of its attachments. In the event of any unauthorised copying or forwarding, the recipient will be required to indemnify the communisis group against any claim for loss or damage caused by any viruses or otherwise. ********************************************************************** ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs Email Security System. For more information on a proactive email security service working around the clock, around the globe, visit http://www.messagelabs.com ________________________________________________________________________ From nbecker at hns.com Fri Jan 9 14:07:28 2004 From: nbecker at hns.com (Neal D. Becker) Date: Fri, 09 Jan 2004 08:07:28 -0500 Subject: [C++-sig] std::complex? Message-ID: How do I reflect std::complex into python? #include #include #include #include #include using namespace boost::python; BOOST_PYTHON_MODULE(hello) { class_ >("DoubleVec") .def(init()) .def(vector_indexing_suite >()) ; class_ > >("CDoubleVec") .def(init()) .def(vector_indexing_suite > >()) ; } z=CDoubleVec(2) >>> z >>> z[0] Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class std::complex I also will need std::complex. What would I need for this? From RaoulGough at yahoo.co.uk Fri Jan 9 14:19:01 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 09 Jan 2004 13:19:01 +0000 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Thu, 2004-01-08 at 20:55, Raoul Gough wrote: [snip] >> part = v[1::4] >> >> calls v.__getitem__ with a PySliceObject (1, None, 4) > > *I* won't end up with a PySliceObject created by the Python interpreter, > I will end up with a boost::python::slice object manager that has been > automatically converted by def() and/or class_::def() from the original > PySliceObject. Well, that's the bit I don't understand. How do you create a boost::python::slice object from a PySliceObject without a suitable constructor? Unless you're just not interested in covering this case. [snip] >> I don't try to support slices unless the container has random access >> (and then there's no need for a reverse iterator). > > Why not? There is no reason whatsoever not to support every container > with bidirectional iterators. You can even slice on maps if you want > to, although such a thing has been forbidden for python dict's. Sure it's possible. I didn't see much need to do it though. For instance, if you have a C++ std::list exposed to Python, do you really want to be able to do: >>> cxx_list[87] or >>> cxx_list[20:80:4] Maybe you do, but I think you would probably be better off with std::vector. > >> > >> >> > >> >> > # I think this should raise IndexError; crashes. >> >> > foo[-1:0] = [7, 8, 9] >> >> >> >> With a real python list, it inserts 7, 8, 9 before the last element: >> >> >> >> >>> v = [1,2,3,4] >> >> >>> v[-1:0] = [7,8,9] >> >> >>> print v >> >> [1, 2, 3, 7, 8, 9, 4] >> > >> > Yes, that is what happens: performing an insertion before the provided >> > start value. However, I think that it should be an undefined operation >> > since the expression is utter nonsense. I've looked at the source code >> > for PyListObject, and I think that this behavior is the result of bounds >> > limiting rather than real error checking. >> >> I don't understand this. Assigning something into an empty slice in a >> container always performs an insertion. More generally, assigning a >> longer list to a plain slice with fewer elements performs insertion. >> e.g. > > No, assigning any sequence to a slice by calling > object.__setslice__(slice, sequence) replaces the old slice with the > values of the new slice IF the slice uses either -1 or 1 (either > implicitly or explicitly) for its step size. If the step size is > non-singular, then the sizes of the slice and the sequence must be > identical. The lack of a step size is what I was getting at with "plain slice". I guess I should have been more precise. > >> >>> l = [1,2,3,4] >> >>> l[3:0] = [7,8,9] > > Think about what this expression means: Starting at the fourth element > inclusive, and ending at the first element, exclusive with an increment > of forward 1, delete elements and replace them with the elements of the > list [7,8,9]. That's like starting off by calling > std::list::delete(start, stop) with a 'stop' iterator that is not > reachable from 'start'! But that's not the way *Python* does things. Are you saying that lst[3:0] should just crash the interpreter? That's what a C++ algorithm would probably do with that kind of input. > > The issue isn't that you are performing an insertion after a > well-defined point in the sequence, it is that you are performing a > replacement of an undefined section of the sequence. I would argue that the section of the sequence *is* well defined. > >> I haven't used Numeric before - is it documented somewhere? > > See numpy.sourceforge.net and in Debian the python2.2-numeric, > python2.3-numeric, and python-numeric-tutorial packages. >From what I can see, the arrays can't change in length, so obviously they don't support insertion, or replacing a shorter slice with a longer sequence. > >> > >> > See Python bug# 873305 at http://sourceforge.net/tracker/?group_id=5470 >> >> I don't see any place to enter the bug number - how do I get to see >> bug 873305? > > Sorry, that was my fault. Try this one: > http://sourceforge.net/tracker/index.php?func=detail&aid=873305&group_id=5470&atid=305470 > I don't think I agree with what you're saying here. Would you agree that __getitem__ from e.g. lst[4:2] should be an empty sequence? Quoting from http://www.python.org/doc/current/lib/typesseq.html "(4) [...] If i is greater than or equal to j, the slice is empty." I think that's pretty clear for __getitem__. So now the question is, what is the result of replacing an empty slice in a container with a non-empty sequence? If the container supports insertion, inserting the sequence seems logical enough to me. -- Raoul Gough. export LESS='-X' From seefeld at sympatico.ca Fri Jan 9 15:01:06 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 09 Jan 2004 09:01:06 -0500 Subject: [C++-sig] Extending & embedding Python? References: <7A7AACCC920AD511BF510090273C2730022D4F09@CHORPCSRV001> Message-ID: <36905f199e9dd689305880508151e1203ffeb1a0@Orthosoft.ca> James Gunn wrote: > I almost had it working yesterday, however, when my script had finished > running > the state had not been updated...I think this is because instead of Python > referencing the same C++ object it had created a new one. Is there a way > around > this? I've looked through the docs and the documentation but I'm a bit > lost/stuck. It's hard to make any guess without some more detail (such as code snippets). If you are not sure whether the objects are passed by value (i.e. copied) or by reference, you may want to have a close look at boost.python's 'call policies' (for example http://www.boost.org/libs/python/doc/tutorial/doc/call_policies.html). What you have in mind should certainly work. HTH, Stefan From jbrandmeyer at earthlink.net Fri Jan 9 15:37:32 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 09 Jan 2004 09:37:32 -0500 Subject: [C++-sig] std::complex? In-Reply-To: References: Message-ID: <1073659052.19547.636.camel@illuvatar> On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote: > How do I reflect std::complex into python? Well, there isn't any prebuilt suite for exporting that type to Python, so you would have to write something along the lines of template void wrap_std_complex( std::string name) { class_ >(name, init >()) .def( "imag", &std::complex::imag) .def( self + self) // ... and so on and so forth ; } The upside is that you will only have to do it once since you will be able to reuse that template by calling different versions of it from the module definition. > #include > #include > #include > #include > #include > > using namespace boost::python; > > > BOOST_PYTHON_MODULE(hello) > { > > class_ >("DoubleVec") > .def(init()) > .def(vector_indexing_suite >()) > ; > > class_ > >("CDoubleVec") > .def(init()) > .def(vector_indexing_suite > >()) > ; wrap_std_complex("CDouble"); wrap_std_complex("CInt"); > > } > z=CDoubleVec(2) > >>> z > > >>> z[0] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No Python class registered for C++ class std::complex > > I also will need std::complex. What would I need for this? > Hope that helps, Jonathan Brandmeyer From james.gunn at communisis-dm.co.uk Fri Jan 9 15:34:29 2004 From: james.gunn at communisis-dm.co.uk (James Gunn) Date: Fri, 9 Jan 2004 14:34:29 -0000 Subject: [C++-sig] Extending & embedding Python? Message-ID: <7A7AACCC920AD511BF510090273C2730022D4F0A@CHORPCSRV001> *** Before acting on this e-mail or opening any attachment you are advised to read the disclaimer at the end of this e-mail *** Hi Stefan, > From: Stefan Seefeld [mailto:seefeld at sympatico.ca] > > James Gunn wrote: > > > I almost had it working yesterday, however, when my script > had finished > > running > > the state had not been updated...I think this is because > instead of Python > > referencing the same C++ object it had created a new one. > Is there a way > > around > > this? I've looked through the docs and the documentation > but I'm a bit > > lost/stuck. > > > It's hard to make any guess without some more detail (such as code > snippets). If you are not sure whether the objects are passed by value > (i.e. copied) or by reference, you may want to have a close look at > boost.python's 'call policies' (for example > > http://www.boost.org/libs/python/doc/tutorial/doc/call_policies.html). > > What you have in mind should certainly work. Thanks for the quick response. I'll try and get something together to show exactly what I'm doing. Cheers, James ********************************************************************** Please note: This e-mail and its attachments contain only the opinions of the sender and do not necessarily reflect the policy(s) of the communisis group in general. Employees of the communisis group are required not to make any defamatory statements and not to infringe or authorise any infringement of copyright or any other legal right by e-mail. Any such communication is therefore outside the scope of employment of the individual concerned. The communisis group will not accept any liability in respect of such a communication. Confidentiality: This e-mail and any attachments, together with their contents, are confidential unless otherwise explicitly stated in writing by the sender of this e-mail and are for the intended recipient only. If they have come to you in error you must not take any action in respect of them, which includes but is not limited to reproducing, sending or storing them, other than to notifying the sender immediately of the mistake, and deleting the e-mail, any attachments and any reproductions made by replying to it. Viruses: This e-mail and any attachments have been scanned for viruses but we cannot guarantee that they are virus free. The recipient should check this e-mail and any attachments for viruses. The communisis group accepts no responsibility for any damage caused by any virus transmitted by this e-mail or any of its attachments. In the event of any unauthorised copying or forwarding, the recipient will be required to indemnify the communisis group against any claim for loss or damage caused by any viruses or otherwise. ********************************************************************** ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs Email Security System. For more information on a proactive email security service working around the clock, around the globe, visit http://www.messagelabs.com ________________________________________________________________________ From dave at boost-consulting.com Fri Jan 9 15:53:56 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 09:53:56 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: "Neal D. Becker" writes: > How do I reflect std::complex into python? > #include > #include > #include > #include > #include > > using namespace boost::python; > > > BOOST_PYTHON_MODULE(hello) > { > > class_ >("DoubleVec") > .def(init()) > .def(vector_indexing_suite >()) > ; > > class_ > >("CDoubleVec") > .def(init()) > .def(vector_indexing_suite > >()) > ; > > } > z=CDoubleVec(2) >>>> z > >>>> z[0] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: No Python class registered for C++ class std::complex That's because the vector_indexing_suite is trying to treat std::complex like any other class, instead of like an int (i.e. a type with an immutable Python counterpart). I don't know what the answer to that is, though. Joel/Raoul? > I also will need std::complex. What would I need for this? complex isn't even guaranteed to work by the C++ standard. You'd need to explicitly register to/from-python converters for it. -- Dave Abrahams Boost Consulting www.boost-consulting.com From RaoulGough at yahoo.co.uk Fri Jan 9 16:03:22 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 09 Jan 2004 15:03:22 +0000 Subject: [C++-sig] Re: std::complex? References: Message-ID: David Abrahams writes: > "Neal D. Becker" writes: [snip] >> z=CDoubleVec(2) >>>>> z >> >>>>> z[0] >> Traceback (most recent call last): >> File "", line 1, in ? >> TypeError: No Python class registered for C++ class std::complex > > That's because the vector_indexing_suite is trying to treat > std::complex like any other class, instead of like an int (i.e. a > type with an immutable Python counterpart). I don't know what the > answer to that is, though. Joel/Raoul? > >> I also will need std::complex. What would I need for this? > > complex isn't even guaranteed to work by the C++ standard. You'd > need to explicitly register to/from-python converters for it. I think what Jonathan Brandmeyer was suggesting would do the trick. The indexing suite(s) just assume that the contained type is already known to Python, and the easiest way to do that is to create a boost::python::class_ instance for it. -- Raoul Gough. export LESS='-X' From nbecker at hns.com Fri Jan 9 16:13:21 2004 From: nbecker at hns.com (Neal D. Becker) Date: Fri, 09 Jan 2004 10:13:21 -0500 Subject: [C++-sig] Re: std::complex? References: <1073659052.19547.636.camel@illuvatar> Message-ID: Jonathan Brandmeyer wrote: > On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote: >> How do I reflect std::complex into python? > > Well, there isn't any prebuilt suite for exporting that type to Python, > so you would have to write something along the lines of > > template > void > wrap_std_complex( std::string name) > { > class_ >(name, init >()) > .def( "imag", &std::complex::imag) > .def( self + self) > // ... and so on and so forth > ; > } > Thanks so much for your reply. I am an amateur at this - what documents can I find that would help me to complete the above outlined example? From nbecker at hns.com Fri Jan 9 16:36:07 2004 From: nbecker at hns.com (Neal D. Becker) Date: Fri, 09 Jan 2004 10:36:07 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: Raoul Gough wrote: > David Abrahams writes: > >> "Neal D. Becker" writes: > [snip] >>> z=CDoubleVec(2) >>>>>> z >>> >>>>>> z[0] >>> Traceback (most recent call last): >>> File "", line 1, in ? >>> TypeError: No Python class registered for C++ class std::complex >> >> That's because the vector_indexing_suite is trying to treat >> std::complex like any other class, instead of like an int (i.e. a >> type with an immutable Python counterpart). I don't know what the >> answer to that is, though. Joel/Raoul? >> >>> I also will need std::complex. What would I need for this? >> >> complex isn't even guaranteed to work by the C++ standard. You'd >> need to explicitly register to/from-python converters for it. > > I think what Jonathan Brandmeyer was suggesting would do the > trick. The indexing suite(s) just assume that the contained type is > already known to Python, and the easiest way to do that is to create a > boost::python::class_ instance for it. > I noticed in boost.cvs/boost/python/converter/builtin_converters.hpp: BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, ::PyComplex_FromDoubles(x.real(), x.imag())) BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, ::PyComplex_FromDoubles(x.real(), x.imag())) BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::complex, ::PyComplex_FromDoubles(x.real(), x.imag())) Does this suggest that some of the machinery is already there? From jbrandmeyer at earthlink.net Fri Jan 9 17:17:50 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 09 Jan 2004 11:17:50 -0500 Subject: [C++-sig] Re: std::complex? In-Reply-To: References: <1073659052.19547.636.camel@illuvatar> Message-ID: <1073665070.19758.757.camel@illuvatar> On Fri, 2004-01-09 at 10:13, Neal D. Becker wrote: > Jonathan Brandmeyer wrote: > > > On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote: > >> How do I reflect std::complex into python? > > > > Well, there isn't any prebuilt suite for exporting that type to Python, > > so you would have to write something along the lines of > > > > template > > void > > wrap_std_complex( std::string name) > > { > > class_ >(name, init >()) > > .def( "imag", &std::complex::imag) > > .def( self + self) > > // ... and so on and so forth > > ; > > } > > > > Thanks so much for your reply. I am an amateur at this - what documents can > I find that would help me to complete the above outlined example? > boost/libs/python/doc/index.html in the source package. From jbrandmeyer at earthlink.net Fri Jan 9 17:30:17 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 09 Jan 2004 11:30:17 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> Message-ID: <1073665816.19758.775.camel@illuvatar> On Fri, 2004-01-09 at 08:19, Raoul Gough wrote: > Jonathan Brandmeyer writes: > > > On Thu, 2004-01-08 at 20:55, Raoul Gough wrote: > [snip] > >> part = v[1::4] > >> > >> calls v.__getitem__ with a PySliceObject (1, None, 4) > > > > *I* won't end up with a PySliceObject created by the Python interpreter, > > I will end up with a boost::python::slice object manager that has been > > automatically converted by def() and/or class_::def() from the original > > PySliceObject. > > Well, that's the bit I don't understand. How do you create a > boost::python::slice object from a PySliceObject without a suitable > constructor? Unless you're just not interested in covering this case. What I believe happens is that PySlice_Check() is called on the PyObject* that is being tested to see if it can be wrapped. If true, then a slice object is created by calling boost::python::slice( detail::borrowed_reference(PyObject*)). Then, if you want to get the objects that the slice was defined with by calling slice::start(), slice::stop(), or slice::step(), each of those functions must cast the wrapped PyObject* to a PySliceObject*. This is guaranteed to be safe since the slice object is never created without either a) creating a new PySliceObject, or b) calling PySlice_Check() first. To the best of my knowledge, that's how most of the object managers work. Can you give me a complete example where you need this extra constructor? Maybe then I'll know how to answer you better. > >> >> > # I think this should raise IndexError; crashes. > >> >> > foo[-1:0] = [7, 8, 9] > >> >> > >> >> With a real python list, it inserts 7, 8, 9 before the last element: > >> >> > >> >> >>> v = [1,2,3,4] > >> >> >>> v[-1:0] = [7,8,9] > >> >> >>> print v > >> >> [1, 2, 3, 7, 8, 9, 4] > >> > > >> > Yes, that is what happens: performing an insertion before the provided > >> > start value. However, I think that it should be an undefined operation > >> > since the expression is utter nonsense. I've looked at the source code > >> > for PyListObject, and I think that this behavior is the result of bounds > >> > limiting rather than real error checking. > >> > >> I don't understand this. Assigning something into an empty slice in a > >> container always performs an insertion. More generally, assigning a > >> longer list to a plain slice with fewer elements performs insertion. > >> e.g. > > > > No, assigning any sequence to a slice by calling > > object.__setslice__(slice, sequence) replaces the old slice with the > > values of the new slice IF the slice uses either -1 or 1 (either > > implicitly or explicitly) for its step size. If the step size is > > non-singular, then the sizes of the slice and the sequence must be > > identical. > > The lack of a step size is what I was getting at with "plain slice". I > guess I should have been more precise. > > > > >> >>> l = [1,2,3,4] > >> >>> l[3:0] = [7,8,9] > > > > Think about what this expression means: Starting at the fourth element > > inclusive, and ending at the first element, exclusive with an increment > > of forward 1, delete elements and replace them with the elements of the > > list [7,8,9]. That's like starting off by calling > > std::list::delete(start, stop) with a 'stop' iterator that is not > > reachable from 'start'! > > But that's not the way *Python* does things. Are you saying that > lst[3:0] should just crash the interpreter? That's what a C++ > algorithm would probably do with that kind of input. No, I'm saying that lst[3:0] should be empty. The difference is that in the Python case we can immediately determine that the stop position is not reachable from the start position and take appropriate action: Do Nothing. > > > > The issue isn't that you are performing an insertion after a > > well-defined point in the sequence, it is that you are performing a > > replacement of an undefined section of the sequence. > > I would argue that the section of the sequence *is* well defined. > > > > >> > > >> > See Python bug# 873305 at > > http://sourceforge.net/tracker/index.php?func=detail&aid=873305&group_id=5470&atid=305470 > > > > I don't think I agree with what you're saying here. Would you agree > that __getitem__ from e.g. lst[4:2] should be an empty sequence? > > Quoting from http://www.python.org/doc/current/lib/typesseq.html > > "(4) [...] If i is greater than or equal to j, the slice is empty." Section 5.3.3 of the Python Language Reference includes: "The slicing now selects all items with index k such that i <= k < j where i and j are the specified lower and upper bounds. This may be an empty sequence." I claim that not only are there no elements to be replaced in the case of __setitem__ with such a slice, but that this doesn't clearly define a point to insert new elements, either. > > I think that's pretty clear for __getitem__. Yes, and my patch doesn't modify that behavior. > So now the question is, > what is the result of replacing an empty slice in a container with a > non-empty sequence? If the container supports insertion, inserting the > sequence seems logical enough to me. So how do you define the point to perform the insertion? If the user asks to replace every element that is greater than or equal to the fourth and less than the first element, where do you place the new sequence? The current action for a built-in list is to range-limit the stop point to be not less than the start point, but I think that is just for safety rather than an API decision, and that it is wrong. -Jonathan Brandmeyer From dave at boost-consulting.com Fri Jan 9 17:39:48 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 11:39:48 -0500 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: >> I don't think I agree with what you're saying here. Would you agree >> that __getitem__ from e.g. lst[4:2] should be an empty sequence? >> >> Quoting from http://www.python.org/doc/current/lib/typesseq.html >> >> "(4) [...] If i is greater than or equal to j, the slice is empty." > > Section 5.3.3 of the Python Language Reference includes: "The slicing > now selects all items with index k such that i <= k < j where i and j > are the specified lower and upper bounds. This may be an empty > sequence." > > I claim that not only are there no elements to be replaced in the case > of __setitem__ with such a slice, but that this doesn't clearly define a > point to insert new elements, either. Doesn't the following pretty much settle the question of what the Pythonic behavior is? $ python Python 2.3.2 (#1, Nov 14 2003, 18:13:01) [GCC 3.3.1 (cygming special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> l = range(100,120) >>> l[5:2] = range(6) >>> l [100, 101, 102, 103, 104, 0, 1, 2, 3, 4, 5, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119] -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Fri Jan 9 17:41:56 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 11:41:56 -0500 Subject: [C++-sig] Re: std::complex? References: <1073659052.19547.636.camel@illuvatar> Message-ID: <4qv53wh7.fsf@boost-consulting.com> Jonathan Brandmeyer writes: > On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote: >> How do I reflect std::complex into python? > > Well, there isn't any prebuilt suite for exporting that type to Python, > so you would have to write something along the lines of > > template > void > wrap_std_complex( std::string name) > { > class_ >(name, init >()) > .def( "imag", &std::complex::imag) > .def( self + self) > // ... and so on and so forth > ; > } > > The upside is that you will only have to do it once since you will be > able to reuse that template by calling different versions of it from the > module definition. It won't work. Why do I get the feeling everyone's ignoring my posts? Have I been silent too long? I did design this library, y'know! ;-> There's a built-in specializations of the to_python converter for complex which turns it into a Python complex object, so no dynamic class registration will help when it comes to converting return values. -- Dave Abrahams Boost Consulting www.boost-consulting.com From jbrandmeyer at earthlink.net Fri Jan 9 18:20:30 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 09 Jan 2004 12:20:30 -0500 Subject: [C++-sig] Re: std::complex? In-Reply-To: <4qv53wh7.fsf@boost-consulting.com> References: <1073659052.19547.636.camel@illuvatar> <4qv53wh7.fsf@boost-consulting.com> Message-ID: <1073668830.19546.783.camel@illuvatar> On Fri, 2004-01-09 at 11:41, David Abrahams wrote: > Jonathan Brandmeyer writes: > > > On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote: > >> How do I reflect std::complex into python? > > > > Well, there isn't any prebuilt suite for exporting that type to Python, > > so you would have to write something along the lines of > > > > template > > void > > wrap_std_complex( std::string name) > > { > > class_ >(name, init >()) > > .def( "imag", &std::complex::imag) > > .def( self + self) > > // ... and so on and so forth > > ; > > } > > > > The upside is that you will only have to do it once since you will be > > able to reuse that template by calling different versions of it from the > > module definition. > > It won't work. Why do I get the feeling everyone's ignoring my posts? > Have I been silent too long? I did design this library, y'know! ;-> Sorry :) > There's a built-in specializations of the to_python converter for > complex which turns it into a Python complex object, so no > dynamic class registration will help when it comes to converting > return values. I didn't realize by the comment "... instead of like an int (ie, a type with an immutable python counterpart)" that it was already set up that way for std::complex. Now I understand that what you meant is that it *should* have worked and returned a Python complex object rather than raising the exception "TypeError: No Python class registered for C++ class std::complex" My apologies, Jonathan Brandmeyer From jbrandmeyer at earthlink.net Fri Jan 9 18:31:11 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Fri, 09 Jan 2004 12:31:11 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> Message-ID: <1073669470.19758.793.camel@illuvatar> On Fri, 2004-01-09 at 11:39, David Abrahams wrote: > Jonathan Brandmeyer writes: > > >> I don't think I agree with what you're saying here. Would you agree > >> that __getitem__ from e.g. lst[4:2] should be an empty sequence? > >> > >> Quoting from http://www.python.org/doc/current/lib/typesseq.html > >> > >> "(4) [...] If i is greater than or equal to j, the slice is empty." > > > > Section 5.3.3 of the Python Language Reference includes: "The slicing > > now selects all items with index k such that i <= k < j where i and j > > are the specified lower and upper bounds. This may be an empty > > sequence." > > > > I claim that not only are there no elements to be replaced in the case > > of __setitem__ with such a slice, but that this doesn't clearly define a > > point to insert new elements, either. > > Doesn't the following pretty much settle the question of what the > Pythonic behavior is? > $ python > Python 2.3.2 (#1, Nov 14 2003, 18:13:01) > [GCC 3.3.1 (cygming special)] on cygwin > Type "help", "copyright", "credits" or "license" for more information. > >>> l = range(100,120) > >>> l[5:2] = range(6) > >>> l > [100, 101, 102, 103, 104, 0, 1, 2, 3, 4, 5, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119] Yes it does. Maybe I'm being arrogant here, but I think that behavior is wrong, and I think it strongly enough that I submitted a patch to Python to change it. I think at this point we should just let this argument rest for a bit pending the resolution of the patch I submitted to Python, or at least, to move any additional comments to the sourceforge tracker for that patch. -Jonathan Brandmeyer From nbecker at hns.com Fri Jan 9 18:47:21 2004 From: nbecker at hns.com (Neal D. Becker) Date: Fri, 09 Jan 2004 12:47:21 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: Raoul Gough wrote: > David Abrahams writes: > >> "Neal D. Becker" writes: > [snip] >>> z=CDoubleVec(2) >>>>>> z >>> >>>>>> z[0] >>> Traceback (most recent call last): >>> File "", line 1, in ? >>> TypeError: No Python class registered for C++ class std::complex >> >> That's because the vector_indexing_suite is trying to treat >> std::complex like any other class, instead of like an int (i.e. a >> type with an immutable Python counterpart). I don't know what the >> answer to that is, though. Joel/Raoul? >> >>> I also will need std::complex. What would I need for this? >> >> complex isn't even guaranteed to work by the C++ standard. You'd >> need to explicitly register to/from-python converters for it. > > I think what Jonathan Brandmeyer was suggesting would do the > trick. The indexing suite(s) just assume that the contained type is > already known to Python, and the easiest way to do that is to create a > boost::python::class_ instance for it. > >From reading the docs, I got the idea that to_python_converter should work. I tried: using namespace boost::python; struct whatever { static PyObject* convert (std::complex const& x) { return PyComplex_FromCComplex(*reinterpret_cast (&x)); } }; BOOST_PYTHON_MODULE(hello) { class_ >("DoubleVec") .def(init()) .def(vector_indexing_suite >()) ; to_python_converter, whatever>(); class_ > >("CDoubleVec") .def(init()) .def(vector_indexing_suite > >()) ; } from hello import * >>> v=CDoubleVec(2) >>> v >>> v[0] Traceback (most recent call last): File "", line 1, in ? TypeError: No Python class registered for C++ class std::complex 1. I don't know why this doesn't work. 2. I don't know if this has the right semantics. I want the python complex value to be a reference to the c++ one. Am I on the correct track here? Can anyone give me a clue? From dave at boost-consulting.com Fri Jan 9 19:39:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 13:39:11 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: "Neal D. Becker" writes: >>From reading the docs, I got the idea that to_python_converter > should work. The library is already handling std::complex. It will work for std::complex, but then you need the other part of the equation: something in the indexing suite to say that the vector's values need to be returned by value and not by reference. > > 1. I don't know why this doesn't work. > 2. I don't know if this has the right semantics. I want the python complex > value to be a reference to the c++ one. No you don't; trust me ;-) There isn't really a good way to do that, since the library already has decided that std::complex becomes a Python complex object. > Am I on the correct track here? Can anyone give me a clue? Been trying? How'm I doing? -- Dave Abrahams Boost Consulting www.boost-consulting.com From nbecker at hns.com Fri Jan 9 20:37:55 2004 From: nbecker at hns.com (Neal D. Becker) Date: Fri, 09 Jan 2004 14:37:55 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: David Abrahams wrote: > "Neal D. Becker" writes: > >>>From reading the docs, I got the idea that to_python_converter >> should work. > > The library is already handling std::complex. > It will work for std::complex, but then you need the other part > of the equation: something in the indexing suite to say that the > vector's values need to be returned by value and not by reference. > >> >> 1. I don't know why this doesn't work. >> 2. I don't know if this has the right semantics. I want the python >> complex value to be a reference to the c++ one. > > No you don't; trust me ;-) > > There isn't really a good way to do that, since the library already > has decided that std::complex becomes a Python complex object. > >> Am I on the correct track here? Can anyone give me a clue? > > Been trying? How'm I doing? > I'm still confused. Let's try 1 thing at a time. Forget about complex for now. All I want, is to write C++ algorithms that use std::vector< std::complex > as arguments. I want to 1. pass such data from python -> c++. 2. read elements of data in python (e.g. print v[i]) 3. write elements from python (e.g., v[i] = 10) So, what I need is probably not surprising. What do I need to do? If I can get this one working, then I'll see about complex later. From RaoulGough at yahoo.co.uk Sat Jan 10 00:41:13 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Fri, 09 Jan 2004 23:41:13 +0000 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Fri, 2004-01-09 at 08:19, Raoul Gough wrote: >> Jonathan Brandmeyer writes: >> >> > On Thu, 2004-01-08 at 20:55, Raoul Gough wrote: >> [snip] >> >> part = v[1::4] >> >> >> >> calls v.__getitem__ with a PySliceObject (1, None, 4) >> > >> > *I* won't end up with a PySliceObject created by the Python interpreter, >> > I will end up with a boost::python::slice object manager that has been >> > automatically converted by def() and/or class_::def() from the original >> > PySliceObject. >> >> Well, that's the bit I don't understand. How do you create a >> boost::python::slice object from a PySliceObject without a suitable >> constructor? Unless you're just not interested in covering this case. > > What I believe happens is that PySlice_Check() is called on the > PyObject* that is being tested to see if it can be wrapped. If true, > then a slice object is created by calling boost::python::slice( > detail::borrowed_reference(PyObject*)). Then, if you want to get the > objects that the slice was defined with by calling slice::start(), > slice::stop(), or slice::step(), each of those functions must cast the > wrapped PyObject* to a PySliceObject*. This is guaranteed to be safe > since the slice object is never created without either a) creating a new > PySliceObject, or b) calling PySlice_Check() first. To the best of my > knowledge, that's how most of the object managers work. > > Can you give me a complete example where you need this extra > constructor? Maybe then I'll know how to answer you better. Sorry - my mistake! I missed the following in your code (at the end of the slice class): // This declaration, in conjunction with the specialization of // object_manager_traits<> below, allows C++ functions accepting // slice arguments to be called from from Python. These // constructors should never be used in client code. BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, object) I thought I'd seen all of the constructors, but missed this one, and searching for PySliceObject didn't find anything of course. Thanks for clarifying this for me. [snip] > So how do you define the point to perform the insertion? If the user > asks to replace every element that is greater than or equal to the > fourth and less than the first element, where do you place the new > sequence? Well, that's an interesting question when you put it like that, independant of implementation issues. In practice, I guess it's just natural that it should go at the starting index, since you would have initialized some kind of variable to this before determining that you're already outside the range of the slice. I know that's how my code works. -- Raoul Gough. export LESS='-X' From dave at boost-consulting.com Sat Jan 10 03:10:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 21:10:50 -0500 Subject: [C++-sig] Re: std::complex? References: Message-ID: <3cao3651.fsf@boost-consulting.com> "Neal D. Becker" writes: > I'm still confused. > > Let's try 1 thing at a time. Forget about complex for now. > > All I want, is to write C++ algorithms that use > std::vector< std::complex > as arguments. I want to > > 1. pass such data from python -> c++. > 2. read elements of data in python (e.g. print v[i]) > 3. write elements from python (e.g., v[i] = 10) > > So, what I need is probably not surprising. What do I need to do? As far as I can tell from the docs, you need to pass true in the NoProxy parameter slot of the vector indexing suite. But I'm not an expert on the indexing suite stuff, which is why I've been trying to get Joel and Raoul to answer this. Incidentally, Joel, NoProxy is listed twice in the template parameters for indexing_suite, and green was meant to be used in the documentation for class_<...> only to indicate that template parameters could appear in any order. Unless indexing_suite has the same property, you should probably use black. -- Dave Abrahams Boost Consulting www.boost-consulting.com From joel at boost-consulting.com Sat Jan 10 03:52:57 2004 From: joel at boost-consulting.com (Joel de Guzman) Date: Sat, 10 Jan 2004 10:52:57 +0800 Subject: [C++-sig] Re: std::complex? In-Reply-To: <3cao3651.fsf@boost-consulting.com> References: <3cao3651.fsf@boost-consulting.com> Message-ID: <3FFF6909.60403@boost-consulting.com> David Abrahams wrote: > "Neal D. Becker" writes: > > >>I'm still confused. >> >>Let's try 1 thing at a time. Forget about complex for now. >> >>All I want, is to write C++ algorithms that use >>std::vector< std::complex > as arguments. I want to >> >>1. pass such data from python -> c++. >>2. read elements of data in python (e.g. print v[i]) >>3. write elements from python (e.g., v[i] = 10) >> >>So, what I need is probably not surprising. What do I need to do? > > > As far as I can tell from the docs, you need to pass true in the > NoProxy parameter slot of the vector indexing suite. But I'm not an > expert on the indexing suite stuff, which is why I've been trying to > get Joel and Raoul to answer this. Pardon me if I'm late. Yes, NoProxy = true should do work. NoProxy tells vector_indexing_suite to return C[I] by value. This is automatically the behavior for built-in types: typedef mpl::or_< mpl::bool_ , mpl::not_ > > no_proxy; It would of course be possible to add complex to the no_proxy detection as a special case. Thoughts? > Incidentally, Joel, NoProxy is listed twice in the template parameters > for indexing_suite, and green was meant to be used in the > documentation for class_<...> only to indicate that template > parameters could appear in any order. Unless indexing_suite has the > same property, you should probably use black. Ohh. Yes. Fixed in both release and head branches. Thanks Dave. -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net From dave at boost-consulting.com Sat Jan 10 04:12:38 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 22:12:38 -0500 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> Message-ID: <65fk1opl.fsf@boost-consulting.com> Raoul Gough writes: >> Can you give me a complete example where you need this extra >> constructor? Maybe then I'll know how to answer you better. > > Sorry - my mistake! I missed the following in your code (at the end of > the slice class): > > // This declaration, in conjunction with the specialization of > // object_manager_traits<> below, allows C++ functions accepting > // slice arguments to be called from from Python. These > // constructors should never be used in client code. > BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, object) > > I thought I'd seen all of the constructors, but missed this one, and > searching for PySliceObject didn't find anything of course. Thanks for > clarifying this for me. > > [snip] >> So how do you define the point to perform the insertion? If the user >> asks to replace every element that is greater than or equal to the >> fourth and less than the first element, where do you place the new >> sequence? > > Well, that's an interesting question when you put it like that, > independant of implementation issues. In practice, I guess it's just > natural that it should go at the starting index, since you would have > initialized some kind of variable to this before determining that > you're already outside the range of the slice. I know that's how my > code works. You guys'll be sure to let me know if/when you come to some consensus about this stuff, right? -- Dave Abrahams Boost Consulting www.boost-consulting.com From dave at boost-consulting.com Sat Jan 10 04:39:58 2004 From: dave at boost-consulting.com (David Abrahams) Date: Fri, 09 Jan 2004 22:39:58 -0500 Subject: [C++-sig] Re: std::complex? References: <3cao3651.fsf@boost-consulting.com> <3FFF6909.60403@boost-consulting.com> Message-ID: Joel de Guzman writes: > David Abrahams wrote: > >> "Neal D. Becker" writes: >> >>>I'm still confused. >>> >>>Let's try 1 thing at a time. Forget about complex for now. >>> >>> All I want, is to write C++ algorithms that use std::vector< >>> std::complex > as arguments. I want to >>> >>>1. pass such data from python -> c++. >>>2. read elements of data in python (e.g. print v[i]) >>>3. write elements from python (e.g., v[i] = 10) >>> >>>So, what I need is probably not surprising. What do I need to do? >> As far as I can tell from the docs, you need to pass true in the >> NoProxy parameter slot of the vector indexing suite. But I'm not an >> expert on the indexing suite stuff, which is why I've been trying to >> get Joel and Raoul to answer this. > > Pardon me if I'm late. Yes, NoProxy = true should do work. NoProxy > tells vector_indexing_suite to return C[I] by value. This is automatically > the behavior for built-in types: > > typedef mpl::or_< > mpl::bool_ > , mpl::not_ > > > no_proxy; > > It would of course be possible to add complex to the no_proxy detection > as a special case. Thoughts? Probably a good idea. We really ought to have a trait for detecting mapping to builtins so special cases are unneeded, but that's a battle for another day. -- Dave Abrahams Boost Consulting www.boost-consulting.com From adruab at hotmail.com Sat Jan 10 10:39:47 2004 From: adruab at hotmail.com (Adrian Bentley) Date: Sat, 10 Jan 2004 01:39:47 -0800 Subject: [C++-sig] accessing instances of C++ objects in Python Message-ID: Just to be clear on some stuff (working with the specific example of Boost): It IS possible to hand an instance of a C++ class to a python function say and have the python function treat the instance of the class like one that was exposed to it. And assuming that I can do this, it would follow that I can do that and any data changes will be reflected once I exit the call and am back in C++. That is really all I would strictly need, but I also have another question: Is it possible to get boost to treat an arbitrary offset like a variable. Essentially what I want to do is allocate a C++ class and a block of space for arbitrary data, and then have Python reference parts of the space as I want it to. Is there any sort of support for this type of thing at all? Or does it have to be a strict member variable (I could just read through the source, but there's a LOT of it :) Also as a side note: is there a more message board like aspect to this mailing list (I'm new to this form of discussion stuff, and I don't know how much my email address can take :). Thanks in advance, Adruab > Adrian Bentley _________________________________________________________________ Rethink your business approach for the new year with the helpful tips here. http://special.msn.com/bcentral/prep04.armx From dave at boost-consulting.com Sat Jan 10 14:32:59 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sat, 10 Jan 2004 08:32:59 -0500 Subject: [C++-sig] Re: accessing instances of C++ objects in Python References: Message-ID: "Adrian Bentley" writes: > Just to be clear on some stuff (working with the specific example of Boost): > > It IS possible to hand an instance of a C++ class to a python function > say and have the python function treat the instance of the class like > one that was exposed to it. Assuming this was really meant to be a question, and by "it" you mean the python function: what does it mean for a class to be "exposed to" a python function? > And assuming that I can do this, it would follow that I can do that > and any data changes will be reflected once I exit the call and am > back in C++. > > That is really all I would strictly need, but I also have another > question: > > Is it possible to get boost to treat an arbitrary offset like a > variable. Essentially what I want to do is allocate a C++ class and a > block of space for arbitrary data, and then have Python reference > parts of the space as I want it to. Is there any sort of support for > this type of thing at all? Not in Python, directly. Need a more detailed example of what you want to do. Showing some Python and C++ code would help. > Or does it have to be a strict member variable (I could just read > through the source, but there's a LOT of it :) Don't read the source. Check out the class_<...>::add_property member in the reference docs. > Also as a side note: is there a more message board like aspect to this > mailing list (I'm new to this form of discussion stuff, and I don't > know how much my email address can take :). You can access the list through GMane. See http://www.boost.org/more/mailing_lists.htm#cplussig for details. -- Dave Abrahams Boost Consulting www.boost-consulting.com From adruab at hotmail.com Sun Jan 11 01:33:14 2004 From: adruab at hotmail.com (Adrian Bentley) Date: Sat, 10 Jan 2004 16:33:14 -0800 Subject: [C++-sig] Re: accessing instances of C++ objects in Python References: Message-ID: Yeah, sorry, after I posted I realized a lot of what I said was really unclear. > Assuming this was really meant to be a question, and by "it" you mean > the python function: what does it mean for a class to be "exposed to" > a python function? What I essentially want is to send python an instance of a C++ object (parameter to calling a Python function for instance) and for python to be able to modify it. I'm sort of new to using Python as a scripting language, so I'm not sure how the interaction is supposed to occur. I understand how you expose classes for python to instantiate itself, but I haven't figured out how to have things interact (i.e. create a structure in C++, pass it into a python function and when I get back into C++ land, it will have been modified or what not). > Not in Python, directly. Need a more detailed example of what you > want to do. Showing some Python and C++ code would help. Ok, so here's what I want to do. I'm making a componentized system for C++, so at run time I want to group a bunch of components together and then allocate all the data they've asked to see (point pos, matrix rot) in a big block. Then some how allow python to interact with this data object. It would be nice if I could just create properties that treat the space that was allocated for pos and rot as variables in python. The whole idea is to provide a scripting system to attach to this dynamic object system and what not. There are some reasons why I'm not just using Python to instantiate all the objects: 1) the engine I'm writing is supposed to be dynamic, so it'd be nice to allow Python to just hook in, just like any other language (which is one reason why boost/python seemed cool :) 2) the interface for the C++ components to share their data is drastically simplified if I can manually construct the composite objects (and their data blocks as I mentioned before). I certainly hope that I can figure this stuff out. It looks like it could be very promising if I could :). Thanks for the response, it's nice to have people to help out when you've got bizarre questions :). > Don't read the source. Check out the class_<...>::add_property member > in the reference docs. Will do... (more so than before at least :P). Thanks again, Adruab > Adrian Bentley From dave at boost-consulting.com Sun Jan 11 06:52:11 2004 From: dave at boost-consulting.com (David Abrahams) Date: Sun, 11 Jan 2004 00:52:11 -0500 Subject: [C++-sig] Re: accessing instances of C++ objects in Python References: Message-ID: "Adrian Bentley" writes: >> Not in Python, directly. Need a more detailed example of what you >> want to do. Showing some Python and C++ code would help. > > Ok, so here's what I want to do. I'm making a componentized system for C++, > so at run time I want to group a bunch of components together and then > allocate all the data they've asked to see (point pos, matrix rot) in a big > block. Then some how allow python to interact with this data object. It > would be nice if I could just create properties that treat the space that > was allocated for pos and rot as variables in python. > > The whole idea is to provide a scripting system to attach to this dynamic > object system and what not. > > There are some reasons why I'm not just using Python to instantiate all the > objects: > 1) the engine I'm writing is supposed to be dynamic, so it'd be nice to > allow Python to just hook in, just like any other language (which is one > reason why boost/python seemed cool :) > > 2) the interface for the C++ components to share their data is drastically > simplified if I can manually construct the composite objects (and their data > blocks as I mentioned before). > > I certainly hope that I can figure this stuff out. It looks like it could > be very promising if I could :). > > Thanks for the response, it's nice to have people to help out when you've > got bizarre questions :). Once again, showing some C++ code and Python code you'd like to work together would help us to help you. You might look at libs/python/test/embedding.cpp in your Boost distribution also. -- Dave Abrahams Boost Consulting www.boost-consulting.com From adruab at hotmail.com Sun Jan 11 22:14:40 2004 From: adruab at hotmail.com (Adrian Bentley) Date: Sun, 11 Jan 2004 13:14:40 -0800 Subject: [C++-sig] Re: accessing instances of C++ objects in Python References: Message-ID: Ok, thanks :). I'll probably post again when I've got a clearer idea of what I need to ask. Thanks again, Adruab > Adrian Bentley From stefan.seefeld at orthosoft.ca Mon Jan 12 16:58:36 2004 From: stefan.seefeld at orthosoft.ca (Stefan Seefeld) Date: Mon, 12 Jan 2004 10:58:36 -0500 Subject: [C++-sig] calling python method using keywords Message-ID: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> hi there, I'm looking for a way to call a python callable not with explicit arguments, but instead using the tuple / dict form, i.e. args = tuple('a', 'b') kwds = {'c':'C', 'd':'D'} f = foobar(*args, **kwds) I can't find any documentation on this, though. Is there a predefined 'call' function with the appropriate signature ? Thanks, Stefan From dave at boost-consulting.com Mon Jan 12 18:35:13 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jan 2004 12:35:13 -0500 Subject: [C++-sig] Re: calling python method using keywords References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> Message-ID: Stefan Seefeld writes: > hi there, > > I'm looking for a way to call a python > callable not with explicit arguments, but > instead using the tuple / dict form, i.e. > > args = tuple('a', 'b') > kwds = {'c':'C', 'd':'D'} > > f = foobar(*args, **kwds) > > I can't find any documentation on this, though. > Is there a predefined 'call' function with the > appropriate signature ? Do you mean that you want to do this from C++? -- Dave Abrahams Boost Consulting www.boost-consulting.com From seefeld at sympatico.ca Mon Jan 12 18:54:16 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 12 Jan 2004 12:54:16 -0500 Subject: [C++-sig] Re: calling python method using keywords References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> Message-ID: <94843383e8c1cf5c5d96b7d3030562ea4002dd38@Orthosoft.ca> David Abrahams wrote: >>args = tuple('a', 'b') >>kwds = {'c':'C', 'd':'D'} >> >>f = foobar(*args, **kwds) >> >>I can't find any documentation on this, though. >>Is there a predefined 'call' function with the >>appropriate signature ? > > > Do you mean that you want to do this from C++? yes. I already know how to do it in python ;-) Stefan From dave at boost-consulting.com Mon Jan 12 19:13:18 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jan 2004 13:13:18 -0500 Subject: [C++-sig] Re: calling python method using keywords References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> <94843383e8c1cf5c5d96b7d3030562ea4002dd38@Orthosoft.ca> Message-ID: Stefan Seefeld writes: > David Abrahams wrote: > >>>args = tuple('a', 'b') >>>kwds = {'c':'C', 'd':'D'} >>> >>>f = foobar(*args, **kwds) >>> >>>I can't find any documentation on this, though. >>>Is there a predefined 'call' function with the >>>appropriate signature ? >> Do you mean that you want to do this from C++? > > yes. I already know how to do it in python ;-) The other interpretation would've been that you want to wrap a C++ function so it can be used that way from Python. For now, you have to go to the Python 'C' API to do it. I just realized that Python doesn't have any unary operator*, so we could make the foobar(*args, **kwds); syntax work in C++. Not implemented yet, though ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com From rwgk at yahoo.com Mon Jan 12 19:14:49 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Mon, 12 Jan 2004 10:14:49 -0800 (PST) Subject: [C++-sig] gcc 3.4 pre-compiled header support? Message-ID: <20040112181449.75860.qmail@web20208.mail.yahoo.com> David and I put in some effort to ensure that the boost 1.31 release candidate works with gcc 3.4 from the most current gcc CVS. I am also interested in trying out the new pre-compiled header support but I have now clue where to start. Could someone please share her/his expertise? Thanks! Ralf __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus From seefeld at sympatico.ca Mon Jan 12 19:22:25 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 12 Jan 2004 13:22:25 -0500 Subject: [C++-sig] Re: calling python method using keywords References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> <94843383e8c1cf5c5d96b7d3030562ea4002dd38@Orthosoft.ca> Message-ID: <06f95ecc0eb6f51c7712a03e6225b9144002e3d1@Orthosoft.ca> David Abrahams wrote: > > For now, you have to go to the Python 'C' API to do it. I just > realized that Python doesn't have any unary operator*, so we could > make the > > foobar(*args, **kwds); > > syntax work in C++. Not implemented yet, though ;-) what's wrong with a version of 'call' like object call(const tuple &t, const dict &d); ? That doesn't provide the syntactic sugar you seem to be looking for, but it comes close and seems fairly easy to implement. Regards, Stefan From mike at nospam.com Mon Jan 12 21:37:10 2004 From: mike at nospam.com (Mike Rovner) Date: Mon, 12 Jan 2004 12:37:10 -0800 Subject: [C++-sig] Re: gcc 3.4 pre-compiled header support? References: <20040112181449.75860.qmail@web20208.mail.yahoo.com> Message-ID: Ralf W. Grosse-Kunstleve wrote: > have now clue where to start. Could someone please share her/his > expertise? FWIW, I successfully use PCH support in VC7.1 I put as first included header in every compilation item and declared it as PCH file. (Inclusion of file which includes didn't work for me.) The only glitches I encoutered was static variables in noname namespace. (This topic discussed here some time ago.) Otherwise I'm _very_ pleased with PCH, as compilation speed increased roughly tenfold. Unfortunately, I can't test gcc PCH at the time. So please share you experience. Good luck with PCH, Mike From Boomdigidy82 at aol.com Mon Jan 12 21:42:17 2004 From: Boomdigidy82 at aol.com (Boomdigidy82 at aol.com) Date: Mon, 12 Jan 2004 15:42:17 EST Subject: [C++-sig] (no subject) Message-ID: <12a.392608b3.2d3460a9@aol.com> How can i get the layer operation I truly need for personnel reason. How is the pain I will appreicate of you can wrtie me back with any feed back!!!!!!! Thank you for your time! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave at boost-consulting.com Mon Jan 12 23:46:10 2004 From: dave at boost-consulting.com (David Abrahams) Date: Mon, 12 Jan 2004 17:46:10 -0500 Subject: [C++-sig] Re: calling python method using keywords References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> <94843383e8c1cf5c5d96b7d3030562ea4002dd38@Orthosoft.ca> <06f95ecc0eb6f51c7712a03e6225b9144002e3d1@Orthosoft.ca> Message-ID: Stefan Seefeld writes: > David Abrahams wrote: > >> For now, you have to go to the Python 'C' API to do it. I just >> realized that Python doesn't have any unary operator*, so we could >> make the foobar(*args, **kwds); >> syntax work in C++. Not implemented yet, though ;-) > > what's wrong with a version of 'call' like > > object call(const tuple &t, const dict &d); > > ? It doesn't take a callable object? > That doesn't provide the syntactic sugar you seem to be looking for, > but it comes close and seems fairly easy to implement. The syntactic sugar is just about as easy to implement. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Tue Jan 13 01:13:02 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 13 Jan 2004 00:13:02 -0000 Subject: [C++-sig] gcc 3.4 pre-compiled header support? In-Reply-To: <20040112181449.75860.qmail@web20208.mail.yahoo.com> Message-ID: <4003380E.4670.245A6EA7@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 12 Jan 2004 at 10:14, Ralf W. Grosse-Kunstleve wrote: > David and I put in some effort to ensure that the boost 1.31 release > candidate works with gcc 3.4 from the most current gcc CVS. I am also > interested in trying out the new pre-compiled header support but I > have now clue where to start. Could someone please share her/his > expertise? Thanks! GCC v3.4 will only use the precompiled version of the *first* include in a compilee. This creates some interesting issues, mainly being that you must put all your includes into one master include. Unfortunately, this increases the dependencies. Also, precompiled header files on GCC were when I tried it very, very large indeed. It would be definitely slower if you were compiling off a network share :( When GCC creates a PCH of a header file, it calls it the same name and stores it next to the header file with a different extension. It's been many months since I tried this so please double check with the docs, but I think it's merely a case of specifying something like - -fenable-precompiled-headers for them to be automatically generated and used. I would be /very/ interested to see how Boost's recursive header includes play with GCC PCH. Let us know - when I tried it PCH support just didn't work. One question for you (off-topic) - I recently submitted what I feel is an important bug to GCC bugzilla regarding GCC not generating correct code when using new and delete within a namespace which defines new versions of them (it mismatches the calls). However, absolutely zero has happened. This problem is preventing the use of my library on Linux so I'd really like to see it fixed soon, especially as surely it's trivial for those who know the internals. The bugzilla number is #13483 - any suggestions about what to do next? Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQAM4D8EcvDLFGKbPEQIRTgCfQRM5Fs+eAwiF4ozPj6hFRyDc+MsAn0Nx Ur5mcgNjSH1puOamIkWnHLSB =eBKx -----END PGP SIGNATURE----- From seefeld at sympatico.ca Tue Jan 13 05:59:44 2004 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 12 Jan 2004 23:59:44 -0500 Subject: [C++-sig] Re: calling python method using keywords In-Reply-To: References: <9729b5666682867343b94b46ebb5b0144002c219@Orthosoft.ca> <94843383e8c1cf5c5d96b7d3030562ea4002dd38@Orthosoft.ca> <06f95ecc0eb6f51c7712a03e6225b9144002e3d1@Orthosoft.ca> Message-ID: <40037B40.1080504@sympatico.ca> David Abrahams wrote: >>what's wrong with a version of 'call' like >> >>object call(const tuple &t, const dict &d); >> >>? > > > It doesn't take a callable object? oh, definitely, sorry. Make that object call(object o, const tuple &t=tuple(), const dict &d=dict()); with default arguments as in python... I suggested const refs for the arguments because I can see one usage where they are passed as temporaries: object a1 = ...; object a2 = ...; object callable; object retn = call(callable, tuple(a1, a2)) Does this make sense ? (with that a new overloaded 'operator()' could be added to the object_operators interface with the appropriate signature) Regards, Stefan From jbrandmeyer at earthlink.net Tue Jan 13 06:04:08 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 13 Jan 2004 00:04:08 -0500 Subject: [C++-sig] gcc 3.4 pre-compiled header support? In-Reply-To: <20040112181449.75860.qmail@web20208.mail.yahoo.com> References: <20040112181449.75860.qmail@web20208.mail.yahoo.com> Message-ID: <1073970247.27246.61.camel@illuvatar> On Mon, 2004-01-12 at 13:14, Ralf W. Grosse-Kunstleve wrote: > David and I put in some effort to ensure that the boost 1.31 release candidate > works with gcc 3.4 from the most current gcc CVS. I am also interested in > trying out the new pre-compiled header support but I have now clue where to > start. Could someone please share her/his expertise? > Thanks! > Ralf Well, starting with the current documentation at http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html#Precompiled%20Headers and some experimenting, this is what I've found. I don't know anything about an -fprecompiled-headers option that Mr. Douglas mentioned, but what I've been experimenting with is using explicitly generated PCH files. Basically, you compile a header file with exactly the same options that you would use to compile a source file, except that the output is the full name of the original file with .gch appended to it. Files ending in .h and .hh are automatically recognized as a header file to be precompiled, however .hpp files are not. To work around this and other issues I've ran into, I made a dummy file boost_python.h that #includes and does nothing else. Then I precompiled that file and used the -include option to force it into the compile of every .cpp file in Boost.Python. Compiling libboost_python.so takes about 2 min on my system without PCH enabled, and with PCH enabled it gets done in 44 seconds. For my own project, the times were 6:56 without and 4 min with PCH support. But, there are several issues: Symbols in anonymous namespaces are colliding, resulting in linker errors. So, I haven't successfully linked libboost_python.so or my own project module with PCH enabled. If the header file that was precompiled is explicitly #included more than once from the source file being compiled, either directly from that .c/.cpp source file or indirectly via other header files, than for every inclusion other than the first, an error is produced regarding a bad file descriptor. For a practical example, say you have two header files that #include "config.h" for the project, and that you choose to make config.h your PCH (since you can have only one). Now, if a source file includes both of those header files, than for the second inclusion of config.h, you will get the error. This does not extend to any of the header files that config.h would include. If config.h included for example, and another source file included as well as config.h than no error is generated. The .h.gch file must be in the same directory as the header file actually being included. To use the file anyway to build for multiple targets, I created an (empty) dummy file of the same name in the build directory. I'll be submitting bugreports for these to GCC tomorrow afternoon. BTW, compiling life_support.cpp with PCH enabled (but not with it disabled) resulted in this error @ line 35: "none is not a member of boost::python::objects::detail". Explicitly calling ::boost::python::detail::none() fixed this error. I hope this is a decent starting point for you. -Jonathan From jbrandmeyer at earthlink.net Tue Jan 13 06:09:33 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 13 Jan 2004 00:09:33 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: <65fk1opl.fsf@boost-consulting.com> References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> <65fk1opl.fsf@boost-consulting.com> Message-ID: <1073970573.27246.67.camel@illuvatar> On Fri, 2004-01-09 at 22:12, David Abrahams wrote: > Raoul Gough writes: > > >> Can you give me a complete example where you need this extra > >> constructor? Maybe then I'll know how to answer you better. > > > > Sorry - my mistake! I missed the following in your code (at the end of > > the slice class): > > > > // This declaration, in conjunction with the specialization of > > // object_manager_traits<> below, allows C++ functions accepting > > // slice arguments to be called from from Python. These > > // constructors should never be used in client code. > > BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, object) > > > > I thought I'd seen all of the constructors, but missed this one, and > > searching for PySliceObject didn't find anything of course. Thanks for > > clarifying this for me. > > > > [snip] > >> So how do you define the point to perform the insertion? If the user > >> asks to replace every element that is greater than or equal to the > >> fourth and less than the first element, where do you place the new > >> sequence? > > > > Well, that's an interesting question when you put it like that, > > independant of implementation issues. In practice, I guess it's just > > natural that it should go at the starting index, since you would have > > initialized some kind of variable to this before determining that > > you're already outside the range of the slice. I know that's how my > > code works. > > You guys'll be sure to let me know if/when you come to some consensus > about this stuff, right? If Mr. Gough doesn't have anything else, I think we've come to an agreement. For the documentation format, do you use some kind of semiautomatic system? If not, do you mind if I use a WYSIWYG system such as the html editor in Mozilla? To be honest, I don't know much about html code. Thanks, Jonathan Brandmeyer From RaoulGough at yahoo.co.uk Tue Jan 13 11:30:38 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Tue, 13 Jan 2004 10:30:38 +0000 Subject: [C++-sig] [OT] gcc bugzilla [was: gcc 3.4 pre-compiled header support?] References: <20040112181449.75860.qmail@web20208.mail.yahoo.com> <4003380E.4670.245A6EA7@localhost> Message-ID: "Niall Douglas" writes: [snip] > One question for you (off-topic) - I recently submitted what I feel > is an important bug to GCC bugzilla regarding GCC not generating > correct code when using new and delete within a namespace which > defines new versions of them (it mismatches the calls). However, > absolutely zero has happened. This problem is preventing the use of > my library on Linux so I'd really like to see it fixed soon, > especially as surely it's trivial for those who know the internals. > The bugzilla number is #13483 - any suggestions about what to do > next? In my experience, gcc bug reports lie dormant for an unpredictable amount of time. Sometimes you get an analysis almost immediately (especially if the report is simple and in error) and sometimes nobody seems to notice it for six months or so. The best way to get action on it is to fix it yourself, of course. Some other suggestions that might help - reduce the size of the demonstration code to the absolute minimum (ten lines would be good) and test it using the latest compiler sources, since it might already be fixed. -- Raoul Gough. export LESS='-X' From RaoulGough at yahoo.co.uk Tue Jan 13 11:36:54 2004 From: RaoulGough at yahoo.co.uk (Raoul Gough) Date: Tue, 13 Jan 2004 10:36:54 +0000 Subject: [C++-sig] Re: (no subject) References: <12a.392608b3.2d3460a9@aol.com> Message-ID: Boomdigidy82 at aol.com writes: > How can i get the layer operation I truly need for personnel > reason. How is the pain I will appreicate of you can wrtie me back > with any feed back!!!!!!! How can *I* get the nose operation I truly need for personnel department. How much pain will I appreciate when the anaesthetic wears off. WTF are you on about? > Thank you for your time! No problem. -- Raoul Gough. export LESS='-X' From rwgk at yahoo.com Tue Jan 13 13:41:15 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 13 Jan 2004 04:41:15 -0800 (PST) Subject: [C++-sig] [OT] gcc bugzilla [was: gcc 3.4 pre-compiled header support?] In-Reply-To: Message-ID: <20040113124115.66072.qmail@web20204.mail.yahoo.com> --- Raoul Gough wrote: > In my experience, gcc bug reports lie dormant for an unpredictable > amount of time. Sometimes you get an analysis almost immediately > (especially if the report is simple and in error) and sometimes nobody > seems to notice it for six months or so. I filed a few bug reports recently which were attended to within a few hours. The most important one is fixed already. I guess I got lucky, but I am posting this here to encourage people to submit bug reports. Chances are that it will help eventually. > The best way to get action on > it is to fix it yourself, of course. Some other suggestions that might > help - reduce the size of the demonstration code to the absolute > minimum (ten lines would be good) and test it using the latest > compiler sources, since it might already be fixed. Niall wrote that all existing gcc's are broken. In a case like that I'd try very hard to come up with an alternative approach. It is always a big advantage if existing/native compilers can be used. In Niall's case I'd try to write a wrapper around std::vector<> that zeros out the memory in the destructor. Ralf __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus From rwgk at yahoo.com Tue Jan 13 13:57:46 2004 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 13 Jan 2004 04:57:46 -0800 (PST) Subject: [C++-sig] gcc 3.4 pre-compiled header support? In-Reply-To: <1073970247.27246.61.camel@illuvatar> Message-ID: <20040113125746.11413.qmail@web20209.mail.yahoo.com> Hi Janathan, Thanks for your detailed message! --- Jonathan Brandmeyer wrote: > I'll be submitting bugreports for these to GCC tomorrow afternoon. > > BTW, compiling life_support.cpp with PCH enabled (but not with it > disabled) resulted in this error @ line 35: "none is not a member of > boost::python::objects::detail". Explicitly calling > ::boost::python::detail::none() fixed this error. I'll try to check this into the main version and the 1.31 release candidate. David, please intervene if you don't like the idea. > I hope this is a decent starting point for you. It sounds like the PCH support is not yet fully mature. I think I'll wait a little while before trying it on my project. If you get a chance, could you please send the bug report numbers to this list? I'd like to be on the cc list (and maybe some other Boost.Python users, too). Ralf __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus From dave at boost-consulting.com Tue Jan 13 16:27:49 2004 From: dave at boost-consulting.com (David Abrahams) Date: Tue, 13 Jan 2004 10:27:49 -0500 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> <65fk1opl.fsf@boost-consulting.com> <1073970573.27246.67.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > On Fri, 2004-01-09 at 22:12, David Abrahams wrote: >> Raoul Gough writes: >> >> >> Can you give me a complete example where you need this extra >> >> constructor? Maybe then I'll know how to answer you better. >> > >> > Sorry - my mistake! I missed the following in your code (at the end of >> > the slice class): >> > >> > // This declaration, in conjunction with the specialization of >> > // object_manager_traits<> below, allows C++ functions accepting >> > // slice arguments to be called from from Python. These >> > // constructors should never be used in client code. >> > BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(slice, object) >> > >> > I thought I'd seen all of the constructors, but missed this one, and >> > searching for PySliceObject didn't find anything of course. Thanks for >> > clarifying this for me. >> > >> > [snip] >> >> So how do you define the point to perform the insertion? If the user >> >> asks to replace every element that is greater than or equal to the >> >> fourth and less than the first element, where do you place the new >> >> sequence? >> > >> > Well, that's an interesting question when you put it like that, >> > independant of implementation issues. In practice, I guess it's just >> > natural that it should go at the starting index, since you would have >> > initialized some kind of variable to this before determining that >> > you're already outside the range of the slice. I know that's how my >> > code works. >> >> You guys'll be sure to let me know if/when you come to some consensus >> about this stuff, right? > > If Mr. Gough doesn't have anything else, I think we've come to an > agreement. > > For the documentation format, do you use some kind of semiautomatic > system? Sadly, no. Maybe the next time around it'll be RestructuredText. You should feel free to use ReST for your docs, though. libs/python/todo.txt and libs/python/todo.html are done that way. Use a .rst extension for the ReST file, though, if you do that. > If not, do you mind if I use a WYSIWYG system such as the html > editor in Mozilla? To be honest, I don't know much about html code. No, I don't mind, as long as the editor doesn't cruft up the HTML with a lot of cr*pola. The output should have "logical coherence", e.g. no fixed positions and sizes for things that should be relative, etc. -- Dave Abrahams Boost Consulting www.boost-consulting.com From s_sourceforge at nedprod.com Tue Jan 13 23:38:40 2004 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 13 Jan 2004 22:38:40 -0000 Subject: [C++-sig] [OT] gcc bugzilla [was: gcc 3.4 pre-compiled header support?] In-Reply-To: <20040113124115.66072.qmail@web20204.mail.yahoo.com> References: Message-ID: <40047370.19445.292A643F@localhost> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 13 Jan 2004 at 4:41, Ralf W. Grosse-Kunstleve wrote: > --- Raoul Gough wrote: > > In my experience, gcc bug reports lie dormant for an unpredictable > > amount of time. Sometimes you get an analysis almost immediately > > (especially if the report is simple and in error) and sometimes > > nobody seems to notice it for six months or so. > > I filed a few bug reports recently which were attended to within a few > hours. The most important one is fixed already. I guess I got lucky, > but I am posting this here to encourage people to submit bug reports. > Chances are that it will help eventually. Thanks to both of you for the advice. If it's normal then I rest easy. > > The best way to get action on > > it is to fix it yourself, of course. Some other suggestions that > > might help - reduce the size of the demonstration code to the > > absolute minimum (ten lines would be good) and test it using the > > latest compiler sources, since it might already be fixed. > > Niall wrote that all existing gcc's are broken. In a case like that > I'd try very hard to come up with an alternative approach. It is > always a big advantage if existing/native compilers can be used. In > Niall's case I'd try to write a wrapper around std::vector<> that > zeros out the memory in the destructor. Well as I noted MSVC7.1 I think is broken here too - it shouldn't treat operator new differently to malloc(). However I can work around MSVC's misbehaviour whereas GCC's is a tad harder :( I'll wait for v3.4 to get more stable, then try the test again and if it fails again, I'll submit another bug report with the same thing. It's not fantastically urgent for me as it only faults at process exit so I can test my code. Besides, from now on there's no platform specific code so theroretically what works on Windows works on Linux (famous last words!). Cheers, Niall -----BEGIN PGP SIGNATURE----- Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2 iQA/AwUBQARzcMEcvDLFGKbPEQJVtACfdbYvqu4WGR63qZQbr4XdcZu5BIQAnRvc /wP/Qn3jtIqSzcYsq0n9wiuj =IO3I -----END PGP SIGNATURE----- From jbrandmeyer at earthlink.net Wed Jan 14 03:38:34 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 13 Jan 2004 21:38:34 -0500 Subject: [C++-sig] Re: New slice implementation In-Reply-To: References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> <65fk1opl.fsf@boost-consulting.com> <1073970573.27246.67.camel@illuvatar> Message-ID: <1074047914.1215.43.camel@illuvatar> On Tue, 2004-01-13 at 10:27, David Abrahams wrote: > Jonathan Brandmeyer writes: > > For the documentation format, do you use some kind of semiautomatic > > system? > > Sadly, no. Maybe the next time around it'll be RestructuredText. > You should feel free to use ReST for your docs, though. > libs/python/todo.txt and libs/python/todo.html are done that way. > Use a .rst extension for the ReST file, though, if you do that. > > > If not, do you mind if I use a WYSIWYG system such as the html > > editor in Mozilla? To be honest, I don't know much about html code. > > No, I don't mind, as long as the editor doesn't cruft up the HTML with > a lot of cr*pola. The output should have "logical coherence", e.g. no > fixed positions and sizes for things that should be relative, etc. I basically wrote this page by editing the documentation page for the list class. Here is a first shot at it, please review for technical completeness. There are a few formatting tweaks that I still need to make, but I think that it should be OK otherwise. Some of the formatting information is specified relative to the page, so to view it properly you will want to copy the file to boost/libs/python/doc/v2/slice.html Thanks, Jonathan Brandmeyer -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbrandmeyer at earthlink.net Wed Jan 14 04:19:54 2004 From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer) Date: Tue, 13 Jan 2004 22:19:54 -0500 Subject: [C++-sig] gcc 3.4 pre-compiled header support? In-Reply-To: <20040113125746.11413.qmail@web20209.mail.yahoo.com> References: <20040113125746.11413.qmail@web20209.mail.yahoo.com> Message-ID: <1074050393.1500.71.camel@illuvatar> On Tue, 2004-01-13 at 07:57, Ralf W. Grosse-Kunstleve wrote: > It sounds like the PCH support is not yet fully mature. I think I'll wait a > little while before trying it on my project. If you get a chance, could you > please send the bug report numbers to this list? I'd like to be on the cc list > (and maybe some other Boost.Python users, too). > Ralf The issue with symbol collision from within anonymous namespaces is already known as bug #10591. The issue with multiple inclusion of a precompiled header within the same compilation unit is new bug #13675. The issue WRT not recognizing .hpp files as header files is new bug #13676. -Jonathan Brandmeyer From dave at boost-consulting.com Wed Jan 14 06:01:09 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 14 Jan 2004 00:01:09 -0500 Subject: [C++-sig] Re: New slice implementation References: <1073361918.13426.31.camel@illuvatar> <1073518393.1796.15.camel@illuvatar> <1073595081.19758.430.camel@illuvatar> <1073620180.19759.565.camel@illuvatar> <1073665816.19758.775.camel@illuvatar> <65fk1opl.fsf@boost-consulting.com> <1073970573.27246.67.camel@illuvatar> <1074047914.1215.43.camel@illuvatar> Message-ID: Jonathan Brandmeyer writes: > I basically wrote this page by editing the documentation page for the > list class. I can see that:
namespace boost { namespace python
{
class list : public ^^^^ BTW, compare this with the HTML source for list.html and you'll see one of the main reasons people hate HTML to be edited with WYSIWYG tools. Sticking
tags in a
 block is just insane.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Wed Jan 14 06:02:49 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 14 Jan 2004 00:02:49 -0500
Subject: [C++-sig] Re: New slice implementation
References: <1073361918.13426.31.camel@illuvatar> 
	<1073518393.1796.15.camel@illuvatar> 
	<1073595081.19758.430.camel@illuvatar> 
	<1073620180.19759.565.camel@illuvatar> 
	<1073665816.19758.775.camel@illuvatar> 
	<65fk1opl.fsf@boost-consulting.com>
	<1073970573.27246.67.camel@illuvatar>
	
	<1074047914.1215.43.camel@illuvatar>
	
Message-ID: 

David Abrahams  writes:

> BTW, compare this with the HTML source for list.html and you'll see
> one of the main reasons people hate HTML to be edited with WYSIWYG
> tools.  Sticking 
tags in a
 block is just insane.

Not that you're insane; it's your editor ;-)

Note also:

  slice::get_indicies(RandomAccessIterator const& begin, RandomAccessIterator const& end);

Is probably too wide and should be wrapped:

  slice::get_indicies(
      RandomAccessIterator const& begin, RandomAccessIterator const& end);


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From IJRICHARDS at mail.dstl.gov.uk  Wed Jan 14 12:52:23 2004
From: IJRICHARDS at mail.dstl.gov.uk (Richards Ian J)
Date: Wed, 14 Jan 2004 11:52:23 -0000
Subject: [C++-sig] GNU Problem 
Message-ID: <85AC030236CCD41182790002A52CFED90ADA4C86@mail.dstl.gov.uk>

Mike,
 
I saw of the web that you had a problem back in Nov 02 where you were
getting a SIGSEGV due to dyn-string.c (see link below). I know it was a long
time ago, but did you find a solution? I am getting the same error but can't
see what I am doing wrong, so I am thinking that it is deeper issue.
 
Best regards,
 
Ian Richards.
 
http://mail.python.org/pipermail/c++-sig/2002-November/002708.html
 

"This e-mail is intended for the recipient only.  If you are not the
intended recipient you must not use, disclose, distribute, copy, print,
or rely upon this e-mail. If an addressing or transmission error has
misdirected this e-mail, please notify the author by replying to this e-mail."

"Recipients should note that all e-mail traffic on MOD systems is
subject to monitoring and auditing."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From dave at boost-consulting.com  Wed Jan 14 13:40:48 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 14 Jan 2004 07:40:48 -0500
Subject: [C++-sig] Re: gcc 3.4 pre-compiled header support?
References: <1073970247.27246.61.camel@illuvatar>
	<20040113125746.11413.qmail@web20209.mail.yahoo.com>
Message-ID: 

"Ralf W. Grosse-Kunstleve"  writes:

> Hi Janathan,
>
> Thanks for your detailed message!
>
> --- Jonathan Brandmeyer  wrote:
>> I'll be submitting bugreports for these to GCC tomorrow afternoon.
>> 
>> BTW, compiling life_support.cpp with PCH enabled (but not with it
>> disabled) resulted in this error @ line 35: "none is not a member of
>> boost::python::objects::detail".  Explicitly calling
>> ::boost::python::detail::none() fixed this error.
>  
> I'll try to check this into the main version and the 1.31 release candidate.
> David, please intervene if you don't like the idea.
>
>> I hope this is a decent starting point for you.
>
> It sounds like the PCH support is not yet fully mature. I think I'll wait a
> little while before trying it on my project. If you get a chance, could you
> please send the bug report numbers to this list? I'd like to be on the cc list
> (and maybe some other Boost.Python users, too).
>
> Ralf

If it's not yet fully mature and won't really work anyway, maybe we
should wait before uglifying Boost.Python sources to accomodate it.
The change mentioned above is arguably OK, but I'd hate to go any
further down that road.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From mike at nospam.com  Wed Jan 14 23:24:07 2004
From: mike at nospam.com (Mike Rovner)
Date: Wed, 14 Jan 2004 14:24:07 -0800
Subject: [C++-sig] Re: GNU Problem
References: <85AC030236CCD41182790002A52CFED90ADA4C86@mail.dstl.gov.uk>
Message-ID: 

Ian,

Yes and no. AFAICR I dodge the problem by moving to another
platform/compiler;
nowadays I use MSVC7.1 on WinXPpro.

However the code fragment is just:
    class_("Obj").add_property("name", &Obj::Name);
and it's enough.

I'll try to recheck with more recent gcc and bpl on some solaris and or
linux platform
but for some reasons it may take time.

Regards,
Mike


"Richards Ian J"  wrote in message
news:85AC030236CCD41182790002A52CFED90ADA4C86 at mail.dstl.gov.uk...
Mike,

I saw of the web that you had a problem back in Nov 02 where you were
getting a SIGSEGV due to dyn-string.c (see link below). I know it was a long
time ago, but did you find a solution? I am getting the same error but can't
see what I am doing wrong, so I am thinking that it is deeper issue.

Best regards,

Ian Richards.

http://mail.python.org/pipermail/c++-sig/2002-November/002708.html
"The Information contained in this E-Mail and any subsequent correspondence"
"is private and is intended solely for the intended recipient(s)."
"For those other than the recipient any disclosure, copying, distribution, "
"or any action taken or omitted to be taken in reliance on such information
is"
"prohibited and may be unlawful."



_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig






From topology at eircom.net  Fri Jan 16 00:26:00 2004
From: topology at eircom.net (Brian Peters)
Date: Thu, 15 Jan 2004 23:26:00 +0000
Subject: [C++-sig] wrapping interfaces and supplied implementations
Message-ID: <40072187.CBC15DBF@eircom.net>

Hello All,

I'd like first to thank the Boost.Python team and commend them on their
creation. Dave Abrahams et.al. have implemented code the likes of which
I could not even have conceived, let alone writen. Boost MPL is not
something I could ever have thought up. My hope is simply that someone
some day finds my work as useful and impressive as I find theirs.

I am trying to wrap a library that implements a generic programming
approach to computational geometry and topology. To achieve this it
defines a number of interfaces it requires to do its job. For developers
who do not wish to code the details of these interfaces it also supplies
concrete implementations.


Having observed Dave Abrahams' penchant for a working test case I have
developed a sandbox representing a portion of the library. It has three
classes that are abstract base  classes: IFacade, IManager, and
IProduct. All their pure virtual methods are defined using raw pointers
to abstract base classes.

The idea is that an application asks the facade for a manager [
IManager* IFacade::manager() ] and then uses the manager to create
products [ IProduct* IManager::create(inti i) ]. The products have state
that may be changed by the client or other operations of the facade. The
manager can also store and retrieve products.

A simple user can use the concrete Manager and Product classes supplied
through these interfaces, but a more advanced user could derive their
own product and manager from the abc's and pass that into the facade [
void IFacade::setManager(IManager* manager) ]. The old addage applies:
"The simple should be easy, but the complex should be possible." i.e use
the supplied system if you want, but you can always over ride it with
something more complex.

So now I want to be able to do the same thing in Python. I want to wrap
everything so that a simple user can:
* see the abstract base classes in python;
   i.e. the interfaces, their doc strings, etc.
* use the supplied implementation of manager and product
* derive their own products and manager if they want/need to in python

Well, I got it all working! Not only working, but doing cool python
stuff too. Being new to python I have found it interesting that
arbitrary attributes and methods can be added to any object regardless
of its class.

I think of a wrapped Product passed out to python from the supplied
Manager class as a python envelope containing the C++ Product. I can
scribble on that envelope. Spill coffee on it. Crumple it up a bit. I
can store it in the manager and throw it away. When I later retrieve
from the manager, not only is it the same C++ Product (i.e same
address), but it is the same PyObject (i.e. same address, or "id" as
they call it in the interpreter), AND it even has the same note
scribbled on it and the coffee stain! Its like decorating C++ classes
dynamically at run time.

I thought the article about C++/Python integration was cool when I read
it a few months ago, but now I really see it. The line between Python
and C++ is very fluid. (
http://www.cuj.com/documents/s=8188/cuj0307abrahams )

The code is attached below. For reference I am using the following
(admittedly somewhat dated) environment:
*  Python 2.2.2
*  Boost 1.30.0
*  Windows NT4 with MSVC6
*  RH linux 2.4.2-2 with g++ 1.96

I am offering this example to anyone that finds it useful. It is more
complex than the examples I found in the documentation and code, yet
still simple enough to examine in detail.

I am hoping that those in the know will tell me if I have done anything
terribly wrong. I will gladly explain why I have done things the way I
have and/or share the verbose version of this sandbox that contains a
lot more testing functions and cout's. This message is already too long
to do so here.

thanks,
bfp

======================
> Brian Peters
>  topologyeircomnet

===============================================================================

============ abcdf_ext.cpp
====================================================

#include 
#include 
#include 

using namespace boost::python;

// --- component code -----------------------------------------------
// published interfaces
struct IProduct
{
  virtual ~IProduct() {}
  virtual int value() const = 0;
  virtual void set(int i) = 0;
  virtual int other(IProduct* product) const = 0;
};

struct IManager
{
  virtual ~IManager() {}
  virtual IProduct* create(int i) = 0;
  virtual IProduct* modify(IProduct* product) = 0;
  virtual int store(IProduct* product) = 0;
  virtual IProduct* retrieve(int index) = 0;
};

struct IFacade
{
  static IFacade* instance();
  virtual ~IFacade() {}
  virtual IManager* manager() = 0;
  virtual void setManager(IManager* manager) = 0;
  virtual void update(int i) = 0;
  virtual std::string notice() const = 0;
};

// supplied implementation of interfaces.
// only exposed through pointers to the above interfaces.
#define MANAGER_CAPACITY 10
struct Product : IProduct
{
  Product(int i): _i(i) {}
  virtual ~Product() {}
  virtual int value() const
    {
    return _i;
    }
  virtual void set(int i)
    {
    _i = i;
    }
  virtual int other(IProduct* product) const
    {
    int v = -10; // TODO Should I throw if NULL == product???
    if (product)
      v = product->value();
    return _i*1000 + v;
    }
  int _i;
};

struct Manager : IManager
{
  Manager(): mCount(0)
    {
    memset(mProducts, 0, sizeof(mProducts));
    }
  virtual ~Manager() {}
  virtual IProduct* create(int i)
    {
    return new Product(i);
    }
  virtual IProduct* modify(IProduct* product)
    {
    product->set(2 * product->value());
    return product;
    }
  virtual int store(IProduct* product)
    {
    int index = -1;
    if (MANAGER_CAPACITY > mCount)
      {
      index = mCount;
      mProducts[mCount++] = product;
      }
    return index;
    }
  virtual IProduct* retrieve(int index)
    {
    IProduct* product = NULL;
    if (MANAGER_CAPACITY > index)
      product = mProducts[index];
    return product;
    }
  int mCount;
  IProduct* mProducts[MANAGER_CAPACITY];
};

struct Facade : IFacade
{
  Facade(): mManager(new Manager) {}
  virtual ~Facade() {}
  virtual IManager* manager()
    {
    return mManager;
    }
  virtual void setManager(IManager* manager)
    {
    // TODO Deleting the old manager will cause trouble if it has
    // already been sent out to python. How do I want to handle this?
    //if (mManager)
    //  delete mManager;
    mManager = manager;
    }
  virtual void update(int delta)
    {
    // TODO get a product iterator from IManager here.
    IProduct* product;
    for (int i=0; i < MANAGER_CAPACITY; i++)
      {
      if (NULL != (product = mManager->retrieve(i)))
        product->set(product->value() + delta);
      }
    }
  virtual std::string notice() const
    {
    return "IFacade::notice() message: hello world!";
    }
  IManager* mManager;
};

// the singleton
IFacade* theFacade = NULL;
IFacade* IFacade::instance()
  {
  if (NULL == theFacade)
    theFacade = new Facade();
  return theFacade;
  }


// --- B.P.L. wrapper code -------------------------------------------
// rudimentary exception class
struct error
{
  error(std::string message): _msg(message) {}
  std::string const _msg;
};

// ProductProxy provides abc methods to pass IProduct* to python.
struct ProductProxy : IProduct
{
  ProductProxy(IProduct* product) : mProduct(product) {}
  virtual ~ProductProxy() {}
  virtual int value() const
    {
    if (!mProduct)
      throw error("Bad proxy");
    return mProduct->value();
    }
  virtual void set(int i)
    {
    if (!mProduct)
      throw error("Bad proxy");
    mProduct->set(i);
    }
  virtual int other(IProduct* product) const
    {
    if (!mProduct)
      throw error("Bad proxy");
    return mProduct->other(product);
    }
  // this virtual function is overridden in ProductBase
  virtual int otherWrap(object& product) const
    {
    if (!mProduct)
      throw error("Bad proxy");
    ProductProxy* proxy =
arg_from_python(product.ptr())(product.ptr());
    return mProduct->other(proxy);
    }
  IProduct* mProduct;
};

// ProductBase is the heldtype for ProductProxy to let python derive
from IProduct.
struct ProductBase : ProductProxy
{
  ProductBase(PyObject* pyobject): ProductProxy(NULL), mSelf(pyobject)
{}
  virtual ~ProductBase() {}
  virtual int value() const
    {
    return call_method(mSelf, "value");
    }
  int default_value() const
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'value'";
    throw error(msg.str());
    }
  virtual void set(int i)
    {
    call_method(mSelf, "set", i);
    }
  void default_set(int i)
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'set'";
    throw error(msg.str());
    }
  virtual int other(IProduct* product) const
    {
    ProductProxy proxy(product);
    return call_method(mSelf, "other", ptr(&proxy));
    }
  // this virtual function is overridden from ProductProxy
  virtual int otherWrap(object& product) const
    {
    return call_method(mSelf, "other", product);
    }
  int default_other(object& product) const
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'other'";
    throw error(msg.str());
    }
  PyObject* mSelf;
};

// ManagerProxy provides abc methods to pass IManager* to python.
struct ManagerProxy : IManager
{
  ManagerProxy(IManager* manager): mManager(manager), mCount(0) {}
  ManagerProxy(ManagerProxy& manager)
  : mManager(manager.mManager), mCount(manager.mCount)
    {
    for (int i=--mCount; 0 <= i; --i)
      mProducts[i] = manager.mProducts[i];
    }
  virtual ~ManagerProxy() {}
  virtual IProduct* create(int i)
    {
    if (!mManager)
      throw error("Bad proxy");
    return mManager->create(i);
    }
  // this virtual function is overridden in ManagerBase
  virtual object createWrap(int i)
    {
    if (NULL == mManager)
      throw error("Bad proxy");
    return object(ptr(new ProductProxy(mManager->create(i))));
    }
  virtual IProduct* modify(IProduct* product)
    {
    if (NULL == mManager)
      throw error("Bad proxy");
    return mManager->modify(product);
    }
  // this virtual function is overridden in ManagerBase
  virtual object modifyWrap(object& product)
    {
    if (NULL == mManager)
      throw error("Bad proxy");
    ProductProxy* proxy =
arg_from_python(product.ptr())(product.ptr());
    mManager->modify(proxy);
    return product;

    // IManager::modify returns its argument, but if another function
might not, do this:
    //IProduct* value = mManager->anotherFunction(proxy);
    //return value == proxy ? product : object(ptr(new
ProductProxy(value)));
    }
  virtual int store(IProduct* product)
    {
    return mManager->store(product);
    }
  virtual int storeWrap(object& product)
    {
    ProductProxy* proxy =
arg_from_python(product.ptr())(product.ptr());

    // make sure side effects will happen
    mManager->store(proxy->mProduct);

    int index = -1;
    if (MANAGER_CAPACITY > mCount)
      {
      index = mCount;
      mProducts[mCount++] = product;
      }
    return index;
    }
  virtual IProduct* retrieve(int index)
    {
    return mManager->retrieve(index);
    }
  virtual object retrieveWrap(int index)
    {
    // make sure side effects will happen
    mManager->retrieve(index);

    if (MANAGER_CAPACITY > index)
      return mProducts[index];
    else
      return object(); // python's None
    }
  IManager* mManager;

  // just mirror the Manager approach to storage for sandbox
  int mCount;
  object mProducts[MANAGER_CAPACITY];
};

// ManagerBase is the heldtype for ManagerProxy to let python derive
from IManager.
struct ManagerBase : ManagerProxy
{
  ManagerBase(PyObject* pyobject): ManagerProxy(NULL), mSelf(pyobject)
{}
  virtual ~ManagerBase() {}
  virtual IProduct* create(int i)
    {
    object product = call_method(mSelf, "create", i);
    return arg_from_python(product.ptr())(product.ptr());

    }
  // this virtual function is overridden from ManagerProxy
  virtual object createWrap(int i)
    {
    return call_method(mSelf, "create", i);
    }
  object default_create(int i)
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'create'";
    throw error(msg.str());
    }
  virtual IProduct* modify(IProduct* product)
    {
    ProductProxy proxy(product);
    return call_method(mSelf, "modify", ptr(&proxy));
    }
  // this virtual function is overridden from ManagerProxy
  virtual object modifyWrap(object& product)
    {
    return call_method(mSelf, "modify", product);
    }
  object default_modify(object& product)
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'modify'";
    throw error(msg.str());
    }
  virtual int store(IProduct* product)
    {
    ProductProxy proxy(product);
    return call_method(mSelf, "store", ptr(&proxy));
    }
  virtual int storeWrap(object& product)
    {
    return call_method(mSelf, "store", product);
    }
  int default_store(object& product)
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'store'";
    throw error(msg.str());
    }
  virtual IProduct* retrieve(int index)
    {
    object product = call_method(mSelf, "retrieve", index);
    return arg_from_python(product.ptr())(product.ptr());

    }
  virtual object retrieveWrap(int index)
    {
    return call_method(mSelf, "retrieve", index);
    }
  object default_retrieve(int index)
    {
    std::ostringstream msg;
    msg << mSelf->ob_type->tp_name << " missing implementation of
function 'retrieve'";
    throw error(msg.str());
    }
  PyObject* mSelf;
};

// after IFacade, but no need to inherit
struct FacadeProxy
{
  ~FacadeProxy() {}
  static FacadeProxy* instance()
    {
    return new FacadeProxy();
    }
  object managerWrap()
    {
    if (mManager == object())
      mManager = object(ptr(new
ManagerProxy(IFacade::instance()->manager())));
    return mManager;
    }
  void setManagerWrap(object manager)
    {
    ManagerProxy* proxy =
arg_from_python(manager.ptr())(manager.ptr());
    if (NULL != proxy)
      {
      mManager = manager;
      IFacade::instance()->setManager(proxy);
      }
    else
      {
      std::ostringstream msg;
      msg << "Object type: " << manager.ptr()->ob_type->tp_name << " not
derived from IManager";
      throw error(msg.str());
      }
    }
  void update(int delta)
    {
    IFacade::instance()->update(delta);
    }
  std::string notice() const
    {
    return IFacade::instance()->notice();
    }
  object mManager;
};

// exception handling
void translate(error const& e)
  {
  PyErr_SetString(PyExc_AttributeError, e._msg.c_str());
  }

// utility functions
PyObject* _last;
void dumpLast()
  {
  std::cout << "dumpLast" << std::endl;
  std::cout << "    last: " << (void*)_last << " [" <<
(typeid(*_last)).name() << "]" << std::endl;
  std::cout << "    last->ob_refcnt: " << _last->ob_refcnt << std::endl;

  std::cout << "    last->ob_type->tp_name: " << _last->ob_type->tp_name
<< std::endl;
  }
void dumpPyObject(PyObject* pyobject)
  {
  _last = pyobject; // steal for dumpLast
  std::cout << "dumpPyObject" << std::endl;
  std::cout << "    pyobject: " << (void*)pyobject << " [" <<
(typeid(*pyobject)).name() << "]" << std::endl;
  std::cout << "    pyobject->ob_refcnt: " << pyobject->ob_refcnt <<
std::endl;
  std::cout << "    pyobject->ob_type->tp_name: " <<
pyobject->ob_type->tp_name << std::endl;
  }
void dumpProduct(ProductProxy* proxy)
  {
  std::cout << "dumpProduct" << std::endl;
  std::cout << "    proxy: " << (void*)proxy << " [" <<
(typeid(*proxy)).name() << "]" << std::endl;
  ProductBase* base = dynamic_cast(proxy);
  if (base)
    {
    std::cout << "    proxy->mSelf: " << (void*)base->mSelf << " [" <<
(typeid(*base->mSelf)).name() << "]" << std::endl;
    std::cout << "    proxy->mSelf->ob_refcnt: " <<
base->mSelf->ob_refcnt << std::endl;
    std::cout << "    proxy->mSelf->ob_type->tp_name: " <<
base->mSelf->ob_type->tp_name << std::endl;
    }
  else
    {
    std::cout << "    proxy->mProduct: " << (void*)proxy->mProduct << "
[" << (typeid(*proxy->mProduct)).name() << "]" << std::endl;
    }
  }

int useValue_PyObject_ptr(PyObject* product)
  {
  return call_method(product, "value");
  }
int useValue_object_ref(object& product)
  {
  return call_method(product.ptr(), "value");
  }
int useValue_ProductProxy_ptr(ProductProxy* product)
  {
  return NULL != product ? product->value() : -1;
  }

ProductProxy* passBack_ProductProxy_ptr(ProductProxy* product)
  {
  return product;
  }
object passBack_object(object& product)
  {
  ProductProxy* proxy =
arg_from_python(product.ptr())(product.ptr());
  if (NULL == proxy)
    return object();
  else
    return product;
  }

BOOST_PYTHON_MODULE(abcdf_ext)
{
  register_exception_translator(&translate);

  class_("IProduct")
      .def("value", &ProductProxy::value, &ProductBase::default_value,
"Returns an int value")
      .def("set", &ProductProxy::set, &ProductBase::default_set, "Sets
an int value")
      .def("other", &ProductProxy::otherWrap,
&ProductBase::default_other, "Returns an int value using another
IProduct")
      ;

  class_("IManager")
      .def("create", &ManagerProxy::createWrap,
&ManagerBase::default_create)
      .def("modify", &ManagerProxy::modifyWrap,
&ManagerBase::default_modify)
      .def("store", &ManagerProxy::storeWrap,
&ManagerBase::default_store)
      .def("retrieve", &ManagerProxy::retrieveWrap,
&ManagerBase::default_retrieve)
      ;

  class_("IFacade", no_init)
      .def("instance", &FacadeProxy::instance,
           return_value_policy())
 // How do I do a singleton?
      .staticmethod("instance")
      .def("manager", &FacadeProxy::managerWrap)
      .def("setManager", &FacadeProxy::setManagerWrap)
 // ,with_custodian_and_ward<1, 2>())
 // I don't think I need this as returning an object keeps track of
reference counts.
      .def("update", &FacadeProxy::update)
      .def("notice", &FacadeProxy::notice)
      ;

  def("dumpLast", &dumpLast);
  def("dumpPyObject", &dumpPyObject);
  def("dumpProduct", &dumpProduct);

  def("useValue_PyObject_ptr", &useValue_PyObject_ptr);
  def("useValue_object_ref", &useValue_object_ref);
  def("useValue_ProductProxy_ptr", &useValue_ProductProxy_ptr);

  def("ProductProxy_ptr_manage_new_object", &passBack_ProductProxy_ptr,
      return_value_policy());
  def("ProductProxy_ptr_reference_existing_object",
&passBack_ProductProxy_ptr,
      return_value_policy());
  def("Product_as_object", &passBack_object);
      // no return_value_policy needed

}

#include "../../../boost_1_30_0/libs/python/test/module_tail.cpp"

============ abcdf_ext.cpp
====================================================

# test abcdf_ext: Abstract Base Class with DeFaults
from abcdf_ext import *

class Derived(IProduct):
  def __init__(self, i):
    IProduct.__init__(self)
    self.i = i
  def value(self):
    return self.i
  def set(self, i):
    self.i = i
  def other(self, product):
    return self.i*1000 + product.value()

def callValue(product):
  return product.value()

def callOther(product, other):
  return product.other(other)

def callSet(product, i):
  product.set(i)

class DManager(IManager):
  def __init__(self):
    IManager.__init__(self)
    self._products = []
  def create(self, i):
    return Derived(i)
  def modify(self, product):
    product.set(product.value()*3)
    return product
  def store(self, product):
    index = len(self._products)
    self._products.append(product)
    return index
  def retrieve(self, index):
    try:
      return self._products[index]
    except:
      return None

E=IFacade.instance()
M=E.manager()
D=DManager()

m = M.create(2)
n = M.create(3)

m._m = "m"
n._n = "n"

i1 = M.store(m)
i2 = M.store(n)
i3 = M.store(M.create(4))

M.retrieve(i1)._m

d = D.create(4)

E.setManager(D)
Dr=E.manager()
e=Dr.create(5)
f=Dr.create(6)

e._e = "e"
f._f = "f"

Dr.store(e)
Dr.store(f)

===============================================================================

===============================================================================






From jzlouis at yahoo.com  Fri Jan 16 14:41:48 2004
From: jzlouis at yahoo.com (Jenna Louis)
Date: Fri, 16 Jan 2004 05:41:48 -0800 (PST)
Subject: [C++-sig] Boost.Python Feature Request
Message-ID: <20040116134148.10753.qmail@web21325.mail.yahoo.com>

Are there any patches or plans to add the following features to Boost.Python/Pyste?
 
1. A major usability problem of  Boost generated proxies is that IDEs are not able to show any details about the expected parameters.  Since Boost already knows everything about the function then it makes sense to at least make some information known about it via a docstring and then these tools can at least show that.
 
2. Another feature would append a docstring with the descriptive text to the specified Class, Function, or Method.
 
3. I often generate modules that require  a very specific order of initialization for the proxies it contains. I often have to rearrange the _main.cpp's BOOST_PYTHON_MODULE code as depicted below to get my module to work.
 
This:

BOOST_PYTHON_MODULE(Sim)

{

Export_SzCoordPos();

Export_SzCoordAng();

Export_SzCoord();

Export_SzMath();

Export_SzPolyUtils()

}

To This:
 
  
BOOST_PYTHON_MODULE(Sim)

{

Export_SzCoord();

Export_SzMath();

Export_SzPolyUtils()

Export_SzCoordPos();

Export_SzCoordAng();

}


It would be nice if this list would be generated in the order in which the pyste files are specified on the command line.

 

4. I would like a way to add pickling code to my class from pyste. I realize its not practical to generate this code automatically but I would at least like to be able to inline this in my pyste file. I can already insert code into the proxy with the declaration_code() feature to handle the pickle struct but I also need to be able to add a pickle method i.e.(".def_pickle(world_pickle_suite())"  to the class definition I specify.  

 

Thanks,

Jenna



---------------------------------
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From s_sourceforge at nedprod.com  Fri Jan 16 19:31:59 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Fri, 16 Jan 2004 18:31:59 -0000
Subject: [C++-sig] Boost.Python Feature Request
In-Reply-To: <20040116134148.10753.qmail@web21325.mail.yahoo.com>
Message-ID: <40082E1F.19180.37BB9F2B@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 16 Jan 2004 at 5:41, Jenna Louis wrote:

> 3. I often generate modules that require  a very specific order of
> initialization for the proxies it contains. I often have to rearrange
> the _main.cpp's BOOST_PYTHON_MODULE code as depicted below to get my
> module to work.

Look into pyste's Import() function which gets pyste to order its 
output.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQAguH8EcvDLFGKbPEQLaVACg+k7j+TwLqYFxVUJXRgUIAfypKdUAoI53
vr+pl4/wS+EntgBuoPJaCO15
=7Obn
-----END PGP SIGNATURE-----



From nicodemus at esss.com.br  Fri Jan 16 20:42:02 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Fri, 16 Jan 2004 16:42:02 -0300
Subject: [C++-sig] Boost.Python Feature Request
In-Reply-To: <20040116134148.10753.qmail@web21325.mail.yahoo.com>
References: <20040116134148.10753.qmail@web21325.mail.yahoo.com>
Message-ID: <40083E8A.6070909@esss.com.br>

Hi Jenna,

Jenna Louis wrote:

 > Are there any patches or plans to add the following features to 
Boost.Python/Pyste?
 > 3. I often generate modules that require  a very specific order of 
initialization for the proxies it contains. I often have to rearrange 
the _main.cpp's BOOST_PYTHON_MODULE code as depicted below to get my 
module to work.
 > 
 > This:
 >
 > BOOST_PYTHON_MODULE(Sim)
 >
 > {
 >
 > Export_SzCoordPos();
 >
 > Export_SzCoordAng();
 >
 > Export_SzCoord();
 >
 > Export_SzMath();
 >
 > Export_SzPolyUtils()
 >
 > }
 > To This:
 > 
 > 
 >
 > BOOST_PYTHON_MODULE(Sim)
 >
 > {
 >
 > Export_SzCoord();
 >
 > Export_SzMath();
 >
 > Export_SzPolyUtils()
 >
 > Export_SzCoordPos();
 >
 > Export_SzCoordAng();
 >
 > }
 >
 > It would be nice if this list would be generated in the order in 
which the pyste files are specified on the command line.

The order of the function takes in account inheritance (base classes 
must be instantiated first), but modules with no relacionship are 
arbitrary... I will think about it.


 > 4. I would like a way to add pickling code to my class from pyste. I 
realize its not practical to generate this code automatically but I 
would at least like to be able to inline this in my pyste file. I can 
already insert code into the proxy with the declaration_code() feature 
to handle the pickle struct but I also need to be able to add a pickle 
method i.e.(".def_pickle(world_pickle_suite())"  to the class definition 
I specify.
 >

I guess we need a class_code(class, code) function for that.

Unfortunately, I have very little time right now to work on Pyste, and I 
have a set of patches by Niall Douglas and Mike Owen (sorry Mike, 
haven't had time yet! 8( ) that have priority to be applied, so it might 
take awhile to see this changes... but I will announce here whenever 
it's ready.

Thanks for the feedback!
Nicodemus.
 




From dholth at fastmail.fm  Sat Jan 17 08:01:44 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Sat, 17 Jan 2004 02:01:44 -0500
Subject: [C++-sig] module unloading callback?
Message-ID: <1074322904.21456.4.camel@bluefish>

I've been wrapping a library thats documentation says you should init()
and free() some internal data structures before and after you use it.  I
can put code in BOOST_MODULE_INIT to call init, but where would I put
the tear-down code?  Thanks.




From pete at pcbartlett.com  Sat Jan 17 19:06:34 2004
From: pete at pcbartlett.com (Pete Bartlett)
Date: Sat, 17 Jan 2004 18:06:34 -0000
Subject: [C++-sig] Operator== for reflected enums can return True when it
	shouldn't?
Message-ID: 

(Apologies if this issue has been raised before - I must have put the
wrong search terms into Google)

On my setup (Python 2.3, boost-cvs from early December, MSVC 7.1),
Python returns True when comparing two reflected enums of different type
that have the same internal integer representation. Though I am sure it
is bad Python style to compare different types, would it right and
possible to return False in this case? 

Pete

Minimal example:

//Cpp:

#include 

enum e_A{e_a}; //e_a has "internal value" 0
enum e_B{e_b}; //e_b has "internal value" 0

BOOST_PYTHON_MODULE( enum_test )
{
	using namespace boost::python;
	enum_("e_A").value("e_a",e_a);
	enum_("e_B").value("e_b",e_b);
}

//Python

>>>import enum_test
>>>print (enum_test.e_A.e_a == enum_test.e_B.e_b )
True




From dholth at fastmail.fm  Sun Jan 18 02:08:07 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Sat, 17 Jan 2004 20:08:07 -0500
Subject: [C++-sig] boolean patch for builtin_converters.hpp
Message-ID: <1074388086.6078.7.camel@bluefish>

Here's something for fans of Python's relatively new True and False
objects.  Now my module's bool ::f() returns True or False inside
Python.

- Daniel Holth

RCS file: /boost/boost/boost/python/converter/builtin_converters.hpp,v

diff -r1.22 builtin_converters.hpp
95c95
< BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
---
> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))




From dave at boost-consulting.com  Sun Jan 18 16:39:03 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Sun, 18 Jan 2004 10:39:03 -0500
Subject: [C++-sig] Re: boolean patch for builtin_converters.hpp
References: <1074388086.6078.7.camel@bluefish>
Message-ID: 

Daniel Holth  writes:

> Here's something for fans of Python's relatively new True and False
> objects.  Now my module's bool ::f() returns True or False inside
> Python.
>
> - Daniel Holth
>
> RCS file: /boost/boost/boost/python/converter/builtin_converters.hpp,v
>
> diff -r1.22 builtin_converters.hpp
> 95c95
> < BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
> ---
>> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))

This patch will break 2.2 compatibility and possibly some of the
Boost.Python regression tests if we take it as-is.

Please try again, though; I'd like to accept a patch for this!

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dholth at fastmail.fm  Sun Jan 18 20:28:08 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Sun, 18 Jan 2004 14:28:08 -0500
Subject: [C++-sig] Re: boolean patch for builtin_converters.hpp
In-Reply-To: 
References: <1074388086.6078.7.camel@bluefish>
	
Message-ID: <1074453968.10816.34.camel@bluefish>

On Sun, 2004-01-18 at 10:39, David Abrahams wrote:
> Daniel Holth  writes:
> 
> > Here's something for fans of Python's relatively new True and False
> > objects.

> > diff -r1.22 builtin_converters.hpp
> > 95c95
> > < BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
> > ---
> >> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))
> 
> This patch will break 2.2 compatibility and possibly some of the
> Boost.Python regression tests if we take it as-is.
> 
> Please try again, though; I'd like to accept a patch for this!

Not too hard, this version will use the new behavior only in Pythons 2.3
and above:

// Bool is not signed.
#if PY_VERSION_HEX >= 0x02030000
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))
#else
BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
#endif

- dwh




From aknuds-1 at broadpark.no  Mon Jan 19 00:26:36 2004
From: aknuds-1 at broadpark.no (Arve Knudsen)
Date: Mon, 19 Jan 2004 00:26:36 +0100
Subject: [C++-sig] Deriving from a PyTypeObject?
Message-ID: 

Hi

Is it possible at all to derive a Boost.Python class from a PyTypeObject 
and not just other registered C++ classes? I wouldn't normally want to do 
it this way, but I have to interface with C code which uses the Python API 
directly. Sorry if this is answered somewhere else, but I couldn't find 
anything related.

Thanks

Arve Knudsen



From jbrandmeyer at earthlink.net  Mon Jan 19 01:50:09 2004
From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer)
Date: Sun, 18 Jan 2004 19:50:09 -0500
Subject: [C++-sig] Re: New slice implementation
In-Reply-To: 
References: <1073361918.13426.31.camel@illuvatar>
	 <1073518393.1796.15.camel@illuvatar>
	 <1073595081.19758.430.camel@illuvatar>
	 <1073620180.19759.565.camel@illuvatar>
	 <1073665816.19758.775.camel@illuvatar>
	 <65fk1opl.fsf@boost-consulting.com>
	<1073970573.27246.67.camel@illuvatar>
	
	<1074047914.1215.43.camel@illuvatar>
	
	
Message-ID: <1074473408.8246.3.camel@illuvatar>

On Wed, 2004-01-14 at 00:02, David Abrahams wrote:
> David Abrahams  writes:
> 
> > BTW, compare this with the HTML source for list.html and you'll see
> > one of the main reasons people hate HTML to be edited with WYSIWYG
> > tools.  Sticking 
tags in a
 block is just insane.
> 
> Not that you're insane; it's your editor ;-)

I understand.  Its fixed, I think.

> Note also:
> 
>   slice::get_indicies(RandomAccessIterator const& begin, RandomAccessIterator const& end);
> 
> Is probably too wide and should be wrapped:
> 
>   slice::get_indicies(
>       RandomAccessIterator const& begin, RandomAccessIterator const& end);

Done.

Attached are diffs for boost/libs/python/doc/v2/reference.html,
object.html, and the new file slice.html.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: object.html.diff
Type: text/x-patch
Size: 535 bytes
Desc: not available
URL: 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reference.html.diff
Type: text/x-patch
Size: 592 bytes
Desc: not available
URL: 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From aashish at vrac.iastate.edu  Mon Jan 19 01:49:26 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Sun, 18 Jan 2004 18:49:26 -0600
Subject: [C++-sig] re: implicitly_convertible
Message-ID: <200401190050.i0J0oP3N2657341@vracs001.vrac.iastate.edu>

Hi, 

 

I have this porgram where I need to convert a python float in to C++ class
object and for that I am using implicitly_convertible

 

In the porgram below (a very simple one) the constructor takd two arguments
and when I compile with that I got this error ..

 

c:\users\aashish\boost-1.30.2\boost\python\converter\implicit.hpp(34): error
C2664: 'PlotVariableTable::PlotVariableTable(const PlotVariableTable &)' :
cannot convert parameter 1 from 'const double' to 'const PlotVariableTable
&'

 

Now when I compiled and tested with the constructor taking only a single
value (and hence changed some lines accordingly) program just worked fine. 

 

Please let know is someone can help me as soon as possible. 

 

Thanks, 

Aashish 

 

 

  

#include 

#include 

#include 

#include 

#include 

#include 

#include 

 

#include 

#include

//#include 

 

 

using namespace boost::python;

namespace bp = boost::python;

 

 

class PlotVariableTable

{  

 

 

 

 

      public:

      

      /**

       * Default Constructor

       * 

       * @param   cols        number of columns in the table

       */

            PlotVariableTable(double rows, double cols):v(rows), v1(cols){}

            double v, v1;

};

 

PlotVariableTable make_x(double n, double n1)

{

      PlotVariableTable a = PlotVariableTable( n , n1); 

      return a;

}

 

 

BOOST_PYTHON_MODULE(hello)

{

      def("make_x",make_x);

      

      class_("PlotVariableTable",init());

      

      implicitly_convertible();

      

}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From dave at boost-consulting.com  Mon Jan 19 02:38:35 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Sun, 18 Jan 2004 20:38:35 -0500
Subject: [C++-sig] Re: boolean patch for builtin_converters.hpp
References: <1074388086.6078.7.camel@bluefish>
	
	<1074453968.10816.34.camel@bluefish>
Message-ID: 

Daniel Holth  writes:

> On Sun, 2004-01-18 at 10:39, David Abrahams wrote:
>> Daniel Holth  writes:
>> 
>> > Here's something for fans of Python's relatively new True and False
>> > objects.
>
>> > diff -r1.22 builtin_converters.hpp
>> > 95c95
>> > < BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
>> > ---
>> >> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))
>> 
>> This patch will break 2.2 compatibility and possibly some of the
>> Boost.Python regression tests if we take it as-is.
>> 
>> Please try again, though; I'd like to accept a patch for this!
>
> Not too hard, this version will use the new behavior only in Pythons 2.3
> and above:
>
> // Bool is not signed.
> #if PY_VERSION_HEX >= 0x02030000
> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyBool_FromLong(x))
> #else
> BOOST_PYTHON_TO_PYTHON_BY_VALUE(bool, ::PyInt_FromLong(x))
> #endif

Did you run the regression tests?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dholth at fastmail.fm  Mon Jan 19 06:16:50 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Mon, 19 Jan 2004 00:16:50 -0500
Subject: [C++-sig] Boost.Python Feature Request
In-Reply-To: <20040116134148.10753.qmail@web21325.mail.yahoo.com>
References: <20040116134148.10753.qmail@web21325.mail.yahoo.com>
Message-ID: <1074489409.25797.54.camel@bluefish>

On Fri, 2004-01-16 at 08:41, Jenna Louis wrote:
> Are there any patches or plans to add the following features to
> Boost.Python/Pyste?
>  
> 1. A major usability problem of  Boost generated proxies is that IDEs
> are not able to show any details about the expected parameters. 
> Since Boost already knows everything about the function then it makes
> sense to at least make some information known about it via a docstring
> and then these tools can at least show that.

The last time I looked into this issue it turned out that pydoc (same as
help(foo) inside python) looks at code objects to automatically
determine the number and names of a method's parameters.  Only real
interpreted python code has these.

boost would have to generate bogus code objects to make help show
anything but f(...); a strategerie that kould be veery nasti at best, to
say nothing of overloaded methods.  So, just like builtin objects like
dict, we resort to providing our own docstrings as the last argument to
a .def(): "x.__cmp__(y) <==> cmp(x,y)" and so on.

On the other hand, if a meaningful docstring could be automatically
generated (perhaps from doxygen style docs embedded in the C++), that
would be awesome.  But really tricky.  It sounds like a job for Pyste
and gccxml.

Of course if the Python tracks the C++ closely enough, the C++ API
documentation is nearly as good - depending on how hard it is to switch
from your ide (vim!) to something like a web or class browser.

Here's an example of help illustrating introspectable and
non-introspectable methods:

    class BadStatusLine(HTTPException)
     |  Method resolution order:
     |      BadStatusLine
     |      HTTPException
     |      exceptions.Exception
     |
     |  Methods defined here:   
     |  __init__(self, line) 	# Python method
     |  Methods inherited from exceptions.Exception:
     |  __getitem__(...)	# Builtin (like Boost makes)
     |  __str__(...)





From dave at boost-consulting.com  Mon Jan 19 18:13:46 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Mon, 19 Jan 2004 12:13:46 -0500
Subject: [C++-sig] Re: New slice implementation
References: <1073361918.13426.31.camel@illuvatar> 
	<1073518393.1796.15.camel@illuvatar> 
	<1073595081.19758.430.camel@illuvatar> 
	<1073620180.19759.565.camel@illuvatar> 
	<1073665816.19758.775.camel@illuvatar> 
	<65fk1opl.fsf@boost-consulting.com>
	<1073970573.27246.67.camel@illuvatar>
	
	<1074047914.1215.43.camel@illuvatar>
	
	
	<1074473408.8246.3.camel@illuvatar>
Message-ID: 

Jonathan Brandmeyer  writes:

> On Wed, 2004-01-14 at 00:02, David Abrahams wrote:
>> David Abrahams  writes:
>> 
>> > BTW, compare this with the HTML source for list.html and you'll see
>> > one of the main reasons people hate HTML to be edited with WYSIWYG
>> > tools.  Sticking  tags in a  block is just insane.
>> 
>> Not that you're insane; it's your editor ;-)
>
> I understand.  Its fixed, I think.
>
>> Note also:
>> 
>>   slice::get_indicies(RandomAccessIterator const& begin, RandomAccessIterator const& end);
>> 
>> Is probably too wide and should be wrapped:
>> 
>>   slice::get_indicies(
>>       RandomAccessIterator const& begin, RandomAccessIterator const& end);
>
> Done.

Much better.  Preformatted text is still too wide in places (including
the one I pointed at above, sorry).  Also, the Throws clause from
get_indicies leaves out which Python exception is raised.  You should
use the "raise" term as defined here:

http://www.boost.org/libs/python/doc/v2/definitions.html#raise

So you can avoid writing error_already_set over and over.  You can use
a hyperlink if you think it's needed for clarity.

I think with those small changes it will be ready.  Send me your
sourceforge user id (the textual one) and I'll give you Boost CVS
access so you can check this in yourself.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Mon Jan 19 18:16:42 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Mon, 19 Jan 2004 12:16:42 -0500
Subject: [C++-sig] Re: implicitly_convertible
References: <200401190050.i0J0oP3N2657341@vracs001.vrac.iastate.edu>
Message-ID: 

"aashish"  writes:

> I have this porgram where I need to convert a python float in to C++ class
> object and for that I am using implicitly_convertible
>
>  
>
> In the porgram below (a very simple one) the constructor takd two arguments
> and when I compile with that I got this error ..
>
>  
>
> c:\users\aashish\boost-1.30.2\boost\python\converter\implicit.hpp(34): error
> C2664: 'PlotVariableTable::PlotVariableTable(const PlotVariableTable &)' :
> cannot convert parameter 1 from 'const double' to 'const PlotVariableTable
> &'
>
>  
>
> Now when I compiled and tested with the constructor taking only a single
> value (and hence changed some lines accordingly) program just worked fine. 
>
>  
>
> Please let know is someone can help me as soon as possible. 

A single-argument constructor that is not marked "explicit" makes the
argument type convertible to the class type.  Without that, a double
is not implicitly convertible to a PlotVariableTable.
implicitly_convertible requires that its first argument is
convertible to its second argument.

These are just C++ rules; and have nothing to do with Boost.Python.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From mike at nospam.com  Mon Jan 19 22:12:25 2004
From: mike at nospam.com (Mike Rovner)
Date: Mon, 19 Jan 2004 13:12:25 -0800
Subject: [C++-sig] Re: module unloading callback?
References: <1074322904.21456.4.camel@bluefish>
Message-ID: 

Daniel Holth wrote:
> I've been wrapping a library thats documentation says you should
> init() and free() some internal data structures before and after you
> use it.  I can put code in BOOST_MODULE_INIT to call init, but where
> would I put the tear-down code?  Thanks.

That is very common problem for many libraries. They usually provide
  libInit(...)
  libFinish(...)

My approach is simply wrap them as (module) lib functions:
  Init(...) and Finish(...)
for the user to call manually.

Optionaly as you said, 'init' is called automatically on module init.
That is really depends on library usage model.
But because python _never_ unloads its modules you can't put 'finish'
call anywere to be called automatically.

My $.02

Regards,
Mike






From nicodemus at esss.com.br  Tue Jan 20 01:08:36 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Mon, 19 Jan 2004 21:08:36 -0300
Subject: [C++-sig] Re: module unloading callback?
In-Reply-To: 
References: <1074322904.21456.4.camel@bluefish> 
Message-ID: <400C7184.4040204@esss.com.br>

Mike Rovner wrote:

>Daniel Holth wrote:
>  
>
>>I've been wrapping a library thats documentation says you should
>>init() and free() some internal data structures before and after you
>>use it.  I can put code in BOOST_MODULE_INIT to call init, but where
>>would I put the tear-down code?  Thanks.
>>    
>>
>
>That is very common problem for many libraries. They usually provide
>  libInit(...)
>  libFinish(...)
>
>My approach is simply wrap them as (module) lib functions:
>  Init(...) and Finish(...)
>for the user to call manually.
>
>Optionaly as you said, 'init' is called automatically on module init.
>That is really depends on library usage model.
>But because python _never_ unloads its modules you can't put 'finish'
>call anywere to be called automatically.
>  
>

One approach is to have a python wrapper for your extension module, that 
calls the Init() on import and register the Finish function in the 
atexit module:

# file myext.py
from _myext import * # bring the _myext namespace

InitLib()

import atexit
atexit.register(FinishLib)

The user is then required to use only "import myext". This also allows 
you to put some Python functionality in your module.

Also, one can call InitLib() inside BOOST_PYTHON_MODULE(), which I find 
best specially in the case in failling to properly initializing the 
library can cause crashes in Python.

Regards,
Nicodemus.




From s_sourceforge at nedprod.com  Tue Jan 20 00:00:41 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Mon, 19 Jan 2004 23:00:41 -0000
Subject: [C++-sig] Re: module unloading callback?
In-Reply-To: 
Message-ID: <400C6199.24992.4824B3DA@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 19 Jan 2004 at 13:12, Mike Rovner wrote:

> Daniel Holth wrote:
> > I've been wrapping a library thats documentation says you should
> > init() and free() some internal data structures before and after you
> > use it.  I can put code in BOOST_MODULE_INIT to call init, but where
> > would I put the tear-down code?  Thanks.
> 
> That is very common problem for many libraries. They usually provide
>   libInit(...)
>   libFinish(...)
> 
> My approach is simply wrap them as (module) lib functions:
>   Init(...) and Finish(...)
> for the user to call manually.
> 
> Optionaly as you said, 'init' is called automatically on module init.
> That is really depends on library usage model. But because python
> _never_ unloads its modules you can't put 'finish' call anywere to be
> called automatically.

You can force it to do so via C and if you're careful it seems to run 
just fine. Just don't refer to the no longer existing module :)

To have something called on python exit eg; if python wants to exit 
the process, use:

	def("DeinitTnFOX", &DeinitialiseTnFOXPython);
	PyRun_SimpleString("import atexit\n"
						   "def Internal_CallDeinitTnFOX():\n"
						   "    DeinitTnFOX()\n"
						   "atexit.register(Internal_CallDeinitTnFOX)\n");

This calls DeinitTnFOX() on exit.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQAxhmcEcvDLFGKbPEQLH1gCbBRdDz0uaF6As6qej1FZsrMNtHsAAmQG1
SWib0ZXNUHScXOQijfLEfeUk
=QlEs
-----END PGP SIGNATURE-----



From aashish at vrac.iastate.edu  Tue Jan 20 16:30:47 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Tue, 20 Jan 2004 09:30:47 -0600
Subject: [C++-sig] Re: implicitly_convertible
In-Reply-To: 
Message-ID: <200401201531.i0KFVg3N2714865@vracs001.vrac.iastate.edu>

Hi, 

This might be a very simple question but I am wondering when I should use 

implicitly_convertible as I found that in certain cases the coversion from
Python type to C++ type is possible without using it. 

Thanks, 
Aashish 


-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of David Abrahams
Sent: Monday, January 19, 2004 11:17 AM
To: c++-sig at python.org
Subject: [C++-sig] Re: implicitly_convertible

"aashish"  writes:

A single-argument constructor that is not marked "explicit" makes the
argument type convertible to the class type.  Without that, a double
is not implicitly convertible to a PlotVariableTable.
implicitly_convertible requires that its first argument is
convertible to its second argument.

These are just C++ rules; and have nothing to do with Boost.Python.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig




From aashish at vrac.iastate.edu  Tue Jan 20 17:32:24 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Tue, 20 Jan 2004 10:32:24 -0600
Subject: [C++-sig] Re: implicitly_convertible
In-Reply-To: 
Message-ID: <200401201633.i0KGXK3N2721117@vracs001.vrac.iastate.edu>

Hi, 

I wanted to have a function like this where when I pass a list I will either
get return as set of integers or std::vector of double. 

I tried to implement the function in this manner .....

C++--------------------------------
int make_vector(bp::list vlist)
{
	//std::vector vector_list;
	int k = extract(vlist.attr("__len__")());	
	
	/*for (int i=0;i<10;i++)
	{
	
vector_list.push_back(extract(lt.attr("__getitem__")(i)));
	}

	return vector_list;*/
	
	int kk = extract(vlist.attr("__getitem__")(0));
	
	return kk;
}
Python-----------------------------

L = ['1','2','3']
a = make_vector(L)
print a

The problem is that I am getting the correct value for 'k' here but then it
does throws error saying that 

Tracekack(most recent call last)
File "pytest2.py" , line 30, in ?
	A = "make.vector"(L)
Typeerror: No registered converter was able to produce a C++ rvalue of type
int from this Python object of type str. 

Now what does this error mean?? And How can sole this problem. 

Thanks. 

~regards,
Aashish





From rwgk at yahoo.com  Tue Jan 20 21:19:54 2004
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Tue, 20 Jan 2004 12:19:54 -0800 (PST)
Subject: [C++-sig] FYI: Boost.Python & Linux Intel C++ 8.0
Message-ID: <20040120201954.28009.qmail@web20201.mail.yahoo.com>

FYI:

Most of Boost.Python works with Linux Intel C++ 8.0 (Build 20031231Z
Package ID: l_cc_pc_8.0.058) but there are a couple of tricks to know:

- To avoid unresolved symbol warnings /opt/intel_cc_80/lib/libirc.a
  has to be converted to a shared library:

    /opt/intel_cc_80/bin/icc -shared -o libirc.so /opt/intel_cc_80/lib/libirc.a

  Store libirc.so somewhere in your LD_LIBRARY_PATH.

- To use the native Python define LD_PRELOAD (thanks to Raoul Gough
  for discovering this). E.g.:

    LD_PRELOAD="/some/path/libirc.so:/opt/intel_cc_80/lib/libunwind.so.5"
    export LD_PRELOAD

All Boost.Python tests (libs/python/test) compile.
If compiled with -O0 all run successfully.
If compiled with -O2 seven end with a segmentation fault.

Attached are a few example compilation and link commands.

Ralf

icc -fPIC -O0 -DBOOST_PYTHON_SOURCE -I/net/worm/scratch1/rwgk/dist/boost
-I/usr/include/python2.2 -c -o
boost/libs/python/src/converter/arg_to_python_base.os
/net/worm/scratch1/rwgk/dist/boost/libs/python/src/converter/arg_to_python_base.cpp

icc -shared -o libtbx/libboost_python.so boost/libs/python/src/list.os ...

icc -fPIC -O0 -I/net/worm/scratch1/rwgk/dist/boost -I/usr/include/python2.2 -c
-o boost/libs/python/test/return_arg.os
/net/worm/scratch1/rwgk/dist/boost/libs/python/test/return_arg.cpp

icc -shared -o libtbx/return_arg_ext.so boost/libs/python/test/return_arg.os
-Llibtbx -lboost_python -lm


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



From aashish at vrac.iastate.edu  Tue Jan 20 23:02:22 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Tue, 20 Jan 2004 16:02:22 -0600
Subject: [C++-sig] Re: module unloading callback?
In-Reply-To: <400C6199.24992.4824B3DA@localhost>
Message-ID: <200401202203.i0KM3H3N2734472@vracs001.vrac.iastate.edu>

Hi, 

I am sorry about asking so many question but I have to as I am new to the
world of C++/Python and couldn't find my answers on Google. 


I need to do something like this so that on the python side I will get the
object of type std::vector (I now that I might need to use
to_python_converter but I couldn't understand the documentation)


std::vector   make_vector(bp::list vlist)
{
	std::vector vector_list;

	int list_length = extract(vlist.attr("__len__")());	
	
	for ( int i = 0; i < list_length; i++ )
	{
	    			
	
vector_list.push_back(extract(vlist.attr("__getitem__")(list_length)));
	}

	
	return vector_list;
	
	
}

And it compiled fine but whenI did something like this on python side I got
the error 

L = [1,2,3]
a = make_vector(L)
print a

saying that "No to_python (by value) converter found for C++ class
std""vector >

Can someone tell how to solve this problem...I know what the problem might
be but  I don't know the solution. 

Thanks, 
Aashish 






From aashish at vrac.iastate.edu  Tue Jan 20 23:57:07 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Tue, 20 Jan 2004 16:57:07 -0600
Subject: [C++-sig] Re: to_python_converter 
In-Reply-To: <200401202203.i0KM3H3N2734472@vracs001.vrac.iastate.edu>
Message-ID: <200401202258.i0KMw33N2731205@vracs001.vrac.iastate.edu>



Hi, 

I am sorry about asking so many question but I have to as I am new to the
world of C++/Python and couldn't find my answers on Google. 


I need to do something like this so that on the python side I will get the
object of type std::vector (I now that I might need to use
to_python_converter but I couldn't understand the documentation)


std::vector   make_vector(bp::list vlist)
{
	std::vector vector_list;

	int list_length = extract(vlist.attr("__len__")());	
	
	for ( int i = 0; i < list_length; i++ )
	{
	    			
	
vector_list.push_back(extract(vlist.attr("__getitem__")(list_length)));
	}

	
	return vector_list;
	
	
}

And it compiled fine but whenI did something like this on python side I got
the error 

L = [1,2,3]
a = make_vector(L)
print a

saying that "No to_python (by value) converter found for C++ class
std""vector >

Can someone tell how to solve this problem...I know what the problem might
be but  I don't know the solution. 

Thanks, 
Aashish 




_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig




From dave at boost-consulting.com  Wed Jan 21 01:46:51 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Tue, 20 Jan 2004 19:46:51 -0500
Subject: [C++-sig] Re: FYI: Boost.Python & Linux Intel C++ 8.0
References: <20040120201954.28009.qmail@web20201.mail.yahoo.com>
Message-ID: 

"Ralf W. Grosse-Kunstleve"  writes:

> FYI:
>
> Most of Boost.Python works with Linux Intel C++ 8.0 (Build 20031231Z
> Package ID: l_cc_pc_8.0.058) but there are a couple of tricks to know:
>
> - To avoid unresolved symbol warnings /opt/intel_cc_80/lib/libirc.a
>   has to be converted to a shared library:
>
>     /opt/intel_cc_80/bin/icc -shared -o libirc.so /opt/intel_cc_80/lib/libirc.a
>
>   Store libirc.so somewhere in your LD_LIBRARY_PATH.
>
> - To use the native Python define LD_PRELOAD (thanks to Raoul Gough
>   for discovering this). E.g.:
>
>     LD_PRELOAD="/some/path/libirc.so:/opt/intel_cc_80/lib/libunwind.so.5"
>     export LD_PRELOAD

Just use Boost.Build and it should work.
We're adding -cxxlib-gcc to the command line.  Works for me.

> All Boost.Python tests (libs/python/test) compile.
> If compiled with -O0 all run successfully.
> If compiled with -O2 seven end with a segmentation fault.

Maybe LD_PRELOAD isn't really the right approach?  I got the
-cxxlib-gcc option from the Intel support people.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From RaoulGough at yahoo.co.uk  Wed Jan 21 03:25:34 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Wed, 21 Jan 2004 02:25:34 +0000
Subject: [C++-sig] Re: FYI: Boost.Python & Linux Intel C++ 8.0
References: <20040120201954.28009.qmail@web20201.mail.yahoo.com>
	
Message-ID: 

David Abrahams  writes:

> "Ralf W. Grosse-Kunstleve"  writes:
[snip]
>> - To use the native Python define LD_PRELOAD (thanks to Raoul Gough
>>   for discovering this). E.g.:
>>
>>     LD_PRELOAD="/some/path/libirc.so:/opt/intel_cc_80/lib/libunwind.so.5"
>>     export LD_PRELOAD
>
> Just use Boost.Build and it should work.
> We're adding -cxxlib-gcc to the command line.  Works for me.
>
>> All Boost.Python tests (libs/python/test) compile.
>> If compiled with -O0 all run successfully.
>> If compiled with -O2 seven end with a segmentation fault.
>
> Maybe LD_PRELOAD isn't really the right approach?  I got the
> -cxxlib-gcc option from the Intel support people.

Hmmm... From
http://www.intel.com/software/products/compilers/clin/docs/ug/lin1106.htm

  "The -cxxlib-gcc option lets you to build your applications using
  the C++ libraries and header files included with the gcc
  compiler. [...] When you compile and link your application using the
  -cxxlib-gcc option, the resulting C++ object files, libraries, and
  executables can interoperate with C++ object files, libraries, and
  executables generated by gcc 3.2."

IIRC, the only problem that the LD_PRELOAD setting fixes had to do
with exception handling (that's the libunwind.so.5).  Presumably the
gcc-compatibility feature also fixes the same problem, and maybe
others.  On the other hand, what if you actually want to use the
Intel-provided standard library (whatever it is)? I wonder if it fixes
the segfaults at -O2 that Ralf mentioned?

Since Python is straight C code, I wouldn't think that full C++ ABI
compatibility would be necessary, but maybe there's more to it than
I'm aware of. Would be interested to know what's really going on
with the crashes...

-- 
Raoul Gough.
export LESS='-X'




From RaoulGough at yahoo.co.uk  Wed Jan 21 03:33:27 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Wed, 21 Jan 2004 02:33:27 +0000
Subject: [C++-sig] Re: to_python_converter
References: <200401202203.i0KM3H3N2734472@vracs001.vrac.iastate.edu>
	<200401202258.i0KMw33N2731205@vracs001.vrac.iastate.edu>
Message-ID: 

"aashish"  writes:

> Hi, 
>
> I am sorry about asking so many question but I have to as I am new to the
> world of C++/Python and couldn't find my answers on Google. 
>
>
> I need to do something like this so that on the python side I will get the
> object of type std::vector (I now that I might need to use
> to_python_converter but I couldn't understand the documentation)
>

Usually, you don't have to mess around with to_python_converter. What
you should do is "expose" the C++ class to Python via an instance of
the boost::python::class_ template. Probably the tutorial is the right
place to start for this kind of stuff.

>
> std::vector   make_vector(bp::list vlist)
> {
> 	std::vector vector_list;
>
> 	int list_length = extract(vlist.attr("__len__")());	
> 	
> 	for ( int i = 0; i < list_length; i++ )
> 	{
> 	    			
> 	
> vector_list.push_back(extract(vlist.attr("__getitem__")(list_length)));
> 	}
>
> 	
> 	return vector_list;
> 	
> 	
> }
>
> And it compiled fine but whenI did something like this on python side I got
> the error 
>
> L = [1,2,3]
> a = make_vector(L)
> print a
>
> saying that "No to_python (by value) converter found for C++ class
> std""vector >
>
> Can someone tell how to solve this problem...I know what the problem might
> be but  I don't know the solution. 

In this case, you want to expose the vector instance via something like this:

// in your BOOST_PYTHON_MODULE function
  boost::python::class_ > ("int_vector")
    .def (/* ... */)
    // ...
    .def (/* ... */);

AFAIK, the super-duper container support stuff is currently only in
the CVS (i.e. wasn't in the 1.30.x releases). If you can upgrade to
the CVS code (see downloading info from the boost home page) then you
would be able to use the "indexing suite" to do something like

  boost::python::class_ > ("int_vector")
    .def (boost::python::indexing >());

or something along those lines, to get all the useful Python support
functions for your vector (like __getitem__ and so on). See link to
the indexing suite documentation right at the bottom of the Boost
Python reference page (once you've got the files from CVS, of course).


-- 
Raoul Gough.
export LESS='-X'




From rwgk at yahoo.com  Wed Jan 21 08:54:45 2004
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Tue, 20 Jan 2004 23:54:45 -0800 (PST)
Subject: [C++-sig] Re: FYI: Boost.Python & Linux Intel C++ 8.0
In-Reply-To: 
Message-ID: <20040121075445.10049.qmail@web20210.mail.yahoo.com>

--- David Abrahams  wrote:
> Just use Boost.Build and it should work.
> We're adding -cxxlib-gcc to the command line.  Works for me.

Do you know anything about the impact on runtime performance?
One would hope that Intel's runtime libraries are faster than gcc's.
Ralf


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



From dave at boost-consulting.com  Wed Jan 21 16:53:41 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 21 Jan 2004 10:53:41 -0500
Subject: [C++-sig] Re: FYI: Boost.Python & Linux Intel C++ 8.0
References: 
	<20040121075445.10049.qmail@web20210.mail.yahoo.com>
Message-ID: 

"Ralf W. Grosse-Kunstleve"  writes:

> --- David Abrahams  wrote:
>> Just use Boost.Build and it should work.
>> We're adding -cxxlib-gcc to the command line.  Works for me.
>
> Do you know anything about the impact on runtime performance?
> One would hope that Intel's runtime libraries are faster than gcc's.

I would not count on it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dholth at fastmail.fm  Wed Jan 21 21:02:08 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Wed, 21 Jan 2004 15:02:08 -0500
Subject: [C++-sig] pyste add_method
Message-ID: <1074715327.2809.1.camel@bluefish>

I'm trying to use Pyste (cvs) like so:

sync is a class within oggpy.

-- oggpy.pyste

oggpy = AllFromHeader("oggcc.h")

Function("get_comments", "oggpy_wrappers.h")
syncwrite = Function("sync_write", "oggpy_wrappers.h")

# strategy 1
add_method(oggpy.sync, syncwrite)

#strategy 2 (mutually exclusive with 1
add_method(oggpy.sync, "sync_write")

rename(oggpy.sync.sync_write, "write")

-- oggpy_wrappers.h

#ifndef OGGPY_WRAPPERS_H
#define OGGPY_WRAPPERS_H

#include "oggcc.h"
#include 

int sync_write(ogg::sync &s, boost::python::str &data);
boost::python::list get_comments(ogg::vorbis::comment *vc);

#endif

--

Unfortunately, with strategy 1, RuntimeError: no  declaration found!
Or, RuntimeError: no sync_write declaration found!

I think I'm missing something obvious?

Thanks,

Daniel Holth





From RaoulGough at yahoo.co.uk  Wed Jan 21 21:28:27 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Wed, 21 Jan 2004 20:28:27 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	 
	
Message-ID: 

Raoul Gough  writes:

> David Abrahams  writes:
>
>> Raoul Gough  writes:
[snip]
>>> I've been wondering about what the container suite
>>> interface should look like after moving to feature sets instead of
>>> static boolean constants. I'm thinking along these lines:
>>>
>>> template<
>>>      class Container,
>>>      SOME_KIND_OF_SET features = supported_features,
>>>      class Algorithms = algorithms
>>>> container_suite;
[snip]
>>
>> Nope; so far it sounds great.
>
> OK, thanks! I think I'll go with the supported_features approach.

This is how the new implementation is actually looking:

  template<
      class Container,
      unsigned int MethodMask = all_methods,  // All supported by algorithms
      class Algorithms = algorithms
  >
  struct container_suite /* ... */;

The second template parameter is an unsigned bitmask that gets
combined with a "supported_methods" value provided by the Algorithms
argument. It worked out this way because determining what features
should be supported by default depends on the value type as well as
the type of container (i.e. it needs to know equality_comparable and
less_than_comparable from the value_traits template).

Here is the new vector_traits template, which works out what methods
to provide (by default) for instances of std::vector:

  template
  class vector_traits
    : public default_container_traits
  {
    typedef default_container_traits base_class;
    BOOST_STATIC_CONSTANT(bool, is_mutable = !is_const::value);

  public:
    typedef typename base_class::value_traits_type value_traits_type;

    BOOST_STATIC_CONSTANT(
        unsigned int,
        supported_methods = (
              method_len
            | method_getitem
            | method_getitem_slice

            | detail::unsigned_if<
                  value_traits_type::equality_comparable,
                    method_index
                  | method_contains
                  | method_count
              >::value

            | detail::unsigned_if<
                  is_mutable,
                    method_setitem
                  | method_setitem_slice
                  | method_delitem
                  | method_delitem_slice
                  | method_reverse
                  | method_append
                  | method_insert
                  | method_extend
              >::value

            | detail::unsigned_if<
                  type_traits::ice_and<
                      is_mutable, value_traits_type::less_than_comparable
                  >::value,
                  method_sort
              >::value

        ));

        // Never supported: method_iter, method_has_key
  };

In case you really wanted to know, unsigned_if looks like this:

  namespace detail {
    template
    struct unsigned_if {
      struct true_type {
        BOOST_STATIC_CONSTANT(unsigned int, value = TrueValue);
      };

      struct false_type {
        BOOST_STATIC_CONSTANT(unsigned int, value = FalseValue);
      };

      typedef typename mpl::if_c::type
          result_type;

      BOOST_STATIC_CONSTANT(unsigned int, value = result_type::value);
    };
  }

I've tested this much under gcc 3.3.1 and MSVC6.0 and 7.1. So before I
get too carried away and convert everything to this new style, does
Dave, Joel, or anyone else have comments or suggestions?

-- 
Raoul Gough.
export LESS='-X'




From s_sourceforge at nedprod.com  Wed Jan 21 21:46:19 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Wed, 21 Jan 2004 20:46:19 -0000
Subject: [C++-sig] pyste add_method
In-Reply-To: <1074715327.2809.1.camel@bluefish>
Message-ID: <400EE51B.8599.51F666C0@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 21 Jan 2004 at 15:02, Daniel Holth wrote:

> I'm trying to use Pyste (cvs) like so:
> 
> sync is a class within oggpy.
> 
> -- oggpy.pyste
> 
> oggpy = AllFromHeader("oggcc.h")

AllFromHeader() doesn't work in more recent versions of pyste.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQA7lG8EcvDLFGKbPEQKVGwCeMeXxjr/cgCxsOA1QZCGnD6EipjMAoNG3
oWO5ddf9JMd9r3QgbzSobxS7
=GoE6
-----END PGP SIGNATURE-----



From dholth at fastmail.fm  Wed Jan 21 22:43:46 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Wed, 21 Jan 2004 16:43:46 -0500
Subject: [C++-sig] pyste add_method
In-Reply-To: <400EE51B.8599.51F666C0@localhost>
References: <400EE51B.8599.51F666C0@localhost>
Message-ID: <1074721426.1151.5.camel@bluefish>

On Wed, 2004-01-21 at 15:46, Niall Douglas wrote:
> AllFromHeader() doesn't work in more recent versions of pyste.

That's too bad.  It seemed like it was working, generating beautiful
wrappers except for that one line trying to add a method to the class.




From s_sourceforge at nedprod.com  Thu Jan 22 00:03:53 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Wed, 21 Jan 2004 23:03:53 -0000
Subject: [C++-sig] pyste add_method
In-Reply-To: <1074721426.1151.5.camel@bluefish>
References: <400EE51B.8599.51F666C0@localhost>
Message-ID: <400F0559.28071.5274598C@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 21 Jan 2004 at 16:43, Daniel Holth wrote:

> On Wed, 2004-01-21 at 15:46, Niall Douglas wrote:
> > AllFromHeader() doesn't work in more recent versions of pyste.
> 
> That's too bad.  It seemed like it was working, generating beautiful
> wrappers except for that one line trying to add a method to the class.

Of course, if you feel like fixing it in the CVS version we'd all be 
very grateful ... :)

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQA8FWcEcvDLFGKbPEQIa8gCg7pKxkTU8h4XllZJtrEUvxoxFD/AAn2Bt
qxOR9nfH1InxvhO4s/9s/iVb
=9si6
-----END PGP SIGNATURE-----



From dholth at fastmail.fm  Thu Jan 22 00:21:40 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Wed, 21 Jan 2004 18:21:40 -0500
Subject: [C++-sig] pyste add_method
In-Reply-To: <400F0559.28071.5274598C@localhost>
References: <400EE51B.8599.51F666C0@localhost>
	<400F0559.28071.5274598C@localhost>
Message-ID: <1074727299.24018.20.camel@bluefish>

On Wed, 2004-01-21 at 18:03, Niall Douglas wrote:
> Of course, if you feel like fixing it in the CVS version we'd all be 
> very grateful ... :)
> 
> Cheers,
> Niall

Well, I love fixing Python code :)

Anyway, my problem is unrelated to AllFromHeader().  Basically, I am
having trouble figuring out how to use add_method when the method to add
is defined in a different header than the class.  It gives an error like
this: RuntimeError: no greet declaration found!

- dwh




From joel at boost-consulting.com  Thu Jan 22 01:16:29 2004
From: joel at boost-consulting.com (Joel de Guzman)
Date: Thu, 22 Jan 2004 08:16:29 +0800
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
References: 
		
		
		
		
		
		
		
		
		
	
Message-ID: <400F165D.4080606@boost-consulting.com>

Raoul Gough wrote:

> This is how the new implementation is actually looking:
> 
>   template<
>       class Container,
>       unsigned int MethodMask = all_methods,  // All supported by algorithms
>       class Algorithms = algorithms
>   >
>   struct container_suite /* ... */;
> 
> The second template parameter is an unsigned bitmask that gets
> combined with a "supported_methods" value provided by the Algorithms
> argument. It worked out this way because determining what features
> should be supported by default depends on the value type as well as
> the type of container (i.e. it needs to know equality_comparable and
> less_than_comparable from the value_traits template).

[snips]

> I've tested this much under gcc 3.3.1 and MSVC6.0 and 7.1. So before I
> get too carried away and convert everything to this new style, does
> Dave, Joel, or anyone else have comments or suggestions?

Looks cool to me ;-) My only concern is: what if the bits of an
unsigned int runs out? Unlikely? What if the methods identifiers
are types instead in a special namespace and specifying the
methods is done using an mpl typelist? Example:

container_suite >

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net



From nicodemus at esss.com.br  Thu Jan 22 05:52:53 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Thu, 22 Jan 2004 01:52:53 -0300
Subject: [C++-sig] pyste add_method
In-Reply-To: <400F0559.28071.5274598C@localhost>
References: <400EE51B.8599.51F666C0@localhost>
	<400F0559.28071.5274598C@localhost>
Message-ID: <400F5725.3000402@esss.com.br>

Niall Douglas wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On 21 Jan 2004 at 16:43, Daniel Holth wrote:
>
>  
>
>>On Wed, 2004-01-21 at 15:46, Niall Douglas wrote:
>>    
>>
>>>AllFromHeader() doesn't work in more recent versions of pyste.
>>>      
>>>
>>That's too bad.  It seemed like it was working, generating beautiful
>>wrappers except for that one line trying to add a method to the class.
>>    
>>
>
>Of course, if you feel like fixing it in the CVS version we'd all be 
>very grateful ... :)
>  
>

Fear not! I think I will have some free time this weekend, and I plan to 
work on this. 8)

Regards,
Nicodemus.




From nicodemus at esss.com.br  Thu Jan 22 05:54:13 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Thu, 22 Jan 2004 01:54:13 -0300
Subject: [C++-sig] pyste add_method
In-Reply-To: <1074727299.24018.20.camel@bluefish>
References: <400EE51B.8599.51F666C0@localhost>	<400F0559.28071.5274598C@localhost>
	<1074727299.24018.20.camel@bluefish>
Message-ID: <400F5775.7080004@esss.com.br>

Daniel Holth wrote:

>On Wed, 2004-01-21 at 18:03, Niall Douglas wrote:
>  
>
>>Of course, if you feel like fixing it in the CVS version we'd all be 
>>very grateful ... :)
>>
>>Cheers,
>>Niall
>>    
>>
>
>Well, I love fixing Python code :)
>
>Anyway, my problem is unrelated to AllFromHeader().  Basically, I am
>having trouble figuring out how to use add_method when the method to add
>is defined in a different header than the class.  It gives an error like
>this: RuntimeError: no greet declaration found!
>  
>

Hmm... without looking at some complete code is hard to say, but I think 
that you may be missing a Include directive:

Include('header_file_where_greet_is_declared.h')

HTH,
Nicodemus.




From dave at boost-consulting.com  Thu Jan 22 05:22:26 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Wed, 21 Jan 2004 23:22:26 -0500
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	 
	 
	<400F165D.4080606@boost-consulting.com>
Message-ID: 

Joel de Guzman  writes:

> Raoul Gough wrote:
>
>> This is how the new implementation is actually looking:
>>   template<
>>       class Container,
>>       unsigned int MethodMask = all_methods,  // All supported by algorithms
>>       class Algorithms = algorithms
>>   >
>>   struct container_suite /* ... */;
>> The second template parameter is an unsigned bitmask that gets
>> combined with a "supported_methods" value provided by the Algorithms
>> argument. It worked out this way because determining what features
>> should be supported by default depends on the value type as well as
>> the type of container (i.e. it needs to know equality_comparable and
>> less_than_comparable from the value_traits template).
>
> [snips]
>
>> I've tested this much under gcc 3.3.1 and MSVC6.0 and 7.1. So before I
>> get too carried away and convert everything to this new style, does
>> Dave, Joel, or anyone else have comments or suggestions?
>
> Looks cool to me ;-) My only concern is: what if the bits of an
> unsigned int runs out? Unlikely? What if the methods identifiers
> are types instead in a special namespace and specifying the
> methods is done using an mpl typelist? Example:

One should at the very least use an unsigned long.  You're only
guaranteed 16 bits with unsigned int.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From RaoulGough at yahoo.co.uk  Thu Jan 22 11:59:20 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Thu, 22 Jan 2004 10:59:20 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	 
	 <400F165D.4080606@boost-consulting.com>
	
Message-ID: 

David Abrahams  writes:

> Joel de Guzman  writes:
[snip]
>> Looks cool to me ;-) My only concern is: what if the bits of an
>> unsigned int runs out? Unlikely? What if the methods identifiers
>> are types instead in a special namespace and specifying the
>> methods is done using an mpl typelist? Example:
>
> One should at the very least use an unsigned long.  You're only
> guaranteed 16 bits with unsigned int.

I thought about this, but figured there weren't any 16-bit compilers
that would compile the rest of the code anyway. Are there any real
platforms where the compiler supports all that template machinery and
has 16-bit ints (maybe some configurations of gcc)? I suppose it
doesn't actually cost anything to go to unsigned long...

-- 
Raoul Gough.
export LESS='-X'




From RaoulGough at yahoo.co.uk  Thu Jan 22 12:10:10 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Thu, 22 Jan 2004 11:10:10 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	 
	 
	<400F165D.4080606@boost-consulting.com>
Message-ID: 

Joel de Guzman  writes:

> Raoul Gough wrote:
[snip]
>> I've tested this much under gcc 3.3.1 and MSVC6.0 and 7.1. So before I
>> get too carried away and convert everything to this new style, does
>> Dave, Joel, or anyone else have comments or suggestions?
>
> Looks cool to me ;-) My only concern is: what if the bits of an
> unsigned int runs out? Unlikely? What if the methods identifiers
> are types instead in a special namespace and specifying the
> methods is done using an mpl typelist? Example:
>
> container_suite >

Well, that's a good question. There are a number of possible methods
that aren't included yet - things like pop, clear and the arithmetic
operator support (__iadd__, __radd__, etc.) I haven't counted them up,
but there are two possible solutions if the bitspace runs out: (1)
select the new methods in groups (e.g. method_all_arithmetic) or (2)
add a new unsigned template parameter for the "advanced" features.

Dave and I discussed using a typelist, but I decided against them
because of their complexity and my doubts about mpl::set, which would
be the appropriate data structure in this case. Maybe it would be
possible to do it with mpl::list - I'll have a look into it. BTW,
aren't there compilers that have limited template recursion depth,
which would also impose a restriction on the number of elements in a
list/set?

-- 
Raoul Gough.
export LESS='-X'




From joel at boost-consulting.com  Thu Jan 22 13:25:38 2004
From: joel at boost-consulting.com (Joel de Guzman)
Date: Thu, 22 Jan 2004 20:25:38 +0800
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
References: 
		
		
		
		
		
		
		
		
		
	<400F165D.4080606@boost-consulting.com>	
	
Message-ID: <400FC142.1020001@boost-consulting.com>

Raoul Gough wrote:

> David Abrahams  writes:
> 
> 
>>Joel de Guzman  writes:
> 
> [snip]
> 
>>>Looks cool to me ;-) My only concern is: what if the bits of an
>>>unsigned int runs out? Unlikely? What if the methods identifiers
>>>are types instead in a special namespace and specifying the
>>>methods is done using an mpl typelist? Example:
>>
>>One should at the very least use an unsigned long.  You're only
>>guaranteed 16 bits with unsigned int.
> 
> 
> I thought about this, but figured there weren't any 16-bit compilers
> that would compile the rest of the code anyway. Are there any real
> platforms where the compiler supports all that template machinery and
> has 16-bit ints (maybe some configurations of gcc)? I suppose it
> doesn't actually cost anything to go to unsigned long...

Maybe I ought to write the static bitset thing. I wrote one before.
I'll see if I can get the prototype. There's one here:
http://spirit.sourceforge.net/dl_more/Spirit_StaticSet.h
I'll see if I can make it MPLish.

Regards,
-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net




From dave at boost-consulting.com  Thu Jan 22 14:21:25 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Thu, 22 Jan 2004 08:21:25 -0500
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	 <400F165D.4080606@boost-consulting.com>
	 
	<400FC142.1020001@boost-consulting.com>
Message-ID: 

Joel de Guzman  writes:

> Raoul Gough wrote:
>
>> David Abrahams  writes:
>> 
>>>Joel de Guzman  writes:
>> [snip]
>> 
>>>>Looks cool to me ;-) My only concern is: what if the bits of an
>>>>unsigned int runs out? Unlikely? What if the methods identifiers
>>>>are types instead in a special namespace and specifying the
>>>>methods is done using an mpl typelist? Example:
>>>
>>>One should at the very least use an unsigned long.  You're only
>>>guaranteed 16 bits with unsigned int.
>> I thought about this, but figured there weren't any 16-bit compilers
>> that would compile the rest of the code anyway. Are there any real
>> platforms where the compiler supports all that template machinery and
>> has 16-bit ints (maybe some configurations of gcc)? I suppose it
>> doesn't actually cost anything to go to unsigned long...
>
> Maybe I ought to write the static bitset thing. I wrote one before.
> I'll see if I can get the prototype. There's one here:
> http://spirit.sourceforge.net/dl_more/Spirit_StaticSet.h
> I'll see if I can make it MPLish.

It'd be easy to base it on vector_c

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From RaoulGough at yahoo.co.uk  Thu Jan 22 19:15:05 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Thu, 22 Jan 2004 18:15:05 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	 
	<400F165D.4080606@boost-consulting.com>
	 
	<400FC142.1020001@boost-consulting.com>
	
Message-ID: 

David Abrahams  writes:

> Joel de Guzman  writes:
>
>> Raoul Gough wrote:
>>
>>> David Abrahams  writes:
>>> 
>>>>Joel de Guzman  writes:
>>> [snip]
>>> 
>>>>>Looks cool to me ;-) My only concern is: what if the bits of an
>>>>>unsigned int runs out? Unlikely? What if the methods identifiers
>>>>>are types instead in a special namespace and specifying the
>>>>>methods is done using an mpl typelist? Example:
>>>>
>>>>One should at the very least use an unsigned long.  You're only
>>>>guaranteed 16 bits with unsigned int.
>>> I thought about this, but figured there weren't any 16-bit compilers
>>> that would compile the rest of the code anyway. Are there any real
>>> platforms where the compiler supports all that template machinery and
>>> has 16-bit ints (maybe some configurations of gcc)? I suppose it
>>> doesn't actually cost anything to go to unsigned long...
>>
>> Maybe I ought to write the static bitset thing. I wrote one before.
>> I'll see if I can get the prototype. There's one here:
>> http://spirit.sourceforge.net/dl_more/Spirit_StaticSet.h
>> I'll see if I can make it MPLish.
>
> It'd be easy to base it on vector_c

Something like this would be a good solution! Especially since it is
possible to take the complement of a set (handy for saying "all
features" or "all features except *this*"). However, it would need to
have compile-time determination of set membership. Is this possible?

-- 
Raoul Gough.
export LESS='-X'




From joel at boost-consulting.com  Thu Jan 22 23:12:28 2004
From: joel at boost-consulting.com (Joel de Guzman)
Date: Fri, 23 Jan 2004 06:12:28 +0800
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
References: 
		
		
		
		
		
		
		
		<400F165D.4080606@boost-consulting.com>	
		<400FC142.1020001@boost-consulting.com>	
	
Message-ID: <40104ACC.5080600@boost-consulting.com>

Raoul Gough wrote:
> David Abrahams  writes:
> 
> 
>>Joel de Guzman  writes:
>>
>>
>>>Raoul Gough wrote:
>>>
>>>
>>>>David Abrahams  writes:
>>>>
>>>>
>>>>>Joel de Guzman  writes:
>>>>
>>>>[snip]
>>>>
>>>>
>>>>>>Looks cool to me ;-) My only concern is: what if the bits of an
>>>>>>unsigned int runs out? Unlikely? What if the methods identifiers
>>>>>>are types instead in a special namespace and specifying the
>>>>>>methods is done using an mpl typelist? Example:
>>>>>
>>>>>One should at the very least use an unsigned long.  You're only
>>>>>guaranteed 16 bits with unsigned int.
>>>>
>>>>I thought about this, but figured there weren't any 16-bit compilers
>>>>that would compile the rest of the code anyway. Are there any real
>>>>platforms where the compiler supports all that template machinery and
>>>>has 16-bit ints (maybe some configurations of gcc)? I suppose it
>>>>doesn't actually cost anything to go to unsigned long...
>>>
>>>Maybe I ought to write the static bitset thing. I wrote one before.
>>>I'll see if I can get the prototype. There's one here:
>>>http://spirit.sourceforge.net/dl_more/Spirit_StaticSet.h
>>>I'll see if I can make it MPLish.
>>
>>It'd be easy to base it on vector_c

Yep. That's what I'm thinking.

> Something like this would be a good solution! Especially since it is
> possible to take the complement of a set (handy for saying "all
> features" or "all features except *this*"). However, it would need to
> have compile-time determination of set membership. Is this possible?

Yep. Sure!

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net



From dholth at fastmail.fm  Fri Jan 23 04:21:20 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Thu, 22 Jan 2004 22:21:20 -0500
Subject: [C++-sig] boost numeric tests
Message-ID: <1074828079.12155.6.camel@bluefish>

I'm running the tests on CVS boost.python, I have numeric and numarray
installed, and I get errors like this: (compiling with Pythons 2.2.3+
and 2.3.3):

Failure in example: exercise_numarray(x, p)
from line #6 of __main__._numarray_tests
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.3/doctest.py", line 442, in _run_examples_inner
    compileflags, 1) in globs
  File "", line 1, in ?
AttributeError: 'NumArray' object has no attribute 'array'

Then the rest of the tests fail because the C++ half never got a chance
to run.

Any idea why this might be happening?

Thanks,

Daniel Holth




From RaoulGough at yahoo.co.uk  Fri Jan 23 11:49:59 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Fri, 23 Jan 2004 10:49:59 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  
	 
	 
	 
	 
	 
	 
	<400F165D.4080606@boost-consulting.com>
	 
	<400FC142.1020001@boost-consulting.com>
	 
	<40104ACC.5080600@boost-consulting.com>
Message-ID: 

Joel de Guzman  writes:

> Raoul Gough wrote:
>> David Abrahams  writes:
>>
>>>Joel de Guzman  writes:
[snip]

>>>>Maybe I ought to write the static bitset thing. I wrote one before.
>>>>I'll see if I can get the prototype. There's one here:
>>>>http://spirit.sourceforge.net/dl_more/Spirit_StaticSet.h
>>>>I'll see if I can make it MPLish.
>>>
>>>It'd be easy to base it on vector_c
>
> Yep. That's what I'm thinking.
>
>> Something like this would be a good solution! Especially since it is
>> possible to take the complement of a set (handy for saying "all
>> features" or "all features except *this*"). However, it would need to
>> have compile-time determination of set membership. Is this possible?
>
> Yep. Sure!

The only worry I see is the notational (or syntax) issue. How easy
would it be to express the combination of possible values? For
reference again, here is what it looks like with plain bits:

    BOOST_STATIC_CONSTANT(
        unsigned int,
        supported_methods = (
              method_len
            | method_getitem
            | method_getitem_slice

            | detail::unsigned_if<
                  value_traits_type::equality_comparable,
                    method_index
                  | method_contains
                  | method_count
              >::value

            // ...

Which is not really pretty, but I think it is understandable
enough. Considering the following two questions:

1. What are the costs of supporting an effectively unlimited number of
   flags?

2. What is the likelihood that we would ever need more than 32 (there
   are currently 16)?

What I'm thinking is, can we go with the simplest approach that works
now, and switch to a more complex solution if it ever becomes
necessary? Of course, it would be helpful to know what the above code
would look like with a vector_c type solution.

-- 
Raoul Gough.
export LESS='-X'




From pierre.barbier at cirad.fr  Fri Jan 23 15:02:24 2004
From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille)
Date: Fri, 23 Jan 2004 15:02:24 +0100
Subject: [C++-sig] Problem with pickling returning a boost::python::dict
	object
Message-ID: <1074866543.26939.14.camel@pbarbier>

I want to enable picking as if the data stored in C++ were stored in
python variables. To do so, I get the __dict__ variable of my object,
add the variables I want to save in the pickling and return the modified
dictionnary. But then I have the error :

Traceback (most recent call last):
  File "", line 1, in ?
cPickle.PicklingError: Can't pickle :
import of module Boost.Python failed

'g' being on object want to pickle :

>>> d = g.__getstate__()
>>> d.__class__


Here is my __getstate__ picklink function (I use boost pickling method
... ):

struct CellGraph3D_pickle_suite : boost::python::pickle_suite
{
  /* ... */
  static boost::python::dict getstate(boost::python::object c_obj)
    {
      using namespace boost::python;
      CellGraph3D & c = extract(c_obj)();

      dict save = extract( c_obj.attr( "__dict__" ) );
      save[ "_vertices_" ] = c.getVertices();
      save[ "_edges_" ] = c.getEdges();
      save[ "_positions_" ] = c.pos_map;
      save[ "_cells_" ] = c.cell_map;
      save[ "_colors_" ] = c.color_map;

      return save;
    }
  /* ... */
}

If, instead of returning a dict I return a tuple, it seems to work, but
that's not what I want.

Thanks,

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 




From pierre.barbier at cirad.fr  Fri Jan 23 15:34:12 2004
From: pierre.barbier at cirad.fr (Pierre Barbier de Reuille)
Date: Fri, 23 Jan 2004 15:34:12 +0100
Subject: [C++-sig] Problem with pickling returning a
	boost::python::dict object
In-Reply-To: <1074866543.26939.14.camel@pbarbier>
References: <1074866543.26939.14.camel@pbarbier>
Message-ID: <1074868452.24889.35.camel@pbarbier>

Sorry, I think I found the problem ... I forgot to enable the picking
for an object nested in an object put in the dictionnary. Now it's fixed
! At least, I must say the pickling support is a great feature !!

Pierre


-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 




From rwgk at yahoo.com  Fri Jan 23 18:53:30 2004
From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve)
Date: Fri, 23 Jan 2004 09:53:30 -0800 (PST)
Subject: [C++-sig] Problem with pickling returning a boost::python::dict
	object
In-Reply-To: <1074868452.24889.35.camel@pbarbier>
Message-ID: <20040123175330.51923.qmail@web20204.mail.yahoo.com>

--- Pierre Barbier de Reuille  wrote:
> At least, I must say the pickling support is a great feature !!

Thanks!

>      save[ "_vertices_" ] = c.getVertices();
>      save[ "_edges_" ] = c.getEdges();
>      save[ "_positions_" ] = c.pos_map;
>      save[ "_cells_" ] = c.cell_map;
>      save[ "_colors_" ] = c.color_map;

It would worry me to clutter the __dict__ with temporary attributes.
What if someone who is not aware of the implementation details of
your pickle support uses your class as a base class and defines
attributes _vertices_ etc.? It will be very hard for your user
to track down what is going wrong. It is much safer to put the
attributes in a new dictionary and to return a tuple with the
unmodified __dict__ and the additional dictionary with the state.
I think all you need to do this is two extra lines of code
(something like dict save; make_tuple(object_dict, save)).

Ralf



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/



From s_sourceforge at nedprod.com  Fri Jan 23 21:23:58 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Fri, 23 Jan 2004 20:23:58 -0000
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
Message-ID: <401182DE.12359.5C2EA924@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 23 Jan 2004 at 10:49, Raoul Gough wrote:

> 2. What is the likelihood that we would ever need more than 32 (there
>    are currently 16)?
> 
> What I'm thinking is, can we go with the simplest approach that works
> now, and switch to a more complex solution if it ever becomes
> necessary? Of course, it would be helpful to know what the above code
> would look like with a vector_c type solution.

Surely you can use long long or __int64 as template parameters?

Also, CUJ had an article about implementing infinite length numbers 
at compile time using templates. May be useful here.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQBGC3sEcvDLFGKbPEQKNFgCcC5w1Hu8bdP2CjS4M697s57izWeQAn0wd
wBHr4+g8fY5amp55FDmXQp0K
=rpRB
-----END PGP SIGNATURE-----



From RaoulGough at yahoo.co.uk  Sat Jan 24 13:24:37 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Sat, 24 Jan 2004 12:24:37 +0000
Subject: [C++-sig] Re: indexing_v2 status update
References:  <401182DE.12359.5C2EA924@localhost>
Message-ID: 

"Niall Douglas"  writes:

> On 23 Jan 2004 at 10:49, Raoul Gough wrote:
>
>> 2. What is the likelihood that we would ever need more than 32 (there
>>    are currently 16)?
>> 
>> What I'm thinking is, can we go with the simplest approach that works
>> now, and switch to a more complex solution if it ever becomes
>> necessary? Of course, it would be helpful to know what the above code
>> would look like with a vector_c type solution.
>
> Surely you can use long long or __int64 as template parameters?

I guess so - on compilers that support one or the other. long long is
(still) not part of the C++ standard, AFAIK.

>
> Also, CUJ had an article about implementing infinite length numbers 
> at compile time using templates. May be useful here.

I haven't seen that issue - is it available online? Anyway I would
guess that the same worry about complexity and notation applies. It's
a common question as to whether you should complicate the current
implementation in preparation for possible extensions in the
future. If those extensions never become necessary, you've created a
lot more effort (including implementation, documentation, maintenance,
user confusion, etc.) for no actual benefit.

-- 
Raoul Gough.
export LESS='-X'




From dave at boost-consulting.com  Sat Jan 24 15:16:19 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Sat, 24 Jan 2004 09:16:19 -0500
Subject: [C++-sig] Re: indexing_v2 status update
References:  <401182DE.12359.5C2EA924@localhost>
	
Message-ID: 

Raoul Gough  writes:

> "Niall Douglas"  writes:
>
>> On 23 Jan 2004 at 10:49, Raoul Gough wrote:
>>
>>> 2. What is the likelihood that we would ever need more than 32 (there
>>>    are currently 16)?
>>> 
>>> What I'm thinking is, can we go with the simplest approach that works
>>> now, and switch to a more complex solution if it ever becomes
>>> necessary? Of course, it would be helpful to know what the above code
>>> would look like with a vector_c type solution.
>>
>> Surely you can use long long or __int64 as template parameters?
>
> I guess so - on compilers that support one or the other. long long is
> (still) not part of the C++ standard, AFAIK.
>
>>
>> Also, CUJ had an article about implementing infinite length numbers 
>> at compile time using templates. May be useful here.
>
> I haven't seen that issue - is it available online? Anyway I would
> guess that the same worry about complexity and notation applies. 

It requires a conforming compiler, and provides no more flexibility
than vector_c<...>

Steve Dewhurst was doing it by representing numbers as array types:

  char[two_to_the_0][two_to_the_32][two_to_the_64]...

It's cute, and probably takes fewer compile-time resources, but it's
probably not better.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From s_sourceforge at nedprod.com  Sat Jan 24 15:19:50 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Sat, 24 Jan 2004 14:19:50 -0000
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
Message-ID: <40127F06.27666.57D8B5@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 24 Jan 2004 at 12:24, Raoul Gough wrote:

> > Surely you can use long long or __int64 as template parameters?
> 
> I guess so - on compilers that support one or the other. long long is
> (still) not part of the C++ standard, AFAIK.

If I remember the standard only guarantees some very short recursion 
depths for templates and macros which if observed, parts of Boost 
wouldn't compile.

Also on most 64 bit compilers, long becomes 64 bit. We'll be in 64 
bit land sooner than we might think.

You're dammed if you do and dammed if you don't. My vote is that you 
choose whatever is the simplest, easiest to maintain mechanism with a 
bias towards faster compile times.

> > Also, CUJ had an article about implementing infinite length numbers
> > at compile time using templates. May be useful here.
> 
> I haven't seen that issue - is it available online? Anyway I would
> guess that the same worry about complexity and notation applies. It's
> a common question as to whether you should complicate the current
> implementation in preparation for possible extensions in the future.
> If those extensions never become necessary, you've created a lot more
> effort (including implementation, documentation, maintenance, user
> confusion, etc.) for no actual benefit.

Yes the CUJ article I refer to is online - look in the experts forum. 
I have no income, therefore can't afford anything not free - hence 
the nasty 33k modem connection to the net I must put up with :(

If I understand things correctly, these changes shouldn't affect 
client code ie; how I've used your indexing library won't require 
more than recompiling to use any changed mechanism you decide upon. 
Therefore it's perfectly reasonable to go with the simple method now 
if you maintain the option to enhance the internals later if demand 
requires it.

Put it this way Raoul - you've done a bang up job on that suite, but 
some people would prefer what's done already now and aren't really 
too bothered if it's "perfect" or not, whatever "perfect" might be. 
Think of all the other useful projects you could be engaged upon! :)

Ultimately Dave's the arbiter, if he's happy with long based bitmaps 
then it's cool. Dave's got a high quality threshold so if he okay's 
it, it's good enough.

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQBJ/BsEcvDLFGKbPEQIYCACaA9cJf6p7vyJungnEHqaF9BqyiqQAoKyb
PYI/uomjDFxxytZj5JHwkogo
=ttBd
-----END PGP SIGNATURE-----



From darylew at hotmail.com  Sun Jan 25 01:20:11 2004
From: darylew at hotmail.com (Daryle Walker)
Date: Sat, 24 Jan 2004 19:20:11 -0500
Subject: [C++-sig] indexing_v2 status update
In-Reply-To: <401182DE.12359.5C2EA924@localhost>
Message-ID: 

On 1/23/04 3:23 PM, "Niall Douglas"  wrote:

[SNIP]
> Surely you can use long long or __int64 as template parameters?
[TRUNCATE]

I don't think that's guaranteed to be supported by a compiler.

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com




From jeff.holle at verizon.net  Sun Jan 25 05:22:24 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Sat, 24 Jan 2004 20:22:24 -0800
Subject: [C++-sig] pyste documentation problem
In-Reply-To: 
References: 
Message-ID: <40134480.3050902@verizon.net>

In experimenting with pyste I believe I've run into problem.

I'm working from a recent boost CVS head version.
My pyste reports version 0.9.28.

The "boost/libs/python/pyste/doc/running_pyste.html" states to run pyste
like:               
  python pyste.py --module=mymodule file1.pyste file2.pyste
  python pyste.py --module=mymodule --generate-main file1.pyste file2.pyste

I discovered that I needed to include "--multiple" in both lines to get
the proper behavior.





From surffirst at yahoo.com  Sun Jan 25 09:27:10 2004
From: surffirst at yahoo.com (Leo Yee)
Date: Sun, 25 Jan 2004 16:27:10 +0800
Subject: [C++-sig] class callback
Message-ID: 

Hi,

I am coding c++ object which gives callback functions to python. I
encountered these problem that a c++ object destruction method won't be
called if a python class holds the c++ object that has a callback function
of this python class.

Let's look the code.

using namespace boost::python;

struct cHolder
{
 cHolder() {}
 ~cHolder()
 {
    // we can't reach here
 }

 void SetCallback( const object &o )
 {
  m_o = o;
 }

 void OnCallback(void)
 {
  if( m_o )
   m_o();
 }

 object m_o;
};


BOOST_PYTHON_MODULE( hello )
{
 class_< cHolder >( "cHolder" )
  .def( "SetCallback", cHolder::SetCallback )
  .def( "OnCallback", cHolder::OnCallback );
}


The python code looks like this:

from hello import *


class cA:
 def __init__(self):
  self._holder = cHolder()
  self._holder.SetCallback( self.callback )


 def callback( self ) :
  print 'callback'


a = cA()
a._holder.OnCallback()


I also tried to manuaully use python weakref functions to help me solving
this problem but I found that the weak reference released just as I called
the 'setcallback' function.

The weak reference code looked like this:

struct cHolder
{
 cHolder() { m_weakRef = NULL; }
 ~cHolder()
 {
    Py_XDECREF( m_weakRef );

 }

 void SetCallback( const object &o, const object &free )
 {
  m_weakRef = PyWeakref_NewRef( o.ptr(), free.ptr() );
    // the pyobject was just freed as this function had been finished
  }

 void OnCallback(void)
 {
  if( m_weakRef )
  {
   object o(borrowed(PyWeakref_GetObject( m_weakRef )));
   if( o )
    o();    // We can't reach here because o is always None
  }
 }

 PyObject *m_weakRef;
};


Does anybody know how I can solve this problem?
Thanks in advance.

Leo Yee






From nicodemus at esss.com.br  Sun Jan 25 15:48:09 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Sun, 25 Jan 2004 11:48:09 -0300
Subject: [C++-sig] class callback
In-Reply-To: 
References: 
Message-ID: <4013D729.5050000@esss.com.br>

Leo Yee wrote:

>Hi,
>
>I am coding c++ object which gives callback functions to python. I
>encountered these problem that a c++ object destruction method won't be
>called if a python class holds the c++ object that has a callback function
>of this python class.
>
>Let's look the code.
>
>
>  
>


Perhaps this recipe can help you: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81253

But I don't understand why did you expect the _cHolder object to be 
destroyed, since a reference to it is still held in the a object...

Regards,
Nicodemus.




From aknuds-1 at broadpark.no  Sun Jan 25 19:39:12 2004
From: aknuds-1 at broadpark.no (Arve Knudsen)
Date: Sun, 25 Jan 2004 19:39:12 +0100
Subject: [C++-sig] Manipulating arguments with CallPolicies::precall?
Message-ID: 

Hi

I want to wrap a native C Python object in a C++ object that takes care of 
constructing and destructing it properly (there isn't any way to specify 
custom allocation/deallocation routines are there?). However, I would like 
to send this object directly to the associated routines (its part of an 
existing Python extension). I haven't found any direct support for this 
kind of thing within boost::python, since everything seems strongly tied 
to the contained type (my wrapping C++ class). But, I figured it might be 
possible to manipulate the Python argument tuple within 
CallPolicies::precall?

So I experimented a little and it seems I am able to change the first 
argument to point to the contained C object, instead of it's wrapper. But, 
when the function (which takes a pointer to one such C object) receives 
the object something is not right. A member which was initialized to zero 
(verified within caller.hpp), now contains some other number. I suppose 
some conversion magic goes wrong? I've tried to figure out what's going on 
myself, but gdb tends to die on me in the process (no pun intended). It'd 
be great if someone could enlighten me as to why this won't work (fingers 
crossed), or perhaps present a better solution :)

Btw, I'm getting lots of warnings building boost::python from CVS (this is 
on Linux with GCC 3.3.2 and Python 2.3), because of this: 
/usr/include/python2.3/pyconfig.h:847:1: warning: "_POSIX_C_SOURCE" 
redefined. Is Python 2.3 to blame? I dont think I ever saw this warning 
with boost 1.30.2, though.

Thanks

Arve Knudsen



From joel at boost-consulting.com  Sun Jan 25 19:38:08 2004
From: joel at boost-consulting.com (Joel de Guzman)
Date: Mon, 26 Jan 2004 02:38:08 +0800
Subject: [C++-sig] Re: indexing_v2 status update
In-Reply-To: 
References: 
		
		
		
		
		
		
		<400F165D.4080606@boost-consulting.com>	
		<400FC142.1020001@boost-consulting.com>	
		<40104ACC.5080600@boost-consulting.com>
	
Message-ID: <40140D10.8000808@boost-consulting.com>

Raoul Gough wrote:

> The only worry I see is the notational (or syntax) issue. How easy
> would it be to express the combination of possible values? For
> reference again, here is what it looks like with plain bits:
> 
>     BOOST_STATIC_CONSTANT(
>         unsigned int,
>         supported_methods = (
>               method_len
>             | method_getitem
>             | method_getitem_slice
> 
>             | detail::unsigned_if<
>                   value_traits_type::equality_comparable,
>                     method_index
>                   | method_contains
>                   | method_count
>               >::value
> 
>             // ...
> 
> Which is not really pretty, but I think it is understandable
> enough. Considering the following two questions:
> 
> 1. What are the costs of supporting an effectively unlimited number of
>    flags?
> 
> 2. What is the likelihood that we would ever need more than 32 (there
>    are currently 16)?
> 
> What I'm thinking is, can we go with the simplest approach that works
> now, and switch to a more complex solution if it ever becomes
> necessary? 

I agree.

> Of course, it would be helpful to know what the above code
> would look like with a vector_c type solution.

If I get some time, I'll design and implement the static-bitset
anyway regardless if it will be used or not. Only by then will
I know what the interface will be. It's still rather sketchy at
this point. Anyway, I'll surely need one for Spirit.

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net




From jeff.holle at verizon.net  Mon Jan 26 01:08:01 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Sun, 25 Jan 2004 16:08:01 -0800
Subject: [C++-sig] pyste code problem
Message-ID: <40145A61.308@verizon.net>

I run on linux and use gcc 3.3.
I'm using a recent CVS head of the boost libraries.
My pyste reports version 0.9.28.

The only problem that I had with pyste is that the code it produces 
references local
*.h files like they are system includes.

Prior alternating the python code I had to change includes like 
"#include " to
"#include "a.h".

The coding changes was easy.  The code from Exporter.py, line 53, needs 
to change to:
    def WriteInclude(self, codeunit):
        codeunit.Write('include', '#include "%s"\n' % self.info.include)

Hopefully this change will be made to a future release of this great 
product.
Every thing that I've looked for in this product, I found.  I am impressed!
   




From jeff.holle at verizon.net  Mon Jan 26 21:19:52 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Mon, 26 Jan 2004 12:19:52 -0800
Subject: [C++-sig] vector_indexing_suite issue
Message-ID: <40157668.2020100@verizon.net>

I am successfully using vector_indexing_suite in following code:

   class_ >("vector_B")
       .def(vector_indexing_suite >())
       ;

However, I find that it requires that the B class conforms to the 
Equality Comparable concept where the STL standard only demands it to 
conform to the Assignable concept.

I'm wondering if this is necessary, and if so how the operator== method 
should be coded.
Can it simply always return true or false?
Or compare "this" pointers?






From jeff.holle at verizon.net  Mon Jan 26 21:47:59 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Mon, 26 Jan 2004 12:47:59 -0800
Subject: [C++-sig] will pyste support Class Properties?
Message-ID: <40157CFF.50700@verizon.net>

This is the one major boost.python feature that find missing from pyste 
version 0.9.28.
Will it support it in the future?  Or does it now and it just isn't 
documented?




From joel at boost-consulting.com  Tue Jan 27 01:23:07 2004
From: joel at boost-consulting.com (Joel de Guzman)
Date: Tue, 27 Jan 2004 08:23:07 +0800
Subject: [C++-sig] vector_indexing_suite issue
In-Reply-To: <40157668.2020100@verizon.net>
References: <40157668.2020100@verizon.net>
Message-ID: <4015AF6B.9090107@boost-consulting.com>

Jeff Holle wrote:
> I am successfully using vector_indexing_suite in following code:
> 
>   class_ >("vector_B")
>       .def(vector_indexing_suite >())
>       ;
> 
> However, I find that it requires that the B class conforms to the 
> Equality Comparable concept where the STL standard only demands it to 
> conform to the Assignable concept.
> 
> I'm wondering if this is necessary, and if so how the operator== method 
> should be coded.

The vector_indexing_suite attempts to encompass all Python methods
relevant to container types. See
http://www.python.org/doc/current/ref/sequence-types.html

This includes __contains__(self, item) which, of course, requires
that the container elements be equally comparable.

> Can it simply always return true or false?
> Or compare "this" pointers?

If you are not using the contains method or doing elemnt comparisons,
perhaps you can get by. However, this might cause confusion in the end
when someone does. << Caveat Emptor >>

Anyway, a nice thing about Raoul's new indexing suite is that each of
the methods can be turned on/off individually. This is not possible in
the original insexing_suite.

HTH,
-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net





From dholth at fastmail.fm  Tue Jan 27 04:03:14 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Mon, 26 Jan 2004 22:03:14 -0500
Subject: [C++-sig] boost.python cross compile
Message-ID: <1075172594.4121.27.camel@bluefish>

Hi.

I was wondering if anyone has had success cross-compiling boost.python
for Windows, from linux, using ming.

- Daniel Holth




From jeff.holle at verizon.net  Tue Jan 27 07:51:27 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Mon, 26 Jan 2004 22:51:27 -0800
Subject: [C++-sig] pyste and C++ namespaces
Message-ID: <40160A6F.7010800@verizon.net>

In further pyste experimenting, I put my C++ code in a namespace.

First surprise was that I needed to decorate my class name in the 
*.pyste file with its housed namespace.
Doing this allowed pyste to run successfully, but.

Second surprise that the generated python interface class now contains a 
"wrapper" class.  Is this necessary?  The class is easily accessible by 
opening the namespace, or not, depending on the C++ choice.





From dholth at fastmail.fm  Tue Jan 27 19:06:18 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Tue, 27 Jan 2004 13:06:18 -0500
Subject: [C++-sig] pyste and C++ namespaces
In-Reply-To: <40160A6F.7010800@verizon.net>
References: <40160A6F.7010800@verizon.net>
Message-ID: <1075226777.1263.26.camel@bluefish>

On Tue, 2004-01-27 at 01:51, Jeff Holle wrote:
> In further pyste experimenting, I put my C++ code in a namespace.
> 
> First surprise was that I needed to decorate my class name in the 
> *.pyste file with its housed namespace.
> Doing this allowed pyste to run successfully, but.
> 
> Second surprise that the generated python interface class now contains a 
> "wrapper" class.  Is this necessary?  The class is easily accessible by 
> opening the namespace, or not, depending on the C++ choice.

Could it be that pyste is adding a wrapper so that you can inherit from
your C++ class within python, and the virtual method calls will transfer
appropriately?  There is a final option somewhere that prevents this.

As far as missing features, I thought the most-missing feature was
specifying docstrings in the .pyste.  Here's a patch to add the feature.

This patch allows any keyword arguments to Function() and Class(); if
you add a doc="the documentation" argument, it adds the docstring to the
wrapper.

Unfortunately, Boost.Python functions don't appear to inherit from
Python functions (yet?) so help() only prints class documentation - but
you can type help(yourmodule.functionname) to read your function
documentation.

- dwh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: docstring.patch
Type: text/x-patch
Size: 5109 bytes
Desc: not available
URL: 

From dholth at fastmail.fm  Tue Jan 27 19:49:04 2004
From: dholth at fastmail.fm (Daniel Holth)
Date: Tue, 27 Jan 2004 13:49:04 -0500
Subject: [C++-sig] pyste and C++ namespaces
In-Reply-To: <1075226777.1263.26.camel@bluefish>
References: <40160A6F.7010800@verizon.net> <1075226777.1263.26.camel@bluefish>
Message-ID: <1075229344.3932.7.camel@bluefish>

> This patch allows any keyword arguments to Function() and Class(); if
> you add a doc="the documentation" argument, it adds the docstring to the
> wrapper.

The main downside so far is that if you misspell a keyword argument,
Python will not complain.

Whoops, there should be an additional comma (',') in that docstring
patch.

def escape_docstring(d):
    # crude escaping; we should also escape " and special characters.
    # we could also expose the function's true name etc. with named
    # replacements, %(foo)s and so on.
    doc = ', "' + "\\n".join(d.splitlines()) + '"'
    return doc




From gideon at computer.org  Tue Jan 27 20:09:25 2004
From: gideon at computer.org (Gideon May)
Date: Tue, 27 Jan 2004 20:09:25 +0100
Subject: [C++-sig] Problem with current pyste and inheritance
Message-ID: <25582984.1075234165@localhost>

Hi,

I've got a C++ class hierarchy which looks like this:

Base
  ^
  |
Derived
  ^
  |
Sub

and I want to use pyste to generate python bindings.
I've got it working except for the fact that the bindings
for Derived are being defined twice by pyste.
I've attached the include files and pyste files. I generate
the code with the following command:
  pyste --module=double Base.pyste Derived.pyste Sub.pyste

Any suggestions ?

Thanks,

Gideon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Base.pyste
Type: application/octet-stream
Size: 32 bytes
Desc: not available
URL: 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Derived.pyste
Type: application/octet-stream
Size: 63 bytes
Desc: not available
URL: 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Sub.pyste
Type: application/octet-stream
Size: 54 bytes
Desc: not available
URL: 
-------------- next part --------------

// Boost Includes ==============================================================
#include 
#include 

// Includes ====================================================================
#include 
#include 
#include 

// Using =======================================================================
using namespace boost::python;

// Module ======================================================================
BOOST_PYTHON_MODULE(double)
{
    class_< Base >("Base", init<  >())
        .def(init< const Base& >())
    ;

    class_< Derived >("Derived", init<  >())
        .def(init< const Derived& >())
    ;

    class_< Derived >("Derived", init<  >())
        .def(init< const Derived& >())
    ;

    class_< Sub, bases< Derived >  >("Sub", init<  >())
        .def(init< const Sub& >())
    ;

}

-------------- next part --------------
class Base {
  public:
    Base();
};
-------------- next part --------------
#include "Base.h"

class Derived : Base {
  public:
    Derived();
};
-------------- next part --------------
#include "Derived.h"

class Sub : public Derived {
  public:
    Sub();
};

From jeff.holle at verizon.net  Tue Jan 27 20:58:02 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Tue, 27 Jan 2004 11:58:02 -0800
Subject: [C++-sig] Re: pyste and C++ namespaces]
Message-ID: <4016C2CA.5040702@verizon.net>

I realize presently that I am mistaken about this.
In experimenting with a simple example, namespaces are handle elegantly.
So the generated wrapper class is caused by other things in "real" code, 
which I will endeavor to avoid.

In further pyste experimenting, I put my C++ code in a namespace.

First surprise was that I needed to decorate my class name in the 
*.pyste file with its housed namespace.
Doing this allowed pyste to run successfully, but.

Second surprise that the generated python interface class now contains a 
"wrapper" class.  Is this necessary?  The class is easily accessible by 
opening the namespace, or not, depending on the C++ choice.







From jeff.holle at verizon.net  Tue Jan 27 20:59:41 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Tue, 27 Jan 2004 11:59:41 -0800
Subject: [C++-sig] Re: will pyste support Class Properties?
Message-ID: <4016C32D.3070804@verizon.net>

I see that this feature of boost.python is supportable via the 
module_code directive of pyste.

This is the one major boost.python feature that find missing from pyste 
version 0.9.28.
Will it support it in the future?  Or does it now and it just isn't 
documented?






From nicodemus at esss.com.br  Wed Jan 28 00:08:09 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Tue, 27 Jan 2004 20:08:09 -0300
Subject: [C++-sig] pyste code problem
In-Reply-To: <40145A61.308@verizon.net>
References: <40145A61.308@verizon.net>
Message-ID: <4016EF59.3000009@esss.com.br>

Jeff Holle wrote:

> I run on linux and use gcc 3.3.
> I'm using a recent CVS head of the boost libraries.
> My pyste reports version 0.9.28.
>
> The only problem that I had with pyste is that the code it produces 
> references local
> *.h files like they are system includes.
>
> Prior alternating the python code I had to change includes like 
> "#include " to
> "#include "a.h".
>
> The coding changes was easy.  The code from Exporter.py, line 53, 
> needs to change to:
>    def WriteInclude(self, codeunit):
>        codeunit.Write('include', '#include "%s"\n' % self.info.include)
>

Hi Jeff!

Thanks for the feedback. I didn't know there was a difference between 
#include <> and #include "". Your change thought can break someone 
else's code, so
I believe we should create a new directive, like 
LocalInclude('myheader.h'), which would generate #include "myheader.h".

Unfortunately, I just moved from my apartament, and I will be without 
internet at home for a while 8/
(waiting eagerly for my DSL 8) )

> Hopefully this change will be made to a future release of this great 
> product.
> Every thing that I've looked for in this product, I found.  I am 
> impressed!


Thanks! 8)

Regards,
Nicodemus.




From nicodemus at esss.com.br  Wed Jan 28 00:10:28 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Tue, 27 Jan 2004 20:10:28 -0300
Subject: [C++-sig] Re: pyste and C++ namespaces]
In-Reply-To: <4016C2CA.5040702@verizon.net>
References: <4016C2CA.5040702@verizon.net>
Message-ID: <4016EFE4.706@esss.com.br>

Jeff Holle wrote:

> I realize presently that I am mistaken about this.
> In experimenting with a simple example, namespaces are handle elegantly.
> So the generated wrapper class is caused by other things in "real" 
> code, which I will endeavor to avoid.
>
> In further pyste experimenting, I put my C++ code in a namespace.
>
> First surprise was that I needed to decorate my class name in the 
> *.pyste file with its housed namespace.
> Doing this allowed pyste to run successfully, but.
>
> Second surprise that the generated python interface class now contains 
> a "wrapper" class.  Is this necessary?  The class is easily accessible 
> by opening the namespace, or not, depending on the C++ choice.


Hmm... a Wrapper class is only generated if you have virtual member 
functions in your C++ class. Perhaps if you post some example code me 
and others can help you out? 8)

Regards,
Nicodemus.




From nicodemus at esss.com.br  Wed Jan 28 00:12:33 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Tue, 27 Jan 2004 20:12:33 -0300
Subject: [C++-sig] pyste and C++ namespaces
In-Reply-To: <1075229344.3932.7.camel@bluefish>
References: <40160A6F.7010800@verizon.net> <1075226777.1263.26.camel@bluefish>
	<1075229344.3932.7.camel@bluefish>
Message-ID: <4016F061.1020001@esss.com.br>

Daniel Holth wrote:

>>This patch allows any keyword arguments to Function() and Class(); if
>>you add a doc="the documentation" argument, it adds the docstring to the
>>wrapper.
>>    
>>
>
>The main downside so far is that if you misspell a keyword argument,
>Python will not complain.
>  
>

No problem, that's easy to fix.

>Whoops, there should be an additional comma (',') in that docstring
>patch.
>
>def escape_docstring(d):
>    # crude escaping; we should also escape " and special characters.
>    # we could also expose the function's true name etc. with named
>    # replacements, %(foo)s and so on.
>    doc = ', "' + "\\n".join(d.splitlines()) + '"'
>    return doc
>  
>

Got it! Thanks a lot for this patch: I will implement it in CVS soon!

Regards,
Nicodemus.




From nicodemus at esss.com.br  Wed Jan 28 00:13:45 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Tue, 27 Jan 2004 20:13:45 -0300
Subject: [C++-sig] Problem with current pyste and inheritance
In-Reply-To: <25582984.1075234165@localhost>
References: <25582984.1075234165@localhost>
Message-ID: <4016F0A9.8050105@esss.com.br>

Gideon May wrote:

> Hi,
>
> I've got a C++ class hierarchy which looks like this:
>
> Base
>  ^
>  |
> Derived
>  ^
>  |
> Sub
>
> and I want to use pyste to generate python bindings.
> I've got it working except for the fact that the bindings
> for Derived are being defined twice by pyste.
> I've attached the include files and pyste files. I generate
> the code with the following command:
>  pyste --module=double Base.pyste Derived.pyste Sub.pyste
>
> Any suggestions ?


Hi Gideon,

I don't have time right now to look at this, but seems like a bug. I 
will take a look ASAP. Thanks!

Regards,
Nicodemus.




From nicodemus at esss.com.br  Wed Jan 28 00:16:50 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Tue, 27 Jan 2004 20:16:50 -0300
Subject: [C++-sig] Re: will pyste support Class Properties?
In-Reply-To: <4016C32D.3070804@verizon.net>
References: <4016C32D.3070804@verizon.net>
Message-ID: <4016F162.8000002@esss.com.br>

Jeff Holle wrote:

> I see that this feature of boost.python is supportable via the 
> module_code directive of pyste.
>
> This is the one major boost.python feature that find missing from 
> pyste version 0.9.28.
> Will it support it in the future?  Or does it now and it just isn't 
> documented?


You mean Python's properties or something else? If you mean Python's 
properties, it is quite easy to add one to Pyste, but I really don't 
have time right now to do this, but contributions are appreciated ;) 
(this has low-priority right now).

Regards,
Nicodemus.




From jbrandmeyer at earthlink.net  Wed Jan 28 02:10:19 2004
From: jbrandmeyer at earthlink.net (Jonathan Brandmeyer)
Date: Tue, 27 Jan 2004 20:10:19 -0500
Subject: [C++-sig] Re: New slice implementation
In-Reply-To: 
References: <1073361918.13426.31.camel@illuvatar>
	 <1073518393.1796.15.camel@illuvatar>
	 <1073595081.19758.430.camel@illuvatar>
	 <1073620180.19759.565.camel@illuvatar>
	 <1073665816.19758.775.camel@illuvatar>
	 <65fk1opl.fsf@boost-consulting.com>
	<1073970573.27246.67.camel@illuvatar>
	
	<1074047914.1215.43.camel@illuvatar>
	
	
	<1074473408.8246.3.camel@illuvatar>
	
Message-ID: <1075252218.12314.14.camel@illuvatar>

I apologize for not getting back to you sooner on this.

On Mon, 2004-01-19 at 12:13, David Abrahams wrote:
> Jonathan Brandmeyer  writes:
> 
> > On Wed, 2004-01-14 at 00:02, David Abrahams wrote:
> >> David Abrahams  writes:
> >> 
> >> > BTW, compare this with the HTML source for list.html and you'll see
> >> > one of the main reasons people hate HTML to be edited with WYSIWYG
> >> > tools.  Sticking  tags in a  block is just insane.
> >> 
> >> Not that you're insane; it's your editor ;-)
> >
> > I understand.  Its fixed, I think.
> >
> >> Note also:
> >> 
> >>   slice::get_indicies(RandomAccessIterator const& begin, RandomAccessIterator const& end);
> >> 
> >> Is probably too wide and should be wrapped:
> >> 
> >>   slice::get_indicies(
> >>       RandomAccessIterator const& begin, RandomAccessIterator const& end);
> >
> > Done.
> 
> Much better.  Preformatted text is still too wide in places (including
> the one I pointed at above, sorry).  

Fixed.  Text within 
 blocks is formatted to stay within 80 columns.

> Also, the Throws clause from
> get_indicies leaves out which Python exception is raised.  You should
> use the "raise" term as defined here:
> 
> http://www.boost.org/libs/python/doc/v2/definitions.html#raise

Done.

> So you can avoid writing error_already_set over and over.  You can use
> a hyperlink if you think it's needed for clarity.
> 
> I think with those small changes it will be ready.  Send me your
> sourceforge user id (the textual one) and I'll give you Boost CVS
> access so you can check this in yourself.

My Sourceforge ID is "jbrandmeyer".  There is also (hopefully only) one
remaining detail.  How exactly is the testsuite driven?  Or, phrased
differently, what do I need to do to get the tests to run automatically
when you execute `bjam test`?

Thanks,
Jonathan Brandmeyer




From surffirst at yahoo.com  Wed Jan 28 08:19:04 2004
From: surffirst at yahoo.com (Leo Yee)
Date: Wed, 28 Jan 2004 15:19:04 +0800
Subject: [C++-sig] Re: class callback
References:  <4013D729.5050000@esss.com.br>
Message-ID: 

Hi, Nicodemus,

I missed some code here. What I want is to delete the object that hold the
_cHolder object. I found that I can't delete it since _cHolder object hold a
class method of that object. So I wonder if there is a method to solve this
problem.

I am reading the articel you recommend to me. I think it is helpful.

Thank you.

Leo Yee

"Nicodemus"  ????
news:4013D729.5050000 at esss.com.br...
> Leo Yee wrote:
>
> >Hi,
> >
> >I am coding c++ object which gives callback functions to python. I
> >encountered these problem that a c++ object destruction method won't be
> >called if a python class holds the c++ object that has a callback
function
> >of this python class.
> >
> >Let's look the code.
> >
> >
> >
> >
>
>
> Perhaps this recipe can help you:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81253
>
> But I don't understand why did you expect the _cHolder object to be
> destroyed, since a reference to it is still held in the a object...
>
> Regards,
> Nicodemus.






From james.gunn at communisis-dm.co.uk  Wed Jan 28 16:56:26 2004
From: james.gunn at communisis-dm.co.uk (James Gunn)
Date: Wed, 28 Jan 2004 15:56:26 -0000
Subject: [C++-sig] Catching C++ exceptions in Python
Message-ID: <7A7AACCC920AD511BF510090273C2730022D4F27@CHORPCSRV001>

*** Before acting on this e-mail or opening any attachment you are advised to read the disclaimer at the end of this e-mail ***


Hi,

I've been trying to figure out how I can catch my C++ exceptions in Python.
I started looking at the register_exception_translator template but this
does not
see to do what I need.

Basically if I have a C++ function such as the following:

void OpenFile( std::string const& fileName) 

and this throws one of my C++ exceptions (such as FileException) how can
I catch the FileException in python. I have wrapped the OpenFile function
with
the following:

void Translate( FileException const& e )
{
	PyErr_SetString( PyExc_UserWarning, e.what() );
}

BOOST_PYTHON_MODULE(testmod)
{
	register_exception_translator(&Translate);
	def("openFile", &OpenFile);
}

All I can get with this is the exception error message. I really need to be
able to do
something like the following in Python:

import testmod

try:
	testmod.openFile("non-existent file")
except testmod.FileException:
	# do something here with exception

I am really stuck as to how I can achieve this. Any help or advice will be
appreciated.

Thanks in advance.

James Gunn
Software Developer

Communisis Chorleys Ltd
Computer Bureau
Manston Lane
Crossgates
Leeds
LS15 8AH

Tel: 0113 305 3001
Email: James.Gunn at communisis-dm.co.uk



**********************************************************************
Please note: This e-mail and its attachments contain only the opinions of the sender and do not necessarily reflect the policy(s) of the communisis group in general. 

Employees of the communisis group are required not to make any defamatory statements and not to infringe or authorise any infringement of copyright or any other legal right by e-mail. Any such communication is therefore outside the scope of employment of the individual concerned. The communisis group will not accept any liability in respect of such a communication.

Confidentiality: This e-mail and any attachments, together with their contents, are confidential unless otherwise explicitly stated in writing by the sender of this e-mail and are for the intended recipient only. If they have come to you in error you must not take any action in respect of them, which includes but is not limited to reproducing, sending or storing them, other than to notifying the sender immediately of the mistake, and deleting the e-mail, any attachments and any reproductions made by replying to it.

Viruses: This e-mail and any attachments have been scanned for viruses but we cannot guarantee that they are virus free. The recipient should check this e-mail and any attachments for viruses. The communisis group accepts no responsibility for any damage caused by any virus transmitted by this e-mail or any of its attachments. In the event of any unauthorised copying or forwarding, the recipient will be required to indemnify the communisis group against any claim for loss or damage caused by any viruses or otherwise.
**********************************************************************


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________



From s_sourceforge at nedprod.com  Wed Jan 28 20:15:22 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Wed, 28 Jan 2004 19:15:22 -0000
Subject: [C++-sig] Catching C++ exceptions in Python
In-Reply-To: <7A7AACCC920AD511BF510090273C2730022D4F27@CHORPCSRV001>
Message-ID: <40180A4A.21465.15FFDAD2@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 28 Jan 2004 at 15:56, James Gunn wrote:

> void Translate( FileException const& e )
> {
>  PyErr_SetString( PyExc_UserWarning, e.what() );
> }

You can set any python object as the exception, not just a string. 
This will achieve what you want.

(BTW you can't use BPL based objects as raisable exception types in 
python because they must derive off the python class Exception).

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQBgKS8EcvDLFGKbPEQKyuwCbBdbtmifZCtZNQFZEUhmrYJJtue4Aniun
yT2lORvL8gNrZ5A3/Wk1yeQH
=k4TL
-----END PGP SIGNATURE-----



From jeff.holle at verizon.net  Thu Jan 29 02:33:32 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Wed, 28 Jan 2004 17:33:32 -0800
Subject: [C++-sig] Problems with link stage...
Message-ID: <401862EC.9020204@verizon.net>

trying to build a cpp test client of my python extension shared library, 
which uses boost.python.

I'm using linux with gcc v3.3, python v2.3.2, boost 04/01/26 CVS head.

I've successfully built a boost.python extension module and tested it 
with python.
Now I'm stuck at the link stage of an equivalent C++ client.

The problem is my link is failing with "unresolved references" like:
    PySequence_DelSlice'  
    PyNumber_InPlaceXor'  
    PyNumber_Subtract'    
    PyMem_Malloc'         
    PyComplex_RealAsDouble'
    PyModule_Type'        
    PySequence_DelSlice'  
    PyNumber_InPlaceXor'  
                      
They mostly emulate from the boost_python library.

In investigating what Python 2.3.2 gives to my linux system, I've only 
found that the likely cantigate is libpython2.3.a.
Including this library to my bjam file appears to have no affect.
My current Jamfile is:

    subproject cppTest ;
    import python ;
    exe cppTest
    :  # sources
      cppTest.cpp
    :  # requirements
      ../../../Python-2.3.2/libpython2.3.a
      /usr/local/include/python2.3
      UMLModel .
    :
      release
    ;

Could somebody tell me what I need to do to resolve this problem?

A more general question:
My experience with linux and gcc is much more limited to my windows 
programming background.
In windows, problems like this where the client of a dll gains an 
appetite  for resources used only by the dll points to a problem of the 
client code using something other than an abstract interface from the dll. 

I have modified my shared library to only use abstract interfaces.  Note 
this involves a simple class factory.  This procedure has not altered 
the linking problems that I have.

Does linux share this problem with windows, MSVC 6.0 sp5?






From jeff.holle at verizon.net  Thu Jan 29 07:11:36 2004
From: jeff.holle at verizon.net (Jeff Holle)
Date: Wed, 28 Jan 2004 22:11:36 -0800
Subject: [C++-sig] Problems with link stage...  (Number 2)
Message-ID: <4018A418.5080307@verizon.net>

trying to build a cpp test client of my python extension shared library, 
which uses boost.python.

I'm using linux with gcc v3.3, python v2.3.2, boost 04/01/26 CVS head.

I've successfully built a boost.python extension module and tested it 
with python.
Now I'm stuck at the link stage of an equivalent C++ client.

The problem is my link is failing with "unresolved references" like:
   PySequence_DelSlice'  
   PyNumber_InPlaceXor'  
   PyNumber_Subtract'    
   PyMem_Malloc'         
   PyComplex_RealAsDouble'
   PyModule_Type'        
   PySequence_DelSlice'  
   PyNumber_InPlaceXor'  
                     
They mostly emulate from the boost_python library.

In investigating what Python 2.3.2 gives to my linux system, I've only 
found that the likely cantigate is libpython2.3.a.
Including this library to my bjam file appears to have no affect.
My current Jamfile is:

   subproject cppTest ;
   import python ;
   exe cppTest
   :  # sources
     cppTest.cpp
   :  # requirements
     ../../../Python-2.3.2/libpython2.3.a
     /usr/local/include/python2.3
     UMLModel .
   :
     release
   ;

A more general question:
My experience with linux and gcc is much more limited to my windows 
programming background.
In windows, problems like this where the client of a dll gains an 
appetite  for resources used only by the dll points to a problem of the 
client code using something other than an abstract interface from the dll. 

I have modified my shared library to only use abstract interfaces.  Note 
this involves a simple class factory.  This procedure has not altered 
the linking problems that I have.

Does linux share this problem with windows, MSVC 6.0 sp5?



Second part:

I've got more information about my problem via experimentation.
First, I cleaned up my Jamfile to:
subproject cppTest ;
import python ;

exe cppTest
:  # sources
  cppTest.cpp
:  # requirements
  python2.3
  UMLModel .
:
  release
  ;

In doing "bjam -a -n", I can see that both "-lpython2.3" and 
"-lUMLModel" are properly feed to the linker.

I get the same 130 link errors has above with python2.3, but when I try 
python2.2 it is reduced to a single link error, concerning 
"PyCFunction_NewEx".  Info found on the web about this is that it was 
changed from a function to a macro at some time in the past.

Also, I installed python 2.3.3 and rebuilt everything.  Nothing changed.

Last, I find that both python 2.3.2 and python 2.3.3 builds did not 
produce a shared library equivalent to libpython2.3.a.  Maybe this is a 
problem?





From nbecker at hns.com  Thu Jan 29 17:33:58 2004
From: nbecker at hns.com (Neal D. Becker)
Date: Thu, 29 Jan 2004 11:33:58 -0500
Subject: [C++-sig] iterator interface question
Message-ID: 

How to I interface algorithms with STL style iterator interface to python?


For example:

typedef std::complex Complex;
//expose std::vector to python:

//also let's pick a simple example function:

inline Complex Sum (const std::vector::iterator& beg, const std::vector::iterator& end) {
  Complex sum = 0;
  return std::accumulate (beg, end, sum);
}

BOOST_PYTHON_MODULE(Test)
{    
    class_ > >("CVec")
      .def(init())
      .def(vector_indexing_suite >, true >())
    ;

    def ("accumulate", Sum);
}

Actually 2 questions:

1) How do I call accumulate from python?

2) (really a c++ question) How can I avoid introducing the "Sum" function?  If I put

def ("accumulate", std::accumulate::iterator&,  Complex>)

I get
Test.cc:115: error: no matching function for call to `def(const char[11], 
   )'

Problem is it's overloaded, I guess, but I don't know what to do.





From aashish at vrac.iastate.edu  Fri Jan 30 04:51:26 2004
From: aashish at vrac.iastate.edu (aashish)
Date: Thu, 29 Jan 2004 21:51:26 -0600
Subject: [C++-sig] Re: shared_ptr 
In-Reply-To: <40160A6F.7010800@verizon.net>
Message-ID: <200401300352.i0U3qc3N3100719@vracs001.vrac.iastate.edu>

Hi, 

I am using shared_ptr and what I am doing is getting the "dictionary" for
the python side and storing pointers to that in  boost::shared_ptr which
pointes toward the C++ STL maps.. 

typedef std::map< std::string, std::vector > ValueMap;
	
typedef boost::shared_ptr ValueMapPtr;

Now what I wanted to do is ,  through this pointer I need to access the
elements of this map and for that I am doing something like this ...

ValueMapItr itr;
ValueMapPtr mValueMap;



itr = mValueMap->begin();


for (itr = mValueMap->begin(); itr != mValueMap->end(); ++itr)
{
	......
}


Now this is compiling  fine but when I tried to run the application I got
this error ...


> Debug error

Assertion failed: px! =0 file C:\.................boost\shared_ptr.hpp line
238 




I will appreciate if someone can help me on this issue ( this is very urgent
for my application)

Thanks. 

~aashish








From fabrizio.duhem at free.fr  Thu Jan 29 22:52:30 2004
From: fabrizio.duhem at free.fr (Fabrizio)
Date: Thu, 29 Jan 2004 22:52:30 +0100
Subject: [C++-sig] call python method from C++
Message-ID: 


sorry for my english

i want to call python method in my C++ code

D:\test\boost_python\Release>python test.py
Traceback (most recent call last):
  File "test.py", line 27, in ?
    eriser.Update(a)
TypeError: Update() takes exactly 2 arguments (1 given)



C++ code

class IRenderable
{
public:
 virtual   ~IRenderable() {}
 virtual void Init()    {}
 virtual void Render()   {}
 virtual void Update(float dt) {}
};


class IRenderableWrapper : public IRenderable
{
public:
 PyObject* self;

 IRenderableWrapper(PyObject* self_) : self(self_) {}

 void Init()
 {
  return boost::python::call_method(self, "Init");
 }

 void DefaultInit()
 {
  return IRenderable::Init();
 }

 void Render()
 {
  return boost::python::call_method(self, "Render");
 }

 void DefaultRender()
 {
  return IRenderable::Render();
 }

 void Update(float dt)
 {
  return boost::python::call_method(self, "Update");
 }

 void DefaultUpdate(float dt)
 {
  return IRenderable::Update(dt);
 }
};


void CallUpdate(IRenderable& i)
{
 i.Update(2.3f);
}


BOOST_PYTHON_MODULE(eriser)
{

 class_("IRenderable")
     .def("Init", &IRenderable::Init, &IRenderableWrapper::DefaultInit)
  .def("Update", &IRenderable::Update, &IRenderableWrapper::DefaultUpdate)
  .def("Render", &IRenderable::Render, &IRenderableWrapper::DefaultRender)
   ;

 def("Update", CallUpdate);

}


python script

class Scene(eriser.IRenderable):

 def Init(self):
  print "pass";

 def Update(self, dt):
  print dt


a = Scene()

eriser.Update(a)


Thanks in advance.

fabrizio





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.573 / Virus Database: 363 - Release Date: 28/01/2004








From dave at boost-consulting.com  Fri Jan 30 16:39:05 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 10:39:05 -0500
Subject: [C++-sig] Re: call python method from C++
References: 
Message-ID: 

"Fabrizio"  writes:

> D:\test\boost_python\Release>python test.py
> Traceback (most recent call last):
>   File "test.py", line 27, in ?
>     eriser.Update(a)
> TypeError: Update() takes exactly 2 arguments (1 given)
>
>
>
> C++ code
>
> class IRenderable
> {
> public:
>  virtual   ~IRenderable() {}
>  virtual void Init()    {}
>  virtual void Render()   {}
>  virtual void Update(float dt) {}
> };
>
>
> class IRenderableWrapper : public IRenderable
> {
> public:
>  PyObject* self;
>
>  IRenderableWrapper(PyObject* self_) : self(self_) {}
>
>  void Init()
>  {
>   return boost::python::call_method(self, "Init");
>  }
>
>  void DefaultInit()
>  {
>   return IRenderable::Init();
>  }
>
>  void Render()
>  {
>   return boost::python::call_method(self, "Render");
>  }
>
>  void DefaultRender()
>  {
>   return IRenderable::Render();
>  }
>
>  void Update(float dt)
>  {
>   return boost::python::call_method(self, "Update");
----------------------------------------------------------^
Your problem is right here

You need to pass dt to the Update method.

HTH,
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Fri Jan 30 16:48:27 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 10:48:27 -0500
Subject: [C++-sig] Re: Problems with link stage...  (Number 2)
References: <4018A418.5080307@verizon.net>
Message-ID: 

Jeff Holle  writes:

> trying to build a cpp test client of my python extension shared
> library, which uses boost.python.
>
> I'm using linux with gcc v3.3, python v2.3.2, boost 04/01/26 CVS head.
>
> I've successfully built a boost.python extension module and tested it
> with python.
> Now I'm stuck at the link stage of an equivalent C++ client.
>
> The problem is my link is failing with "unresolved references" like:
>    PySequence_DelSlice'   PyNumber_InPlaceXor'   PyNumber_Subtract'
>    PyMem_Malloc'          PyComplex_RealAsDouble'
>    PyModule_Type'         PySequence_DelSlice'   PyNumber_InPlaceXor'
>    They mostly emulate from the boost_python library.
>
> In investigating what Python 2.3.2 gives to my linux system, I've only
> found that the likely cantigate is libpython2.3.a.
> Including this library to my bjam file appears to have no affect.
> My current Jamfile is:
>
>    subproject cppTest ;
>    import python ;
>    exe cppTest
>    :  # sources
>      cppTest.cpp
>    :  # requirements
>      ../../../Python-2.3.2/libpython2.3.a
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Won't work for various reasons.

>      /usr/local/include/python2.3
>      UMLModel .
>    :
>      release
>    ;

To build a Python embedding application with Boost.Python, add:

   @boost/libs/python/build/boost_python

to your sources, and:

      $(PYTHON_PROPERTIES)
        BOOST_PYTHON_STATIC_LIB
        BOOST_PYTHON_STATIC_MODULE
        $(PYTHON_LIB_PATH)
          <$(gcc-compilers)>$(CYGWIN_PYTHON_DEBUG_DLL_PATH)
            <$(gcc-compilers)><*>$(CYGWIN_PYTHON_DLL_PATH)
              $(PYTHON_EMBEDDED_LIBRARY)

to your requirements.  Should be easier, I know :(.

You can see a working example in libs/python/test/Jamfile

> A more general question:
> My experience with linux and gcc is much more limited to my windows
> programming background.
> In windows, problems like this where the client of a dll gains an
> appetite  for resources used only by the dll points to a problem of
> the client code using something other than an abstract interface from
> the dll. 
>
> I have modified my shared library to only use abstract interfaces.
> Note this involves a simple class factory.  This procedure has not
> altered the linking problems that I have.
>
> Does linux share this problem with windows, MSVC 6.0 sp5?

Shared libraries on Linux are different, but I've got no time to do a
complete explanation now.  I'm really Sorry!  The info is out there.

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Fri Jan 30 16:42:00 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 10:42:00 -0500
Subject: [C++-sig] Re: iterator interface question
References: 
Message-ID: 

"Neal D. Becker"  writes:

> How to I interface algorithms with STL style iterator interface to python?
>
>
> For example:
>
> typedef std::complex Complex;
> //expose std::vector to python:
>
> //also let's pick a simple example function:
>
> inline Complex Sum (const std::vector::iterator& beg, const std::vector::iterator& end) {
>   Complex sum = 0;
>   return std::accumulate (beg, end, sum);
> }
>
> BOOST_PYTHON_MODULE(Test)
> {    
>     class_ > >("CVec")
>       .def(init())
>       .def(vector_indexing_suite >, true >())
>     ;
>
>     def ("accumulate", Sum);
> }
>
> Actually 2 questions:
>
> 1) How do I call accumulate from python?

Depends what you want to pass to it.  In other words, how would you
*like* to call accumulate from Python?  ;-)

> 2) (really a c++ question) How can I avoid introducing the "Sum" function?  If I put
>
> def ("accumulate", std::accumulate::iterator&,  Complex>)
>
> I get
> Test.cc:115: error: no matching function for call to `def(const char[11], 
>    )'

That's a compiler bug probably, but nonetheless you're not allowed to
take the address of a function in the standard library, so answer:
"you can't"

> Problem is it's overloaded, I guess, but I don't know what to do.

Between the allowed overloading and extra default arguments,
forwarding is the only way.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From nbecker at hns.com  Fri Jan 30 16:59:24 2004
From: nbecker at hns.com (Neal D. Becker)
Date: Fri, 30 Jan 2004 10:59:24 -0500
Subject: [C++-sig] Re: iterator interface question
References:  
Message-ID: 

My question is really generic.  I have lots of C++ algorithms written in STL
style.  They pass containers as pairs of iterators.

Consider the generic algorithm X:

template
void X (in_t in, in_t inend, out_t out);

Now I have exposed std::vector (for example) to python, so python
can create a std::vector like:

x = DVec (10)

But what I want to know, how can python call algorithm X, which expects a
pair of iterators?

Since STL became widely used, it is increasingly common to write algorithms
in this style, so I hope there is a way to do this.






From fabrizio.duhem at free.fr  Fri Jan 30 17:10:20 2004
From: fabrizio.duhem at free.fr (Fabrizio)
Date: Fri, 30 Jan 2004 17:10:20 +0100
Subject: [C++-sig] Re: call python method from C++
References:  
Message-ID: 


thanx you :-)


"David Abrahams"  a ?crit dans le message de
news: ufzdx78fa.fsf at boost-consulting.com...
> "Fabrizio"  writes:
>
> > D:\test\boost_python\Release>python test.py
> > Traceback (most recent call last):
> >   File "test.py", line 27, in ?
> >     eriser.Update(a)
> > TypeError: Update() takes exactly 2 arguments (1 given)
> >
> >
> >
> > C++ code
> >
> > class IRenderable
> > {
> > public:
> >  virtual   ~IRenderable() {}
> >  virtual void Init()    {}
> >  virtual void Render()   {}
> >  virtual void Update(float dt) {}
> > };
> >
> >
> > class IRenderableWrapper : public IRenderable
> > {
> > public:
> >  PyObject* self;
> >
> >  IRenderableWrapper(PyObject* self_) : self(self_) {}
> >
> >  void Init()
> >  {
> >   return boost::python::call_method(self, "Init");
> >  }
> >
> >  void DefaultInit()
> >  {
> >   return IRenderable::Init();
> >  }
> >
> >  void Render()
> >  {
> >   return boost::python::call_method(self, "Render");
> >  }
> >
> >  void DefaultRender()
> >  {
> >   return IRenderable::Render();
> >  }
> >
> >  void Update(float dt)
> >  {
> >   return boost::python::call_method(self, "Update");
> ----------------------------------------------------------^
> Your problem is right here
>
> You need to pass dt to the Update method.
>
> HTH,
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.573 / Virus Database: 363 - Release Date: 28/01/2004






From steam at nurfuerspam.de  Fri Jan 30 17:11:50 2004
From: steam at nurfuerspam.de (Hanz Meizer)
Date: Fri, 30 Jan 2004 17:11:50 +0100
Subject: [C++-sig] pyste && private copy constructor question.
Message-ID: 

Hi,

I'm trying to make the classes of an existing c++-project accessible to 
python via the means of python. Unfortunately, there is a class that has 
an interface like this:

...
protected:
   Bla(const std::string&, int);

private:
   Bla();
   Bla(const Element&);
...


I get the following error:

..
Bla.h:94: `
    Blub::Bla(const Blub::Bla&)' is private
...

My question is: How can I modify my pyste input file to work around this 
problem? I figure that it's related to the fact that the copy 
constructor is private. Unfortunately, I can't find any reasonable pyste 
tutorial that covers more sophisticated topics and examples.

Any help, links, pointers etc. welcome.

--tt.

P.S.: Unfortunately, modifying the C++ Headers is not an option :-|




From dave at boost-consulting.com  Fri Jan 30 18:28:13 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 12:28:13 -0500
Subject: [C++-sig] Re: iterator interface question
References:  
	
Message-ID: 

"Neal D. Becker"  writes:

> My question is really generic.  I have lots of C++ algorithms written in STL
> style.  They pass containers as pairs of iterators.
>
> Consider the generic algorithm X:
>
> template
> void X (in_t in, in_t inend, out_t out);
>
> Now I have exposed std::vector (for example) to python, so python
> can create a std::vector like:
>
> x = DVec (10)
>
> But what I want to know, how can python call algorithm X, which expects a
> pair of iterators?
>
> Since STL became widely used, it is increasingly common to write algorithms
> in this style, so I hope there is a way to do this.

Again, what do you want to be able to pass to the algorithm?

e.g., any Python sequence, just a vector, a Python iterator,
etc.

There's no one accepted idiom for this across the Python/C++ boundary.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From fabrizio.duhem at free.fr  Fri Jan 30 17:11:19 2004
From: fabrizio.duhem at free.fr (Fabrizio)
Date: Fri, 30 Jan 2004 17:11:19 +0100
Subject: [C++-sig] Re: call python method from C++
References:  
Message-ID: 


thanx you :-)


"David Abrahams"  a ?crit dans le message de
news: ufzdx78fa.fsf at boost-consulting.com...
> "Fabrizio"  writes:
>
> > D:\test\boost_python\Release>python test.py
> > Traceback (most recent call last):
> >   File "test.py", line 27, in ?
> >     eriser.Update(a)
> > TypeError: Update() takes exactly 2 arguments (1 given)
> >
> >
> >
> > C++ code
> >
> > class IRenderable
> > {
> > public:
> >  virtual   ~IRenderable() {}
> >  virtual void Init()    {}
> >  virtual void Render()   {}
> >  virtual void Update(float dt) {}
> > };
> >
> >
> > class IRenderableWrapper : public IRenderable
> > {
> > public:
> >  PyObject* self;
> >
> >  IRenderableWrapper(PyObject* self_) : self(self_) {}
> >
> >  void Init()
> >  {
> >   return boost::python::call_method(self, "Init");
> >  }
> >
> >  void DefaultInit()
> >  {
> >   return IRenderable::Init();
> >  }
> >
> >  void Render()
> >  {
> >   return boost::python::call_method(self, "Render");
> >  }
> >
> >  void DefaultRender()
> >  {
> >   return IRenderable::Render();
> >  }
> >
> >  void Update(float dt)
> >  {
> >   return boost::python::call_method(self, "Update");
> ----------------------------------------------------------^
> Your problem is right here
>
> You need to pass dt to the Update method.
>
> HTH,
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.573 / Virus Database: 363 - Release Date: 28/01/2004







From RaoulGough at yahoo.co.uk  Fri Jan 30 18:03:49 2004
From: RaoulGough at yahoo.co.uk (Raoul Gough)
Date: Fri, 30 Jan 2004 17:03:49 +0000
Subject: [C++-sig] Re: iterator interface question
References:  
	
Message-ID: 

"Neal D. Becker"  writes:

> My question is really generic.  I have lots of C++ algorithms written in STL
> style.  They pass containers as pairs of iterators.
>
> Consider the generic algorithm X:
>
> template
> void X (in_t in, in_t inend, out_t out);
>
> Now I have exposed std::vector (for example) to python, so python
> can create a std::vector like:
>
> x = DVec (10)
>
> But what I want to know, how can python call algorithm X, which expects a
> pair of iterators?
>
> Since STL became widely used, it is increasingly common to write algorithms
> in this style, so I hope there is a way to do this.

Well, you've got two problems as I see it. Firstly, how to get the
address of a function template instance, and secondly, how to pass an
iterator between Python and C++.

If I understand Dave's post in this thread, he says you can't take the
address of a function in the standard library. AFAIK, this is not
really a problem in practice. The potential problems are just the
usual overload resolution/template argument specification. If you have
overloaded functions, you need to cast the function to the correct
type:

e.g. def (static_cast(overloaded_function));

This looks worse for member functions. For function templates, you
have to select a particular instance of the template, e.g.

def (X::iterator, some_type>);

This is tedious since it doesn't have automatic template argument
deduction.

The second problem of passing iterators to/from Python is just a
question of deciding how to pass them around. For instance, you might
be able to expose them like any other types:

class_::iterator ...

so that you can pass them around. However, I forsee problems with
std::vector if your standard library uses pointers for iterators
here. Probably a better solution would be to write a simple
iterator_range wrapper that contains two C++ iterators, expose that to
Python and use simple forwarding functions for your algorithms.

-- 
Raoul Gough.
export LESS='-X'




From nbecker at hns.com  Fri Jan 30 18:53:36 2004
From: nbecker at hns.com (Neal D. Becker)
Date: Fri, 30 Jan 2004 12:53:36 -0500
Subject: [C++-sig] Re: iterator interface question
References:  
	 
Message-ID: 

David Abrahams wrote:

> "Neal D. Becker"  writes:
> 
>> My question is really generic.  I have lots of C++ algorithms written in
>> STL
>> style.  They pass containers as pairs of iterators.
>>
>> Consider the generic algorithm X:
>>
>> template
>> void X (in_t in, in_t inend, out_t out);
>>
>> Now I have exposed std::vector (for example) to python, so python
>> can create a std::vector like:
>>
>> x = DVec (10)
>>
>> But what I want to know, how can python call algorithm X, which expects a
>> pair of iterators?
>>
>> Since STL became widely used, it is increasingly common to write
>> algorithms in this style, so I hope there is a way to do this.
> 
> Again, what do you want to be able to pass to the algorithm?
> 
> e.g., any Python sequence, just a vector, a Python iterator,
> etc.
> 
> There's no one accepted idiom for this across the Python/C++ boundary.
> 

Oh, OK.

At minimum, I want to pass vector,  maybe like this:


x = DVec (10)
y = CppAlg (x.begin(), x.end())

To be really useful, it would be nice to be able to do more.
Hopefully, python would be able to modify the iterators being passed, so
something equivalent to :

x = DVec(10)
y = CppAlg (x.begin()+1, x.end())

would be possible.  Or perhaps:

y = CppAlg (make_strided_iterator (x.begin(), 2), make_strided_iterator
(x.end(), 2))

would be possible, although I have no idea how this would work.






From nbecker at hns.com  Fri Jan 30 19:57:38 2004
From: nbecker at hns.com (Neal D. Becker)
Date: Fri, 30 Jan 2004 13:57:38 -0500
Subject: [C++-sig] Re: iterator interface question (progress!)
References:  
	 
	
Message-ID: 

I have made some progress, I am really impressed with boost python capabilities!

  typedef std::vector::iterator vd_it;

  class_("DVecIter")
    ;

  class_ >("DVec")
    .def(init())
    .def(vector_indexing_suite >())
    .def("begin", (vd_it (std::vector::*)())(&std::vector::begin))
    .def("end", (vd_it (std::vector::*)())(&std::vector::end))
    ;

  typedef std::vector::iterator vc_it;

  class_("CVecIter")
    ;

  class_ >("CVec")
    .def(init())
    .def(vector_indexing_suite, true >())
    .def("begin", (vc_it (std::vector::*)())(&std::vector::begin))
    .def("end", (vc_it (std::vector::*)())(&std::vector::end))
    ;
    [...]

Just with this, my main goal is accomplished:

>>> from Test import *
>>> a = DVec (2)

>>> for x in range (0, len (a)): a[x] = x
>>> PrintV (a.begin(), a.end())
0
1
(where PrintV is a C++ function taking a pair of std::vector iterators)

Now to see if I can teach python more tricks to do with DVecIter (e.g., arithmetic)





From stefan.seefeld at orthosoft.ca  Fri Jan 30 19:59:13 2004
From: stefan.seefeld at orthosoft.ca (Stefan Seefeld)
Date: Fri, 30 Jan 2004 13:59:13 -0500
Subject: [C++-sig] replacing object constructors by factories
Message-ID: <10217cd7eb3c189a4a1b11add3471d73401aa7b9@Orthosoft.ca>

hi there,

I'm exposing classes to python which are not directly
instantiable via constructors, but via factories.

However, I'd like to be able to instantiate class 'Foo'
by

foo = Foo()


nonetheless, I'v managed to do that by defining 'Foo'
as a global Function returning a 'Foo' instance.
But as soon as that is done, python obviously reports
'Foo' as a function, not a 'class'.

Are there other ways provide 'user hooks' as constructors ?

Thanks,
		Stefan




From nbecker at hns.com  Fri Jan 30 21:31:58 2004
From: nbecker at hns.com (Neal D. Becker)
Date: Fri, 30 Jan 2004 15:31:58 -0500
Subject: [C++-sig] More std::vector, this time with pyste
Message-ID: 

I'm trying out pyste to see whether it is useful for exporting std::vector. 
I get an error, which I don't know how to resolve.

Test2.pyste----------------------
P = Template ("std::vector", "Test2.H")
exclude (P.at)
exclude (P.front)
exclude (P.back)
exclude (P.assign)
P("double")

Test2.H------------------
#include 

/usr/bin/pyste.py --module=Test2 Test2.pyste
Module Test2 generated
1.94 seconds

g++ -shared -I /usr/include/python2.3 -I /usr/local/src/boost_1_31_0_rc2
-I ./ -L /usr/local/src/boost_1_31_0_rc2/stage/lib/ -lboost_python-gcc
Test2.cpp -Wl,-rpath -Wl,/usr/local/src/boost_1_31_0_rc2/stage/lib -lfftw
-o Test2.so
In file included from /usr/include/python2.3/Python.h:8,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/detail/wrap_python.hpp:121,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/detail/prefix.hpp:13,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/args.hpp:9,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python.hpp:12,
                 from Test2.cpp:3:
/usr/include/python2.3/pyconfig.h:847:1: warning: "_POSIX_C_SOURCE"
redefined
In file included from /usr/include/limits.h:26,
                 from /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/include/limits.h:122,
                 from /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/include/syslimits.h:7,
                 from /usr/lib/gcc-lib/i386-redhat-linux/3.3.2/include/limits.h:11,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/detail/wrap_python.hpp:27,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/detail/prefix.hpp:13,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python/args.hpp:9,
                 from /usr/local/src/boost_1_31_0_rc2/boost/python.hpp:12,
                 from Test2.cpp:3:
/usr/include/features.h:131:1: warning: this is the location of the previous
definition
/usr/local/src/boost_1_31_0_rc2/boost/python/object/inheritance.hpp: In
static 
   member function `static void* 
   boost::python::objects::implicit_cast_generator::execute(void*) [with Source = std::vector >, Target = std::_Vector_alloc_base, true>]':
/usr/local/src/boost_1_31_0_rc2/boost/python/object/inheritance.hpp:123:  
instantiated from `void boost::python::objects::register_conversion(bool,
Source*, Target*) [with Source = std::vector
>, Target = std::_Vector_alloc_base, true>]'
/usr/local/src/boost_1_31_0_rc2/boost/python/object/class_converters.hpp:61:  
instantiated from `void
boost::python::objects::register_base_of::operator()(Base*) const
[with Base = std::_Vector_alloc_base, true>,
Derived = std::vector >]'
/usr/local/src/boost_1_31_0_rc2/boost/mpl/for_each.hpp:76:   instantiated
from `static void boost::mpl::aux::for_each_impl::execute(Iterator*,
LastIterator*, TransformFunc*, F) [with Iterator =
boost::mpl::vector_iterator, true> >, boost::mpl::integral_c >,
LastIterator =
boost::mpl::vector_iterator, true> >, boost::mpl::integral_c >,
TransformFunc =
boost::mpl::protect, boost::mpl::arg<-1> > >, F =
boost::python::objects::register_base_of > >]'
/usr/local/src/boost_1_31_0_rc2/boost/mpl/for_each.hpp:100:   instantiated
from `void boost::mpl::for_each(F, Sequence*, TransformOp*) [with Sequence
= boost::python::bases, true>, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, TransformOp =
boost::add_pointer, F =
boost::python::objects::register_base_of > >]'
/usr/local/src/boost_1_31_0_rc2/boost/python/object/class_converters.hpp:88:  
instantiated from `void
boost::python::objects::register_class_from_python(Derived*, Bases*) [with
Derived = std::vector >, Bases =
boost::python::bases, true>, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>]'
/usr/local/src/boost_1_31_0_rc2/boost/python/class.hpp:626:   instantiated
from `void boost::python::class_::register_() const [with T
= std::vector >, X1 =
boost::python::bases, true>, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 =
boost::python::detail::not_specified, X3 =
boost::python::detail::not_specified]'
/usr/local/src/boost_1_31_0_rc2/boost/python/class.hpp:640:   instantiated
from `void boost::python::class_::register_holder() [with T
= std::vector >, X1 =
boost::python::bases, true>, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 =
boost::python::detail::not_specified, X3 =
boost::python::detail::not_specified]'
/usr/local/src/boost_1_31_0_rc2/boost/python/class.hpp:275:   instantiated
from `boost::python::class_::class_(const char*, const
boost::python::init_base&) [with DerivedT =
boost::python::init&,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_>, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_>, T = std::vector >, X1 =
boost::python::bases, true>, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 =
boost::python::detail::not_specified, X3 =
boost::python::detail::not_specified]'
Test2.cpp:15:   instantiated from here
/usr/local/src/boost_1_31_0_rc2/boost/python/object/inheritance.hpp:100:
error: `
   std::_Vector_alloc_base, true>' is an 
   inaccessible base of `std::vector >'

I guess I need to convince pyste not to put std::_Vector_alloc_base, true> in bases?
No idea how.





From dave at boost-consulting.com  Fri Jan 30 23:06:01 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 17:06:01 -0500
Subject: [C++-sig] Re: iterator interface question
References:  
	 
Message-ID: 

Raoul Gough  writes:

> so that you can pass them around. However, I forsee problems with
> std::vector if your standard library uses pointers for iterators
> here. Probably a better solution would be to write a simple
> iterator_range wrapper that contains two C++ iterators, expose that to
> Python...

That's what Boost.Python's iterator<> and range components do.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Fri Jan 30 23:08:43 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 17:08:43 -0500
Subject: [C++-sig] Re: iterator interface question (progress!)
References:  
	 
	 
Message-ID: 

"Neal D. Becker"  writes:

> I have made some progress, I am really impressed with boost python capabilities!
>
>   typedef std::vector::iterator vd_it;
>
>   class_("DVecIter")
>     ;
>
>   class_ >("DVec")
>     .def(init())
>     .def(vector_indexing_suite >())
>     .def("begin", (vd_it (std::vector::*)())(&std::vector::begin))
>     .def("end", (vd_it (std::vector::*)())(&std::vector::end))
>     ;
>
>   typedef std::vector::iterator vc_it;
>
>   class_("CVecIter")
>     ;
>
>   class_ >("CVec")
>     .def(init())
>     .def(vector_indexing_suite, true >())
>     .def("begin", (vc_it (std::vector::*)())(&std::vector::begin))
>     .def("end", (vc_it (std::vector::*)())(&std::vector::end))
>     ;
>     [...]
>
> Just with this, my main goal is accomplished:
>
>>>> from Test import *
>>>> a = DVec (2)
>
>>>> for x in range (0, len (a)): a[x] = x
>>>> PrintV (a.begin(), a.end())
> 0
> 1

Better make begin and end functions use return_internal_reference, so
the iterators won't outlive the container.  UNfortunately, they're
still not safe since they can still run off the end of the vector or
become invalidated.  These are the sorts of issues that the indexing
suites should handle.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From dave at boost-consulting.com  Fri Jan 30 23:19:16 2004
From: dave at boost-consulting.com (David Abrahams)
Date: Fri, 30 Jan 2004 17:19:16 -0500
Subject: [C++-sig] Re: replacing object constructors by factories
References: <10217cd7eb3c189a4a1b11add3471d73401aa7b9@Orthosoft.ca>
Message-ID: 

Stefan Seefeld  writes:

> hi there,
>
> I'm exposing classes to python which are not directly
> instantiable via constructors, but via factories.
>
> However, I'd like to be able to instantiate class 'Foo'
> by
>
> foo = Foo()
>
>
> nonetheless, I'v managed to do that by defining 'Foo'
> as a global Function returning a 'Foo' instance.
> But as soon as that is done, python obviously reports
> 'Foo' as a function, not a 'class'.
>
> Are there other ways provide 'user hooks' as constructors ?

See http://www.boost-consulting.com/boost/libs/python/doc/v2/make_function.html#make_constructor-spec

I know that isn't very clear, but along with 
http://www.boost-consulting.com/boost/libs/python/test/injected.cpp
it should get you there.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




From s_sourceforge at nedprod.com  Fri Jan 30 22:00:39 2004
From: s_sourceforge at nedprod.com (Niall Douglas)
Date: Fri, 30 Jan 2004 21:00:39 -0000
Subject: [C++-sig] More std::vector, this time with pyste
In-Reply-To: 
Message-ID: <401AC5F7.32208.20ACF821@localhost>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 30 Jan 2004 at 15:31, Neal D. Becker wrote:

> I'm trying out pyste to see whether it is useful for exporting
> std::vector. I get an error, which I don't know how to resolve.

pyste won't do this, nor should it. Find the indexing suite v2 (it's 
probably still in CVS) and it doesn this in a cinch.

To list: Didn't I add a FAQ about this topic?

Cheers,
Niall





-----BEGIN PGP SIGNATURE-----
Version: idw's PGP-Frontend 4.9.6.1 / 9-2003 + PGP 8.0.2

iQA/AwUBQBrF+sEcvDLFGKbPEQKvbwCeMWNzJdlyjLu9ZZx5qyYUC7B/K/gAnAlZ
6hL2QUBSsMwnBa87JekpmTxM
=e/0A
-----END PGP SIGNATURE-----



From seefeld at sympatico.ca  Sat Jan 31 03:26:58 2004
From: seefeld at sympatico.ca (Stefan Seefeld)
Date: Fri, 30 Jan 2004 21:26:58 -0500
Subject: [C++-sig] Re: replacing object constructors by factories
In-Reply-To: 
References: <10217cd7eb3c189a4a1b11add3471d73401aa7b9@Orthosoft.ca>
	
Message-ID: <401B1272.9020508@sympatico.ca>

David Abrahams wrote:

>>Are there other ways provide 'user hooks' as constructors ?
> 
> 
> See http://www.boost-consulting.com/boost/libs/python/doc/v2/make_function.html#make_constructor-spec
> 
> I know that isn't very clear, but along with 
> http://www.boost-consulting.com/boost/libs/python/test/injected.cpp
> it should get you there.

Thanks ! That looks like what I need, I'll try it out on monday...

Stefan





From ndbecker at verizon.net  Sat Jan 31 19:40:44 2004
From: ndbecker at verizon.net (Neal Becker)
Date: Sat, 31 Jan 2004 13:40:44 -0500
Subject: [C++-sig] Re: iterator interface question (progress!)
References:  
	 
	 
	
Message-ID: 

David Abrahams wrote:

> "Neal D. Becker"  writes:
> 
>> I have made some progress, I am really impressed with boost python
>> capabilities!
>>
>>   typedef std::vector::iterator vd_it;
>>
>>   class_("DVecIter")
>>     ;
>>
>>   class_ >("DVec")
>>     .def(init())
>>     .def(vector_indexing_suite >())
>>     .def("begin", (vd_it
>>     (std::vector::*)())(&std::vector::begin)) .def("end",
>>     (vd_it (std::vector::*)())(&std::vector::end)) ;
>>
>>   typedef std::vector::iterator vc_it;
>>
>>   class_("CVecIter")
>>     ;
>>
>>   class_ >("CVec")
>>     .def(init())
>>     .def(vector_indexing_suite, true >())
>>     .def("begin", (vc_it
>>     (std::vector::*)())(&std::vector::begin))
>>     .def("end", (vc_it
>>     (std::vector::*)())(&std::vector::end)) ;
>>     [...]
>>
>> Just with this, my main goal is accomplished:
>>
>>>>> from Test import *
>>>>> a = DVec (2)
>>
>>>>> for x in range (0, len (a)): a[x] = x
>>>>> PrintV (a.begin(), a.end())
>> 0
>> 1
> 
> Better make begin and end functions use return_internal_reference, so
> the iterators won't outlive the container.  UNfortunately, they're
> still not safe since they can still run off the end of the vector or
> become invalidated.  These are the sorts of issues that the indexing
> suites should handle.
> 

Thanks for the help, but I still have 1 question about your reply (the
meaning of "should").  Do you mean the indexing suites already do provide a
better solution (and I should look at it) or do you mean that you wish the
indexing suites provided a better solution, and may in the future?




From nicodemus at esss.com.br  Sat Jan 31 20:19:12 2004
From: nicodemus at esss.com.br (Nicodemus)
Date: Sat, 31 Jan 2004 16:19:12 -0300
Subject: [C++-sig] pyste && private copy constructor question.
In-Reply-To: 
References: 
Message-ID: <401BFFB0.1030206@esss.com.br>

Hanz Meizer wrote:

> Hi,


Hi Hanz, sorry about the delay!

> I'm trying to make the classes of an existing c++-project accessible 
> to python via the means of python. Unfortunately, there is a class 
> that has an interface like this:
>
> 
> My question is: How can I modify my pyste input file to work around 
> this problem? I figure that it's related to the fact that the copy 
> constructor is private. Unfortunately, I can't find any reasonable 
> pyste tutorial that covers more sophisticated topics and examples.


Actually, Pyste should generate a no_init declaration. This example does:

C++:

struct A
{
protected:
    A(int) {}

private:
    A() {}
    A(const A&) {}
}; 


generated:

BOOST_PYTHON_MODULE(a)
{
    class_< A, boost::noncopyable >("A", no_init)
    ;

}


Perhaps if you provide some code we can figure out the problem?

Regards,
Nicodemus.





From steam at nurfuerspam.de  Sat Jan 31 22:00:14 2004
From: steam at nurfuerspam.de (Hanz Meizer)
Date: Sat, 31 Jan 2004 22:00:14 +0100
Subject: [C++-sig] Re: pyste && private copy constructor question.
In-Reply-To: <401BFFB0.1030206@esss.com.br>
References:  <401BFFB0.1030206@esss.com.br>
Message-ID: 

> Perhaps if you provide some code we can figure out the problem?
> 
> Regards,
> Nicodemus.

Dear Nicodemus,

I will try to reduce the size of the class until I get a small example 
that provokes the error. I hope it won't take too long.

Greetings,

Hanz.