[cairo] UserFontFace vs FtFontFace management (cairomm)

Anne et Damien Carbonne aetdcarbonne at free.fr
Fri Dec 5 14:20:24 PST 2008


Jonathon Jongsma a écrit :
> Behdad Esfahbod wrote:
>   
>> Ian Britten wrote:
>>
>>     
>>> Nor do I, especially not knowing all the C<->C++ separation issues
>>> you need to maintain between cairo<->cairomm...
>>>       
>>> Anything I would come up with would lean towards trying to store the
>>> actual C++ object in the user-data part of the C object, but I'm
>>> assuming you've been down that road...
>>>       
>> Yes, that's how it's supposed to be done.
>>     
>
> Yes, and I do store a *pointer* to the wrapper object in the user-data part of the C 
> object, but that does not really help me here since that will not keep the wrapper object 
> alive.  It is simply a weak reference -- once the wrapper object is destroyed, the pointer 
> will be dangling, which causes the memory corruption and crash that Ian reported initially.
>
> In the current cairomm implementation, the lifetime of the wrapper object is managed by 
> the smart pointer that it is created with.  When the wrapper object is deleted, the 
> destructor simply calls cairo_font_face_destroy() on the wrapped object.  If I were to 
> store an owning reference to the wrapper inside of the wrapped C object, the wrapper's 
> destructor would never be called, so we'd never _destroy() the underlying font face, and 
> it seems that we'd have circular reference issues.  Or am I missing something? (quite 
> possible, I admit)
>
>   
In the Ada solution I explained in another mail, the "Ada handle" never 
destroys the "Ada object" itself.
The "Ada handle" only calls ref and unref.
It is cairo that calls destroy on the attached user data when the ref 
count is 0.
Then, I destroy the Ada create object(s).
If I'm correct, there is no cycle here.
I think this is applicable to C++: Replace "Ada handle" by "C++ smart 
pointer" and "Ada object" by "C++ wrapper".


More information about the cairo mailing list