Regarding this bit, I just noticed that all integer types are simply
ctypedef'ed to int in that file:
ctypedef signed int int8_t
ctypedef signed int int16_t
ctypedef signed int int32_t
ctypedef signed int int64_t
ctypedef unsigned int uint8_t
ctypedef unsigned int uint16_t
ctypedef unsigned int uint32_t
ctypedef unsigned int uint64_t
Wouldn't it make more sense to typedef them to something with a closer
match to the integer types that Cython knows, i.e. byte/8, short/16,
int/32, long/64?
> However, it seems that Cython can only convert python objects to
> "char*", even when the typedef is the same type as char*.
Well, it won't convert *most* pointer types to Python objects
automatically, with (s/u)char* being the only special cased exception. But
you can use an explicit cast.
> cdef extern from "header.h":
> ctypedef char int8_t
> void prototype(int8_t*)
>
> def test(pystring):
> prototype(pystring)
>
> Cannot convert 'int8_t *' to Python Object
Try
prototype(<char*>pystring)
instead to get automatic conversion from a byte string to a char*, which
Cython should then be able to assign to a ctypedef'ed int8_t*.
BTW, note that this only handles byte strings, unicode strings require
explicit encoding.
Stefan
prototype(<int8_t*>(<char*>pystring))
--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
I'd try this first:
prototype(<unsigned char*>pystring)
Stefan
Cython has stricter typing than C, more or less like to C++, you have to:
prototype(<int8_t*>(<unsigned char*>pystring))
It really doesn't matter, as it completely ignores the defined
longness and generates code based on the actual longness.
- Robert
Well, for integer promotion rules it does matter, right?
Sorry, yes, it does there. I was only thinking about conversion, so
yes, we should fix that (and bite the bullet that we can't be
right...).
- Robert
Should we follow LP64?
Yes, that model makes the most sense to use.
- Robert