Determine PyArg_ParseTuple parameters at runtime?

N

Nikolaus Rath

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top