Skip to content
Closed

ignore #10232

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb7cac6
methods, basic types, sync, nullable-sync, async, and classes
tarrinneal Apr 15, 2025
9fa695d
broken nullable async methods
tarrinneal Apr 15, 2025
0aff0fd
refactor type logic, add codec
tarrinneal Apr 17, 2025
1ed8a8b
objects and enums
tarrinneal Apr 22, 2025
ee50607
full codec
tarrinneal May 9, 2025
4c6eb1a
error handling and more tests
tarrinneal May 29, 2025
f87efd4
fix codec
tarrinneal May 29, 2025
3e9d9f0
flutter api and plumbing through legacy apis and tests
tarrinneal Jun 27, 2025
6ad2e37
jnigen.yaml
tarrinneal Jun 27, 2025
9b55d44
ffi just getting started
tarrinneal Jul 7, 2025
25e8c30
gen fluff
tarrinneal Jul 11, 2025
df40332
not working
tarrinneal Jul 16, 2025
d90ecca
missing files
tarrinneal Jul 17, 2025
92933f8
gitignore
tarrinneal Jul 17, 2025
cb1c0fe
ios ffigen settings
tarrinneal Jul 17, 2025
a7cc7ce
remove macos min version from ffigen config
tarrinneal Jul 17, 2025
8fb8dca
no dylibs
tarrinneal Jul 17, 2025
ab64302
more basic, still can't see class
tarrinneal Jul 17, 2025
c7d00c6
upload macos
tarrinneal Jul 17, 2025
33f8fa1
fix ffigen files
tarrinneal Jul 17, 2025
4977cc2
test
tarrinneal Jul 29, 2025
586edf2
wip
tarrinneal Jul 29, 2025
74b1cb1
Merge branch 'Frillback' of github.com:tarrinneal/packages into Frill…
tarrinneal Jul 29, 2025
3736528
ns
tarrinneal Jul 29, 2025
31d182f
dunno
tarrinneal Jul 30, 2025
c63e598
something
tarrinneal Jul 30, 2025
6dc23e7
working again
tarrinneal Jul 30, 2025
982dfe6
Merge branch 'Frillback' of https://github.com/tarrinneal/packages in…
tarrinneal Jul 30, 2025
ecc088a
enums
tarrinneal Aug 12, 2025
927fd8d
and this one
tarrinneal Aug 12, 2025
877d60d
ffi support for classes, enums, and objects (partial testing)
tarrinneal Aug 26, 2025
910ac95
tests
tarrinneal Aug 26, 2025
b522d6c
fix enums, still need to resolve Any?
tarrinneal Sep 4, 2025
bd47b34
actually fix enums
tarrinneal Sep 5, 2025
4192a89
starting nullables, gonna be a mess
tarrinneal Sep 5, 2025
86e6907
nullable base types in classes
tarrinneal Sep 17, 2025
87f4f8a
add nullable enums (no tests for null things though.....)
tarrinneal Sep 18, 2025
ed3eb93
update to latest version
tarrinneal Sep 19, 2025
457edef
Not even I understand
tarrinneal Sep 24, 2025
9214479
fix null object?
tarrinneal Sep 25, 2025
aadd859
multi-arity and nullable enums in classes
tarrinneal Sep 26, 2025
8cb24b6
nested classes
tarrinneal Sep 27, 2025
d29e86a
typed lists and maps except int keys
tarrinneal Oct 14, 2025
b32d506
Merge branch 'main' of https://github.com/flutter/packages into Frill…
tarrinneal Oct 15, 2025
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
Prev Previous commit
Next Next commit
Not even I understand
  • Loading branch information
tarrinneal committed Sep 24, 2025
commit 457edef012bf420e9db029cb0fac87fc988972fe
41 changes: 24 additions & 17 deletions packages/pigeon/lib/src/dart/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class _FfiType {
// case 'Float64List':
// return 'NSDoubleArray';
case 'Object':
return 'ObjCObjectBase';
return 'NSObject';
case 'List':
return 'NSMutableArray';
case 'Map':
Expand Down Expand Up @@ -325,7 +325,7 @@ class _FfiType {
type.baseName == 'bool')) {
return name;
}
return '_PigeonFfiCodec.writeValue<${ffiType.ffiName}${_getNullableSymbol(type.isNullable)}>($name)';
return '_PigeonFfiCodec.writeValue<${ffiType.ffiName}${_getNullableSymbol(type.isNullable && type.baseName != 'Object')}>($name)';
}

