From: Michael Tremer Date: Sun, 29 Jun 2025 13:58:34 +0000 (+0000) Subject: parser: Internally pass around the context X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d1265b0892e17e75cd87a5080e54b7daa1b3ad5;p=pakfire.git parser: Internally pass around the context Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index cbf6a2be..0011ddef 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -153,10 +153,6 @@ pakfire_parser* pakfire_parser_ref(pakfire_parser* parser) { return parser; } -pakfire_root* pakfire_parser_get_root(pakfire_parser* parser) { - return pakfire_root_ref(parser->root); -} - pakfire_parser* pakfire_parser_unref(pakfire_parser* parser) { if (--parser->nrefs > 0) return parser; @@ -941,7 +937,7 @@ int pakfire_parser_read(pakfire_parser* parser, FILE* f, } // Run the parser - r = pakfire_parser_parse_data(parser, data, length, error); + r = pakfire_parser_parse_data(parser->ctx, parser->root, parser, data, length, error); if (r < 0) goto ERROR; @@ -976,7 +972,7 @@ int pakfire_parser_read_file(pakfire_parser* parser, const char* path, int pakfire_parser_parse(pakfire_parser* parser, const char* data, size_t size, pakfire_parser_error** error) { - return pakfire_parser_parse_data(parser, data, size, error); + return pakfire_parser_parse_data(parser->ctx, parser->root, parser, data, size, error); } char* pakfire_parser_dump(pakfire_parser* parser) { diff --git a/src/pakfire/parser.h b/src/pakfire/parser.h index 64eea460..50745783 100644 --- a/src/pakfire/parser.h +++ b/src/pakfire/parser.h @@ -31,6 +31,7 @@ typedef struct pakfire_parser pakfire_parser; #include #include #include +#include enum pakfire_parser_flags { PAKFIRE_PARSER_FLAGS_NONE = 0, @@ -83,8 +84,6 @@ const char* pakfire_parser_error_get_filename(pakfire_parser_error* error); int pakfire_parser_error_get_line(pakfire_parser_error* error); const char* pakfire_parser_error_get_message(pakfire_parser_error* error); -pakfire_root* pakfire_parser_get_root(pakfire_parser* parser); - typedef struct pakfire_parser_state { unsigned int lineno; @@ -110,8 +109,8 @@ typedef struct pakfire_parser_declaration { int pakfire_parser_apply_declaration( pakfire_parser* parser, pakfire_parser_declaration* declaration); -int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t len, - pakfire_parser_error** error); +int pakfire_parser_parse_data(pakfire_ctx* ctx, pakfire_root* root, pakfire_parser* parent, + const char* data, size_t len, pakfire_parser_error** error); int pakfire_parser_set_env(pakfire_parser* parser, pakfire_env* env); diff --git a/src/pakfire/parser/grammar.y b/src/pakfire/parser/grammar.y index 0308c8c3..120d3efc 100644 --- a/src/pakfire/parser/grammar.y +++ b/src/pakfire/parser/grammar.y @@ -409,9 +409,8 @@ else_stmt : T_ELSE T_EOL block %% -int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t len, - pakfire_parser_error** error) { - pakfire_root* root = pakfire_parser_get_root(parent); +int pakfire_parser_parse_data(pakfire_ctx* ctx, pakfire_root* root, pakfire_parser* parent, + const char* data, size_t len, pakfire_parser_error** error) { yyscan_t scanner; int r; @@ -423,9 +422,6 @@ int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t l .readline_indent = 0, }; - // Fetch context - pakfire_ctx* ctx = pakfire_root_get_ctx(root); - #ifdef ENABLE_DEBUG DEBUG(ctx, "Parsing the following data (%zu):\n%.*s\n", len, (int)len, data); @@ -482,10 +478,6 @@ int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t l ERROR: if (parser) pakfire_parser_unref(parser); - if (root) - pakfire_root_unref(root); - if (ctx) - pakfire_ctx_unref(ctx); yylex_destroy(scanner); return r;