Commit Graph

2183 Commits (1a4a89a749100db97cc00cef0c79ee2eceda4c69)

Author SHA1 Message Date
Ran Benita 8cd688c063 keysym: avoid strtoul in xkb_keysym_from_name
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 22:24:05 +03:00
Ran Benita 68e69b7deb keysym: use a perfect hash function for case sensitive xkb_keysym_from_name
In 7d84809fdc I added a fast path for the
case-sensitive case, but it is still slowing down Compose parsing.

Instead of the binary search, use a perfect hash function, computed with
a simple python module I found (vendored).

It is faster -- perf diff is:

   Baseline  Delta Abs  Shared Object      Symbol
   ........  .........  .................  ...................................

     22.35%    -14.04%  libc-2.33.so       [.] __strcmp_avx2
     16.75%    +10.28%  bench-compose      [.] xkb_keysym_from_name
     20.72%     +2.40%  bench-compose      [.] parse.constprop.0
      2.29%     -1.97%  bench-compose      [.] strcmp@plt
      2.56%     +1.81%  bench-compose      [.] resolve_name
      2.37%     +0.92%  libc-2.33.so       [.] __GI_____strtoull_l_internal
     26.19%     -0.63%  bench-compose      [.] lex
      1.45%     +0.56%  libc-2.33.so       [.] __memchr_avx2
      1.13%     -0.31%  libc-2.33.so       [.] __strcpy_avx2

Also reduces the binary size:

Before:

      text    data     bss     dec     hex filename
    341111    5064       8  346183   54847 build/libxkbcommon.so.0.0.0

After:

      text    data     bss     dec     hex filename
    330215    5064       8  335287   51db7 build/libxkbcommon.so.0.0.0

Note however that it's still larger than before 7d84809fdccbb5898d08388:

      text    data     bss     dec     hex filename
    320617    5168       8  325793   4f8a1 build/libxkbcommon.so.0.0.0

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 20:06:59 +03:00
Ran Benita 02b9cabf98 compose: use a ternary tree instead of a regular trie
Previously we used a simple trie with a linked list for each chain.
Unfortunately most compose files have very long chains which means the
constructions performs an almost quadratic number of comparisons.

Switch to using a ternary search tree instead. This is very similar to a
trie, only the linked list is essentially replaced with a binary tree.

On the en_US/Compose file, the perf diff is the following (the modified
function is `parse`):

  Event 'cycles:u'

  Baseline  Delta Abs  Shared Object     Symbol
  ........  .........  ................  .................................

    39.91%    -17.62%  bench-compose     [.] parse.constprop.0
    20.54%     +6.47%  bench-compose     [.] lex
    17.28%     +5.55%  libc-2.33.so      [.] __strcmp_avx2
    12.78%     +4.01%  bench-compose     [.] xkb_keysym_from_name
     2.30%     +0.83%  libc-2.33.so      [.] __GI_____strtoull_l_internal
     3.36%     +0.78%  bench-compose     [.] strcmp@plt

Thanks to some careful packing, the memory usage is pretty much the
same.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-31 12:10:52 +03:00
Ran Benita 3a6c3b2c48 ast: remove comment re. anonymous struct
C11 is not sufficient for this, needs `--ms-extensions` which we don't
want to enable.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 20:42:31 +03:00
Ran Benita 8b09e1772c compose: use anonymous union
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 20:42:31 +03:00
Ran Benita 90e2d5ee76 build: require C11
I'd really like to use anonymous unions/structs. Supposedly even MSVC
supports it now. Let's try and see.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 20:42:31 +03:00
Ran Benita 1c0e28ad26 keysym: properly handle overflow in 0x keysym names
Relatedly, strtoul allows a lot of unwanted stuff (spaces, +/- sign,
thousand seperators), we really ought not use it. But that's for another
time.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 19:17:29 +03:00
Ran Benita 1638409b22 compose: add a limit of 65535 sequences
Fits in uint16_t, which enables some future optimizations. But also a
good idea to have some limit. Not aware of any compose files which come
close.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 17:52:36 +03:00
Peter Hutterer 127f8c976d utils: assert on streq for NULL pointers
We have streq_null for that purpose

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer d172652753 test: move an assert up to before the strlen() use
../../../test/keysym.c:80:24: warning: Null pointer passed to 1st parameter
expecting 'nonnull' [core.NonNullParamChecker]
  (unsigned) strlen(expected));

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer fa86433e7c xkbcomp: remove useless assignment
../../../src/xkbcomp/compat.c:693:16: warning: Although the value stored to
'merge' is used in the enclosing expression, the value is never actually read
from 'merge' [deadcode.DeadStores]
    si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer 20f7f80c23 xkbcomp: use memcpy over strncpy to avoid analyzer warnings
The target buffer is 7 bytes long, null-termination is optional (as the comment
already suggests). Coverity is unhappy about this though so let's use memset and
memcpy instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:34:33 +03:00
Ran Benita cda2eaf1f5 man: add missing pointer to xkbcli-compile-keymap(1)
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-29 20:59:45 +03:00
Ran Benita 7d84809fdc keysym: fast path for case sensitive xkb_keysym_from_name
xkb_keysym_from_name() is called a lot in Compose file parsing. The
lower case handling slows things down a lot (particularly given we can't
use the optimized strcasecmp() due to locale issues). So add separate
handling for the non-case-sensitive case which is used by Compose.

To do this we need to add another version of the ks_tables table. This
adds ~20kb to the shared library binary. We can probably do something
better here but I think it's fine.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 3b506497bf keysym: inline find_sym function
It's easier when everything is in one place.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 2d87ab08f3 keysym: use a more descriptive argument name
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita a717549eb2 keysym: open-code bsearch
We want to optimize things here which requires messing with the binary
search some.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita c14910a0de interactive-evdev: fix missing initialization
Accidentally got lost in 6b65be4.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 6b65be4c4e interactive-evdev: switch from epoll(2) to poll(2)
Turns out FreeBSD supports evdev, so this toll can work on it; however
it does not support epoll, so switch to poll, which is portable.

