[cairo] cairo_current_xxx, reference or not?

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Fri Nov 5 08:23:05 PST 2004


Qui, 2004-11-04 às 14:14 -0500, Carl Worth escreveu:
> On Thu, 4 Nov 2004 10:55:58 -0800, Ned Konz wrote:
> > On Thursday 04 November 2004 9:52 am, David Reveman wrote:
> > > With the recent font changes, cairo_current_font returns a cairo_font_t
> > > object that needs to be destroyed. This is different from before and
> > > different from what cairo_current_pattern and
> > > cairo_current_target_surface are doing. If this is the intended
> > > behavior, cairo_current_pattern and cairo_current_target_surface should
> > > probably be modified to return a references instead of just pointers.
> > > It's a bit confusing right now.
> 
> Yes, thanks for bringing this up. I'd been sitting on the cairo_matrix_t
> thread for a couple of months, intending to bring up this same point
> about unifying the semantics across the board. You know helped push me
> into finally replying to that thread.
> 
> > I'd be in favor of having a simple rule: whenever there's a function that 
> > *returns* a pointer to a managed (reference-counted) type, you *always* have 
> > to destroy it.
> 
> Either always or never--there are arguments for both sides, and I don't know which side I come down on just yet.

  IMHO, it has to be "always".  Say you have a function returning a new
object, which the function doesn't need (it is created specifically for
the caller).  If you return a shared reference, when is the owner of the
initial reference going to unref? Next call to the same function?  That
would mean storing a pointer somewhere, like in a static variable.  What
if the function doesn't get called again soon?  Surely you can see this
path leads to confusion...

  Best regards.

> 
> But, yes, I do want a single, simple rule. A C API is just too hard to
> use correctly otherwise.
> 
> -Carl
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo
-- 
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3086 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041105/8b2e494a/smime.bin


More information about the cairo mailing list