[pygobject/pygobject-2-28] [GI] Remove implicit loading of gi module preserve the code path for static bindings.
- From: Laszlo Pandy <lpandy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-2-28] [GI] Remove implicit loading of gi module preserve the code path for static bindings.
- Date: Tue, 15 Feb 2011 20:03:16 +0000 (UTC)
commit 71b0dd93d524afce9f4a4b0b393c8a16a1f70e2f
Author: Laszlo Pandy <lpandy src gnome org>
Date: Tue Feb 15 16:26:24 2011 +0100
[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
gi/pygi.h | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi.h b/gi/pygi.h
index 274af4d..1c3bf5e 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]