[libpeas] Do not wrap PyGObject extensions



commit f5f8bc1f4a82e5faede3fe20cad7889da414c25c
Author: Garrett Regier <garrettregier gmail com>
Date:   Wed Nov 13 00:20:12 2013 -0800

    Do not wrap PyGObject extensions
    
    PyGObject already wraps them so it is unneeded.

 loaders/python/Makefile.am                 |    2 -
 loaders/python/peas-extension-python.c     |  163 ----------------------------
 loaders/python/peas-extension-python.h     |   62 -----------
 loaders/python/peas-plugin-loader-python.c |   17 ++--
 loaders/python3/Makefile.am                |    2 -
 tests/libpeas/extension-py.c               |   12 +--
 6 files changed, 13 insertions(+), 245 deletions(-)
---
diff --git a/loaders/python/Makefile.am b/loaders/python/Makefile.am
index 2bd1321..a33d0af 100644
--- a/loaders/python/Makefile.am
+++ b/loaders/python/Makefile.am
@@ -16,8 +16,6 @@ INCLUDES = \
 loader_LTLIBRARIES = libpythonloader.la
 
 libpythonloader_la_SOURCES = \
-       peas-extension-python.c         \
-       peas-extension-python.h         \
        peas-plugin-loader-python.c     \
        peas-plugin-loader-python.h
 
diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c
index f59a0bc..1c7daf2 100644
--- a/loaders/python/peas-plugin-loader-python.c
+++ b/loaders/python/peas-plugin-loader-python.c
@@ -24,7 +24,6 @@
 #include <config.h>
 #endif
 
-#include "peas-extension-python.h"
 #include "peas-plugin-loader-python.h"
 
 /* _POSIX_C_SOURCE is defined in Python.h and in limits.h included by
@@ -141,11 +140,10 @@ peas_plugin_loader_python_create_extension (PeasPluginLoader *loader,
   PythonInfo *pyinfo;
   PyTypeObject *pytype;
   GType the_type;
-  GObject *object;
+  GObject *object = NULL;
   PyObject *pyobject;
   PyObject *pyplinfo;
   PyGILState_STATE state;
-  PeasExtension *exten = NULL;
 
   pyinfo = (PythonInfo *) g_hash_table_lookup (pyloader->priv->loaded_plugins, info);
 
@@ -172,24 +170,27 @@ peas_plugin_loader_python_create_extension (PeasPluginLoader *loader,
   if (!object)
     goto out;
 
+  /* 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_get_extension_type() method.
+   */
+  g_object_set_data (object, "peas-extension-type",
+                     GUINT_TO_POINTER (exten_type));
+
   pyobject = pygobject_new (object);
-  g_object_unref (object);
 
   /* Set the plugin info as an attribute of the instance */
   pyplinfo = pyg_boxed_new (PEAS_TYPE_PLUGIN_INFO, info, TRUE, TRUE);
   PyObject_SetAttrString (pyobject, "plugin_info", pyplinfo);
   Py_DECREF (pyplinfo);
 
-  exten = peas_extension_python_new (exten_type,
-                                     g_type_interfaces (the_type, NULL),
-                                     pyobject);
   Py_DECREF (pyobject);
 
 out:
 
   PyGILState_Release (state);
 
-  return exten;
+  return object;
 }
 
 /* NOTE: This must be called with the GIL held */
diff --git a/loaders/python3/Makefile.am b/loaders/python3/Makefile.am
index 6116665..884d710 100644
--- a/loaders/python3/Makefile.am
+++ b/loaders/python3/Makefile.am
@@ -16,8 +16,6 @@ INCLUDES = \
 loader_LTLIBRARIES = libpython3loader.la
 
 libpython3loader_la_SOURCES = \
-       $(top_srcdir)/loaders/python/peas-extension-python.c            \
-       $(top_srcdir)/loaders/python/peas-extension-python.h            \
        $(top_srcdir)/loaders/python/peas-plugin-loader-python.c        \
        $(top_srcdir)/loaders/python/peas-plugin-loader-python.h
 
diff --git a/tests/libpeas/extension-py.c b/tests/libpeas/extension-py.c
index 4794d83..b50eeb9 100644
--- a/tests/libpeas/extension-py.c
+++ b/tests/libpeas/extension-py.c
@@ -28,7 +28,6 @@
 
 #include <libpeas/peas-activatable.h>
 #include "libpeas/peas-engine-priv.h"
-#include "loaders/python/peas-extension-python.h"
 
 #include "testing/testing-extension.h"
 #include "introspection/introspection-base.h"
@@ -51,7 +50,6 @@ test_extension_py_instance_refcount (PeasEngine     *engine,
                                      PeasPluginInfo *info)
 {
   PeasExtension *extension;
-  PyObject *instance;
 
   extension = peas_engine_create_extension (engine, info,
                                             INTROSPECTION_TYPE_BASE,
@@ -59,14 +57,12 @@ test_extension_py_instance_refcount (PeasEngine     *engine,
 
   g_assert (PEAS_IS_EXTENSION (extension));
 
-  instance = ((PeasExtensionPython *) extension)->instance;
+  g_object_add_weak_pointer (extension, (gpointer *) &extension);
 
-  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_assert_cmpint (extension->ref_count, ==, 2);
 
   g_object_unref (extension);
+  g_assert (extension == NULL);
 }
 
 static void
@@ -100,7 +96,7 @@ test_extension_py_activatable_subject_refcount (PeasEngine     *engine,
   wrapper = g_object_get_data (object, "PyGObject::wrapper");
   g_assert_cmpint (wrapper->ob_refcnt, ==, 1);
 
-  g_assert_cmpint (G_OBJECT (extension)->ref_count, ==, 1);
+  g_assert_cmpint (G_OBJECT (extension)->ref_count, ==, 2);
   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]