[PyKDE] sipping char[N] datatypes in structs

Phil Thompson phil at riverbankcomputing.co.uk
Fri May 16 10:34:01 BST 2003


On Friday 16 May 2003 4:13 am, Jonathan Gardner wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> sip -V -> 3.5 (build 57)
>
> I am doing my first sip of a C header file (or any file for that matter).
> Please pardon me for my naivety. I did read through the two books
> referenced by the sip documentation site. They were pretty helpful. I still
> have a lot of questions, naturally.
>
> For reference, I am doing a sip interface to the postgresql C library
> (libpq). You can find the header I am working from normally somewhere
> around /usr/include/libpg-fe.h. I am working off of Red Hat 8.0, so it is
> in the postgresql-devel package.
>
> I am doing this because I wanted a "closer to the metal" interface. There
> are probably a few things I will smooth out (like freeing memory with the
> supplied PQ functions, etc..) later on. For now, I just want the bare
> metal.
>
> I got some of the stuff working -- like enum and some function calls.
> However, I am having a bit of trouble with the structs.
>
> There are some structs that are opaque. For example, in the header:
>
> typedef struct pg_conn PGconn;
>
> So, in the .sip file, I put the same. For functions that return a pointer
> to the struct, it seems to work okay. It returns a sip.voidptr when called
> in python. I guess this won't cause a lot of problems, because PGconn is
> supposed to be opaque.
>
> Now for transparent structs. It seems as long as I change it around so it
> reads:
>
> struct  StructName { ... };
>
> instead of:
>
> extern struct _StructName { ... } StructName;
>
> it works okay. I was able to get PQconninfoOption working in this way.
>
> This sucker won't sip, though:
>
> struct PGnotify
> {
> 	char		relname[NAMEDATALEN];
> 	int			be_pid;
> };
>
> If I do "char *relname", then it won't compile because char * is not the
> same as char[32] (NAMEDATALEN is defined to be 32).
>
> Any tips?

SIP doesn't support arrays (as you have found). In fact I've never used SIP to 
wrap a C library, so I'm pleasently surprised you've got as far as you have.

The only thing I can think of at the moment is to create a thin C++ class 
library that implements exactly the API you want and SIP that - but it's 
obviously not the bare metal.

Phil




More information about the PyQt mailing list