diff options
Diffstat (limited to 'gobject/pygobject.h')
-rw-r--r-- | gobject/pygobject.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gobject/pygobject.h b/gobject/pygobject.h index 85d8bca..21743ba 100644 --- a/gobject/pygobject.h +++ b/gobject/pygobject.h @@ -198,6 +198,7 @@ struct _PyGObject_Functions { gpointer data); gboolean (*gerror_exception_check) (GError **error); PyObject* (*option_group_new) (GOptionGroup *group); + GType (* type_from_object_strict) (PyObject *obj, gboolean strict); }; #ifndef _INSIDE_PYGOBJECT_ @@ -218,6 +219,7 @@ struct _PyGObject_Functions *_PyGObject_API; #define pygobject_watch_closure (_PyGObject_API->object_watch_closure) #define pyg_closure_set_exception_handler (_PyGObject_API->closure_set_exception_handler) #define pyg_destroy_notify (_PyGObject_API->destroy_notify) +#define pyg_type_from_object_strict (_PyGObject_API->type_from_object_strict) #define pyg_type_from_object (_PyGObject_API->type_from_object) #define pyg_type_wrapper_new (_PyGObject_API->type_wrapper_new) #define pyg_enum_get_value (_PyGObject_API->enum_get_value) @@ -317,9 +319,32 @@ pygobject_init(int req_major, int req_minor, int req_micro) Py_XDECREF(type); Py_XDECREF(value); Py_XDECREF(traceback); + + +#if PY_VERSION_HEX < 0x03000000 PyErr_Format(PyExc_ImportError, "could not import gobject (error was: %s)", PyString_AsString(py_orig_exc)); +#else + { + /* Can not use PyErr_Format because it doesn't have + * a format string for dealing with PyUnicode objects + * like PyUnicode_FromFormat has + */ + PyObject *errmsg = PyUnicode_FromFormat("could not import gobject (error was: %U)", + py_orig_exc); + + if (errmsg) { + PyErr_SetObject(PyExc_ImportError, + errmsg); + Py_DECREF(errmsg); + } + /* if errmsg is NULL then we might have OOM + * PyErr should already be set and trying to + * return our own error would be futile + */ + } +#endif Py_DECREF(py_orig_exc); } else { PyErr_SetString(PyExc_ImportError, @@ -329,8 +354,14 @@ pygobject_init(int req_major, int req_minor, int req_micro) } cobject = PyObject_GetAttrString(gobject, "_PyGObject_API"); +#if PY_VERSION_HEX >= 0x03000000 + if (cobject && PyCapsule_CheckExact(cobject)) + _PyGObject_API = (struct _PyGObject_Functions *) PyCapsule_GetPointer(cobject, "gobject._PyGObject_API"); + +#else if (cobject && PyCObject_Check(cobject)) _PyGObject_API = (struct _PyGObject_Functions *) PyCObject_AsVoidPtr(cobject); +#endif else { PyErr_SetString(PyExc_ImportError, "could not import gobject (could not find _PyGObject_API object)"); |