python27.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. diff --git a/gtk/gtkmodule.c b/gtk/gtkmodule.c
  2. index c0e1493..aa8cf10 100644
  3. --- a/gtk/gtkmodule.c
  4. +++ b/gtk/gtkmodule.c
  5. @@ -227,8 +227,12 @@ init_gtk(void)
  6. pygtk_add_stock_items(d);
  7. /* extension API */
  8. - PyDict_SetItemString(d, "_PyGtk_API",
  9. - o=PyCObject_FromVoidPtr(&functions, NULL));
  10. +#if PY_VERSION_HEX >= 0x02070000
  11. + o = PyCapsule_New(&functions, "gtk._gtk._PyGtk_API", NULL);
  12. +#else
  13. + o = PyCObject_FromVoidPtr(&functions, NULL);
  14. +#endif
  15. + PyDict_SetItemString(d, "_PyGtk_API", o);
  16. Py_DECREF(o);
  17. PyGtkDeprecationWarning = PyErr_NewException("gtk.GtkDeprecationWarning",
  18. diff --git a/gtk/pygtk.h b/gtk/pygtk.h
  19. index 573c3b9..e4c680f 100644
  20. --- a/gtk/pygtk.h
  21. +++ b/gtk/pygtk.h
  22. @@ -60,6 +60,18 @@ struct _PyGtk_FunctionStruct *_PyGtk_API;
  23. /* a function to initialise the pygtk functions */
  24. +
  25. +/* Python 2.7 introduced the PyCapsule API and deprecated the CObject API */
  26. +#if PY_VERSION_HEX >= 0x02070000
  27. +#define init_pygtk() G_STMT_START { \
  28. + void *capsule = PyCapsule_Import("gtk._gtk._PyGtk_API", 0); \
  29. + if (!capsule) { \
  30. + return; \
  31. + } \
  32. + _PyGtk_API = (struct _PyGtk_FunctionStruct*)capsule; \
  33. +} G_STMT_END
  34. +#else /* PY_VERSION_HEX */
  35. +/* Python 2.6 and earlier use the CObject API */
  36. #define init_pygtk() G_STMT_START { \
  37. PyObject *pygtk = PyImport_ImportModule("gtk"); \
  38. if (pygtk != NULL) { \
  39. @@ -79,6 +91,7 @@ struct _PyGtk_FunctionStruct *_PyGtk_API;
  40. return; \
  41. } \
  42. } G_STMT_END
  43. +#endif /* PY_VERSION_HEX */
  44. #endif