girepository: Add a gi_repository_new() function

It’s not intended that most people will use this, but it’s going to be
quite useful for adding unit tests — we don’t really want the unit tests
to share global state (a singleton `GIRepository`) between tests.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3155
This commit is contained in:
Philip Withnall 2023-11-23 23:22:55 +00:00
parent f5d13c9cf8
commit 0d9b674784
2 changed files with 21 additions and 1 deletions

View File

@ -184,7 +184,7 @@ init_globals (void)
return;
if (default_repository == NULL)
default_repository = g_object_new (GI_TYPE_REPOSITORY, NULL);
default_repository = gi_repository_new ();
if (typelib_search_path == NULL)
{
@ -688,6 +688,23 @@ gi_repository_get_default (void)
return get_repository (NULL);
}
/**
* gi_repository_new:
*
* Create a new (non-singleton) #GIRepository.
*
* Most callers should use gi_repository_get_default() instead, as a singleton
* repository is more useful in most situations.
*
* Returns: (transfer full): a new #GIRepository
* Since: 2.80
*/
GIRepository *
gi_repository_new (void)
{
return g_object_new (GI_TYPE_REPOSITORY, NULL);
}
/**
* gi_repository_get_n_infos:
* @repository: (allow-none): A #GIRepository or %NULL for the singleton

View File

@ -103,6 +103,9 @@ GType gi_repository_get_type (void) G_GNUC_CONST;
GI_AVAILABLE_IN_ALL
GIRepository *gi_repository_get_default (void);
GI_AVAILABLE_IN_ALL
GIRepository *gi_repository_new (void);
GI_AVAILABLE_IN_ALL
void gi_repository_prepend_search_path (const char *directory);