[PyKDE] SIP questions 2

Jim Bublitz jbublitz at nwinternet.com
Thu Mar 27 06:13:00 GMT 2003


On 27-Mar-03 dwelch wrote:
> Thanks again to Phil and Jim for all their help. I have 1
> additional question at this stage. I am trying to wrap a C++
> class that has a  member function that takes a fd_set as a
> parameter. Something like:
 
> int DoSpecialSelectLikeOperation( fd_set f );
 
> On my RH8 Linux box, the fd_set is a struct that contains a
> bitfield.  Any suggestions on how to handle this?

I got into this once, but quite a while so I'm not sure. I *think*
sip handles bit field variables, so first I'd try:

int a;
int b;

for the corresponding bit-field variables. The actual variable
declarations from the h file might work too.

sip will take the above (sip doesn't look at h files, so it doesn't
know any better). It might cause compile or execution errors - you'd
want to test it. If it does work, you might have to be careful to
not "overflow" the variables from Python. 

The other way is to write a %MappedType for fd_set, which would
allow you to view it as a tuple in Python and struct in C++. You
could also write %MemberCode, but you then have the problem of
getting sip to recognize the fd_set type (%MappedType does that for
you). In either case you'd be handling the bit-field variables at
the C++ level, so it wouldn't be a problem. That would also let you
handle overflows from the Python side. (I used to handle all C++
structs as tuples via %MappedTypes, but I write them as classes
now). In that case, you wouldn't instantiate fd_set directly in
Python - you'd pass in an appropriately structured tuple (or get a
tuple back).

Writing a mapped type is basically writing one code fragment that
converts from C++ -> Python and another going the other way. Both
use Python/C API functions (and sip generated methods for class
conversions) to do the actual conversions.

There also is a %VariableCode directive in sip, but there aren't
any useful examples in either PyQt and PyKDE (one trivial PyKDE
example that's no longer used), and I don't recall if it would help
here or not.

Jim




More information about the PyQt mailing list