[Cairo] Re: Semantics of cairo_copy changed in 0.1.7
Carl Worth
cworth at east.isi.edu
Tue Sep 30 13:15:25 PDT 2003
On Sep 30, Keith Packard wrote:
> I looked at that patch and am confused:
>
> *dest = *src;
> dest->ref_count = 0;
>
> dest->gstate = _cairo_gstate_clone (src->gstate);
Wow. I'm glad someone looked. That was horribly broken. (A bad case of
looking at the old implementation and thinking, "Sure, I can just drop
the call to malloc and then I have exactly what I want".)
Let's try this instead:
if (dest->status)
return;
if (src->status)
dest->status = src->status;
dest->status = _cairo_gstate_copy (dest->gstate, src->gstate);
where _cairo_gstate_copy is a new function that does:
/* Preserve next pointer over fini/init */
next = dest->next;
_cairo_gstate_fini (dest);
status = _cairo_gstate_init_copy (dest, src);
dest->next = next;
Better? At least valgrind is happy with that.
> Is the intent to *push* src->gstate onto the dest gstate stack? Or is the
> intent to *discard* the existing gstate stack and replace it with (a copy
> of) the top of the src gstate stack? It doesn't do either of
> these.
It didn't do either of these, nor did it do what I actually intended.
The intent is to copy the contents of the top of the src stack to the
top of the dest stack. This seems like the operation that will be
commonly desired in practice. Let me know if it needs a better name or
if I botched the implementation yet again.
-Carl
More information about the cairo
mailing list