summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* compose: drop the 65535 node limit (#343)HEADmasteralois312023-05-153-10/+11
| | | | | | | | | | | In commit 1638409b22aef33d487863876ab214b949db4984, the number of compose nodes was limited to 65535 to enable "future optimizations", which apparently means slightly reduced memory usage due to fitting in a uint16_t. At this time, it was mentioned that the author was not aware of "any compose files which come close". However, I'm one of the users that actually do require a larger number of nodes for their compose file. Thus, use a uint32_t again and raise the limit significantly.
* Do not interpret nor emit invalid Unicode encoding formsPierre Le Marre2023-05-132-5/+27
| | | | | | Surrogates are invalid in both UTF-32 and UTF-8. See https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G28875 and https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G31703
* Add warning when RMLVO with no layout but variant setPierre Le Marre2023-05-131-0/+10
| | | | | | There is no feedback that they are both replaced with default values. Fix it by adding a warning informing about missing layout and show the defaults for both.
* utils: fix printf format warnings on mingwRan Benita2023-05-061-1/+3
| | | | | | | | | See: https://github.com/mesonbuild/wrapdb/pull/819 https://github.com/Exiv2/exiv2/blob/c86ae6acf597304db37246434ebc393d732c22c2/src/image_int.hpp#L15 https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ Signed-off-by: Ran Benita <ran@unusedvar.com>
* scanner: allow for a zero terminated string as keymapPeter Hutterer2023-05-051-0/+4
| | | | | | | | | | | As the documentation for xkb_keymap_new_from_buffer() states, the "input string does not have to be zero-terminated". The actual implementation however failed with "unrecognized token/syntax error" when it encountered a null byte. Fix this by allowing a null byte at the last position of the buffer. Anything else is likely a client error anyway. Fixes #307
* registry: remove a few asprintf/free() calls with snprintfPeter Hutterer2023-05-041-13/+4
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* registry: simplify strdup() error handlingPeter Hutterer2023-05-041-12/+8
| | | | | | | strdup() is the least likely call to fail here, let's move it to the bottom so we don't need to worry about the allocated string. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add support for modmap None (#291)Wismill2023-05-014-9/+30
| | | | | | | | | | | | | | | | | | | Unlike current xkbcommon, X11’s xkbcomp allows to remove entries in the modifiers’ map using “modifier_map None { … }”. “None” is translated to the special value “XkbNoModifier” defined in “X11/extensions/XKB.h”. Then it relies on the fact that in "CopyModMapDef", the following code: 1U << entry->modifier ends up being zero when “entry->modifier” is “XkbNoModifier” (i.e. 0xFF). Indeed, it relies on the overflow behaviour of the left shift, which in practice resolves to use only the 5 low bits of the shift amount, i.e. 0x1F here. Then the result of “1U << 0xFF” is cast to “char”, i.e. 0. This is a good trick but too magical, so in libxkbcommon we will use an explicit test against our new constant XKB_MOD_NONE.
* keysyms: add new keysyms XF86EmojiPicker, XF86DictateRan Benita2023-04-121-862/+867
| | | | | | Ref: https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/commit/914d8f5e0f469cd0416364dd008e9eea752bf703 Ref: https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/commit/a839f0c7fc5596d10e786394d3b0953eb8a1731b Signed-off-by: Ran Benita <ran@unusedvar.com>
* Possible fix for non-MSVC windows compilersRan Benita2023-04-111-1/+1
| | | | | | | | `_MSC_VER` is specific to MSVC, but there can be other compilers targeting windows. Hopefully they do define `_WIN32`, so let's use that. Refs: https://github.com/xkbcommon/libxkbcommon/issues/305 Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: replace deprecated Serbian_DZE with Cyrillic_DZHEPeter Hutterer2023-03-311-2/+2
| | | | | | | | | Same numeric value for both and the Serbian one has been listed as deprecated for decades. See https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/merge_requests/69#note_1843415 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312)Ronan Pigott2022-12-169-52/+81
| | | | | | | | | This flag is useful for clients that may have relatively benign capabilities set, like CAP_SYS_NICE, that also want to use the xkb configuration from the environment and user configs in XDG_CONFIG_HOME. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/308 Fixes: https://github.com/xkbcommon/libxkbcommon/issues/129 Signed-off-by: Ran Benita <ran@unusedvar.com>
* utils: move some MSVC compat stuff to common placeRan Benita2022-09-242-14/+13
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym-utf: remove bogus currency sign entriesRan Benita2022-05-151-11/+0
| | | | | | | | | | | | | | | | | | | | | | These ended up being mapping in the 0x100xxxx Unicode range, which are handled automatically ; these special keysyms don't exist (except for EuroSign). #define XKB_KEY_EcuSign 0x10020a0 /* U+20A0 EURO-CURRENCY SIGN */ #define XKB_KEY_ColonSign 0x10020a1 /* U+20A1 COLON SIGN */ #define XKB_KEY_CruzeiroSign 0x10020a2 /* U+20A2 CRUZEIRO SIGN */ #define XKB_KEY_FFrancSign 0x10020a3 /* U+20A3 FRENCH FRANC SIGN */ #define XKB_KEY_LiraSign 0x10020a4 /* U+20A4 LIRA SIGN */ #define XKB_KEY_MillSign 0x10020a5 /* U+20A5 MILL SIGN */ #define XKB_KEY_NairaSign 0x10020a6 /* U+20A6 NAIRA SIGN */ #define XKB_KEY_PesetaSign 0x10020a7 /* U+20A7 PESETA SIGN */ #define XKB_KEY_RupeeSign 0x10020a8 /* U+20A8 RUPEE SIGN */ #define XKB_KEY_WonSign 0x10020a9 /* U+20A9 WON SIGN */ #define XKB_KEY_NewSheqelSign 0x10020aa /* U+20AA NEW SHEQEL SIGN */ #define XKB_KEY_DongSign 0x10020ab /* U+20AB DONG SIGN */ #define XKB_KEY_EuroSign 0x20ac /* U+20AC EURO SIGN */ Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym-utf: remove bogus Korean Won sign entryRan Benita2022-05-151-1/+0
| | | | | | | This entry maps a non existing special keysym 0x20a9. The correct mapping for XKB_KEY_Korean_Won (0x0eff) already exists. Signed-off-by: Ran Benita <ran@unusedvar.com>
* Remove bogus euro sign entry from keysymtabSam Lantinga2022-05-151-1/+0
| | | | | | | | | | | | Not sure what it's doing here, but converting "€" to a keysym doesn't work with this entry. 0x13a4 doesn't appear in xkbcommon-keysyms.h. 0x20ac is the keysym documented in the header (and it's the last entry in the table). It's been in the table since it was introduced in e0524296d2e0 ("Add API for getting unicode representation of a keysym"). Co-authored-by: Simon Ser <contact@emersion.fr>
* Do not clear sibling entries when override.Weng Xuetian2022-05-151-1/+1
| | | | | | | | | | lokid and hikid actually stores the sibling to current node, which should not be cleared when override. This would break the sequence with a common prefix when override another. Fix #286 Signed-off-by: Weng Xuetian <wengxt@gmail.com>
* scanner: prefix functions with `scanner_` to avoid symbol conflictsRan Benita2022-03-144-151/+151
| | | | | | | | Particularly `eof()` in mingw-w64. Fixes: https://github.com/xkbcommon/libxkbcommon/pull/285 Reported-by: Marko Lindqvist Signed-off-by: Ran Benita <ran@unusedvar.com>
* Variants should inherit iso639, iso3166 and brief from parent layout if ↵M Hickford2022-01-241-3/+28
| | | | omitted (#266)
* registry: skip over invalid ISO639 or ISO3166 entriesPeter Hutterer2022-01-241-0/+10
| | | | If the XML file is somehow off, don't load entries that are against the spec.
* registry: don't call xmlCleanupParser()Peter Hutterer2022-01-181-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
* x11: try to fix crash in xkb_x11_keymap_new_from_device error handlingRan Benita2021-09-091-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>
* x11: stylistic fixesRan Benita2021-08-312-8/+9
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* ignore: remove no longer relevant gitignore filesRan Benita2021-05-221-2/+0
| | | | | | These were relevant for the autoconf build but now we're meson only. Signed-off-by: Ran Benita <ran@unusedvar.com>
* compose: add mapped locale to Compose-file-not-found error logRan Benita2021-05-081-1/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: rewrite as a hash tableRan Benita2021-04-271-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>
* keysym: fix underflow in binary searchesIsaac Freund2021-04-251-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.
* x11: fix xkb_x11_keymap_new_from_device failing when a level name is emptyRan Benita2021-04-071-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>
* compose: fix max compose nodes checkRan Benita2021-04-021-2/+3
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: speed up the perfect hash functionRan Benita2021-04-011-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>
* keysym: avoid strtoul in xkb_keysym_from_nameRan Benita2021-04-011-10/+28
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: use a perfect hash function for case sensitive xkb_keysym_from_nameRan Benita2021-04-012-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>
* compose: use a ternary tree instead of a regular trieRan Benita2021-03-314-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>
* ast: remove comment re. anonymous structRan Benita2021-03-301-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>
* compose: use anonymous unionRan Benita2021-03-304-25/+27
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: properly handle overflow in 0x keysym namesRan Benita2021-03-301-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>
* compose: add a limit of 65535 sequencesRan Benita2021-03-303-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>
* utils: assert on streq for NULL pointersPeter Hutterer2021-03-301-0/+1
| | | | | | We have streq_null for that purpose Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: remove useless assignmentPeter Hutterer2021-03-301-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>
* xkbcomp: use memcpy over strncpy to avoid analyzer warningsPeter Hutterer2021-03-301-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>
* keysym: fast path for case sensitive xkb_keysym_from_nameRan Benita2021-03-282-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>
* keysym: inline find_sym functionRan Benita2021-03-281-56/+46
| | | | | | It's easier when everything is in one place. Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: use a more descriptive argument nameRan Benita2021-03-281-11/+11
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* keysym: open-code bsearchRan Benita2021-03-281-34/+26
| | | | | | | We want to optimize things here which requires messing with the binary search some. Signed-off-by: Ran Benita <ran@unusedvar.com>
* x11: fix comparison of integer expressions of different signednessRan Benita2021-03-281-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>
* xkbcomp: plug a potential memory leakPeter Hutterer2021-03-191-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>
* registry: plug a potential memleak for invalid rules filesPeter Hutterer2021-03-191-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>
* Inline x11_atom_interner_adopt_atoms() into callersUli Schlachter2021-03-093-19/+8
| | | | Signed-off-by: Uli Schlachter <psychon@znc.in>
* Save another GetAtomName round tripUli Schlachter2021-03-093-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>
* Also batch the XKB GetNames requestUli Schlachter2021-03-091-23/+24
| | | | | | This gets rid of another round trip. Signed-off-by: Uli Schlachter <psychon@znc.in>