[libpeas] [Python] Fix extension implementation lookup



commit 907db927685896ea0b315c7e3efc8b65d9fbe067
Author: Steve Frécinaux <code istique net>
Date:   Sun Jun 27 19:00:34 2010 +0200

    [Python] Fix extension implementation lookup
    
    The wrong implementation could be returned if an error happened in
    PyObject_IsSubclass() (for instance because a gtype wrapper was not
    available).

 loaders/python/peas-plugin-loader-python.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c
index 9de24c7..0ba8ff7 100644
--- a/loaders/python/peas-plugin-loader-python.c
+++ b/loaders/python/peas-plugin-loader-python.c
@@ -77,15 +77,24 @@ find_python_extension_type (PeasPluginInfo *info,
   pytype = PyObject_GetAttrString (pygtype, "pytype");
   g_return_val_if_fail (pytype != NULL, NULL);
 
+  if (pytype == Py_None)
+    return NULL;
+
   while (PyDict_Next (locals, &pos, &key, &value))
     {
       if (!PyType_Check (value))
         continue;
 
-      if (PyObject_IsSubclass (value, pytype))
+      switch (PyObject_IsSubclass (value, pytype))
         {
+        case 1:
           Py_DECREF (pygtype);
           return (PyTypeObject *) value;
+        case 0:
+          continue;
+        case -1:
+          PyErr_Print ();
+          continue;
         }
     }
 
@@ -167,6 +176,8 @@ peas_plugin_loader_python_get_extension (PeasPluginLoader *loader,
       return NULL;
     }
 
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (pygobject->obj, exten_type), NULL);
+
   /* now call tp_init manually */
   if (PyType_IsSubtype (pyobject->ob_type, pytype)
       && pyobject->ob_type->tp_init != NULL)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]