gplugin/gplugin

6966466e0e43
Parents 7d9e362672b7
Children b3ed6897b812
Move the dependecy regex instance to the manager instance

We used to do this as a global to save a tiny amount of memory, but this is
problematic when don't call gplugin_manager_init which is private.

I ran across this as I'm porting the unit tests to stop using the default
manager and instead create an instance to help their reproducibility.

Testing Done:
Ran with the turtles.

Reviewed at https://reviews.imfreedom.org/r/2985/
--- a/gplugin/gplugin-manager.c Wed Feb 28 00:06:21 2024 -0600
+++ b/gplugin/gplugin-manager.c Wed Feb 28 18:58:38 2024 -0600
@@ -76,6 +76,8 @@
GHashTable *loaders;
gboolean refresh_needed;
+
+ GRegex *dependency_regex;
};
G_DEFINE_FINAL_TYPE(GPluginManager, gplugin_manager, G_TYPE_OBJECT)
@@ -90,7 +92,6 @@
};
const gchar *dependency_pattern =
"^(?P<id>.+?)((?P<op>\\<=|\\<|==|=|\\>=|\\>)(?P<version>.+))?$";
-GRegex *dependency_regex = NULL;
/******************************************************************************
* Helpers
@@ -268,6 +269,8 @@
g_queue_free_full(manager->paths, g_free);
manager->paths = NULL;
+ g_clear_pointer(&manager->dependency_regex, g_regex_unref);
+
/* unload all of the loaded plugins */
g_hash_table_foreach(
manager->plugins,
@@ -480,6 +483,8 @@
manager->loaders =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
+
+ manager->dependency_regex = g_regex_new(dependency_pattern, 0, 0, NULL);
}
/******************************************************************************
@@ -511,8 +516,6 @@
}
}
}
-
- dependency_regex = g_regex_new(dependency_pattern, 0, 0, NULL);
}
void
@@ -520,8 +523,6 @@
{
g_clear_object(&native_loader);
- g_regex_unref(dependency_regex);
-
/* g_clear_pointer (and therefore g_clear_object), clears the pointer
* before calling the destroy function. So we have to handle this ourself
* and clear the pointer after destruction since plugins are unloaded
@@ -1203,7 +1204,7 @@
GSList *matches = NULL;
gchar *oid = NULL, *oop = NULL, *over = NULL;
- if(!g_regex_match(dependency_regex, ors[o], 0, &match)) {
+ if(!g_regex_match(manager->dependency_regex, ors[o], 0, &match)) {
continue;
}