summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2020-07-11 09:58:21 +0200
committerUli Schlachter <psychon@znc.in>2021-09-30 17:15:34 +0000
commit6d72110e1eddf4e802aff3442b7b58f471175ceb (patch)
treee072910d36fec2c1a86931904ca228ec9fe4d85c
parent151ee69847c706e2b9d38c82e20534910f140b55 (diff)
downloadxcb-proto-6d72110e1eddf4e802aff3442b7b58f471175ceb.tar.gz
Add missing fields to errors
All X11 errors have the same fields. There are no differences. In a perfect world, the XML could thus just say "define an error" and xcbgen would do all the rest. However, the world is imperfect and we already have a mixture of fields defined in the XML. Some of the XML even defines trailing padding, while most does not. This commit makes xcbgen add all fields to X11 errors, but those that are already defined in the XML are skipped and left as-is. Due to the structure of the code, this requires pretending that a different XML was read, i.e. the code now modifies the in-memory structure of ElementTree to add the missing fields to the in-memory representation of the XML. This is the simplest way that I found to append elements. The existing mechanisms can only prepend fields. The approach taken by this commit was suggested by Peter Harris. Thanks a lot for this idea, it's a lot simpler than my previous approach. Fixes: https://gitlab.freedesktop.org/xorg/proto/xcbproto/-/issues/16 Signed-off-by: Uli Schlachter <psychon@znc.in>
-rw-r--r--xcbgen/xtypes.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 3359a09..0d92f2e 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -3,6 +3,7 @@ This module contains the classes which represent XCB data types.
'''
from xcbgen.expr import Field, Expression
from xcbgen.align import Alignment, AlignmentLog
+from xml.etree.ElementTree import SubElement
import __main__
verbose_align_log = False
@@ -1352,6 +1353,15 @@ class Error(ComplexType):
if self.required_start_align is None:
self.required_start_align = Alignment(4,0)
+ # All errors are basically the same, but they still got different XML
+ # for historic reasons. This 'invents' the missing parts.
+ if len(self.elt) < 1:
+ SubElement(self.elt, "field", type="CARD32", name="bad_value")
+ if len(self.elt) < 2:
+ SubElement(self.elt, "field", type="CARD16", name="minor_opcode")
+ if len(self.elt) < 3:
+ SubElement(self.elt, "field", type="CARD8", name="major_opcode")
+
def add_opcode(self, opcode, name, main):
self.opcodes[name] = opcode
if main: