Commit Graph

2058 Commits (baf5522649954d54ebb0227d42ceb71c7c6ea32c)

Author SHA1 Message Date
Ran Benita baf5522649 bench: add atom benchmark
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 16:41:32 +03:00
Ran Benita 5f8c2fa41a bench/rulescomp: decrease benchmark iterations
No need for more, and easier to convert to milliseconds per iteration.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 12:32:21 +03:00
Ran Benita 9d87f84915 build: fix missing includes
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 10:57:42 +03:00
Ran Benita de1b6943d2 Move include files to include/ subdirectory
This way we don't specify `include_directorories('.')` which brings in
more than needed.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 10:10:26 +03:00
Ran Benita 8ff0232bda build: move the subproject variables to a common section at the end
As suggested in:
https://github.com/xkbcommon/libxkbcommon/pull/240#discussion_r620784021

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 10:02:54 +03:00
Adrian Perez de Castro 4238417ba0 Meson: Allow building as subproject
Specify where to find the headers for libxkbcommon_dep,
libxkbcommon_x11_dep, and libxkbregistry_dep,  which allows other
projects to correctly locate the headers when libxkbcommon is being
built as a Meson subproject.

The dep_libxkbregistry variable is renamed to libxkbregistry_dep,
to follow the usual convention for variables which hold declared
dependencies to be used from subproject builds.
2021-04-27 09:54:58 +03:00
Adrian Perez de Castro 5cd76a8d93 Windows: Pass list of symbols to export to MSVC
Arrange for passing .def files with the lists of symbols to export from
DLLs when building on Windows with MSVC. Without this no symbols were
being exported at all.

The .def files are generated from the .map files at build time using
scripts/map-to-def, which avoids needing to maintain two different sets
of files.
2021-04-27 09:54:00 +03:00
Peter Hutterer f434c690cc tools: change xkbcli list to output YAML
We have a lot of keyboard layouts and the current output format is virtually
useless at searching for a specific one to debug any issues with either the
layout list or the output from libxkbregistry.

Let's use YAML instead because that can easily be post-processed to extract the
specific layouts wanted, e.g. to get the list of all layouts:
  xkbcli-list | yq -r ".layouts[].layout"
to get the list of all variants of the "us" layout:
  xkbcli-list | yq -r '.layouts[] | select(.layout == "us") | .variant
and the number of option groups:
  xkbcli-list | yq -r '.option_groups[] | length'

Note that the top-level nodes have been de-capitalized, so where it was "Models"
before it is now "models" and the "Options" node is now "option_groups".

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-27 09:53:32 +03:00
Peter Hutterer 693ffb073b tools: change the list separator handling
Slightly easier to read than the "bool first" approach.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-27 09:53:32 +03:00
Isaac Freund 68dddd4132 keysym: fix underflow in binary searches
This is hit when passing an empty string and XKB_KEYSYM_CASE_INSENSITIVE
to xkb_keysym_from_name currently if `(lo + hi) / 2` is 0 and `cmp < 0`,
causing mid to underflow and the the array access into name_to_keysym on
the next iteration of the loop to be out of bounds .

We *would* use ssize_t here as it is the appropriate type, but windows
unfortunately does not define it.
2021-04-25 12:25:58 +03:00
Peter Hutterer 1557668364 test: allow skipping errors in certain conditions
Add a skipError test function that can analyse rc, stdout, stderr to skip a test
even when we expect an error. We use that to skip if we couldn't find a keyboard
in the interactive-evdev test.

Fixes #235

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-22 10:02:46 +10:00
Peter Hutterer f60bdb1680 test: add extra info to the layout-tester --help output
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer be520ef91c test: print the layout-tester progress bar to stdout by default
tqdm prints to stderr by default but we're using that for failed keymap
compiles (which are the ones that really matter). Plus, whether we're using tqdm
is dependent on isatty(sys.stdout) anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer efa5805032 test: add an LVO argument to the XKB layout tester
Slightly easier to debug if we can have it only parse one single layout.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer a955dca3d5 test: print the compiled keymaps to a given directory
With --keymap-output-dir, the given directory will contain a list of files named
after the layout + variant ('us', 'us(euro)', ...) that contain the keymaps for
each variant + option combination compiled.

This is still a lot, but better to sift through hundreds of keymaps than tens of
thousands.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer 1cae250052 test: rework the output for the xkeyboard-config layout tester
The previous output is largely unusable. The result in the CI test runs is a 6GB
file with every compiled keymap in it and while we can grep for ERROR, it's not
particularly useful.

Let's change this and print out YAML instead - that can be machine-processed.
This patch adds a new parent class that prints itself in YAML format,
the tool invocations are child classes of that class. The result looks like this:

Example output:
- rmlvo: ["evdev", "pc105", "us", "haw", "grp:rwin_switch"]
  cmd: "xkbcli-compile-keymap --verbose --rules evdev --model pc105 --layout us --variant haw --options grp:rwin_switch"
  status: 0
- rmlvo: ["evdev", "pc105", "us", "foo", ""]
  cmd: "xkbcli-compile-keymap --verbose --rules evdev --model pc105 --layout us --variant foo"
  status: 1
  error: "failed to compile keymap"

Special status codes are: 99 for "unrecognized keysym" and 90 for "Cannot open
display" in the setxkbmap case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer 44e8d4b044 test: add proper --verbose handling to the xkeyboard-config tester
Instead of defaulting to verbose on/off depending on isatty, make it an
argument instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Evgeniy Khramtsov f04c7e93ce interactive-wayland: fallback to ftruncate() if needed
Fallback to ftruncate() if the underlying filesystem does not
support posix_fallocate().

Idea by: Jan Beich <jbeich@FreeBSD.org>, Niclas Zeising <zeising@FreeBSD.org>
Inspired by: Wayland cursor/os-compatibility.c
[ran: small adjustments]
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-14 13:44:57 +03:00
Jouke Witteveen 8b603dbe11 doc: fix user-configuration sample file
Support copy-pasting from the docs to get something functional.

Signed-off-by: Jouke Witteveen <j.witteveen@gmail.com>
2021-04-11 10:25:56 +03:00
Ran Benita 5d297c5012 scripts: update license note in perfect_hash.py
Ref: https://github.com/ilanschnell/perfect-hash/issues/5

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-08 10:14:15 +03:00
Ran Benita 097a0ca7d6 Bump version to 1.2.1
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-07 19:27:30 +03:00
Ran Benita 29af25eaa8 x11: fix xkb_x11_keymap_new_from_device failing when a level name is empty
The numpad:mac option doesn't specify a name for the first level:

    // On Mac keypads, level 1 and 2 are swapped.
    partial xkb_types "mac" {
        type "KEYPAD" {
            modifiers = None;
            map[None] = Level2;
            level_name[Level2] = "Number";
        };
        include "extra(keypad)"
    };

This means the atom for level name is XCB_ATOM_NONE. We tried to get its
name, which fails. This regressed in 40c00b4721.

Instead, translate it to XKB_ATOM_NONE, same as the previous behavior.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/229
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-07 19:21:10 +03:00
Ran Benita 086353b380 Bump version to 1.2.0
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-03 14:11:38 +03:00
Ran Benita 7e6d942a4f compose: fix max compose nodes check
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-02 15:15:33 +03:00
Ran Benita 45b1ca2205 keysym: speed up the perfect hash function
Make it use a bit operation instead of an expensive modulo.

perf diff:

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

      28.15%     -6.57%  bench-compose      [.] xkb_keysym_from_name

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 22:52:59 +03:00
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