diff options
author | Edward Hervey <bilboed@bilboed.com> | 2009-02-27 12:29:04 +0100 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2009-02-27 12:29:04 +0100 |
commit | 6d6781e01f919dfd04c18b881b64553bf320e5a2 (patch) | |
tree | 213e696a1f422644387f3c7b63101f1980d1ed49 /plugin/gstpythonplugin.c | |
parent | 3f5c8795c367f772f855133b175c401bdac25748 (diff) |
plugin: Don't import modules that were already imported.
This avoids warnings for the cases where pygst.require() was already
called.
Diffstat (limited to 'plugin/gstpythonplugin.c')
-rw-r--r-- | plugin/gstpythonplugin.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/plugin/gstpythonplugin.c b/plugin/gstpythonplugin.c index 6648020..dc3f0e2 100644 --- a/plugin/gstpythonplugin.c +++ b/plugin/gstpythonplugin.c @@ -252,22 +252,32 @@ pygst_require (gchar * version) { PyObject *pygst, *gst; PyObject *require; - - if (!(pygst = PyImport_ImportModule ("pygst"))) { - GST_ERROR ("the pygst module is not available!"); - goto error; - } - - if (!(PyObject_CallMethod (pygst, "require", "s", version))) { - GST_ERROR ("the required version, %s, of gst-python is not available!"); - Py_DECREF (pygst); - goto error; - } - - if (!(gst = PyImport_ImportModule ("gst"))) { - GST_ERROR ("couldn't import the gst module"); - Py_DECREF (pygst); - goto error; + PyObject *modules; + + modules = PySys_GetObject ("modules"); + /* Try to see if 'gst' is already imported */ + if (!(gst = PyMapping_GetItemString (modules, "gst"))) { + + /* if not, see if 'pygst' was already imported. If so, we assume that + * 'pygst.require' has already been called. */ + if (!(pygst = PyMapping_GetItemString (modules, "pygst"))) { + if (!(pygst = PyImport_ImportModule ("pygst"))) { + GST_ERROR ("the pygst module is not available!"); + goto error; + } + + if (!(PyObject_CallMethod (pygst, "require", "s", version))) { + GST_ERROR ("the required version, %s, of gst-python is not available!", + version); + Py_DECREF (pygst); + goto error; + } + } + if (!(gst = PyImport_ImportModule ("gst"))) { + GST_ERROR ("couldn't import the gst module"); + Py_DECREF (pygst); + goto error; + } } #define IMPORT(x, y) \ _PyGst##x##_Type = (PyTypeObject *)PyObject_GetAttrString(gst, y); \ |