]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Internally pass around the context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:58:34 +0000 (13:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 29 Jun 2025 13:58:34 +0000 (13:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c
src/pakfire/parser.h
src/pakfire/parser/grammar.y

index cbf6a2be96a15e4e3e3919811145dc57f6b951b7..0011ddefcaf702f37f08f724650266171660456c 100644 (file)
@@ -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) {
index 64eea460cc01b35df49cd3b8715f97cdd0a61392..50745783775c4824d40e37298aaab579debb3f1b 100644 (file)
@@ -31,6 +31,7 @@ typedef struct pakfire_parser pakfire_parser;
 #include <pakfire/package.h>
 #include <pakfire/parser.h>
 #include <pakfire/repo.h>
+#include <pakfire/root.h>
 
 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);
 
index 0308c8c346c73ad354e9c4974ac1a491d99a4c24..120d3efcf610db4ab6e79cae6c08a2a5ee6ad215 100644 (file)
@@ -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;