[libxcb,v2,3/4] c_client: Add support for lists of FDs

Submitted by Daniel Stone on June 8, 2017, 6:41 p.m.

Details

Message ID 20170608184111.4704-4-daniels@collabora.com
State New
Headers show
Series "Support lists of FDs, DRI3 v1.1" ( rev: 1 ) in XCB

Not browsing as part of any series.

Commit Message

Daniel Stone June 8, 2017, 6:41 p.m.
Matching xcbgen changes, add support having a ListType which contains
file descriptors. Use this to send a variable number of FDs to the
server, including when the list size is not fixed.

Signed-off-by: Daniel Stone <daniels@collabora.com>
---
 src/c_client.py | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

v2: No changes.

Patch hide | download patch | download mbox

diff --git a/src/c_client.py b/src/c_client.py
index f3fa5b1..2213a31 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -2340,12 +2340,30 @@  def _c_request_helper(self, name, void, regular, aux=False, reply_fds=False):
         if aux:
             _c('    void *xcb_aux%d = 0;' % (idx))
     if list_with_var_size_elems:
-        _c('    unsigned int i;')
         _c('    unsigned int xcb_tmp_len;')
         _c('    char *xcb_tmp;')
-    num_fds = len([field for field in param_fields if field.isfd])
-    if num_fds > 0:
-        _c('    int fds[%d];' % (num_fds))
+
+    num_fds_fixed = 0
+    num_fds_expr = []
+    for field in param_fields:
+        if field.isfd:
+            if not field.type.is_list:
+                num_fds_fixed += 1
+            else:
+                num_fds_expr.append(_c_accessor_get_expr(field.type.expr, None))
+
+    if list_with_var_size_elems or len(num_fds_expr) > 0:
+        _c('    unsigned int i;')
+
+    if num_fds_fixed > 0:
+        num_fds_expr.append('%d' % (num_fds_fixed))
+    if len(num_fds_expr) > 0:
+        num_fds = '+'.join(num_fds_expr)
+        _c('    int fds[%s];' % (num_fds))
+        _c('    int fd_index = 0;')
+    else:
+        num_fds = None
+
     _c('')
 
     # fixed size fields
@@ -2451,16 +2469,18 @@  def _c_request_helper(self, name, void, regular, aux=False, reply_fds=False):
         # no padding necessary - _serialize() keeps track of padding automatically
 
     _c('')
-    fd_index = 0
     for field in param_fields:
         if field.isfd:
-            _c('    fds[%d] = %s;', fd_index, field.c_field_name)
-            fd_index = fd_index + 1
+            if not field.type.is_list:
+                _c('    fds[fd_index++] = %s;', field.c_field_name)
+            else:
+                _c('    for (i = 0; i < %s; i++)', _c_accessor_get_expr(field.type.expr, None))
+                _c('        fds[fd_index++] = %s[i];', field.c_field_name)
 
-    if num_fds == 0:
+    if not num_fds:
         _c('    xcb_ret.sequence = xcb_send_request(c, %s, xcb_parts + 2, &xcb_req);', func_flags)
     else:
-        _c('    xcb_ret.sequence = xcb_send_request_with_fds(c, %s, xcb_parts + 2, &xcb_req, %d, fds);', func_flags, num_fds)
+        _c('    xcb_ret.sequence = xcb_send_request_with_fds(c, %s, xcb_parts + 2, &xcb_req, %s, fds);', func_flags, num_fds)
 
     # free dyn. all. data, if any
     for f in free_calls:

Comments

Daniel Stone <daniels@collabora.com> writes:

> Matching xcbgen changes, add support having a ListType which contains
> file descriptors. Use this to send a variable number of FDs to the
> server, including when the list size is not fixed.
>
> Signed-off-by: Daniel Stone <daniels@collabora.com>

I've verified that patch 1 and 2 don't change the generated code, that
this patch only cosmetically changes the code, and that the generated
code for patch 4 looks reasonable.

