
On 03.04.2013 17:06, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Playing games with field offsets in a struct causes all sorts of alignment warnings on ARM platforms
util/virkeycode.c: In function '__virKeycodeValueFromString': util/virkeycode.c:26:7: warning: cast increases required alignment of target type [-Wcast-align] (*(typeof(field_type) *)((char *)(object) + field_offset)) ^ util/virkeycode.c:91:28: note: in expansion of macro 'getfield' const char *name = getfield(virKeycodes + i, const char *, name_offset); ^ util/virkeycode.c:26:7: warning: cast increases required alignment of target type [-Wcast-align] (*(typeof(field_type) *)((char *)(object) + field_offset)) ^ util/virkeycode.c:94:20: note: in expansion of macro 'getfield' return getfield(virKeycodes + i, unsigned short, code_offset); ^ util/virkeycode.c: In function '__virKeycodeValueTranslate': util/virkeycode.c:26:7: warning: cast increases required alignment of target type [-Wcast-align] (*(typeof(field_type) *)((char *)(object) + field_offset)) ^ util/virkeycode.c:127:13: note: in expansion of macro 'getfield' if (getfield(virKeycodes + i, unsigned short, from_offset) == key_value) ^ util/virkeycode.c:26:7: warning: cast increases required alignment of target type [-Wcast-align] (*(typeof(field_type) *)((char *)(object) + field_offset)) ^ util/virkeycode.c:128:20: note: in expansion of macro 'getfield' return getfield(virKeycodes + i, unsigned short, to_offset);
There is no compelling reason to use a struct for the keycode tables. It can easily just use an array of arrays instead, avoiding all alignment problems
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/virkeycode-mapgen.py | 78 ++++++++++++++++++------- src/util/virkeycode.c | 130 ++++++++++++++++++------------------------ 2 files changed, 110 insertions(+), 98 deletions(-)
diff --git a/src/util/virkeycode-mapgen.py b/src/util/virkeycode-mapgen.py index d3d2aae..34de637 100755 --- a/src/util/virkeycode-mapgen.py +++ b/src/util/virkeycode-mapgen.py @@ -13,7 +13,22 @@ instead of keymaps.csv which is a mirror. import sys import re
-namecolums = (0,2,10) +cols = ( + ["linux", True], + ["linux", False], + ["os_x", True], + ["os_x", False], + ["atset1", False], + ["atset2", False], + ["atset3", False], + ["xt", False], + ["xt_kbd", False], + ["usb", False], + ["win32", True], + ["win32", False], + ["rfb", False], +) + xtkbdkey_index = 8
def quotestring(str): @@ -28,29 +43,48 @@ print ''' # error do not use this; it is not a public header #endif
-struct keycode virKeycodes[] = { '''
sys.stdin.readline() # eat the fist line.
+keycodes = [] + +max = 0 + for line in sys.stdin.xreadlines(): - a = re.match("([^,]*)," * 13 + "([^,]*)$", line[0:-1]).groups() - b = "" - rfbkey = 0 - for i in namecolums: - b = b + (a[i] and quotestring(a[i]) or 'NULL') + ',' - for i in [ x for x in range(12) if not x in namecolums ]: - b = b + (a[i] or '0') + ',' - if i == xtkbdkey_index: - # RFB keycodes are XT kbd keycodes with a slightly - # different encoding of 0xe0 scan codes. RFB uses - # the high bit of the first byte, instead of the low - # bit of the second byte. - rfbkey = int(a[i] or '0') - rfbkey = (rfbkey & 0x100) >> 1 | (rfbkey & 0x7f) - - # Append RFB keycode as the last column - b = b + str(rfbkey) - print " { " + b + "}," - -print '};' + values = re.match("([^,]*)," * 13 + "([^,]*)$", line[0:-1]).groups() + + data = [] + for v in values: + data.append(v) + + # RFB keycodes are XT kbd keycodes with a slightly + # different encoding of 0xe0 scan codes. RFB uses + # the high bit of the first byte, instead of the low + # bit of the second byte. + rfbkey = int(data[xtkbdkey_index] or '0') + rfbkey = (rfbkey & 0x100) >> 1 | (rfbkey & 0x7f) + data.append(rfbkey) + + keycodes.append(data) + max = max + 1 + +print "#define VIR_KEYMAP_ENTRY_MAX " + str(max) + +for i in range(len(cols)): + col=cols[i] + name=col[0] + isname=col[1] + if isname: + print "const char *virKeymapNames_" + name + "[] = {" + else: + print "unsigned short virKeymapValues_" + name + "[] = {" + + for entry in keycodes: + if isname: + print " " + quotestring(entry[i] or "NULL") + "," + else: + print " " + (entry[i] or "0") + "," + + print "};\n" +
Empty line at EOF. Michal