Commit bd2722c7 authored by Nate Summers's avatar Nate Summers
Browse files

libgimptool/gimptoolmodule.[ch] More error checking. Introduced a


 	* libgimptool/gimptoolmodule.[ch]
 	* plug-ins/tools/tool-safe-mode.c: More error checking. Introduced a
 	versioning scheme. Increment GIMP_TOOL_MODULE_ABI_VERSION any time you
 	break binary compatiblity.
parent ad5e9dcd
......@@ -85,6 +85,7 @@ static gboolean
gimp_tool_module_load (GTypeModule *gmodule)
{
GimpToolModule *module;
guint version;
g_return_val_if_fail (G_IS_TYPE_MODULE (gmodule), FALSE);
g_return_val_if_fail (g_module_supported (), FALSE);
......@@ -95,19 +96,33 @@ gimp_tool_module_load (GTypeModule *gmodule)
module->module = g_module_open (module->filename, G_MODULE_BIND_LAZY);
if (!module)
return FALSE;
if (!g_module_symbol (module->module, "gimp_tool_module_register_tool",
if (!module->module ||
!g_module_symbol (module->module, "gimp_tool_module_register_tool",
(gpointer *) &module->register_tool) ||
!g_module_symbol (module->module, "gimp_tool_module_register_type",
(gpointer *) &module->register_type))
(gpointer *) &module->register_type) ||
!g_module_symbol (module->module, "gimp_tool_module_get_abi_version",
(gpointer *) &module->abi_version))
{
g_warning (g_module_error());
g_module_close (module->module);
if(module->module)
g_module_close (module->module);
return FALSE;
}
version = module->abi_version();
if (version != GIMP_TOOL_MODULE_ABI_VERSION)
{
if (version > GIMP_TOOL_MODULE_ABI_VERSION)
g_warning ("Cannot load tool plug-in %s. It is for a newer version of GIMP.", module->filename);
else
g_warning ("Cannot load tool plug-in %s. It is for an older version of GIMP.", module->filename);
return FALSE;
}
return module->register_type (module);
}
......@@ -141,11 +156,16 @@ gimp_tool_module_new (const gchar *filename,
module = GIMP_TOOL_MODULE (g_object_new (GIMP_TYPE_TOOL_MODULE, NULL));
module->filename = g_strdup (filename);
/* FIXME: check for errors! */
gimp_tool_module_load (G_TYPE_MODULE (module));
module->register_tool (callback, register_data);
gimp_tool_module_unload (G_TYPE_MODULE (module));
module->filename = g_strdup (filename); /* FIXME: memory leak; free on delete */
if (gimp_tool_module_load (G_TYPE_MODULE (module)))
{
module->register_tool (callback, register_data);
gimp_tool_module_unload (G_TYPE_MODULE (module));
return module;
}
else
return NULL;
return module;
}
......@@ -22,6 +22,8 @@
#include <gmodule.h>
#include "gimptooltypes.h"
#define GIMP_TOOL_MODULE_ABI_VERSION 0x1
#define GIMP_TYPE_TOOL_MODULE (gimp_tool_module_get_type ())
#define GIMP_TOOL_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_MODULE, GimpToolModule))
#define GIMP_TOOL_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_MODULE, GimpToolModuleClass))
......@@ -44,6 +46,7 @@ struct _GimpToolModule
gpointer register_data);
gboolean (* register_type) (GimpToolModule *module);
guint (* abi_version) (void);
};
......
......@@ -72,6 +72,8 @@ safe_mode_init (void)
{
gchar *tool_plug_in_path, *free_me;
g_type_init();
g_message ("tool-safe-mode init called");
free_me = tool_plug_in_path = gimp_gimprc_query ("tool-plug-in-path");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment