[gtk/wip/chergert/spellcheck: 190/194] spellcheck: allow language init to fail
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/spellcheck: 190/194] spellcheck: allow language init to fail
- Date: Mon, 29 Mar 2021 20:38:27 +0000 (UTC)
commit b0988e501b5055b915641735c2b84f07d7c4cd17
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 15 15:24:08 2021 -0700
spellcheck: allow language init to fail
gtk/gtkspellcheck.c | 19 +++++++++++++++----
gtk/gtkspellcheckprivate.h | 2 +-
2 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkspellcheck.c b/gtk/gtkspellcheck.c
index cfbf49d5d2..7578889008 100644
--- a/gtk/gtkspellcheck.c
+++ b/gtk/gtkspellcheck.c
@@ -33,7 +33,7 @@ static gboolean gtk_enchant_supports (const char *code);
static gboolean gtk_enchant_contains_word (GtkSpellLanguage *language,
const char *word,
gssize word_length);
-static void gtk_enchant_init_language (GtkSpellLanguage *language);
+static gboolean gtk_enchant_init_language (GtkSpellLanguage *language);
static void gtk_enchant_fini_language (GtkSpellLanguage *language);
static GListModel *gtk_enchant_list_corrections (GtkSpellLanguage *language,
const char *word,
@@ -119,7 +119,14 @@ _gtk_spell_language_new (const GtkSpellProvider *provider,
language->code = g_strdup (code);
if (provider->init_language != NULL)
- provider->init_language (language);
+ {
+ if (!provider->init_language (language))
+ {
+ g_free (language->code);
+ g_free (language);
+ return NULL;
+ }
+ }
return language;
}
@@ -457,11 +464,15 @@ gtk_enchant_list_corrections (GtkSpellLanguage *language,
return G_LIST_MODEL (model);
}
-static void
+static gboolean
gtk_enchant_init_language (GtkSpellLanguage *language)
{
EnchantBroker *broker = gtk_enchant_get_broker ();
- language->native = enchant_broker_request_dict (broker, language->code);
+
+ if (!(language->native = enchant_broker_request_dict (broker, language->code)))
+ return FALSE;
+
+ return TRUE;
}
static void
diff --git a/gtk/gtkspellcheckprivate.h b/gtk/gtkspellcheckprivate.h
index 71e4806e13..ca370d2788 100644
--- a/gtk/gtkspellcheckprivate.h
+++ b/gtk/gtkspellcheckprivate.h
@@ -35,7 +35,7 @@ struct _GtkSpellProvider
GListModel *(*list_corrections) (GtkSpellLanguage *language,
const char *word,
gssize word_length);
- void (*init_language) (GtkSpellLanguage *language);
+ gboolean (*init_language) (GtkSpellLanguage *language);
void (*fini_language) (GtkSpellLanguage *language);
gboolean (*contains_word) (GtkSpellLanguage *language,
const char *word,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]