tags:

views:

45

answers:

1

I need access to the uint64_t typedef from stdint.h in some wrapper code that I'm writing and I can't figure out how to get it done. The problem is that from what I can tell from the docs, my ctypedef will have to take the form:

ctypedef unsigned long uint64_t

or

ctypedef unsigned long long uint64_t

depending on if WORDSIZE from bits/wordsize.h is 64 or 32. I haven't been able to find out out how to get access to this preprocessor definition from Cython and if I could, Cython doesn't seem to like ctypedef statements in if statements and when I try to put an if statement in a cdef block, it seems to confuse it with a declaration. Any ideas? Hopefully I'm just missing something really basic here.

+1  A: 
extern from "stdint.h":
    ctypedef unsigned long long uint64_t

Any ctypedef that's extern'd won't have a typedef generated in the .c file. Cython will include stdint.h and your C compiler will use the actual typedef from there.

The only thing that the type provided matters for is when cython generates code that automatically converts between C types and Python types. Using unsigned long long means that Cython will use PyLong_FromUnsignedLongLong and PyLong_AsLongLongAndOverflow. This way, you hopefully won't get any truncation on conversion.

Aaron Gallagher
perfect. That's exactly what I was using in the meantime. I don't have to change anything. It probably should have occurred to me to check the generated C file now that I think about it.
aaronasterling