From: Michael Tremer Date: Sun, 29 Jun 2025 13:54:50 +0000 (+0000) Subject: parser: Directly pass the context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=211d7cc81b3305fe1da18d6fdc71378c137de869;p=people%2Fms%2Fpakfire.git parser: Directly pass the context Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/dist.c b/src/pakfire/dist.c index 107036f8..86ac3989 100644 --- a/src/pakfire/dist.c +++ b/src/pakfire/dist.c @@ -154,7 +154,8 @@ int pakfire_read_makefile(pakfire_parser** parser, pakfire_ctx* ctx, pakfire_roo int r; // Create a new parser - r = pakfire_parser_create(parser, root, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); + r = pakfire_parser_create(parser, ctx, root, NULL, NULL, + PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); if (r < 0) goto ERROR; diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index 12664d1e..cbf6a2be 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -94,8 +94,8 @@ static void pakfire_parser_free(pakfire_parser* parser) { free(parser); } -int pakfire_parser_create(pakfire_parser** parser, - pakfire_root* root, pakfire_parser* parent, const char* namespace, int flags) { +int pakfire_parser_create(pakfire_parser** parser, pakfire_ctx* ctx, pakfire_root* root, + pakfire_parser* parent, const char* namespace, int flags) { pakfire_parser* self = NULL; int r; @@ -105,7 +105,7 @@ int pakfire_parser_create(pakfire_parser** parser, return -errno; // Store a reference to the context - self->ctx = pakfire_root_get_ctx(root); + self->ctx = pakfire_ctx_ref(ctx); // Store a reference to the root self->root = pakfire_root_ref(root); @@ -140,7 +140,7 @@ pakfire_parser* pakfire_parser_create_child(pakfire_parser* parser, const char* int r; // Create the parser - r = pakfire_parser_create(&child, parser->root, parser, namespace, parser->flags); + r = pakfire_parser_create(&child, parser->ctx, parser->root, parser, namespace, parser->flags); if (r < 0) return NULL; diff --git a/src/pakfire/parser.h b/src/pakfire/parser.h index 91d1046e..64eea460 100644 --- a/src/pakfire/parser.h +++ b/src/pakfire/parser.h @@ -26,6 +26,7 @@ typedef struct pakfire_parser pakfire_parser; +#include #include #include #include @@ -38,7 +39,7 @@ enum pakfire_parser_flags { typedef struct pakfire_parser_error pakfire_parser_error; -int pakfire_parser_create(pakfire_parser** parser, pakfire_root* root, +int pakfire_parser_create(pakfire_parser** parser, pakfire_ctx* ctx, pakfire_root* root, pakfire_parser* parent, const char* namespace, int flags); pakfire_parser* pakfire_parser_create_child(pakfire_parser* parser, const char* namespace); diff --git a/src/pakfire/parser/grammar.y b/src/pakfire/parser/grammar.y index aba5c43c..0308c8c3 100644 --- a/src/pakfire/parser/grammar.y +++ b/src/pakfire/parser/grammar.y @@ -171,7 +171,7 @@ static void pakfire_parser_free_declaration(pakfire_parser_declaration* declarat } %initial-action { - int r = pakfire_parser_create(parser, root, parent, NULL, 0); + int r = pakfire_parser_create(parser, ctx, root, parent, NULL, 0); if (r < 0) ABORT; }; @@ -185,7 +185,7 @@ static void pakfire_parser_free_declaration(pakfire_parser_declaration* declarat grammar : %empty { - int r = pakfire_parser_create(&$$, root, *parser, NULL, 0); + int r = pakfire_parser_create(&$$, ctx, root, *parser, NULL, 0); if (r < 0) ABORT; @@ -347,7 +347,7 @@ subparser : subparser_name T_EOL block T_END T_EOL int r; // Create a new parser - r = pakfire_parser_create(&$$, root, *parser, NULL, 0); + r = pakfire_parser_create(&$$, ctx, root, *parser, NULL, 0); if (r < 0) ABORT; diff --git a/tests/libpakfire/makefile.c b/tests/libpakfire/makefile.c index a35a91d2..b764e044 100644 --- a/tests/libpakfire/makefile.c +++ b/tests/libpakfire/makefile.c @@ -70,7 +70,7 @@ static int test_parse(const struct test* t) { FILE* f = fopen(path, "r"); ASSERT(f); - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, 0)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, 0)); ASSERT_SUCCESS(pakfire_parser_read(parser, f, NULL)); @@ -96,7 +96,7 @@ static int test_macros(const struct test* t) { pakfire_parser* parser = NULL; int r = EXIT_FAILURE; - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, 0)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, 0)); // Load 'em all ASSERT_SUCCESS(load_macros(parser)); @@ -121,7 +121,7 @@ static int test_packages(const struct test* t) { ASSERT_SUCCESS(pakfire_repo_create(&repo, t->root, "test")); ASSERT(repo); - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS)); // Set some architecture diff --git a/tests/libpakfire/parser.c b/tests/libpakfire/parser.c index 39b97fc6..81bb935d 100644 --- a/tests/libpakfire/parser.c +++ b/tests/libpakfire/parser.c @@ -35,7 +35,7 @@ static int test_parser(const struct test* t) { char* s = NULL; // Create a new parser - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, 0)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, 0)); // Retrieve a value that does not exist ASSERT_NULL(pakfire_parser_get(parser, NULL, "null")); @@ -119,7 +119,7 @@ static int test_parser_files(const struct test* t) { ASSERT_SUCCESS(pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, *file)); // Create a new parser - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, 0)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, 0)); FILE* f = fopen(path, "r"); ASSERT(f); @@ -150,7 +150,7 @@ static int test_append(const struct test* t) { char* s = NULL; // Create a new parser - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, 0)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, 0)); const char* str1 = "a = 1\n" @@ -202,7 +202,8 @@ static int test_parser_command(const struct test* t) { pakfire_parser* parser = NULL; int r = EXIT_FAILURE; - ASSERT_SUCCESS(pakfire_parser_create(&parser, t->root, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS)); + ASSERT_SUCCESS(pakfire_parser_create(&parser, t->ctx, t->root, NULL, NULL, + PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS)); ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "command", command, 0)); diff --git a/tests/parser/test.c b/tests/parser/test.c index 0acd12bb..e86f1f86 100644 --- a/tests/parser/test.c +++ b/tests/parser/test.c @@ -72,7 +72,7 @@ int main(int argc, const char* argv[]) { } // Create a new parser - r = pakfire_parser_create(&parser, root, NULL, NULL, 0); + r = pakfire_parser_create(&parser, ctx, root, NULL, NULL, 0); if (r < 0) { fprintf(stderr, "Could not create a parser: %s\n", strerror(-r)); goto ERROR;