robertwb / issues-import-test

0 stars 0 forks source link

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

Closed robertwb closed 9 years ago

robertwb commented 9 years ago

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 9 years ago

scoder changed resolution to invalid status from new to closed 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')