This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bytearray type not supported as a mutable object in the fcntl.ioctl function
Type: behavior Stage:
Components: IO Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, pitrou, vxgmichel
Priority: normal Keywords:

Created on 2013-06-14 08:58 by vxgmichel, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg191110 - (view) Author: Vincent Michel (vxgmichel) * Date: 2013-06-14 08:58
The Bytearray type is a mutable object that support the read-write buffer interface. The fcntl.ioctl() function is supposed to handle mutable object (such as array.array) for the system calls in order to pass object that are more than 1024 bytes long.

The problem is that in Python 2.7, Bytearray type is not supported as a mutable object in the fcntl.ioctl function. In Python 3.2, it works perfectly.

In the specific case where a large C structure is needed (more than 1024 bytes), the Bytearray type is extremely useful compare to the array.array type that is adapted for C arrays.

Example :

>>> file_handle = open('/dev/my_device')
>>> arg = bytearray()
>>> arg += pack('IL',1,2)
>>> command = 0
>>> ioctl(file_handle,command,arg)

Traceback (most recent call last):
  File "<pyshell#22>", line 1, in <module>
    ioctl(file_handle,command,arg)
TypeError: an integer is required
msg199903 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-14 15:06
It doesn't work in 2.7 because bytearray only supports the new buffer API (which is more secure), not the old one. I don't think it's worth trying to fix at this point, so I'm tempted to close as won't fix.
msg199908 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-14 15:33
Agreed.  This is not really a bugfix.
History
Date User Action Args
2022-04-11 14:57:46adminsetgithub: 62409
2013-10-14 15:33:45georg.brandlsetstatus: open -> closed
resolution: wont fix
messages: + msg199908
2013-10-14 15:06:07pitrousetnosy: + georg.brandl
messages: + msg199903
2013-10-14 14:23:18georg.brandlsetnosy: + pitrou
2013-06-14 08:58:44vxgmichelcreate