Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow string -> unsigned char* #922

Closed
robertwb opened this issue Sep 9, 2009 · 2 comments
Closed

allow string -> unsigned char* #922

robertwb opened this issue Sep 9, 2009 · 2 comments

Comments

@robertwb
Copy link
Contributor

robertwb commented Sep 9, 2009

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?

Migrated from http://trac.cython.org/ticket/359

@robertwb
Copy link
Contributor Author

@robertwb changed owner from somebody to scoder
commented

See http://www.mail-archive.com/cython-dev@codespeak.net/msg06322.html for followup.

@robertwb
Copy link
Contributor Author

scoder changed resolution to fixed
status from new to closed
commented

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant