summaryrefslogtreecommitdiff
path: root/cffi/backend_ctypes.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-08-05 09:44:09 +0200
committerArmin Rigo <arigo@tunes.org>2012-08-05 09:44:09 +0200
commit1564dcf454c50bb088248de8fb52eb48dd376feb (patch)
tree07b683ef60480ca421d4b080c8235ae607c77647 /cffi/backend_ctypes.py
parent99df488b7d502288ddc2561ede1c034129a57961 (diff)
downloadcffi-1564dcf454c50bb088248de8fb52eb48dd376feb.tar.gz
Workaround: allow out-of-bound array indexes if the array is 'type[0]'.
Diffstat (limited to 'cffi/backend_ctypes.py')
-rw-r--r--cffi/backend_ctypes.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
index 22c6239..23278f2 100644
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -583,14 +583,22 @@ class CTypesBackend(object):
return len(self._blob)
def __getitem__(self, index):
- if not (0 <= index < len(self._blob)):
+ if 0 <= index < len(self._blob):
+ x = self._blob[index]
+ elif len(self._blob) == 0:
+ x = ctypes.cast(self._blob, CTypesPtr._ctype)[index]
+ else:
raise IndexError
- return BItem._from_ctypes(self._blob[index])
+ return BItem._from_ctypes(x)
def __setitem__(self, index, value):
- if not (0 <= index < len(self._blob)):
+ x = BItem._to_ctypes(value)
+ if 0 <= index < len(self._blob):
+ self._blob[index] = x
+ elif len(self._blob) == 0:
+ ctypes.cast(self._blob, CTypesPtr._ctype)[index] = x
+ else:
raise IndexError
- self._blob[index] = BItem._to_ctypes(value)
if kind == 'char' or kind == 'byte':
def _to_string(self, maxlen):