Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
e542163c
Commit
e542163c
authored
15 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support conversion between Python byte strings and unsigned char*
parent
0474c27a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+18
-0
tests/run/unsigned_char_ptr_bytes_conversion_T359.pyx
tests/run/unsigned_char_ptr_bytes_conversion_T359.pyx
+18
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
e542163c
...
...
@@ -767,6 +767,9 @@ class StringNode(ConstNode):
if
dst_type
==
PyrexTypes
.
c_char_ptr_type
:
self
.
type
=
PyrexTypes
.
c_char_ptr_type
return
self
elif
dst_type
==
PyrexTypes
.
c_uchar_ptr_type
:
self
.
type
=
PyrexTypes
.
c_char_ptr_type
return
CastNode
(
self
,
PyrexTypes
.
c_uchar_ptr_type
)
if
dst_type
.
is_int
:
if
not
self
.
type
.
is_pyobject
and
len
(
self
.
value
)
==
1
:
...
...
This diff is collapsed.
Click to expand it.
Cython/Compiler/PyrexTypes.py
View file @
e542163c
...
...
@@ -1577,6 +1577,18 @@ class CCharPtrType(CStringType, CPtrType):
CPtrType
.
__init__
(
self
,
c_char_type
)
class
CUCharPtrType
(
CStringType
,
CPtrType
):
# C 'unsigned char *' type.
pymemberdef_typecode
=
"T_STRING"
to_py_function
=
"__Pyx_PyBytes_FromUString"
from_py_function
=
"__Pyx_PyBytes_AsUString"
def
__init__
(
self
):
CPtrType
.
__init__
(
self
,
c_uchar_type
)
class
UnspecifiedType
(
PyrexType
):
# Used as a placeholder until the type can be determined.
...
...
@@ -1664,6 +1676,7 @@ c_double_complex_type = CComplexType(c_double_type)
c_null_ptr_type
=
CNullPtrType
(
c_void_type
)
c_char_array_type
=
CCharArrayType
(
None
)
c_char_ptr_type
=
CCharPtrType
()
c_uchar_ptr_type
=
CUCharPtrType
()
c_utf8_char_array_type
=
CUTF8CharArrayType
(
None
)
c_char_ptr_ptr_type
=
CPtrType
(
c_char_ptr_type
)
c_int_ptr_type
=
CPtrType
(
c_int_type
)
...
...
@@ -1808,6 +1821,8 @@ def c_ptr_type(base_type):
# Construct a C pointer type.
if
base_type
is
c_char_type
:
return
c_char_ptr_type
elif
base_type
is
c_uchar_type
:
return
c_uchar_ptr_type
elif
base_type
is
error_type
:
return
error_type
else
:
...
...
@@ -1857,6 +1872,9 @@ type_conversion_predeclarations = """
#define __Pyx_PyBytes_AsString PyBytes_AsString
#endif
#define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) __Pyx_PyBytes_AsString(s))
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
...
...
This diff is collapsed.
Click to expand it.
tests/run/unsigned_char_ptr_bytes_conversion_T359.pyx
0 → 100644
View file @
e542163c
__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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment