testinterpreterplugin and primitive cleaning?
Ned Konz
ned at bike-nomad.com
Sat May 17 02:02:05 UTC 2003
On Friday 16 May 2003 05:24 pm, Ragnar Hojland Espinosa wrote:
> Inside a primitive's C code I have code that uses a library call
> which allocates memory and returns it to the caller. I convert
> that to an oop, to be stored in an object. How do I call the
> library cleanup code when the object is destroyed (GCed if you
> prefer)?
So the library allocates the memory outside of Squeak? How do you
safely convert that to an oop?
Usually with externally allocated structures like these we just stick
the pointer into a ByteArray for later use by the primitive code.
This is what's done with file handles, for instance. See
FilePlugin>>fileValueOf: for this kind of conversion. And
fileOpen:name:size:write:secure: for how you'd allocate a Squeak
ByteArray object to hold such an external pointer.
Andreas has already described how to call a finalizer on the Smalltalk
side. This would then call a primitive that would take the ByteArray
containing the handle and pass it back to the library cleanup
routine.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|