summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
2022-01-24registry: skip over invalid ISO639 or ISO3166 entriesPeter Hutterer1-0/+10
If the XML file is somehow off, don't load entries that are against the spec.
2022-01-18registry: don't call xmlCleanupParser()Peter Hutterer1-1/+0
From the documentation: > It does not clean up parser state, it cleans up memory allocated by the library > itself. It is a cleanup function for the XML library. It tries to reclaim all > related global memory allocated for the library processing. [...] > One should call xmlCleanupParser() only when the process has finished using the library. http://xmlsoft.org/html/libxml-parser.html#xmlCleanupParser Since we're a library ourselves we cannot know if something else in the same proces uses the parser, so we must not call this. Reported-by: M Hickford
2021-09-09x11: try to fix crash in xkb_x11_keymap_new_from_device error handlingRan Benita1-12/+30
In 1b3a1c277a033083fee669e92c8cad862716ebd1 we changed the error handling in this code to not bail out immediately but only after everything has been processed, to simplify the code. But I suspect the code isn't prepared for this and that's what causing the crash reported in the issue. Bring back the short-circuit error handling which would hopefully fix such crashes. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/252 Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-08-31x11: stylistic fixesRan Benita2-8/+9
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22ignore: remove no longer relevant gitignore filesRan Benita1-2/+0
These were relevant for the autoconf build but now we're meson only. Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-08compose: add mapped locale to Compose-file-not-found error logRan Benita1-1/+2
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27atom: rewrite as a hash tableRan Benita1-68/+64
While the previous 1987-style[0] scheme was fun (and I reasonably optimized it for a fair comparison), this task is more suited to a hash table. Even a simple implementation beats the old one. [0] Seems to have first appeared in X11R1, released September 1987. See server/dix/atom.c here: https://www.x.org/releases/X11R1/X.V11R1.tar.gz Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-25keysym: fix underflow in binary searchesIsaac Freund1-4/+4
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-07x11: fix xkb_x11_keymap_new_from_device failing when a level name is emptyRan Benita1-1/+4
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 40c00b472144d1684d2fb97cafef39. 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-02compose: fix max compose nodes checkRan Benita1-2/+3
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01keysym: speed up the perfect hash functionRan Benita1-297/+298
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-01keysym: avoid strtoul in xkb_keysym_from_nameRan Benita1-10/+28
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01keysym: use a perfect hash function for case sensitive xkb_keysym_from_nameRan Benita2-2570/+327
In 7d84809fdccbb5898d0838849ec7c321410182d5 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-03-31compose: use a ternary tree instead of a regular trieRan Benita4-128/+139
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-30ast: remove comment re. anonymous structRan Benita1-1/+0
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-30compose: use anonymous unionRan Benita4-25/+27
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30keysym: properly handle overflow in 0x keysym namesRan Benita1-6/+10
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-30compose: add a limit of 65535 sequencesRan Benita3-10/+18
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-30utils: assert on streq for NULL pointersPeter Hutterer1-0/+1
We have streq_null for that purpose Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30xkbcomp: remove useless assignmentPeter Hutterer1-1/+1
../../../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-30xkbcomp: use memcpy over strncpy to avoid analyzer warningsPeter Hutterer1-4/+5
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-28keysym: fast path for case sensitive xkb_keysym_from_nameRan Benita2-52/+2617
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-28keysym: inline find_sym functionRan Benita1-56/+46
It's easier when everything is in one place. Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28keysym: use a more descriptive argument nameRan Benita1-11/+11
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28keysym: open-code bsearchRan Benita1-34/+26
We want to optimize things here which requires messing with the binary search some. Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28x11: fix comparison of integer expressions of different signednessRan Benita1-1/+1
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-19xkbcomp: plug a potential memory leakPeter Hutterer1-3/+8
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-19registry: plug a potential memleak for invalid rules filesPeter Hutterer1-0/+4
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-09Inline x11_atom_interner_adopt_atoms() into callersUli Schlachter3-19/+8
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09Save another GetAtomName round tripUli Schlachter3-76/+66
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-09Also batch the XKB GetNames requestUli Schlachter1-23/+24
This gets rid of another round trip. Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09Also batch the XKB-GetMapMap requestUli Schlachter1-15/+15
This gets rid of one more round trip. Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09Remove three more round tripsUli Schlachter1-18/+18
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-09Save three more round trips in xkb_x11_keymap_new_from_device()Uli Schlachter3-8/+39
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-09xkb_x11_keymap_new_from_device: Less X11 round-tripsUli Schlachter3-104/+157
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-02-27Fix a few keysymtab entries to match their comment in xkbcommon-keysyms.hPierre Le Marre1-3/+3
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-22Update keysym definitions to latest xorgprotoPeter Hutterer1-3499/+3925
As of xorgproto commit e5d8af9711516385f8346c9e077692b29c914478 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-11-23keymap-dump: follow xkbcomp in printing affect=both in pointer actionsRan Benita1-4/+6
It is equivalent to nothing but good to match up. Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23x11: fix type level names missingRan Benita1-0/+1
When reading the keymap, the level names would get discarded. Regressed in 26453b84732da870f5695ee347970b337cfea9c1. Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23x11/keymap: fix case with no actionsRan Benita1-9/+10
Possible regression in f41e609bbea8447fc82849a1a6ea0d116189f2f8 (not confirmed yet). Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-20x11: cache X11 atomsRan Benita3-5/+56
On every keymap notify event, the keymap should be refreshed, which fetches the required X11 atoms. A big keymap might have a few hundred of atoms. A profile by a user has shown this *might* be slow when some intensive amount of keymap activity is occurring. It might also be slow on a remote X server. While I'm not really sure this is the actual bottleneck, caching the atoms is easy enough and only needs a couple kb of memory, so do that. On the added bench-x11: Before: retrieved 2500 keymaps from X in 11.233237s After : retrieved 2500 keymaps from X in 1.592339s Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-20x11: eliminate slow divisionsRan Benita1-22/+23
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-10-20xkbcomp: where a keysym cannot be resolved, set it to NoSymbolPeter Hutterer1-1/+3
Where resolve_keysym fails we warn but use the otherwise uninitialized variable as our keysym. That later ends up in the keymap as random garbage hex value. Simplest test case, set this in the 'us' keymap: key <TLDE> { [ xyz ] }; And without this patch we get random garbage: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ 0x018a5cf0 ] }; With this patch, we now get NoSymbol: ./build/xkbcli-compile-keymap --layout us | grep TLDE: key <TLDE> { [ NoSymbol ] };
2020-09-11parser: fix another format string for int64_t (#191)hhb1-1/+1
2020-09-07utils: include unistd.h where we have itPeter Hutterer1-1/+1
MacOS doesn't have eaccess/euidaccess but it does have unistd.h, so let's include it to silence the R_OK redefinition compiler warnings. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07context: fix a compiler warningPeter Hutterer1-1/+1
../src/context.c:57:9: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07registry: mark the rxkb_log function as attribute printfPeter Hutterer1-0/+1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30Add /etc/xkb as extra lookup path for system data filesPeter Hutterer4-2/+27
This completes the usual triplet of configuration locations available for most processes: - vendor-provided data files in /usr/share/X11/xkb - system-specific data files in /etc/xkb - user-specific data files in $XDG_CONFIG_HOME/xkb The default lookup order user, system, vendor, just like everything else that uses these conventions. For include directives in rules files, the '%E' resolves to that path. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30xkbcomp: allow including kccgst files from other pathsPeter Hutterer3-22/+49
Previously, a 'symbols/us' file in path A would shadow the same file in path B. This is suboptimal, we rarely need to hide the system files - we care mostly about *extending* them. By continuing to check other lookup paths, we make it possible for a XDG_CONFIG_HOME/xkb/symbols/us file to have sections including those from /usr/share/X11/xkb/symbols/us. Note that this is not possible for rules files which need to be manually controlled to get the right bits resolved. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30xkbcomp: simplify the include path handlingPeter Hutterer1-18/+11
Streamline the code a bit - instead of handling all the if (!file) conditions handle the case of where we have a file and jump to the end. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>