[Xfce4-commits] <thunarx-python:master> The pygobject and pygtk init functions should both use PyCapsule_Import if possible.

Adam Plumb noreply at xfce.org
Wed Mar 23 20:20:01 CET 2011


Updating branch refs/heads/master
         to 6485b36d34928a67cb4ce1427cdb0d7bbe687423 (commit)
       from 3ea8c96e11bc9b6f2b0237adc3d5f39205d114c5 (commit)

commit 6485b36d34928a67cb4ce1427cdb0d7bbe687423
Author: Adam Plumb <adamplumb at gmail.com>
Date:   Wed Mar 23 15:19:47 2011 -0400

    The pygobject and pygtk init functions should both use PyCapsule_Import if possible.

 src/thunarx-python.c |   52 ++++++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/src/thunarx-python.c b/src/thunarx-python.c
index 3133511..5adae02 100644
--- a/src/thunarx-python.c
+++ b/src/thunarx-python.c
@@ -48,6 +48,15 @@ static gboolean thunarx_python_init_python (void);
 static inline gboolean 
 thunarx_python_init_pygobject(void)
 {
+#ifdef Py_CAPSULE_H
+	void *capsule = PyCapsule_Import("gobject._PyGObject_API", 1);
+	if (capsule)
+	{
+		_PyGObject_API = (struct _PyGObject_Functions *)capsule;
+        return TRUE;
+	}
+#endif
+
     PyObject *gobject = PyImport_ImportModule("gobject");
     if (gobject != NULL)
     {
@@ -61,8 +70,8 @@ thunarx_python_init_pygobject(void)
         {
             PyErr_SetString(PyExc_RuntimeError,
                             "could not find _PyGObject_API object");
-			PyErr_Print();
-			return FALSE;
+		    PyErr_Print();
+		    return FALSE;
         }
     }
     else
@@ -79,32 +88,31 @@ thunarx_python_init_pygobject(void)
 static inline gboolean 
 thunarx_python_init_pygtk(void)
 {
+#ifdef Py_CAPSULE_H
+	void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0);
+	if (capsule)
+	{
+		_PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule;
+		return TRUE;
+	}
+#endif
+
     PyObject *pygtk = PyImport_ImportModule("gtk._gtk");
     if (pygtk != NULL)
     {
-#ifdef Py_CAPSULE_H
-		void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0);
-		if (capsule)
+		PyObject *module_dict = PyModule_GetDict(pygtk);
+		PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
+		if (PyCObject_Check(cobject))
 		{
-			_PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule;
+			_PyGtk_API = (struct _PyGtk_FunctionStruct*)
+				PyCObject_AsVoidPtr(cobject);
 		}
-#endif
-		if (!_PyGtk_API)
+		else
 		{
-			PyObject *module_dict = PyModule_GetDict(pygtk);
-			PyObject *cobject = PyDict_GetItemString(module_dict, "_PyGtk_API");
-			if (PyCObject_Check(cobject))
-			{
-				_PyGtk_API = (struct _PyGtk_FunctionStruct*)
-					PyCObject_AsVoidPtr(cobject);
-			}
-			else
-			{
-				PyErr_SetString(PyExc_RuntimeError,
-				                "could not find _PyGtk_API object");
-				PyErr_Print();
-				return FALSE;
-			}
+			PyErr_SetString(PyExc_RuntimeError,
+			                "could not find _PyGtk_API object");
+			PyErr_Print();
+			return FALSE;
 		}
     }
     else



More information about the Xfce4-commits mailing list