New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dart:ffi asFunction / lookupFunction static function vs instance method #35903

Open
dcharkes opened this Issue Feb 11, 2019 · 0 comments

Comments

1 participant
@dcharkes
Copy link
Contributor

dcharkes commented Feb 11, 2019

Currently Pointer.asFunction and DynamicLibrary.lookup are instance methods.
However, this enables users to call these dynamically.

Pointer<Int8 Function(Int8)> p = fromAddress(memoryAddress);
dynamic q = p;
int Function(int) f = q.asFunction();
f(123);

Unfortunately we cannot at compile-time discover this, which means that we cannot generate trampolines in AOT mode.

We have two possible solutions:

  1. throw a runtime exception on a dynamic invocation
  2. make these functions static: f = asFunction(q)

The second option is a bit less ergonomic, but safer.

@dcharkes dcharkes added this to To do in Dart VM FFI via automation Feb 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment