Factor out a get_gio_module_dir

This also fixes some memory leaks on windows
This commit is contained in:
Ignacio Casal Quinteiro 2015-10-22 08:18:24 +02:00
parent 31c45cb6ae
commit 6dedc0364a

View File

@ -950,16 +950,6 @@ _g_io_win32_get_module (void)
return gio_dll; return gio_dll;
} }
#undef GIO_MODULE_DIR
/* GIO_MODULE_DIR is used only in code called just once,
* so no problem leaking this
*/
#define GIO_MODULE_DIR \
g_build_filename (g_win32_get_package_installation_directory_of_module (gio_dll), \
"lib", "gio", "modules", \
NULL)
#endif #endif
void void
@ -1020,13 +1010,36 @@ _g_io_modules_ensure_extension_points_registered (void)
G_UNLOCK (registered_extensions); G_UNLOCK (registered_extensions);
} }
static gchar *
get_gio_module_dir (void)
{
gchar *module_dir;
module_dir = g_strdup (g_getenv ("GIO_MODULE_DIR"));
if (module_dir == NULL)
{
#ifdef G_OS_WIN32
gchar *install_dir;
install_dir = g_win32_get_package_installation_directory_of_module (gio_dll);
module_dir = g_build_filename (install_dir,
"lib", "gio", "modules",
NULL);
g_free (install_dir);
#else
module_dir = GIO_MODULE_DIR;
#endif
}
return module_dir;
}
void void
_g_io_modules_ensure_loaded (void) _g_io_modules_ensure_loaded (void)
{ {
static gboolean loaded_dirs = FALSE; static gboolean loaded_dirs = FALSE;
const char *module_path; const char *module_path;
GIOModuleScope *scope; GIOModuleScope *scope;
const gchar *module_dir;
_g_io_modules_ensure_extension_points_registered (); _g_io_modules_ensure_extension_points_registered ();
@ -1034,6 +1047,8 @@ _g_io_modules_ensure_loaded (void)
if (!loaded_dirs) if (!loaded_dirs)
{ {
gchar *module_dir;
loaded_dirs = TRUE; loaded_dirs = TRUE;
scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES); scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
@ -1055,11 +1070,10 @@ _g_io_modules_ensure_loaded (void)
} }
/* Then load the compiled in path */ /* Then load the compiled in path */
module_dir = g_getenv ("GIO_MODULE_DIR"); module_dir = get_gio_module_dir ();
if (module_dir == NULL)
module_dir = GIO_MODULE_DIR;
g_io_modules_scan_all_in_directory_with_scope (module_dir, scope); g_io_modules_scan_all_in_directory_with_scope (module_dir, scope);
g_free (module_dir);
g_io_module_scope_free (scope); g_io_module_scope_free (scope);