X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fc_client.py;h=161cbf59d6b1aae0450e402347fe58940355d867;hb=e7263931aff3e3450dc938ad465a7577f943549f;hp=cc26f72f9483be35fcbe4d975fd52a948787f2b7;hpb=7b53fb0f9bddae77b3ab8823743db57faee4e99b;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/c_client.py b/src/c_client.py index cc26f72..161cbf5 100644 --- a/src/c_client.py +++ b/src/c_client.py @@ -303,6 +303,7 @@ def _c_type_setup(self, name, postfix): self.c_reply_name = _n(name + ('reply',)) self.c_reply_type = _t(name + ('reply',)) self.c_cookie_type = _t(name + ('cookie',)) + self.c_reply_fds_name = _n(name + ('reply_fds',)) self.need_aux = False self.need_serialize = False @@ -980,15 +981,22 @@ def _c_serialize_helper_fields(context, self, # fields with variable size else: - # switch/bitcase: always calculate padding before and after variable sized fields - if need_padding or is_bitcase: + if field.type.is_pad: + # Variable length pad is + code_lines.append('%s xcb_align_to = %d;' % (space, field.type.align)) count += _c_serialize_helper_insert_padding(context, code_lines, space, + self.var_followed_by_fixed_fields) + continue + else: + # switch/bitcase: always calculate padding before and after variable sized fields + if need_padding or is_bitcase: + count += _c_serialize_helper_insert_padding(context, code_lines, space, self.var_followed_by_fixed_fields) - value, length = _c_serialize_helper_fields_variable_size(context, self, field, - code_lines, temp_vars, - space, prefix) - prev_field_was_variable = True + value, length = _c_serialize_helper_fields_variable_size(context, self, field, + code_lines, temp_vars, + space, prefix) + prev_field_was_variable = True # save (un)serialization C code if '' != value: @@ -1060,8 +1068,8 @@ def _c_serialize_helper(context, complex_type, if context in ('unserialize', 'unpack', 'sizeof') and not self.var_followed_by_fixed_fields: code_lines.append('%s xcb_block_len += sizeof(%s);' % (space, self.c_type)) code_lines.append('%s xcb_tmp += xcb_block_len;' % space) - # probably not needed - #_c_serialize_helper_insert_padding(context, code_lines, space, False) + code_lines.append('%s xcb_buffer_len += xcb_block_len;' % space) + code_lines.append('%s xcb_block_len = 0;' % space) count += _c_serialize_helper_fields(context, self, code_lines, temp_vars, @@ -1739,10 +1747,11 @@ def _c_accessors(self, name, base): # else: if True: for field in self.fields: - if field.type.is_list and not field.type.fixed_size(): - _c_accessors_list(self, field) - elif field.prev_varsized_field is not None or not field.type.fixed_size(): - _c_accessors_field(self, field) + if not field.type.is_pad: + if field.type.is_list and not field.type.fixed_size(): + _c_accessors_list(self, field) + elif field.prev_varsized_field is not None or not field.type.fixed_size(): + _c_accessors_field(self, field) def c_simple(self, name): ''' @@ -1761,7 +1770,7 @@ def c_simple(self, name): # Iterator _c_iterator(self, name) -def _c_complex(self): +def _c_complex(self, force_packed = False): ''' Helper function for handling all structure types. Called for all structs, requests, replies, events, errors. @@ -1816,7 +1825,7 @@ def _c_complex(self): if b.type.has_name: _h(' } %s;', b.c_field_name) - _h('} %s;', self.c_type) + _h('} %s%s;', 'XCB_PACKED ' if force_packed else '', self.c_type) def c_struct(self, name): ''' @@ -1835,7 +1844,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): +def _c_request_helper(self, name, cookie_type, void, regular, aux=False, reply_fds=False): ''' Declares a request function. ''' @@ -1864,6 +1873,12 @@ def _c_request_helper(self, name, cookie_type, void, regular, aux=False): # What flag is passed to xcb_request func_flags = '0' if (void and regular) or (not void and not regular) else 'XCB_REQUEST_CHECKED' + if reply_fds: + if func_flags == '0': + func_flags = 'XCB_REQUEST_REPLY_FDS' + else: + func_flags = func_flags + '|XCB_REQUEST_REPLY_FDS' + # Global extension id variable or NULL for xproto func_ext_global = '&' + _ns.c_ext_global_name if _ns.is_ext else '0' @@ -2256,6 +2271,51 @@ def _c_reply(self, name): _c('}') +def _c_reply_has_fds(self): + for field in self.fields: + if field.isfd: + return True + return False + +def _c_reply_fds(self, name): + ''' + Declares the function that returns fds related to the reply. + ''' + spacing1 = ' ' * (len(self.c_reply_type) - len('xcb_connection_t')) + spacing3 = ' ' * (len(self.c_reply_fds_name) + 2) + _h('') + _h('/**') + _h(' * Return the reply fds') + _h(' * @param c The connection') + _h(' * @param reply The reply') + _h(' *') + _h(' * Returns the array of reply fds of the request asked by') + _h(' * ') + _h(' * The returned value must be freed by the caller using free().') + _h(' */') + _c('') + _hc('') + _hc('/*****************************************************************************') + _hc(' **') + _hc(' ** int * %s', self.c_reply_fds_name) + _hc(' ** ') + _hc(' ** @param xcb_connection_t%s *c', spacing1) + _hc(' ** @param %s *reply', self.c_reply_type) + _hc(' ** @returns int *') + _hc(' **') + _hc(' *****************************************************************************/') + _hc(' ') + _hc('int *') + _hc('%s (xcb_connection_t%s *c /**< */,', self.c_reply_fds_name, spacing1) + _h('%s%s *reply /**< */);', spacing3, self.c_reply_type) + _c('%s%s *reply /**< */)', spacing3, self.c_reply_type) + _c('{') + + _c(' return xcb_get_reply_fds(c, reply, sizeof(%s) + 4 * reply->length);', self.c_reply_type) + + _c('}') + + def _c_opcode(name, opcode): ''' Declares the opcode define for requests, events, and errors. @@ -2816,14 +2876,17 @@ def c_request(self, name): # Reply structure definition _c_complex(self.reply) # Request prototypes - _c_request_helper(self, name, self.c_cookie_type, False, True) - _c_request_helper(self, name, self.c_cookie_type, False, False) + 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) if self.need_aux: - _c_request_helper(self, name, self.c_cookie_type, False, True, True) - _c_request_helper(self, name, self.c_cookie_type, False, False, True) + _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) # Reply accessors _c_accessors(self.reply, name + ('reply',), name) _c_reply(self, name) + if has_fds: + _c_reply_fds(self, name) else: # Request prototypes _c_request_helper(self, name, 'xcb_void_cookie_t', True, False) @@ -2847,6 +2910,7 @@ def c_event(self, name): # events while generating the structure for them. Otherwise we would read # garbage (the internal full_sequence) when accessing normal event fields # there. + force_packed = False if hasattr(self, 'is_ge_event') and self.is_ge_event and self.name == name: event_size = 0 for field in self.fields: @@ -2856,6 +2920,11 @@ def c_event(self, name): full_sequence = Field(tcard32, tcard32.name, 'full_sequence', False, True, True) idx = self.fields.index(field) self.fields.insert(idx + 1, full_sequence) + + # If the event contains any 64-bit extended fields, they need + # to remain aligned on a 64-bit boundary. Adding full_sequence + # would normally break that; force the struct to be packed. + force_packed = any(f.type.size == 8 and f.type.is_simple for f in self.fields[(idx+1):]) break _c_type_setup(self, name, ('event',)) @@ -2865,7 +2934,7 @@ def c_event(self, name): if self.name == name: # Structure definition - _c_complex(self) + _c_complex(self, force_packed) else: # Typedef _h('')