[Xcb] parametrized structs implemented

Christian Linhart chris at DemoRecorder.com
Mon Sep 8 06:57:01 PDT 2014

Hi all,

I have implemented parametrized structs now.

I'll post the patches in this thread.
This includes the xml-def for the GetDeviceMotionEvents-reply
with its parametrized struct DeviceTimeCoord. So there's
an example to to test.

You can also get these patches, including all of my prior patches, at the following git-repos:

Branch: ParametrizedStruct

The actual branch to be used can have a version added.
such as "ParametrizedStruct-V4".
Always use the branch with the highest version, please.

A testcase for the GetDeviceMotionEvents-reply is attached to this email.
I have also attached a diff which shows the changes in the C-code
caused by these patches.

Implementing the parametrized structs turned out 
to be somewhat easier than previously thought 
because the generator already had some support for type-parametrization
because this is needed when case or bitcase refers to fields outside 
of the switch.

So I decided to go with the flow and to implement the solution 
which best fits the current implementation.

I did the following:
* I provided a way to specify fieldref with an explicitely given type:
  This resulted in <paramref type="CARD8>fieldname</paramref>
  A paramref is just a fieldref with an explicit type.
  The type is necessary because there is no local field of that
  name where the type can be derived from.

* then I tested it and made several changes in the generator
  such that it really works.

Basically the generated code is as follows:
* The parameter appears on the parameter list of the 
  sizeof-function of the parametrized struct.
  When that function gets called, an appropriate argument is supplied.

* The parameter also appears as an additional member of the iterator-struct
  for the iterator of lists of that parametrized struct.
  This way, the next-function can get the value of that parameter from the iterator.
  When the iterator is created, this iterator-member is set accordingly.

* When the paramref appears in the length-expression of a list, then
  the parameter appears on the parameterlist of the "length" and "end" functions.
  When these functions get called, an appropriate argument is supplied.

Some comments:
* I did not implement inline structs. 
  This would probably have been more complicated, and at least some additional effort.
  But that can be implemented later if needed.
  (Inline structs could probably use some code from switch-case/bitcase which is already kind of
  an inlined struct but one has to be careful not to break the functionality 
  of switch-case/bitcase. Support for inline structs inside lists must probably
  be implemented from scratch...)

* The paramref expression refers to a field of the same name in the struct/request/... 
  where it is used.
  So it is not possible to pass the value of arbitrary fields or even expressions
  to the parametrized struct.
  This would have been possible with the previously discussed <typearg>.
  That can be added later, if needed.
  ( Wont be too complicated )

* So this is pretty much like the proposal from Ran Benita.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: param-struct-c-code-changes.diff
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20140908/de5105ee/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20140908/de5105ee/attachment-0003.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xinput-test.c
Type: text/x-csrc
Size: 15956 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20140908/de5105ee/attachment-0001.c>

More information about the Xcb mailing list