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
This commit is contained in:
parent
228e08543a
commit
0058587958
|
@ -159,49 +159,65 @@ initialize_enchant (void)
|
||||||
{
|
{
|
||||||
GModule *enchant;
|
GModule *enchant;
|
||||||
gpointer funcptr;
|
gpointer funcptr;
|
||||||
|
gsize i;
|
||||||
|
const char * const libnames[] = {
|
||||||
enchant = g_module_open("libenchant."G_MODULE_SUFFIX, 0);
|
#ifdef G_OS_WIN32
|
||||||
if (enchant == NULL)
|
"libenchant.dll",
|
||||||
{
|
#endif
|
||||||
#ifndef WIN32
|
#ifdef G_OS_UNIX
|
||||||
enchant = g_module_open("libenchant.so.1", 0);
|
"libenchant.so.1",
|
||||||
if (enchant == NULL)
|
"libenchant.so.2",
|
||||||
{
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
enchant = g_module_open("libenchant.dylib", 0);
|
"libenchant.dylib",
|
||||||
if (enchant == NULL)
|
|
||||||
#endif
|
#endif
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
#else
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
have_enchant = TRUE;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define MODULE_SYMBOL(name, func) \
|
if (!have_enchant)
|
||||||
g_module_symbol(enchant, (name), &funcptr); \
|
return;
|
||||||
(func) = funcptr;
|
|
||||||
|
|
||||||
MODULE_SYMBOL("enchant_broker_init", enchant_broker_init)
|
#define MODULE_SYMBOL(name, func, alt_name) G_STMT_START { \
|
||||||
MODULE_SYMBOL("enchant_broker_free", enchant_broker_free)
|
const char *funcname = name; \
|
||||||
MODULE_SYMBOL("enchant_broker_free_dict", enchant_broker_free_dict)
|
gboolean ret = g_module_symbol(enchant, funcname, &funcptr); \
|
||||||
MODULE_SYMBOL("enchant_broker_list_dicts", enchant_broker_list_dicts)
|
if (alt_name) { \
|
||||||
MODULE_SYMBOL("enchant_broker_request_dict", enchant_broker_request_dict)
|
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_dict_add_to_personal", enchant_dict_add_to_personal)
|
MODULE_SYMBOL("enchant_broker_init", enchant_broker_init, NULL)
|
||||||
MODULE_SYMBOL("enchant_dict_add_to_session", enchant_dict_add_to_session)
|
MODULE_SYMBOL("enchant_broker_free", enchant_broker_free, NULL)
|
||||||
MODULE_SYMBOL("enchant_dict_check", enchant_dict_check)
|
MODULE_SYMBOL("enchant_broker_free_dict", enchant_broker_free_dict, NULL)
|
||||||
MODULE_SYMBOL("enchant_dict_describe", enchant_dict_describe)
|
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",
|
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",
|
MODULE_SYMBOL("enchant_dict_store_replacement",
|
||||||
enchant_dict_store_replacement)
|
enchant_dict_store_replacement, NULL)
|
||||||
MODULE_SYMBOL("enchant_dict_suggest", enchant_dict_suggest)
|
MODULE_SYMBOL("enchant_dict_suggest", enchant_dict_suggest, NULL)
|
||||||
|
|
||||||
#undef MODULE_SYMBOL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue