mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-04-05 05:15:38 +00:00
Verify struct sizing at build time.
This commit is contained in:
parent
3730ddacac
commit
d17aed8e82
@ -142,6 +142,7 @@
|
|||||||
name: Request Header
|
name: Request Header
|
||||||
description: Packet format for inbound data.
|
description: Packet format for inbound data.
|
||||||
type: struct
|
type: struct
|
||||||
|
struct_length: 3
|
||||||
struct_members: [
|
struct_members: [
|
||||||
{
|
{
|
||||||
type: token
|
type: token
|
||||||
@ -158,6 +159,7 @@
|
|||||||
name: Response Header
|
name: Response Header
|
||||||
description: Packet format for inbound data.
|
description: Packet format for inbound data.
|
||||||
type: struct
|
type: struct
|
||||||
|
struct_length: 4
|
||||||
struct_members: [
|
struct_members: [
|
||||||
{
|
{
|
||||||
type: token
|
type: token
|
||||||
|
@ -83,6 +83,7 @@
|
|||||||
name: Broadcast Header
|
name: Broadcast Header
|
||||||
description: Packet format for broadcast messages.
|
description: Packet format for broadcast messages.
|
||||||
type: struct
|
type: struct
|
||||||
|
struct_length: 4
|
||||||
struct_members: [
|
struct_members: [
|
||||||
{
|
{
|
||||||
type: token
|
type: token
|
||||||
@ -240,6 +241,7 @@
|
|||||||
Retrieves the set of identifying information for the board.
|
Retrieves the set of identifying information for the board.
|
||||||
'''
|
'''
|
||||||
return_type: struct
|
return_type: struct
|
||||||
|
return_struct_length: 10
|
||||||
return_struct_members: [
|
return_struct_members: [
|
||||||
{
|
{
|
||||||
type: u16
|
type: u16
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
define: GET_KEYMAP_KEYCODE
|
define: GET_KEYMAP_KEYCODE
|
||||||
description: TODO
|
description: TODO
|
||||||
request_type: struct
|
request_type: struct
|
||||||
|
request_struct_length: 3
|
||||||
request_struct_members: [
|
request_struct_members: [
|
||||||
{
|
{
|
||||||
type: u8
|
type: u8
|
||||||
@ -61,6 +62,7 @@
|
|||||||
define: SET_KEYMAP_KEYCODE
|
define: SET_KEYMAP_KEYCODE
|
||||||
description: TODO
|
description: TODO
|
||||||
request_type: struct
|
request_type: struct
|
||||||
|
request_struct_length: 5
|
||||||
request_struct_members: [
|
request_struct_members: [
|
||||||
{
|
{
|
||||||
type: u8
|
type: u8
|
||||||
|
@ -133,6 +133,9 @@ def _append_route_types(lines, container, container_id=None, route_stack=None):
|
|||||||
lines.append(f' {member_type} {member_name};')
|
lines.append(f' {member_type} {member_name};')
|
||||||
lines.append(f'}} __attribute__((__packed__)) {route_name}_arg_t;')
|
lines.append(f'}} __attribute__((__packed__)) {route_name}_arg_t;')
|
||||||
|
|
||||||
|
req_len = container['request_struct_length']
|
||||||
|
lines.append(f'_Static_assert(sizeof({route_name}_arg_t) == {req_len}, "{route_name}_arg_t needs to be {req_len} bytes in size");')
|
||||||
|
|
||||||
elif 'request_type' in container:
|
elif 'request_type' in container:
|
||||||
request_type = container['request_type']
|
request_type = container['request_type']
|
||||||
found = re.search(r'(u\d+)\[(\d+)\]', request_type)
|
found = re.search(r'(u\d+)\[(\d+)\]', request_type)
|
||||||
@ -153,6 +156,9 @@ def _append_route_types(lines, container, container_id=None, route_stack=None):
|
|||||||
lines.append(f' {member_type} {member_name};')
|
lines.append(f' {member_type} {member_name};')
|
||||||
lines.append(f'}} __attribute__((__packed__)) {route_name}_t;')
|
lines.append(f'}} __attribute__((__packed__)) {route_name}_t;')
|
||||||
|
|
||||||
|
req_len = container['return_struct_length']
|
||||||
|
lines.append(f'_Static_assert(sizeof({route_name}_t) == {req_len}, "{route_name}_t needs to be {req_len} bytes in size");')
|
||||||
|
|
||||||
elif 'return_type' in container:
|
elif 'return_type' in container:
|
||||||
return_type = container['return_type']
|
return_type = container['return_type']
|
||||||
found = re.search(r'(u\d+)\[(\d+)\]', return_type)
|
found = re.search(r'(u\d+)\[(\d+)\]', return_type)
|
||||||
@ -213,6 +219,9 @@ def _append_internal_types(lines, container):
|
|||||||
member_type = additional_types[member["type"]]
|
member_type = additional_types[member["type"]]
|
||||||
lines.append(f' {member_type} {member_name};')
|
lines.append(f' {member_type} {member_name};')
|
||||||
lines.append(f'}} __attribute__((__packed__)) xap_{key}_t;')
|
lines.append(f'}} __attribute__((__packed__)) xap_{key}_t;')
|
||||||
|
|
||||||
|
req_len = value['struct_length']
|
||||||
|
lines.append(f'_Static_assert(sizeof(xap_{key}_t) == {req_len}, "xap_{key}_t needs to be {req_len} bytes in size");')
|
||||||
else:
|
else:
|
||||||
lines.append(f'typedef {data_type} xap_{key}_t;')
|
lines.append(f'typedef {data_type} xap_{key}_t;')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user