]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Another attempt to fix refcounting
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 16:54:46 +0000 (16:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 16:54:46 +0000 (16:54 +0000)
This allows tests to run without any problems, but there must be other
problems elsewhere.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 3f7417993d979fa339f2a7dd746e50942cb6c304..cc5d5915d202dc52fd328d34fac8dbe621725711 100644 (file)
@@ -145,7 +145,7 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d
 %token <string>                                T_SUBPARSER
 
 %type <parser>                         grammar
-%type <parser>                         subgrammar
+%type <parser>                         block
 %type <parser>                         subparser
 %type <string>                         subparser_name
 %type <parser>                         if_stmt
@@ -165,14 +165,8 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d
 }
 
 %initial-action {
+       //*parser = pakfire_parser_ref(parent);
        *parser = pakfire_parser_create(pakfire, parent, NULL, 0);
-       if (!*parser)
-               ABORT;
-
-       // This is now the new parent parser
-       if (parent)
-               pakfire_parser_unref(parent);
-       parent = pakfire_parser_ref(*parser);
 };
 
 %destructor { if ($$) pakfire_parser_unref($$); } <parser>
@@ -184,7 +178,14 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d
 
 grammar                                                : %empty
                                                        {
-                                                               $$ = pakfire_parser_ref(parent);
+                                                               $$ = pakfire_parser_create(pakfire, *parser, NULL, 0);
+                                                               if (!$$)
+                                                                       ABORT;
+
+                                                               // This becomes the new top parser
+                                                               if (*parser)
+                                                                       pakfire_parser_unref(*parser);
+                                                               *parser = pakfire_parser_ref($$);
                                                        }
                                                        | grammar declaration
                                                        {
@@ -222,32 +223,13 @@ grammar                                           : %empty
                                                        }
                                                        ;
 
-subgrammar_open                                : T_INDENT
-                                                       {
-                                                               // Create a new parser and make it parent
-                                                               PakfireParser p = pakfire_parser_create(pakfire, parent, NULL, 0);
-                                                               if (!p)
-                                                                       ABORT;
-
-                                                               if (parent)
-                                                                       pakfire_parser_unref(parent);
-                                                               parent = p;
-                                                       }
-                                                       ;
-
-subgrammar_close                       : T_OUTDENT
+block                                          : T_INDENT grammar T_OUTDENT
                                                        {
-                                                               // Move the parent pointer back
-                                                               PakfireParser p = pakfire_parser_get_parent(parent);
+                                                               // Reset the top parser
+                                                               PakfireParser p = pakfire_parser_get_parent(*parser);
+                                                               pakfire_parser_unref(*parser);
+                                                               *parser = p;
 
-                                                               if (parent)
-                                                                       pakfire_parser_unref(parent);
-                                                               parent = p;
-                                                       }
-                                                       ;
-
-subgrammar                                     : subgrammar_open grammar subgrammar_close
-                                                       {
                                                                $$ = $2;
                                                        }
                                                        ;
@@ -320,7 +302,7 @@ line                                                : T_STRING T_EOL
                                                        }
                                                        ;
 
-subparser                                      : subparser_name T_EOL subgrammar T_END T_EOL
+subparser                                      : subparser_name T_EOL block T_END T_EOL
                                                        {
                                                                pakfire_parser_set_namespace($3, $1);
 
@@ -332,7 +314,7 @@ subparser                                   : subparser_name T_EOL subgrammar T_END T_EOL
                                                                char* value;
 
                                                                // Create a new parser
-                                                               $$ = pakfire_parser_create(pakfire, parent, NULL, 0);
+                                                               $$ = pakfire_parser_create(pakfire, *parser, NULL, 0);
                                                                if (!$$)
                                                                        ABORT;
 
@@ -358,7 +340,7 @@ subparser_name                              : T_SUBPARSER
                                                        }
                                                        ;
 
-if_stmt                                                : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END T_EOL
+if_stmt                                                : T_IF T_STRING T_EQUALS T_STRING T_EOL block else_stmt T_END T_EOL
                                                        {
                                                                $$ = make_if_stmt(pakfire, OP_EQUALS, $2, $4, $6, $7);
 
@@ -369,7 +351,7 @@ if_stmt                                             : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END
                                                        }
                                                        ;
 
-else_stmt                                      : T_ELSE T_EOL subgrammar
+else_stmt                                      : T_ELSE T_EOL block
                                                        {
                                                                $$ = $3;
                                                        }