Closed mezoni closed 9 years ago
Thanks, was trying to figure that out :)
On Wednesday, March 18, 2015, mezoni notifications@github.com wrote:
Don't use directly "unsafe_exetension" use "binary_types" instead. This is harmful to use volatile package "unsafe extension". It does not intended for direct use and never be as such.
Example how to correctly use "binary_types":
static int getErrorNumber() { return Unsafe.readIntPtr(0, libc.symbol("errno")); }
// Only for speed upstatic final INT_T = types["int"]; static int getErrorNumber() { return INT_T.extern(dl.symbol("errno")).value; }
Yes, "binary_types" are slower than "unsafe_exetension" but not so much and they are intended for such usage.
P.S. Possible in the future an "unsafe_exetension" will be unavailable but "binary_types" will remain. Also "binary_types" are type safe (as far as possible).
— Reply to this email directly or view it on GitHub https://github.com/DirectMyFile/coreutils/issues/1.
Another way.
// Somewhere
BinaryData errno = types["int"].extern(dl.symbol("errno"));
int getErrorNumber() {
return errno.value;
}
Ahh nice :)
Don't use directly "unsafe_exetension" use "binary_types" instead. This is harmful to use volatile package "unsafe extension". It does not intended for direct use and never be as such.
Example how to correctly use "binary_types":
Yes, "binary_types" are slower than "unsafe_exetension" but not so much and they are intended for such usage.
P.S. Possible in the future an "unsafe_exetension" will be unavailable but "binary_types" will remain. Also "binary_types" are type safe (as far as possible).