From 005858795878b92fc17b4c2127bce90a1d053483 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Fri, 24 Nov 2017 03:51:10 -0500 Subject: spell-entry: Improve robustness of enchant loading and fix 2.0 support - Add logging and error handling to loading symbols - Don't load unversioned symbol - Handle new function names in Enchant 2.0 Closes #2095 --- src/fe-gtk/sexy-spell-entry.c | 94 +++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/src/fe-gtk/sexy-spell-entry.c b/src/fe-gtk/sexy-spell-entry.c index 566abcf3..bd31d223 100644 --- a/src/fe-gtk/sexy-spell-entry.c +++ b/src/fe-gtk/sexy-spell-entry.c @@ -159,49 +159,65 @@ initialize_enchant (void) { GModule *enchant; gpointer funcptr; - - - enchant = g_module_open("libenchant."G_MODULE_SUFFIX, 0); - if (enchant == NULL) - { -#ifndef WIN32 - enchant = g_module_open("libenchant.so.1", 0); - if (enchant == NULL) - { -#ifdef __APPLE__ - enchant = g_module_open("libenchant.dylib", 0); - if (enchant == NULL) + gsize i; + const char * const libnames[] = { +#ifdef G_OS_WIN32 + "libenchant.dll", #endif - return; - } -#else - return; +#ifdef G_OS_UNIX + "libenchant.so.1", + "libenchant.so.2", #endif - } - - have_enchant = TRUE; - -#define MODULE_SYMBOL(name, func) \ - g_module_symbol(enchant, (name), &funcptr); \ - (func) = funcptr; - - MODULE_SYMBOL("enchant_broker_init", enchant_broker_init) - MODULE_SYMBOL("enchant_broker_free", enchant_broker_free) - MODULE_SYMBOL("enchant_broker_free_dict", enchant_broker_free_dict) - MODULE_SYMBOL("enchant_broker_list_dicts", enchant_broker_list_dicts) - MODULE_SYMBOL("enchant_broker_request_dict", enchant_broker_request_dict) - - MODULE_SYMBOL("enchant_dict_add_to_personal", enchant_dict_add_to_personal) - MODULE_SYMBOL("enchant_dict_add_to_session", enchant_dict_add_to_session) - MODULE_SYMBOL("enchant_dict_check", enchant_dict_check) - MODULE_SYMBOL("enchant_dict_describe", enchant_dict_describe) +#ifdef __APPLE__ + "libenchant.dylib", +#endif + }; + + for (i = 0; i < G_N_ELEMENTS(libnames); ++i) + { + enchant = g_module_open(libnames[i], 0); + if (enchant) + { + g_info ("Loaded %s", libnames[i]); + have_enchant = TRUE; + break; + } + } + + if (!have_enchant) + return; + +#define MODULE_SYMBOL(name, func, alt_name) G_STMT_START { \ + const char *funcname = name; \ + gboolean ret = g_module_symbol(enchant, funcname, &funcptr); \ + if (alt_name) { \ + funcname = alt_name; \ + ret = g_module_symbol(enchant, funcname, &funcptr); \ + } \ + if (ret == FALSE) { \ + g_warning ("Failed to find enchant symbol %s", funcname); \ + have_enchant = FALSE; \ + return; \ + } \ + (func) = funcptr; \ +} G_STMT_END; + + MODULE_SYMBOL("enchant_broker_init", enchant_broker_init, NULL) + MODULE_SYMBOL("enchant_broker_free", enchant_broker_free, NULL) + MODULE_SYMBOL("enchant_broker_free_dict", enchant_broker_free_dict, NULL) + MODULE_SYMBOL("enchant_broker_list_dicts", enchant_broker_list_dicts, NULL) + MODULE_SYMBOL("enchant_broker_request_dict", enchant_broker_request_dict, NULL) + + MODULE_SYMBOL("enchant_dict_add_to_personal", enchant_dict_add_to_personal, + "enchant_dict_add") + MODULE_SYMBOL("enchant_dict_add_to_session", enchant_dict_add_to_session, NULL) + MODULE_SYMBOL("enchant_dict_check", enchant_dict_check, NULL) + MODULE_SYMBOL("enchant_dict_describe", enchant_dict_describe, NULL) MODULE_SYMBOL("enchant_dict_free_suggestions", - enchant_dict_free_suggestions) + enchant_dict_free_suggestions, "enchant_dict_free_string_list") MODULE_SYMBOL("enchant_dict_store_replacement", - enchant_dict_store_replacement) - MODULE_SYMBOL("enchant_dict_suggest", enchant_dict_suggest) - -#undef MODULE_SYMBOL + enchant_dict_store_replacement, NULL) + MODULE_SYMBOL("enchant_dict_suggest", enchant_dict_suggest, NULL) } static void -- cgit 1.4.1