[Cython] Cython compiler directives: c_string_encoding

Hannes Röst hroest_nospam2333 at quantentunnel.de
Fri Jul 19 10:38:39 CEST 2013


Hi Stefan

Thank for your fast and detailed answer, this is helping us a lot.

On 17 July 2013 18:24, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Hannes Röst, 17.07.2013 14:45:
>> I am trying to compile a program with Cython using the compiler directives and
>> I am running into some trouble. Specifically, I am trying to port a Cython 0.18
>> program to Cython 0.19 and due to changes how char * and Python str are
>> handled, I need to set the c_string_encoding directive.
>
> This may or may not be so. The fact that it gives an error in 0.19 might
> also hint at problems in your code. There's some documentation available:
>
> http://docs.cython.org/src/tutorial/strings.html
>
> If you need further help, then the cython-users mailing list is the right
> place to ask.
>
>

Thanks, I will have a look at it. Currently we have strong guarantees
that our strings only contain ascii since they are part of a
controlled vocabulary which does not contain non-ASCII. Also there is
no other option to convert since our code is talking to external C
code. However, we might want to test for the assumptions that we make
here.

>> Unfortunately, this
>> fails for my project and also in the following testcase when I try to do it
>> locally:
>>
>> cimport cython
>> cdef class TestClass:
>>     def foo(self):
>>         with cython.c_string_encoding("ascii"):
>>             return
>
> This can't work. The string encoding is a module global option.
>

Thank you, I wasn’t aware of that. Maybe the documentation could be
more clear on this point and specifically state the that the "Locally"
method at the bottom of the page will only work with certain flags
(and maybe list which ones work).

>
>> The error message that
>> I get is attached at the end. Did I do something wrong or can somebody point me
>> in the right direction?
>>
>> Error message:
>>
>> inimalcase.pyx:6:13: Compiler crash in InterpretCompilerDirectives
>>   [...]
>>   File "/home/hr/lib/Cython-0.19.1/Cython/Compiler/ParseTreeTransforms.py",
>> line 913, in try_to_parse_directive
>>     assert False
>> AssertionError:
>
> That's a bug. It shouldn't crash and instead give a compile error. Thanks
> for the report.
>
> Stefan
>
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel


More information about the cython-devel mailing list