Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2c5e9646
Commit
2c5e9646
authored
Jul 12, 2007
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept bytes in c_char_p and c_wchar_p types.
parent
3af4266d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
Lib/ctypes/test/test_bytes.py
Lib/ctypes/test/test_bytes.py
+8
-0
Modules/_ctypes/cfield.c
Modules/_ctypes/cfield.c
+10
-9
No files found.
Lib/ctypes/test/test_bytes.py
View file @
2c5e9646
...
...
@@ -14,5 +14,13 @@ class BytesTest(unittest.TestCase):
c_wchar
.
from_param
(
b"x"
)
(
c_wchar
*
3
)(
b"a"
,
b"b"
,
b"c"
)
def
test_c_char_p
(
self
):
c_char_p
(
"foo bar"
)
c_char_p
(
b"foo bar"
)
def
test_c_wchar_p
(
self
):
c_wchar_p
(
"foo bar"
)
c_wchar_p
(
b"foo bar"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Modules/_ctypes/cfield.c
View file @
2c5e9646
...
...
@@ -1354,8 +1354,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF
(
value
);
return
value
;
}
if
(
Py
String
_Check
(
value
))
{
*
(
char
**
)
ptr
=
Py
String_AS_STRING
(
value
);
if
(
Py
Bytes
_Check
(
value
))
{
*
(
char
**
)
ptr
=
Py
Bytes_AsString
(
value
);
Py_INCREF
(
value
);
return
value
;
}
else
if
(
PyUnicode_Check
(
value
))
{
...
...
@@ -1410,13 +1410,7 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
Py_INCREF
(
value
);
return
value
;
}
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode_encoding
,
conversion_mode_errors
);
if
(
!
value
)
return
NULL
;
}
else
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
*
(
wchar_t
**
)
ptr
=
(
wchar_t
*
)
PyInt_AsUnsignedLongLongMask
(
value
);
#else
...
...
@@ -1424,6 +1418,13 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
#endif
Py_INCREF
(
Py_None
);
return
Py_None
;
}
if
(
PyBytes_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode_encoding
,
conversion_mode_errors
);
if
(
!
value
)
return
NULL
;
}
else
if
(
!
PyUnicode_Check
(
value
))
{
PyErr_Format
(
PyExc_TypeError
,
"unicode string or integer address expected instead of %s instance"
,
...
...
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