summaryrefslogtreecommitdiff
path: root/cffi/api.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-04-17 00:18:19 +0200
committerArmin Rigo <arigo@tunes.org>2016-04-17 00:18:19 +0200
commita8bd9eb3ade58e5804b0856d2dec60043a55d804 (patch)
treedcc992029ce15c4ccec6266405be882bf9098839 /cffi/api.py
parent4b765c16d4f60f46084abd74341e79267be751d0 (diff)
downloadcffi-a8bd9eb3ade58e5804b0856d2dec60043a55d804.tar.gz
There is no reason to restrict ffi.unpack() to primitives.
Diffstat (limited to 'cffi/api.py')
-rw-r--r--cffi/api.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/cffi/api.py b/cffi/api.py
index 7c6ad28..ed816bb 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -300,17 +300,19 @@ class FFI(object):
return self._backend.string(cdata, maxlen)
def unpack(self, cdata, length):
- """Unpack an array of primitive C data of the given length,
+ """Unpack an array of C data of the given length,
returning a Python string/unicode/list.
If 'cdata' is a pointer to 'char', returns a byte string.
- Unlike ffi.string(), it does not stop at the first null.
+ It does not stop at the first null. This is equivalent to:
+ ffi.buffer(cdata, length)[:]
If 'cdata' is a pointer to 'wchar_t', returns a unicode string.
'length' is measured in wchar_t's; it is not the size in bytes.
- If 'cdata' is a pointer to some other integer or floating-point
- type, returns a list of 'length' integers or floats.
+ If 'cdata' is a pointer to anything else, returns a list of
+ 'length' items. This is a faster equivalent to:
+ [cdata[i] for i in range(length)]
"""
return self._backend.unpack(cdata, length)