Determine PyArg_ParseTuple parameters at runtime?

Nikolaus Rath Nikolaus at rath.org
Tue Dec 8 10:10:41 EST 2009


Hello,

I want to create an extension module that provides an interface to a
couple of C functions that take arguments of type struct iovec, struct
stat, struct flock, etc (the FUSE library, in case it matters).

Now the problem is that these structures contain attributes of type
fsid_t, off_t, dev_t etc. Since I am receiving the values for these
attributes from the Python caller, I have to convert them to the correct
type using PyArg_ParseTuple.

However, since the structs are defined in a system-dependent header
file, when writing the code I do not know if on the target system, e.g.
off_t will be of type long, long long or unsigned long, so I don't know
which format string to pass to PyArg_ParseTuple.


Are there any best practices for handling this kind of situation? I'm at
a loss right now.

The only thing that comes to my mind is to, e.g., to compare
sizeof(off_t) to sizeof(long) and sizeof(long long) and thereby
determine the correct bit length at runtime. But this does not help me
to figure out if it is signed or unsigned, or (in case of other
attributes than off_t) if it is an integer at all.


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the Python-list mailing list