SF.net SVN: geany: [2612] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Fri May 23 17:09:04 UTC 2008


Revision: 2612
          http://geany.svn.sourceforge.net/geany/?rev=2612&view=rev
Author:   ntrel
Date:     2008-05-23 10:08:58 -0700 (Fri, 23 May 2008)

Log Message:
-----------
Deprecate PLUGIN_INFO() in favour of PLUGIN_SET_INFO().
Remove plugin symbol info(), which is replaced by plugin_set_info()
and a new symbol plugin_info. This is so the PluginInfo struct is
zero'd first by Geany, so plugins are still ABI compatible if we
want to add any more fields in the future.
Fail to load a plugin if plugin_info->name is not set.
Remove now unused string.h include from plugindata.h.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/doc/plugin-symbols.c
    trunk/doc/plugins.dox
    trunk/plugins/autosave.c
    trunk/plugins/classbuilder.c
    trunk/plugins/demoplugin.c
    trunk/plugins/export.c
    trunk/plugins/filebrowser.c
    trunk/plugins/htmlchars.c
    trunk/plugins/vcdiff.c
    trunk/src/plugindata.h
    trunk/src/plugins.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/ChangeLog	2008-05-23 17:08:58 UTC (rev 2612)
@@ -7,6 +7,17 @@
    by the plugin, not Geany.
  * src/plugindata.h:
    Increment plugin ABI, API versions for plugin_callbacks change.
+ * src/plugindata.h, src/plugins.c, doc/plugin-symbols.c,
+   doc/plugins.dox, plugins/export.c, plugins/vcdiff.c,
+   plugins/demoplugin.c, plugins/filebrowser.c, plugins/htmlchars.c,
+   plugins/autosave.c, plugins/classbuilder.c:
+   Deprecate PLUGIN_INFO() in favour of PLUGIN_SET_INFO().
+   Remove plugin symbol info(), which is replaced by plugin_set_info()
+   and a new symbol plugin_info. This is so the PluginInfo struct is
+   zero'd first by Geany, so plugins are still ABI compatible if we
+   want to add any more fields in the future.
+   Fail to load a plugin if plugin_info->name is not set.
+   Remove now unused string.h include from plugindata.h.
 
 
 2008-05-22  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/doc/plugin-symbols.c
===================================================================
--- trunk/doc/plugin-symbols.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/doc/plugin-symbols.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -37,16 +37,25 @@
 /** Use the PLUGIN_VERSION_CHECK() macro instead. Required by Geany. */
 gint version_check(gint);
 
-/** Use the PLUGIN_INFO() macro to define it. Required by Geany. */
-PluginInfo* info();
+/** Use the PLUGIN_SET_INFO() macro to define it. Required by Geany.
+ * This function is called before the plugin is initialized, so Geany
+ * can read the plugin's name.
+ * @param info The data struct which should be initialized by this function. */
+void plugin_set_info(PluginInfo *info);
 
+/** Basic information about a plugin, which is set in plugin_set_info(). */
+const PluginInfo* plugin_info;
+
 /** Geany owned data pointers.
  * Example: @c assert(geany_data->app->configdir != NULL); */
-GeanyData* geany_data;
+const GeanyData* geany_data;
 
 /** Geany owned function pointers, split into groups.
- * Example: @c geany_functions->p_document->new_file(NULL, NULL, NULL); */
-GeanyFunctions* geany_functions;
+ * Example: @c geany_functions->p_document->new_file(NULL, NULL, NULL);
+ *
+ * Note: Usually plugins would use the pluginmacros.h file and just call:
+ * @c p_document->new_file(NULL, NULL, NULL); */
+const GeanyFunctions* geany_functions;
 
 /** Plugin owned fields, including flags. */
 PluginFields* plugin_fields;
@@ -78,5 +87,5 @@
 
 /** Called before unloading the plugin. Required for normal plugins - it should undo
  * everything done in init() - e.g. destroy menu items, free memory. */
-void cleanup(); */
+void cleanup();
 

Modified: trunk/doc/plugins.dox
===================================================================
--- trunk/doc/plugins.dox	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/doc/plugins.dox	2008-05-23 17:08:58 UTC (rev 2612)
@@ -180,9 +180,9 @@
  *  Every plugin should include "geany.h" and "plugindata.h" which provide necessary
  *  preprocessor macros and other basic information.
  *  There are two important preprocessor macros which need to be used at the beginning:
- *  PLUGIN_INFO() and PLUGIN_VERSION_CHECK().
+ *  PLUGIN_SET_INFO() and PLUGIN_VERSION_CHECK().
  *
- *  PLUGIN_INFO() tells Geany about basic plugin information like name, description,
+ *  PLUGIN_SET_INFO() tells Geany about basic plugin information like name, description,
  *  version and author of the plugin.
  *
  *  PLUGIN_VERSION_CHECK() checks for compatibility of the API version which

