[libpeas] Simplify installing gettext in the python plugin loader



commit 6b0c65f7598cfd178bf53d5cd4e9f08458de84dc
Author: Garrett Regier <garrettregier gmail com>
Date:   Thu May 29 19:00:51 2014 -0700

    Simplify installing gettext in the python plugin loader
    
    Also check for an error after installing.

 loaders/python/peas-plugin-loader-python.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c
index 778af3f..ed018a3 100644
--- a/loaders/python/peas-plugin-loader-python.c
+++ b/loaders/python/peas-plugin-loader-python.c
@@ -376,7 +376,7 @@ peas_plugin_loader_python_initialize (PeasPluginLoader *loader)
 {
   PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader);
   long hexversion;
-  PyObject *mdict, *gettext, *install, *gettext_args;
+  PyObject *gettext, *result;
   const gchar *prgname;
 #if PY_VERSION_HEX < 0x03000000
   const char *argv[] = { NULL, NULL };
@@ -491,11 +491,17 @@ peas_plugin_loader_python_initialize (PeasPluginLoader *loader)
       goto python_init_error;
     }
 
-  mdict = PyModule_GetDict (gettext);
-  install = PyDict_GetItemString (mdict, "install");
-  gettext_args = Py_BuildValue ("ss", GETTEXT_PACKAGE, PEAS_LOCALEDIR);
-  PyObject_CallObject (install, gettext_args);
-  Py_DECREF (gettext_args);
+  result = PyObject_CallMethod (gettext, "install", "ss",
+                                GETTEXT_PACKAGE, PEAS_LOCALEDIR);
+  Py_XDECREF (result);
+
+  if (PyErr_Occurred ())
+    {
+      g_warning ("Error initializing Python Plugin Loader: "
+                 "failed to install gettext");
+
+      goto python_init_error;
+    }
 
   /* Python has been successfully initialized */
   pyloader->priv->init_failed = FALSE;


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