summaryrefslogtreecommitdiff
path: root/xcbgen
Commit message (Collapse)AuthorAgeFilesLines
* Fix python version check from 65169c1af7893882c21d1e2a544903212b8d6fb0Alex Richardson2021-10-041-1/+2
| | | | | With commit 65169c1af7893882c21d1e2a544903212b8d6fb0, I am seeing build failures in libxcb, using sys.version_info fixes those.
* Use xml.etree.cElementTree where appropriateUli Schlachter2021-09-301-1/+6
| | | | | | | | | | | | | | | 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@fedoraproject.org>
* Add missing fields to errorsUli Schlachter2021-09-301-0/+10
| | | | | | | | | | | | | | | | | | | | | | | 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>
* Add element to specify expression that defines length of a structPovilas Kanapickas2021-09-021-0/+6
| | | | | | | | | | | | | | | | 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.
* xcbgen: Use xml.etree.ElementTree for Python >= 3.3.Björn Esser2020-06-042-2/+2
| | | | | | | | | | | | | | In commit 7d58eed95f796fc764741d7549ee2214bbbcc64c we started to use xml.etree.ElementTree for Python >= 3.9. In fact the xml.etree.cElementTree module has already been deprecated since Python 3.3. Given this fact, we should start to use the xml.etree.ElementTree module beginning with Python 3.3. See: https://github.com/python/cpython/commit/a72a98f24a19928e31dcc4cab2cd2ad0f1846e11 Signed-off-by: Björn Esser <besser82@fedoraproject.org>
* xcbgen: xml.etree.cElementTree has been dropped in Python 3.9.Björn Esser2020-06-012-2/+12
| | | | | | It can be replaced with xml.etree.ElementTree safely. Signed-off-by: Björn Esser <besser82@fedoraproject.org>
* xcbgen: Use math.gcd() for Python >= 3.5.Björn Esser2020-06-011-1/+6
| | | | | | | | fractions.gcd() has been deprecated since Python 3.5, and was finally dropped in Python 3.9. It is recommended to use math.gcd() instead. Signed-off-by: Björn Esser <besser82@fedoraproject.org>
* Parse a field's "enum=" correctlyUli Schlachter2020-03-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | In xv.xml, there is something like this: <struct name="ImageFormatInfo"> [...] <field type="CARD8" name="byte_order" enum="ImageOrder" /> <pad bytes="2" /> <list type="CARD8" name="guid"> <value>16</value> </list> [...] </struct> When parsing this, the Field instance for "guid" ended up with .enum == "ImageOrder". This is because the loop that parses complex type did not unset a variable across iterations, meaning that the last "enum" property "stuck" and was also used for all following fields. Fix this by simply moving the initialisation of the "enum" variable inside of the loop. Signed-off-by: Uli Schlachter <psychon@znc.in>
* Allow access to the original type in the XMLUli Schlachter2019-12-282-19/+22
| | | | | | | | | | | | | | | | | | | | | | | | | xcbgen 'helpfully' transforms things to C types already so that libxcb does not have to do so. Thus, even though the XML says that a field has type CARD8, xcbgen will claim uint8_t. This might be a bit weird, but is so far totally fine. However, the type mapping that xcbgen uses is not injective. All of CARD8, BYTE and BOOL get turned into uint8_t and the original type is lost. This is totally fine for libxcb, but programming languages other than C do have built in boolean types. My personal problem is with Rust, where providing a boolean for an integer argument causes a compiler error. This results in (relatively) ugly "0 / 1" instead of "false / true". This commit adds a new xml_type member to SimpleType. This type contains the original string that appeared in the XML file. Since libxcb creates instances of SimpleType itself and to avoid breaking the API, the new argument to SimpleType.__init__ defaults to None. Signed-off-by: Uli Schlachter <psychon@znc.in>
* Fix size computation of imported listsUli Schlachter2019-12-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | XFixes contains a CreateRegion request: <request name="CreateRegion" opcode="5"> <field type="REGION" name="region" /> <list type="RECTANGLE" name="rectangles" /> </request> This request contains a list of type RECTANGLE. This struct comes from xproto and is thus not contained in xfixes itself. Normal "Struct"s have their resolve() method called early, because they appear in the module itself. However, in the CreateRegion case, this struct is imported and thus does not get resolved. Instead, ListType's resolve() method calls self.member.resolve(module). Thus, only at this point is the struct resolved. Why is this important? Struct.resolve() is the same as ComplexType.resolve() and this function does self.calc_size() at the end. Thus, only after the struct was resolved is its size known. Before that, the size is just set to 0 (this happens in ComplexType.__init__). However, ListType.__init__ already computes its size member based on its member. At this point, this is still 0 so the list ends up believing its size to be zero. Fix this by recomputing self.size in ListType.resolve(). Signed-off-by: Uli Schlachter <psychon@znc.in>
* Removed unused member "fds"Uli Schlachter2019-11-021-1/+0
| | | | | | | According to git grep '\.fds', this does not appear anywhere else in xcb-proto or libxcb. Signed-off-by: Uli Schlachter <psychon@znc.in>
* xcbgen: Add support for lists of FDsDaniel Stone2017-06-051-4/+24
| | | | | | | | | | Add a special case in ListType to support lists of file descriptors, which also requires explicit support within clients. File descriptors are not supported as children of other complex types, e.g. switch. Signed-off-by: Daniel Stone <daniels@collabora.com>
* add support for eventstructChristian Linhart2017-03-113-0/+135
| | | | | | | | | | eventstruct is a new xml element that allows to use events as part of requests. This is, e.g., needed by the SendExtensionEvent request of the XINPUT extension. Signed-off-by: Christian Linhart <chris@demorecorder.com>
* move symboltable lookup of sumof expr to the parserChristian Linhart2017-03-111-0/+1
| | | | | | | | | | Set the lenfield of a sumof expression object, so that libxcb or other generators won't need to look it up. This object is trivially available in the parser but needs a complex lookup in generators. Signed-off-by: Christian Linhart <chris@demorecorder.com>
* print() is a function and needs parentheses.Thomas Klausner2016-05-281-6/+6
| | | | | | | Fixes build with python-3.x. Signed-off-by: Thomas Klausner <wiz@NetBSD.org> Signed-off-by: Uli Schlachter <psychon@znc.in>
* Make whitespace use consistent.Thomas Klausner2016-05-281-48/+48
| | | | | | | At least python-3.5.x complains about this forcefully. Signed-off-by: Thomas Klausner <wiz@NetBSD.org> Signed-off-by: Uli Schlachter <psychon@znc.in>
* optionally enforce serialization of padsChristian Linhart2016-01-271-0/+2
| | | | | | | | | | | | | From now on, due to a patch in libxcb, pads will not be serialized anymore. This is to maintain ABI-compatibility when adding explicit align pads. However, some align pads were already be serialized in prior official versions of libxcb. Therefore we need a method to enforce serialization, so we can maintainn ABI compatibility with that legacy. Signed-off-by: Christian Linhart <chris@demorecorder.com>
* calculate lengthless listJaya Tiwari2016-01-061-0/+7
| | | | | | | Some rework done by Christian Linhart Signed-off-by: Jaya Tiwari <tiwari.jaya18@gmail.com> Signed-off-by: Christian Linhart <chris@demorecorder.com>
* automatic alignment checker / manual offsetsChristian Linhart2016-01-064-23/+757
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The verification algorithm basically traverses the protocol-description of a protocol entity by recursively processing all fields and their types. A start-align consists of two numbers: * the alignment: This is a power of 2, and guarantees that the address (or protocol position) minus the offset can be divided by this number. * the offset: how many bytes the current position is after a position that can be divided by the alignment. The algorithm starts with the start-alignment and computes the alignment of each field from the start-align of the previous field as follows: * if the previous field is a primitive type then the offset is increased by the size of the primitive type module the alignment. If the alignment or offset are incompatible with the primitive type, then an error is reported. * if the previous field is a complex type, then it is processed recursively. * if the previous field is an alignment-pad, then the alignment is adjusted accordingly, as to be expected by the alignment-pad. Start-aligns can also be set manually with the xml-element "required_start_align" which has two attributes: "align" and "offset" If "offset" is omitted, it is assumed to 0. All toplevel protocol entities default to 4-byte start-alignment with offset 0. All non-toplevel complex entities, such as structs, switch, case, ... do not have a default alignment. If no alignment is explicitly specified for them, their alignment is computed by their usage in other entities. In that case, if they are used with aligments that violate the alignment requirements of some of their fields, an error is issued. If they are used with an alignment with non-zero offset, a warning is issued, which recommends to specify the required_start_align explicitly. (Reason: I don't want non-zero offsets to be silently computed automatically. These non-zero offsets have to be reviewed by a human and specified explicitely to record that this was reviewed by a human) If the required_start_align is explicitly specified for an entity then an error will be issued if it is used with an aligment that's incompatible with the explicitly specified alignment. If an entity is used in different contexts with different start-aligns then those start-aligns are combined to an align which is compatible with all aligns. E.g. (align 4, offset 0) and (align 4, offset 2) are combined to (align 2, offset 0). Error reports include the relevant context for a misalignment. For non-toplevel entities this includes the entity-usage stack. There is some complexity in the algorithm for reducing the size of the error-reports to include only the relevant info. This alignment verifier is also a prerequisite for getting rid of implicit alignment altogether. (This will then simplify the generated code and make it faster.) Signed-off-by: Christian Linhart <chris@demorecorder.com>
* Remove valueparam support from xcbgen parsers and schema definitionJaya Tiwari2015-02-222-14/+0
| | | | | | | | | Removed all the valueparam occurences from parsers and xml schema as well along with all the protocol definitions as valueparam has been replaced by switch bit-case Signed-off-by: Jaya Tiwari <tiwari.jaya18@gmail.com> Reviewed-by: Christian Linhart <chris@demorecorder.com>
* xcbgen: support paramref in the parserChristian Linhart2014-11-031-0/+4
| | | | | | | | | | | paramref is similar to fieldref, but has a type attribute. Message-ID: <1410136150-30254-1-git-send-email-chris@demorecorder.com> Patch-Thread-Subject: [Xcb] parametrized structs implemented Patch-Set: ParametrizedStruct Patch-Number: proto 1/5 Patch-Version: V1 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
* xcbgen: new expr-type listelement-refChristian Linhart2014-11-031-0/+15
| | | | | | | | | | | | | | | | | | Add parser-support for the new expression-type "listelement-ref" which represents the current list-element when used inside a list-iteration expression such as <sumof>. This patch includes computation of the flag "contains_listelement_ref" which is set to True when an expression or any of its subexpressions is a listelement-ref. (This is needed by the generator) Message-ID: <1409845742-38797-2-git-send-email-chris@demorecorder.com> Patch-Thread-Subject: [Xcb] support popcount of a list and associated xml changes Patch-Set: PopcountList Patch-Number: proto 2/8 Patch-Version: V1 Signed-off-by: Christian Linhart <chris@DemoRecorder.com>
* xcbgen: sumof with nested expressionChristian Linhart2014-11-031-0/+6
| | | | | | | | | | | | | | | | | | | | Add parser support for sumof with a nested expression. For example: <sumof ref="mylist1"> <fieldref>bar</fieldref> </sumof> The nested expression is added as the "rhs"-field of the expression.object. Signed-off-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <545627E1.8070302@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: proto 4/8 Patch-Version: V1
* xcbgen: fields get a parent referenceChristian Linhart2014-11-032-0/+2
| | | | | | | | | | | | | | | Objects of type Field get a reference to their parent. This is needed in the generator to differentiate field handling dependend on properties of their parent. Signed-off-by: Christian Linhart <chris@demorecorder.com> Reviewed-by: Ran Benita <ran234@gmail.com> Message-ID: <545627CB.1000606@DemoRecorder.com> Patch-Thread-Subject: [Xcb] [PATCHSET] ListInputDevices revision 2 Patch-Set: ListInputDevices Patch-Number: proto 1/8 Patch-Version: V1
* xcbgen-parser: support switch-caseChristian Linhart2014-08-252-7/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | "case" is implemented as a variation of "bitcase" as follows: The old class "BitCaseType" became the abstract class "CaseOrBitcaseType" with two derived classes "CaseType" and "BitcaseType". (Therefore BitcaseType keeps the old semantic which may be important for some generators) There are two additional flags in class Type: * is_case * is_case_or_bitcase The latter is for convenience because case and bitcase have to be treated the same way in many cases. The list of cases and bitcases in a SwitchType object is still called "bitcases". Reasons: * Renaming that list would break generators based on the parser. * Creating an extra list for cases would make other code more complicated because you usually want to iterate over all case and bitcase members of a switch. Reviewed-by: Ran Benita <ran234@gmail.com>
* Also track directly imported modules in a separate listKeith Packard2014-02-192-0/+6
| | | | | | | | | This allows the generated header files to only include the directly referenced header files, with the indirectly referenced header files included by the directly referenced ones. Signed-off-by: Keith Packard <keithp@keithp.com> Signed-off-by: Uli Schlachter <psychon@znc.in>
* Support <pad align="n" />Peter Harris2014-01-211-2/+6
| | | | | Reviewed-By: Ran Benita <ran234@gmail.com> Signed-off-by: Peter Harris <pharris@opentext.com>
* Track pad count at the module levelPeter Harris2014-01-212-4/+5
| | | | | | | | If the pad count is reset for each bitcase, the names will collide in the encompasing switch struct. Reviewed-By: Ran Benita <ran234@gmail.com> Signed-off-by: Peter Harris <pharris@opentext.com>
* xcbgen: Remove tab from xtypes.py.Matt Turner2013-11-141-1/+1
| | | | Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=71418
* Add support for file descriptor request fieldsKeith Packard2013-11-072-2/+21
| | | | | | | These are present in the API, but not present on the wire. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
* Add CARD64/INT64 protocol typesKeith Packard2013-11-062-0/+4
| | | | | | | | No reason to make people use two 32-bit values when every modern compiler has native 64-bit objects. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
* Add support for X Generic Extension eventsDaniel Martin2013-07-121-5/+21
| | | | | | | | | | | With these patches, we are able to mark an XGE event as such and generate the correct header for it. XGE events can be found in the X Input Extension v2++. Signed-off-by: Daniel Martin <consume.noise@gmail.com> Reviewed-by: Keith Packard <keithp@keithp.com> Signed-off-by: Peter Harris <pharris@opentext.com>
* xcbgen: Handle multiple <enumref> in a <bitcase>Daniel Martin2013-05-231-4/+11
| | | | | | | | | | Adopt the XML schema change from commit ee71d96 Allow multiple <enumref> in a <bitcase> and its usage with commit b3b5e02 XKB: Fix GetKbdByName. Signed-off-by: Daniel Martin <consume.noise@gmail.com> Signed-off-by: Peter Harris <pharris@opentext.com>
* Simplify boolean attribute retrievalDaniel Martin2013-02-141-2/+1
|
* xproto: add doc tags, xcbgen: handle doc tagsMichael Stapelberg2012-03-262-12/+64
| | | | Signed-off-by: Julien Danjou <julien@danjou.info>
* Rename the ExprType "parent" attribute to "parents".Alex Plotnick2012-03-231-2/+2
| | | | | | | | This is fallout from commit 76ca2c0b1527541be59c344118c538ba055ad9d8, which renamed the *parent parameter of ExprType.__init__, but failed to rename the instance attribute to which it was assigned. Signed-off-by: Julien Danjou <julien@danjou.info>
* Use absolute imports in xcbgen for Python 3 compatibilityDavid Coles2011-05-033-6/+7
| | | | | | | | | Python 3 has stricter syntax for relative imports. Use absolute imports to ensure compatibility with all versions of Python. Also break cyclical module import between state.py and matcher.py by deferring import. Signed-off-by: David Coles <dcoles@gaikai.com> Signed-off-by: Julien Danjou <julien@danjou.info>
* xcbgen: small fix to store anchestor objects more systematicChristoph Reimann2010-08-161-8/+7
| | | | xml: small fixes according to Xlib or the spec
* small fix wrt bitcase type namesChristoph Reimann2010-08-021-5/+4
|
* support name attribute for bitcases and set BitcaseType.has_name accordinglyChristoph Reimann2010-07-221-1/+11
|
* assign switch name to bitcases as well (important in case of switch that ↵Christoph Reimann2010-07-152-4/+13
| | | | appear inside another switch)
* - changed handling of anchestor types (may be more than one now)Christoph Reimann2010-07-131-2/+147
| | | | - added SwitchType and BitcaseType
* add support for new expr tags popcount, enumref, sumofChristoph Reimann2010-07-131-1/+29
|
* xcbgen: perform lenfield lookup within all anchestorsChristoph Reimann2010-06-121-12/+15
|
* changed Exception message in case of unknown/unhandled XML tagsChristoph Reimann2010-05-221-2/+2
|
* xcbgen: Add unop supportMarcin Kościelnicki2010-05-141-1/+8
| | | | | Reviewed-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Julien Danjou <julien@danjou.info>
* Revive support for hex literals in protocolMikhail Gusarov2010-05-142-3/+3
| | | | | | | | | | | As a side-effect it also adds octal and binary literals. Exact syntax is described at http://docs.python.org/reference/lexical_analysis.html#numbers It is unwise to use full syntax, as there might be other binding generators, octal, binary and hex literals seem to be safe though. Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net> Signed-off-by: Julien Danjou <julien@danjou.info>
* Revert "made changes to support new value-mask-pad field of valueparam ↵Eamon Walsh2009-10-211-24/+4
| | | | | | | | | structures" This change fixes a ConfigureWindow request padding issue, but has a bug that affects xpyb (#24507). This reverts commit 57934caa3fb207320c33312646d8e98290950f51.
* Make bit-numbers available to code-generatorsCarsten Meier2008-09-031-0/+3
| | | | | | | The Enum-class now exports the bit numbers in the 'bits'-list if they have been specified in the protocol description. Signed-off-by: Bart Massey <bart@cs.pdx.edu>
* Generate values instead of shift-expressions for enum-bitsCarsten Meier2008-09-031-2/+1
| | | | | | | Now more language independent as some languages don't have C-like shift-operators. Signed-off-by: Bart Massey <bart@cs.pdx.edu>