[clean-list] Finalizer
John van Groningen
johnvg at cs.ru.nl
Wed Jul 30 14:08:25 MEST 2008
Shivkumar Chandrasekaran wrote:
>Is there a way (even ABC code) to call a finalizer for an object that is about to be garbage collected in Clean?
The function make_finalizer defined in the module below creates an object in
the heap containing the address of a c function and an argument for this
function. If the object becomes garbage during a garbage collection,
the c function will be called with this argument at the end of the garbage
collection. This c function cannot call back to Clean.
Kind regards,
John van Groningen
definition module finalizer;
make_finalizer :: !Int /*address of c function*/ !Int /*argument of c function*/ -> Finalizer;
:: Finalizer = {finalizer_implementation::!FinalizerT};
:: FinalizerT;
implementation module finalizer;
:: Finalizer = {finalizer_implementation::!FinalizerT};
:: FinalizerT = DummyFinalizer !Int !Int !Int;
make_finalizer :: !Int !Int -> Finalizer;
make_finalizer f v
# (finalizer,_) = make_finalizer_c f v;
= {finalizer_implementation=finalizer};
make_finalizer_c :: !Int !Int -> (!FinalizerT,!Int);
make_finalizer_c f v = code {
push_finalizers
push_a_b 0
pop_a 1
build_r e__system_kFinalizer 0 3 0 0
pop_b 3
set_finalizers
pushI 0
};
More information about the clean-list
mailing list