Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also scanner
Browse files Browse the repository at this point in the history
total heap usage: 1,483,536 allocs, 1,483,536 frees, 512,020,213 bytes allocated

Signed-off-by: Ran Benita <[email protected]>
bluetech committed Jan 26, 2025

Verified

This commit was signed with the committer’s verified signature.
vbudhram Vijay Budhram
1 parent 229325c commit 2e70428
Showing 5 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/compose/parser.c
Original file line number Diff line number Diff line change
@@ -504,7 +504,7 @@ parse_string_literal(struct xkb_context *ctx, const char *string)
{
struct scanner s;
union lvalue val;
scanner_init(&s, ctx, string, strlen(string), "(unamed)", NULL);
scanner_init(&s, ctx, NULL, string, strlen(string), "(unamed)", NULL);
switch (lex(&s, &val)) {
case TOK_STRING:
return strdup(val.string.str);
@@ -551,7 +551,7 @@ do_include(struct xkb_compose_table *table, struct scanner *s,
goto err_file;
}

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

ok = parse(table, &new_s, include_depth + 1);
if (!ok)
@@ -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, string, len, file_name, NULL);
scanner_init(&s, table->ctx, NULL, string, len, file_name, NULL);
if (!parse(table, &s, 0))
return false;
/* Maybe the allocator can use the excess space. */
4 changes: 4 additions & 0 deletions src/scanner-utils.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
#include <stddef.h>
#include <string.h>

#include "bump.h"
#include "context.h"
#include "darray.h"
#include "messages-codes.h"
@@ -63,6 +64,7 @@ struct scanner {
size_t token_line, token_column;
const char *file_name;
struct xkb_context *ctx;
struct bump *bump;
void *priv;
};

@@ -87,6 +89,7 @@ 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)
{
@@ -97,6 +100,7 @@ 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;
}

10 changes: 3 additions & 7 deletions src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
@@ -231,8 +231,6 @@ resolve_keysym(struct parser_param *param, const char *name, xkb_keysym_t *sym_r
%type <fileList> XkbMapConfigList
%type <file> XkbCompositeMap

%destructor { free($$); } <str>

%%

/*
@@ -390,7 +388,6 @@ Decl : OptMergeMode VarDecl
| MergeMode STRING
{
$$ = (ParseCommon *) IncludeCreate(param->bump, param->ctx, $2, $1);
free($2);
}
;

@@ -763,7 +760,6 @@ KeySym : IDENT
);
$$ = XKB_KEY_NoSymbol;
}
free($1);
}
/* Handle keysym that is also a keyword */
| SECTION { $$ = XKB_KEY_section; }
@@ -822,18 +818,18 @@ Integer : INTEGER { $$ = $1; }
KeyCode : INTEGER { $$ = $1; }
;

Ident : IDENT { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); free($1); }
Ident : IDENT { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); }
| DEFAULT { $$ = xkb_atom_intern_literal(param->ctx, "default"); }
;

String : STRING { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); free($1); }
String : STRING { $$ = xkb_atom_intern(param->ctx, $1, strlen($1)); }
;

OptMapName : MapName { $$ = $1; }
| { $$ = NULL; }
;

MapName : STRING { $$ = bump_strdup(param->bump, $1); free($1); }
MapName : STRING { $$ = bump_strdup(param->bump, $1); }
;

%%
4 changes: 2 additions & 2 deletions src/xkbcomp/rules.c
Original file line number Diff line number Diff line change
@@ -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, inc.start, inc.len,
scanner_init(&s, m->ctx, NULL, inc.start, inc.len,
parent_scanner->file_name, NULL);
s.token_line = parent_scanner->token_line;
s.token_column = parent_scanner->token_column;
@@ -1514,7 +1514,7 @@ read_rules_file(struct xkb_context *ctx,
return false;
}

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

/* Basic detection of wrong character encoding.
The first character relevant to the grammar must be ASCII:
7 changes: 4 additions & 3 deletions src/xkbcomp/scanner.c
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@

#include "config.h"

#include "bump.h"
#include "xkbcomp-priv.h"
#include "parser-priv.h"
#include "scanner-utils.h"
@@ -123,7 +124,7 @@ _xkbcommon_lex(YYSTYPE *yylval, struct scanner *s)
"unterminated string literal");
return ERROR_TOK;
}
yylval->str = strdup(s->buf);
yylval->str = s->bump ? bump_strdup(s->bump, s->buf) : strdup(s->buf);
if (!yylval->str)
return ERROR_TOK;
return STRING;
@@ -176,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 = strdup(s->buf);
yylval->str = s->bump ? bump_strdup(s->bump, s->buf) : strdup(s->buf);
if (!yylval->str)
return ERROR_TOK;
return IDENT;
@@ -203,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, string, len, file_name, NULL);
scanner_init(&scanner, ctx, bump, string, len, file_name, NULL);

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

0 comments on commit 2e70428

Please sign in to comment.