sdk
sdk copied to clipboard
[analyzer/ffi] Analyzer reporting false positives for NativeFieldWrapperClass1
trafficstars
The analyzer reports an error on the following two cases.
/// Subtracts 2 integers.
@ffi.FfiNative<ffi.Int Function(ffi.Pointer<ffi.Int>, ffi.Int)>('subtract')
external int subtract(
ffi.Pointer<ffi.Int> a,
int b,
);
/// Divides 2 floats, returns a pointer to double.
@ffi.FfiNative<
ffi.Pointer<ffi.Double> Function(
ffi.Pointer<ffi.Float>, ffi.Pointer<ffi.Float>)>('dividePrecision')
external ffi.Pointer<ffi.Double> dividePrecision(
ffi.Pointer<ffi.Float> a,
ffi.Pointer<ffi.Float> b,
);
- Only classes extending NativeFieldWrapperClass1 can be passed as Pointer. Pass as Handle instead.
This is a bit too zealous. These are not implicitly passing this, they have the same amount of Dart parameters as C types and are top level functions.
Discovered in https://github.com/dart-lang/ffigen/pull/447.
This is causing the CI of ffigen to go red: https://github.com/dart-lang/ffigen/actions/runs/3029924189/jobs/4875652903
Also:
@FfiNative<Void Function(Pointer)>('free')
external void posixFree(Pointer pointer);
@FfiNative<Void Function(Pointer)>('CoTaskMemFree')
external void winCoTaskMemFree(Pointer pv);