Modified: trunk/plugins/autosave.c
===================================================================
--- trunk/plugins/autosave.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/autosave.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -39,7 +39,7 @@
 
 PLUGIN_VERSION_CHECK(32)
 
-PLUGIN_INFO(_("Auto Save"), _("Save automatically all open files in a given time interval."),
+PLUGIN_SET_INFO(_("Auto Save"), _("Save automatically all open files in a given time interval."),
 	VERSION, _("The Geany developer team"))
 
 

Modified: trunk/plugins/classbuilder.c
===================================================================
--- trunk/plugins/classbuilder.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/classbuilder.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -41,7 +41,7 @@
 
 PLUGIN_VERSION_CHECK(7)
 
-PLUGIN_INFO(_("Class Builder"), _("Creates source files for new class types."), VERSION,
+PLUGIN_SET_INFO(_("Class Builder"), _("Creates source files for new class types."), VERSION,
 	"Alexander Rodin")
 
 

Modified: trunk/plugins/demoplugin.c
===================================================================
--- trunk/plugins/demoplugin.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/demoplugin.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -44,6 +44,7 @@
 
 
 /* These items are set by Geany before init() is called. */
+PluginInfo		*plugin_info;
 PluginFields	*plugin_fields;
 GeanyData		*geany_data;
 GeanyFunctions	*geany_functions;
@@ -54,7 +55,7 @@
 PLUGIN_VERSION_CHECK(7)
 
 /* All plugins must set name, description, version and author. */
-PLUGIN_INFO(_("Demo"), _("Example plugin."), VERSION, _("The Geany developer team"))
+PLUGIN_SET_INFO(_("Demo"), _("Example plugin."), VERSION, _("The Geany developer team"))
 
 
 /* text to be shown in the plugin dialog */
@@ -74,7 +75,7 @@
 		GTK_BUTTONS_OK,
 		"%s", welcome_text);
 	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
-		_("(From the %s plugin)"), info()->name);
+		_("(From the %s plugin)"), plugin_info->name);
 
 	gtk_dialog_run(GTK_DIALOG(dialog));
 	gtk_widget_destroy(dialog);

Modified: trunk/plugins/export.c
===================================================================
--- trunk/plugins/export.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/export.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -43,7 +43,7 @@
 GeanyFunctions	*geany_functions;
 
 PLUGIN_VERSION_CHECK(20)
