src/compose


Log

Author Commit Date CI Message
Pierre Le Marre b5d969dd 2025-08-06T17:22:38 compose: Move constants to dedicated header
Pierre Le Marre d60b3213 2025-07-16T08:00:30 Make the ref counting invariants explicit with assertions
Pierre Le Marre dc63e5f8 2025-07-07T12:28:24 Ensure config.h is always included first While `config.h` may not be necessary in every file, it ensures consistency and makes code refactoring safer.
Pierre Le Marre 16c079d6 2025-06-06T20:27:45 chore: Rename is_absolute to is_absolute_path
Jules Bertholet 7a2aa9c9 2024-12-20T22:53:11 Always retain later Compose sequence in case of conflict This ensures that it is always possible to override previous definitions, for example when `include`ing the system Compose file. Signed-off-by: Jules Bertholet <julesbertholet@quoi.xyz>
Pierre Le Marre 3a8bb1a1 2025-05-16T13:13:55 compose: Fix sequence not fully overriden Previously if a new sequence did not produce a keysym or a string, the corresponding property was not overriden, possibly leaking the previous entry. - Fixed by always writting all the properties. - Also try to reuse the previous string entry, if possible, so that we avoid allocating.
Pierre Le Marre 61d8ec67 2025-05-12T18:20:47 misc: Fix string format specifiers Ensure better portability.
Pierre Le Marre 3031f6c3 2025-05-12T10:38:15 misc: Always use `unsigned` with `int` Better semantics & facilitate search.
Pierre Le Marre 3bfc1bc1 2025-05-12T18:52:05 misc: Ensure proper type for darray size
Pierre Le Marre 5a32b779 2025-04-06T06:16:41 logging: Handle NULL map name Display “(unnamed map)” instead of “(null)”.
Pierre Le Marre f348c6e9 2025-04-05T12:48:50 logging: Quote invalid escape sequence
Pierre Le Marre 70d11abd 2025-03-26T07:38:05 messages: Add file encoding and invalid syntax entries Added: - `XKB_ERROR_INVALID_FILE_ENCODING` - `XKB_ERROR_INVALID_RULES_SYNTAX` - `XKB_ERROR_INVALID_COMPOSE_SYNTAX` Changed: - `XKB_ERROR_INVALID_SYNTAX` renamed to `XKB_ERROR_INVALID_XKB_SYNTAX`.
Ran Benita 113ac304 2025-01-25T03:18:01 meson: link tests and benches against shared library, not static library This makes the tests, and especially benches, more realistic, since xkbcommon is almost always used as a shared library. Also significantly reduces the build time with LTO enabled (for me, from 90s to 30s). Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita a380ba52 2025-01-25T07:00:43 Move XKB_EXPORT to headers The Windows dllexport annotation wants to be on the declarations, not the definitions. Signed-off-by: Ran Benita <ran@unusedvar.com>
Pierre Le Marre c051d0ae 2025-02-05T14:09:17 Replace include guards by `#pragma once` (again) Follow-up of df2322d70cb0922f67c41db639a5c70733b4ce66.
Ran Benita df2322d7 2025-02-05T14:41:21 Replace include guards by `#pragma once` We currently have a mix of include headers, pragma once and some missing. pragma once is not standard but is widely supported, and we already use it with no issues, so I'd say it's not a problem. Let's convert all headers to pragma once to avoid the annoying include guards. The public headers are *not* converted. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita e120807b 2025-01-29T15:35:22 Update license notices to SDPX short identifiers + update LICENSE Fix #628. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 26807a90 2025-01-28T20:24:05 scanner: compute token line/column lazily on errors The scanner functions are hot, and the line/column location tracking is quite expensive. We only use it for errors, which don't need to be fast, because we bail if there are too many; and for warnings, which are usually not shown by default. So only keep the token start pos, and compute the line/column lazily from that. This will also allow some further improvements ahead. bench/rulescomp before: compiled 1000 keymaps in 1.669028s after: compiled 1000 keymaps in 1.550411s bench/compose: before: compiled 1000 compose tables in 2.145217s after: compiled 1000 compose tables in 2.016044s Signed-off-by: Ran Benita <ran@unusedvar.com>
Pierre Le Marre 3249223f 2025-01-30T07:58:20 test: Add check for keymap and compose compilation logs
Pierre Le Marre 3ee08251 2025-01-22T16:50:19 clang-tidy: Fix possible leak
Pierre Le Marre 5389a31e 2025-01-22T17:33:03 clang-tidy: Use memcpy instead of the insecure strcpy
Pierre Le Marre 53b3f446 2025-01-22T17:43:53 clang-tidy: Fix headers includes
Pierre Le Marre 425dc634 2025-01-21T15:40:33 Fix some implicit integers casts
Pierre Le Marre e3e44998 2025-01-16T20:23:47 Fix missing or incorrect integer literal suffixes The correct suffix is required in order to have the expected value in a portable way.
Jeffrey Cliff b1b9ff61 2024-11-23T10:07:24 compose/paths: fix `false` <-> `NULL` confusion, errors on C23 i don't have access to github but this patch enabled me to compile libxkbcommon with -std=gnu23 otherwise the following compilation error will result : ../src/compose/paths.c:70:16: error: incompatible types when returning type ‘_Bool’ but ‘char *’ was expected ( gcc (GCC) 15.0.0 20240509 (experimental) ) Signed-off-by: Ran Benita <ran@unusedvar.com>
Pierre Le Marre 8b45556d 2024-09-24T21:51:14 logging: Make log_err_func* use a message ID
Pierre Le Marre ba896935 2024-09-24T21:28:12 logging: Make scanner_warn use a message ID
Pierre Le Marre c8bd57dd 2024-09-24T21:20:41 logging: Make scanner_err use a message ID
Pierre Le Marre fdcd458c 2024-09-24T21:20:29 nit: Format files
Pierre Le Marre a600c36d 2024-09-16T18:11:57 compose: Use is_absolute to test absolute paths
Pierre Le Marre 44df6eee 2024-09-23T07:27:48 Add new warnings for deprecated keysyms Add 2 new warnings: - Deprecated keysym name (typo, historical alias, etc.); - Deprecated keysym (all names and forms). Guard deprecated keysym tests with verbosity level ≥2, so they are run only when actually needed.
Pierre Le Marre 5e539bf0 2024-07-08T09:19:00 compose: Make iteration API faster New implementation without explicit direction
Pierre Le Marre 652b03cc 2024-09-01T08:32:21 compose: Add Compose table dump internal API - Move `print_compose_table_entry` to own file and add a `file` argument to select output. - Add `xkb_compose_table_dump` to dump a Compose table. This change is needed in order to share the feature “dump a Compose table” between tests and tools.
Peter Hutterer 08deb9c3 2024-07-16T11:00:39 compose: initialize the dummy node to zero src/compose/table.c:66:5: uninit_use: Using uninitialized value "dummy". Field "dummy.lokid" is uninitialized. This looks like a false positive but it's easy enough to shut up:
Peter Hutterer 4b5d1027 2024-07-16T10:19:55 compose: fix a sizeof char* vs char warning ../../../src/compose/dump.h:48:16: warning: Result of 'calloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'char *' [unix.MallocSizeof] 48 | char* to = calloc(4 * length + 1, sizeof(to)); | ~~~~~ ^~~~~~ ~~~~~~~~~~ No security impact as sizeof(char*) is always >1 so we were just overallocating here.
Pierre Le Marre addf73c5 2024-07-12T09:17:34 keysyms: Require only 5 bytes for UTF-8 encoding Require only 5 bytes for the buffer of `xkb_keysym_to_utf8`, as UTF-8 encodes code points on up to 4 bytes + 1 byte for the NULL-terminating byte. Previous standard [RFC 2279] (1998) required up to 6 bytes per code point, but has been superseded by [RFC 3629] (2003). [RFC 2279]: https://datatracker.ietf.org/doc/html/rfc2279 [RFC 3629]: https://datatracker.ietf.org/doc/html/rfc3629
Pierre Le Marre 1731c6b3 2024-02-05T11:55:39 compose: Ensure we mmap only regular files Currently we do not check that the Compose files we try successively are *regular* files. This may result in an error, while we should just really just skip the corresponding path. Fixed by adding the new utily function `open_file`.
Pierre Le Marre 43c9752d 2024-01-16T11:04:59 compose: Fix iterator for empty tables The current `xkb_compose_table_iterator_next` segfaults when used with an empty table. Indeed, in this case we initialize cursors in `xkb_compose_table_iterator_new` with the dummy node and the direction `NODE_LEFT`, but the dummy node is a leaf! Fixed by initializing with no cursors when the table is has no non-dummy nodes.
Pierre Le Marre 1034f272 2023-12-05T18:43:41 compose: Reduce xkb_compose_state_get_utf8 buffer `xkb_keysym_to_utf8` does not return a keysym name but its corresponding character, if defined.
Pierre Le Marre 8cca3a7b 2023-12-05T17:39:59 compose: Add XKB_COMPOSE_MAX_STRING_SIZE Define the maximum size of a compose sequence result string explicit as a constant and use it everywhere to improve the code readability.
Pierre Le Marre 0a577a09 2023-11-07T12:58:41 xkbcli-compile-compose: Fix string result escaping Currently the result string is not escaped and may produce invalid results. Fixed by introducing an ad-hoc escape function and relative tests.
Pierre Le Marre a2da57ab 2023-10-30T14:50:00 Compose: early detection of invalid encoding Also move “unrecognized token” error message before skiping the line, in order to fix token position.
Pierre Le Marre 6c54681f 2023-10-30T12:31:42 Compose: Fix UTF-8 BOM detection The leading UTF-8 BOM detection code is misplaced as it is executed after each EOL. Fixed by moving the code before the goto labels.
Pierre Le Marre 59886e41 2023-10-29T07:20:29 Compose: skip heading UTF-8 encoded BOM (U+FEFF) Leading BOM is legal and is used as a signature — an indication that an otherwise unmarked text file is in UTF-8. See: https://www.unicode.org/faq/utf_bom.html#bom5 for further details.
Pierre Le Marre 9d15c6a7 2023-09-26T17:05:14 Show invalid escape sequences It is easier to debug when the message actually displays the offending escape sequence.
Pierre Le Marre ca7aa69c 2023-09-26T17:05:05 Disallow producing NULL character with escape sequences NULL usually terminates the strings; allowing to produce it via escape sequences may lead to undefined behaviour. - Make NULL escape sequences (e.g. `\0` and `\x0`) invalid. - Add corresponding test. - Introduce the new message: XKB_WARNING_INVALID_ESCAPE_SEQUENCE.
Ran Benita a1770132 2023-09-25T11:41:48 Compose: add iterator API Allow users to iterate the entries in a compose table. This is useful for other projects which want programmable access to the sequences, without having to write their own parser. - New API: - `xkb_compose_table_entry_sequence`; - `xkb_compose_table_entry_keysym`; - `xkb_compose_table_entry_utf8`; - `xkb_compose_table_iterator_new`; - `xkb_compose_table_iterator_free`; - `xkb_compose_table_iterator_next`. - Add tests in `test/compose.c`. - Add benchmark for compose traversal. - `tools/compose.c`: - Print entries instead of just validating them. - Add `--file` option. - TODO: make this tool part of the xkbcli commands. Co-authored-by: Pierre Le Marre <dev@wismill.eu> Co-authored-by: Ran Benita <ran@unusedvar.com> Signed-off-by: Ran Benita <ran@unusedvar.com>
Pierre Le Marre c0065c95 2023-09-21T20:06:27 Messages: merge macros with and without message code Previously we had two types of macros for logging: with and without message code. They were intended to be merged afterwards. The idea is to use a special code – `XKB_LOG_MESSAGE_NO_ID = 0` – that should *not* be displayed. But we would like to avoid checking this special code at run time. This is achieved using macro tricks; they are detailed in the code (see: `PREPEND_MESSAGE_ID`). Now it is also easier to spot the remaining undocumented log entries: just search `XKB_LOG_MESSAGE_NO_ID`.
alois31 f3210cbf 2023-05-15T14:23:16 compose: drop the 65535 node limit (#343) 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.
Ronan Pigott b4e81ca1 2022-12-16T01:26:25 context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312) 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>
Weng Xuetian b064b609 2022-05-14T01:11:32 Do not clear sibling entries when override. 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>
Ran Benita 0b3d9092 2022-03-14T16:44:13 scanner: prefix functions with `scanner_` to avoid symbol conflicts 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>
Ran Benita 1915632e 2021-05-08T21:08:37 compose: add mapped locale to Compose-file-not-found error log Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 7e6d942a 2021-04-02T15:00:46 compose: fix max compose nodes check Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 02b9cabf 2021-03-29T16:05:14 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>
Ran Benita 8b09e177 2021-03-30T20:12:08 compose: use anonymous union Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 1638409b 2021-03-30T17:52:36 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>
Emmanuel Gil Peyrot ddd1188d 2020-07-17T01:09:47 Make path retrieval consistent in xkb_compose_table_new_from_locale()
Emmanuel Gil Peyrot 17ad0df1 2020-07-16T12:06:49 compose: add xdg base directory support Before reading ~/.XCompose, try to read $XDG_CONFIG_HOME/XCompose (falling back to ~/.config/XCompose). This helps unclutter the home directory of users who want that.
Peter Hutterer 41a7c975 2020-07-10T14:57:57 Add asprintf_safe helper function We only ever care about whether we error out or not, so let's wrap this into something more sane. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Ran Benita da4a90c1 2019-12-28T13:49:40 Open files in binary mode This turns off some misfeatures on Windows, and does nothing on POSIX. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 40aab05e 2019-12-27T13:03:20 build: include config.h manually Previously we included it with an `-include` compiler directive. But that's not portable. And it's better to be explicit anyway. Every .c file should have `include "config.h"` first thing. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 406beeca 2019-11-12T22:06:02 Replace some tabs that sneaked in with spaces Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 842e4351 2018-03-12T09:43:55 compose: fix infinite loop in parser on some inputs The parser would enter an infinite loop if an unterminated keysym literal occurs at EOF. Found with the afl fuzzer. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 47f45194 2017-12-12T15:44:52 compose/parser: be more careful when checking if sequence overrides or duplicates another Signed-off-by: Ran Benita <ran234@gmail.com>
Daniel Stone ce38f96e 2017-04-11T15:09:23 Add explicit fallthrough case statements When we fall through to another label in a case, add an explicit comment noting so, to quiet GCC 7's warnings. Signed-off-by: Daniel Stone <daniels@collabora.com>
Ran Benita 1ec14d09 2016-12-02T22:46:53 compose: remove the keysym_from_name cache The hit rate is high, but either the cache is slow or the function is not fast enough -- the cache no longer holds its weight, leading only to very modest improvements. If it's the former, it can definitely be improved, the code is very dumb (though it worked just as well as any other I tried back then). But instead, let's just kill it. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 2cca0289 2015-11-19T00:44:27 src/utils: change map_file to not take const string argument map_file() uses PROT_READ, so const seems fitting; however unmap_file calls munmap/free, which do not take const, so an UNCONSTIFY is needed. To avoid the UNCONSTIFY hack, which is likely undefined behavior or some such, just remove the const. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 8e1fed6c 2015-03-24T16:40:29 compose: correctly parse modifier syntax As described in: http://cgit.freedesktop.org/xorg/lib/libX11/commit/?id=ddf3b09bb262d01b56fbaade421ac85b0e60a69f Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita c03834a1 2014-10-23T21:00:20 Reduce variable scopes Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita f774f819 2014-10-18T13:23:53 Replace some strncmp's with memcmp Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita a4cc119b 2014-10-18T12:36:40 compose/parser: save len in keysym_from_name cache This reduces a lot of strcmp's, and allows to use a faster memcmp. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita c6e63fd7 2014-10-14T11:28:17 compose/parser: fix parsing of multiple modifiers Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita d1c5dd14 2014-10-13T18:19:16 compose/parser: parse (! mods) properly We don't actually do anything with them. But if someone uses them we can at least not choke. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 3c0c3afa 2014-10-13T15:47:13 compose/parser: resolve keysyms in parser instead of scanner It will become context-sensitive. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 0b99c63c 2014-10-13T15:05:48 compose/parser: use parameter as intended Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 8bba4b34 2014-10-13T00:16:59 compose/parser: one more skip_to_eol() Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita a3116f97 2014-10-13T18:51:12 compose/parser: fix segfault when including The keysym cache for the new scanner was not initialized. To avoid such errors also in the future, require passing the priv argument in scanner_init(), instead of initializing it separately. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 65c355aa 2014-10-13T14:28:27 COPYING: add copyright notice from libX11:modules/im/ximcp/imLcPrs.c We have used some portions of it, so add the notice. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 8a0acf2c 2014-10-07T23:42:08 scanner-utils: optimize one-line comments Compose files have a lot of those. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita edc98b54 2014-09-12T18:44:30 compose: add xkbcommon-compose - implementation Signed-off-by: Ran Benita <ran234@gmail.com>