2015-06-17 5:11 GMT-03:00 Hermann Hamann <hermann-***@web.de>:
>
> I want to suggest a small change to pyusb to improve speed.
> Currently you can only provide an array.array buffer to put the USB data
> into.
> I use the multiprocessing feature and the final destination of the USB data
> is a mmap.mmap
> Object. I would like to specify this as a receive buffer to save a pickle
> and
> unpickle operation.
> It is not so difficult to use the pyapi.PyObject_GetBuffer function to
> retrieve address and length
> of any buffer protocol compliant object.
> So this array restriction should be lifted, I assume there are more users
> who would
> appreciate this change. I would not like to distribute my software with a
> modified pyusb.
> Sincerely
> Hermann Hamann
>
> Here follows the modifications I made:
> -----------------------------------------
> # in backend1.py, similar for other backends
> from ctypes import *
> from struct import unpack
> getBuffer = pythonapi.PyObject_GetBuffer
> getBuffer.argtypes = [py_object, c_void_p, c_int]
> view = create_string_buffer(11*sizeof(int))
> def getBufferInfo(someObject):
> pointer_to_sO = py_object(someObject)
> result = getBuffer(pointer_to_sO,view,1) # flag writeable
> ### this call can raise an Exception. However this would be a
> consequence
> ### of an invalid caller, so no recovery is possible and simply let it
> ### crash, the message is helpful.
>
> if result != 0 : return None,None
>
> bufadr,objadr,buflen,itemsize,readonly,ndim,bformat,shape,strides,\
> suboffsets,internal = unpack("11I",view)
>
> result = pythonapi.PyBuffer_Release(string_buffer)
> return (bufadr,buflen)
>
> # and some lines later
> def __read(self, fn, dev_handle, ep, intf, buff, timeout):
> ### !!!! changed address, length = buff.buffer_info()
> address,length = getBufferInfo(buff)
> ##length *= buff.itemsize changed
>
> ----------------------------------
> # in core.py
> if isinstance(size_or_buffer,int):
>
Hi,
Could you please open a Pull Request or, if you are not willing to
supply a patch, an issue detailing your proposal?
--
Best Regards,
Wander Lairson Costa
------------------------------------------------------------------------------