Some standard C libraries that I want to access with Cython have a ton of flags. The Cython docs state that I must replicate the parts of the header I need. Which is fine when it comes to functions definitions. They are usually replicated everywhere, docs included. But what about all those magic numbers?
If I want to call mmap
, I can always find the function definition and paste it into a .pxd file:
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
But calling it needs a ton of flags like PROT_READ
, MAP_ANONYMOUS
and so on. I have at least two problems with this:
Firstly, it is annoying work to hunt down exactly where those numbers are defined. In fact I'd rather write a .c file and printf the values I need. Are there any better way of finding the value of a given flag such as PROT_READ
?
Secondly, how stable are these numbers? Having extracted all the values I need and hardcoded them into my Cython source, what are the chances that compiling on a different platform has switched around, let's say PROT_READ
and PROT_EXEC
?
Even if the answer is that there are no good or proper ways to do it, I'd like to hear it. I can always accept that something is cumbersome as long as I know I'm not missing something.