As the comment nicely puts it, this is a bit weird. When you try to
evaluate an expression of type string into an integer, what it does is:
"" -> 0
"c" -> (ascii value, i.e. like a char literal)
more than one char -> error
The first one is obviously not very useful; why not just write 0?
The second one might be useful (though I don't see where in a keymap
it would be), but I don't think anyone would consider trying "X" for
that anyway.
A look through xkeyboard-config shows "" only used once as a string, and
"X" also only used as strings (and mostly in geometry which we don't
evaluate anyway). And I seriously doubt it's used (purposely) anywhere
else. So remove it.
Signed-off-by: Ran Benita <ran234@gmail.com>
Clean up the return code handling from
xkb_context_add_include_paths_default, and thus fail context creation if
we can't add any of the default include paths, but were asked to. If
this happens, dump the DFLT_XKB_CONFIG_ROOT out in the log message, so
at least we know what we aren't looking at.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Explicit is better than implicit, and this union makes it hard to follow
what's what, particularly the confusion with ival/uval.
The other Resolve functions will follow.
Signed-off-by: Ran Benita <ran234@gmail.com>
It's more tidy and less error prone, since we use strcasecmp == 0 a lot.
We replace strcmp == 0 by streq, strcasecmp == 0 by istreq,
uStrCasePrefix by istreq_prefix and uDupString by strdup_safe.
Signed-off-by: Ran Benita <ran234@gmail.com>
The key name is always XkbKeyNameLength (= 4) bytes, so we can maintain
it directly in YYSTYPE union and copy when needed, instead of treating
it like a full blown string and then copy. This means the scanner
checks the length itself.
rulescomp under valgrind, before:
==1038== total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated
after:
==9377== total heap usage: 155,643 allocs, 155,643 frees, 9,672,788 bytes allocated
Signed-off-by: Ran Benita <ran234@gmail.com>
We often get a strdup'd string, just to pass it over the atom_intern and
then immediately free it. But atom_intern then strdup's it again (if
it's not interned already); so instead we can have the interning "steal"
the memory instead of allocing a new one and freeing the old one. This
is done by a new xkb_atom_steal function.
It also turns out, that every time we strdup an atom, we don't actually
modify it afterwards. Since we are guaranteed that the atom table will
live as long as the context, we can just use xkb_atom_text instead. This
removes a some more dynamic allocations.
For this change we had to remove the ability to append two strings, e.g.
"foo" + "bar" -> "foobar"
which is only possible with string literals. This is unused and quite
useless for our purposes.
xkb_atom_strdup is left unused, as it may still be useful.
Running rulescomp in valgrind, Before:
==7907== total heap usage: 173,698 allocs, 173,698 frees, 9,775,973 bytes allocated
After:
==6348== total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated
Signed-off-by: Ran Benita <ran234@gmail.com>
Without the re-initialization, the copying fails. This wasn't noticed
because this code practically never gets executed with ordinary keymaps.
Signed-off-by: Ran Benita <ran234@gmail.com>
==7071== Conditional jump or move depends on uninitialised value(s)
==7071== at 0x40B6CB: AddIndicatorName (keycodes.c:148)
==7071== by 0x40C34F: MergeIncludedKeycodes (keycodes.c:420)
==7071== by 0x40C613: HandleIncludeKeycodes (keycodes.c:480)
==7071== by 0x40D022: HandleKeycodesFile (keycodes.c:733)
==7071== by 0x40D79F: CompileKeycodes (keycodes.c:881)
==7071== by 0x401E22: compile_keymap (xkbcomp.c:157)
==7071== by 0x402091: xkb_map_new_from_kccgst (xkbcomp.c:229)
==7071== by 0x40216A: xkb_map_new_from_names (xkbcomp.c:254)
==7071== by 0x4046F5: test_compile_rules (common.c:164)
==7071== by 0x4015C1: test_rmlvo (rulescomp.c:44)
==7071== by 0x40180D: main (rulescomp.c:98)
Signed-off-by: Ran Benita <ran234@gmail.com>
and let the info always be the first argument to the various functions,
just for consistency (and it acting as the contex for this file).
Signed-off-by: Ran Benita <ran234@gmail.com>
Add new public API to provide the library users with some options to
control and customize the logging output from the library. It is based
upon the skeleton from the libabc demo libray:
https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git
which is public domain and works pretty well.
This requires passing in the context object in every logging call, and
thus the conversion is done file by file. We also remove the global
warningLevel variable in favor of a verbosity level in the context,
which can be set by the user and is silent by default.
One issue is the ACTION calls, which, while nice, do not play very well
with line- and priority-based logging, and would require some
line continuation handling or keeping state or some other compromise. So
instead remove these and just inline them with their respective
warning/error. So instead of:
ERROR("Memory allocation failed\n")
ACTION("Removing all files on hardisk\n")
its something like that:
log_err("Memory allocation failed; Removing all files on harddisk\n")
Signed-off-by: Ran Benita <ran234@gmail.com>