diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index df0d88a8..134d7dfa 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -19,7 +19,8 @@ jobs: strategy: fail-fast: false matrix: - sdk: [3.0.0] + # TODO: Change to 3.2.0 stable once it's released. + sdk: [3.2.0-114.0.dev] steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f @@ -44,7 +45,7 @@ jobs: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.0.0 + sdk: 3.2.0-114.0.dev - name: Install dependencies run: dart pub get - name: Install libclang-14-dev @@ -61,7 +62,7 @@ jobs: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.0.0 + sdk: 3.2.0-114.0.dev - name: Install dependencies run: dart pub get - name: Build test dylib and bindings @@ -83,7 +84,7 @@ jobs: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.0.0 + sdk: 3.2.0-114.0.dev - name: Install dependencies run: dart pub get - name: Build test dylib and bindings diff --git a/CHANGELOG.md b/CHANGELOG.md index b4bdf287..7036a8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 10.0.0-dev.0 + +- Add support for ObjC Blocks that can be invoked from any thread, using + NativeCallable.listener. +- Bump min SDK version to 3.2.0-114.0.dev. + # 9.0.1 - Fix doc comment missing on struct/union array fields. diff --git a/example/c_json/cjson_generated_bindings.dart b/example/c_json/cjson_generated_bindings.dart index 0fb9e1aa..fa9e56ef 100644 --- a/example/c_json/cjson_generated_bindings.dart +++ b/example/c_json/cjson_generated_bindings.dart @@ -73,8 +73,9 @@ class CJson { } late final _cJSON_ParsePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('cJSON_Parse'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_Parse'); late final _cJSON_Parse = _cJSON_ParsePtr .asFunction Function(ffi.Pointer)>(); @@ -109,8 +110,9 @@ class CJson { } late final _cJSON_PrintPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('cJSON_Print'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_Print'); late final _cJSON_Print = _cJSON_PrintPtr .asFunction Function(ffi.Pointer)>(); @@ -123,9 +125,9 @@ class CJson { } late final _cJSON_PrintUnformattedPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_PrintUnformatted'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_PrintUnformatted'); late final _cJSON_PrintUnformatted = _cJSON_PrintUnformattedPtr .asFunction Function(ffi.Pointer)>(); @@ -286,9 +288,9 @@ class CJson { } late final _cJSON_GetStringValuePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_GetStringValue'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_GetStringValue'); late final _cJSON_GetStringValue = _cJSON_GetStringValuePtr .asFunction Function(ffi.Pointer)>(); @@ -499,9 +501,9 @@ class CJson { } late final _cJSON_CreateStringPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateString'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateString'); late final _cJSON_CreateString = _cJSON_CreateStringPtr .asFunction Function(ffi.Pointer)>(); @@ -514,9 +516,9 @@ class CJson { } late final _cJSON_CreateRawPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateRaw'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateRaw'); late final _cJSON_CreateRaw = _cJSON_CreateRawPtr .asFunction Function(ffi.Pointer)>(); @@ -549,9 +551,9 @@ class CJson { } late final _cJSON_CreateStringReferencePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateStringReference'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateStringReference'); late final _cJSON_CreateStringReference = _cJSON_CreateStringReferencePtr .asFunction Function(ffi.Pointer)>(); @@ -1199,9 +1201,9 @@ class CJson { } late final _cJSON_SetNumberHelperPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function( - ffi.Pointer, ffi.Double)>>('cJSON_SetNumberHelper'); + ffi + .NativeFunction, ffi.Double)>>( + 'cJSON_SetNumberHelper'); late final _cJSON_SetNumberHelper = _cJSON_SetNumberHelperPtr .asFunction, double)>(); @@ -1256,12 +1258,13 @@ final class cJSON extends ffi.Struct { } final class cJSON_Hooks extends ffi.Struct { - external ffi.Pointer< - ffi.NativeFunction Function(ffi.Size sz)>> + external ffi + .Pointer Function(ffi.Size sz)>> malloc_fn; - external ffi.Pointer< - ffi.NativeFunction ptr)>> free_fn; + external ffi + .Pointer ptr)>> + free_fn; } typedef cJSON_bool = ffi.Int; diff --git a/example/c_json/pubspec.yaml b/example/c_json/pubspec.yaml index 33010135..c1277a89 100644 --- a/example/c_json/pubspec.yaml +++ b/example/c_json/pubspec.yaml @@ -5,7 +5,7 @@ name: c_json_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/ffinative/pubspec.yaml b/example/ffinative/pubspec.yaml index ef452f81..7be76fc1 100644 --- a/example/ffinative/pubspec.yaml +++ b/example/ffinative/pubspec.yaml @@ -5,7 +5,7 @@ name: ffinative_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/libclang-example/generated_bindings.dart b/example/libclang-example/generated_bindings.dart index 64de33cb..fe7f3c4f 100644 --- a/example/libclang-example/generated_bindings.dart +++ b/example/libclang-example/generated_bindings.dart @@ -205,8 +205,8 @@ class LibClang { } late final _clang_CXIndex_setInvocationEmissionPathOptionPtr = _lookup< - ffi.NativeFunction< - NativeClang_CXIndex_setInvocationEmissionPathOption>>( + ffi + .NativeFunction>( 'clang_CXIndex_setInvocationEmissionPathOption'); late final _clang_CXIndex_setInvocationEmissionPathOption = _clang_CXIndex_setInvocationEmissionPathOptionPtr @@ -2938,8 +2938,8 @@ class LibClang { } late final _clang_Cursor_getTemplateArgumentUnsignedValuePtr = _lookup< - ffi.NativeFunction< - NativeClang_Cursor_getTemplateArgumentUnsignedValue>>( + ffi + .NativeFunction>( 'clang_Cursor_getTemplateArgumentUnsignedValue'); late final _clang_Cursor_getTemplateArgumentUnsignedValue = _clang_Cursor_getTemplateArgumentUnsignedValuePtr @@ -4849,8 +4849,8 @@ class LibClang { } late final _clang_CXXConstructor_isConvertingConstructorPtr = _lookup< - ffi.NativeFunction< - NativeClang_CXXConstructor_isConvertingConstructor>>( + ffi + .NativeFunction>( 'clang_CXXConstructor_isConvertingConstructor'); late final _clang_CXXConstructor_isConvertingConstructor = _clang_CXXConstructor_isConvertingConstructorPtr @@ -6850,8 +6850,8 @@ class _SymbolAddresses { get clang_CXIndex_getGlobalOptions => _library._clang_CXIndex_getGlobalOptionsPtr; ffi.Pointer< - ffi.NativeFunction< - NativeClang_CXIndex_setInvocationEmissionPathOption>> + ffi + .NativeFunction> get clang_CXIndex_setInvocationEmissionPathOption => _library._clang_CXIndex_setInvocationEmissionPathOptionPtr; ffi.Pointer> @@ -7148,8 +7148,8 @@ class _SymbolAddresses { get clang_Cursor_getTemplateArgumentValue => _library._clang_Cursor_getTemplateArgumentValuePtr; ffi.Pointer< - ffi.NativeFunction< - NativeClang_Cursor_getTemplateArgumentUnsignedValue>> + ffi + .NativeFunction> get clang_Cursor_getTemplateArgumentUnsignedValue => _library._clang_Cursor_getTemplateArgumentUnsignedValuePtr; ffi.Pointer> @@ -7406,8 +7406,8 @@ class _SymbolAddresses { get clang_Module_getTopLevelHeader => _library._clang_Module_getTopLevelHeaderPtr; ffi.Pointer< - ffi.NativeFunction< - NativeClang_CXXConstructor_isConvertingConstructor>> + ffi + .NativeFunction> get clang_CXXConstructor_isConvertingConstructor => _library._clang_CXXConstructor_isConvertingConstructorPtr; ffi.Pointer> @@ -11104,8 +11104,8 @@ typedef DartClang_indexLoc_getCXSourceLocation = CXSourceLocation Function( /// The visitor should return one of the \c CXVisitorResult values /// to direct \c clang_Type_visitFields. typedef CXFieldVisitor = ffi.Pointer< - ffi.NativeFunction< - ffi.Int32 Function(CXCursor C, CXClientData client_data)>>; + ffi + .NativeFunction>; typedef NativeClang_Type_visitFields = ffi.UnsignedInt Function( CXType T, CXFieldVisitor visitor, CXClientData client_data); typedef DartClang_Type_visitFields = int Function( diff --git a/example/libclang-example/pubspec.yaml b/example/libclang-example/pubspec.yaml index 9d7e8ab8..a8ecc544 100644 --- a/example/libclang-example/pubspec.yaml +++ b/example/libclang-example/pubspec.yaml @@ -5,7 +5,7 @@ name: libclang_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/objective_c/avf_audio_bindings.dart b/example/objective_c/avf_audio_bindings.dart index ae0d3fd9..eaa669d7 100644 --- a/example/objective_c/avf_audio_bindings.dart +++ b/example/objective_c/avf_audio_bindings.dart @@ -22381,8 +22381,8 @@ class AVFAudio { ffi.Pointer, ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>)>(); + ffi + .NativeFunction)>>)>(); late final _sel_descriptionFunction1 = _registerName1("descriptionFunction"); ffi.Pointer< @@ -22541,8 +22541,8 @@ class AVFAudio { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>, + ffi + .NativeFunction)>>, ffi.Bool)>> _objc_msgSend_803( ffi.Pointer obj, ffi.Pointer sel, @@ -22553,20 +22553,20 @@ class AVFAudio { ); } - late final __objc_msgSend_803Ptr = - _lookup< - ffi.NativeFunction< - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer< + late final __objc_msgSend_803Ptr = _lookup< + ffi.NativeFunction< + ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi + .Pointer< ffi.NativeFunction< NSUInteger Function( ffi.Pointer)>>, - ffi.Bool)>> - Function(ffi.Pointer, ffi.Pointer)>>( - 'objc_msgSend'); + ffi.Bool)>> + Function(ffi.Pointer, ffi.Pointer)>>( + 'objc_msgSend'); late final __objc_msgSend_803 = __objc_msgSend_803Ptr.asFunction< ffi.Pointer< ffi.NativeFunction< @@ -36092,16 +36092,17 @@ class ObjCBlock4 extends _ObjCBlockBase { NSUInteger arg1, ffi.Pointer arg2)>> ptr) : this._( - lib._newBlock1( - ffi.Pointer.fromFunction< - ffi.Bool Function( - ffi.Pointer<_ObjCBlock> block, - ffi.Pointer arg0, - NSUInteger arg1, - ffi.Pointer arg2)>( - _ObjCBlock4_fnPtrTrampoline, false) - .cast(), - ptr.cast()), + lib + ._newBlock1( + ffi.Pointer.fromFunction< + ffi.Bool Function( + ffi.Pointer<_ObjCBlock> block, + ffi.Pointer arg0, + NSUInteger arg1, + ffi.Pointer arg2)>( + _ObjCBlock4_fnPtrTrampoline, false) + .cast(), + ptr.cast()), lib); /// Creates a block from a Dart function. @@ -40641,8 +40642,8 @@ class ObjCBlock15 extends _ObjCBlockBase { ObjCBlock15.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -43044,8 +43045,8 @@ class ObjCBlock16 extends _ObjCBlockBase { void call() { return _id.ref.invoke .cast< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer<_ObjCBlock> block)>>() + ffi + .NativeFunction block)>>() .asFunction block)>()(_id); } @@ -44324,8 +44325,8 @@ class ObjCBlock17 extends _ObjCBlockBase { ObjCBlock17.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -47403,15 +47404,16 @@ class ObjCBlock19 extends _ObjCBlockBase { ffi.Pointer arg1)>> ptr) : this._( - lib._newBlock1( - ffi.Pointer.fromFunction< - ffi.Void Function( - ffi.Pointer<_ObjCBlock> block, - ffi.Pointer arg0, - ffi.Pointer arg1)>( - _ObjCBlock19_fnPtrTrampoline) - .cast(), - ptr.cast()), + lib + ._newBlock1( + ffi.Pointer.fromFunction< + ffi.Void Function( + ffi.Pointer<_ObjCBlock> block, + ffi.Pointer arg0, + ffi.Pointer arg1)>( + _ObjCBlock19_fnPtrTrampoline) + .cast(), + ptr.cast()), lib); /// Creates a block from a Dart function. @@ -47560,7 +47562,8 @@ class ObjCBlock21 extends _ObjCBlockBase { ObjCBlock21.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< + ffi + .NativeFunction< ffi.Void Function(ffi.Pointer arg0, ffi.Bool arg1, ffi.Pointer arg2)>> ptr) @@ -47654,15 +47657,16 @@ class ObjCBlock22 extends _ObjCBlockBase { ffi.Pointer arg1)>> ptr) : this._( - lib._newBlock1( - ffi.Pointer.fromFunction< - ffi.Void Function( - ffi.Pointer<_ObjCBlock> block, - ffi.Pointer arg0, - ffi.Pointer arg1)>( - _ObjCBlock22_fnPtrTrampoline) - .cast(), - ptr.cast()), + lib + ._newBlock1( + ffi.Pointer.fromFunction< + ffi.Void Function( + ffi.Pointer<_ObjCBlock> block, + ffi.Pointer arg0, + ffi.Pointer arg1)>( + _ObjCBlock22_fnPtrTrampoline) + .cast(), + ptr.cast()), lib); /// Creates a block from a Dart function. @@ -47811,15 +47815,16 @@ class ObjCBlock24 extends _ObjCBlockBase { ffi.Pointer arg1)>> ptr) : this._( - lib._newBlock1( - ffi.Pointer.fromFunction< - ffi.Void Function( - ffi.Pointer<_ObjCBlock> block, - ffi.Pointer arg0, - ffi.Pointer arg1)>( - _ObjCBlock24_fnPtrTrampoline) - .cast(), - ptr.cast()), + lib + ._newBlock1( + ffi.Pointer.fromFunction< + ffi.Void Function( + ffi.Pointer<_ObjCBlock> block, + ffi.Pointer arg0, + ffi.Pointer arg1)>( + _ObjCBlock24_fnPtrTrampoline) + .cast(), + ptr.cast()), lib); /// Creates a block from a Dart function. @@ -53644,8 +53649,8 @@ class ObjCBlock29 extends _ObjCBlockBase { ObjCBlock29.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -55582,8 +55587,8 @@ class ObjCBlock30 extends _ObjCBlockBase { ObjCBlock30.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -57065,8 +57070,8 @@ class NSPointerFunctions extends NSObject { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>, + ffi + .NativeFunction)>>, ffi.Bool)>> get acquireFunction { return _lib._objc_msgSend_803(_id, _lib._sel_acquireFunction1); } @@ -58822,8 +58827,8 @@ class ObjCBlock33 extends _ObjCBlockBase { ObjCBlock33.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -59834,8 +59839,8 @@ class ObjCBlock35 extends _ObjCBlockBase { ObjCBlock35.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -59902,8 +59907,8 @@ class ObjCBlock36 extends _ObjCBlockBase { ObjCBlock36.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -62217,8 +62222,8 @@ class ObjCBlock38 extends _ObjCBlockBase { ObjCBlock38.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -62442,7 +62447,8 @@ class ObjCBlock39 extends _ObjCBlockBase { ObjCBlock39.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< + ffi + .NativeFunction< ffi.Void Function(ffi.Pointer arg0, ffi.Bool arg1, ffi.Pointer arg2)>> ptr) @@ -63106,15 +63112,16 @@ class ObjCBlock40 extends _ObjCBlockBase { ffi.Pointer arg1)>> ptr) : this._( - lib._newBlock1( - ffi.Pointer.fromFunction< - ffi.Void Function( - ffi.Pointer<_ObjCBlock> block, - ffi.Pointer arg0, - ffi.Pointer arg1)>( - _ObjCBlock40_fnPtrTrampoline) - .cast(), - ptr.cast()), + lib + ._newBlock1( + ffi.Pointer.fromFunction< + ffi.Void Function( + ffi.Pointer<_ObjCBlock> block, + ffi.Pointer arg0, + ffi.Pointer arg1)>( + _ObjCBlock40_fnPtrTrampoline) + .cast(), + ptr.cast()), lib); /// Creates a block from a Dart function. @@ -63770,8 +63777,8 @@ class ObjCBlock43 extends _ObjCBlockBase { ObjCBlock43.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( diff --git a/example/objective_c/pubspec.yaml b/example/objective_c/pubspec.yaml index 4cedaa34..c06b7a0a 100644 --- a/example/objective_c/pubspec.yaml +++ b/example/objective_c/pubspec.yaml @@ -5,7 +5,7 @@ name: objective_c_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/shared_bindings/pubspec.yaml b/example/shared_bindings/pubspec.yaml index 2f270f10..23008d23 100644 --- a/example/shared_bindings/pubspec.yaml +++ b/example/shared_bindings/pubspec.yaml @@ -5,7 +5,7 @@ name: shared_bindings environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: cli_util: ^0.4.0 diff --git a/example/simple/generated_bindings.dart b/example/simple/generated_bindings.dart index 71f0414a..b26a8ac7 100644 --- a/example/simple/generated_bindings.dart +++ b/example/simple/generated_bindings.dart @@ -81,8 +81,9 @@ class NativeLibrary { } late final _dividePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Int, ffi.Int)>>('divide'); + ffi + .NativeFunction Function(ffi.Int, ffi.Int)>>( + 'divide'); late final _divide = _dividePtr.asFunction Function(int, int)>(); diff --git a/example/simple/pubspec.yaml b/example/simple/pubspec.yaml index ea435727..bef37902 100644 --- a/example/simple/pubspec.yaml +++ b/example/simple/pubspec.yaml @@ -5,7 +5,7 @@ name: simple_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/swift/pubspec.yaml b/example/swift/pubspec.yaml index 07d93eba..de19bf24 100644 --- a/example/swift/pubspec.yaml +++ b/example/swift/pubspec.yaml @@ -5,7 +5,7 @@ name: swift_example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-42.1.beta <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/swift/swift_api_bindings.dart b/example/swift/swift_api_bindings.dart index f741f7fa..2a8783aa 100644 --- a/example/swift/swift_api_bindings.dart +++ b/example/swift/swift_api_bindings.dart @@ -22386,8 +22386,8 @@ class SwiftLibrary { ffi.Pointer, ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>)>(); + ffi + .NativeFunction)>>)>(); late final _sel_descriptionFunction1 = _registerName1("descriptionFunction"); ffi.Pointer< @@ -22546,8 +22546,8 @@ class SwiftLibrary { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>, + ffi + .NativeFunction)>>, ffi.Bool)>> _objc_msgSend_803( ffi.Pointer obj, ffi.Pointer sel, @@ -22558,20 +22558,20 @@ class SwiftLibrary { ); } - late final __objc_msgSend_803Ptr = - _lookup< - ffi.NativeFunction< - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer< + late final __objc_msgSend_803Ptr = _lookup< + ffi.NativeFunction< + ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi + .Pointer< ffi.NativeFunction< NSUInteger Function( ffi.Pointer)>>, - ffi.Bool)>> - Function(ffi.Pointer, ffi.Pointer)>>( - 'objc_msgSend'); + ffi.Bool)>> + Function(ffi.Pointer, ffi.Pointer)>>( + 'objc_msgSend'); late final __objc_msgSend_803 = __objc_msgSend_803Ptr.asFunction< ffi.Pointer< ffi.NativeFunction< @@ -34838,7 +34838,11 @@ class ObjCBlock4 extends _ObjCBlockBase { /// Creates a block from a C function pointer. ObjCBlock4.fromFunctionPointer( SwiftLibrary lib, - ffi.Pointer arg0, NSUInteger arg1, ffi.Pointer arg2)>> + ffi.Pointer< + ffi + .NativeFunction< + ffi.Bool Function(ffi.Pointer arg0, + NSUInteger arg1, ffi.Pointer arg2)>> ptr) : this._( lib._newBlock1( @@ -39398,8 +39402,8 @@ class ObjCBlock15 extends _ObjCBlockBase { ObjCBlock15.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -41807,8 +41811,8 @@ class ObjCBlock16 extends _ObjCBlockBase { void call() { return _id.ref.invoke .cast< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer<_ObjCBlock> block)>>() + ffi + .NativeFunction block)>>() .asFunction block)>()(_id); } @@ -43090,8 +43094,8 @@ class ObjCBlock17 extends _ObjCBlockBase { ObjCBlock17.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -46332,7 +46336,8 @@ class ObjCBlock21 extends _ObjCBlockBase { ObjCBlock21.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< + ffi + .NativeFunction< ffi.Void Function(ffi.Pointer arg0, ffi.Bool arg1, ffi.Pointer arg2)>> ptr) @@ -52432,8 +52437,8 @@ class ObjCBlock29 extends _ObjCBlockBase { ObjCBlock29.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -54371,8 +54376,8 @@ class ObjCBlock30 extends _ObjCBlockBase { ObjCBlock30.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -55856,8 +55861,8 @@ class NSPointerFunctions extends NSObject { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi.NativeFunction< - NSUInteger Function(ffi.Pointer)>>, + ffi + .NativeFunction)>>, ffi.Bool)>> get acquireFunction { return _lib._objc_msgSend_803(_id, _lib._sel_acquireFunction1); } @@ -57616,8 +57621,8 @@ class ObjCBlock33 extends _ObjCBlockBase { ObjCBlock33.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -58632,8 +58637,8 @@ class ObjCBlock35 extends _ObjCBlockBase { ObjCBlock35.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -58700,8 +58705,8 @@ class ObjCBlock36 extends _ObjCBlockBase { ObjCBlock36.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -61015,8 +61020,8 @@ class ObjCBlock38 extends _ObjCBlockBase { ObjCBlock38.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( @@ -61240,7 +61245,8 @@ class ObjCBlock39 extends _ObjCBlockBase { ObjCBlock39.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< + ffi + .NativeFunction< ffi.Void Function(ffi.Pointer arg0, ffi.Bool arg1, ffi.Pointer arg2)>> ptr) @@ -62568,8 +62574,8 @@ class ObjCBlock43 extends _ObjCBlockBase { ObjCBlock43.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer arg0)>> + ffi + .NativeFunction arg0)>> ptr) : this._( lib._newBlock1( diff --git a/lib/src/code_generator/objc_block.dart b/lib/src/code_generator/objc_block.dart index 1599748c..883acd73 100644 --- a/lib/src/code_generator/objc_block.dart +++ b/lib/src/code_generator/objc_block.dart @@ -35,7 +35,7 @@ class ObjCBlock extends BindingType { params.add(Parameter(name: 'arg$i', type: argTypes[i])); } - final isVoid = returnType == NativeType(SupportedNativeType.Void); + final isVoid = returnType == voidType; final voidPtr = PointerType(voidType).getCType(w); final blockPtr = PointerType(builtInFunctions.blockStruct); final funcType = FunctionType(returnType: returnType, parameters: params); @@ -55,6 +55,8 @@ class ObjCBlock extends BindingType { returnType: returnType, parameters: [Parameter(type: blockPtr, name: 'block'), ...params]); final natTrampFnType = NativeFunc(trampFuncType); + final nativeCallableType = + '${w.ffiLibraryPrefix}.NativeCallable<${trampFuncType.getCType(w)}>'; // Write the function pointer based trampoline function. s.write(returnType.getDartType(w)); @@ -107,6 +109,10 @@ class $name extends _ObjCBlockBase { super._(id, lib, retain: false, release: true); /// Creates a block from a C function pointer. + /// + /// This block must be invoked by native code running on the same thread as + /// the isolate that registered it. Invoking the block on the wrong thread + /// will result in a crash. $name.fromFunctionPointer(${w.className} lib, $natFnPtr ptr) : this._(lib.${builtInFunctions.newBlock.name}( _cFuncTrampoline ??= ${w.ffiLibraryPrefix}.Pointer.fromFunction< @@ -115,13 +121,40 @@ class $name extends _ObjCBlockBase { static $voidPtr? _cFuncTrampoline; /// Creates a block from a Dart function. + /// + /// This block must be invoked by native code running on the same thread as + /// the isolate that registered it. Invoking the block on the wrong thread + /// will result in a crash. $name.fromFunction(${w.className} lib, ${funcType.getDartType(w)} fn) : this._(lib.${builtInFunctions.newBlock.name}( _dartFuncTrampoline ??= ${w.ffiLibraryPrefix}.Pointer.fromFunction< ${trampFuncType.getCType(w)}>($closureTrampoline $exceptionalReturn).cast(), $registerClosure(fn)), lib); static $voidPtr? _dartFuncTrampoline; + +'''); + + // Listener block constructor is only available for void blocks. + if (isVoid) { + s.write(''' + /// Creates a listener block from a Dart function. + /// + /// This is based on FFI's NativeCallable.listener, and has the same + /// capabilities and limitations. This block can be invoked from any thread, + /// but only supports void functions, and is not run synchronously. See + /// NativeCallable.listener for more details. + /// + /// Note that unlike the default behavior of NativeCallable.listener, listener + /// blocks do not keep the isolate alive. + $name.listener(${w.className} lib, ${funcType.getDartType(w)} fn) : + this._(lib.${builtInFunctions.newBlock.name}( + (_dartFuncListenerTrampoline ??= $nativeCallableType.listener($closureTrampoline + $exceptionalReturn)..keepIsolateAlive = false).nativeFunction.cast(), + $registerClosure(fn)), lib); + static $nativeCallableType? _dartFuncListenerTrampoline; + '''); + } // Call method. s.write(' ${returnType.getDartType(w)} call('); diff --git a/lib/src/config_provider/config_spec.dart b/lib/src/config_provider/config_spec.dart index 3ad32491..c7ed4061 100644 --- a/lib/src/config_provider/config_spec.dart +++ b/lib/src/config_provider/config_spec.dart @@ -591,7 +591,7 @@ class StringConfigSpec extends ConfigSpec { if (!o.checkType(log: log)) { return false; } - if (_regexp != null && !_regexp!.hasMatch(o.value as String)) { + if (_regexp != null && !_regexp.hasMatch(o.value as String)) { if (log) { _logger.severe( "Expected value of key '${o.pathString}' to match pattern $pattern (Input - ${o.value})."); diff --git a/lib/src/header_parser/clang_bindings/clang_bindings.dart b/lib/src/header_parser/clang_bindings/clang_bindings.dart index 4c5fba22..fc5ca177 100644 --- a/lib/src/header_parser/clang_bindings/clang_bindings.dart +++ b/lib/src/header_parser/clang_bindings/clang_bindings.dart @@ -1097,9 +1097,9 @@ class Clang { } late final _clang_Cursor_getObjCPropertyAttributesPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(CXCursor, - ffi.UnsignedInt)>>('clang_Cursor_getObjCPropertyAttributes'); + ffi + .NativeFunction>( + 'clang_Cursor_getObjCPropertyAttributes'); late final _clang_Cursor_getObjCPropertyAttributes = _clang_Cursor_getObjCPropertyAttributesPtr .asFunction(); diff --git a/pubspec.yaml b/pubspec.yaml index 3a8e0c15..ae45a104 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,8 +3,10 @@ # BSD-style license that can be found in the LICENSE file. name: ffigen -version: 9.0.1 -description: Generator for FFI bindings, using LibClang to parse C header files. +version: 10.0.0-dev.0 +description: > + Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift + files. repository: https://github.com/dart-lang/ffigen topics: @@ -13,7 +15,7 @@ topics: - codegen environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.2.0-114.0.dev <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart b/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart index 015821ea..ff7dc120 100644 --- a/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart +++ b/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart @@ -29,8 +29,9 @@ class Bindings { } late final _test1Ptr = _lookup< - ffi.NativeFunction< - ffi.Bool Function(ffi.Bool, ffi.Pointer)>>('test1'); + ffi + .NativeFunction)>>( + 'test1'); late final _test1 = _test1Ptr.asFunction)>(); } diff --git a/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart b/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart index 7475b09d..7b6682c4 100644 --- a/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart +++ b/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart @@ -128,8 +128,9 @@ class NativeLibrary { } late final _diffCharsPtr = _lookup< - ffi.NativeFunction< - ffi.Char Function(ffi.UnsignedChar, ffi.SignedChar)>>('diffChars'); + ffi + .NativeFunction>( + 'diffChars'); late final _diffChars = _diffCharsPtr.asFunction(); late final addresses = _SymbolAddresses(this); diff --git a/test/header_parser_tests/expected_bindings/_expected_struct_fptr_fields_bindings.dart b/test/header_parser_tests/expected_bindings/_expected_struct_fptr_fields_bindings.dart index 2b2fe8a3..2a769db2 100644 --- a/test/header_parser_tests/expected_bindings/_expected_struct_fptr_fields_bindings.dart +++ b/test/header_parser_tests/expected_bindings/_expected_struct_fptr_fields_bindings.dart @@ -8,7 +8,7 @@ final class S extends ffi.Struct { external ffi.Pointer> func1; external ffi - .Pointer> + .Pointer> comparator; external ffi.Pointer< @@ -53,8 +53,8 @@ final class S extends ffi.Struct { @ffi.Array.multi([2]) external ffi.Array< - ffi.Pointer< - ffi.NativeFunction>> + ffi + .Pointer>> manyFunctions; external ffi.Pointer< diff --git a/test/large_integration_tests/_expected_cjson_bindings.dart b/test/large_integration_tests/_expected_cjson_bindings.dart index b93c74f1..f4edb598 100644 --- a/test/large_integration_tests/_expected_cjson_bindings.dart +++ b/test/large_integration_tests/_expected_cjson_bindings.dart @@ -54,8 +54,9 @@ class CJson { } late final _cJSON_ParsePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('cJSON_Parse'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_Parse'); late final _cJSON_Parse = _cJSON_ParsePtr .asFunction Function(ffi.Pointer)>(); @@ -90,8 +91,9 @@ class CJson { } late final _cJSON_PrintPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function(ffi.Pointer)>>('cJSON_Print'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_Print'); late final _cJSON_Print = _cJSON_PrintPtr .asFunction Function(ffi.Pointer)>(); @@ -104,9 +106,9 @@ class CJson { } late final _cJSON_PrintUnformattedPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_PrintUnformatted'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_PrintUnformatted'); late final _cJSON_PrintUnformatted = _cJSON_PrintUnformattedPtr .asFunction Function(ffi.Pointer)>(); @@ -267,9 +269,9 @@ class CJson { } late final _cJSON_GetStringValuePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_GetStringValue'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_GetStringValue'); late final _cJSON_GetStringValue = _cJSON_GetStringValuePtr .asFunction Function(ffi.Pointer)>(); @@ -480,9 +482,9 @@ class CJson { } late final _cJSON_CreateStringPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateString'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateString'); late final _cJSON_CreateString = _cJSON_CreateStringPtr .asFunction Function(ffi.Pointer)>(); @@ -495,9 +497,9 @@ class CJson { } late final _cJSON_CreateRawPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateRaw'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateRaw'); late final _cJSON_CreateRaw = _cJSON_CreateRawPtr .asFunction Function(ffi.Pointer)>(); @@ -530,9 +532,9 @@ class CJson { } late final _cJSON_CreateStringReferencePtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer)>>('cJSON_CreateStringReference'); + ffi + .NativeFunction Function(ffi.Pointer)>>( + 'cJSON_CreateStringReference'); late final _cJSON_CreateStringReference = _cJSON_CreateStringReferencePtr .asFunction Function(ffi.Pointer)>(); @@ -1180,9 +1182,9 @@ class CJson { } late final _cJSON_SetNumberHelperPtr = _lookup< - ffi.NativeFunction< - ffi.Double Function( - ffi.Pointer, ffi.Double)>>('cJSON_SetNumberHelper'); + ffi + .NativeFunction, ffi.Double)>>( + 'cJSON_SetNumberHelper'); late final _cJSON_SetNumberHelper = _cJSON_SetNumberHelperPtr .asFunction, double)>(); @@ -1237,12 +1239,13 @@ final class cJSON extends ffi.Struct { } final class cJSON_Hooks extends ffi.Struct { - external ffi.Pointer< - ffi.NativeFunction Function(ffi.Size sz)>> + external ffi + .Pointer Function(ffi.Size sz)>> malloc_fn; - external ffi.Pointer< - ffi.NativeFunction ptr)>> free_fn; + external ffi + .Pointer ptr)>> + free_fn; } typedef cJSON_bool = ffi.Int; diff --git a/test/large_integration_tests/_expected_libclang_bindings.dart b/test/large_integration_tests/_expected_libclang_bindings.dart index 22c6f266..2bc76881 100644 --- a/test/large_integration_tests/_expected_libclang_bindings.dart +++ b/test/large_integration_tests/_expected_libclang_bindings.dart @@ -133,9 +133,9 @@ class LibClang { } late final _clang_VirtualFileOverlay_setCaseSensitivityPtr = _lookup< - ffi.NativeFunction< - ffi.Int32 Function(CXVirtualFileOverlay, - ffi.Int)>>('clang_VirtualFileOverlay_setCaseSensitivity'); + ffi + .NativeFunction>( + 'clang_VirtualFileOverlay_setCaseSensitivity'); late final _clang_VirtualFileOverlay_setCaseSensitivity = _clang_VirtualFileOverlay_setCaseSensitivityPtr .asFunction(); @@ -384,8 +384,8 @@ class LibClang { } late final _clang_CXIndex_setInvocationEmissionPathOptionPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(CXIndex, ffi.Pointer)>>( + ffi + .NativeFunction)>>( 'clang_CXIndex_setInvocationEmissionPathOption'); late final _clang_CXIndex_setInvocationEmissionPathOption = _clang_CXIndex_setInvocationEmissionPathOptionPtr @@ -453,9 +453,9 @@ class LibClang { } late final _clang_isFileMultipleIncludeGuardedPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(CXTranslationUnit, - CXFile)>>('clang_isFileMultipleIncludeGuarded'); + ffi + .NativeFunction>( + 'clang_isFileMultipleIncludeGuarded'); late final _clang_isFileMultipleIncludeGuarded = _clang_isFileMultipleIncludeGuardedPtr .asFunction(); @@ -943,9 +943,9 @@ class LibClang { } late final _clang_disposeSourceRangeListPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer)>>('clang_disposeSourceRangeList'); + ffi + .NativeFunction)>>( + 'clang_disposeSourceRangeList'); late final _clang_disposeSourceRangeList = _clang_disposeSourceRangeListPtr .asFunction)>(); @@ -3586,9 +3586,9 @@ class LibClang { } late final _clang_constructUSR_ObjCIvarPtr = _lookup< - ffi.NativeFunction< - CXString Function( - ffi.Pointer, CXString)>>('clang_constructUSR_ObjCIvar'); + ffi + .NativeFunction, CXString)>>( + 'clang_constructUSR_ObjCIvar'); late final _clang_constructUSR_ObjCIvar = _clang_constructUSR_ObjCIvarPtr .asFunction, CXString)>(); @@ -3626,9 +3626,9 @@ class LibClang { } late final _clang_constructUSR_ObjCPropertyPtr = _lookup< - ffi.NativeFunction< - CXString Function(ffi.Pointer, - CXString)>>('clang_constructUSR_ObjCProperty'); + ffi + .NativeFunction, CXString)>>( + 'clang_constructUSR_ObjCProperty'); late final _clang_constructUSR_ObjCProperty = _clang_constructUSR_ObjCPropertyPtr .asFunction, CXString)>(); @@ -3900,9 +3900,9 @@ class LibClang { } late final _clang_Cursor_getObjCPropertyAttributesPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(CXCursor, - ffi.UnsignedInt)>>('clang_Cursor_getObjCPropertyAttributes'); + ffi + .NativeFunction>( + 'clang_Cursor_getObjCPropertyAttributes'); late final _clang_Cursor_getObjCPropertyAttributes = _clang_Cursor_getObjCPropertyAttributesPtr .asFunction(); @@ -4595,9 +4595,9 @@ class LibClang { } late final _clang_getTokenExtentPtr = _lookup< - ffi.NativeFunction< - CXSourceRange Function( - CXTranslationUnit, CXToken)>>('clang_getTokenExtent'); + ffi + .NativeFunction>( + 'clang_getTokenExtent'); late final _clang_getTokenExtent = _clang_getTokenExtentPtr .asFunction(); @@ -8225,8 +8225,8 @@ abstract class CXIndexOptFlags { /// Visitor invoked for each field found by a traversal. typedef CXFieldVisitor = ffi.Pointer< - ffi.NativeFunction< - ffi.Int32 Function(CXCursor C, CXClientData client_data)>>; + ffi + .NativeFunction>; const int CINDEX_VERSION_MAJOR = 0; diff --git a/test/large_integration_tests/_expected_sqlite_bindings.dart b/test/large_integration_tests/_expected_sqlite_bindings.dart index af6cccf4..984fad3c 100644 --- a/test/large_integration_tests/_expected_sqlite_bindings.dart +++ b/test/large_integration_tests/_expected_sqlite_bindings.dart @@ -914,8 +914,8 @@ class SQLite { int sqlite3_busy_handler( ffi.Pointer arg0, ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> + ffi + .NativeFunction, ffi.Int)>> arg1, ffi.Pointer arg2, ) { @@ -1410,9 +1410,9 @@ class SQLite { } late final _sqlite3_randomnessPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Int, ffi.Pointer)>>('sqlite3_randomness'); + ffi + .NativeFunction)>>( + 'sqlite3_randomness'); late final _sqlite3_randomness = _sqlite3_randomnessPtr .asFunction)>(); @@ -4733,10 +4733,11 @@ class SQLite { ffi.Pointer, ffi.Int, ffi.Pointer>)>>, - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer)>>)>>( + ffi + .Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer)>>)>>( 'sqlite3_create_function'); late final _sqlite3_create_function = _sqlite3_create_functionPtr.asFunction< int Function( @@ -4810,10 +4811,11 @@ class SQLite { ffi.Pointer, ffi.Int, ffi.Pointer>)>>, - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer)>>)>>( + ffi + .Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer)>>)>>( 'sqlite3_create_function16'); late final _sqlite3_create_function16 = _sqlite3_create_function16Ptr.asFunction< @@ -4894,9 +4896,10 @@ class SQLite { ffi.Pointer< ffi.NativeFunction< ffi.Void Function(ffi.Pointer)>>, - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer)>>)>>( + ffi + .Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>)>>( 'sqlite3_create_function_v2'); late final _sqlite3_create_function_v2 = _sqlite3_create_function_v2Ptr.asFunction< @@ -4987,9 +4990,10 @@ class SQLite { ffi.Pointer, ffi.Int, ffi.Pointer>)>>, - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer)>>)>>( + ffi + .Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>>)>>( 'sqlite3_create_window_function'); late final _sqlite3_create_window_function = _sqlite3_create_window_functionPtr.asFunction< @@ -5294,9 +5298,9 @@ class SQLite { } late final _sqlite3_value_int64Ptr = _lookup< - ffi.NativeFunction< - sqlite3_int64 Function( - ffi.Pointer)>>('sqlite3_value_int64'); + ffi + .NativeFunction)>>( + 'sqlite3_value_int64'); late final _sqlite3_value_int64 = _sqlite3_value_int64Ptr .asFunction)>(); @@ -8361,9 +8365,9 @@ class SQLite { } late final _sqlite3_vfs_registerPtr = _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer, ffi.Int)>>('sqlite3_vfs_register'); + ffi + .NativeFunction, ffi.Int)>>( + 'sqlite3_vfs_register'); late final _sqlite3_vfs_register = _sqlite3_vfs_registerPtr .asFunction, int)>(); @@ -9756,8 +9760,9 @@ class SQLite { } late final _sqlite3_logPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function(ffi.Int, ffi.Pointer)>>('sqlite3_log'); + ffi + .NativeFunction)>>( + 'sqlite3_log'); late final _sqlite3_log = _sqlite3_logPtr.asFunction)>(); @@ -10689,21 +10694,22 @@ class SQLite { ); } - late final _sqlite3_rtree_query_callbackPtr = - _lookup< - ffi.NativeFunction< - ffi.Int Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer< + late final _sqlite3_rtree_query_callbackPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi + .Pointer< ffi.NativeFunction< ffi.Int Function( ffi.Pointer)>>, - ffi.Pointer, - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer)>>)>>( - 'sqlite3_rtree_query_callback'); + ffi.Pointer, + ffi.Pointer< + ffi + .NativeFunction< + ffi.Void Function(ffi.Pointer)>>)>>( + 'sqlite3_rtree_query_callback'); late final _sqlite3_rtree_query_callback = _sqlite3_rtree_query_callbackPtr.asFunction< int Function( @@ -10804,8 +10810,9 @@ final class sqlite3_vfs extends ffi.Struct { xRandomness; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> xSleep; + ffi + .NativeFunction, ffi.Int)>> + xSleep; external ffi.Pointer< ffi.NativeFunction< @@ -10853,12 +10860,12 @@ typedef sqlite3_syscall_ptr final class sqlite3_mem_methods extends ffi.Struct { /// Memory allocation function external ffi - .Pointer Function(ffi.Int)>> + .Pointer Function(ffi.Int)>> xMalloc; /// Free a prior allocation external ffi - .Pointer)>> + .Pointer)>> xFree; /// Resize an allocation @@ -10869,7 +10876,7 @@ final class sqlite3_mem_methods extends ffi.Struct { /// Return the size of an allocation external ffi - .Pointer)>> + .Pointer)>> xSize; /// Round up request size to allocation size @@ -10877,12 +10884,12 @@ final class sqlite3_mem_methods extends ffi.Struct { /// Initialize the memory allocator external ffi - .Pointer)>> + .Pointer)>> xInit; /// Deinitialize the memory allocator external ffi - .Pointer)>> + .Pointer)>> xShutdown; /// Argument to xInit() and xShutdown() @@ -10984,8 +10991,9 @@ final class sqlite3_module extends ffi.Struct { ffi.Pointer> ppCursor)>> xOpen; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer)>> xClose; + ffi + .NativeFunction)>> + xClose; external ffi.Pointer< ffi.NativeFunction< @@ -10997,12 +11005,13 @@ final class sqlite3_module extends ffi.Struct { ffi.Pointer>)>> xFilter; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer)>> xNext; + ffi + .NativeFunction)>> + xNext; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer)>> xEof; + ffi + .NativeFunction)>> xEof; external ffi.Pointer< ffi.NativeFunction< @@ -11063,21 +11072,24 @@ final class sqlite3_module extends ffi.Struct { /// The methods above are in version 1 of the sqlite_module object. Those /// below are for version 2 and greater. external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> xSavepoint; + ffi + .NativeFunction, ffi.Int)>> + xSavepoint; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> xRelease; + ffi + .NativeFunction, ffi.Int)>> + xRelease; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> xRollbackTo; + ffi + .NativeFunction, ffi.Int)>> + xRollbackTo; /// The methods above are in versions 1 and 2 of the sqlite_module object. /// Those below are for version 3 and greater. external ffi - .Pointer)>> + .Pointer)>> xShadowName; } @@ -11296,8 +11308,8 @@ final class sqlite3_mutex_methods extends ffi.Struct { external ffi.Pointer> xMutexEnd; - external ffi.Pointer< - ffi.NativeFunction Function(ffi.Int)>> + external ffi + .Pointer Function(ffi.Int)>> xMutexAlloc; external ffi.Pointer< @@ -11308,20 +11320,20 @@ final class sqlite3_mutex_methods extends ffi.Struct { ffi.NativeFunction)>> xMutexEnter; - external ffi.Pointer< - ffi.NativeFunction)>> + external ffi + .Pointer)>> xMutexTry; external ffi.Pointer< ffi.NativeFunction)>> xMutexLeave; - external ffi.Pointer< - ffi.NativeFunction)>> + external ffi + .Pointer)>> xMutexHeld; - external ffi.Pointer< - ffi.NativeFunction)>> + external ffi + .Pointer)>> xMutexNotheld; } @@ -11344,11 +11356,11 @@ final class sqlite3_pcache_methods2 extends ffi.Struct { external ffi.Pointer pArg; external ffi - .Pointer)>> + .Pointer)>> xInit; external ffi - .Pointer)>> + .Pointer)>> xShutdown; external ffi.Pointer< @@ -11400,11 +11412,11 @@ final class sqlite3_pcache_methods extends ffi.Struct { external ffi.Pointer pArg; external ffi - .Pointer)>> + .Pointer)>> xInit; external ffi - .Pointer)>> + .Pointer)>> xShutdown; external ffi.Pointer< @@ -11489,7 +11501,7 @@ final class sqlite3_rtree_geometry extends ffi.Struct { /// Called by SQLite to clean up pUser external ffi - .Pointer)>> + .Pointer)>> xDelUser; } @@ -11518,7 +11530,7 @@ final class sqlite3_rtree_query_info extends ffi.Struct { /// function to free pUser external ffi - .Pointer)>> + .Pointer)>> xDelUser; /// Coordinates of node or entry to check @@ -11781,8 +11793,8 @@ final class Fts5ExtensionApi extends ffi.Struct { ffi.NativeFunction< ffi.Pointer Function(ffi.Pointer)>> xUserData; - external ffi.Pointer< - ffi.NativeFunction)>> + external ffi + .Pointer)>> xColumnCount; external ffi.Pointer< @@ -11812,13 +11824,14 @@ final class Fts5ExtensionApi extends ffi.Struct { ffi.Int, ffi.Int)>>)>> xTokenize; - external ffi.Pointer< - ffi.NativeFunction)>> + external ffi + .Pointer)>> xPhraseCount; external ffi.Pointer< - ffi.NativeFunction< - ffi.Int Function(ffi.Pointer, ffi.Int)>> xPhraseSize; + ffi + .NativeFunction, ffi.Int)>> + xPhraseSize; external ffi.Pointer< ffi.NativeFunction< @@ -11968,8 +11981,8 @@ final class fts5_api extends ffi.Struct { ffi.Pointer pContext, ffi.Pointer pTokenizer, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer)>> + ffi + .NativeFunction)>> xDestroy)>> xCreateTokenizer; /// Find an existing tokenizer @@ -11990,8 +12003,8 @@ final class fts5_api extends ffi.Struct { ffi.Pointer pContext, fts5_extension_function xFunction, ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer)>> + ffi + .NativeFunction)>> xDestroy)>> xCreateFunction; } diff --git a/test/native_objc_test/block_test.dart b/test/native_objc_test/block_test.dart index 76f7a936..fd8c491f 100644 --- a/test/native_objc_test/block_test.dart +++ b/test/native_objc_test/block_test.dart @@ -5,6 +5,7 @@ // Objective C support is only available on mac. @TestOn('mac-os') +import 'dart:async'; import 'dart:ffi'; import 'dart:io'; @@ -51,7 +52,7 @@ void main() { }); test('Block from function pointer', () { - final block = ObjCBlock.fromFunctionPointer( + final block = ObjCBlock1.fromFunctionPointer( lib, Pointer.fromFunction(_add100, 999)); final blockTester = BlockTester.makeFromBlock_(lib, block); blockTester.pokeBlock(); @@ -64,15 +65,44 @@ void main() { } test('Block from function', () { - final block = ObjCBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock1.fromFunction(lib, makeAdder(4000)); final blockTester = BlockTester.makeFromBlock_(lib, block); blockTester.pokeBlock(); expect(blockTester.call_(123), 4123); expect(block(123), 4123); }); + test('Listener block same thread', () async { + final hasRun = Completer(); + int value = 0; + final block = ObjCBlock.listener(lib, () { + value = 123; + hasRun.complete(); + }); + + BlockTester.callOnSameThread_(lib, block); + + await hasRun.future; + expect(value, 123); + }); + + test('Listener block new thread', () async { + final hasRun = Completer(); + int value = 0; + final block = ObjCBlock.listener(lib, () { + value = 123; + hasRun.complete(); + }); + + final thread = BlockTester.callOnNewThread_(lib, block); + thread.start(); + + await hasRun.future; + expect(value, 123); + }); + Pointer funcPointerBlockRefCountTest() { - final block = ObjCBlock.fromFunctionPointer( + final block = ObjCBlock1.fromFunctionPointer( lib, Pointer.fromFunction(_add100, 999)); expect(BlockTester.getBlockRetainCount_(lib, block.pointer.cast()), 1); return block.pointer.cast(); @@ -85,7 +115,7 @@ void main() { }); Pointer funcBlockRefCountTest() { - final block = ObjCBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock1.fromFunction(lib, makeAdder(4000)); expect(BlockTester.getBlockRetainCount_(lib, block.pointer.cast()), 1); return block.pointer.cast(); } @@ -97,7 +127,7 @@ void main() { }); test('Block fields have sensible values', () { - final block = ObjCBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock1.fromFunction(lib, makeAdder(4000)); final blockPtr = block.pointer; expect(blockPtr.ref.isa, isNot(0)); expect(blockPtr.ref.flags, isNot(0)); // Set by Block_copy. diff --git a/test/native_objc_test/block_test.m b/test/native_objc_test/block_test.m index bdd37a79..5e0174f0 100644 --- a/test/native_objc_test/block_test.m +++ b/test/native_objc_test/block_test.m @@ -3,8 +3,10 @@ // BSD-style license that can be found in the LICENSE file. #import +#import typedef int32_t (^IntBlock)(int32_t); +typedef void (^VoidBlock)(); // Wrapper around a block, so that our Dart code can test creating and invoking // blocks in Objective C code. @@ -17,6 +19,8 @@ + (uint64_t)getBlockRetainCount:(void*)block; - (int32_t)call:(int32_t)x; - (IntBlock)getBlock; - (void)pokeBlock; ++ (void)callOnSameThread:(VoidBlock)block; ++ (NSThread*)callOnNewThread:(VoidBlock)block; @end @implementation BlockTester @@ -73,4 +77,13 @@ - (void)pokeBlock { // Used to repro https://github.com/dart-lang/ffigen/issues/376 [[myBlock retain] release]; } + ++ (void)callOnSameThread:(VoidBlock)block { + block(); +} + ++ (NSThread*)callOnNewThread:(VoidBlock)block { + return [[NSThread alloc] initWithBlock: block]; +} + @end