Force XCB event structures with 64-bit extended fields to be packed.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 3 Jan 2014 23:08:33 +0000 (15:08 -0800)
committerAlan Coopersmith <alan.coopersmith@oracle.com>
Fri, 3 Jan 2014 23:31:19 +0000 (15:31 -0800)
commit3b72a2c9d1d656c74c691a45689e1d637f669e3a
tree85f45fe0c247fc7d331c8fdf306688b00d2c62ea
parent010872f611a044ced4e96b18a7514796b2a443df
Force XCB event structures with 64-bit extended fields to be packed.

With the advent of the Present extension, some events (such as
PresentCompleteNotify) now use native 64-bit types on the wire.

For XGE events, we insert an extra "uint32_t full_sequence" field
immediately after the first 32 bytes of data.  Normally, this causes
the subsequent fields to be shifted over by 4 bytes, and the structure
to grow in size by 4 bytes.  Everything works fine.

However, if event contains 64-bit extended fields, this may result in
the compiler adding an extra 4 bytes of padding so that those fields
remain aligned on 64-bit boundaries.  This causes the structure to grow
by 8 bytes, not 4.  Unfortunately, XCB doesn't realize this, and
always believes that the length only increased by 4.  read_packet()
then fails to malloc enough memory to hold the event, and the event
processing code uses the wrong offsets.

To fix this, mark any event structures containing 64-bit extended
fields with __attribute__((__packed__)).

v2: Use any(...) instead of True in (...), as suggested by
    Daniel Martin.

v3 (Alan Coopersmith): Fix build with Solaris Studio 12.3 by moving the
attribute to after the structure definition.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Keith Packard <keithp@keithp.com> [v1]
Reviewed-by: Josh Triplett <josh@joshtriplett.org> [v1]
Reviewed-by: Daniel Martin <consume.noise@gmail.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
src/c_client.py
src/xcb.h