state: fix possible index-out-of-bounds in action dispatch table

The current code assumes that action->type always falls in the range of
the xkb_action_type enum. But keymaps can also have Private actions,
which are allowed to set their own type number.

So with a default xkeyboard-config keymap, keycode 86 at level 4, which
triggers such an action, causes us to crash.

Fix it by always checking the bounds.

Signed-off-by: Ran Benita <ran234@gmail.com>
test: add key processing benchmark

This runs a bunch of random keys against xkb_state_update_key() and
xkb_state_key_get_one_sym(), in a fairly unintelligent way.

It might be nice to check when modifying this code path, or changing it,
to see things haven't slowed down considerably. However, given the
numbers this benchmark gives, it is pretty clear that we are not going
to be the bottleneck for anything. So this can more-or-less be ignored.

Incidentally, this also turned out to be a poor man's fuzzer, because it
turned up the fix in the previous commit. Maybe we should consider
beefing it up with an actual 'break stuff' intention and running it as
part of 'make check'.

Signed-off-by: Ran Benita <ran234@gmail.com>
configure.ac: add explicit PKG_PROG_PKG_CONFIG

We still use pkg-config to get the xkb_base variable from
xkeyboard-config, but we removed all of the other PKG_ macro calls. This
still works now, because XORG_DEFAULT_OPTIONS runs it somehow. But we
shouldn't rely on it.

Signed-off-by: Ran Benita <ran234@gmail.com>
configure.ac: don't tramp on user's CFLAGS

The configure test shouldn't touch CFLAGS, because they come last on the
command line and allow to users to override settings if needed.

Signed-off-by: Ran Benita <ran234@gmail.com>
Makefile.am: split sed script into multiple lines

To make it visible on one screen.

Signed-off-by: Ran Benita <ran234@gmail.com>
Makefile.am: move test.h to libtest_la_SOURCES

Rather than EXTRA_DIST, where it doesn't belong.

Signed-off-by: Ran Benita <ran234@gmail.com>
state: don't use xkb_state_serialize_* internally

The code in these cases is clearer when done directly.

Signed-off-by: Ran Benita <ran234@gmail.com>
doc: fix wrong comment

Signed-off-by: Ran Benita <ran234@gmail.com>
state: don't use xkb_keymap_num_layouts internally

Clearer and more greppable this way.

Signed-off-by: Ran Benita <ran234@gmail.com>
state, context: allow passing NULL to *_unref()

For error handling code, it's nice to be able to pass NULL to these
function without worrying about segfaults ensuing. free() sets the
precedent here.

Also document this fact.

Signed-off-by: Ran Benita <ran234@gmail.com>
test/keyseq: add test for setting depressed group

Tests the SetGroup action is working properly.

Signed-off-by: Ran Benita <ran234@gmail.com>
build: Make autoreconf honour ACLOCAL_FLAGS

When running autoreconf, it's possible to give flags to the underlying
aclocal by declaring a ACLOCAL_AMFLAGS variable in the top level
Makefile.am.

Putting ${ACLOCAL_FLAGS} there allows the user to set an environment
variable up before running autogen.sh and pull in the right directories
to look for m4 macros, say an up-to-date version of the xorg-util macros.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Cc: Daniel Stone <daniel@fooishbar.org>
build: Require xorg macros 1.16

For XORG_TESTSET_CFLAG and XORG_MEMORY_CHECK_FLAGS.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Cc: Daniel Stone <daniel@fooishbar.org>
action: don't allow private actions with a known type

Some obscure bug having to do with Private actions; see the comments.
This was prompted by:
https://bugs.freedesktop.org/show_bug.cgi?id=56491

Signed-off-by: Ran Benita <ran234@gmail.com>
Add some explanations on consumed modifiers

This should hopefully clarify this somewhat subtle point to the
uninitiated users.

Signed-off-by: Ran Benita <ran234@gmail.com>