[libpeas] Test that C plugins have local linkage
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Test that C plugins have local linkage
- Date: Thu, 18 Dec 2014 14:14:36 +0000 (UTC)
commit f766cdf142f109e573293fa8be4f8362fb21811a
Author: Garrett Regier <garrettregier gmail com>
Date: Thu Dec 18 05:43:39 2014 -0800
Test that C plugins have local linkage
Otherwise two symbols from different plugins could
share the same global reference.
Based on a patch by Thomas Martitz
https://bugzilla.gnome.org/show_bug.cgi?id=740823
tests/libpeas/extension-c.c | 39 +++++++++++++++++++
.../plugins/extension-c/extension-c-plugin.c | 41 ++++++++++++++++++++
.../plugins/extension-c/extension-c-plugin.h | 3 +
tests/plugins/loadable/loadable-plugin.c | 24 +++++++++++-
tests/plugins/loadable/loadable-plugin.h | 3 +
5 files changed, 109 insertions(+), 1 deletions(-)
---
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
index 950f7e5..ef82b9c 100644
--- a/tests/libpeas/extension-c.c
+++ b/tests/libpeas/extension-c.c
@@ -61,6 +61,44 @@ test_extension_c_nonexistent (PeasEngine *engine)
g_assert (!peas_engine_load_plugin (engine, info));
}
+static void
+test_extension_c_local_linkage (PeasEngine *engine,
+ PeasPluginInfo *info)
+{
+ PeasPluginInfo *loadable_info;
+ PeasExtension *c_extension, *loadable_extension;
+ gpointer c_global_symbol, loadable_global_symbol;
+
+ loadable_info = peas_engine_get_plugin_info (engine, "loadable");
+ g_assert (peas_engine_load_plugin (engine, loadable_info));
+
+ c_extension = peas_engine_create_extension (engine, info,
+ INTROSPECTION_TYPE_BASE,
+ NULL);
+ loadable_extension = peas_engine_create_extension (engine, loadable_info,
+ PEAS_TYPE_ACTIVATABLE,
+ NULL);
+
+ g_assert (PEAS_IS_EXTENSION (c_extension));
+ g_assert (PEAS_IS_EXTENSION (loadable_extension));
+ g_assert (c_extension != loadable_extension);
+
+ g_object_get (c_extension,
+ "global-symbol-clash", &c_global_symbol,
+ NULL);
+ g_object_get (loadable_extension,
+ "global-symbol-clash", &loadable_global_symbol,
+ NULL);
+
+ /* Both plugins export the same global variable,
+ * check that they are not the same global reference
+ */
+ g_assert (c_global_symbol != loadable_global_symbol);
+
+ g_object_unref (loadable_extension);
+ g_object_unref (c_extension);
+}
+
int
main (int argc,
char *argv[])
@@ -77,6 +115,7 @@ main (int argc,
EXTENSION_TEST (c, "instance-refcount", instance_refcount);
EXTENSION_TEST (c, "nonexistent", nonexistent);
+ EXTENSION_TEST (c, "local-linkage", local_linkage);
return testing_extension_run_tests ();
}
diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.c
b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
index 6aa5ede..d40e6e1 100644
--- a/tests/libpeas/plugins/extension-c/extension-c-plugin.c
+++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.c
@@ -35,6 +35,9 @@
#include "extension-c-plugin.h"
+/* Used by the local linkage test */
+G_MODULE_EXPORT gpointer global_symbol_clash;
+
static void introspection_base_iface_init (IntrospectionBaseInterface *iface);
static void introspection_extension_c_iface_init (IntrospectionCallableInterface *iface);
static void introspection_has_prerequisite_iface_init (IntrospectionHasPrerequisiteInterface *iface);
@@ -50,6 +53,15 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (TestingExtensionCPlugin,
G_IMPLEMENT_INTERFACE_DYNAMIC (INTROSPECTION_TYPE_HAS_PREREQUISITE,
introspection_has_prerequisite_iface_init))
+/* Properties */
+enum {
+ PROP_0,
+ PROP_GLOBAL_SYMBOL_CLASH,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
static void
testing_extension_c_plugin_init (TestingExtensionCPlugin *plugin)
{
@@ -100,8 +112,37 @@ testing_extension_c_plugin_call_multi_args (IntrospectionCallable *callable,
}
static void
+testing_extension_c_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id)
+ {
+ case PROP_GLOBAL_SYMBOL_CLASH:
+ g_value_set_pointer (value, &global_symbol_clash);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
testing_extension_c_plugin_class_init (TestingExtensionCPluginClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = testing_extension_c_get_property;
+
+ properties[PROP_GLOBAL_SYMBOL_CLASH] =
+ g_param_spec_pointer ("global-symbol-clash",
+ "Global symbol clash",
+ "A global symbol that clashes",
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
static void
diff --git a/tests/libpeas/plugins/extension-c/extension-c-plugin.h
b/tests/libpeas/plugins/extension-c/extension-c-plugin.h
index 00581ad..7fe8357 100644
--- a/tests/libpeas/plugins/extension-c/extension-c-plugin.h
+++ b/tests/libpeas/plugins/extension-c/extension-c-plugin.h
@@ -45,6 +45,9 @@ struct _TestingExtensionCPluginClass {
PeasExtensionBaseClass parent_class;
};
+/* Used by the local linkage test */
+G_MODULE_EXPORT gpointer global_symbol_clash;
+
GType testing_extension_c_plugin_get_type (void) G_GNUC_CONST;
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
diff --git a/tests/plugins/loadable/loadable-plugin.c b/tests/plugins/loadable/loadable-plugin.c
index 456f675..f391a07 100644
--- a/tests/plugins/loadable/loadable-plugin.c
+++ b/tests/plugins/loadable/loadable-plugin.c
@@ -35,6 +35,9 @@ struct _TestingLoadablePluginPrivate {
GObject *object;
};
+/* Used by the local linkage test */
+G_MODULE_EXPORT gpointer global_symbol_clash;
+
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (TestingLoadablePlugin,
@@ -46,9 +49,15 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (TestingLoadablePlugin,
enum {
PROP_0,
- PROP_OBJECT
+ PROP_GLOBAL_SYMBOL_CLASH,
+
+ /* PeasActivatable */
+ PROP_OBJECT,
+ N_PROPERTIES = PROP_OBJECT
};
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
static void
testing_loadable_plugin_set_property (GObject *object,
guint prop_id,
@@ -79,6 +88,10 @@ testing_loadable_plugin_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_GLOBAL_SYMBOL_CLASH:
+ g_value_set_pointer (value, &global_symbol_clash);
+ break;
+
case PROP_OBJECT:
g_value_set_object (value, plugin->priv->object);
break;
@@ -117,6 +130,15 @@ testing_loadable_plugin_class_init (TestingLoadablePluginClass *klass)
g_object_class_override_property (object_class, PROP_OBJECT, "object");
+ properties[PROP_GLOBAL_SYMBOL_CLASH] =
+ g_param_spec_pointer ("global-symbol-clash",
+ "Global symbol clash",
+ "A global symbol that clashes",
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+
g_type_class_add_private (klass, sizeof (TestingLoadablePluginPrivate));
}
diff --git a/tests/plugins/loadable/loadable-plugin.h b/tests/plugins/loadable/loadable-plugin.h
index 178c721..c134133 100644
--- a/tests/plugins/loadable/loadable-plugin.h
+++ b/tests/plugins/loadable/loadable-plugin.h
@@ -50,6 +50,9 @@ struct _TestingLoadablePluginClass {
PeasExtensionBaseClass parent_class;
};
+/* Used by the local linkage test */
+G_MODULE_EXPORT gpointer global_symbol_clash;
+
GType testing_loadable_plugin_get_type (void) G_GNUC_CONST;
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]