summaryrefslogtreecommitdiff
path: root/cffi/model.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-05-20 23:29:46 +0200
committerArmin Rigo <arigo@tunes.org>2020-05-20 23:29:46 +0200
commitbb48fdcc86c5bd2c211fba2ac4cffe8b6efb49e2 (patch)
treedd4e9101065c0a799cca5c03f31c3c310ef15d9a /cffi/model.py
parent680aa960da02dfa304c6b889489c05c38de89318 (diff)
downloadcffi-bb48fdcc86c5bd2c211fba2ac4cffe8b6efb49e2.tar.gz
#453
Special-case typedefs of arrays with '...' length, so that they can be used through recompiler.py as if they had a specified length in most cases.
Diffstat (limited to 'cffi/model.py')
-rw-r--r--cffi/model.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/cffi/model.py b/cffi/model.py
index 5f1b0d2..ad1c176 100644
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -307,11 +307,14 @@ class ArrayType(BaseType):
self.c_name_with_marker = (
self.item.c_name_with_marker.replace('&', brackets))
+ def length_is_unknown(self):
+ return isinstance(self.length, str)
+
def resolve_length(self, newlength):
return ArrayType(self.item, newlength)
def build_backend_type(self, ffi, finishlist):
- if self.length == '...':
+ if self.length_is_unknown():
raise CDefError("cannot render the type %r: unknown length" %
(self,))
self.item.get_cached_btype(ffi, finishlist) # force the item BType
@@ -430,7 +433,7 @@ class StructOrUnion(StructOrUnionOrEnum):
fsize = fieldsize[i]
ftype = self.fldtypes[i]
#
- if isinstance(ftype, ArrayType) and ftype.length == '...':
+ if isinstance(ftype, ArrayType) and ftype.length_is_unknown():
# fix the length to match the total size
BItemType = ftype.item.get_cached_btype(ffi, finishlist)
nlen, nrest = divmod(fsize, ffi.sizeof(BItemType))