[PyKDE] More sip on C fun!
Jonathan Gardner
jgardner at jonathangardner.net
Tue May 20 04:20:01 BST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have three questions about using sip to wrap C->C++. I have done all the
"easy" stuff. If anyone would like to see my code, I'll post it.
1) I am running into a bit of a problem translating a struct to sip.
The struct in question has an attribute 'char **fieldNames' -- which is
meant to be a null-terminated list of null-terminated strings. Of course,
sip doesn't know what to do with this.
Is there something akin to '%MemberCode' that I can put after the attribute
that allows me to specify how to set and get the value 'fieldNames'? Or, do
I need to wrap it with a C++ class that doesn't provide a direct interface
to fieldNames?
2) One function requires a struct as an argument. This struct is so deep
into C it doesn't make any sense to translate it to Python at all (it has a
union with a void pointer and an integer for one of the attributes, and
half the other attributes describe the length and types of the other
attributes). Can I just invent a function that takes a dict or a list as an
argument in place of the struct? How would I specify this?
Here is the prototype for reference (wrapped as far as I dare go in C++)
:
class Conn {
...
public:
result *fn(int fnid, int *result_buf, int *result_len, int result_is_int,
const PQArgBlock *args, int nargs);
...
};
3) There is a callback function that I would like to use. How would I go
about doing this in sip? What kind of function should I put as the
callback? What kind of arguments should I expect from sip?
Let's just keep it simple:
The callback prototype: typedef void (*callback_func)(int);
The "set callback" prototype: int set_callback(callback_func *);
(And there is a corresponding release_callback() function as well, of
course).
What I would like to see in python:
def callback(x): print x
set_callback(callback)
how do I get from C to Python via sip?
- --
Jonathan Gardner
jgardner at jonathangardner.net
(was jgardn at alumni.washington.edu)
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+yZFrWgwF3QvpWNwRAu0+AKCm00nUbssxRO56W7jhn7r6fcjLeQCdEyJA
8SSjg70pZtbWJxWEUKlNYPM=
=qe7e
-----END PGP SIGNATURE-----
More information about the PyQt
mailing list