1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.handles alien.syntax
4 destructors kernel math tools.test ;
5 IN: alien.handles.tests
7 TUPLE: thingy { x integer } ;
10 CALLBACK: int thingy-callback ( uint thingy-handle )
11 CALLBACK: int thingy-ptr-callback ( void* thingy-handle )
13 : test-thingy-callback ( -- alien )
14 [ alien-handle> x>> 1 + ] thingy-callback ;
16 : test-thingy-ptr-callback ( -- alien )
17 [ alien-handle-ptr> x>> 1 + ] thingy-ptr-callback ;
19 : invoke-test-thingy-callback ( thingy -- n )
20 test-thingy-callback int { uint } cdecl alien-indirect ;
21 : invoke-test-thingy-ptr-callback ( thingy -- n )
22 test-thingy-ptr-callback int { void* } cdecl alien-indirect ;
25 [ 5 <thingy> <alien-handle> &release-alien-handle [ alien-handle? ] keep ] with-destructors
30 [ 5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr [ alien-handle-ptr? ] keep ] with-destructors
36 5 <thingy> <alien-handle> &release-alien-handle
37 invoke-test-thingy-callback
43 5 <thingy> <alien-handle-ptr> &release-alien-handle-ptr
44 invoke-test-thingy-ptr-callback