Skip to content

Commit

Permalink
Don't put bump in scanner
Browse files Browse the repository at this point in the history
Signed-off-by: Ran Benita <[email protected]>
  • Loading branch information
bluetech committed Jan 28, 2025
1 parent 5bf26bf commit c10c9f2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/compose/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ parse_string_literal(struct xkb_context *ctx, const char *string)
{
struct scanner s;
union lvalue val;
scanner_init(&s, ctx, NULL, string, strlen(string), "(unamed)", NULL);
scanner_init(&s, ctx, string, strlen(string), "(unamed)", NULL);
switch (lex(&s, &val)) {
case TOK_STRING:
return strdup(val.string.str);
Expand Down Expand Up @@ -551,7 +551,7 @@ do_include(struct xkb_compose_table *table, struct scanner *s,
goto err_file;
}

scanner_init(&new_s, table->ctx, NULL, string, size, path, s->priv);
scanner_init(&new_s, table->ctx, string, size, path, s->priv);

ok = parse(table, &new_s, include_depth + 1);
if (!ok)
Expand Down Expand Up @@ -804,7 +804,7 @@ parse_string(struct xkb_compose_table *table, const char *string, size_t len,
const char *file_name)
{
struct scanner s;
scanner_init(&s, table->ctx, NULL, string, len, file_name, NULL);
scanner_init(&s, table->ctx, string, len, file_name, NULL);
if (!parse(table, &s, 0))
return false;
/* Maybe the allocator can use the excess space. */
Expand Down
3 changes: 0 additions & 3 deletions src/scanner-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct scanner {
size_t token_line, token_column;
const char *file_name;
struct xkb_context *ctx;
struct bump *bump;
void *priv;
};

Expand All @@ -89,7 +88,6 @@ struct scanner {

static inline void
scanner_init(struct scanner *s, struct xkb_context *ctx,
struct bump *bump,
const char *string, size_t len, const char *file_name,
void *priv)
{
Expand All @@ -100,7 +98,6 @@ scanner_init(struct scanner *s, struct xkb_context *ctx,
s->token_line = s->token_column = 1;
s->file_name = file_name;
s->ctx = ctx;
s->bump = bump;
s->priv = priv;
}

Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/parser-priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct scanner;
#include "parser.h"

int
_xkbcommon_lex(YYSTYPE *yylval, struct scanner *scanner);
_xkbcommon_lex(YYSTYPE *yylval, struct scanner *s, struct bump *bump);

XkbFile *
parse(struct bump *bump, struct xkb_context *ctx, struct scanner *scanner, const char *map);
Expand Down
3 changes: 2 additions & 1 deletion src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ resolve_keysym(struct parser_param *param, const char *name, xkb_keysym_t *sym_r
}

#define param_scanner param->scanner
#define param_bump param->bump
%}

%define api.pure
%lex-param { struct scanner *param_scanner }
%lex-param { struct scanner *param_scanner } { struct bump *param_bump }
%parse-param { struct parser_param *param }

%token
Expand Down
4 changes: 2 additions & 2 deletions src/xkbcomp/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ matcher_include(struct matcher *m, struct scanner *parent_scanner,
{
struct scanner s; /* parses the !include value */

scanner_init(&s, m->ctx, NULL, inc.start, inc.len,
scanner_init(&s, m->ctx, inc.start, inc.len,
parent_scanner->file_name, NULL);
s.token_line = parent_scanner->token_line;
s.token_column = parent_scanner->token_column;
Expand Down Expand Up @@ -1514,7 +1514,7 @@ read_rules_file(struct xkb_context *ctx,
return false;
}

scanner_init(&scanner, matcher->ctx, NULL, string, size, path, NULL);
scanner_init(&scanner, matcher->ctx, string, size, path, NULL);

/* Basic detection of wrong character encoding.
The first character relevant to the grammar must be ASCII:
Expand Down
8 changes: 4 additions & 4 deletions src/xkbcomp/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ number(struct scanner *s, int64_t *out, int *out_tok)
}

int
_xkbcommon_lex(YYSTYPE *yylval, struct scanner *s)
_xkbcommon_lex(YYSTYPE *yylval, struct scanner *s, struct bump *bump)
{
int tok;

Expand Down Expand Up @@ -124,7 +124,7 @@ _xkbcommon_lex(YYSTYPE *yylval, struct scanner *s)
"unterminated string literal");
return ERROR_TOK;
}
yylval->str = s->bump ? bump_strdup(s->bump, s->buf) : strdup(s->buf);
yylval->str = bump_strdup(bump, s->buf);
if (!yylval->str)
return ERROR_TOK;
return STRING;
Expand Down Expand Up @@ -177,7 +177,7 @@ _xkbcommon_lex(YYSTYPE *yylval, struct scanner *s)
tok = keyword_to_token(s->buf, s->buf_pos - 1);
if (tok != -1) return tok;

yylval->str = s->bump ? bump_strdup(s->bump, s->buf) : strdup(s->buf);
yylval->str = bump_strdup(bump, s->buf);
if (!yylval->str)
return ERROR_TOK;
return IDENT;
Expand All @@ -204,7 +204,7 @@ XkbParseString(struct bump *bump, struct xkb_context *ctx,
const char *file_name, const char *map)
{
struct scanner scanner;
scanner_init(&scanner, ctx, bump, string, len, file_name, NULL);
scanner_init(&scanner, ctx, string, len, file_name, NULL);

/* Basic detection of wrong character encoding.
The first character relevant to the grammar must be ASCII:
Expand Down

0 comments on commit c10c9f2

Please sign in to comment.