Skip to content

Commit

Permalink
Ensure buffer data is 1-dimensional bytes
Browse files Browse the repository at this point in the history
cast doesn't exist under Python 2, but that's okay - we'll just throw an
error (which we need to do anyway given the data isn't 1-D bytes). Under
Python 3, it'll attempt to cast but may fail if the data isn't
C-contiguous (again, that's okay)
  • Loading branch information
waveform80 committed Jul 3, 2016
1 parent a8f9fa9 commit 8a6d460
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions picamera/mmalobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,8 @@ def update(self, data):
Some buffer objects *cannot* be modified without consequence (for
example, buffers returned by an encoder's output port).
"""
if isinstance(data, memoryview) and (data.ndim > 1 or data.itemsize > 1):
data = data.cast('B')
bp = ct.c_uint8 * len(data)
try:
sp = bp.from_buffer(data)
Expand Down

0 comments on commit 8a6d460

Please sign in to comment.