From 7eab2517633605d06c390183b497bbc8f28eaad5 Mon Sep 17 00:00:00 2001 From: Edward Hesketh Date: Sun, 6 Oct 2024 01:27:46 +0100 Subject: [PATCH] BREAKING: attempting to fix usage of pointers --- CMakeLists.txt | 1 + include/squirrel_key.h | 15 ++- include/squirrel_quantum.h | 48 +++------ src/squirrel_init.c | 18 +--- src/squirrel_key.c | 19 ++-- src/squirrel_keymap.c | 68 ++++-------- src/squirrel_quantum.c | 126 ++++++---------------- tests/key.c | 10 +- tests/multikey.c | 14 +-- tests/quantum_passthrough_press_release.c | 10 +- 10 files changed, 102 insertions(+), 227 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d81f64..6326228 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_compile_options(-Og) # Enable debug optimizations elseif(CMAKE_BUILD_TYPE STREQUAL "Testing") message(STATUS "Testing enabled") + add_compile_options(-O3) # Don't include test code in coverage percent. include(CTest) enable_testing() diff --git a/include/squirrel_key.h b/include/squirrel_key.h index 41f7e85..534ed62 100644 --- a/include/squirrel_key.h +++ b/include/squirrel_key.h @@ -5,15 +5,12 @@ struct key { enum squirrel_error (*pressed)(struct key *, uint8_t layer, uint8_t key_index, - int arg_count, - void **args); // called when the key is pressed - void **pressed_arguments; // arguments to pass to pressed - int pressed_argument_count; // the amount of arguments in pressed_arguments - enum squirrel_error (*released)( - struct key *, uint8_t layer, uint8_t key_index, int arg_count, - void **args); // called when the key is released - void **released_arguments; // arguments to pass to released - int released_argument_count; // the amount of arguments in released_arguments + void *arg); // called when the key is pressed + void *pressed_argument; // argument to pass to pressed + enum squirrel_error (*released)(struct key *, uint8_t layer, + uint8_t key_index, + void *arg); // called when the key is released + void *released_argument; // argument to pass to released }; extern int key_count; // number of keys on the keyboard diff --git a/include/squirrel_quantum.h b/include/squirrel_quantum.h index 51d916b..e811948 100644 --- a/include/squirrel_quantum.h +++ b/include/squirrel_quantum.h @@ -7,8 +7,8 @@ #include struct layer { - struct key *keys; // array of keys in this layer - bool active; // true if this layer is currently active + bool active; // true if this layer is currently active + struct key *keys[]; // array of keys in this layer }; // layers is a list of all the layers in the keyboard. 0-15 are configured, @@ -17,91 +17,77 @@ extern struct layer layers[17]; // key_nop does nothing (no operation) enum squirrel_error key_nop(struct key *key, uint8_t layer, uint8_t key_index, - int arg_count, void **args); + void *arg); // keyboard_press expects a single uint8 keycode enum squirrel_error keyboard_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // keyboard_release expects a single uint8 keycode enum squirrel_error keyboard_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // keyboard_modifier_press expects a single uint8 modifier enum squirrel_error keyboard_modifier_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // keyboard_modifier_release expects a single uint8 modifier enum squirrel_error keyboard_modifier_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // consumer_press expects a single uint16 consumer code. See // https://www.freebsddiary.org/APC/usb_hid_usages for all defined codes. enum squirrel_error consumer_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // consumer_release expects a single uint16 consumer code. See // https://www.freebsddiary.org/APC/usb_hid_usages for all defined codes. enum squirrel_error consumer_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // quantum_passthrough_press passes the press action to the highest active layer // below the current one. It expectes no extra args. Equivalent to KC_TRNS in // QMK. enum squirrel_error quantum_passthrough_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // quantum_passthrough_release passes the release action to the highest active // layer below the current one. It expectes no extra args. Equivalent to KC_TRNS // in QMK. enum squirrel_error quantum_passthrough_release(struct key *key, uint8_t layer, - uint8_t key_index, - int arg_count, void **args); + uint8_t key_index, void *arg); // layer_momentary_press activates the layer with the given index. It expects // the layer number as the first uint8 argument. Equivalent to MO() in QMK. enum squirrel_error layer_momentary_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // layer_momentary_release deactivates the layer with the given index. It // expects the layer number as the first uint8 argument. Equivalent to MO() in // QMK. enum squirrel_error layer_momentary_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // layer_toggle_press toggles the layer with the given index. It expects the // layer number as the first uint8 argument. Equivalent to TG() in QMK. enum squirrel_error layer_toggle_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // layer_toggle_release does nothing at the moment. It expects the layer number // as a uint8 anyway - this is a placeholder for future functionality. // Equivalent to TG() in QMK. enum squirrel_error layer_toggle_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // layer_solo_press turns off all other layers than the layer with the given // index. It expects the layer number as the first uint8 argument. Equivalent to // TO() in QMK. enum squirrel_error layer_solo_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); // layer_solo_release does nothing at the moment. It expects the layer number // as a uint8 anyway - this is a placeholder for future functionality. // Equivalent to TO() in QMK. enum squirrel_error layer_solo_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args); + uint8_t key_index, void *arg); #endif diff --git a/src/squirrel_init.c b/src/squirrel_init.c index 665ed51..4d24c22 100644 --- a/src/squirrel_init.c +++ b/src/squirrel_init.c @@ -8,20 +8,12 @@ enum squirrel_error squirrel_init(int total_keys) { key_count = total_keys; - struct key passthrough_key; - passthrough_key.pressed = quantum_passthrough_press; - passthrough_key.pressed_argument_count = 0; - passthrough_key.pressed_arguments = NULL; - passthrough_key.released = quantum_passthrough_release; - passthrough_key.released_argument_count = 0; - passthrough_key.released_arguments = NULL; + struct key *passthrough_key = + &(struct key){.pressed = quantum_passthrough_press, + .released = quantum_passthrough_release}; for (uint8_t j = 16; j != 255; j--) { - layers[j].keys = (struct key *)malloc(total_keys * sizeof(struct key)); - if (layers[j].keys == NULL) { - return ERR_OUT_OF_MEMORY_KEYS; - } - for (int i = 0; i < total_keys; i++) { - copy_key(&passthrough_key, &(layers[j].keys[i])); + for (uint8_t i = 0; i < total_keys; i++) { + layers[j].keys[i] = passthrough_key; } } key_states = (bool *)malloc(total_keys * sizeof(bool)); diff --git a/src/squirrel_key.c b/src/squirrel_key.c index fb50939..b234937 100644 --- a/src/squirrel_key.c +++ b/src/squirrel_key.c @@ -15,17 +15,16 @@ enum squirrel_error press_key(uint8_t key_index) { if (!layers[i].active) { continue; } - struct key *selected_key = &(layers[i].keys[key_index]); + struct key *selected_key = layers[i].keys[key_index]; enum squirrel_error err = selected_key->pressed( - selected_key, i, key_index, selected_key->pressed_argument_count, - selected_key->pressed_arguments); + selected_key, i, key_index, selected_key->pressed_argument); if (err != ERR_NONE) { return err; } if (i == 16) { continue; } - copy_key(selected_key, &layers[16].keys[key_index]); + copy_key(selected_key, layers[16].keys[key_index]); } return ERR_NONE; } @@ -35,10 +34,9 @@ enum squirrel_error release_key(uint8_t key_index) { if (!layers[i].active) { continue; } - struct key *selected_key = &(layers[i].keys[key_index]); + struct key *selected_key = layers[i].keys[key_index]; enum squirrel_error err = selected_key->released( - selected_key, i, key_index, selected_key->released_argument_count, - selected_key->released_arguments); + selected_key, i, key_index, selected_key->released_argument); if (err != ERR_NONE) { return err; } @@ -47,13 +45,8 @@ enum squirrel_error release_key(uint8_t key_index) { } struct key passthrough_key; passthrough_key.pressed = quantum_passthrough_press; - passthrough_key.pressed_argument_count = 0; - passthrough_key.pressed_arguments = NULL; passthrough_key.released = quantum_passthrough_release; - passthrough_key.released_argument_count = 0; - passthrough_key.released_arguments = NULL; - copy_key(&passthrough_key, &layers[16].keys[key_index]); - layers[16].keys[0].pressed_argument_count = 0; + copy_key(&passthrough_key, layers[16].keys[key_index]); } return ERR_NONE; } diff --git a/src/squirrel_keymap.c b/src/squirrel_keymap.c index ada945f..1106b3c 100644 --- a/src/squirrel_keymap.c +++ b/src/squirrel_keymap.c @@ -10,94 +10,62 @@ struct key nop(void) { } struct key keyboard(uint8_t keycode) { - struct key key = { + return (struct key){ .pressed = keyboard_press, .released = keyboard_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &keycode, + .released_argument = &keycode, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &keycode; - key.released_arguments[0] = &keycode; - return key; } struct key keyboard_modifier(uint8_t modifier) { - struct key key = { + return (struct key){ .pressed = keyboard_modifier_press, .released = keyboard_modifier_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &modifier, + .released_argument = &modifier, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &modifier; - key.released_arguments[0] = &modifier; - return key; } struct key consumer(uint16_t consumer) { - struct key key = { + return (struct key){ .pressed = consumer_press, .released = consumer_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &consumer, + .released_argument = &consumer, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &consumer; - key.released_arguments[0] = &consumer; - return key; } struct key passthrough(void) { return (struct key){ .pressed = quantum_passthrough_press, .released = quantum_passthrough_release, - .pressed_argument_count = 0, - .released_argument_count = 0, }; } struct key layer_momentary(uint8_t layer) { - struct key key = { + return (struct key){ .pressed = layer_momentary_press, .released = layer_momentary_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &layer, + .released_argument = &layer, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &layer; - key.released_arguments[0] = &layer; - return key; } struct key layer_toggle(uint8_t layer) { - struct key key = { + return (struct key){ .pressed = layer_toggle_press, .released = layer_toggle_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &layer, + .released_argument = &layer, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &layer; - key.released_arguments[0] = &layer; - return key; } struct key layer_solo(uint8_t layer) { - struct key key = { + return (struct key){ .pressed = layer_solo_press, .released = layer_solo_release, - .pressed_argument_count = 1, - .released_argument_count = 1, + .pressed_argument = &layer, + .released_argument = &layer, }; - key.pressed_arguments = malloc(1 * sizeof(void *)); - key.released_arguments = malloc(1 * sizeof(void *)); - key.pressed_arguments[0] = &layer; - key.released_arguments[0] = &layer; - return key; } diff --git a/src/squirrel_quantum.c b/src/squirrel_quantum.c index d7f495d..19bef10 100644 --- a/src/squirrel_quantum.c +++ b/src/squirrel_quantum.c @@ -9,93 +9,63 @@ struct layer layers[17]; enum squirrel_error key_nop(struct key *key, uint8_t layer, uint8_t key_index, - int arg_count, void **args) { + void *arg) { (void)key; - (void)arg_count; - (void)args; + (void)arg; return ERR_NONE; } enum squirrel_error keyboard_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - - keyboard_activate_keycode(*(uint8_t *)args[0]); // squirrel_keyboard + keyboard_activate_keycode(*(uint8_t *)arg); // squirrel_keyboard return ERR_NONE; }; enum squirrel_error keyboard_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - keyboard_deactivate_keycode(*(uint8_t *)args[0]); // squirrel_keyboard + keyboard_deactivate_keycode(*(uint8_t *)arg); // squirrel_keyboard return ERR_NONE; } enum squirrel_error keyboard_modifier_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - keyboard_activate_modifier(*(uint8_t *)args[0]); // squirrel_keyboard + keyboard_activate_modifier(*(uint8_t *)arg); // squirrel_keyboard return ERR_NONE; } enum squirrel_error keyboard_modifier_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - keyboard_deactivate_modifier(*(uint8_t *)args[0]); // squirrel_keyboard + keyboard_deactivate_modifier(*(uint8_t *)arg); // squirrel_keyboard return ERR_NONE; } enum squirrel_error consumer_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - consumer_activate_consumer_code(*(uint16_t *)args[0]); // squirrel_consumer + consumer_activate_consumer_code(*(uint16_t *)arg); // squirrel_consumer return ERR_NONE; } enum squirrel_error consumer_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { + uint8_t key_index, void *arg) { (void)layer; (void)key_index; - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - consumer_deactivate_consumer_code(*(uint16_t *)args[0]); // squirrel_consumer + consumer_deactivate_consumer_code(*(uint16_t *)arg); // squirrel_consumer return ERR_NONE; } // quantum_passthrough_press does not take extra arguments. enum squirrel_error quantum_passthrough_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 0) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; + uint8_t key_index, void *arg) { if (layer == 0) { return ERR_PASSTHROUGH_ON_BOTTOM_LAYER; }; @@ -103,28 +73,23 @@ enum squirrel_error quantum_passthrough_press(struct key *key, uint8_t layer, if (!layers[i].active) { continue; } - struct key *selected_key = &(layers[i].keys[key_index]); + struct key *selected_key = layers[i].keys[key_index]; enum squirrel_error err = selected_key->pressed( - selected_key, i, key_index, selected_key->pressed_argument_count, - selected_key->pressed_arguments); + selected_key, i, key_index, selected_key->pressed_argument); if (err != ERR_NONE) { return err; } if (i == 16) { continue; } - copy_key(selected_key, &layers[16].keys[key_index]); + copy_key(selected_key, layers[16].keys[key_index]); } return ERR_NONE; } // quantum_passthrough_release does not take extra arguments. enum squirrel_error quantum_passthrough_release(struct key *key, uint8_t layer, - uint8_t key_index, - int arg_count, void **args) { - if (arg_count != 0) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; + uint8_t key_index, void *arg) { if (layer == 0) { return ERR_PASSTHROUGH_ON_BOTTOM_LAYER; }; @@ -132,10 +97,9 @@ enum squirrel_error quantum_passthrough_release(struct key *key, uint8_t layer, if (!layers[i].active) { continue; } - struct key *selected_key = &(layers[i].keys[key_index]); + struct key *selected_key = layers[i].keys[key_index]; enum squirrel_error err = selected_key->released( - selected_key, i, key_index, selected_key->released_argument_count, - selected_key->released_arguments); + selected_key, i, key_index, selected_key->released_argument); if (err != ERR_NONE) { return err; } @@ -144,63 +108,41 @@ enum squirrel_error quantum_passthrough_release(struct key *key, uint8_t layer, } struct key passthrough_key; passthrough_key.pressed = quantum_passthrough_press; - passthrough_key.pressed_argument_count = 0; passthrough_key.released = quantum_passthrough_release; - passthrough_key.released_argument_count = 0; - copy_key(&passthrough_key, &layers[16].keys[key_index]); + copy_key(&passthrough_key, layers[16].keys[key_index]); } return ERR_NONE; } enum squirrel_error layer_momentary_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - uint8_t target_layer = *(uint8_t *)args[0]; + uint8_t key_index, void *arg) { + uint8_t target_layer = *(uint8_t *)arg; layers[target_layer].active = true; return ERR_NONE; } enum squirrel_error layer_momentary_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - uint8_t target_layer = *(uint8_t *)args[0]; + uint8_t key_index, void *arg) { + uint8_t target_layer = *(uint8_t *)arg; layers[target_layer].active = false; return ERR_NONE; } enum squirrel_error layer_toggle_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - uint8_t target_layer = *(uint8_t *)args[0]; + uint8_t key_index, void *arg) { + uint8_t target_layer = *(uint8_t *)arg; layers[target_layer].active = !layers[target_layer].active; return ERR_NONE; } enum squirrel_error layer_toggle_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; + uint8_t key_index, void *arg) { return ERR_NONE; } enum squirrel_error layer_solo_press(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; - uint8_t target_layer = *(uint8_t *)args[0]; + uint8_t key_index, void *arg) { + uint8_t target_layer = *(uint8_t *)arg; for (uint8_t i = 0; i < 16; i++) { layers[i].active = false; } @@ -209,10 +151,6 @@ enum squirrel_error layer_solo_press(struct key *key, uint8_t layer, } enum squirrel_error layer_solo_release(struct key *key, uint8_t layer, - uint8_t key_index, int arg_count, - void **args) { - if (arg_count != 1) { - return ERR_KEY_FUNC_WRONG_ARGUMENT_COUNT; - }; + uint8_t key_index, void *arg) { return ERR_NONE; } diff --git a/tests/key.c b/tests/key.c index 3ea9957..8b43be7 100644 --- a/tests/key.c +++ b/tests/key.c @@ -61,7 +61,7 @@ int main() { testkey.released_arguments[0] = &code2; testkey.released_arguments[1] = &code1; - layers[0].keys[0] = testkey; + layers[0].keys[0] = &testkey; layers[0].active = true; // check that arguments are correct, and in the correct order. @@ -73,10 +73,10 @@ int main() { return 3; } // keys are copied to layer 17 (index 16) when pressed, to avoid layer issues. - if (layers[16].keys[0].pressed_arguments[0] != &code1) { + if (layers[16].keys[0]->pressed_arguments[0] != &code1) { return 4; } - if (layers[16].keys[0].pressed_arguments[1] != &code2) { + if (layers[16].keys[0]->pressed_arguments[1] != &code2) { return 5; } @@ -89,10 +89,10 @@ int main() { return 7; } // Keys are replaced with passthrough on layer 17 when released. - if (layers[16].keys[0].pressed_arguments != NULL) { + if (layers[16].keys[0]->pressed_arguments != NULL) { return 8; } - if (layers[16].keys[0].released_arguments != NULL) { + if (layers[16].keys[0]->released_arguments != NULL) { return 9; } diff --git a/tests/multikey.c b/tests/multikey.c index 373f35d..44ea5e2 100644 --- a/tests/multikey.c +++ b/tests/multikey.c @@ -58,7 +58,7 @@ void make_testkey(int index) { testkey.released_arguments[0] = &code2; testkey.released_arguments[1] = &code1; - layers[0].keys[index] = testkey; + layers[0].keys[index] = &testkey; }; // test: press_key, release_key + check_key - in squirrel_key.c, @@ -84,10 +84,10 @@ int main() { } // keys are copied to layer 17 (index 16) when pressed, to avoid layer // issues. - if (layers[16].keys[i].pressed_arguments[0] != &code1) { + if (layers[16].keys[i]->pressed_arguments[0] != &code1) { return 4; } - if (layers[16].keys[i].pressed_arguments[1] != &code2) { + if (layers[16].keys[i]->pressed_arguments[1] != &code2) { return 5; } @@ -100,10 +100,10 @@ int main() { return 7; } // Keys are replaced with passthrough on layer 17 when released. - if (layers[16].keys[i].pressed_arguments != NULL) { + if (layers[16].keys[i]->pressed_arguments != NULL) { return 8; } - if (layers[16].keys[i].released_arguments != NULL) { + if (layers[16].keys[i]->released_arguments != NULL) { return 9; } @@ -163,8 +163,8 @@ int main() { // cleanup for (int i = 0; i < 5; i++) { - free(layers[0].keys[i].pressed_arguments); - free(layers[0].keys[i].released_arguments); + free(layers[0].keys[i]->pressed_arguments); + free(layers[0].keys[i]->released_arguments); } return 0; diff --git a/tests/quantum_passthrough_press_release.c b/tests/quantum_passthrough_press_release.c index 7f9ccab..f888580 100644 --- a/tests/quantum_passthrough_press_release.c +++ b/tests/quantum_passthrough_press_release.c @@ -44,14 +44,14 @@ int main() { testkey.pressed_argument_count = 0; testkey.released = test_release; testkey.released_argument_count = 0; - layers[0].keys[0] = testkey; // When testkey is pressed, the test is passing. + layers[0].keys[0] = &testkey; // When testkey is pressed, the test is passing. struct key passthroughkey; passthroughkey.pressed = quantum_passthrough_press; passthroughkey.pressed_argument_count = 0; passthroughkey.released = quantum_passthrough_release; passthroughkey.released_argument_count = 0; - layers[1].keys[0] = passthroughkey; // This is the key being tested. + layers[1].keys[0] = &passthroughkey; // This is the key being tested. layers[0].active = true; layers[1].active = true; @@ -80,15 +80,15 @@ int main() { false; // this layer contains the badtestkey and should be ignored. layers[2].active = true; // this layer contains the passthrough key. - layers[2].keys[0] = passthroughkey; + layers[2].keys[0] = &passthroughkey; struct key badtestkey; badtestkey.pressed = bad_test_press; badtestkey.pressed_argument_count = 0; badtestkey.released = bad_test_release; badtestkey.released_argument_count = 0; - layers[1].keys[0] = badtestkey; // When badtestkey is pressed, the test is - // failing. + layers[1].keys[0] = &badtestkey; // When badtestkey is pressed, the test is + // failing. test_result = 1; // Reset the test result to failing again. err = press_key(0); // Press the key.