[PyKDE] sipping char[N] datatypes in structs

Jim Bublitz jbublitz at nwinternet.com
Fri May 16 19:22:01 BST 2003


On Friday 16 May 2003 09:15, Jonathan Gardner wrote:
> On Friday 16 May 2003 08:33, Jim Bublitz wrote:
> > On Friday 16 May 2003 01:33, Phil Thompson wrote:

> And I have to admit, when it comes to C++, sip makes it
> EXTREMELY easy to write an interface. In literally a few
> minutes, I had most of the function calls for a connection
> mapped to methods of a connection class. Thanks to the
> tutorial by Donovan, everything hard (writing makefiles and
> how to invoke sip) was already solved.

Yep - it's pretty easy once you figure out sip. I did a fairly 
user-friendly wrapper for most of KSpread in a couple days - 
almost as fast as I could type/cut/paste. The actual sip files 
took less than an hour.

You can also arrange the wrapper to hide things from sip but 
still have them visible to the wrapper code - don't make the 
ugly stuff visible to the wrapper h file, but let it be visible 
from the wrapper .c or .cpp file (for example, put the #includes 
for hidden stuff in wrapper.c, not wrapper.h).


> This is exciting because I can take these bare-metal library
> calls, and build the stuff to make them presentable on top of
> it. Python won't be missing anything C has when it comes to
> postgresql! 

You can also enhance the usability of the C/C++ stuff with a 
wrapper. For example, in KSpread C/C++, you address a 
spreadsheet cell as:

    KSpreadCell cell (int row, int col); 

(KSpreadCell might not be real - just an example)

but in the wrapper you can do:

    KSpreadCell cell (const char* cellAddr);

and convert cellAddr => (row, col) in the wrapper's C++ code so 
that in Python you can call

    x = cell ("A17")

    cell ("B3").value = cell ("B1").value + cell ("B2").value

which is the cell addressing the user sees on the actual 
spreadsheet. 

You're no longer constrained to what was a good API for the C/C++ 
programmer, but the enhancements still run at C/C++ speed. I 
found I could make KSpread do things with Python (eg load a 
second spreadsheet in the background and reference it or modify 
it) that KSpread (the application) couldn't do.

> This opens up the whole C world to sip -- all we
> have to do is write thin C++ layers to get it to work. After
> this, I want to take a stab at ImageMagick... ;-)

Yes - there's a ton of stuff I'd like to get to but can't find 
time for.

The drawback with wrappers is maintainability - everytime the 
C/C++ API changes significantly you have a lot of work to do.
PyQt and PyKDE (being bindings instead of wrappers in my scheme 
of things) are easier to maintain/automate. On the other hand, 
the wrapper libs (both the C/C++ lib and the binding lib) are 
usually very small.

Jim




More information about the PyQt mailing list