[gspell] language: code cleanup in get dirs functions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell] language: code cleanup in get dirs functions
- Date: Sun, 27 Dec 2015 18:06:27 +0000 (UTC)
commit fa38911aef2f719a8dbe486f9b3469eec727dbd5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Dec 27 17:10:57 2015 +0100
language: code cleanup in get dirs functions
Free the strings when no longer needed instead of keeping them in
memory.
gspell/gspell-language.c | 69 ++++++++++++++++++++--------------------------
1 files changed, 30 insertions(+), 39 deletions(-)
---
diff --git a/gspell/gspell-language.c b/gspell/gspell-language.c
index 16c0244..20de9b7 100644
--- a/gspell/gspell-language.c
+++ b/gspell/gspell-language.c
@@ -43,12 +43,12 @@ G_DEFINE_BOXED_TYPE (GspellLanguage,
static GHashTable *iso_639_table = NULL;
static GHashTable *iso_3166_table = NULL;
-#define ISOCODESLOCALEDIR ISO_CODES_PREFIX "/share/locale"
-
#ifdef G_OS_WIN32
+
#ifdef DATADIR
#undef DATADIR
#endif
+
#include <shlobj.h>
static HMODULE hmodule;
@@ -72,55 +72,38 @@ DllMain (HINSTANCE hinstDLL,
return TRUE;
}
+#endif /* G_OS_WIN32 */
+
static gchar *
-_get_iso_codes_prefix (void)
+get_iso_codes_prefix (void)
{
- static gchar retval[1000];
- static gboolean beenhere = FALSE;
- gchar *temp_dir = 0;
+ gchar *prefix = NULL;
- if (beenhere)
- {
- return retval;
- }
+#ifdef G_OS_WIN32
+ prefix = g_win32_get_package_installation_directory_of_module ((gpointer) hmodule);
+#endif
- if (!(temp_dir = g_win32_get_package_installation_directory_of_module ((gpointer) hmodule)))
+ if (prefix == NULL)
{
- strcpy (retval, ISO_CODES_PREFIX);
- return retval;
+ prefix = g_strdup (ISO_CODES_PREFIX);
}
- strcpy (retval, temp_dir);
- g_free (temp_dir);
- beenhere = TRUE;
- return retval;
+ return prefix;
}
static gchar *
-_get_isocodeslocaledir (void)
+get_iso_codes_localedir (void)
{
- static gchar retval[1000];
- static gboolean beenhere = FALSE;
+ gchar *prefix;
+ gchar *localedir;
- if (beenhere)
- {
- return retval;
- }
+ prefix = get_iso_codes_prefix ();
+ localedir = g_build_filename (prefix, "share", "locale", NULL);
+ g_free (prefix);
- strcpy (retval, _get_iso_codes_prefix ());
- strcat (retval, "\\share\\locale");
- beenhere = TRUE;
- return retval;
+ return localedir;
}
-#undef ISO_CODES_PREFIX
-#define ISO_CODES_PREFIX _get_iso_codes_prefix ()
-
-#undef ISOCODESLOCALEDIR
-#define ISOCODESLOCALEDIR _get_isocodeslocaledir ()
-
-#endif /* G_OS_WIN32 */
-
static void
iso_639_start_element (GMarkupParseContext *context,
const gchar *element_name,
@@ -225,15 +208,18 @@ iso_codes_parse (const GMarkupParser *parser,
GHashTable *hash_table)
{
GMappedFile *mapped_file;
+ gchar *prefix;
gchar *filename;
GError *error = NULL;
- filename = g_build_filename (ISO_CODES_PREFIX,
+ prefix = get_iso_codes_prefix ();
+ filename = g_build_filename (prefix,
"share",
"xml",
"iso-codes",
basename,
NULL);
+ g_free (prefix);
mapped_file = g_mapped_file_new (filename, FALSE, &error);
g_free (filename);
@@ -351,6 +337,7 @@ gspell_language_get_available (void)
{
static gboolean initialized = FALSE;
static GList *available_languages = NULL;
+ gchar *localedir;
EnchantBroker *broker;
GTree *tree;
@@ -361,12 +348,16 @@ gspell_language_get_available (void)
initialized = TRUE;
- bindtextdomain (ISO_639_DOMAIN, ISOCODESLOCALEDIR);
+ localedir = get_iso_codes_localedir ();
+
+ bindtextdomain (ISO_639_DOMAIN, localedir);
bind_textdomain_codeset (ISO_639_DOMAIN, "UTF-8");
- bindtextdomain (ISO_3166_DOMAIN, ISOCODESLOCALEDIR);
+ bindtextdomain (ISO_3166_DOMAIN, localedir);
bind_textdomain_codeset (ISO_3166_DOMAIN, "UTF-8");
+ g_free (localedir);
+
iso_639_table = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]