diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2022-03-07 14:44:21 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2022-03-09 10:16:07 +1000 |
commit | 395d12d63446a1897dd64f35c2eb603203d55c21 (patch) | |
tree | caa6beb13eb89b3babadd1889a61e2e307093bfd | |
parent | 1f1ddbc6dff0cf0451e3c9ac923f9821278560aa (diff) | |
download | libinput-395d12d63446a1897dd64f35c2eb603203d55c21.tar.gz |
util: auto-declare the element variable in ARRAY_FOR_EACH
All cases we have in our code base have an otherwise unused variable to
loop through the array. Let's auto-declare this as part of the loop.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/evdev-mt-touchpad.c | 1 | ||||
-rw-r--r-- | src/evdev-tablet-pad.c | 1 | ||||
-rw-r--r-- | src/evdev-tablet.c | 1 | ||||
-rw-r--r-- | src/quirks.c | 1 | ||||
-rw-r--r-- | src/util-macros.h | 8 | ||||
-rw-r--r-- | src/util-prop-parsers.c | 1 | ||||
-rw-r--r-- | src/util-time.h | 1 | ||||
-rw-r--r-- | test/litest.c | 2 | ||||
-rw-r--r-- | test/test-device.c | 3 | ||||
-rw-r--r-- | test/test-keyboard.c | 1 | ||||
-rw-r--r-- | test/test-quirks.c | 18 | ||||
-rw-r--r-- | test/test-touchpad.c | 5 | ||||
-rw-r--r-- | test/test-utils.c | 57 | ||||
-rw-r--r-- | tools/libinput-debug-gui.c | 6 | ||||
-rw-r--r-- | tools/libinput-debug-tablet.c | 1 | ||||
-rw-r--r-- | tools/libinput-record.c | 1 | ||||
-rw-r--r-- | udev/libinput-fuzz-extract.c | 2 | ||||
-rw-r--r-- | udev/libinput-fuzz-to-zero.c | 1 |
18 files changed, 61 insertions, 50 deletions
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 4386bdad..ea9c8f1e 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -2885,7 +2885,6 @@ tp_init_slots(struct tp_dispatch *tp, { BTN_TOOL_TRIPLETAP, 3 }, { BTN_TOOL_DOUBLETAP, 2 }, }; - struct map *m; unsigned int i, n_btn_tool_touches = 1; absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_SLOT); diff --git a/src/evdev-tablet-pad.c b/src/evdev-tablet-pad.c index fdce7322..991c2851 100644 --- a/src/evdev-tablet-pad.c +++ b/src/evdev-tablet-pad.c @@ -642,7 +642,6 @@ pad_init_keys(struct pad_dispatch *pad, struct evdev_device *device) KEY_ONSCREEN_KEYBOARD, KEY_CONTROLPANEL, }; - unsigned int *code; /* Wacom's keys are the only ones we know anything about */ if (libevdev_get_id_vendor(device->evdev) != VENDOR_ID_WACOM) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 25bb57d6..58cc46d8 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -2026,7 +2026,6 @@ tablet_proximity_out_quirk_timer_func(uint64_t now, void *data) .code = SYN_REPORT, .value = 0 }, }; - struct input_event *e; if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) || tablet_has_status(tablet, TABLET_BUTTONS_DOWN)) { diff --git a/src/quirks.c b/src/quirks.c index bccbaa24..9c5efaa6 100644 --- a/src/quirks.c +++ b/src/quirks.c @@ -1338,7 +1338,6 @@ match_fill_udev_type(struct match *m, { "ID_INPUT_KEYBOARD", UDEV_KEYBOARD }, { "ID_INPUT_KEY", UDEV_KEYBOARD }, }; - struct ut_map *map; ARRAY_FOR_EACH(mappings, map) { if (udev_prop(device, map->prop)) diff --git a/src/util-macros.h b/src/util-macros.h index 978d0f39..004b0ccf 100644 --- a/src/util-macros.h +++ b/src/util-macros.h @@ -28,8 +28,14 @@ #include "config.h" #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) +/** + * Iterate through the array _arr, assigning the variable elem to each + * element. elem only exists within the loop. + */ #define ARRAY_FOR_EACH(_arr, _elem) \ - for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) + for (__typeof__((_arr)[0]) *_elem = _arr; \ + _elem < (_arr) + ARRAY_LENGTH(_arr); \ + _elem++) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/src/util-prop-parsers.c b/src/util-prop-parsers.c index 62902520..598e40c9 100644 --- a/src/util-prop-parsers.c +++ b/src/util-prop-parsers.c @@ -321,7 +321,6 @@ parse_evcode_string(const char *s, int *type_out, int *code_out) { "REL_", EV_REL }, { "SW_", EV_SW }, }; - struct map *m; bool found = false; ARRAY_FOR_EACH(map, m) { diff --git a/src/util-time.h b/src/util-time.h index c239e993..a5ac4b57 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -116,7 +116,6 @@ to_human_time(uint64_t us) {"h", 60, 48}, {"d", 24, ~0}, }; - struct c *c; uint64_t value = us; ARRAY_FOR_EACH(conversion, c) { diff --git a/test/litest.c b/test/litest.c index 4f4739d2..54b15bef 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2734,7 +2734,6 @@ litest_button_click(struct litest_device *d, unsigned int button, bool is_press) { - struct input_event *ev; struct input_event click[] = { { .type = EV_KEY, .code = button, .value = is_press ? 1 : 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, @@ -2803,7 +2802,6 @@ litest_button_scroll_locked(struct litest_device *dev, void litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) { - struct input_event *ev; struct input_event click[] = { { .type = EV_KEY, .code = key, .value = is_press ? 1 : 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, diff --git a/test/test-device.c b/test/test-device.c index 8c1679d5..3b153436 100644 --- a/test/test-device.c +++ b/test/test-device.c @@ -1448,7 +1448,7 @@ debug_log_handler(struct libinput *libinput, const char *format, va_list args) { - char *message, **dmsg; + char *message; int n; if (priority != LIBINPUT_LOG_PRIORITY_DEBUG) @@ -1542,7 +1542,6 @@ START_TEST(device_capability_at_least_one) LIBINPUT_DEVICE_CAP_GESTURE, LIBINPUT_DEVICE_CAP_SWITCH, }; - enum libinput_device_capability *cap; int ncaps = 0; ARRAY_FOR_EACH(caps, cap) { diff --git a/test/test-keyboard.c b/test/test-keyboard.c index 55c5c365..0cb8a80d 100644 --- a/test/test-keyboard.c +++ b/test/test-keyboard.c @@ -111,7 +111,6 @@ START_TEST(keyboard_ignore_no_pressed_release) EV_KEY, KEY_A, -1, -1, }; - enum libinput_key_state *state; enum libinput_key_state expected_states[] = { LIBINPUT_KEY_STATE_PRESSED, LIBINPUT_KEY_STATE_RELEASED, diff --git a/test/test-quirks.c b/test/test-quirks.c index ac6a68d7..dc9bcd09 100644 --- a/test/test-quirks.c +++ b/test/test-quirks.c @@ -561,7 +561,6 @@ START_TEST(quirks_parse_vendor_invalid) "MatchVendor=123\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -622,7 +621,6 @@ START_TEST(quirks_parse_product_invalid) "MatchProduct=123\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -683,7 +681,6 @@ START_TEST(quirks_parse_version_invalid) "MatchVersion=123\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -747,7 +744,6 @@ START_TEST(quirks_parse_name_invalid) "MatchName=\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -821,7 +817,6 @@ START_TEST(quirks_parse_udev_invalid) "MatchUdevType=123\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -878,7 +873,6 @@ START_TEST(quirks_parse_dmi_invalid) "MatchDMIModalias=foo\n" "ModelAppleTouchpad=1\n", }; - const char **qf; ARRAY_FOR_EACH(quirks_file, qf) { struct data_dir dd = make_data_dir(*qf); @@ -965,7 +959,6 @@ START_TEST(quirks_parse_dimension_attr) QUIRK_ATTR_SIZE_HINT, QUIRK_ATTR_RESOLUTION_HINT, }; - enum quirk *a; struct qtest_dim test_values[] = { { "10x10", true, 10, 10 }, { "20x30", true, 20, 30 }, @@ -975,7 +968,6 @@ START_TEST(quirks_parse_dimension_attr) { "0x00", false, 0, 0 }, { "0xa0", false, 0, 0 }, }; - struct qtest_dim *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { @@ -1011,7 +1003,6 @@ START_TEST(quirks_parse_range_attr) QUIRK_ATTR_TOUCH_SIZE_RANGE, QUIRK_ATTR_PRESSURE_RANGE, }; - enum quirk *a; struct qtest_range test_values[] = { { "20:10", true, 20, 10 }, { "30:5", true, 30, 5 }, @@ -1029,7 +1020,6 @@ START_TEST(quirks_parse_range_attr) { "0xa0", false, 0, 0 }, { "0x10:0x5", false, 0, 0 }, }; - struct qtest_range *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { @@ -1066,7 +1056,6 @@ START_TEST(quirks_parse_uint_attr) QUIRK_ATTR_PALM_PRESSURE_THRESHOLD, QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD, }; - enum quirk *a; struct qtest_uint test_values[] = { { "10", true, 10 }, { "0", true, 0 }, @@ -1078,7 +1067,6 @@ START_TEST(quirks_parse_uint_attr) { "0xab", false, 0 }, { "ab", false, 0 }, }; - struct qtest_uint *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { @@ -1112,7 +1100,6 @@ START_TEST(quirks_parse_double_attr) enum quirk attrs[] = { QUIRK_ATTR_TRACKPOINT_MULTIPLIER, }; - enum quirk *a; struct qtest_double test_values[] = { { "10", true, 10.0 }, { "10.0", true, 10.0 }, @@ -1132,7 +1119,6 @@ START_TEST(quirks_parse_double_attr) { "10:5", false, 0 }, { "10x5", false, 0 }, }; - struct qtest_double *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { @@ -1167,7 +1153,6 @@ START_TEST(quirks_parse_string_attr) QUIRK_ATTR_LID_SWITCH_RELIABILITY, QUIRK_ATTR_KEYBOARD_INTEGRATION, }; - enum quirk *a; struct qtest_str test_values[] = { { "below", QUIRK_ATTR_TPKBCOMBO_LAYOUT }, { "reliable", QUIRK_ATTR_LID_SWITCH_RELIABILITY }, @@ -1185,7 +1170,6 @@ START_TEST(quirks_parse_string_attr) { "0xa", 0 }, { "0.0", 0 }, }; - struct qtest_str *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { @@ -1219,7 +1203,6 @@ START_TEST(quirks_parse_bool_attr) QUIRK_ATTR_USE_VELOCITY_AVERAGING, QUIRK_ATTR_TABLET_SMOOTHING, }; - enum quirk *a; struct qtest_bool test_values[] = { { "0", true, false }, { "1", true, true }, @@ -1227,7 +1210,6 @@ START_TEST(quirks_parse_bool_attr) { "-1", false, false }, { "a", false, false }, }; - struct qtest_bool *t; ARRAY_FOR_EACH(attrs, a) { ARRAY_FOR_EACH(test_values, t) { diff --git a/test/test-touchpad.c b/test/test-touchpad.c index 161cfcaa..b55d979f 100644 --- a/test/test-touchpad.c +++ b/test/test-touchpad.c @@ -3346,7 +3346,6 @@ START_TEST(touchpad_trackpoint_buttons) { BTN_1, BTN_RIGHT }, { BTN_2, BTN_MIDDLE }, }; - const struct buttons *b; trackpoint = litest_add_device(li, LITEST_TRACKPOINT); @@ -4197,7 +4196,6 @@ START_TEST(touchpad_dwt_modifier_no_dwt) KEY_RIGHTMETA, KEY_LEFTMETA, }; - unsigned int *key; if (!has_disable_while_typing(touchpad)) return; @@ -4243,7 +4241,6 @@ START_TEST(touchpad_dwt_modifier_combo_no_dwt) KEY_RIGHTMETA, KEY_LEFTMETA, }; - unsigned int *key; if (!has_disable_while_typing(touchpad)) return; @@ -4293,7 +4290,6 @@ START_TEST(touchpad_dwt_modifier_combo_dwt_after) KEY_RIGHTMETA, KEY_LEFTMETA, }; - unsigned int *key; if (!has_disable_while_typing(touchpad)) return; @@ -4347,7 +4343,6 @@ START_TEST(touchpad_dwt_modifier_combo_dwt_remains) KEY_RIGHTMETA, KEY_LEFTMETA, }; - unsigned int *key; if (!has_disable_while_typing(touchpad)) return; diff --git a/test/test-utils.c b/test/test-utils.c index 989adecd..ca804a94 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -41,6 +41,57 @@ #include "check-double-macros.h" +START_TEST(array_for_each) +{ + int ai[6]; + char ac[10]; + struct as { + int a; + char b; + int *ptr; + } as[32]; + + for (size_t i = 0; i < 6; i++) + ai[i] = 20 + i; + for (size_t i = 0; i < 10; i++) + ac[i] = 100 + i; + for (size_t i = 0; i < 32; i++) { + as[i].a = 10 + i; + as[i].b = 20 + i; + as[i].ptr = (int*)0xab + i; + } + + int iexpected = 20; + ARRAY_FOR_EACH(ai, entry) { + ck_assert_int_eq(*entry, iexpected); + ++iexpected; + } + ck_assert_int_eq(iexpected, 26); + + int cexpected = 100; + ARRAY_FOR_EACH(ac, entry) { + ck_assert_int_eq(*entry, cexpected); + ++cexpected; + } + ck_assert_int_eq(cexpected, 110); + + struct as sexpected = { + .a = 10, + .b = 20, + .ptr = (int*)0xab, + }; + ARRAY_FOR_EACH(as, entry) { + ck_assert_int_eq(entry->a, sexpected.a); + ck_assert_int_eq(entry->b, sexpected.b); + ck_assert_ptr_eq(entry->ptr, sexpected.ptr); + ++sexpected.a; + ++sexpected.b; + ++sexpected.ptr; + } + ck_assert_int_eq(sexpected.a, 42); +} +END_TEST + START_TEST(bitfield_helpers) { /* This value has a bit set on all of the word boundaries we want to @@ -678,7 +729,6 @@ START_TEST(evdev_abs_parser) { .which = 0, .prop = ":asb::::" }, { .which = 0, .prop = "foo" }, }; - struct test *t; ARRAY_FOR_EACH(tests, t) { struct input_absinfo abs; @@ -1071,7 +1121,6 @@ START_TEST(strargv_test) { 1, {NULL, NULL}, 0 }, { 3, {"hello", NULL, "World"}, 0 }, }; - struct argv_test *t; ARRAY_FOR_EACH(tests, t) { char **strv = strv_from_argv(t->argc, t->argv); @@ -1414,7 +1463,6 @@ START_TEST(basename_test) { "/bar", "bar" }, { "", NULL }, }; - struct test *t; ARRAY_FOR_EACH(tests, t) { const char *result = safe_basename(t->path); @@ -1442,7 +1490,6 @@ START_TEST(trunkname_test) { "/bar", "bar" }, { "", "" }, }; - struct test *t; ARRAY_FOR_EACH(tests, t) { char *result = trunkname(t->path); @@ -1461,6 +1508,8 @@ litest_utils_suite(void) s = suite_create("litest:utils"); tc = tcase_create("utils"); + tcase_add_test(tc, array_for_each); + tcase_add_test(tc, bitfield_helpers); tcase_add_test(tc, matrix_helpers); tcase_add_test(tc, ratelimit_helpers); diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index 0ef66145..b8685c8c 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -603,8 +603,6 @@ draw_scrollbars(struct window *w, cairo_t *cr) static inline void draw_touchpoints(struct window *w, cairo_t *cr) { - struct touch *t; - cairo_save(cr); ARRAY_FOR_EACH(w->touches, t) { if (t->state == TOUCH_ACTIVE) @@ -1155,7 +1153,6 @@ window_init(struct window *w) static void window_cleanup(struct window *w) { - struct libinput_device **dev; ARRAY_FOR_EACH(w->devices, dev) { if (*dev) libinput_device_unref(*dev); @@ -1165,8 +1162,6 @@ window_cleanup(struct window *w) static void change_ptraccel(struct window *w, double amount) { - struct libinput_device **dev; - ARRAY_FOR_EACH(w->devices, dev) { double speed; enum libinput_config_status status; @@ -1341,7 +1336,6 @@ static void handle_event_device_notify(struct libinput_event *ev) { struct libinput_device *dev = libinput_event_get_device(ev); - struct libinput_device **device; struct libinput *li; struct window *w; const char *type; diff --git a/tools/libinput-debug-tablet.c b/tools/libinput-debug-tablet.c index 73948de2..05d3b9a1 100644 --- a/tools/libinput-debug-tablet.c +++ b/tools/libinput-debug-tablet.c @@ -307,7 +307,6 @@ handle_tablet_button_event(struct context *ctx, struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); unsigned int button = libinput_event_tablet_tool_get_button(t); - unsigned int *btn; enum libinput_button_state state = libinput_event_tablet_tool_get_button_state(t); ARRAY_FOR_EACH(ctx->buttons_down, btn) { diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 7adebdf2..b31b6fe3 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -1820,7 +1820,6 @@ print_libinput_description(struct record_device *dev) {LIBINPUT_DEVICE_CAP_GESTURE, "gesture"}, {LIBINPUT_DEVICE_CAP_SWITCH, "switch"}, }; - struct cap *cap; const char *sep = ""; if (!device) diff --git a/udev/libinput-fuzz-extract.c b/udev/libinput-fuzz-extract.c index 48ef79ce..6158e357 100644 --- a/udev/libinput-fuzz-extract.c +++ b/udev/libinput-fuzz-extract.c @@ -46,7 +46,6 @@ handle_absfuzz(struct udev_device *device) struct libevdev *evdev = NULL; int fd = -1; int rc; - unsigned int *code; unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, @@ -88,7 +87,6 @@ out: static void handle_evdev_abs(struct udev_device *device) { - unsigned int *code; unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, diff --git a/udev/libinput-fuzz-to-zero.c b/udev/libinput-fuzz-to-zero.c index a8767bed..e2e9a036 100644 --- a/udev/libinput-fuzz-to-zero.c +++ b/udev/libinput-fuzz-to-zero.c @@ -39,7 +39,6 @@ reset_absfuzz_to_zero(struct udev_device *device) struct libevdev *evdev = NULL; int fd = -1; int rc; - unsigned int *code; unsigned int axes[] = {ABS_X, ABS_Y, ABS_MT_POSITION_X, |