diff options
| author | Michael Forney <mforney@mforney.org> | 2019-06-07 13:25:54 -0700 |
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2019-06-14 00:37:09 -0700 |
| commit | 5f61b01da9f50968b18af900f9f9b3f024b314a1 (patch) | |
| tree | 1a9d799590b24837a70ad653269865bc490bbeb7 /pkg/mtdev/patch | |
| parent | 7e634f86530a1f64a732a312267f7a179f5dbc2d (diff) | |
mtdev: Fix some portability issues
Diffstat (limited to 'pkg/mtdev/patch')
| -rw-r--r-- | pkg/mtdev/patch/0001-Use-a-macro-for-nlongs-so-it-can-be-used-in-constant.patch | 55 | ||||
| -rw-r--r-- | pkg/mtdev/patch/0002-Avoid-__builtin_ffs.patch | 44 |
2 files changed, 99 insertions, 0 deletions
diff --git a/pkg/mtdev/patch/0001-Use-a-macro-for-nlongs-so-it-can-be-used-in-constant.patch b/pkg/mtdev/patch/0001-Use-a-macro-for-nlongs-so-it-can-be-used-in-constant.patch new file mode 100644 index 00000000..4e3f53ec --- /dev/null +++ b/pkg/mtdev/patch/0001-Use-a-macro-for-nlongs-so-it-can-be-used-in-constant.patch @@ -0,0 +1,55 @@ +From 43c6faf96712324bea4121157d292b84a86b0d45 Mon Sep 17 00:00:00 2001 +From: Michael Forney <mforney@mforney.org> +Date: Fri, 7 Jun 2019 10:36:05 -0700 +Subject: [PATCH] Use a macro for `nlongs` so it can be used in constant + expression + +This way, it can be used to specify the `absbits` array size (in +`mtdev_configure`) without making it a VLA. + +VLAs are an optional feature in C11, and in this case we can determine +the array size statically. + +This also matches the macros used in libevdev and libinput. + +Signed-off-by: Michael Forney <mforney@mforney.org> +--- + src/caps.c | 12 ++++-------- + 1 file changed, 4 insertions(+), 8 deletions(-) + +diff --git a/src/caps.c b/src/caps.c +index 2e6b0d4..b493425 100644 +--- a/src/caps.c ++++ b/src/caps.c +@@ -32,16 +32,12 @@ static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ + static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ + static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ + +-static const int bits_per_long = 8 * sizeof(long); +- +-static inline int nlongs(int nbit) +-{ +- return (nbit + bits_per_long - 1) / bits_per_long; +-} ++#define LONG_BITS (sizeof(long) * 8) ++#define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) + + static inline int getbit(const unsigned long *map, int key) + { +- return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; ++ return (map[key / LONG_BITS] >> (key % LONG_BITS)) & 0x01; + } + + static int getabs(struct input_absinfo *abs, int key, int fd) +@@ -106,7 +102,7 @@ int mtdev_set_slots(struct mtdev *dev, int fd) + + int mtdev_configure(struct mtdev *dev, int fd) + { +- unsigned long absbits[nlongs(ABS_MAX)]; ++ unsigned long absbits[NLONGS(ABS_MAX)]; + int rc, i; + + SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); +-- +2.20.1 + diff --git a/pkg/mtdev/patch/0002-Avoid-__builtin_ffs.patch b/pkg/mtdev/patch/0002-Avoid-__builtin_ffs.patch new file mode 100644 index 00000000..37a14ae7 --- /dev/null +++ b/pkg/mtdev/patch/0002-Avoid-__builtin_ffs.patch @@ -0,0 +1,44 @@ +From 365d628a9c944989cab0bfa6ae39d1df0ec5a905 Mon Sep 17 00:00:00 2001 +From: Michael Forney <mforney@mforney.org> +Date: Fri, 7 Jun 2019 11:55:26 -0700 +Subject: [PATCH] Avoid __builtin_ffs + +--- + src/common.h | 5 +---- + src/core.c | 2 +- + 2 files changed, 2 insertions(+), 5 deletions(-) + +diff --git a/src/common.h b/src/common.h +index 80a3d6e..3c77f48 100644 +--- a/src/common.h ++++ b/src/common.h +@@ -77,12 +77,9 @@ static inline int bitcount(unsigned v) + return (((v + (v>>4)) & 0xF0F0F0F) * 0x1010101) >> 24; + } + +-/* Return index of first bit [0-31], -1 on zero */ +-#define firstbit(v) (__builtin_ffs(v) - 1) +- + /* boost-style foreach bit */ + #define foreach_bit(i, m) \ +- for (i = firstbit(m); i >= 0; i = firstbit((m) & (~0U << (i + 1)))) ++ for (i = -1; (m) & ~0U << (i + 1);) if ((m) & 1U << ++i) + + /* robust system ioctl calls */ + #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) +diff --git a/src/core.c b/src/core.c +index 87ef420..f5b6272 100644 +--- a/src/core.c ++++ b/src/core.c +@@ -298,7 +298,7 @@ static void apply_typeA_changes(struct mtdev_state *state, + break; + } + if (id != MT_ID_NULL) { +- slot = firstbit(unused); ++ foreach_bit(slot, unused) break; + push_slot_changes(state, &data[i], prop[i], slot, syn); + SETBIT(used, slot); + CLEARBIT(unused, slot); +-- +2.20.1 + |
