diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 75f45851..0e03e0b4 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -19,8 +19,7 @@ jobs: strategy: fail-fast: false matrix: - # TODO: Change to 3.2.0 stable once it's released. - sdk: [3.2.0-114.0.dev] + sdk: [3.0.0] steps: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f @@ -45,7 +44,7 @@ jobs: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.2.0-114.0.dev + sdk: 3.0.0 - name: Install dependencies run: dart pub get - name: Install libclang-14-dev @@ -62,7 +61,7 @@ jobs: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.2.0-114.0.dev + sdk: 3.0.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings @@ -84,7 +83,7 @@ jobs: - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: 3.2.0-114.0.dev + sdk: 3.0.0 - name: Install dependencies run: dart pub get - name: Build test dylib and bindings diff --git a/CHANGELOG.md b/CHANGELOG.md index efc5af31..7036a8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,6 @@ - Add support for ObjC Blocks that can be invoked from any thread, using NativeCallable.listener. -- Fix invalid exceptional return value ObjCBlocks that return floats. -- Fix return_of_invalid_type analysis error for ObjCBlocks. -- Fix crash in ObjC methods and blocks that return structs by value. -- Fix ObjC methods returning instancetype having the wrong type in sublasses. - Bump min SDK version to 3.2.0-114.0.dev. # 9.0.1 diff --git a/example/c_json/cjson_generated_bindings.dart b/example/c_json/cjson_generated_bindings.dart index fa9e56ef..0fb9e1aa 100644 --- a/example/c_json/cjson_generated_bindings.dart +++ b/example/c_json/cjson_generated_bindings.dart @@ -73,9 +73,8 @@ class CJson { } late final _cJSON_ParsePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_Parse'); + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('cJSON_Parse'); late final _cJSON_Parse = _cJSON_ParsePtr .asFunction Function(ffi.Pointer)>(); @@ -110,9 +109,8 @@ class CJson { } late final _cJSON_PrintPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_Print'); + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('cJSON_Print'); late final _cJSON_Print = _cJSON_PrintPtr .asFunction Function(ffi.Pointer)>(); @@ -125,9 +123,9 @@ class CJson { } late final _cJSON_PrintUnformattedPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_PrintUnformatted'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_PrintUnformatted'); late final _cJSON_PrintUnformatted = _cJSON_PrintUnformattedPtr .asFunction Function(ffi.Pointer)>(); @@ -288,9 +286,9 @@ class CJson { } late final _cJSON_GetStringValuePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_GetStringValue'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_GetStringValue'); late final _cJSON_GetStringValue = _cJSON_GetStringValuePtr .asFunction Function(ffi.Pointer)>(); @@ -501,9 +499,9 @@ class CJson { } late final _cJSON_CreateStringPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateString'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateString'); late final _cJSON_CreateString = _cJSON_CreateStringPtr .asFunction Function(ffi.Pointer)>(); @@ -516,9 +514,9 @@ class CJson { } late final _cJSON_CreateRawPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateRaw'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateRaw'); late final _cJSON_CreateRaw = _cJSON_CreateRawPtr .asFunction Function(ffi.Pointer)>(); @@ -551,9 +549,9 @@ class CJson { } late final _cJSON_CreateStringReferencePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateStringReference'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateStringReference'); late final _cJSON_CreateStringReference = _cJSON_CreateStringReferencePtr .asFunction Function(ffi.Pointer)>(); @@ -1201,9 +1199,9 @@ class CJson { } late final _cJSON_SetNumberHelperPtr = _lookup< - ffi - .NativeFunction, ffi.Double)>>( - 'cJSON_SetNumberHelper'); + ffi.NativeFunction< + ffi.Double Function( + ffi.Pointer, ffi.Double)>>('cJSON_SetNumberHelper'); late final _cJSON_SetNumberHelper = _cJSON_SetNumberHelperPtr .asFunction, double)>(); @@ -1258,13 +1256,12 @@ final class cJSON extends ffi.Struct { } final class cJSON_Hooks extends ffi.Struct { - external ffi - .Pointer Function(ffi.Size sz)>> + external ffi.Pointer< + ffi.NativeFunction Function(ffi.Size sz)>> malloc_fn; - external ffi - .Pointer ptr)>> - free_fn; + external ffi.Pointer< + ffi.NativeFunction ptr)>> free_fn; } typedef cJSON_bool = ffi.Int; diff --git a/example/c_json/pubspec.yaml b/example/c_json/pubspec.yaml index c1277a89..33010135 100644 --- a/example/c_json/pubspec.yaml +++ b/example/c_json/pubspec.yaml @@ -5,7 +5,7 @@ name: c_json_example environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/ffinative/pubspec.yaml b/example/ffinative/pubspec.yaml index 7be76fc1..ef452f81 100644 --- a/example/ffinative/pubspec.yaml +++ b/example/ffinative/pubspec.yaml @@ -5,7 +5,7 @@ name: ffinative_example environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <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 fe7f3c4f..64de33cb 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>( + ffi.NativeFunction< + NativeClang_CXIndex_setInvocationEmissionPathOption>>( '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>( + ffi.NativeFunction< + NativeClang_Cursor_getTemplateArgumentUnsignedValue>>( '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>( + ffi.NativeFunction< + NativeClang_CXXConstructor_isConvertingConstructor>>( '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> + ffi.NativeFunction< + NativeClang_CXIndex_setInvocationEmissionPathOption>> 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> + ffi.NativeFunction< + NativeClang_Cursor_getTemplateArgumentUnsignedValue>> 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> + ffi.NativeFunction< + NativeClang_CXXConstructor_isConvertingConstructor>> 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.NativeFunction< + ffi.Int32 Function(CXCursor C, CXClientData client_data)>>; 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 a8ecc544..9d7e8ab8 100644 --- a/example/libclang-example/pubspec.yaml +++ b/example/libclang-example/pubspec.yaml @@ -5,7 +5,7 @@ name: libclang_example environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <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 eaa669d7..ae0d3fd9 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)>>)>(); + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>)>(); late final _sel_descriptionFunction1 = _registerName1("descriptionFunction"); ffi.Pointer< @@ -22541,8 +22541,8 @@ class AVFAudio { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi - .NativeFunction)>>, + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>, 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,17 +36092,16 @@ 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. @@ -40642,8 +40641,8 @@ class ObjCBlock15 extends _ObjCBlockBase { ObjCBlock15.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -43045,8 +43044,8 @@ class ObjCBlock16 extends _ObjCBlockBase { void call() { return _id.ref.invoke .cast< - ffi - .NativeFunction block)>>() + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer<_ObjCBlock> block)>>() .asFunction block)>()(_id); } @@ -44325,8 +44324,8 @@ class ObjCBlock17 extends _ObjCBlockBase { ObjCBlock17.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -47404,16 +47403,15 @@ 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. @@ -47562,8 +47560,7 @@ 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) @@ -47657,16 +47654,15 @@ 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. @@ -47815,16 +47811,15 @@ 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. @@ -53649,8 +53644,8 @@ class ObjCBlock29 extends _ObjCBlockBase { ObjCBlock29.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -55587,8 +55582,8 @@ class ObjCBlock30 extends _ObjCBlockBase { ObjCBlock30.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -57070,8 +57065,8 @@ class NSPointerFunctions extends NSObject { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi - .NativeFunction)>>, + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>, ffi.Bool)>> get acquireFunction { return _lib._objc_msgSend_803(_id, _lib._sel_acquireFunction1); } @@ -58827,8 +58822,8 @@ class ObjCBlock33 extends _ObjCBlockBase { ObjCBlock33.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -59839,8 +59834,8 @@ class ObjCBlock35 extends _ObjCBlockBase { ObjCBlock35.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -59907,8 +59902,8 @@ class ObjCBlock36 extends _ObjCBlockBase { ObjCBlock36.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -62222,8 +62217,8 @@ class ObjCBlock38 extends _ObjCBlockBase { ObjCBlock38.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -62447,8 +62442,7 @@ 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) @@ -63112,16 +63106,15 @@ 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. @@ -63777,8 +63770,8 @@ class ObjCBlock43 extends _ObjCBlockBase { ObjCBlock43.fromFunctionPointer( AVFAudio lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( diff --git a/example/objective_c/pubspec.yaml b/example/objective_c/pubspec.yaml index c06b7a0a..4cedaa34 100644 --- a/example/objective_c/pubspec.yaml +++ b/example/objective_c/pubspec.yaml @@ -5,7 +5,7 @@ name: objective_c_example environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/shared_bindings/pubspec.yaml b/example/shared_bindings/pubspec.yaml index 23008d23..2f270f10 100644 --- a/example/shared_bindings/pubspec.yaml +++ b/example/shared_bindings/pubspec.yaml @@ -5,7 +5,7 @@ name: shared_bindings environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: cli_util: ^0.4.0 diff --git a/example/simple/generated_bindings.dart b/example/simple/generated_bindings.dart index b26a8ac7..71f0414a 100644 --- a/example/simple/generated_bindings.dart +++ b/example/simple/generated_bindings.dart @@ -81,9 +81,8 @@ class NativeLibrary { } late final _dividePtr = _lookup< - ffi - .NativeFunction Function(ffi.Int, ffi.Int)>>( - 'divide'); + ffi.NativeFunction< + ffi.Pointer 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 bef37902..ea435727 100644 --- a/example/simple/pubspec.yaml +++ b/example/simple/pubspec.yaml @@ -5,7 +5,7 @@ name: simple_example environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ffi: ^2.0.1 diff --git a/example/swift/pubspec.yaml b/example/swift/pubspec.yaml index de19bf24..07d93eba 100644 --- a/example/swift/pubspec.yaml +++ b/example/swift/pubspec.yaml @@ -5,7 +5,7 @@ name: swift_example environment: - sdk: ">=3.2.0-42.1.beta <4.0.0" + sdk: ">=3.0.0 <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 2a8783aa..f741f7fa 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)>>)>(); + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>)>(); late final _sel_descriptionFunction1 = _registerName1("descriptionFunction"); ffi.Pointer< @@ -22546,8 +22546,8 @@ class SwiftLibrary { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi - .NativeFunction)>>, + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>, 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,11 +34838,7 @@ class ObjCBlock4 extends _ObjCBlockBase { /// Creates a block from a C function pointer. ObjCBlock4.fromFunctionPointer( SwiftLibrary lib, - ffi.Pointer< - ffi - .NativeFunction< - ffi.Bool Function(ffi.Pointer arg0, - NSUInteger arg1, ffi.Pointer arg2)>> + ffi.Pointer arg0, NSUInteger arg1, ffi.Pointer arg2)>> ptr) : this._( lib._newBlock1( @@ -39402,8 +39398,8 @@ class ObjCBlock15 extends _ObjCBlockBase { ObjCBlock15.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -41811,8 +41807,8 @@ class ObjCBlock16 extends _ObjCBlockBase { void call() { return _id.ref.invoke .cast< - ffi - .NativeFunction block)>>() + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer<_ObjCBlock> block)>>() .asFunction block)>()(_id); } @@ -43094,8 +43090,8 @@ class ObjCBlock17 extends _ObjCBlockBase { ObjCBlock17.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -46336,8 +46332,7 @@ 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) @@ -52437,8 +52432,8 @@ class ObjCBlock29 extends _ObjCBlockBase { ObjCBlock29.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -54376,8 +54371,8 @@ class ObjCBlock30 extends _ObjCBlockBase { ObjCBlock30.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -55861,8 +55856,8 @@ class NSPointerFunctions extends NSObject { ffi.Pointer Function( ffi.Pointer, ffi.Pointer< - ffi - .NativeFunction)>>, + ffi.NativeFunction< + NSUInteger Function(ffi.Pointer)>>, ffi.Bool)>> get acquireFunction { return _lib._objc_msgSend_803(_id, _lib._sel_acquireFunction1); } @@ -57621,8 +57616,8 @@ class ObjCBlock33 extends _ObjCBlockBase { ObjCBlock33.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -58637,8 +58632,8 @@ class ObjCBlock35 extends _ObjCBlockBase { ObjCBlock35.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -58705,8 +58700,8 @@ class ObjCBlock36 extends _ObjCBlockBase { ObjCBlock36.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -61020,8 +61015,8 @@ class ObjCBlock38 extends _ObjCBlockBase { ObjCBlock38.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( @@ -61245,8 +61240,7 @@ 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) @@ -62574,8 +62568,8 @@ class ObjCBlock43 extends _ObjCBlockBase { ObjCBlock43.fromFunctionPointer( SwiftLibrary lib, ffi.Pointer< - ffi - .NativeFunction arg0)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer arg0)>> ptr) : this._( lib._newBlock1( diff --git a/lib/src/code_generator/objc_block.dart b/lib/src/code_generator/objc_block.dart index 7bbb4c0e..1a2dbed3 100644 --- a/lib/src/code_generator/objc_block.dart +++ b/lib/src/code_generator/objc_block.dart @@ -58,7 +58,7 @@ class ObjCBlock extends BindingType { params.add(Parameter(name: 'arg$i', type: argTypes[i])); } - final isVoid = returnType == voidType; + final isVoid = returnType == NativeType(SupportedNativeType.Void); final voidPtr = PointerType(voidType).getCType(w); final blockPtr = PointerType(builtInFunctions.blockStruct); final funcType = FunctionType(returnType: returnType, parameters: params); @@ -78,8 +78,6 @@ 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)); @@ -138,10 +136,6 @@ 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< @@ -150,40 +144,13 @@ 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/header_parser/clang_bindings/clang_bindings.dart b/lib/src/header_parser/clang_bindings/clang_bindings.dart index fc5ca177..4c5fba22 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>( - 'clang_Cursor_getObjCPropertyAttributes'); + ffi.NativeFunction< + ffi.UnsignedInt Function(CXCursor, + ffi.UnsignedInt)>>('clang_Cursor_getObjCPropertyAttributes'); late final _clang_Cursor_getObjCPropertyAttributes = _clang_Cursor_getObjCPropertyAttributesPtr .asFunction(); diff --git a/pubspec.yaml b/pubspec.yaml index ae45a104..3a8e0c15 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,10 +3,8 @@ # BSD-style license that can be found in the LICENSE file. name: ffigen -version: 10.0.0-dev.0 -description: > - Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift - files. +version: 9.0.1 +description: Generator for FFI bindings, using LibClang to parse C header files. repository: https://github.com/dart-lang/ffigen topics: @@ -15,7 +13,7 @@ topics: - codegen environment: - sdk: ">=3.2.0-114.0.dev <4.0.0" + sdk: ">=3.0.0 <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 ff7dc120..015821ea 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,9 +29,8 @@ class Bindings { } late final _test1Ptr = _lookup< - ffi - .NativeFunction)>>( - 'test1'); + ffi.NativeFunction< + ffi.Bool Function(ffi.Bool, ffi.Pointer)>>('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 7b6682c4..7475b09d 100644 --- a/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart +++ b/test/header_parser_tests/expected_bindings/_expected_functions_bindings.dart @@ -128,9 +128,8 @@ class NativeLibrary { } late final _diffCharsPtr = _lookup< - ffi - .NativeFunction>( - 'diffChars'); + ffi.NativeFunction< + ffi.Char Function(ffi.UnsignedChar, ffi.SignedChar)>>('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 2a769db2..2b2fe8a3 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.Pointer< + ffi.NativeFunction>> 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 f4edb598..b93c74f1 100644 --- a/test/large_integration_tests/_expected_cjson_bindings.dart +++ b/test/large_integration_tests/_expected_cjson_bindings.dart @@ -54,9 +54,8 @@ class CJson { } late final _cJSON_ParsePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_Parse'); + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('cJSON_Parse'); late final _cJSON_Parse = _cJSON_ParsePtr .asFunction Function(ffi.Pointer)>(); @@ -91,9 +90,8 @@ class CJson { } late final _cJSON_PrintPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_Print'); + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer)>>('cJSON_Print'); late final _cJSON_Print = _cJSON_PrintPtr .asFunction Function(ffi.Pointer)>(); @@ -106,9 +104,9 @@ class CJson { } late final _cJSON_PrintUnformattedPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_PrintUnformatted'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_PrintUnformatted'); late final _cJSON_PrintUnformatted = _cJSON_PrintUnformattedPtr .asFunction Function(ffi.Pointer)>(); @@ -269,9 +267,9 @@ class CJson { } late final _cJSON_GetStringValuePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_GetStringValue'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_GetStringValue'); late final _cJSON_GetStringValue = _cJSON_GetStringValuePtr .asFunction Function(ffi.Pointer)>(); @@ -482,9 +480,9 @@ class CJson { } late final _cJSON_CreateStringPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateString'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateString'); late final _cJSON_CreateString = _cJSON_CreateStringPtr .asFunction Function(ffi.Pointer)>(); @@ -497,9 +495,9 @@ class CJson { } late final _cJSON_CreateRawPtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateRaw'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateRaw'); late final _cJSON_CreateRaw = _cJSON_CreateRawPtr .asFunction Function(ffi.Pointer)>(); @@ -532,9 +530,9 @@ class CJson { } late final _cJSON_CreateStringReferencePtr = _lookup< - ffi - .NativeFunction Function(ffi.Pointer)>>( - 'cJSON_CreateStringReference'); + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer)>>('cJSON_CreateStringReference'); late final _cJSON_CreateStringReference = _cJSON_CreateStringReferencePtr .asFunction Function(ffi.Pointer)>(); @@ -1182,9 +1180,9 @@ class CJson { } late final _cJSON_SetNumberHelperPtr = _lookup< - ffi - .NativeFunction, ffi.Double)>>( - 'cJSON_SetNumberHelper'); + ffi.NativeFunction< + ffi.Double Function( + ffi.Pointer, ffi.Double)>>('cJSON_SetNumberHelper'); late final _cJSON_SetNumberHelper = _cJSON_SetNumberHelperPtr .asFunction, double)>(); @@ -1239,13 +1237,12 @@ final class cJSON extends ffi.Struct { } final class cJSON_Hooks extends ffi.Struct { - external ffi - .Pointer Function(ffi.Size sz)>> + external ffi.Pointer< + ffi.NativeFunction Function(ffi.Size sz)>> malloc_fn; - external ffi - .Pointer ptr)>> - free_fn; + external ffi.Pointer< + ffi.NativeFunction 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 2bc76881..22c6f266 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>( - 'clang_VirtualFileOverlay_setCaseSensitivity'); + ffi.NativeFunction< + ffi.Int32 Function(CXVirtualFileOverlay, + ffi.Int)>>('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.NativeFunction< + ffi.Void Function(CXIndex, ffi.Pointer)>>( 'clang_CXIndex_setInvocationEmissionPathOption'); late final _clang_CXIndex_setInvocationEmissionPathOption = _clang_CXIndex_setInvocationEmissionPathOptionPtr @@ -453,9 +453,9 @@ class LibClang { } late final _clang_isFileMultipleIncludeGuardedPtr = _lookup< - ffi - .NativeFunction>( - 'clang_isFileMultipleIncludeGuarded'); + ffi.NativeFunction< + ffi.UnsignedInt Function(CXTranslationUnit, + CXFile)>>('clang_isFileMultipleIncludeGuarded'); late final _clang_isFileMultipleIncludeGuarded = _clang_isFileMultipleIncludeGuardedPtr .asFunction(); @@ -943,9 +943,9 @@ class LibClang { } late final _clang_disposeSourceRangeListPtr = _lookup< - ffi - .NativeFunction)>>( - 'clang_disposeSourceRangeList'); + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer)>>('clang_disposeSourceRangeList'); late final _clang_disposeSourceRangeList = _clang_disposeSourceRangeListPtr .asFunction)>(); @@ -3586,9 +3586,9 @@ class LibClang { } late final _clang_constructUSR_ObjCIvarPtr = _lookup< - ffi - .NativeFunction, CXString)>>( - 'clang_constructUSR_ObjCIvar'); + ffi.NativeFunction< + CXString Function( + ffi.Pointer, 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)>>( - 'clang_constructUSR_ObjCProperty'); + ffi.NativeFunction< + CXString Function(ffi.Pointer, + 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>( - 'clang_Cursor_getObjCPropertyAttributes'); + ffi.NativeFunction< + ffi.UnsignedInt Function(CXCursor, + ffi.UnsignedInt)>>('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>( - 'clang_getTokenExtent'); + ffi.NativeFunction< + CXSourceRange Function( + CXTranslationUnit, CXToken)>>('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.NativeFunction< + ffi.Int32 Function(CXCursor C, CXClientData client_data)>>; 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 984fad3c..af6cccf4 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)>> + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>> arg1, ffi.Pointer arg2, ) { @@ -1410,9 +1410,9 @@ class SQLite { } late final _sqlite3_randomnessPtr = _lookup< - ffi - .NativeFunction)>>( - 'sqlite3_randomness'); + ffi.NativeFunction< + ffi.Void Function( + ffi.Int, ffi.Pointer)>>('sqlite3_randomness'); late final _sqlite3_randomness = _sqlite3_randomnessPtr .asFunction)>(); @@ -4733,11 +4733,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_function'); late final _sqlite3_create_function = _sqlite3_create_functionPtr.asFunction< int Function( @@ -4811,11 +4810,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_function16'); late final _sqlite3_create_function16 = _sqlite3_create_function16Ptr.asFunction< @@ -4896,10 +4894,9 @@ 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< @@ -4990,10 +4987,9 @@ 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< @@ -5298,9 +5294,9 @@ class SQLite { } late final _sqlite3_value_int64Ptr = _lookup< - ffi - .NativeFunction)>>( - 'sqlite3_value_int64'); + ffi.NativeFunction< + sqlite3_int64 Function( + ffi.Pointer)>>('sqlite3_value_int64'); late final _sqlite3_value_int64 = _sqlite3_value_int64Ptr .asFunction)>(); @@ -8365,9 +8361,9 @@ class SQLite { } late final _sqlite3_vfs_registerPtr = _lookup< - ffi - .NativeFunction, ffi.Int)>>( - 'sqlite3_vfs_register'); + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, ffi.Int)>>('sqlite3_vfs_register'); late final _sqlite3_vfs_register = _sqlite3_vfs_registerPtr .asFunction, int)>(); @@ -9760,9 +9756,8 @@ class SQLite { } late final _sqlite3_logPtr = _lookup< - ffi - .NativeFunction)>>( - 'sqlite3_log'); + ffi.NativeFunction< + ffi.Void Function(ffi.Int, ffi.Pointer)>>('sqlite3_log'); late final _sqlite3_log = _sqlite3_logPtr.asFunction)>(); @@ -10694,22 +10689,21 @@ 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( @@ -10810,9 +10804,8 @@ final class sqlite3_vfs extends ffi.Struct { xRandomness; external ffi.Pointer< - ffi - .NativeFunction, ffi.Int)>> - xSleep; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>> xSleep; external ffi.Pointer< ffi.NativeFunction< @@ -10860,12 +10853,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 @@ -10876,7 +10869,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 @@ -10884,12 +10877,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() @@ -10991,9 +10984,8 @@ final class sqlite3_module extends ffi.Struct { ffi.Pointer> ppCursor)>> xOpen; external ffi.Pointer< - ffi - .NativeFunction)>> - xClose; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer)>> xClose; external ffi.Pointer< ffi.NativeFunction< @@ -11005,13 +10997,12 @@ final class sqlite3_module extends ffi.Struct { ffi.Pointer>)>> xFilter; external ffi.Pointer< - ffi - .NativeFunction)>> - xNext; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer)>> xNext; external ffi.Pointer< - ffi - .NativeFunction)>> xEof; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer)>> xEof; external ffi.Pointer< ffi.NativeFunction< @@ -11072,24 +11063,21 @@ 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)>> - xSavepoint; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>> xSavepoint; external ffi.Pointer< - ffi - .NativeFunction, ffi.Int)>> - xRelease; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>> xRelease; external ffi.Pointer< - ffi - .NativeFunction, ffi.Int)>> - xRollbackTo; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, 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; } @@ -11308,8 +11296,8 @@ final class sqlite3_mutex_methods extends ffi.Struct { external ffi.Pointer> xMutexEnd; - external ffi - .Pointer Function(ffi.Int)>> + external ffi.Pointer< + ffi.NativeFunction Function(ffi.Int)>> xMutexAlloc; external ffi.Pointer< @@ -11320,20 +11308,20 @@ final class sqlite3_mutex_methods extends ffi.Struct { ffi.NativeFunction)>> xMutexEnter; - external ffi - .Pointer)>> + external ffi.Pointer< + ffi.NativeFunction)>> xMutexTry; external ffi.Pointer< ffi.NativeFunction)>> xMutexLeave; - external ffi - .Pointer)>> + external ffi.Pointer< + ffi.NativeFunction)>> xMutexHeld; - external ffi - .Pointer)>> + external ffi.Pointer< + ffi.NativeFunction)>> xMutexNotheld; } @@ -11356,11 +11344,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< @@ -11412,11 +11400,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< @@ -11501,7 +11489,7 @@ final class sqlite3_rtree_geometry extends ffi.Struct { /// Called by SQLite to clean up pUser external ffi - .Pointer)>> + .Pointer)>> xDelUser; } @@ -11530,7 +11518,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 @@ -11793,8 +11781,8 @@ final class Fts5ExtensionApi extends ffi.Struct { ffi.NativeFunction< ffi.Pointer Function(ffi.Pointer)>> xUserData; - external ffi - .Pointer)>> + external ffi.Pointer< + ffi.NativeFunction)>> xColumnCount; external ffi.Pointer< @@ -11824,14 +11812,13 @@ final class Fts5ExtensionApi extends ffi.Struct { ffi.Int, ffi.Int)>>)>> xTokenize; - external ffi - .Pointer)>> + external ffi.Pointer< + ffi.NativeFunction)>> xPhraseCount; external ffi.Pointer< - ffi - .NativeFunction, ffi.Int)>> - xPhraseSize; + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Int)>> xPhraseSize; external ffi.Pointer< ffi.NativeFunction< @@ -11981,8 +11968,8 @@ final class fts5_api extends ffi.Struct { ffi.Pointer pContext, ffi.Pointer pTokenizer, ffi.Pointer< - ffi - .NativeFunction)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>> xDestroy)>> xCreateTokenizer; /// Find an existing tokenizer @@ -12003,8 +11990,8 @@ final class fts5_api extends ffi.Struct { ffi.Pointer pContext, fts5_extension_function xFunction, ffi.Pointer< - ffi - .NativeFunction)>> + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer)>> xDestroy)>> xCreateFunction; } diff --git a/test/native_objc_test/block_test.dart b/test/native_objc_test/block_test.dart index 0253eaf1..5803ec13 100644 --- a/test/native_objc_test/block_test.dart +++ b/test/native_objc_test/block_test.dart @@ -5,7 +5,6 @@ // Objective C support is only available on mac. @TestOn('mac-os') -import 'dart:async'; import 'dart:ffi'; import 'dart:io'; @@ -59,8 +58,8 @@ void main() { }); test('Block from function pointer', () { - final block = - IntBlock.fromFunctionPointer(lib, Pointer.fromFunction(_add100, 999)); + final block = ObjCBlock.fromFunctionPointer( + lib, Pointer.fromFunction(_add100, 999)); final blockTester = BlockTester.makeFromBlock_(lib, block); blockTester.pokeBlock(); expect(blockTester.call_(123), 223); @@ -72,99 +71,16 @@ void main() { } test('Block from function', () { - final block = IntBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock.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 = VoidBlock.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 = VoidBlock.listener(lib, () { - value = 123; - hasRun.complete(); - }); - - final thread = BlockTester.callOnNewThread_(lib, block); - thread.start(); - - await hasRun.future; - expect(value, 123); - }); - - test('Float block', () { - final block = FloatBlock.fromFunction(lib, (double x) { - return x + 4.56; - }); - expect(block(1.23), closeTo(5.79, 1e-6)); - expect(BlockTester.callFloatBlock_(lib, block), closeTo(5.79, 1e-6)); - }); - - test('Double block', () { - final block = DoubleBlock.fromFunction(lib, (double x) { - return x + 4.56; - }); - expect(block(1.23), closeTo(5.79, 1e-6)); - expect(BlockTester.callDoubleBlock_(lib, block), closeTo(5.79, 1e-6)); - }); - - test('Struct block', () { - final inputPtr = calloc(); - final input = inputPtr.ref; - input.x = 1.2; - input.y = 3.4; - input.z = 5.6; - input.w = 7.8; - - final tempPtr = calloc(); - final temp = tempPtr.ref; - final block = Vec4Block.fromFunction(lib, (Vec4 v) { - // Twiddle the Vec4 components. - temp.x = v.y; - temp.y = v.z; - temp.z = v.w; - temp.w = v.x; - return temp; - }); - - final result1 = block(input); - expect(result1.x, 3.4); - expect(result1.y, 5.6); - expect(result1.z, 7.8); - expect(result1.w, 1.2); - - final result2Ptr = calloc(); - final result2 = result2Ptr.ref; - BlockTester.callVec4Block_(lib, result2Ptr, block); - expect(result2.x, 3.4); - expect(result2.y, 5.6); - expect(result2.z, 7.8); - expect(result2.w, 1.2); - - calloc.free(inputPtr); - calloc.free(tempPtr); - calloc.free(result2Ptr); - }); - Pointer funcPointerBlockRefCountTest() { - final block = - IntBlock.fromFunctionPointer(lib, Pointer.fromFunction(_add100, 999)); + final block = ObjCBlock.fromFunctionPointer( + lib, Pointer.fromFunction(_add100, 999)); expect(BlockTester.getBlockRetainCount_(lib, block.pointer.cast()), 1); return block.pointer.cast(); } @@ -176,7 +92,7 @@ void main() { }); Pointer funcBlockRefCountTest() { - final block = IntBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock.fromFunction(lib, makeAdder(4000)); expect(BlockTester.getBlockRetainCount_(lib, block.pointer.cast()), 1); return block.pointer.cast(); } @@ -188,7 +104,7 @@ void main() { }); test('Block fields have sensible values', () { - final block = IntBlock.fromFunction(lib, makeAdder(4000)); + final block = ObjCBlock.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 a864f2ef..bdd37a79 100644 --- a/test/native_objc_test/block_test.m +++ b/test/native_objc_test/block_test.m @@ -3,20 +3,8 @@ // BSD-style license that can be found in the LICENSE file. #import -#import - -typedef struct { - double x; - double y; - double z; - double w; -} Vec4; typedef int32_t (^IntBlock)(int32_t); -typedef float (^FloatBlock)(float); -typedef double (^DoubleBlock)(double); -typedef Vec4 (^Vec4Block)(Vec4); -typedef void (^VoidBlock)(); // Wrapper around a block, so that our Dart code can test creating and invoking // blocks in Objective C code. @@ -29,11 +17,6 @@ + (uint64_t)getBlockRetainCount:(void*)block; - (int32_t)call:(int32_t)x; - (IntBlock)getBlock; - (void)pokeBlock; -+ (void)callOnSameThread:(VoidBlock)block; -+ (NSThread*)callOnNewThread:(VoidBlock)block; -+ (float)callFloatBlock:(FloatBlock)block; -+ (double)callDoubleBlock:(DoubleBlock)block; -+ (Vec4)callVec4Block:(Vec4Block)block; @end @implementation BlockTester @@ -90,30 +73,4 @@ - (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]; -} - -+ (float)callFloatBlock:(FloatBlock)block { - return block(1.23); -} - -+ (double)callDoubleBlock:(DoubleBlock)block { - return block(1.23); -} - -+ (Vec4)callVec4Block:(Vec4Block)block { - Vec4 vec4; - vec4.x = 1.2; - vec4.y = 3.4; - vec4.z = 5.6; - vec4.w = 7.8; - return block(vec4); -} - @end