-PLUGIN_INFO(_("Export"), _("Exports the current file into different formats."), VERSION,
+PLUGIN_SET_INFO(_("Export"), _("Exports the current file into different formats."), VERSION,
 	_("The Geany developer team"))
 
 #define ROTATE_RGB(color) \

Modified: trunk/plugins/filebrowser.c
===================================================================
--- trunk/plugins/filebrowser.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/filebrowser.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -25,6 +25,7 @@
 /* Sidebar file browser plugin. */
 
 #include "geany.h"
+#include <string.h>
 
 #include <gdk/gdkkeysyms.h>
 
@@ -47,7 +48,7 @@
 
 PLUGIN_VERSION_CHECK(26)
 
-PLUGIN_INFO(_("File Browser"), _("Adds a file browser tab to the sidebar."), VERSION,
+PLUGIN_SET_INFO(_("File Browser"), _("Adds a file browser tab to the sidebar."), VERSION,
 	_("The Geany developer team"))
 
 

Modified: trunk/plugins/htmlchars.c
===================================================================
--- trunk/plugins/htmlchars.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/htmlchars.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -40,7 +40,7 @@
 
 PLUGIN_VERSION_CHECK(48)
 
-PLUGIN_INFO(_("HTML Characters"), _("Inserts HTML character entities like '&'."), VERSION,
+PLUGIN_SET_INFO(_("HTML Characters"), _("Inserts HTML character entities like '&'."), VERSION,
 	_("The Geany developer team"))
 
 

Modified: trunk/plugins/vcdiff.c
===================================================================
--- trunk/plugins/vcdiff.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/plugins/vcdiff.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -28,6 +28,8 @@
  * e.g. ".svn". */
 
 #include "geany.h"
+#include <string.h>
+
 #include "support.h"
 #include "plugindata.h"
 #include "document.h"
@@ -45,7 +47,7 @@
 
 PLUGIN_VERSION_CHECK(27)
 
-PLUGIN_INFO(_("Version Diff"), _("Creates a patch of a file against version control."), VERSION,
+PLUGIN_SET_INFO(_("Version Diff"), _("Creates a patch of a file against version control."), VERSION,
 	_("The Geany developer team"))
 
 
@@ -120,7 +122,7 @@
 	else
 	    base = g_path_get_dirname(filename);
 
-	while(strcmp(base, base_prev) != 0)
+	while (strcmp(base, base_prev) != 0)
 	{
 	    gitdir = g_build_path("/", base, subdir, NULL);
 	    ret = g_file_test(gitdir, G_FILE_TEST_IS_DIR);

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/src/plugindata.h	2008-05-23 17:08:58 UTC (rev 2612)
@@ -28,6 +28,7 @@
  * For detailed documentation of the plugin system please read the plugin
  * API documentation.
  **/
+/* Note: Remember to increment api_version (and abi_version if necessary) when making changes. */
 
 
 #ifndef PLUGINDATA_H
@@ -35,12 +36,12 @@
 
 /* The API version should be incremented whenever any plugin data types below are
  * modified or appended to. */
-static const gint api_version = 62;
+static const gint api_version = 63;
 
 /* The ABI version should be incremented whenever existing fields in the plugin
  * data types below have to be changed or reordered. It should stay the same if fields
  * are only appended, as this doesn't affect existing fields. */
-static const gint abi_version = 32;
+static const gint abi_version = 33;
 
 /** Check the plugin can be loaded by Geany.
  * This performs runtime checks that try to ensure:
@@ -58,7 +59,7 @@
 
 
 /** Plugin info structure to hold basic information about a plugin.
- *  Should only be set with PLUGIN_INFO. */
+ * Should usually be set with PLUGIN_SET_INFO(). */
 typedef struct PluginInfo
 {
 	/** The name of the plugin. */
@@ -69,25 +70,24 @@
 	gchar	*version;
 	/** The author of the plugin. */
 	gchar	*author;
-	/** Reserved for later use. */
-	gpointer reserved2;
 }
 PluginInfo;
 
-#include <string.h>
-
-/** Set the plugin name and some other basic information about a plugin. */
-#define PLUGIN_INFO(p_name, p_description, p_version, p_author) \
-	PluginInfo *info(void) \
+/** Set the plugin name and some other basic information about a plugin.
+ * This declares a function, so you can use the _() translation macro for arguments.
+ *
+ * Example:
+ * @code PLUGIN_SET_INFO(_("Cool Feature"), _("Adds cool feature support."), "0.1", "Joe Author") @endcode */
+/* plugin_set_info() could be written manually for plugins if we want to add any
+ * extra PluginInfo features (such as an icon), so we don't need to break API
+ * compatibility. Alternatively just add a new macro, PLUGIN_SET_INFO_FULL(). -ntrel */
+#define PLUGIN_SET_INFO(p_name, p_description, p_version, p_author) \
+	void plugin_set_info(PluginInfo* info) \
 	{ \
-		static PluginInfo p_info; \
-		\
-		memset(&p_info, 0, sizeof(PluginInfo)); \
-		p_info.name = (p_name); \
-		p_info.description = (p_description); \
-		p_info.version = (p_version); \
-		p_info.author = (p_author); \
-		return &p_info; \
+		info->name = (p_name); \
+		info->description = (p_description); \
+		info->version = (p_version); \
+		info->author = (p_author); \
 	}
 
 
@@ -136,7 +136,6 @@
 PluginFlags;
 
 /** Fields set and owned by the plugin. */
-/* Note: Remember to increment api_version (and abi_version if necessary) when making changes. */
 typedef struct PluginFields
 {
 	/** Bitmask of PluginFlags. */
@@ -451,6 +450,8 @@
 typedef PluginCallback GeanyCallback;
 #define geany_callbacks plugin_callbacks
 
+#define PLUGIN_INFO PLUGIN_SET_INFO
+
 #endif	/* GEANY_DISABLE_DEPRECATED */
 
 #endif

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2008-05-23 14:14:04 UTC (rev 2611)
+++ trunk/src/plugins.c	2008-05-23 17:08:58 UTC (rev 2612)
@@ -68,12 +68,12 @@
 {
 	GModule 	*module;
 	gchar		*filename;				/* plugin filename (/path/libname.so) */
+	PluginInfo		info;				/* plugin name, description, etc */
 	PluginFields	fields;
 	gulong		*signal_ids;			/* signal IDs to disconnect when unloading */
 	gsize		signal_ids_len;
 	KeyBindingGroup	*key_group;
 
-	PluginInfo*	(*info) (void);			/* Returns plugin name, description */
 	void	(*init) (GeanyData *data);	/* Called when the plugin is enabled */
 	void	(*configure) (GtkWidget *parent);	/* plugin configure dialog, optionally */
 	void	(*cleanup) (void);			/* Called when the plugin is disabled or when Geany exits */
@@ -419,7 +419,7 @@
 		return;
 	}
 
-	plugin->key_group->label = plugin->info()->name;
+	plugin->key_group->label = plugin->info.name;
 
 	g_ptr_array_add(keybinding_groups, plugin->key_group);
 }
@@ -429,6 +429,7 @@
 plugin_init(Plugin *plugin)
 {
 	PluginCallback *callbacks;
+	PluginInfo **p_info;
 
 	if (plugin->init)
 		plugin->init(&geany_data);
@@ -439,6 +440,10 @@
 		gtk_widget_set_sensitive(plugin->fields.menu_item, enable);
 	}
 
+	g_module_symbol(plugin->module, "plugin_info", (void *) &p_info);
+	if (p_info)
+		*p_info = &plugin->info;
+
 	g_module_symbol(plugin->module, "plugin_callbacks", (void *) &callbacks);
 	if (callbacks)
 		add_callbacks(plugin, callbacks);
@@ -451,7 +456,7 @@
 	active_plugin_list = g_list_append(active_plugin_list, plugin);
 
 	geany_debug("Loaded:   %s (%s)", plugin->filename,
-		NVL(plugin->info()->name, "<Unknown>"));
+		NVL(plugin->info.name, "<Unknown>"));
 }
 
 
@@ -465,7 +470,7 @@
 {
 	Plugin *plugin;
 	GModule *module;
-	PluginInfo* (*info)(void);
+	void (*plugin_set_info)(PluginInfo*);
 	PluginFields **plugin_fields;
 	GeanyData **p_geany_data;
 	GeanyFunctions **p_geany_functions;
@@ -488,7 +493,8 @@
 	 * causing a segfault. Without that flag the module will safely fail to load.
 	 * G_MODULE_BIND_LOCAL also helps find undefined symbols e.g. app when it would
 	 * otherwise not be detected due to the shadowing of Geany's app variable.
-	 * Also without G_MODULE_BIND_LOCAL calling info() in a plugin will be shadowed. */
+	 * Also without G_MODULE_BIND_LOCAL calling public functions e.g. the old info()
+	 * function from a plugin will be shadowed. */
 	module = g_module_open(fname, G_MODULE_BIND_LOCAL);
 	if (! module)
 	{
@@ -512,19 +518,31 @@
 		return NULL;
 	}
 
-	g_module_symbol(module, "info", (void *) &info);
-	if (info == NULL)
+	g_module_symbol(module, "plugin_set_info", (void *) &plugin_set_info);
+	if (plugin_set_info == NULL)
 	{
-		geany_debug("Unknown plugin info for \"%s\"!", fname);
+		geany_debug("No plugin_set_info() defined for \"%s\"!", fname);
 
 		if (! g_module_close(module))
 			g_warning("%s: %s", fname, g_module_error());
 		return NULL;
 	}
-	geany_debug("Initializing plugin '%s'", info()->name);
 
 	plugin = g_new0(Plugin, 1);
-	plugin->info = info;
+
+	/* read plugin name, etc. */
+	plugin_set_info(&plugin->info);
+	if (!NZV(plugin->info.name))
+	{
+		geany_debug("No plugin name set in plugin_set_info() for \"%s\"!", fname);
+
+		if (! g_module_close(module))
+			g_warning("%s: %s", fname, g_module_error());
+		g_free(plugin);
+		return NULL;
+	}
+	geany_debug("Initializing plugin '%s'", plugin->info.name);
+
 	plugin->filename = g_strdup(fname);
 	plugin->module = module;
 
@@ -545,7 +563,7 @@
 	{
 		if (app->debug_mode)
 			g_warning("Plugin '%s' has no cleanup() function - there may be memory leaks!",
-				info()->name);
+				plugin->info.name);
 	}
 
 	if (init_plugin)
@@ -871,7 +889,7 @@
 			gchar *text;
 			PluginInfo *pi;
 
-			pi = p->info();
+			pi = &p->info;
 			text = g_strdup_printf(
 				_("Plugin: %s %s\nDescription: %s\nAuthor(s): %s"),
 				pi->name, pi->version, pi->description, pi->author);
@@ -976,12 +994,14 @@
 	{
 		for (; list != NULL; list = list->next)
 		{
+			Plugin *p = list->data;
+
 			gtk_list_store_append(store, &iter);
 			gtk_list_store_set(store, &iter,
-				PLUGIN_COLUMN_CHECK, is_active_plugin(list->data),
-				PLUGIN_COLUMN_NAME, ((Plugin*)list->data)->info()->name,
-				PLUGIN_COLUMN_FILE, ((Plugin*)list->data)->filename,
-				PLUGIN_COLUMN_PLUGIN, list->data,
+				PLUGIN_COLUMN_CHECK, is_active_plugin(p),
+				PLUGIN_COLUMN_NAME, p->info.name,
+				PLUGIN_COLUMN_FILE, p->filename,
+				PLUGIN_COLUMN_PLUGIN, p,
 				-1);
 		}
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list