[Xcb-commit] xcb/proto: 2 commits - xcbgen
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Sep 30 17:16:32 UTC 2021
xcbgen/xtypes.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
New commits:
commit 65169c1af7893882c21d1e2a544903212b8d6fb0
Author: Uli Schlachter <psychon at znc.in>
Date: Fri Jul 17 15:31:58 2020 +0200
Use xml.etree.cElementTree where appropriate
This makes the code added in the previous commit consistent with the
rest of the code base. From Björn's suggestion:
This should import xml.etree.{,c}ElementTree conditionally on the
version of the Python interpreter used to import this module.
xml.etree.ElementTree is preferred for Python >= 3.3, as it uses the
fastest possible implementation automatically. Earlier versions of
Python need xml.etree.cElementTree as they may not have an
implementation that can be used in a platform generic way.
Suggested-by: Björn Esser <besser82 at fedoraproject.org>
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 0d92f2e..c8c4e01 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -3,7 +3,12 @@ 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
+
+if version_info[:2] >= (3, 3):
+ from xml.etree.ElementTree import SubElement
+else:
+ from xml.etree.cElementTree import SubElement
+
import __main__
verbose_align_log = False
commit 6d72110e1eddf4e802aff3442b7b58f471175ceb
Author: Uli Schlachter <psychon at znc.in>
Date: Sat Jul 11 09:58:21 2020 +0200
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 at znc.in>
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:
More information about the xcb-commit
mailing list