[Xcb] Compile time asserts to catch things like: [Bug 23403] compiler padding causes reply parsing to use incorrect offsets

Uli Schlachter psychon at znc.in
Tue Oct 31 11:42:05 UTC 2017


Hi everyone,

due to the recent activity on [1], I wrote the attached patch. It adds
compile time asserts checking that sizeof() various things is as
expected. The full list of failures is also attached (but some of these
are still bugs with my patch, i.e. I doubt sizeof(xcb_xkb_get_map_map_t)
== 0 should hold).

I only took a quick look at the result of the patch.
xcb_sync_systemcounter_t (the subject of bug 23403) is spotted. The
first two GLX-related things are about structs with uint8_t fields at
their end. I didn't look closer than this at the results.

Should something like this be added to libxcb eventually? Does anyone
want to look at these? For example, the compiler-added padding at the
end of xcb_*_request_t either is correct or sending this request never
worked correctly in the first place, so should be possible to add to the
XML.

>From the total 38 failures, there are 11 failures for requests. 2 for
errors (both in SYNC), 4 in replies, and 21 "remaining" failures.

Cheers,
Uli

P.S.: I don't know python and I don't know the python code around
xcb/proto. The attached patch was written by trial and error, and by
hacking around until xproto.c compiled. I bet/hope someone with an
actual clue about the code can come up with a nicer patch.

[1]: https://bugs.freedesktop.org/show_bug.cgi?id=23403
-- 
A learning experience is one of those things that say,
'You know that thing you just did? Don't do that.'
                     -- Douglas Adams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_struct_sizes.patch
Type: text/x-diff
Size: 1473 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20171031/41211548/attachment.patch>
-------------- next part --------------
sizeof(xcb_glx_read_pixels_request_t) == 34
sizeof(xcb_glx_get_pixel_mapusv_reply_t) == 34
sizeof(xcb_glx_get_polygon_stipple_request_t) == 9
sizeof(xcb_glx_get_tex_image_request_t) == 25
sizeof(xcb_glx_get_color_table_request_t) == 21
sizeof(xcb_glx_get_convolution_filter_request_t) == 21
sizeof(xcb_glx_get_separable_filter_request_t) == 21
sizeof(xcb_glx_get_histogram_request_t) == 22
sizeof(xcb_glx_get_minmax_request_t) == 22
sizeof(xcb_randr_get_monitors_request_t) == 9
sizeof(xcb_sync_systemcounter_t) == 14
sizeof(xcb_sync_counter_error_t) == 11
sizeof(xcb_sync_alarm_error_t) == 11
sizeof(xcb_sync_create_fence_request_t) == 13
sizeof(xcb_xf86dri_query_direct_rendering_capable_reply_t) == 9
sizeof(xcb_input_input_info_info_t) == 14
sizeof(xcb_input_ungrab_device_key_request_t) == 13
sizeof(xcb_input_feedback_state_data_t) == 88
sizeof(xcb_input_feedback_ctl_data_t) == 48
sizeof(xcb_input_input_state_data_t) == 70
sizeof(xcb_input_device_state_data_t) == 68
sizeof(xcb_input_device_ctl_data_t) == 68
sizeof(xcb_input_change_device_property_items_t) == 0
sizeof(xcb_input_get_device_property_items_t) == 0
sizeof(xcb_input_hierarchy_change_data_t) == 20
sizeof(xcb_input_device_class_data_t) == 62
sizeof(xcb_input_xi_change_property_items_t) == 0
sizeof(xcb_input_xi_get_property_items_t) == 0
sizeof(xcb_xkb_select_events_details_t) == 50
sizeof(xcb_xkb_get_map_map_t) == 0
sizeof(xcb_xkb_set_map_values_t) == 0
sizeof(xcb_xkb_get_names_value_list_t) == 24
sizeof(xcb_xkb_set_names_values_t) == 24
sizeof(xcb_xkb_get_kbd_by_name_replies_types_map_t) == 0
sizeof(xcb_xkb_get_kbd_by_name_replies_key_names_value_list_t) == 24
sizeof(xcb_xkb_get_kbd_by_name_replies_t) == 168
sizeof(xcb_xkb_get_device_info_reply_t) == 34
sizeof(xcb_test_get_version_reply_t) == 10


More information about the Xcb mailing list