Friday, August 31, 2007

py++ and boost python


I was debating which Python interface/wrapper generator to use for some of my personal projects. I had played with SWIG in the past, and more recently sip, after noticing that PyQt used it. Qt is great, and if sip is capable of creating the python bindings that it must be fully featured enough for any of my own projects. The only problem being that I'm lazy and don't want to have to manually specify any of the required interface files (maybe there is a way around this), but I realize the wrappers aren't going to come for free.


While looking into sip I found a comparison of it against its competitors, which included boost python. In order to keep dependencies to a minimum I figured it would be helpful to look into the boost python package (the use of template programming for this task is interesting in its own right). Anyhow, it turns out that manually specifying the interfaces for wrappers is extremely easy, not to mention the handy object wrappers for native python types.


The existance of more automatic tools for generating the interfaces, such as Py++, made me settle in on boost. As I mentioned earlier, I really want the python bindings to my own libraries for use in an interactive console. While boost python is feature rich, I couldn't find a direct approach to access global variables, say for example an integer flag that denotes a draw flag in a GL application (e.g., int wireframe=0;). I'm sure I did this in SWIG, so there has to be a way, but I would like to keep it as standard as possible using boost. So the easiest workaround would be to define a function that just returns a reference/pointer to these global variable (there is a Singleton example in the python documentation doing exactly this), but a quick attempt at doing this failed to work for assignment...probably due to the semantics of basic types in python. Because of this, the next easiest approach, I guess, is to gather up all the globals and put them in a Singleton class, as this is guaranteed to work, although using them now requires more typing in both python and c++.


Anyhow, after figuring out some workarounds for common constructs in my code (e.g., returning a non-const reference from operator() and operator[] so they can be used for assignment), Py++ was extremely easy to use, and with a little bit of tinkering it had magically created the necessary boost-python code for bindings my common libraries. Py++ provides an API to workaround common argument/return-value passing policy workarounds for references/pointers. My only complaint is the API documentation, with multiple Google ads panes, was annoying to navigate. Oh yeah, and the Py++/boost-python solution is pretty damn slow, but that I can deal with.

Thursday, August 30, 2007

Journal


I decided it was time to start documenting some software design decisions, and tidbits of handy knowledge I learn on my daily adventures, and since the only search result that appeared in yum on fc7 were interfaces to online blogs (e.g., drivel) I had to start using one. Besides, if I lose another hard disk, at least I won't have to worry about my precious thoughts. I'm sure that other random thoughts will creep into this, but I'm going to try and keep it more technical than random personal. As much as I would like to look back and read that I did a legit backside noseblunt yesterday (on a plastic ledge on 124st) and made heaps of corn chowder last night.


Actually, forget it, I'm going to mix random stuff in here, so I have to weed out any important stuff in the future, like for instance this: today, I decided that along with Joggers and runners, wandering oblivious people listening to their I-pods are the most annoying obstacles for a person on a bike--one who is actually using the sidewalk to get somewhere. I'm sorry to all the runners out there, its nothing personal and I'm sure it's good excercise but it can't really be all that fun...can it? I mean, can't you play soccer or find some other way to get an aerobic exercise while actually having fun and not obstructing a sidewalk on some hill that you obsessively run up and down, over and over?


Anyhow, I'm about to enjoy some of that chowder I mentioned, and hopefully later I will get to what I intended on talking about: my thoughts for automatically generated python bindings for use in my personal c/c++ projects, and what solution I think is best for a (well actually my) python-based console.