robertwb / issues-import-test

0 stars 0 forks source link

str(char *) doesn't obey Python 3 semantics #88

Closed robertwb closed 8 years ago

robertwb commented 8 years ago

Reported by nikratio on 1 Aug 2015 18:55 UTC When calling str on a char * variable, the result is of type bytes. I believe that when using Python 3 semantics, the result should be str.

Testcase:

$ cat test.pyx
cdef extern char* LLFUSE_VERSION
__version__ = str(LLFUSE_VERSION)

$ cython -3 test.pyx 

$ cython --version
Cython version 0.21.1

$ grep -A 5 '"test.pyx":2' test.c
  /* "test.pyx":2
 * cdef extern char* LLFUSE_VERSION
 * __version__ = str(LLFUSE_VERSION)             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_PyBytes_FromString(LLFUSE_VERSION); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

Migrated-From: http://trac.cython.org/ticket/855

robertwb commented 8 years ago

Comment by scoder on 9 Aug 2015 13:35 UTC The C code you copied does only the conversion from char* to a Python object. The actual str() call comes after that and should turn the bytes object into a b'...' representation.

My guess is that you should use this instead:

__version__ = LLFUSE_VERSION.decode('ascii')