I find the python to be pretty hairy, but it seems fine, and it's really
the generated code that matters, so patch 1-3 are:

Reviewed-by: Eric Anholt <eric@anholt.net>
Hi Eric,

On 17 June 2017 at 02:11, Eric Anholt <eric@anholt.net> wrote:
> Daniel Stone <daniels@collabora.com> writes:
>> Matching xcbgen changes, add support having a ListType which contains
>> file descriptors. Use this to send a variable number of FDs to the
>> server, including when the list size is not fixed.
>
> I've verified that patch 1 and 2 don't change the generated code, that
> this patch only cosmetically changes the code, and that the generated
> code for patch 4 looks reasonable.
>
> I find the python to be pretty hairy, but it seems fine, and it's really
> the generated code that matters, so patch 1-3 are:
>
> Reviewed-by: Eric Anholt <eric@anholt.net>

Thanks for the review! FWIW, I find the Python quite hairy as well,
but after a couple of attempted reworks, couldn't find anything which
worked better.

Uli, would you be OK pushing these first 3 support patches, or would
you prefer I did, or ... ?

Cheers,
Daniel
On 20.07.2017 19:15, Daniel Stone wrote:
> Hi Eric,
> 
> On 17 June 2017 at 02:11, Eric Anholt <eric@anholt.net> wrote:
>> Daniel Stone <daniels@collabora.com> writes:
>>> Matching xcbgen changes, add support having a ListType which contains
>>> file descriptors. Use this to send a variable number of FDs to the
>>> server, including when the list size is not fixed.
>>
>> I've verified that patch 1 and 2 don't change the generated code, that
>> this patch only cosmetically changes the code, and that the generated
>> code for patch 4 looks reasonable.
>>
>> I find the python to be pretty hairy, but it seems fine, and it's really
>> the generated code that matters, so patch 1-3 are:
>>
>> Reviewed-by: Eric Anholt <eric@anholt.net>
> 
> Thanks for the review! FWIW, I find the Python quite hairy as well,
> but after a couple of attempted reworks, couldn't find anything which
> worked better.
> 
> Uli, would you be OK pushing these first 3 support patches, or would
> you prefer I did, or ... ?

I'd think that it is less work overall if you push them since you
already have them in Git. Also, I usually try to stay away from the
Python code around XCB. :-)

So, feel free to push them.

Uli
Hi Uli,

On 22 July 2017 at 12:12, Uli Schlachter <psychon@znc.in> wrote:
> On 20.07.2017 19:15, Daniel Stone wrote:
>> On 17 June 2017 at 02:11, Eric Anholt <eric@anholt.net> wrote:
>>> I've verified that patch 1 and 2 don't change the generated code, that
>>> this patch only cosmetically changes the code, and that the generated
>>> code for patch 4 looks reasonable.
>>>
>>> I find the python to be pretty hairy, but it seems fine, and it's really
>>> the generated code that matters, so patch 1-3 are:
>>>
>>> Reviewed-by: Eric Anholt <eric@anholt.net>
>>
>> Thanks for the review! FWIW, I find the Python quite hairy as well,
>> but after a couple of attempted reworks, couldn't find anything which
>> worked better.
>>
>> Uli, would you be OK pushing these first 3 support patches, or would
>> you prefer I did, or ... ?
>
> I'd think that it is less work overall if you push them since you
> already have them in Git. Also, I usually try to stay away from the
> Python code around XCB. :-)
>
> So, feel free to push them.

Thanks a lot! I've pushed both sets of preparatory patches now, so
there's just the actual DRI3 protocol pending.

To ssh://git.freedesktop.org/git/xcb/proto
   1c05de5..9df4ead  9df4eadb482be083c66c856e9c7f38331d50a2b4 -> master

To ssh://git.freedesktop.org/git/xcb/libxcb
   d10194a..a3e9821  master -> master

Cheers,
Daniel