[Cython] Potential bug: hole in "C <-> Python" conversion

Dieter Maurer dieter at handshake.de
Fri Jun 29 12:18:46 CEST 2012


Stefan Behnel wrote at 2012-6-29 11:42 +0200:
>Dieter Maurer, 29.06.2012 11:25:
>> I have
>>
>> cdef extern from *:
>>         ctypedef char const_unsigned_char "const unsigned char"
>
>This is an incorrect declaration. "char" != "unsigned char".

You are right. I cheat to get "Cython" convert between "unsigned char*"
and "bytes" in the same way as it does for "char *".

For this conversion, there is no real difference between
"char *" and "unsigned char *" (apart from a C level warning
about a pointer of a bad type passed to "PyString_FromStringAndSize").

>> cdef const_unsigned_char *c_data = data
>>
>> leads to "Cannot convert Python object to 'const_unsigned_char *'"
>> while "cdef char *c_data = data" works.
>>
>> Should the "ctypedef char const_unsigned_char" not ensure
>> that "char" and "const_unsigned_char" are used as synonyms?
>
>I assume you are not using the latest Cython (0.17pre) from github, are
>you? It should have a fix for this.

You are right.

I am using the "cython" version which comes with my operating
system ("cython 0.13").

Very good, if the latest "Cython" behaves better :-)

>Also note that libc.string contains declarations for "const char*" and friends.

Unformatunately, I need "const unsigned char*" and "const xmlChar *"
(where "xmlChar" is defined as "unsigned char").

I used the "libc.string" definitions as a blueprint for mine.



--
Dieter


More information about the cython-devel mailing list