Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
`Declarations.includeMemberSet`, `Declarations.useOriginalName`,
`Declarations.renameWithMap`, `Declarations.useMemberOriginalName`, and
`Declarations.renameMemberWithMap`.
- Fix [a bug](https://github.com/dart-lang/native/issues/2760) in the internal
variables generated by function bindings.

## 20.0.0

Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffigen/lib/src/code_generator/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Func extends LookUpBinding with HasLocalScope {
functionType.getFfiDartType(context, writeArgumentNames: false);
final needsWrapper = !functionType.sameDartAndFfiDartType && !isInternal;

final funcVarName = localScope.addPrivate('_$name');
final funcVarName = context.rootScope.addPrivate('_$name');
final ffiReturnType = functionType.returnType.getFfiDartType(context);
final ffiArgDeclString = functionType.dartTypeParameters
.map((p) => '${p.type.getFfiDartType(context)} ${p.name},\n')
Expand Down Expand Up @@ -182,7 +182,7 @@ $dartReturnType $enclosingFuncName($dartArgDeclString) => $funcImplCall;
);
}
} else {
final funcPointerName = localScope.addPrivate('_${name}Ptr');
final funcPointerName = context.rootScope.addPrivate('_${name}Ptr');
final isLeafString = isLeaf ? 'isLeaf:true' : '';

// Write enclosing function.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffigen/test/native_objc_test/method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void main() {
'objc_test.dylib',
),
);
// verifySetupFile(dylib);
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
testInstance = MethodInterface();
// generateBindingsForCoverage('method');
generateBindingsForCoverage('method');
});

group('Instance methods', () {
Expand Down
2 changes: 2 additions & 0 deletions pkgs/ffigen/test/native_objc_test/static_func_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ output: 'static_func_bindings.dart'
exclude-all-by-default: true
functions:
include:
- foo
- fooPtr
- staticFuncOfObject
- staticFuncOfNullableObject
- staticFuncOfBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ exclude-all-by-default: true
ffi-native:
functions:
include:
- foo
- fooPtr
- staticFuncOfObject
- staticFuncOfNullableObject
- staticFuncOfBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,11 @@ void main() {
expect(counter.value, 0);
calloc.free(counter);
}, skip: !canDoGC);

test('Internal variable conflict resolution', () {
// Regression test for https://github.com/dart-lang/native/issues/2760
expect(foo(123), 1230);
expect(fooPtr(123), 12300);
});
});
}
6 changes: 6 additions & 0 deletions pkgs/ffigen/test/native_objc_test/static_func_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,11 @@ void main() {
expect(counter.value, 0);
calloc.free(counter);
}, skip: !canDoGC);

test('Internal variable conflict resolution', () {
// Regression test for https://github.com/dart-lang/native/issues/2760
expect(lib.foo(123), 1230);
expect(lib.fooPtr(123), 12300);
});
});
}
3 changes: 3 additions & 0 deletions pkgs/ffigen/test/native_objc_test/static_func_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ - (void)dealloc {
if (counter != nil) --*counter;
}
@end

int foo(int x) { return 10 * x; }
int fooPtr(int x) { return 100 * x; }