[Xcb-commit] xcb/proto: 2 commits - doc src xcbgen
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Sep 17 13:54:58 UTC 2021
doc/xml-xcb.txt | 21 +++++++++++++++++++--
src/xcb.xsd | 8 ++++++++
src/xinput.xml | 6 ++++++
xcbgen/xtypes.py | 6 ++++++
4 files changed, 39 insertions(+), 2 deletions(-)
New commits:
commit f0db8b7d31a379fe26f6cc592be997c8ce5f0b2d
Author: Povilas Kanapickas <povilas at radix.lt>
Date: Fri Jul 30 22:48:48 2021 +0300
xinput: Add length specification for DeviceClass struct
diff --git a/src/xinput.xml b/src/xinput.xml
index 5f88a98..3610645 100644
--- a/src/xinput.xml
+++ b/src/xinput.xml
@@ -1689,6 +1689,12 @@ authorization from the authors.
</struct>
<struct name="DeviceClass">
+ <length>
+ <op op="*">
+ <fieldref>len</fieldref>
+ <value>4</value>
+ </op>
+ </length>
<field type="CARD16" name="type" enum="DeviceClassType" />
<field type="CARD16" name="len" />
<field type="DeviceId" name="sourceid" />
commit c36dde3f4535e948318edc843faeee118492b38e
Author: Povilas Kanapickas <povilas at radix.lt>
Date: Fri Jul 30 22:48:47 2021 +0300
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 <switch> 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.
diff --git a/doc/xml-xcb.txt b/doc/xml-xcb.txt
index f5b9aed..baef734 100644
--- a/doc/xml-xcb.txt
+++ b/doc/xml-xcb.txt
@@ -65,8 +65,8 @@ Top-Level Elements
This element represents a data structure. The name attribute gives the name
of the structure. The content represents the fields of the structure, and
- consists of one or more of the field, pad, and list elements described in
- the section "Structure Contents" below.
+ consists of one or more of the length, field, pad, and list elements described
+ in the section "Structure Contents" below.
<union name="identifier">structure contents</union>
@@ -215,6 +215,23 @@ enum; the value is restricted to one of the constants named in the enum.
declares the data type of the field, and the name attribute gives the name
of the field.
+<length>expression</length>
+ This element overrides the length of the data structure by specifying it
+ explicitly instead of it being defined by the layout of the structure.
+ This makes it possible to handle structures with conditional fields
+ (see the <switch> element) where the future revisions of protocols may
+ introduce new variants and old code must still properly ignore them.
+
+ The content is an expression giving the length of the data structure in terms
+ of other fields in the structure. See the section "Expressions" for details
+ on the expression representation.
+
+ The expression must not depend on conditional fields.
+
+ Additionally, the length of the data structure must be at least such that it
+ includes the fields that the expression depends on. Smaller length is
+ considered a violation of the protocol.
+
<fd name="identifier" />
This element represents a file descriptor field passed with the request. The
diff --git a/src/xcb.xsd b/src/xcb.xsd
index dc3d7cc..86a51c5 100644
--- a/src/xcb.xsd
+++ b/src/xcb.xsd
@@ -101,6 +101,13 @@ authorization from the authors.
<!-- field replaces FIELD, PARAM, and REPLY. -->
<xsd:element name="field" type="var" />
+ <!-- Length of data structures -->
+ <xsd:element name="length">
+ <xsd:complexType>
+ <xsd:group ref="expression" />
+ </xsd:complexType>
+ </xsd:element>
+
<!-- fd passing parameter -->
<xsd:element name="fd">
<xsd:complexType>
@@ -210,6 +217,7 @@ authorization from the authors.
<xsd:element ref="list" />
<xsd:element ref="fd" />
<xsd:element ref="required_start_align" />
+ <xsd:element ref="length" />
</xsd:choice>
</xsd:group>
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
More information about the xcb-commit
mailing list