String getFfiCallReturnType(bool forceUnwrap, {bool forceNullable = false}) {
Expand All @@ -335,6 +335,9 @@ class _FfiType {
if (type.baseName == 'List') {
return 'NSArray?';
}
if (type.baseName == 'Object' && !type.isNullable) {
return 'ObjCObjectBase?';
}
return '$ffiName${_getNullableSymbol(forceNullable || type.isNullable)}';
}

Expand Down Expand Up @@ -1726,7 +1729,7 @@ class DartGenerator extends StructuredGenerator<InternalDartOptions> {
indent.writeln(
'final ffi_bridge.${generatorOptions.ffiErrorClassName} error = ffi_bridge.${generatorOptions.ffiErrorClassName}();');
indent.writeln(
'$methodCallReturnString${method.isAsynchronous ? 'await ' : ''}_ffiApi.${method.name}${method.parameters.isNotEmpty ? 'With${toUpperCamelCase(method.parameters.first.name)}' : 'WithWrappedError'}(${_getFfiMethodCallArguments(method.parameters)}${method.parameters.isEmpty ? '' : ', wrappedError: '}error);',
'$methodCallReturnString${method.isAsynchronous ? 'await ' : ''}_ffiApi.${method.name}${method.parameters.isNotEmpty ? 'With${toUpperCamelCase(method.parameters.first.name)}' : 'WithWrappedError'}(${_getFfiMethodCallArguments(method.parameters)}${method.parameters.isEmpty ? '' : ', wrappedError: '}error)${returnType.type.baseName == 'Object' && returnType.type.isNullable ? ' as NSObject?' : ''};',
);
indent.writeScoped('if (error.code != null) {', '}', () {
indent.writeln(
Expand Down Expand Up @@ -2384,7 +2387,7 @@ ${api.name}({
}
if (generatorOptions.useFfi) {
_writeFfiCodec(indent, root);
_writeConvertNSNumberWrapper(indent, root);
_writeConvertNumberWrapper(indent, root);
}

indent.writeln('bool isType<T>(Type t) => T == t;');
Expand Down Expand Up @@ -2627,11 +2630,11 @@ class _PigeonJniCodec {
''');
}

void _writeConvertNSNumberWrapper(Indent indent, Root root) {
void _writeConvertNumberWrapper(Indent indent, Root root) {
indent.newln();
int typeNum = 4;
indent.format('''
Object? convertNSNumberWrapperToDart(ffi_bridge.NSNumberWrapper value) {
Object? convertNumberWrapperToDart(ffi_bridge.NumberWrapper value) {
switch (value.type) {
case 1:
return value.number.longValue;
Expand All @@ -2654,18 +2657,18 @@ class _PigeonJniCodec {
''');
typeNum = 4;
indent.format('''
ffi_bridge.NSNumberWrapper convertNSNumberWrapperToFfi(Object value) {
ffi_bridge.NumberWrapper convertNumberWrapperToFfi(Object value) {
switch (value) {
case int _:
return ffi_bridge.NSNumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithLong(value), type: 1);
return ffi_bridge.NumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithLong(value), type: 1);
case double _:
return ffi_bridge.NSNumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithDouble(value), type: 2);
return ffi_bridge.NumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithDouble(value), type: 2);
case bool _:
return ffi_bridge.NSNumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithLong(value ? 1 : 0), type: 3);''');
return ffi_bridge.NumberWrapper.alloc().initWithNumber(NSNumber.alloc().initWithLong(value ? 1 : 0), type: 3);''');
for (final Enum anEnum in root.enums) {
indent.format('''
case ${anEnum.name} _:
return ffi_bridge.NSNumberWrapper.alloc().initWithNumber(value.toNSNumber(), type: ${typeNum++});''');
return ffi_bridge.NumberWrapper.alloc().initWithNumber(value.toNSNumber(), type: ${typeNum++});''');
}
indent.format('''
default:
Expand All @@ -2680,7 +2683,7 @@ class _PigeonJniCodec {
indent.format('''
class _PigeonFfiCodec {
static Object? readValue(ObjCObjectBase? value, [Type? outType]) {
if (value == null) {
if (value == null || ffi_bridge.PigeonInternalNull.isInstance(value)) {
return null;
} else if (NSNumber.isInstance(value)) {
value as NSNumber;
Expand Down Expand Up @@ -2735,8 +2738,8 @@ case const (${enumDefinition.name}):
res[readValue(entry.key)] = readValue(entry.value);
}
return res;
} else if (ffi_bridge.NSNumberWrapper.isInstance(value)) {
return convertNSNumberWrapperToDart(ffi_bridge.NSNumberWrapper.castFrom(value));
} else if (ffi_bridge.NumberWrapper.isInstance(value)) {
return convertNumberWrapperToDart(ffi_bridge.NumberWrapper.castFrom(value));
${root.classes.map((Class dataClass) {
final _FfiType ffiType = _FfiType.fromClass(dataClass);
return '''
Expand All @@ -2751,10 +2754,14 @@ case const (${enumDefinition.name}):

static T writeValue<T extends ObjCObjectBase?>(Object? value) {
if (value == null) {
final String tString = T.toString();
if (tString.contains('ObjCObjectBase') || tString.contains('NSObject')) {
return ffi_bridge.PigeonInternalNull() as T;
}
return null as T;
} else if (value is bool || value is double || value is int || value is Enum) {
if (T != NSNumber && T.toString() != 'NSNumber?') {
return convertNSNumberWrapperToFfi(value) as T;
return convertNumberWrapperToFfi(value) as T;
}
if (value is bool) {
return NSNumber.alloc().initWithLong(value ? 1 : 0) as T;
Expand All @@ -2768,7 +2775,7 @@ case const (${enumDefinition.name}):
if (value is Enum) {
return NSNumber.alloc().initWithLong(value.index) as T;
}
return convertNSNumberWrapperToFfi(value) as T;
return convertNumberWrapperToFfi(value) as T;
} else if (value is String) {
return NSString(value) as T;
// } else if (isTypeOrNullableType<NSByteArray>(T)) {
Expand Down Expand Up @@ -2808,7 +2815,7 @@ case const (${enumDefinition.name}):
} else if (value is Map) {
final NSMutableDictionary res = NSMutableDictionary();
for (final MapEntry<Object?, Object?> entry in value.entries) {
res.setObject(writeValue(entry.value), forKey: writeValue(entry.key));
NSMutableDictionary\$Methods(res).setObject(writeValue(entry.value), forKey: NSCopying.castFrom(writeValue(entry.key)));
}
return res as T;
${root.classes.map((Class dataClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import 'package:swiftgen/swiftgen.dart';
indent.writeScoped('Future<void> main() async {', '}', () {
indent.writeScoped('final List<String> classes = <String>[', '];', () {
indent.inc();
indent.writeln("'NSNumberWrapper',");
indent.writeln("'PigeonInternalNull',");
indent.writeln("'NumberWrapper',");
for (final Api api in root.apis) {
if (api is AstHostApi || api is AstFlutterApi) {
indent.writeln("'${api.name}',");
Expand Down Expand Up @@ -115,6 +116,9 @@ import 'package:swiftgen/swiftgen.dart';
include: (fg.Declaration decl) =>
classes.contains(decl.originalName) ||
enums.contains(decl.originalName),
module: (fg.Declaration decl) {
return decl.originalName.startsWith('NS') ? null : 'test_plugin';
}
),
),
),
Expand Down
25 changes: 15 additions & 10 deletions packages/pigeon/lib/src/swift/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class SwiftGenerator extends StructuredGenerator<InternalSwiftOptions> {
void _writeFfiCodec(Indent indent, Root root) {
indent.newln();
indent.format('''
@objc class PigeonInternalNull: NSObject {}

@available(iOS 13, macOS 16.0.0, *)
class _PigeonFfiCodec {
static func readValue(value: NSObject?, type: String?) -> Any? {
Expand Down Expand Up @@ -343,8 +345,8 @@ class _PigeonFfiCodec {
}
return res
}
if (value is NSNumberWrapper) {
return unwrapNumber(wrappedNumber: value as! NSNumberWrapper)
if (value is NumberWrapper) {
return unwrapNumber(wrappedNumber: value as! NumberWrapper)
}
if (value is NSString) {
return value as! NSString
Expand All @@ -354,7 +356,7 @@ class _PigeonFfiCodec {

static func writeValue(value: Any?, isObject: Bool = false) -> Any? {
if (isNullish(value)) {
return nil
return PigeonInternalNull()
}
if (value is Bool || value is Double || value is Int${root.enums.map((Enum enumDefinition) {
return ' || value is ${enumDefinition.name}';
Expand Down Expand Up @@ -802,6 +804,8 @@ if (wrapped == nil) {
return '_PigeonFfiCodec.writeValue(value: $varName, isObject: true) as${type.isNullable ? '?' : '!'} [NSObject]';
case 'Map':
return '_PigeonFfiCodec.writeValue(value: $varName, isObject: true) as${type.isNullable ? '?' : '!'} [NSObject: NSObject]';
case 'Object':
return '$varName as! NSObject$nullable';
default:
return varName;
}
Expand Down Expand Up @@ -1697,11 +1701,12 @@ if (wrapped == nil) {
}
}

void _writeIsNullish(Indent indent) {
void _writeIsNullish(Indent indent, {bool useFfi = false}) {
indent.newln();
indent.write('private func isNullish(_ value: Any?) -> Bool ');
indent.addScoped('{', '}', () {
indent.writeln('return value is NSNull || value == nil');
indent.writeln(
'return value is NSNull || value == nil${useFfi ? ' || value is PigeonInternalNull' : ''}');
});
}

Expand Down Expand Up @@ -1767,7 +1772,7 @@ private func nilOrValue<T>(_ value: Any?) -> T? {

void _writeNumberWrapper(Root root, Indent indent) {
indent.newln();
indent.writeScoped('@objc class NSNumberWrapper: NSObject {', '}', () {
indent.writeScoped('@objc class NumberWrapper: NSObject {', '}', () {
indent.writeScoped('@objc init(', ')', () {
indent.writeln('number: NSNumber,');
indent.writeln('type: Int,');
Expand All @@ -1781,13 +1786,13 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
});
indent.newln();
indent.writeScoped(
'private func wrapNumber(number: NSNumber, type: Int) -> NSNumberWrapper {',
'private func wrapNumber(number: NSNumber, type: Int) -> NumberWrapper {',
'}', () {
indent.writeln('return NSNumberWrapper(number: number, type: type)');
indent.writeln('return NumberWrapper(number: number, type: type)');
});
indent.newln();
indent.writeScoped(
'private func unwrapNumber<T>(wrappedNumber: NSNumberWrapper) -> T {',
'private func unwrapNumber<T>(wrappedNumber: NumberWrapper) -> T {',
'}', () {
indent.writeScoped('switch (wrappedNumber.type) {', '}', () {
int caseNum = 4;
Expand Down Expand Up @@ -1863,7 +1868,7 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
_writeNumberWrapper(root, indent);
}

_writeIsNullish(indent);
_writeIsNullish(indent, useFfi: generatorOptions.useFfi);
_writeNilOrValue(indent);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/pigeon/pigeons/ni_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NIAllTypes {
this.anEnum = NIAnEnum.one,
this.anotherEnum = NIAnotherEnum.justInCase,
this.aString = '',
// this.anObject = 0,
this.anObject = 0,

// Lists
// This name is in a different format than the others to ensure that name
Expand Down Expand Up @@ -82,7 +82,7 @@ class NIAllTypes {
NIAnEnum anEnum;
NIAnotherEnum anotherEnum;
String aString;
// Object anObject;
Object anObject;

// Lists
List list;
Expand Down Expand Up @@ -201,7 +201,7 @@ class NIAllNullableTypesWithoutRecursion {
// this.aNullableEnum,
// this.anotherNullableEnum,
this.aNullableString,
// this.aNullableObject,
this.aNullableObject,

// // Lists
// // This name is in a different format than the others to ensure that name
Expand Down Expand Up @@ -237,7 +237,7 @@ class NIAllNullableTypesWithoutRecursion {
// NIAnEnum? aNullableEnum;
// NIAnotherEnum? anotherNullableEnum;
String? aNullableString;
// Object? aNullableObject;
Object? aNullableObject;

// // Lists
List? list;
Expand Down Expand Up @@ -534,10 +534,10 @@ abstract class NIHostIntegrationCoreApi {
// @SwiftFunction('echo(_:)')
// Float64List? echoNullableFloat64List(Float64List? aNullableFloat64List);

// /// Returns the passed in generic Object.
// @ObjCSelector('echoNullableObject:')
/// Returns the passed in generic Object.
@ObjCSelector('echoNullableObject:')
// @SwiftFunction('echo(_:)')
// Object? echoNullableObject(Object? aNullableObject);
Object? echoNullableObject(Object? aNullableObject);

/// Returns the passed list, to test serialization and deserialization.
@ObjCSelector('echoNullableList:')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class _ExampleAppState extends State<ExampleApp> {
// final NIHostIntegrationCoreApiForNativeInterop? api =
// NIHostIntegrationCoreApiForNativeInterop.getInstance();
// api!.noop();
// api.echoAllTypes(genericNIAllTypes);
// api.echoAllNullableTypesWithoutRecursion(
// genericNIAllNullableTypesWithoutRecursion);
} catch (e) {
setState(() {
status = 'Failed: $e';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ final NIAllNullableTypesWithoutRecursion
// aNullable8ByteArray: Int64List.fromList(<int>[7, 8, 9]),
// aNullableFloatArray: Float64List.fromList(<double>[2.71828, doublePi]),
// aNullableEnum: NIAnEnum.fourHundredTwentyTwo,
// aNullableObject: 0,
aNullableObject: 'nullable',
list: list,
// stringList: stringList,
// intList: intList,
Expand Down Expand Up @@ -328,7 +328,7 @@ final NIAllTypes genericNIAllTypes = NIAllTypes(
// a8ByteArray: Int64List.fromList(<int>[7, 8, 9]),
// aFloatArray: Float64List.fromList(<double>[2.71828, doublePi]),
anEnum: NIAnEnum.fortyTwo,
// anObject: 1,
anObject: 'notNullable',
list: nonNullList,
// stringList: nonNullStringList,
// intList: nonNullIntList,
Expand Down
Loading