initgtask (void) { PyObject *m, *d; PyEval_InitThreads (); init_pygobject (); m = Py_InitModule ("gtask", pygtask_functions); d = PyModule_GetDict (m); pygtask_register_classes (d); pygtask_add_constants (m, "G_"); if (PyErr_Occurred ()) Py_FatalError ("Error initializing module GTask"); pyg_enable_threads (); }
static gboolean peas_plugin_loader_python_initialize (PeasPluginLoader *loader) { PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader); PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader); PyGILState_STATE state = 0; long hexversion; /* We can't support multiple Python interpreter states: * https://bugzilla.gnome.org/show_bug.cgi?id=677091 */ /* Python initialization */ if (Py_IsInitialized ()) { state = PyGILState_Ensure (); } else { Py_InitializeEx (FALSE); priv->must_finalize_python = TRUE; } hexversion = PyLong_AsLong (PySys_GetObject ((char *) "hexversion")); #if PY_VERSION_HEX < 0x03000000 if (hexversion >= 0x03000000) #else if (hexversion < 0x03000000) #endif { g_critical ("Attempting to mix incompatible Python versions"); goto python_init_error; } /* Initialize PyGObject */ pygobject_init (PYGOBJECT_MAJOR_VERSION, PYGOBJECT_MINOR_VERSION, PYGOBJECT_MICRO_VERSION); if (PyErr_Occurred ()) { g_warning ("Error initializing Python Plugin Loader: " "PyGObject initialization failed"); goto python_init_error; } /* Initialize support for threads */ pyg_enable_threads (); PyEval_InitThreads (); /* Only redirect warnings when python was not already initialized */ if (!priv->must_finalize_python) pyg_disable_warning_redirections (); /* Must be done last, finalize() depends on init_failed */ if (!peas_python_internal_setup (!priv->must_finalize_python)) { /* Already warned */ goto python_init_error; } if (!priv->must_finalize_python) PyGILState_Release (state); else priv->py_thread_state = PyEval_SaveThread (); return TRUE; python_init_error: if (PyErr_Occurred ()) PyErr_Print (); g_warning ("Please check the installation of all the Python " "related packages required by libpeas and try again"); if (!priv->must_finalize_python) PyGILState_Release (state); priv->init_failed = TRUE; return FALSE; }