Some standard C libraries that I want to handle with Cython have tons of flags. Cython docs indicate that I must replicate parts of the required header. Which is good when it comes to defining functions. They are usually replicated everywhere, including documents. But what about all these magic numbers?
If I want to call mmap , I can always find the function definition and paste it into the .pxd file:
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
But calling requires a ton of flags, such as PROT_READ , MAP_ANONYMOUS , etc. I have at least two problems with this:
First, itโs an annoying job to track down exactly where these numbers are determined. In fact, I would rather write a .c file and print the desired values. Is there a better way to find the value of a given flag, for example PROT_READ ?
Secondly, how stable are these numbers? Having selected all the values โโI need and encoded them in my Cython source, what are the chances that the compilation on another platform has switched, say PROT_READ and PROT_EXEC ?
Even if the answer is that there are no good or right ways to do this, I would love to hear it. I can always admit that something is cumbersome if I know that I did not miss something.
source share