Reported-by: Evgeniy Khramtsov <evgeniy@khramtsov.org>
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 14:39:03 +03:00
Ran Benita 62b5b4a170 x11: fix comparison of integer expressions of different signedness
src/x11/keymap.c:980:26: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  980 |     for (size_t i = 0; i < length; i++) {
      |                          ^

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 13:02:27 +03:00
Peter Hutterer 95e2907978 xkbcomp: plug a potential memory leak
libxkbcommon-1.0.3/src/xkbcomp/ast-build.c:526: leaked_storage: Variable "file"
going out of scope leaks the storage it points to.

Where we exit the loop early, we don't release the various allocated memory.

Make this patch more obvious my moving the declaration for those into the loop
as well, this way we know that they aren't used outside the loop anywhere.

Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Peter Hutterer 01aa222257 registry: plug a potential memleak for invalid rules files
If the name is missing in a configItem, we'd fail and leak the memory for
description, brief and vendor.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Peter Hutterer 694b8f7127 test: fix missing va_end in case of test failures
Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Peter Hutterer 7a205e25ac bench: silence coverity complaint about a double free
False positive because we rely on xkb_components_from_rules() to initalize this
struct, but let's localize the variable anyway to shut coverity up.

libxkbcommon-1.0.3/bench/rules.c:59:9: warning[-Wanalyzer-double-free]:
double-free of kccgst.symbols

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Uli Schlachter 21c864ccbf Inline x11_atom_interner_adopt_atoms() into callers
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter c033970163 Save another GetAtomName round trip
Both get_atom_name() and the new atom interner required a round trip. Move
get_atom_name() into the atom interner to save one more round trip. This brings
xkb_x11_keymap_new_from_device() down to two round trips, which is the minimum
possible number.

(Also, I think the new code in keymap.c is more readable than the mess I
previously created)

With this last commit in the series, this definitely:

Fixes: https://github.com/xkbcommon/libxkbcommon/pull/217
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter c8efc3d67d Also batch the XKB GetNames request
This gets rid of another round trip.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter 599064cf28 Also batch the XKB-GetMapMap request
This gets rid of one more round trip.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter 1b3a1c277a Remove three more round trips
There are a number of XKB requests needed to request all the information from
the X11 server. So far, the code was sending one request and waiting for the
reply. This commit starts batching the request so that we get multiple replies
with one round trip.

This removes three round trips.

Only the simple requests are converted. get_map() and get_names() use some
bitmasks that are needed for both the request and the reply. These will be dealt
with separately.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter b9707c1db0 Save three more round trips in xkb_x11_keymap_new_from_device()
Instead of asking for an atom name and waiting for the reply four times, this
now sends four GetAtomName requests and waits for all the replies at once. Thus,
this saves three round trips.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter 40c00b4721 xkb_x11_keymap_new_from_device: Less X11 round-trips
On my system, calling xkb_x11_keymap_new_from_device() did 78 round trips to the
X11 server, which seems excessive. This commit brings this number down to about
9 to 10 round trips.

The existing functions adopt_atom() and adopt_atoms() guarantee that the atom
was adopted by the time they return. Thus, each call to these functions must do
a round-trip. However, none of the callers need this guarantee.

This commit makes "atom adopting" asynchronous: Only some time later is the atom
actually adopted. Until then, it is in some pending "limbo" state.

This actually fixes a TODO in the comments.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/216
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Ran Benita 82a5bdc43c Bump version to 1.1.0
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 22:48:35 +02:00
Ran Benita 83e3a53ddc doc: add keymap-format-text-v1.md to the HTML documentation
It's incomplete but might be helpful for someone.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 22:38:21 +02:00
Ran Benita afc5370c86 doc: add note on variants in rule names
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/208
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 22:13:17 +02:00
Pierre Le Marre 30ce6c04f9 Fix a few keysymtab entries to match their comment in xkbcommon-keysyms.h
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 22:06:42 +02:00
Ran Benita 2dd391b66e scripts: remove meson-junit-report.py
Not used since ed5a0b4fed.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 21:38:02 +02:00
Peter Hutterer d1ba81c4dd meson.build: replace the remaining join_paths() with the nicer / syntax
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer 0abd430e85 test: add a keysym tester
A simple script that creates a new layout with the given keysym replacing TLDE.
Then we compile a keymap and search for the keysym being assigned to TLDE and
bail if that fails.

The list of keysyms is manually maintained but we only need to add one or two to
spot-check whenever the xorgproto is updated.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer b4802b0642 Fix documentation for XKB_CONFIG_EXTRA_PATH
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer 0bfc71e7b5 Update keysym definitions to latest xorgproto
As of xorgproto commit e5d8af9711516385f8346c9e077692b29c914478

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer 3852106a8e scripts: update makeheader script for the _EVDEVK keysym defines
As of xorgproto commit 5dbb5b76597f [1], the 0x10081XXX keycode range is defined
for direct evdev kernel keycode mapping. For example, KEY_MACRO1 (0x290) is
mapped to 0x10081290. The format of the #define lines for these keys is
stable to allow for parsing:

  #define XF86XK_FooBar _EVDEVK(0x123) /* optional comment */

Update our script so we detect these new lines. Our keysym generation is a
two-step process: makeheader and then makekeys. Replacing the key with its full
value in the makeheader script means we don't have to update makekeys to handle
the _EVDEVK macro and our header file is fully resolved.

[1] https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/merge_requests/23

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer 5c1f4f0da0 Update imported comments in xkbcommon-keysyms.h
Matches xorgproto commits 39eb5974 and 09602b213.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Peter Hutterer 069777f47f test: fix interactive evdev test invocation
rmlvos is the parent list which then fails during a list join because, well,
it's a list of lists.

Fixes #206

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-23 18:57:23 +02:00
Peter Hutterer d5e3695ea2 test: fill in srcdir/builddir when not set in the environment
Makes this test easier to run from the commandline. Where either of top_srcdir
or top_builddir isn't set, fill them in from the CWD or fail otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-23 18:57:23 +02:00
Ran Benita 44df69c928 doc/keymap: some slight editing
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-12-27 09:49:20 +02:00
Simon Zeni 7420521ff4
doc/keymap: add documentation for xkb_symbols (#205) 2020-12-27 09:48:39 +02:00
Ran Benita c60b77ea51 Bump version to 1.0.3
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 20:30:13 +02:00
Ran Benita fbf087ea94 keymap-dump: follow xkbcomp in printing affect=both in pointer actions
It is equivalent to nothing but good to match up.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 20:03:17 +02:00
Ran Benita ac6cd20c55 x11: fix type level names missing
When reading the keymap, the level names would get discarded.
Regressed in 26453b8473.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 18:49:49 +02:00
Ran Benita 95f8ff8355 test/data: update host.xkb to match keymap-dump style
This is needed for fixing the x11comp test.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 18:35:27 +02:00