girepository/girparser: Move dependencies ownership to each module

In this way the module can survive without that the parser is fully
alive.

At the moment a module has not a ref-count system, but this makes things
clearer when we return the module from a parser.
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-10 18:08:26 +02:00 committed by Philip Withnall
parent 9d65076eba
commit 6e38293fec
3 changed files with 6 additions and 3 deletions

View File

@ -47,7 +47,7 @@ struct _GIIrModule
char *version;
char *shared_library;
char *c_prefix;
GList *dependencies;
GList *dependencies; /* (owned) */
GList *entries;
/* All modules that are included directly or indirectly */

View File

@ -83,7 +83,7 @@ gi_ir_module_free (GIIrModule *module)
gi_ir_node_free ((GIIrNode *)e->data);
g_list_free (module->entries);
/* Don't free dependencies, we inherit that from the parser */
g_clear_list (&module->dependencies, g_free);
g_list_free (module->include_modules);

View File

@ -3194,7 +3194,9 @@ start_element_handler (GMarkupParseContext *context,
ctx->include_modules = NULL;
ctx->modules = g_list_append (ctx->modules, ctx->current_module);
ctx->current_module->dependencies = ctx->dependencies;
g_clear_list (&ctx->current_module->dependencies, g_free);
ctx->current_module->dependencies =
g_list_copy_deep (ctx->dependencies, (GCopyFunc) g_strdup, NULL);
state_switch (ctx, STATE_NAMESPACE);
goto out;
@ -3824,6 +3826,7 @@ gi_ir_parser_parse_string (GIIrParser *parser,
}
g_clear_slist (&ctx.node_stack, NULL);
g_clear_list (&ctx.dependencies, g_free);
g_markup_parse_context_free (context);
if (ctx.modules)