Skip to content

Commit 77fa8cc

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Avoid use of late initialization for vm:shared fields.
Fixes #60687 TEST=tsan Change-Id: Ibe414f682396f7ffaa19c0f7c902c945ef4c0fab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427681 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent f2d4ca7 commit 77fa8cc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

sdk/lib/_internal/vm/lib/ffi_patch.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,15 +1924,22 @@ class Native<T> {
19241924
_get_ffi_native_resolver<T extends NativeFunction>();
19251925

19261926
// Resolver for FFI Native C function pointers.
1927+
//
1928+
// TODO(dartbug.com/60699): Once the referenced issue is fixed, this can be
1929+
// restored back to use of a field with initializer.
19271930
@pragma('vm:entry-point')
19281931
@pragma('vm:shared')
1929-
static final _ffi_resolver =
1930-
_get_ffi_native_resolver<
1931-
NativeFunction<IntPtr Function(Handle, Handle, IntPtr)>
1932-
>()
1933-
.asFunction<int Function(Object, Object, int)>();
1932+
static int Function(Object, Object, int)? _ffi_resolver = null;
19341933

19351934
@pragma('vm:entry-point')
1936-
static int _ffi_resolver_function(Object a, Object s, int n) =>
1937-
_ffi_resolver(a, s, n);
1935+
static int _ffi_resolver_function(Object a, Object s, int n) {
1936+
if (_ffi_resolver == null) {
1937+
_ffi_resolver =
1938+
_get_ffi_native_resolver<
1939+
NativeFunction<IntPtr Function(Handle, Handle, IntPtr)>
1940+
>()
1941+
.asFunction<int Function(Object, Object, int)>();
1942+
}
1943+
return _ffi_resolver!(a, s, n);
1944+
}
19381945
}

0 commit comments

Comments
 (0)