Hi everybody. In the latest repo sources, I've changed the FFI so that pointers
to struct types now automatically present themselves as Factor struct objects.
So where you used to need to do things like this:
---
FUNCTION: foo* return_struct_pointer ( ) ;
return_struct_pointer foo memory>struct
CALLBACK: void struct_pointer_callback ( foo* arg ) ;
: my-callback ( -- alien ) [ foo memory>struct frob ] struct_pointer_callback ;
STRUCT: pointing_struct { x foo* } ;
pointing_struct <struct> x>> foo memory>struct
---
You can now drop the "foo memory>struct" bit; the FFI does that for you now. In
fact, it will raise a "bad store to specialized slot" error if you try to do it
again—I've updated the code in the repository, but your private code might need
updating if it makes heavy use of the FFI or struct types. If the pointer value
being boxed is a null pointer, it will be left as f. In cases where the pointer
really references an array, you can still use <direct-foo-array> to transform
the struct object into an array object over the same memory. Currently, C types
of higher levels of indirection (for example, foo**, foo[10]*, foo*[10], etc.)
and pointers to primitive types still get treated as generic pointers, and you
need to manually wrap the alien objects in struct or array objects to make use
of them.
To make this happen, C types for pointers no longer parse as separate words
from the pointed-to type; they instead construct a "pointer" tuple to represent
the type. As a side effect of this, using "TYPEDEF: void* bar*" to define an
opaque pointer type "bar*" no longer works; you now have to use "C-TYPE: bar".
Note that you can still make typedefs to pointer types, as in "TYPEDEF: void*
BarRef"; you just can't define a pointer type directly as a typedef. In
contexts where a C type is expected, such as TYPEDEF:, FUNCTION:, CALLBACK:,
and STRUCT:, "bar*" will parse to a pointer type as it always has. To reference
pointer types in normal Factor, such as if you're making a naked call to
alien-invoke or alien-indirect, you can use the "pointer:" syntax word to
construct a pointer C type:
---
FUNCTION: void wut ( foo* x ) ;
: wut ( x -- ) void "wutlib" "wut" { pointer: foo } alien-invoke ;
---
-Joe
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk