[nautilus-python] The pygobject and pygtk init functions should both use PyCapsule_Import if possible.
- From: Adam Plumb <adamplumb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-python] The pygobject and pygtk init functions should both use PyCapsule_Import if possible.
- Date: Wed, 23 Mar 2011 19:11:24 +0000 (UTC)
commit 542c63560e024249172506a99845bf5f781ee663
Author: Adam Plumb <adamplumb gmail com>
Date: Wed Mar 23 15:11:00 2011 -0400
The pygobject and pygtk init functions should both use PyCapsule_Import if possible.
src/nautilus-python.c | 44 ++++++++++++++++++++++++--------------------
1 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/src/nautilus-python.c b/src/nautilus-python.c
index 27df331..99a9098 100644
--- a/src/nautilus-python.c
+++ b/src/nautilus-python.c
@@ -44,6 +44,13 @@ static GArray *all_types = NULL;
static inline gboolean
np_init_pygobject(void)
{
+#ifdef Py_CAPSULE_H
+ void *capsule = PyCapsule_Import("gobject._PyGObject_API", 0);
+ if (capsule)
+ {
+ _PyGObject_API = (struct _PyGObject_Functions*)capsule;
+ }
+#endif
PyObject *gobject = PyImport_ImportModule("gobject");
if (gobject != NULL)
{
@@ -73,32 +80,29 @@ np_init_pygobject(void)
static inline gboolean
np_init_pygtk(void)
{
+#ifdef Py_CAPSULE_H
+ void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0);
+ if (capsule)
+ {
+ _PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule;
+ }
+#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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]