[libpeas] Add a test to check the refcount of python extensions.
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Add a test to check the refcount of python extensions.
- Date: Mon, 7 Mar 2011 17:21:32 +0000 (UTC)
commit 1ab75ec6e1036600ee3a1d14d8d6e39f9f1d49e3
Author: Steve Frécinaux <code istique net>
Date: Sun Mar 6 19:47:32 2011 +0100
Add a test to check the refcount of python extensions.
loaders/python/peas-extension-python.c | 21 ++++++++++++++++++-
tests/libpeas/Makefile.am | 1 +
tests/libpeas/extension-python.c | 34 ++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/loaders/python/peas-extension-python.c b/loaders/python/peas-extension-python.c
index 24ab7ed..2182943 100644
--- a/loaders/python/peas-extension-python.c
+++ b/loaders/python/peas-extension-python.c
@@ -68,6 +68,24 @@ peas_extension_python_set_property (GObject *object,
}
}
+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,
@@ -117,6 +135,7 @@ peas_extension_python_class_init (PeasExtensionPythonClass *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;
@@ -126,7 +145,7 @@ peas_extension_python_class_init (PeasExtensionPythonClass *klass)
g_param_spec_pointer ("instance",
"Extension Instance",
"The Python Extension Instance",
- G_PARAM_WRITABLE |
+ G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
diff --git a/tests/libpeas/Makefile.am b/tests/libpeas/Makefile.am
index c2b7dbe..09ee419 100644
--- a/tests/libpeas/Makefile.am
+++ b/tests/libpeas/Makefile.am
@@ -31,6 +31,7 @@ extension_c_LDADD = $(progs_ldadd)
if ENABLE_PYTHON
TEST_PROGS += extension-python
extension_python_SOURCES = extension-python.c
+extension_python_CFLAGS = $(PYGTK_CFLAGS) $(PYTHON_CFLAGS)
extension_python_LDADD = $(progs_ldadd)
endif
diff --git a/tests/libpeas/extension-python.c b/tests/libpeas/extension-python.c
index 6cc9b85..27e91a2 100644
--- a/tests/libpeas/extension-python.c
+++ b/tests/libpeas/extension-python.c
@@ -24,6 +24,38 @@
#endif
#include "testing/testing-extension.h"
+#include "introspection/introspection-callable.h"
+#include <pygobject.h>
+
+static void
+extension_python_instance_refcount (PeasEngine *engine)
+{
+ PeasPluginInfo *info;
+ PeasExtension *extension;
+ PyObject *instance;
+
+ info = peas_engine_get_plugin_info (engine, "extension-python");
+
+ g_assert (peas_engine_load_plugin (engine, info));
+
+ extension = peas_engine_create_extension (engine, info,
+ INTROSPECTION_TYPE_CALLABLE,
+ NULL);
+
+ g_assert (PEAS_IS_EXTENSION (extension));
+
+ g_object_get (extension, "instance", &instance, NULL);
+
+ /* 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. */
+ g_assert_cmpint (((PyGObject *)instance)->obj->ref_count, ==, 1);
+
+ g_object_unref (extension);
+}
int
main (int argc,
@@ -34,5 +66,7 @@ main (int argc,
EXTENSION_TESTS ("python");
+ EXTENSION_TEST_ADD ("python", "instance-refcount", extension_python_instance_refcount);
+
return testing_run_tests ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]