[cairo] cairo_matrix_t

Owen Taylor otaylor at redhat.com
Thu Nov 4 11:34:21 PST 2004


On Thu, 2004-11-04 at 13:52 -0500, Carl Worth wrote:

> One general problem with C APIs is that with a function like:
> 
> 	foo_t *bar_get_foo (bar_t *bar);
> 
> It's not obvious whether the caller or the callee is responsible for the
> memory allocation pointed to by the return value. I want to make this
> very obvious in cairo. Preferably, there will be global convention
> across all cairo functions of this type. Less appealing would be a
> naming convention to distinguish the few exceptions.
> 
> So, if we're going to do this, first I want to audit all similar
> functions in cairo to see if we can't get them acting the same way. (See
> the new thread today regarding cairo_current_xxx).
> 
> There's another potential problem with returning pointers to objects
> owned by cairo. If cairo returns a pointer to the live CTM, then the
> user can inadvertently scramble cairo state when a copy really was
> necessary. That's no big deal as its just a user bug (which we can't
> eliminate). Worse though, is the possibility of a user relying on
> modifying cairo state through direct manipulation of the returned
> object. This could lead to behavior that works today and breaks
> tomorrow. For example, we may have internal caches that must be informed
> if the CTM ever changes. Direct manipulation of the CTM through a
> returned object could break that.
> 
> I guess we could address that issue by having cairo return pointers to
> copied objects. That would still allow cairo to maintain the memory, but
> prevent the user from effecting state changes.

Returning pointers to copied objects requires freeing ... not pleasant
for the API standpoint.

'const' is often a useful solution for this problem, especially for
things like matrices that are basically like structures. I did that
for PangoMatrix. It doesn't work everywhere though.

PangoMatrix, GdkColor, etc, are appropriately constified in the API.
But we don't try for, say,  GtkWidget ... would something like 
gtk_widget_get_parent() return a const GtkWidget or a GtkWidget?

Regards,
						Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041104/4e520f9d/attachment.pgp


More information about the cairo mailing list