samadhiweb

smalltalk programming for the web



« Previous  |  Next »

DemoFFI - Garbage Collection

12 March 2016

I've pushed an update to libffidemo, adding the class DemoFFIAutoThing and tests.

DemoFFIAutoThing sends #autoRelease to its handle when said handle is filled by libffidemo with a proper pointer. To support auto-release, DemoFFIExternalObject implements the following class-side method:

finalizeResourceData: resourceData
    DemoFFILibrary uniqueInstance
        ffiCall: #(int free_thing (ExternalAddress resourceData))

Note the C function signature, which is different from DemoFFILibrary>>apiFree:'s:

apiFree: handle
    "int free_thing(demo_thing*)"
    ^ self ffiCall: #(int free_thing (DemoFFIExternalObject handle))

DemoFFIAutoThing>>letGo becomes a no-op. Making it send "super letGo", which effectively calls DemoFFILibrary>>apiFree:, crashes the VM.

Blog comments powered by Disqus