diff options
Diffstat (limited to 'gi/pygi-foreign-cairo.c')
-rw-r--r-- | gi/pygi-foreign-cairo.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c index 095f6cb..6326397 100644 --- a/gi/pygi-foreign-cairo.c +++ b/gi/pygi-foreign-cairo.c @@ -22,6 +22,7 @@ */ #include <cairo.h> +#include <Python.h> #if PY_VERSION_HEX < 0x03000000 #include <pycairo.h> @@ -111,6 +112,58 @@ cairo_surface_release (GIBaseInfo *base_info, Py_RETURN_NONE; } +#ifdef PycairoRectangleInt_FromRectangleInt +PyObject * +cairo_rectangle_int_to_arg (PyObject *value, + GITypeInfo *type_info, + GITransfer transfer, + GIArgument *arg) +{ + cairo_rectangle_int_t *rect; + + rect = ( (PycairoRectangleInt *) value)->rectangle_int; + if (!rect) { + PyErr_SetString (PyExc_ValueError, "RectangleInt instance wrapping a NULL pointer"); + return NULL; + } + + if (transfer == GI_TRANSFER_EVERYTHING) { + unsigned int size = sizeof(cairo_rectangle_int_t); + cairo_rectangle_int_t *transfer = malloc(size); + if (!transfer) { + PyErr_NoMemory(); + return NULL; + } + + memcpy(transfer, rect, size); + rect = transfer; + } + + arg->v_pointer = rect; + Py_RETURN_NONE; +} + +PyObject * +cairo_rectangle_int_from_arg (GITypeInfo *type_info, GIArgument *arg) +{ + cairo_rectangle_int_t *rect = (cairo_rectangle_int_t*) arg; + + if (rect) + return PycairoRectangleInt_FromRectangleInt (rect); + else { + cairo_rectangle_int_t temp = {}; + return PycairoRectangleInt_FromRectangleInt (&temp); + } +} + +PyObject * +cairo_rectangle_int_release (GIBaseInfo *base_info, + gpointer struct_) +{ + g_free (struct_); + Py_RETURN_NONE; +} +#endif static PyMethodDef _gi_cairo_functions[] = {}; PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo") @@ -130,5 +183,14 @@ PYGLIB_MODULE_START(_gi_cairo, "_gi_cairo") cairo_surface_to_arg, cairo_surface_from_arg, cairo_surface_release); + +#ifdef PycairoRectangleInt_FromRectangleInt + pygi_register_foreign_struct ("cairo", + "RectangleInt", + cairo_rectangle_int_to_arg, + cairo_rectangle_int_from_arg, + cairo_rectangle_int_release); +#endif + } PYGLIB_MODULE_END; |