[issue10803] ctypes: better support of bytearray objects

2014-10-14 Thread Stefan Krah

Changes by Stefan Krah stefan-use...@bytereef.org:


--
nosy:  -skrah

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Existing inconsistency was fixed in issue22161.

Patch updated, synchronized with tip. Added new tests.

--
Added file: http://bugs.python.org/file36326/ctypes_bytearray_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-07 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here are things which support bytes instances only:

1. Constructor and setter of the value attribute of NUL terminated char 
buffer.

 p = create_string_buffer(bHello)
 p.value
b'Hello'
 p.raw
b'Hello\x00'
 p.value = b'Bye'
 p.value
b'Bye'
 p.raw
b'Bye\x00o\x00'
 create_string_buffer(bytearray(bHello))
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/serhiy/py/cpython-3.4/Lib/ctypes/__init__.py, line 63, in 
create_string_buffer
raise TypeError(init)
TypeError: bytearray(b'Hello')
 p.value = bytearray(b'Hi')
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: bytes expected instead of bytearray instance

But setter of the raw attribute accepts arbitrary bytes-like objects.

 p.raw = bytearray(b'Hi')
 p.raw
b'Hie\x00o\x00'

The patch adds support of bytearray here. It would be not so easy to add 
support for arbitrary bytes-like objects, and due to NUL-terminating it can be 
confused. I even not sure that support of bytearray is needed here.

2. Constructor of NUL terminated wchar buffer (create_unicode_buffer). Actually 
this doesn't work. Bytes argument is accepted, but then rejected in internal 
setting function. This is a bug, bytes should be removed here.

3. c_wchar_p.from_param() accepts bytes argument, but then reject it in 
internal function. This is a bug, bytes should be removed here.

4. c_void_p.from_param() accepts bytes and bytearray arguments, but then 
reject bytearray in internal function. This is a bug, either bytearray should 
be rejected here, or support of bytearray should be added in internal function 
(very easy, the patch does this). Adding support of arbitrary bytes-like 
objects is more complicated.

5. c_char_p.from_param() accepts bytes argument. Adding support for bytearray 
or arbitrary bytes-like objects has same complexity as in 
c_void_p.from_param().

6. Bytes arguments of call_function(), call_cdeclfunction() and 
CopyComPointer() are implicitly converted to pointers. It is easy to add 
support of bytearray, and more complicated for arbitrary bytes-like objects.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-07 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
dependencies: +Remove unsupported code from ctypes

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-06 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
keywords: +needs review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-06 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Why not use the buffer API instead?

--
assignee: theller - 
nosy: +pitrou, skrah

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-08-06 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Because it is simpler and more efficient. The buffer API requires the releasing 
of buffer. Correct tracking the ownership of the buffer requires larger and 
more complicated patch. Even if support for general buffers will be added, I 
suppose it will be worth to left specialized paths for bytes and bytearrays in 
some places.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2014-07-31 Thread Martin Panter

Changes by Martin Panter vadmium...@gmail.com:


--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2013-12-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is preliminary patch which makes bytearray support in ctypes better.

--
keywords: +patch
nosy: +amaury.forgeotdarc, belopolsky, meador.inge, serhiy.storchaka
stage:  - patch review
versions: +Python 3.5 -Python 3.2
Added file: http://bugs.python.org/file32921/ctype_bytearray.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10803] ctypes: better support of bytearray objects

2011-01-01 Thread Markus F.X.J. Oberhumer

New submission from Markus F.X.J. Oberhumer mar...@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 rep...@bugs.python.org
http://bugs.python.org/issue10803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com