alien: a test and docs for free-callback
parent
e00798cd2a
commit
8fb317b721
|
@ -60,6 +60,13 @@ $nl
|
||||||
|
|
||||||
{ <alien> <displaced-alien> alien-address } related-words
|
{ <alien> <displaced-alien> alien-address } related-words
|
||||||
|
|
||||||
|
HELP: free-callback
|
||||||
|
{ $values { "alien" alien } }
|
||||||
|
{ $description "Releases the callback heap memory allocated for an alien callback. " }
|
||||||
|
{ $warning "If the callback is invoked (either from C or Factor) after it has been freed, then Factor may crash." } ;
|
||||||
|
|
||||||
|
{ <callback> free-callback } related-words
|
||||||
|
|
||||||
HELP: alien-address
|
HELP: alien-address
|
||||||
{ $values { "c-ptr" c-ptr } { "addr" "a non-negative integer" } }
|
{ $values { "c-ptr" c-ptr } { "addr" "a non-negative integer" } }
|
||||||
{ $description "Outputs the address of an alien." }
|
{ $description "Outputs the address of an alien." }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: accessors alien alien.accessors alien.syntax byte-arrays arrays
|
USING: accessors alien alien.accessors alien.c-types alien.libraries
|
||||||
kernel kernel.private namespaces tools.test sequences libc math
|
alien.syntax arrays byte-arrays continuations fry kernel kernel.private layouts
|
||||||
system prettyprint layouts alien.libraries sets ;
|
libc math namespaces prettyprint sequences sets system tools.test ;
|
||||||
FROM: namespaces => set ;
|
FROM: namespaces => set ;
|
||||||
IN: alien.tests
|
IN: alien.tests
|
||||||
|
|
||||||
|
@ -85,3 +85,17 @@ f initialize-test set-global
|
||||||
[ 7575 ] [ initialize-test [ 7575 ] initialize-alien ] unit-test
|
[ 7575 ] [ initialize-test [ 7575 ] initialize-alien ] unit-test
|
||||||
|
|
||||||
[ { BAD-ALIEN } ] [ { BAD-ALIEN BAD-ALIEN BAD-ALIEN } members ] unit-test
|
[ { BAD-ALIEN } ] [ { BAD-ALIEN BAD-ALIEN BAD-ALIEN } members ] unit-test
|
||||||
|
|
||||||
|
! Generate callbacks until the whole callback-heap is full, then free
|
||||||
|
! them. Do it ten times in a row for good measure.
|
||||||
|
: produce-until-error ( quot -- error seq )
|
||||||
|
'[ [ @ t ] [ f ] recover ] [ ] produce ; inline
|
||||||
|
|
||||||
|
SYMBOL: foo
|
||||||
|
|
||||||
|
: fill-and-free-callback-heap ( -- )
|
||||||
|
[ \ foo 33 <callback> ] produce-until-error nip [ free-callback ] each ;
|
||||||
|
|
||||||
|
[ ] [
|
||||||
|
10 [ fill-and-free-callback-heap ] times
|
||||||
|
] unit-test
|
||||||
|
|
Loading…
Reference in New Issue