summaryrefslogtreecommitdiff
path: root/src/py3cairo.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/py3cairo.h')
-rw-r--r--src/py3cairo.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/py3cairo.h b/src/py3cairo.h
index 35b4240..1aaf743 100644
--- a/src/py3cairo.h
+++ b/src/py3cairo.h
@@ -193,13 +193,21 @@ typedef struct {
#define Pycairo_Check_Status (Pycairo_CAPI->Check_Status)
-/* To access the Pycairo C API, edit the client module file to:
- * 1) Add the following line to define a global variable for the C API
- * static Pycairo_CAPI_t *Pycairo_CAPI;
- * 2) Add 'Pycairo_IMPORT;' to the init<module> function
+/* To access the Pycairo C API, the client module should call 'import_cairo()'
+ * from the init<module> function, and check the return value, < 0 means the
+ * import failed.
*/
-#define Pycairo_IMPORT \
- Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import("cairo", "CAPI")
+static Pycairo_CAPI_t *Pycairo_CAPI;
+
+/* Return -1 on error, 0 on success.
+ * PyCapsule_Import will set an exception if there's an error.
+ */
+static int
+import_cairo(void)
+{
+ Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import("cairo.CAPI", 0);
+ return (Pycairo_CAPI != 0) ? 0 : -1;
+}
#endif /* ifndef _INSIDE_PYCAIRO_ */