[Cython] File encoding issue

Vitja Makarov vitja.makarov at gmail.com
Sun Nov 6 18:10:53 CET 2011


When file encoding is specified cython generates two PyObject entries
for string consts one for the variable name and one for the string
constant.

Here is ticket: http://trac.cython.org/cython_trac/ticket/740

At the first time I thought that this is C++ related bug. Now I
realise that C doesn't complains about.

Here is minimal example:
$ cat cplus.pyx
# -*- coding: koi8-r -*-
wtf = 'wtf'

Generaets the following code:

/* Implementation of 'cplus' */
static char __pyx_k__wtf[] = "wtf";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s__wtf;
static PyObject *__pyx_n_s__wtf;

...

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__),
0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__),
0, 0, 1, 1},
  {&__pyx_n_s__wtf, __pyx_k__wtf, sizeof(__pyx_k__wtf), "koi8-r", 0, 1, 1},
  {&__pyx_n_s__wtf, __pyx_k__wtf, sizeof(__pyx_k__wtf), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};

-- 
vitja.


More information about the cython-devel mailing list