[libpeas] Do not create a wrapper around C extension instances.
- From: Steve FrÃcinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Do not create a wrapper around C extension instances.
- Date: Thu, 14 Jul 2011 19:12:48 +0000 (UTC)
commit e5dbe03b6d1b7f50b248735ecd86bd9b78ca48f0
Author: Steve FrÃcinaux <code istique net>
Date: Fri Jun 24 23:26:02 2011 +0200
Do not create a wrapper around C extension instances.
There is no need to "proxy" C extensions into wrappers implementing the
same interface. This makes it possible to use libpeas without
gobject-introspection as long as you restrain yourself to C plugins.
libpeas/peas-extension.c | 30 ++++++++--
loaders/c/Makefile.am | 2 -
loaders/c/peas-extension-c.c | 120 --------------------------------------
loaders/c/peas-extension-c.h | 56 ------------------
loaders/c/peas-plugin-loader-c.c | 9 ++-
tests/libpeas/extension-c.c | 15 +----
6 files changed, 35 insertions(+), 197 deletions(-)
---
diff --git a/libpeas/peas-extension.c b/libpeas/peas-extension.c
index 31f2826..bec5b2b 100644
--- a/libpeas/peas-extension.c
+++ b/libpeas/peas-extension.c
@@ -78,7 +78,14 @@ peas_extension_get_type ()
GType
peas_extension_get_extension_type (PeasExtension *exten)
{
- return peas_extension_wrapper_get_extension_type (PEAS_EXTENSION_WRAPPER (exten));
+ if (PEAS_IS_EXTENSION_WRAPPER (exten))
+ {
+ return peas_extension_wrapper_get_extension_type (PEAS_EXTENSION_WRAPPER (exten));
+ }
+ else
+ {
+ return GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (exten), "peas-extension-type"));
+ }
}
/**
@@ -203,8 +210,21 @@ peas_extension_callv (PeasExtension *exten,
GIArgument *args,
GIArgument *return_value)
{
- return peas_extension_wrapper_callv (PEAS_EXTENSION_WRAPPER (exten),
- method_name,
- args,
- return_value);
+ if (PEAS_IS_EXTENSION_WRAPPER (exten))
+ {
+ return peas_extension_wrapper_callv (PEAS_EXTENSION_WRAPPER (exten),
+ method_name,
+ args,
+ return_value);
+ }
+ else
+ {
+ GType gtype = peas_extension_get_extension_type (exten);
+
+ return peas_method_apply (G_OBJECT (exten),
+ gtype,
+ method_name,
+ args,
+ return_value);
+ }
}
diff --git a/loaders/c/Makefile.am b/loaders/c/Makefile.am
index dedece8..2b88ef4 100644
--- a/loaders/c/Makefile.am
+++ b/loaders/c/Makefile.am
@@ -12,8 +12,6 @@ INCLUDES = \
loader_LTLIBRARIES = libcloader.la
libcloader_la_SOURCES = \
- peas-extension-c.c \
- peas-extension-c.h \
peas-plugin-loader-c.c \
peas-plugin-loader-c.h
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index b4dfc82..a8e45a9 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -27,7 +27,6 @@
#include <gmodule.h>
#include "peas-plugin-loader-c.h"
-#include "peas-extension-c.h"
#include <libpeas/peas-object-module.h>
#include <libpeas/peas-extension-base.h>
@@ -145,7 +144,13 @@ peas_plugin_loader_c_create_extension (PeasPluginLoader *loader,
g_return_val_if_fail (G_IS_OBJECT (instance), NULL);
g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (instance, exten_type), NULL);
- return peas_extension_c_new (exten_type, G_OBJECT (instance));
+ /* As we do not instantiate a PeasExtensionWrapper, we have to remember
+ * somehow which interface we are instantiating, to make it possible to use
+ * the deprecated peas_extension_call() method.
+ */
+ g_object_set_data (instance, "peas-extension-type", GUINT_TO_POINTER (exten_type));
+
+ return instance;
}
static void
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
index c387734..4edd0a2 100644
--- a/tests/libpeas/extension-c.c
+++ b/tests/libpeas/extension-c.c
@@ -24,7 +24,6 @@
#endif
#include "libpeas/peas-extension-base.h"
-#include "loaders/c/peas-extension-c.h"
#include "testing/testing-extension.h"
#include "introspection/introspection-callable.h"
@@ -35,7 +34,6 @@ test_extension_c_instance_refcount (PeasEngine *engine)
{
PeasPluginInfo *info;
PeasExtension *extension;
- GObject *instance;
info = peas_engine_get_plugin_info (engine, "extension-c");
@@ -47,12 +45,10 @@ test_extension_c_instance_refcount (PeasEngine *engine)
g_assert (PEAS_IS_EXTENSION (extension));
- instance = ((PeasExtensionC *) extension)->instance;
-
/* The refcount of the returned object should be 1:
* - one ref for the PeasExtension
*/
- g_assert_cmpint (instance->ref_count, ==, 1);
+ g_assert_cmpint (extension->ref_count, ==, 1);
g_object_unref (extension);
}
@@ -62,7 +58,6 @@ test_extension_c_plugin_info (PeasEngine *engine)
{
PeasPluginInfo *info;
PeasExtension *extension;
- PeasExtensionBase *instance;
info = peas_engine_get_plugin_info (engine, "extension-c");
@@ -72,12 +67,8 @@ test_extension_c_plugin_info (PeasEngine *engine)
INTROSPECTION_TYPE_PROPERTIES,
NULL);
- g_assert (PEAS_IS_EXTENSION (extension));
-
- instance = (PeasExtensionBase *) ((PeasExtensionC *) extension)->instance;
-
- g_assert (PEAS_IS_EXTENSION_BASE (instance));
- g_assert (peas_extension_base_get_plugin_info (instance) == info);
+ g_assert (PEAS_IS_EXTENSION_BASE (extension));
+ g_assert (peas_extension_base_get_plugin_info (PEAS_EXTENSION_BASE (extension)) == info);
g_object_unref (extension);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]