aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src
diff options
context:
space:
mode:
Diffstat (limited to 'libxcb/src')
-rw-r--r--libxcb/src/c_client.py136
1 files changed, 47 insertions, 89 deletions
diff --git a/libxcb/src/c_client.py b/libxcb/src/c_client.py
index 8a2900c62..e55fc3c6b 100644
--- a/libxcb/src/c_client.py
+++ b/libxcb/src/c_client.py
@@ -1,12 +1,9 @@
#!/usr/bin/env python
-from xml.etree.cElementTree import *
-from os.path import basename
-from functools import reduce
+from __future__ import print_function
import getopt
import os
import sys
import errno
-import time
import re
# Jump to the bottom of this file for the main routine
@@ -529,7 +526,6 @@ def _c_type_setup(self, name, postfix):
if not module.namespace.is_ext or self.name[:2] == module.namespace.prefix:
finished_sizeof.append(self.c_sizeof_name)
_c_serialize('sizeof', self)
-# _c_type_setup()
# Functions for querying field properties
def _c_field_needs_list_accessor(field):
@@ -590,7 +586,6 @@ def _c_helper_fieldaccess_expr(prefix, field=None):
prefix_str += last_sep + _cpp(field.field_name)
return prefix_str
-# _c_absolute_name
def _c_helper_field_mapping(complex_type, prefix, flat=False):
"""
@@ -606,7 +601,7 @@ def _c_helper_field_mapping(complex_type, prefix, flat=False):
else:
bitcase_prefix = prefix
- if (True==flat and not b.type.has_name) or False==flat:
+ if (flat and not b.type.has_name) or not flat:
all_fields.update(_c_helper_field_mapping(b.type, bitcase_prefix, flat))
else:
for f in complex_type.fields:
@@ -615,7 +610,7 @@ def _c_helper_field_mapping(complex_type, prefix, flat=False):
raise Exception("field name %s has been registered before" % f.field_name)
all_fields[f.field_name] = (fname, f)
- if f.type.is_container and flat==False:
+ if f.type.is_container and not flat:
if f.type.is_case_or_bitcase and not f.type.has_name:
new_prefix = prefix
elif f.type.is_switch and len(f.type.parents)>1:
@@ -626,7 +621,6 @@ def _c_helper_field_mapping(complex_type, prefix, flat=False):
all_fields.update(_c_helper_field_mapping(f.type, new_prefix, flat))
return all_fields
-# _c_field_mapping()
def _c_helper_resolve_field_names (prefix):
"""
@@ -647,7 +641,6 @@ def _c_helper_resolve_field_names (prefix):
all_fields.update(_c_helper_field_mapping(obj, tmp_prefix, flat=True))
return all_fields
-# _c_helper_resolve_field_names
def get_expr_fields(self):
"""
@@ -692,13 +685,12 @@ def get_expr_fields(self):
prefix.append(('', '', self))
all_fields = _c_helper_resolve_field_names (prefix)
- resolved_fields_names = list(filter(lambda x: x in all_fields.keys(), unresolved_fields_names))
+ resolved_fields_names = [x for x in unresolved_fields_names if x in all_fields]
if len(unresolved_fields_names) != len(resolved_fields_names):
raise Exception("could not resolve all fields for %s" % self.name)
resolved_fields = [all_fields[n][1] for n in resolved_fields_names]
return resolved_fields
-# get_expr_fields()
def resolve_expr_fields(complex_obj):
"""
@@ -721,7 +713,6 @@ def resolve_expr_fields(complex_obj):
if e not in all_fields and e not in unresolved:
unresolved.append(e)
return unresolved
-# resolve_expr_fields()
def resolve_expr_fields_list(self, parents):
"""
@@ -825,7 +816,6 @@ def get_serialize_params(context, self, buffer_var='_buffer', aux_var='_aux'):
add_param(params, (p.c_field_const_type, '*', p.c_field_name))
return (param_fields, wire_fields, params)
-# get_serialize_params()
def _c_serialize_helper_insert_padding(context, code_lines, space, postpone, is_case_or_bitcase):
code_lines.append('%s /* insert padding */' % space)
@@ -836,7 +826,6 @@ def _c_serialize_helper_insert_padding(context, code_lines, space, postpone, is_
else:
code_lines.append(
'%s xcb_pad = -xcb_block_len & (xcb_align_to - 1);' % space)
-# code_lines.append('%s printf("automatically inserting padding: %%%%d\\n", xcb_pad);' % space)
code_lines.append('%s xcb_buffer_len += xcb_block_len + xcb_pad;' % space)
if not postpone:
@@ -858,7 +847,6 @@ def _c_serialize_helper_insert_padding(context, code_lines, space, postpone, is_
# keep tracking of xcb_parts entries for serialize
return 1
-# _c_serialize_helper_insert_padding()
def _c_serialize_helper_switch(context, self, complex_name,
code_lines, temp_vars,
@@ -911,14 +899,12 @@ def _c_serialize_helper_switch(context, self, complex_name,
# code_lines.append('%s xcb_buffer_len += xcb_block_len + xcb_pad;' % space)
return count
-# _c_serialize_helper_switch
def _c_serialize_helper_switch_field(context, self, field, c_switch_variable, prefix):
"""
handle switch by calling _serialize() or _unpack(), depending on context
"""
# switch is handled by this function as a special case
- param_fields, wire_fields, params = get_serialize_params(context, self)
field_mapping = _c_helper_field_mapping(self, prefix)
prefix_str = _c_helper_fieldaccess_expr(prefix)
@@ -955,7 +941,6 @@ def _c_serialize_helper_switch_field(context, self, field, c_switch_variable, pr
length = "%s(xcb_tmp, %s)" % (field.type.c_sizeof_name, my_c_field_names)
return length
-# _c_serialize_helper_switch_field()
def _c_get_additional_type_params(type):
"""
@@ -979,8 +964,8 @@ def _c_serialize_helper_list_field(context, self, field,
param_names = [p[2] for p in params]
expr_fields_names = [f.field_name for f in get_expr_fields(field.type)]
- resolved = list(filter(lambda x: x in param_names, expr_fields_names))
- unresolved = list(filter(lambda x: x not in param_names, expr_fields_names))
+ resolved = [x for x in expr_fields_names if x in param_names]
+ unresolved = [x for x in expr_fields_names if x not in param_names]
field_mapping = {}
for r in resolved:
@@ -993,8 +978,8 @@ def _c_serialize_helper_list_field(context, self, field,
field.c_field_name)
field_mapping.update(_c_helper_resolve_field_names(prefix))
- resolved += list(filter(lambda x: x in field_mapping, unresolved))
- unresolved = list(filter(lambda x: x not in field_mapping, unresolved))
+ resolved += [x for x in unresolved if x in field_mapping]
+ unresolved = [x for x in unresolved if x not in field_mapping]
if len(unresolved)>0:
raise Exception('could not resolve the length fields required for list %s' % field.c_field_name)
@@ -1040,7 +1025,6 @@ def _c_serialize_helper_list_field(context, self, field,
code_lines.append('%s xcb_block_len = xcb_parts[xcb_parts_idx].iov_len;' % space)
return length
-# _c_serialize_helper_list_field()
def _c_serialize_helper_fields_fixed_size(context, self, field,
code_lines, temp_vars,
@@ -1050,7 +1034,7 @@ def _c_serialize_helper_fields_fixed_size(context, self, field,
code_lines.append('%s /* %s.%s */' % (space, self.c_type, field.c_field_name))
else:
scoped_name = [p[2].c_type if idx==0 else p[0] for idx, p in enumerate(prefix)]
- typename = reduce(lambda x,y: "%s.%s" % (x, y), scoped_name)
+ typename = ".".join(scoped_name)
code_lines.append('%s /* %s.%s */' % (space, typename, field.c_field_name))
abs_field_name = _c_helper_fieldaccess_expr(prefix, field)
@@ -1110,7 +1094,6 @@ def _c_serialize_helper_fields_fixed_size(context, self, field,
length = '%d' % field.type.nmemb
return (value, length)
-# _c_serialize_helper_fields_fixed_size()
def _c_serialize_helper_fields_variable_size(context, self, field,
code_lines, temp_vars,
@@ -1163,7 +1146,6 @@ def _c_serialize_helper_fields_variable_size(context, self, field,
length = "%s(%s)" % (field.type.c_sizeof_name, var_field_name)
return (value, length)
-# _c_serialize_helper_fields_variable_size
def _c_serialize_helper_fields(context, self,
code_lines, temp_vars,
@@ -1265,7 +1247,6 @@ def _c_serialize_helper_fields(context, self,
_c_pre.pop_indent()
return count
-# _c_serialize_helper_fields()
def _c_serialize_helper(context, complex_type,
code_lines, temp_vars,
@@ -1305,7 +1286,6 @@ def _c_serialize_helper(context, complex_type,
count += _c_serialize_helper_insert_padding(context, code_lines, space, False, self.is_switch)
return count
-# _c_serialize_helper()
def _c_serialize(context, self):
"""
@@ -1339,8 +1319,7 @@ def _c_serialize(context, self):
if not field.type.fixed_size() or self.is_switch:
variable_size_fields += 1
# determine maxtypelen
- for p in params:
- maxtypelen = max(maxtypelen, len(p[0]) + len(p[1]))
+ maxtypelen = max(len(p[0]) + len(p[1]) for p in params)
# write to .c/.h
indent = ' '*(len(func_name)+2)
@@ -1351,7 +1330,7 @@ def _c_serialize(context, self):
param_str.append("%s%s%s %s%s /**< */" % (indent, typespec, spacing, pointerspec, field_name))
# insert function name
param_str[0] = "%s (%s" % (func_name, param_str[0].strip())
- param_str = list(map(lambda x: "%s," % x, param_str))
+ param_str = ["%s," % x for x in param_str]
for s in param_str[:-1]:
_hc(s)
_h("%s);" % param_str[-1].rstrip(','))
@@ -1407,13 +1386,13 @@ def _c_serialize(context, self):
if self.is_switch:
# switch: call _unpack()
_c(' %s _aux;', self.c_type)
- _c(' return %s(%s, &_aux);', self.c_unpack_name, reduce(lambda x,y: "%s, %s" % (x, y), param_names))
+ _c(' return %s(%s, &_aux);', self.c_unpack_name, ", ".join(param_names))
_c('}')
_c_pre.redirect_end()
return
elif self.c_var_followed_by_fixed_fields:
# special case: call _unserialize()
- _c(' return %s(%s, NULL);', self.c_unserialize_name, reduce(lambda x,y: "%s, %s" % (x, y), param_names))
+ _c(' return %s(%s, NULL);', self.c_unserialize_name, ", ".join(param_names))
_c('}')
_c_pre.redirect_end()
return
@@ -1440,7 +1419,7 @@ def _c_serialize(context, self):
if not (self.is_switch or self.c_var_followed_by_fixed_fields):
# look if we have to declare an '_aux' variable at all
- if len(list(filter(lambda x: x.find('_aux')!=-1, code_lines)))>0:
+ if any('_aux' in x for x in code_lines):
if not self.c_var_followed_by_fixed_fields:
_c(' const %s *_aux = (%s *)_buffer;', self.c_type, self.c_type)
else:
@@ -1514,7 +1493,6 @@ def _c_serialize(context, self):
_c('')
_c(' return xcb_buffer_len;')
_c('}')
-# _c_serialize()
def _c_iterator_get_end(field, accum):
'''
@@ -1672,7 +1650,6 @@ def _c_accessor_get_expr(expr, field_mapping):
return c_name
elif expr.op == 'sumof':
# locate the referenced list object
- list_obj = expr.lenfield_type
field = None
for f in expr.lenfield_parent.fields:
if f.field_name == expr.lenfield_name:
@@ -1813,14 +1790,13 @@ def _c_accessors_list(self, field):
'''
def get_align_pad(field):
- prev = field.prev_varsized_field
- prev_prev = field.prev_varsized_field.prev_varsized_field
-
- if (prev.type.is_pad and prev.type.align > 0 and prev_prev is not None):
- return (prev_prev, '((-prev.index) & (%d - 1))' % prev.type.align)
- else:
- return (prev, None)
+ prev = field.prev_varsized_field
+ prev_prev = field.prev_varsized_field.prev_varsized_field
+ if prev.type.is_pad and prev.type.align > 0 and prev_prev is not None:
+ return (prev_prev, '((-prev.index) & (%d - 1))' % prev.type.align)
+ else:
+ return (prev, None)
list = field.type
c_type = self.c_type
@@ -1857,8 +1833,7 @@ def _c_accessors_list(self, field):
fields.update(_c_helper_field_mapping(toplevel_switch, [('S', '->', toplevel_switch)], flat=True))
# initialize prefix for everything "below" S
- prefix_str = '/* %s */ S' % toplevel_switch.name[-1]
- prefix = [(prefix_str, '->', toplevel_switch)]
+ prefix = [('S', '->', toplevel_switch)]
# look for fields in the remaining containers
for p in parents[2:] + [self]:
@@ -2071,12 +2046,8 @@ def _c_complex(self, force_packed = False):
struct_fields = []
maxtypelen = 0
- varfield = None
for field in self.fields:
- if not field.type.fixed_size() and not self.is_switch and not self.is_union:
- varfield = field.c_field_name
- continue
- if field.wire:
+ if field.wire and (field.type.fixed_size() or self.is_switch or self.is_union):
struct_fields.append(field)
for field in struct_fields:
@@ -2130,7 +2101,7 @@ def c_union(self, name):
_c_complex(self)
_c_iterator(self, name)
-def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_fds=False):
+def _c_request_helper(self, name, void, regular, aux=False, reply_fds=False):
'''
Declares a request function.
'''
@@ -2268,7 +2239,7 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
_h(' * placed in the event queue.')
_h(' */')
_c('')
- _hc('%s', cookie_type)
+ _hc('%s', func_cookie)
spacing = ' ' * (maxtypelen - len('xcb_connection_t'))
comma = ',' if len(param_fields) else ');'
@@ -2305,10 +2276,10 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
_c('{')
_c(' static const xcb_protocol_request_t xcb_req = {')
- _c(' /* count */ %d,', count)
- _c(' /* ext */ %s,', func_ext_global)
- _c(' /* opcode */ %s,', self.c_request_name.upper())
- _c(' /* isvoid */ %d', 1 if void else 0)
+ _c(' .count = %d,', count)
+ _c(' .ext = %s,', func_ext_global)
+ _c(' .opcode = %s,', self.c_request_name.upper())
+ _c(' .isvoid = %d', 1 if void else 0)
_c(' };')
_c('')
@@ -2328,8 +2299,6 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
_c(' unsigned int xcb_tmp_len;')
_c(' char *xcb_tmp;')
_c('')
- # simple request call tracing
-# _c(' printf("in function %s\\n");' % func_name)
# fixed size fields
for field in wire_fields:
@@ -2351,7 +2320,7 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
serialize_args = get_serialize_params(context, type_obj,
c_field_name,
aux_var)[2]
- return reduce(lambda x,y: "%s, %s" % (x,y), [a[2] for a in serialize_args])
+ return ", ".join(a[2] for a in serialize_args)
# calls in order to free dyn. all. memory
free_calls = []
@@ -2379,7 +2348,6 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_f
else:
list_length = _c_accessor_get_expr(field.type.expr, None)
- length = ''
_c(" xcb_parts[%d].iov_len = 0;" % count)
_c(" xcb_tmp = (char *)%s;", field.c_field_name)
_c(" for(i=0; i<%s; i++) {" % list_length)
@@ -2526,10 +2494,7 @@ def _c_reply(self, name):
_c('}')
def _c_reply_has_fds(self):
- for field in self.fields:
- if field.isfd:
- return True
- return False
+ return any(field.isfd for field in self.fields)
def _c_reply_fds(self, name):
'''
@@ -2581,7 +2546,7 @@ def _c_cookie(self, name):
_h(' unsigned int sequence; /**< */')
_h('} %s;', self.c_cookie_type)
-def _man_request(self, name, cookie_type, void, aux):
+def _man_request(self, name, void, aux):
param_fields = [f for f in self.fields if f.visible]
func_name = self.c_request_name if not aux else self.c_aux_name
@@ -2627,7 +2592,8 @@ def _man_request(self, name, cookie_type, void, aux):
f.write('.SS Request function\n')
f.write('.HP\n')
base_func_name = self.c_request_name if not aux else self.c_aux_name
- f.write('%s \\fB%s\\fP(xcb_connection_t\\ *\\fIconn\\fP, %s\n' % (cookie_type, base_func_name, prototype))
+ func_cookie = 'xcb_void_cookie_t' if void else self.c_cookie_type
+ f.write('%s \\fB%s\\fP(xcb_connection_t\\ *\\fIconn\\fP, %s\n' % (func_cookie, base_func_name, prototype))
create_link('%s_%s' % (base_func_name, ('checked' if void else 'unchecked')))
if not void:
f.write('.PP\n')
@@ -2674,8 +2640,7 @@ def _man_request(self, name, cookie_type, void, aux):
for field in b.type.fields:
_c_complex_field(self, field, space)
if b.type.has_name:
- print >> sys.stderr, 'ERROR: New unhandled documentation case'
- pass
+ print('ERROR: New unhandled documentation case\n', file=sys.stderr)
f.write('} \\fB%s\\fP;\n' % self.reply.c_type)
f.write('.fi\n')
@@ -2744,8 +2709,6 @@ def _man_request(self, name, cookie_type, void, aux):
# 'R': parents[0] is always the 'toplevel' container type
params.append(('const %s *\\fIreply\\fP' % parents[0].c_type, parents[0]))
fields.update(_c_helper_field_mapping(parents[0], [('R', '->', parents[0])], flat=True))
- # auxiliary object for 'R' parameters
- R_obj = parents[0]
if switch_obj is not None:
# now look where the fields are defined that are needed to evaluate
@@ -2758,8 +2721,7 @@ def _man_request(self, name, cookie_type, void, aux):
fields.update(_c_helper_field_mapping(toplevel_switch, [('S', '->', toplevel_switch)], flat=True))
# initialize prefix for everything "below" S
- prefix_str = '/* %s */ S' % toplevel_switch.name[-1]
- prefix = [(prefix_str, '->', toplevel_switch)]
+ prefix = [('S', '->', toplevel_switch)]
# look for fields in the remaining containers
for p in parents[2:] + [self]:
@@ -2769,9 +2731,6 @@ def _man_request(self, name, cookie_type, void, aux):
prefix.append((p.name[-1], '.', p))
fields.update(_c_helper_field_mapping(p, prefix, flat=True))
- # auxiliary object for 'S' parameter
- S_obj = parents[1]
-
if list.member.fixed_size():
idx = 1 if switch_obj is not None else 0
f.write('.HP\n')
@@ -2930,7 +2889,7 @@ def _man_request(self, name, cookie_type, void, aux):
'handle errors in the event loop instead, use '
'\\fI%s_unchecked\\fP. See \\fBxcb-requests(%s)\\fP for '
'details.\n') %
- (cookie_type, self.c_reply_name, base_func_name, section))
+ (self.c_cookie_type, self.c_reply_name, base_func_name, section))
f.write('.SH ERRORS\n')
if hasattr(self, "doc") and self.doc:
for errtype, errtext in sorted(self.doc.errors.items()):
@@ -3012,7 +2971,7 @@ def _man_event(self, name):
spacing = ' ' * (maxtypelen - len(field.c_field_type))
f.write('%s %s%s \\fI%s\\fP%s;\n' % (space, field.c_field_type, spacing, field.c_field_name, field.c_subscript))
else:
- print >> sys.stderr, 'ERROR: New unhandled documentation case'
+ print('ERROR: New unhandled documentation case', file=sys.stderr)
if not self.is_switch:
for field in struct_fields:
@@ -3025,7 +2984,7 @@ def _man_event(self, name):
for field in b.type.fields:
_c_complex_field(self, field, space)
if b.type.has_name:
- print >> sys.stderr, 'ERROR: New unhandled documentation case'
+ print('ERROR: New unhandled documentation case', file=sys.stderr)
pass
f.write('} \\fB%s\\fP;\n' % self.c_type)
@@ -3120,11 +3079,11 @@ def c_request(self, name):
_c_complex(self.reply)
# Request prototypes
has_fds = _c_reply_has_fds(self.reply)
- _c_request_helper(self, name, self.c_cookie_type, False, True, False, has_fds)
- _c_request_helper(self, name, self.c_cookie_type, False, False, False, has_fds)
+ _c_request_helper(self, name, void=False, regular=True, aux=False, reply_fds=has_fds)
+ _c_request_helper(self, name, void=False, regular=False, aux=False, reply_fds=has_fds)
if self.c_need_aux:
- _c_request_helper(self, name, self.c_cookie_type, False, True, True, has_fds)
- _c_request_helper(self, name, self.c_cookie_type, False, False, True, has_fds)
+ _c_request_helper(self, name, void=False, regular=True, aux=True, reply_fs=has_fds)
+ _c_request_helper(self, name, void=False, regular=False, aux=True, reply_fs=has_fds)
# Reply accessors
_c_accessors(self.reply, name + ('reply',), name)
_c_reply(self, name)
@@ -3132,17 +3091,16 @@ def c_request(self, name):
_c_reply_fds(self, name)
else:
# Request prototypes
- _c_request_helper(self, name, 'xcb_void_cookie_t', True, False)
- _c_request_helper(self, name, 'xcb_void_cookie_t', True, True)
+ _c_request_helper(self, name, void=True, regular=False)
+ _c_request_helper(self, name, void=True, regular=True)
if self.c_need_aux:
- _c_request_helper(self, name, 'xcb_void_cookie_t', True, False, True)
- _c_request_helper(self, name, 'xcb_void_cookie_t', True, True, True)
+ _c_request_helper(self, name, void=True, regular=False, aux=True)
+ _c_request_helper(self, name, void=True, regular=True, aux=True)
_c_accessors(self, name, name)
# We generate the manpage afterwards because _c_type_setup has been called.
# TODO: what about aux helpers?
- cookie_type = self.c_cookie_type if self.reply else 'xcb_void_cookie_t'
- _man_request(self, name, cookie_type, not self.reply, False)
+ _man_request(self, name, void=not self.reply, aux=False)
def c_event(self, name):
'''