Ticket #359 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

allow string -> unsigned char*

Reported by: robertwb Owned by: scoder
Priority: major Milestone: 0.11.3
Component: Type Analysis Keywords:
Cc:

Description

On Jul 13, 2009, at 6:47 AM, Eric Eisner wrote:

Hi,

I was working on a wrapper for a c function that took an unsigned
char* and its length (the string could have null bytes, so it needs a
specific length). I was having some trouble getting cython to compile
a simple conversion of string to unsigned char*, the way I eventually
got it to work is:

udata = <unsigned char*><char*>pydata

This was a surprising requirement that took me a while to figure out.
Is it intentional that strings cannot be directly cast to unsigned
char?

Change History

Changed 4 years ago by robertwb

  • owner changed from somebody to scoder

Changed 4 years ago by scoder

  • status changed from new to closed
  • resolution set to fixed

Implemented here:

 http://hg.cython.org/cython-devel/rev/d273a3dc784b

This works now:

__doc__ = u"""
>>> py_string1.decode('ASCII') == 'test toast taste'
True
>>> py_string1 == py_string2 == py_string3
True
"""

cdef unsigned char* some_c_unstring = 'test toast taste'

py_string1 = some_c_unstring

cdef unsigned char* c_unstring_from_py = py_string1

py_string2 = c_unstring_from_py

cdef char* c_string_from_py = py_string2

py_string3 = c_string_from_py
Note: See TracTickets for help on using tickets.