summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Pandy <lpandy@src.gnome.org>2011-02-15 16:26:24 +0100
committerLaszlo Pandy <lpandy@src.gnome.org>2011-02-15 21:00:30 +0100
commit71b0dd93d524afce9f4a4b0b393c8a16a1f70e2f (patch)
treeefb746b50256057bd52112abca82293a504bbe81
parent97e78181813f15f693e650df5a8901bd2fe71541 (diff)
downloadpygobject-71b0dd93d524afce9f4a4b0b393c8a16a1f70e2f.tar.gz
[GI] Remove implicit loading of gi module preserve the code path for static bindings.
Previously type lookups (as well as property accesses and signal connects would trigger an import of the gi module). Now we make those paths fail, and fallback to the old static binding code paths *unless* the gi module is already in sys.modules. So if Python code calls: from gi.repository import Gtk or even just: import gi then everything will work just like it did without this patch. If gi is not explicitly imported, the code skips the introspection code and acts like the old static bindings did. https://bugzilla.gnome.org/show_bug.cgi?id=642387
-rw-r--r--gi/pygi.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/gi/pygi.h b/gi/pygi.h
index 274af4d0..1c3bf5e3 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -88,14 +88,20 @@ static struct PyGI_API *PyGI_API = NULL;
static int
_pygi_import (void)
{
+ PyObject *modules_dict;
+
if (PyGI_API != NULL) {
return 1;
}
+
+ modules_dict = PyImport_GetModuleDict(); /* borrowed reference -- don't unref */
+ if (PyMapping_HasKeyString(modules_dict, "gi")) {
#if PY_VERSION_HEX >= 0x03000000
- PyGI_API = (struct PyGI_API*) PyCapsule_Import("gi._API", FALSE);
+ PyGI_API = (struct PyGI_API*) PyCapsule_Import("gi._API", FALSE);
#else
- PyGI_API = (struct PyGI_API*) PyCObject_Import("gi", "_API");
+ PyGI_API = (struct PyGI_API*) PyCObject_Import("gi", "_API");
#endif
+ }
if (PyGI_API == NULL) {
return -1;
}