[issue10803] ctypes: better support of bytearray objects
Markus F.X.J. Oberhumer
report at bugs.python.org
Sun Jan 2 07:59:06 CET 2011
New submission from Markus F.X.J. Oberhumer <markus at oberhumer.com>:
Python 3.2b2 does not properly support accessing bytearrays from
ctypes, which makes dealing with large buffers somewhat unpleasant.
A very first fix - a simple patch for the z_set() function - is given here.
build/Python-3.2b2 $ quilt diff
Index: b/Modules/_ctypes/cfield.c
===================================================================
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1363,6 +1363,10 @@
*(char **)ptr = PyBytes_AsString(value);
Py_INCREF(value);
return value;
+ } else if (PyByteArray_Check(value)) {
+ *(char **)ptr = PyByteArray_AsString(value);
+ Py_INCREF(value);
+ return value;
} else if (PyLong_Check(value)) {
#if SIZEOF_VOID_P == SIZEOF_LONG_LONG
*(char **)ptr = (char *)PyLong_AsUnsignedLongLongMask(value);
----------
assignee: theller
components: ctypes
messages: 125032
nosy: mfxmfx, theller
priority: normal
severity: normal
status: open
title: ctypes: better support of bytearray objects
type: feature request
versions: Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10803>
_______________________________________
More information about the Python-bugs-list
mailing list