[cairo] Issue with Font_Face reference count?

Anne et Damien Carbonne aetdcarbonne at free.fr
Mon Dec 15 14:39:50 PST 2008


Vladimir Vukicevic a écrit :
> On 12/14/08 11:09 AM, Anne et Damien Carbonne wrote:
>> Thanks for rapid answer.
>>
>> Why is this function called that way (_debug_)? Compliance with previous
>> versions?
>> If it is only intended for debug purpose, then it means that the
>> solution I have used for the binding is wrong :-(
>> I attach only one Ada wrapper object for each C object. The Ada wrapper
>> is destroyed when the C object is destroyed.
>
> Hm, what do you mean when the C object is destroyed?  The typical way 
> to do bindings is to store a pointer to your native object using 
> user_data on the surface/font_face/whatever, and use the user_data 
> destructor to clean up your wrapper object.  Doing that should avoid 
> any problems when refs are kept to the C object outside of your 
> binding's knowledge.  The only complexity arises from then needing to 
> do refcounting on your wrapper object as well, to know when to release 
> the final cairo ref.
>
>     - Vlad
>
I meant what you explained!
I store a pointer to the Ada wrapper (as well as a destroy function) on 
the cairo side (C object), using user data.
When ref count (on the cairo C side) is back to 0, cairo calls the 
attached destroy function that frees the attached Ada wrapper.
Except in the case I "discovered" (ref count nevers go back to 0, even 
if application has called all necessaruy destroy functions, unless 
cairo_debug_reset_static_data is called).
But this is expected, as explained by Chris Wilson.
Do you mean that I must implement my own ref counting on the Ada side, 
in addition to the one implemented by cairo itself?
This is indeed a solution to avoid usage of 
cairo_debug_reset_static_data. I'm not sure it is worth.
It is perfectly possible to accept that certain objects are not 
destroyed at the end of main program by application itself (most OS 
should do the job anyway). One only needs to know this, in order to do 
the right thing, if necessary.

Damien





More information about the cairo mailing list