[Cairo] another set of Python bindings
james at daa.com.au
Thu Sep 11 18:26:50 PDT 2003
On 12/09/03 00:20, Carl Worth wrote:
>I'm afraid I didn't understand your comment here. Is the deficiency
>here in Cairo itself or in the pycairo bindings? If there's something
>that Cairo could do differently that would make your job easier,
>please let me know.
I'll try and explain the issue again:
For languages like Python where garbage collection is available, it is
nice to hide the details of memory management from the user. I do this
by making the wrapper for the cairo_t object own the reference. When
Python calls the destructor for the wrapper, my code calls
cairo_destroy() on the cairo_t. This works fairly well in isolation.
On gtk-devel-list, Owen posted some information about how he might
integrate Cairo with GTK:
>There are no definite plans currently, but hope is to use the Cairo
>API natively. That is, you'd have something like:
> void my_widget_expose (GtkWidget *widget, GdkEventExpose *expose)
> cairo_t context = gdk_drawable_get_cairo (widget->window);
> /* draw with cairo commands */
If I were to wrap this hypothetical gdk_drawable_get_cairo() routine for
PyGTK, how would I handle the returned cairo_t? The cairo_t object
would belong to the GdkDrawable in this bit of code, so it would be
wrong for the Python wrapper to destroy it.
One option is to copy the object, but this has the disadvantage that
Python code wouldn't be able to modify the state of the cairo_t
belonging to the GdkDrawable (in this particular case, this wouldn't be
a problem, but I can think of other cases where it would be).
By exposing reference counting operations on cairo_t objects, this
particular case would be easy to handle, so that neither the Python code
or C code destroy the cairo_t object until both are finished with it.
A similar argument goes for surfaces. I didn't consider matrices to be
a problem because it seems sensible to treat them as plain values as far
as the Cairo API is concerned.
Email: james at daa.com.au
More information about the cairo