From c36dde3f4535e948318edc843faeee118492b38e Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Fri, 30 Jul 2021 22:48:47 +0300 Subject: Add element to specify expression that defines length of a struct Currently the layout of a struct is used to compute its size. This works fine in case of structs of fixed size. However this introduces forwards-compatibility problems in cases when the struct has multiple variants and the exact variant is specified by the value of some field (e.g. in the case of elements). Future revisions of protocols may introduce new layout variants, in which case the old code does not know the size of the struct variant and can't parse the incoming byte stream. Instead of relying on knowledge about the layout of data structures we should instead use the length field for length information. This way when old client libxcb communicates with newer server it can at least ignore unknown struct variants. --- xcbgen/xtypes.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'xcbgen') diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py index e47189d..3359a09 100644 --- a/xcbgen/xtypes.py +++ b/xcbgen/xtypes.py @@ -503,6 +503,8 @@ class ComplexType(Type): Public fields added: fields is an array of Field objects describing the structure fields. + length_expr is an expression that defines the length of the structure. + ''' def __init__(self, name, elt): Type.__init__(self, name) @@ -512,6 +514,7 @@ class ComplexType(Type): self.nmemb = 1 self.size = 0 self.lenfield_parent = [self] + self.length_expr = None # get required_start_alignment required_start_align_element = elt.find("required_start_align") @@ -573,6 +576,9 @@ class ComplexType(Type): type = module.get_type('INT32') type.make_fd_of(module, self, fd_name) continue + elif child.tag == 'length': + self.length_expr = Expression(list(child)[0], self) + continue else: # Hit this on Reply continue -- cgit v1.2.1