Remove unnecessary !!(expressions)

_Bool already does that.

Signed-off-by: Ran Benita <ran234@gmail.com>
x11: don't iterate on empty batches

If count % SIZE == 0 we did a useless iteration where start==stop. It's
harmless but strange, so don't do that.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: don't shadow "str"

It's a name of a function in scanner-utils.h and also of some
parameters.

https://bugs.freedesktop.org/show_bug.cgi?id=79898

Reported-by: Bryce Harrington <b.harrington@samsung.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
keycodes: split CopyKeyInfoToKeymap to several functions

It's a bit easier to read and self-documenting. Also handles OOM better.

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

So it's OOM-safe and doesn't clobber keymap on failure.

Signed-off-by: Ran Benita <ran234@gmail.com>
ast-build: use cast instead of ->common

Missed in 1b2bb204e0baa2246a6232aea762c1edb00cd44a.

Signed-off-by: Ran Benita <ran234@gmail.com>
Replace darray_mem with a new darray_steal

That's a more declarative interface.

Signed-off-by: Ran Benita <ran234@gmail.com>
test: add file with a syntax error

We didn't really have any. It also a exposes a memory leak, since the
parser doesn't clean up the AST nodes of the discarded symbols.

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: don't leak AST nodes for discarded symbols

If the parser has symbols on the stack, and then enters an error, it
discards the symbols and fails. But their actions which allocate AST
nodes had already ran. So we must free these to avoid leaks.

We use %destructor declarations, see
http://www.gnu.org/software/bison/manual/html_node/Destructor-Decl.html

Note: byacc only supports %destructor when compiled with
--enable-btyacc. Also, it doesn't support using the parse-param in the
destructor. So we might revert this commit before the next release, or
forget about byacc.

https://github.com/xkbcommon/libxkbcommon/issues/8

Signed-off-by: Ran Benita <ran234@gmail.com>
parser: silence bison "unused value" warnings

Previous commit triggered these for some reason:

/home/ran/src/libxkbcommon/src/xkbcomp/parser.y:555.25-33: warning: unused value: $1 [-Wother]
 CoordList       :       CoordList COMMA Coord
                         ^^^^^^^^^

Signed-off-by: Ran Benita <ran234@gmail.com>
ast-build: make sure InterpDef is freeable

With the following two rules:

    InterpretDecl   :       INTERPRET InterpretMatch OBRACE
                                VarDeclList
                            CBRACE SEMI
                            { $2->def = $4; $$ = $2; }
                    ;

    InterpretMatch  :       KeySym PLUS Expr
                            { $$ = InterpCreate($1, $3); }
                    |       KeySym
                            { $$ = InterpCreate($1, NULL); }
                    ;

And the fact that InterpCreate doesn't initialize ->def, if the
VarDeclList fails, the %destructor tries to recursively free the
uninitialized ->def VarDef. So always initialize it.

That was the only problematic code in the parser for %destructor (I'm
pretty sure).

Signed-off-by: Ran Benita <ran234@gmail.com>
interactive-evdev: don't use sysexits.h

Signed-off-by: Ran Benita <ran234@gmail.com>
docs: fix self-reference

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