[cairo] const-ness fixes for transform_distance and transform_point

Robert O'Callahan rocallahan at novell.com
Mon May 9 15:03:35 PDT 2005


On Mon, 2005-05-09 at 12:43 -0400, Carl Worth wrote:
> Here's a more complete patch that adds const to all appropriate uses
> of cairo_matrix_t in cairo.h and chases the const-correctness down
> through the implementation. And this seems entirely non-controversial,
> so I've just committed it.

Thanks for that.

> With this in place, I think I'd like to change cairo_get_matrix (yes,
> one more time), to return a const pointer to the current matrix. This
> should be about as convenient to use as the matrix-as-value version I
> wanted earlier, but without the efficiency problems. As is, I've found
> situations where one has to do things such as:
> 
> 	cairo_matrix_t ctm;
> 	cairo_get_matrix (cr, &ctm);
> 	cairo_scaled_font_create (face, font_matrix, &ctm);
> 
> where one would prefer to do:
> 
> 	cairo_scaled_font_create (face, font_matrix,
> 				  cairo_get_matrix (cr));
> 
> But it wasn't really feasible to even consider returning a const
> pointer without the current patch for const-correctness.

I'm not entirely comfortable with that. The problem is that although the
matrix is const to the API user, its contents can change over time. So
if you were to write a really good specification for cairo you'd have to
document exactly which cairo API functions can change the matrix.
(Equivalently, you'd have to specify precisely how long the contents of
the matrix remain valid.) But you'd still have the possibility of poorly
written client programs making unjustified assumptions that you later
break. In general I prefer to only return const pointers to things that
are truly immutable.

Rob




More information about the cairo mailing list