On 26 Apr 2018, at 12:09, Serge Stinckwich <serge.stinckwich@gmail.com> wrote:



On Wed, Apr 25, 2018 at 11:07 PM, Ben Coman <btc@openinworld.com> wrote:


On 25 April 2018 at 23:08, Serge Stinckwich <serge.stinckwich@gmail.com> wrote:
I don't understand the default 

finalizeResourceData: handle
    handle isNull ifTrue: [ ^ self ].
    handle free.
    handle beNull


when handle is an ExternaData, free is defined as in ExternalStructure class as: 

free
    "Free the handle pointed to by the receiver"
    (handle ~~ nil and:[handle isExternalAddress]) ifTrue:[handle free].
    handle := nil. 

Theorectical side thought.   I wonder how threadsafe that code for #free is?
Sending two messages between the ~~nil test and nil-assignment 
seems to leave the door open for another thread to erroneously pass the ~~nil test.

IIUC, with an inlined #ifNotNil, the following might be safer (?)

    free
        "Save handle so its nil assignment is inlined with its #ifNotNil: test, eliminating possible thread change during message sends"
        |savedhandle|
        handle ifNotNil: [
            savedHandle := handle.
            handle := nil.
            savedHandle isExternalAddress ifTrue: [ savedHandle  free].
            ].



���You don't reply to my original question, Ben :-)


I have another concern with UFFI !

When I call ffiCall: and the call returns an Opaque Object, an instance of this Opaque object is created, but apparently,
basicNew is called instead of new on the class. What is the ���
 
���intention behind ?���

basicNew ensures the object is created ���virgin���, since its contents will depend on what comes from outside and not in Pharo. 
you can then call initialize by yourself if needed, as it happens for example in AthensCairoSurface>>extent:format: 

Esteban


���Thank you.���

-- 
Serge Stinckwich
UMI UMMISCO 209 (SU/IRD/UY1)
"Programs must be written for people to read, and only incidentally for machines to execute."
http://www.doesnotunderstand.org/