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.
cdef extern from "stdint.h":
ctypedef unsigned long long uint64_t
Любой ctypedef
, который extern
d, не будет иметь typedef, созданного в файле .c. Cython будет включать stdint.h
, и ваш компилятор C будет использовать фактический typedef оттуда.
Единственное, что имеет значение предоставленный тип, - это когда cython генерирует код, который автоматически преобразуется между типами C и типами Python. Использование unsigned long long
означает, что Cython будет использовать PyLong_FromUnsignedLongLong
и PyLong_AsLongLongAndOverflow
. Таким образом, вы, надеюсь, не получите усечения при преобразовании.