[libpeas] Don't use properties to store the extension instance
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Don't use properties to store the extension instance
- Date: Thu, 24 Mar 2011 23:05:51 +0000 (UTC)
commit 22a2b507736218085ba73b56268cbea61466bae5
Author: Garrett Regier <alias301 gmail com>
Date: Mon Mar 7 22:37:19 2011 -0800
Don't use properties to store the extension instance
The properties were intended for the tests but we can just as
easily include the loader's extension.h file and acess it directly.
In the future we will be using get_property() and set_property()
for getting and setting properties on extension instances and if
extensions had their own properties they could shadow the properties
of the instances.
loaders/c/peas-extension-c.c | 64 +++------------------------
loaders/python/peas-extension-python.c | 68 +++--------------------------
loaders/seed/peas-extension-seed.c | 74 ++++++--------------------------
tests/libpeas/extension-c.c | 10 ++--
tests/libpeas/extension-python.c | 15 +++---
5 files changed, 41 insertions(+), 190 deletions(-)
---
diff --git a/loaders/c/peas-extension-c.c b/loaders/c/peas-extension-c.c
index 2b2d44a..4344e9d 100644
--- a/loaders/c/peas-extension-c.c
+++ b/loaders/c/peas-extension-c.c
@@ -30,52 +30,11 @@
G_DEFINE_TYPE (PeasExtensionC, peas_extension_c, PEAS_TYPE_EXTENSION);
-enum {
- PROP_0,
- PROP_INSTANCE
-};
-
static void
peas_extension_c_init (PeasExtensionC *cexten)
{
}
-static void
-peas_extension_c_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionC *cexten = PEAS_EXTENSION_C (object);
-
- switch (prop_id)
- {
- case PROP_INSTANCE:
- cexten->instance = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-peas_extension_c_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionC *cexten = PEAS_EXTENSION_C (object);
-
- switch (prop_id)
- {
- case PROP_INSTANCE:
- g_value_set_object (value, cexten->instance);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
static gboolean
peas_extension_c_call (PeasExtension *exten,
GType gtype,
@@ -111,31 +70,24 @@ peas_extension_c_class_init (PeasExtensionCClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PeasExtensionClass *extension_class = PEAS_EXTENSION_CLASS (klass);
- object_class->set_property = peas_extension_c_set_property;
- object_class->get_property = peas_extension_c_get_property;
object_class->dispose = peas_extension_c_dispose;
extension_class->call = peas_extension_c_call;
-
- g_object_class_install_property (object_class,
- PROP_INSTANCE,
- g_param_spec_object ("instance",
- "Extension Instance",
- "The C Extension Instance",
- G_TYPE_OBJECT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
}
PeasExtension *
peas_extension_c_new (GType gtype,
GObject *instance)
{
+ PeasExtensionC *cexten;
GType real_type;
real_type = peas_extension_register_subclass (PEAS_TYPE_EXTENSION_C, gtype);
- return PEAS_EXTENSION (g_object_new (real_type,
- "extension-type", gtype,
- "instance", instance,
- NULL));
+ cexten = PEAS_EXTENSION_C (g_object_new (real_type,
+ "extension-type", gtype,
+ NULL));
+
+ cexten->instance = instance;
+
+ return PEAS_EXTENSION (cexten);
}
diff --git a/loaders/python/peas-extension-python.c b/loaders/python/peas-extension-python.c
index 2182943..4ee6a65 100644
--- a/loaders/python/peas-extension-python.c
+++ b/loaders/python/peas-extension-python.c
@@ -35,57 +35,11 @@
G_DEFINE_TYPE (PeasExtensionPython, peas_extension_python, PEAS_TYPE_EXTENSION);
-enum {
- PROP_0,
- PROP_INSTANCE
-};
-
static void
peas_extension_python_init (PeasExtensionPython *pyexten)
{
}
-static void
-peas_extension_python_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionPython *pyexten = PEAS_EXTENSION_PYTHON (object);
- PyGILState_STATE state;
-
- switch (prop_id)
- {
- case PROP_INSTANCE:
- pyexten->instance = g_value_get_pointer (value);
-
- state = pyg_gil_state_ensure ();
- Py_INCREF (pyexten->instance);
- pyg_gil_state_release (state);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-peas_extension_python_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionPython *pyexten = PEAS_EXTENSION_PYTHON (object);
-
- switch (prop_id)
- {
- case PROP_INSTANCE:
- g_value_set_pointer (value, pyexten->instance);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
static gboolean
peas_extension_python_call (PeasExtension *exten,
GType gtype,
@@ -134,19 +88,9 @@ peas_extension_python_class_init (PeasExtensionPythonClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PeasExtensionClass *extension_class = PEAS_EXTENSION_CLASS (klass);
- object_class->set_property = peas_extension_python_set_property;
- object_class->get_property = peas_extension_python_get_property;
object_class->dispose = peas_extension_python_dispose;
extension_class->call = peas_extension_python_call;
-
- g_object_class_install_property (object_class,
- PROP_INSTANCE,
- g_param_spec_pointer ("instance",
- "Extension Instance",
- "The Python Extension Instance",
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
}
PeasExtension *
@@ -157,8 +101,12 @@ peas_extension_python_new (GType gtype,
GType real_type;
real_type = peas_extension_register_subclass (PEAS_TYPE_EXTENSION_PYTHON, gtype);
- return PEAS_EXTENSION (g_object_new (real_type,
- "extension-type", gtype,
- "instance", instance,
- NULL));
+ pyexten = PEAS_EXTENSION_PYTHON (g_object_new (real_type,
+ "extension-type", gtype,
+ NULL));
+
+ pyexten->instance = instance;
+ Py_INCREF (instance);
+
+ return PEAS_EXTENSION (pyexten);
}
diff --git a/loaders/seed/peas-extension-seed.c b/loaders/seed/peas-extension-seed.c
index 9d5f607..27f0a47 100644
--- a/loaders/seed/peas-extension-seed.c
+++ b/loaders/seed/peas-extension-seed.c
@@ -30,52 +30,15 @@
G_DEFINE_TYPE (PeasExtensionSeed, peas_extension_seed, PEAS_TYPE_EXTENSION);
-enum {
- PROP_0,
- PROP_JS_CONTEXT,
- PROP_JS_OBJECT,
-};
-
typedef struct {
GITypeInfo *type_info;
GIArgument *ptr;
} OutArg;
-static void
-peas_extension_seed_init (PeasExtensionSeed *sexten)
-{
-}
static void
-peas_extension_seed_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PeasExtensionSeed *sexten = PEAS_EXTENSION_SEED (object);
-
- switch (prop_id)
- {
- case PROP_JS_CONTEXT:
- sexten->js_context = g_value_get_pointer (value);
- break;
- case PROP_JS_OBJECT:
- sexten->js_object = g_value_get_pointer (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-peas_extension_seed_constructed (GObject *object)
+peas_extension_seed_init (PeasExtensionSeed *sexten)
{
- PeasExtensionSeed *sexten = PEAS_EXTENSION_SEED (object);
-
- /* We do this here as we can't be sure the context is already set when
- * the "JS_PLUGIN" property is set. */
- seed_context_ref (sexten->js_context);
- seed_value_protect (sexten->js_context, sexten->js_object);
}
static void
@@ -384,27 +347,9 @@ peas_extension_seed_class_init (PeasExtensionSeedClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PeasExtensionClass *extension_class = PEAS_EXTENSION_CLASS (klass);
- object_class->set_property = peas_extension_seed_set_property;
- object_class->constructed = peas_extension_seed_constructed;
object_class->dispose = peas_extension_seed_dispose;
extension_class->call = peas_extension_seed_call;
-
- g_object_class_install_property (object_class,
- PROP_JS_CONTEXT,
- g_param_spec_pointer ("js-context",
- "JavaScript Context",
- "A Seed JavaScript context",
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (object_class,
- PROP_JS_OBJECT,
- g_param_spec_pointer ("js-object",
- "JavaScript Object",
- "A Seed JavaScript object",
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
}
PeasExtension *
@@ -412,15 +357,22 @@ peas_extension_seed_new (GType exten_type,
SeedContext js_context,
SeedObject js_object)
{
+ PeasExtensionSeed *sexten;
GType real_type;
g_return_val_if_fail (js_context != NULL, NULL);
g_return_val_if_fail (js_object != NULL, NULL);
real_type = peas_extension_register_subclass (PEAS_TYPE_EXTENSION_SEED, exten_type);
- return PEAS_EXTENSION (g_object_new (real_type,
- "extension-type", exten_type,
- "js-context", js_context,
- "js-object", js_object,
- NULL));
+ sexten = PEAS_EXTENSION_SEED (g_object_new (real_type,
+ "extension-type", exten_type,
+ NULL));
+
+ sexten->js_context = js_context;
+ sexten->js_object = js_object;
+
+ seed_context_ref (sexten->js_context);
+ seed_value_protect (sexten->js_context, sexten->js_object);
+
+ return PEAS_EXTENSION (sexten);
}
diff --git a/tests/libpeas/extension-c.c b/tests/libpeas/extension-c.c
index 776ccb9..b34f3f9 100644
--- a/tests/libpeas/extension-c.c
+++ b/tests/libpeas/extension-c.c
@@ -23,6 +23,8 @@
#include <config.h>
#endif
+#include "loaders/c/peas-extension-c.h"
+
#include "testing/testing-extension.h"
#include "introspection/introspection-callable.h"
@@ -43,14 +45,12 @@ test_extension_c_instance_refcount (PeasEngine *engine)
g_assert (PEAS_IS_EXTENSION (extension));
- g_object_get (extension, "instance", &instance, NULL);
+ instance = ((PeasExtensionC *) extension)->instance;
- /* The refcount of the returned object should be 2:
+ /* The refcount of the returned object should be 1:
* - one ref for the PeasExtension
- * - one ref added by g_object_get()
*/
- g_assert_cmpint (instance->ref_count, ==, 2);
- g_object_unref (instance);
+ g_assert_cmpint (instance->ref_count, ==, 1);
g_object_unref (extension);
}
diff --git a/tests/libpeas/extension-python.c b/tests/libpeas/extension-python.c
index 653de25..9010f69 100644
--- a/tests/libpeas/extension-python.c
+++ b/tests/libpeas/extension-python.c
@@ -23,11 +23,13 @@
#include <config.h>
#endif
-#include "testing/testing-extension.h"
-#include "introspection/introspection-callable.h"
+#include <pygobject.h>
+
#include <libpeas/peas-activatable.h>
+#include "loaders/python/peas-extension-python.h"
-#include <pygobject.h>
+#include "testing/testing-extension.h"
+#include "introspection/introspection-callable.h"
static void
test_extension_python_instance_refcount (PeasEngine *engine)
@@ -46,11 +48,8 @@ test_extension_python_instance_refcount (PeasEngine *engine)
g_assert (PEAS_IS_EXTENSION (extension));
- g_object_get (extension, "instance", &instance, NULL);
+ instance = ((PeasExtensionPython *) extension)->instance;
- /* The property getter for PeasExtensionPython.instance doesn't increment the
- * refcount, so the refcount here should be 1.
- */
g_assert_cmpint (instance->ob_refcnt, ==, 1);
/* The internal extension GObject should only be reffed by its python wrapper. */
@@ -93,7 +92,7 @@ test_extension_python_activatable_subject_refcount (PeasEngine *engine)
wrapper = g_object_get_data (object, "PyGObject::wrapper");
g_assert_cmpint (wrapper->ob_refcnt, ==, 1);
- g_assert_cmpint (((GObject *)extension)->ref_count, ==, 1);
+ g_assert_cmpint (G_OBJECT (extension)->ref_count, ==, 1);
g_object_unref (extension);
/* We unreffed the extension, so it should have been destroyed and our dummy
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]