summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstrap.conf4
-rw-r--r--m4/.gitignore3
-rw-r--r--m4/gnulib-cache.m44
-rw-r--r--src/applespell/applespell_checker.mm1
-rw-r--r--src/enchant-ispell.c10
-rw-r--r--src/enchant-lsmod.c14
-rw-r--r--src/enchant-provider.h7
-rw-r--r--src/enchant.c97
-rw-r--r--src/hunspell/hunspell_checker.cpp22
-rw-r--r--src/uspell/uspell_provider.cpp9
-rw-r--r--src/voikko/voikko_provider.c2
11 files changed, 87 insertions, 86 deletions
diff --git a/bootstrap.conf b/bootstrap.conf
index e7b4ef6..487d51f 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -1,4 +1,4 @@
-# bootstrap.conf (GNU zile) version 2017-02-22
+# bootstrap.conf (GNU zile) version 2017-03-03
# Written by Gary V. Vaughan, 2010
# Copyright (C) 2010 Free Software Foundation, Inc.
@@ -45,10 +45,12 @@ gnulib_tool_options='
# gnulib modules used by this package.
gnulib_modules='
+ alloca
bootstrap
flock
manywarnings
snippet/unused-parameter
+ strdup-posix
'
diff --git a/m4/.gitignore b/m4/.gitignore
index 605f5ff..f5ac187 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -37,3 +37,6 @@
/ssize_t.m4
/manywarnings.m4
/warnings.m4
+/malloc.m4
+/strdup.m4
+/string_h.m4
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 4700350..e8e2c5b 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -27,15 +27,17 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --local-dir=gl --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=gl bootstrap flock manywarnings snippet/unused-parameter
+# gnulib-tool --import --local-dir=gl --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=gl alloca bootstrap flock manywarnings snippet/unused-parameter strdup-posix
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gl])
gl_MODULES([
+ alloca
bootstrap
flock
manywarnings
snippet/unused-parameter
+ strdup-posix
])
gl_AVOID([])
gl_SOURCE_BASE([lib])
diff --git a/src/applespell/applespell_checker.mm b/src/applespell/applespell_checker.mm
index 2ad3fc3..67688a4 100644
--- a/src/applespell/applespell_checker.mm
+++ b/src/applespell/applespell_checker.mm
@@ -1,3 +1,4 @@
+// FIXME: Use @autoreleasepool
/* enchant
* Copyright (C) 2004 Remi Payette
* Copyright (C) 2004 Francis James Franklin
diff --git a/src/enchant-ispell.c b/src/enchant-ispell.c
index 6696f09..9489aa3 100644
--- a/src/enchant-ispell.c
+++ b/src/enchant-ispell.c
@@ -322,12 +322,10 @@ convert_language_code (gchar *code)
size_t i;
for (i = 0; lingua[i].ispell; i++) {
if (!strcmp(code,lingua[i].ispell)) {
- /* We must call g_strdup() because the calling program g_free()s the result. */
- return g_strdup (lingua[i].enchant);
+ return strdup (lingua[i].enchant);
}
}
- /* Let's call g_strdup() here too! */
- return g_strdup (code);
+ return strdup (code);
}
@@ -417,12 +415,12 @@ parse_file (FILE * in, FILE * out, IspellMode_t mode, int countLines, gchar *dic
if (!dict) {
fprintf (stderr, "Couldn't create a dictionary for %s\n", lang);
- g_free (lang);
+ free (lang);
enchant_broker_free (broker);
return 1;
}
- g_free (lang);
+ free (lang);
str = g_string_new (NULL);
diff --git a/src/enchant-lsmod.c b/src/enchant-lsmod.c
index f635dc3..87f8ea1 100644
--- a/src/enchant-lsmod.c
+++ b/src/enchant-lsmod.c
@@ -82,23 +82,23 @@ main (int argc, char **argv)
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "-lang")) {
if (i < (argc - 1)) {
- lang_tag = g_strdup (argv[++i]);
+ lang_tag = strdup (argv[++i]);
} else {
lang_tag = enchant_get_user_language();
if (!lang_tag || !strcmp (lang_tag, "C")) {
- g_free(lang_tag); /* lang might be "C" */
- lang_tag = g_strdup ("en");
+ free(lang_tag); /* lang might be "C" */
+ lang_tag = strdup ("en");
}
}
mode = 1;
} else if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "-?") || !strcmp(argv[i], "-help")) {
printf ("%s [-lang [language_tag]] [-list-dicts] [-h] [-v]\n", argv[0]);
- g_free (lang_tag);
+ free (lang_tag);
return 0;
} else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "-version")) {
printf ("%s %s\n", argv[0], PACKAGE_VERSION);
- g_free (lang_tag);
+ free (lang_tag);
return 0;
} else if (!strcmp (argv[i], "-list-dicts")) {
mode = 2;
@@ -121,7 +121,7 @@ main (int argc, char **argv)
if (!dict) {
printf ("No dictionary available for '%s'.\n", lang_tag);
- g_free (lang_tag);
+ free (lang_tag);
enchant_broker_free (broker);
return 1;
} else {
@@ -132,7 +132,7 @@ main (int argc, char **argv)
enchant_broker_list_dicts (broker, enumerate_dicts, stdout);
}
- g_free (lang_tag);
+ free (lang_tag);
enchant_broker_free (broker);
return 0;
diff --git a/src/enchant-provider.h b/src/enchant-provider.h
index 1d4c7a3..d8dd2ac 100644
--- a/src/enchant-provider.h
+++ b/src/enchant-provider.h
@@ -42,12 +42,11 @@
extern "C" {
#endif
-/* private */
-ENCHANT_MODULE_EXPORT(char *)
- enchant_get_user_language(void);
-
typedef struct str_enchant_provider EnchantProvider;
+ENCHANT_MODULE_EXPORT(char *)
+ enchant_get_user_language(void);
+
ENCHANT_MODULE_EXPORT (GSList *)
enchant_get_user_config_dirs (void);
diff --git a/src/enchant.c b/src/enchant.c
index 260a686..aa2bddb 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -103,7 +103,7 @@ _enchant_get_user_home_dirs (void)
home_dir = g_get_home_dir ();
if (home_dir)
{
- dirs = g_slist_append (dirs, g_strdup (home_dir));
+ dirs = g_slist_append (dirs, strdup (home_dir));
}
return dirs;
@@ -135,7 +135,7 @@ _enchant_get_dirs_from_string (const char * string)
for (i = 0; tokens[i]; i++)
{
char *token = g_strstrip(tokens[i]);
- dirs = g_slist_append (dirs, g_strdup (token));
+ dirs = g_slist_append (dirs, strdup (token));
}
g_strfreev (tokens);
@@ -184,8 +184,7 @@ enchant_get_user_config_dirs (void)
NULL));
}
- g_slist_foreach (home_dirs, (GFunc)g_free, NULL);
- g_slist_free (home_dirs);
+ g_slist_free_full (home_dirs, free);
}
return user_dirs;
@@ -212,7 +211,7 @@ enchant_get_module_dirs (void)
}
#if defined(ENCHANT_GLOBAL_MODULE_DIR)
- module_dirs = g_slist_append (module_dirs, g_strdup (ENCHANT_GLOBAL_MODULE_DIR));
+ module_dirs = g_slist_append (module_dirs, strdup (ENCHANT_GLOBAL_MODULE_DIR));
#endif
/* Dynamically locate library and search for modules relative to it. */
prefix = enchant_get_prefix_dir();
@@ -267,7 +266,7 @@ enchant_get_conf_dirs (void)
}
#if defined(ENCHANT_GLOBAL_ORDERING)
- conf_dirs = g_slist_append (conf_dirs, g_strdup (ENCHANT_GLOBAL_ORDERING));
+ conf_dirs = g_slist_append (conf_dirs, strdup (ENCHANT_GLOBAL_ORDERING));
#endif
return conf_dirs;
@@ -329,7 +328,7 @@ enchant_is_valid_dictionary_tag(const char * const tag)
static char *
enchant_normalize_dictionary_tag (const char * const dict_tag)
{
- char * new_tag = g_strdup (dict_tag);
+ char * new_tag = strdup (dict_tag);
char * needle;
new_tag = g_strstrip (new_tag);
@@ -363,7 +362,7 @@ enchant_normalize_dictionary_tag (const char * const dict_tag)
static char *
enchant_iso_639_from_tag (const char * const dict_tag)
{
- char * new_tag = g_strdup (dict_tag);
+ char * new_tag = strdup (dict_tag);
char * needle;
if ((needle = strchr (new_tag, '_')) != NULL)
@@ -381,7 +380,7 @@ enchant_session_destroy (EnchantSession * session)
enchant_pwl_free (session->exclude);
g_free (session->personal_filename);
g_free (session->exclude_filename);
- g_free (session->language_tag);
+ free (session->language_tag);
if (session->error)
g_free (session->error);
@@ -421,9 +420,9 @@ enchant_session_new_with_pwl (EnchantProvider * provider,
session->personal = personal;
session->exclude = exclude;
session->provider = provider;
- session->language_tag = g_strdup (lang);
- session->personal_filename = g_strdup (pwl);
- session->exclude_filename = g_strdup (excl);
+ session->language_tag = strdup (lang);
+ session->personal_filename = g_strdup (pwl); /* Need g_strdup because may be NULL */
+ session->exclude_filename = g_strdup (excl); /* Need g_strdup because may be NULL */
return session;
}
@@ -473,8 +472,7 @@ enchant_session_new (EnchantProvider *provider, const char * const lang)
session = _enchant_session_new (provider, user_config_dirs->data, lang, FALSE);
}
- g_slist_foreach (user_config_dirs, (GFunc)g_free, NULL);
- g_slist_free (user_config_dirs);
+ g_slist_free_full (user_config_dirs, g_free);
return session;
}
@@ -595,7 +593,7 @@ enchant_dict_set_error (EnchantDict * dict, const char * const err)
session = ((EnchantDictPrivateData*)dict->enchant_private_data)->session;
enchant_session_clear_error (session);
- session->error = g_strdup (err);
+ session->error = strdup (err);
}
/**
@@ -697,7 +695,7 @@ enchant_dict_merge_suggestions(char ** suggs, size_t n_suggs, char ** new_suggs,
if(!is_duplicate)
{
- suggs[n_suggs] = g_strdup (new_suggs[i]);
+ suggs[n_suggs] = strdup (new_suggs[i]);
++n_suggs;
}
}
@@ -729,7 +727,7 @@ enchant_dict_get_good_suggestions(EnchantDict * dict,
if(g_utf8_validate(suggs[i], sugg_len, NULL) &&
!enchant_session_exclude(session, suggs[i], sugg_len) )
{
- filtered_suggs[n_filtered_suggs] = g_strdup (suggs[i]);
+ filtered_suggs[n_filtered_suggs] = strdup (suggs[i]);
++n_filtered_suggs;
}
}
@@ -1130,7 +1128,7 @@ static void
enchant_broker_set_error (EnchantBroker * broker, const char * const err)
{
enchant_broker_clear_error (broker);
- broker->error = g_strdup (err);
+ broker->error = strdup (err);
}
static int
@@ -1281,8 +1279,7 @@ enchant_load_providers (EnchantBroker * broker)
enchant_load_providers_in_dir (broker, iter->data);
}
- g_slist_foreach (module_dirs, (GFunc)g_free, NULL);
- g_slist_free (module_dirs);
+ g_slist_free_full (module_dirs, free);
}
static void
@@ -1335,8 +1332,7 @@ enchant_load_provider_ordering (EnchantBroker * broker)
g_free (ordering_file);
}
- g_slist_foreach (conf_dirs, (GFunc)g_free, NULL);
- g_slist_free (conf_dirs);
+ g_slist_free_full (conf_dirs, g_free);
}
static GSList *
@@ -1416,7 +1412,7 @@ enchant_dict_destroyed (gpointer data)
}
static void
-enchant_provider_free (gpointer data, gpointer user_data _GL_UNUSED_PARAMETER)
+enchant_provider_free (gpointer data)
{
EnchantProvider *provider;
GModule *module;
@@ -1479,8 +1475,7 @@ enchant_broker_free (EnchantBroker * broker)
g_hash_table_destroy (broker->dict_map);
g_hash_table_destroy (broker->provider_ordering);
- g_slist_foreach (broker->provider_list, enchant_provider_free, NULL);
- g_slist_free (broker->provider_list);
+ g_slist_free_full (broker->provider_list, enchant_provider_free);
enchant_broker_clear_error (broker);
@@ -1534,8 +1529,7 @@ enchant_broker_request_pwl_dict (EnchantBroker * broker, const char *const pwl)
enchant_dict_private_data->session = session;
dict->enchant_private_data = (void *)enchant_dict_private_data;
-
- g_hash_table_insert (broker->dict_map, (gpointer)g_strdup (pwl), dict);
+ g_hash_table_insert (broker->dict_map, (gpointer)strdup (pwl), dict);
return dict;
}
@@ -1574,7 +1568,7 @@ _enchant_broker_request_dict (EnchantBroker * broker, const char *const tag)
enchant_dict_private_data->reference_count = 1;
enchant_dict_private_data->session = session;
dict->enchant_private_data = (void *)enchant_dict_private_data;
- g_hash_table_insert (broker->dict_map, (gpointer)g_strdup (tag), dict);
+ g_hash_table_insert (broker->dict_map, (gpointer)strdup (tag), dict);
break;
}
}
@@ -1616,10 +1610,10 @@ enchant_broker_request_dict (EnchantBroker * broker, const char *const tag)
dict = _enchant_broker_request_dict (broker, iso_639_only_tag);
- g_free (iso_639_only_tag);
+ free (iso_639_only_tag);
}
- g_free (normalized_tag);
+ free (normalized_tag);
return dict;
}
@@ -1721,7 +1715,7 @@ enchant_broker_list_dicts (EnchantBroker * broker,
if (ptr != NULL)
min_priority = g_slist_index (providers, ptr);
if (this_priority < min_priority)
- g_hash_table_insert (tags, g_strdup (tag), provider);
+ g_hash_table_insert (tags, strdup (tag), provider);
}
}
}
@@ -1888,10 +1882,10 @@ enchant_broker_dict_exists (EnchantBroker * broker,
exists = _enchant_broker_dict_exists (broker, iso_639_only_tag);
}
- g_free (iso_639_only_tag);
+ free (iso_639_only_tag);
}
- g_free (normalized_tag);
+ free (normalized_tag);
return exists;
}
@@ -1931,7 +1925,7 @@ enchant_broker_set_ordering (EnchantBroker * broker,
{
/* we will free ordering_dupl && tag_dupl when the hash is destroyed */
g_hash_table_insert (broker->provider_ordering, (gpointer)tag_dupl,
- (gpointer)(ordering_dupl));
+ (gpointer)(ordering_dupl));
}
else
{
@@ -1979,34 +1973,45 @@ enchant_broker_get_error (EnchantBroker * broker)
return broker->error;
}
-/* private. returned string should be free'd with g_free */
+/**
+ * enchant_get_user_language
+ *
+ * Returns a char string giving the current language.
+ * Defaults to "en" if no language or locale can be found, or
+ * locale is C.
+ *
+ * The returned string should be free'd with free.
+ */
ENCHANT_MODULE_EXPORT(char *)
enchant_get_user_language(void)
{
- char * locale = NULL;
+ const char * locale = NULL;
#if defined(G_OS_WIN32)
if(!locale)
- locale = g_win32_getlocale ();
+ { /* Copy locale string so it does not need to be freed */
+ char * win_locale = g_win32_getlocale ();
+ locale = alloca (strlen (win_locale));
+ strcpy (locale, win_locale);
+ g_free (win_locale);
+ }
#endif
if(!locale)
- locale = g_strdup (g_getenv ("LANG"));
+ locale = g_getenv ("LANG");
#if defined(HAVE_LC_MESSAGES)
if(!locale)
- locale = g_strdup (setlocale (LC_MESSAGES, NULL));
+ locale = setlocale (LC_MESSAGES, NULL);
#endif
if(!locale)
- locale = g_strdup (setlocale (LC_ALL, NULL));
+ locale = setlocale (LC_ALL, NULL);
- if(!locale || strcmp(locale, "C") == 0) {
- g_free(locale);
- locale = g_strdup("en");
- }
+ if(!locale || strcmp(locale, "C") == 0)
+ locale = "en";
- return locale;
+ return strdup (locale);
}
@@ -2019,7 +2024,7 @@ enchant_get_user_language(void)
* compiled, except it is determined at runtime based on the location
* of the enchant library.
*
- * Returns: the prefix dir if it can be determined, or %null otherwise. Must be free'd.
+ * Returns: the prefix dir if it can be determined, or %null otherwise. Must be g_free'd.
*
* This API is private to the providers.
*
diff --git a/src/hunspell/hunspell_checker.cpp b/src/hunspell/hunspell_checker.cpp
index c9abba7..6198a0d 100644
--- a/src/hunspell/hunspell_checker.cpp
+++ b/src/hunspell/hunspell_checker.cpp
@@ -69,12 +69,6 @@ private:
Hunspell *hunspell;
};
-static void
-hunspell_checker_free_helper (gpointer p, gpointer user _GL_UNUSED_PARAMETER)
-{
- g_free (p);
-}
-
/***************************************************************************/
static bool
@@ -187,8 +181,7 @@ hunspell_checker_get_dictionary_dirs ()
"hunspell", nullptr));
}
- g_slist_foreach (config_dirs, hunspell_checker_free_helper, nullptr);
- g_slist_free (config_dirs);
+ g_slist_free_full (config_dirs, free);
}
{
@@ -218,7 +211,7 @@ hunspell_checker_get_dictionary_dirs ()
const gchar* hun_dir = g_getenv("DICPATH");
if (hun_dir)
{
- dirs = g_slist_append(dirs, g_strdup(hun_dir));
+ dirs = g_slist_append(dirs, strdup(hun_dir));
}
}
@@ -238,8 +231,7 @@ s_buildDictionaryDirs (std::vector<std::string> & dirs)
dirs.push_back (static_cast<const char *>(iter->data));
}
- g_slist_foreach (hunspell_dirs, hunspell_checker_free_helper, nullptr);
- g_slist_free (hunspell_dirs);
+ g_slist_free_full (hunspell_dirs, g_free);
}
static void
@@ -300,7 +292,7 @@ hunspell_request_dictionary (const char * tag)
for (size_t i = 0; i < names.size (); i++) {
if (g_file_test(names[i].c_str(), G_FILE_TEST_EXISTS)) {
if(s_hasCorrespondingAffFile(names[i])){
- return g_strdup (names[i].c_str());
+ return strdup (names[i].c_str());
}
}
}
@@ -339,15 +331,15 @@ HunspellChecker::requestDictionary(const char *szLang)
if (!dic)
return false;
- aff = g_strdup(dic);
+ aff = strdup(dic);
int len_dic = strlen(dic);
strcpy(aff+len_dic-3, "aff");
if (g_file_test(aff, G_FILE_TEST_EXISTS))
{
hunspell = new Hunspell(aff, dic);
}
- g_free(dic);
- g_free(aff);
+ free(dic);
+ free(aff);
if(hunspell == NULL){
return false;
}
diff --git a/src/uspell/uspell_provider.cpp b/src/uspell/uspell_provider.cpp
index 039160f..a035ad3 100644
--- a/src/uspell/uspell_provider.cpp
+++ b/src/uspell/uspell_provider.cpp
@@ -64,8 +64,7 @@ uspell_checker_get_dictionary_dirs (EnchantBroker * broker)
"uspell", NULL));
}
- g_slist_foreach (config_dirs, (GFunc)g_free, NULL);
- g_slist_free (config_dirs);
+ g_slist_free_full (config_dirs, free);
}
{
@@ -254,8 +253,7 @@ s_buildHashNames (std::vector<std::string> & names, EnchantBroker * broker, cons
g_free (tmp);
}
- g_slist_foreach (dirs, (GFunc)g_free, NULL);
- g_slist_free (dirs);
+ g_slist_free_full (dirs, g_free);
}
}
@@ -345,8 +343,7 @@ uspell_provider_request_dict (EnchantProvider * me, const char *const tag)
manager = uspell_request_manager ((const char *)iter->data, mapIndex);
}
- g_slist_foreach (dirs, (GFunc)g_free, NULL);
- g_slist_free (dirs);
+ g_slist_free_full (dirs, g_free);
if (!manager)
return NULL;
diff --git a/src/voikko/voikko_provider.c b/src/voikko/voikko_provider.c
index 3c937ce..8a3c6f5 100644
--- a/src/voikko/voikko_provider.c
+++ b/src/voikko/voikko_provider.c
@@ -1,3 +1,4 @@
+/* FIXME: Use current voikko API, not deprecated */
/* enchant
* Copyright (C) 2003,2004 Dom Lachowicz
* 2006-2007 Harri Pitkänen <hatapitk@iki.fi>
@@ -152,6 +153,7 @@ static void
voikko_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER,
char **str_list)
{
+ /* FIXME: suggestion list should be freed with voikkoFreeCstrArray */
g_strfreev (str_list);
}