[cairo] Re: cairo_get_current_point bug ?

Behdad Esfahbod behdad at behdad.org
Fri Sep 22 13:43:37 PDT 2006

On Fri, 2006-09-22 at 15:49 -0400, Carl Worth wrote:
> On Thu, 14 Sep 2006 16:59:11 -0700, "Mike Emmel" wrote:
> > -void
> > +cairo_status_t
> >  cairo_get_current_point (cairo_t *cr, double *x_ret, double *y_ret)
> Behdad just mentioned that it's too late to do this. From an API
> point-of-view, there would obviously be no problem, but presumably
> changing the stack like that would not allow us to provide the ABI
> compatibility we've promised.

Like Jamey pointed already, it most probably is not an ABI problem on
any platform that cairo has been compiled on so far.  However, it
definitely is an API change.  One that may not break any code though.
It will cause warnings for example if someone is using the function in
question as an rvalue without casting.  Or if for any reason they are
prototyping it again (will error).  Both are rare situations.

I agree that we really should keep our API/ABI interface very strict.
But if we figure it will not break /any/ current code, I think we should
take advantage of it.  Changing API in this way allows making
cairo_device_to_user* return an error too.

Of particular importance here are language bindings.  Most probably they
can't handle this change in a clean way.  For example, what is the
python binding going to do with this change?  Throw an exception if no
current point is set?  That will surprise current users.

> > @@ -2674,13 +2674,14 @@ cairo_get_current_point (cairo_t *cr, do
> >      } else {
> >  	x = _cairo_fixed_to_double (x_fixed);
> >  	y = _cairo_fixed_to_double (y_fixed);
> > -	_cairo_gstate_backend_to_user (cr->gstate, &x, &y);
> >      }
> > +	_cairo_gstate_backend_to_user (cr->gstate, &x, &y);
> As for this, is there any reason that the device-space origin is more
> reasonable than the user-space origin as a value for get_current_point
> when there is no path? Does cairo ever treat a no-current-path
> situation as equivalent to the current point being at the device-space
> origin?

Mike has a point.  We really want to keep the invariant that:

  cairo_get_current_point (cr, &x0, &y0);
  cairo_translate (cr, x1, y1);
  cairo_get_current_point (cr, &x2, &y2);
  assert (x0 == x1 + x2 && y0 == y1 + y2);

> It seems pretty arbitrary to me either way.
> So what are good options for fixing the current bug?
> Do we want:
> 	cairo_bool_t
> 	cairo_has_current_point (cairo_t *cr);
> Or maybe:
> 	cairo_bool_t
> 	cairo_has_path (cairo_t *cr);
> Or maybe both? (They are not equivalent functions since
> cairo_new_sub_path will cause there to be no current point even when
> there is a non-empty path.)

Both I guess.

> Other ideas?
> -Carl


"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
        -- Dan Bern, "New American Language"

More information about the cairo mailing list