Skip to content

Commit ef36f11

Browse files
Clement Skaucommit-bot@chromium.org
authored andcommitted
[VM] Change internal name for FfiNatives.
Changes the naming format for synthetic variables used for @FfiNatives. The name was based on the native function, but since multiple FfiNatives can reference the same native function, this can result in name clashes. Instead the name is now based on the name of the associated function, which cannot have a name clashing with another function by the same name. TEST=CQ Change-Id: Id829ff3f207ab11e83f3194b8410f4be297623c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206374 Commit-Queue: Clement Skau <[email protected]> Reviewed-by: Tess Strickland <[email protected]>
1 parent ff2be51 commit ef36f11

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/vm/lib/transformations/ffi_native.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ class FfiNativeTransformer extends Transformer {
7272

7373
// Transform:
7474
// @FfiNative<Double Function(Double)>('Math_sqrt')
75-
// external double _sqrt(double x);
75+
// external double _square_root(double x);
7676
//
7777
// Into:
78-
// final _@FfiNative_Math_sqrt =
78+
// final _@FfiNative__square_root =
7979
// Pointer<NativeFunction<Double Function(Double)>>
8080
// .fromAddress(_ffi_resolver('dart:math', 'Math_sqrt'))
8181
// .asFunction<double Function(double)>();
82-
// double _sqrt(double x) => _@FfiNative_Math_sqrt(x);
82+
// double _square_root(double x) => _@FfiNative__square_root(x);
8383
Statement transformFfiNative(
8484
Procedure node, InstanceConstant annotationConst) {
8585
assert(currentLibrary != null);
@@ -119,8 +119,8 @@ class FfiNativeTransformer extends Transformer {
119119
final asFunctionInvocation = StaticInvocation(asFunctionProcedure,
120120
Arguments([fromAddressInvocation], types: [nativeType, dartType]));
121121

122-
// final _@FfiNative_Math_sqrt = ...
123-
final fieldName = Name('_@FfiNative_${functionName.value}', currentLibrary);
122+
// final _@FfiNative__square_root = ...
123+
final fieldName = Name('_@FfiNative_${node.name.text}', currentLibrary);
124124
final funcPtrField = Field.immutable(fieldName,
125125
type: dartType,
126126
initializer: asFunctionInvocation,
@@ -130,7 +130,7 @@ class FfiNativeTransformer extends Transformer {
130130
getterReference: currentLibraryIndex?.lookupGetterReference(fieldName));
131131
currentLibrary!.addField(funcPtrField);
132132

133-
// _@FfiNative_Math_sqrt(x)
133+
// _@FfiNative__square_root(x)
134134
final callFuncPtrInvocation = FunctionInvocation(
135135
FunctionAccessKind.FunctionType,
136136
StaticGet(funcPtrField),
@@ -144,7 +144,7 @@ class FfiNativeTransformer extends Transformer {
144144
visitProcedure(Procedure node) {
145145
// Only transform functions that are external and have FfiNative annotation:
146146
// @FfiNative<Double Function(Double)>('Math_sqrt')
147-
// external double _sqrt(double x);
147+
// external double _square_root(double x);
148148
if (!node.isExternal) {
149149
return node;
150150
}

0 commit comments

Comments
 (0)