From d42c833d9dbc78804f163ed6afd1784655326045 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Fri, 10 Jan 2025 15:45:39 +1100 Subject: [PATCH] Support blocking blocks --- .../lib/src/code_generator/objc_block.dart | 168 ++- .../objc_built_in_functions.dart | 72 +- .../ffigen/lib/src/code_generator/writer.dart | 15 +- .../test/native_objc_test/block_test.dart | 79 +- pkgs/objective_c/lib/src/internal.dart | 39 +- .../src/objective_c_bindings_generated.dart | 1344 +++++++---------- .../src/objective_c_bindings_generated.m | 282 ++-- pkgs/objective_c/test/main.c | 2 +- pkgs/objective_c/test/setup.dart | 2 +- 9 files changed, 913 insertions(+), 1090 deletions(-) diff --git a/pkgs/ffigen/lib/src/code_generator/objc_block.dart b/pkgs/ffigen/lib/src/code_generator/objc_block.dart index 81bba4ab9..56c44c722 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_block.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_block.dart @@ -15,6 +15,8 @@ class ObjCBlock extends BindingType { final List params; final bool returnsRetained; late final ObjCBlockWrapperFuncs _blockWrappers; + late final _FnTypeHelper _typeHelper; + late final _FnTypeHelper _blockingTypeHelper; factory ObjCBlock({ required Type returnType, @@ -108,9 +110,10 @@ class ObjCBlock extends BindingType { final voidPtr = PointerType(voidType); final blockPtr = PointerType(objCBlockType); - final func = _FnHelper(w, returnType, params); - final blockingFunc = _FnHelper(w, returnType, [ + _typeHelper = _FnTypeHelper(w, returnType, params); + + _blockingTypeHelper = _FnTypeHelper(w, returnType, [ Parameter(type: voidPtr, name: 'waiter', objCConsumed: false), ...params, ]); @@ -144,12 +147,9 @@ class ObjCBlock extends BindingType { ObjCBuiltInFunctions.registerBlockClosure.gen(w); final getBlockClosure = ObjCBuiltInFunctions.getBlockClosure.gen(w); final releaseFn = ObjCBuiltInFunctions.objectRelease.gen(w); - final wrapBlockingBlockFn = ObjCBuiltInFunctions.wrapBlockingBlock.gen(w); + final pkgNewClosureBlock = ObjCBuiltInFunctions.newClosureBlock.gen(w); + final pkgNewBlockingBlock = ObjCBuiltInFunctions.newBlockingBlock.gen(w); final signalWaiterFn = ObjCBuiltInFunctions.signalWaiter.gen(w); - final blockClosureDisposePort = - ObjCBuiltInFunctions.blockClosureDisposePort.gen(w); - final disposeObjCBlockWithClosure = - ObjCBuiltInFunctions.disposeObjCBlockWithClosure.gen(w); final returnFfiDartType = returnType.getFfiDartType(w); final voidPtrCType = voidPtr.getCType(w); final int64Type = NativeType(SupportedNativeType.int64).getCType(w); @@ -161,47 +161,46 @@ class ObjCBlock extends BindingType { // Write the function pointer based trampoline function. s.write(''' $returnFfiDartType $funcPtrTrampoline( - $blockCType block, int closureId, ${func.paramsFfiDartType}) => - ${w.ffiLibraryPrefix}.Pointer<${func.natFnFfiDartType}>.fromAddress(closureId) - .asFunction<${func.ffiDartType}>()(${func.paramsNameOnly}); + $blockCType block, int closureId, ${_typeHelper.paramsFfiDartType}) => + ${w.ffiLibraryPrefix}.Pointer<${_typeHelper.natFnFfiDartType}>.fromAddress(closureId).asFunction<${_typeHelper.ffiDartType}>()(${_typeHelper.paramsNameOnly}); final $funcPtrCallable = ${w.ffiLibraryPrefix}.Pointer.fromFunction< - ${func.trampCType}>($funcPtrTrampoline $exceptionalReturn); + ${_typeHelper.trampCType}>($funcPtrTrampoline $exceptionalReturn); '''); // Write the closure based trampoline function. s.write(''' $returnFfiDartType $closureTrampoline( - $blockCType block, int closureId, ${func.paramsFfiDartType}) => - ($getBlockClosure(closureId) as ${func.ffiDartType})(${func.paramsNameOnly}); + $blockCType block, int closureId, ${_typeHelper.paramsFfiDartType}) => + ($getBlockClosure(closureId) as ${_typeHelper.ffiDartType})(${_typeHelper.paramsNameOnly}); final $closureCallable = ${w.ffiLibraryPrefix}.Pointer.fromFunction< - ${func.trampCType}>($closureTrampoline $exceptionalReturn); + ${_typeHelper.trampCType}>($closureTrampoline $exceptionalReturn); '''); if (hasListener) { // Write the listener trampoline function. s.write(''' $returnFfiDartType $listenerTrampoline( - $blockCType block, int closureId, ${func.paramsFfiDartType}) { - ($getBlockClosure(closureId) as ${func.ffiDartType})(${func.paramsNameOnly}); + $blockCType block, int closureId, ${_typeHelper.paramsFfiDartType}) { + ($getBlockClosure(closureId) as ${_typeHelper.ffiDartType})(${_typeHelper.paramsNameOnly}); $releaseFn(block.cast()); } -${func.trampNatCallType} $listenerCallable = ${func.trampNatCallType}.listener( - $listenerTrampoline $exceptionalReturn)..keepIsolateAlive = false; -$returnFfiDartType $blockingTrampoline( - $blockCType block, int closureId, ${blockingFunc.paramsFfiDartType}) { +${_typeHelper.trampNatCallType} $listenerCallable = ${_typeHelper.trampNatCallType}.listener( + $listenerTrampoline $exceptionalReturn)..keepIsolateAlive = false; +$returnFfiDartType $blockingTrampoline($blockCType block, int closureId, + ${_blockingTypeHelper.paramsFfiDartType}) { try { - ($getBlockClosure(closureId) as ${func.ffiDartType})(${func.paramsNameOnly}); + ($getBlockClosure(closureId) as ${_typeHelper.ffiDartType})(${_typeHelper.paramsNameOnly}); } catch (e) { } finally { $signalWaiterFn(waiter); $releaseFn(block.cast()); } } -${blockingFunc.trampNatCallType} $blockingCallable = - ${blockingFunc.trampNatCallType}.isolateLocal( +${_blockingTypeHelper.trampNatCallType} $blockingCallable = + ${_blockingTypeHelper.trampNatCallType}.isolateLocal( $blockingTrampoline $exceptionalReturn)..keepIsolateAlive = false; -${blockingFunc.trampNatCallType} $blockingListenerCallable = - ${blockingFunc.trampNatCallType}.listener( +${_blockingTypeHelper.trampNatCallType} $blockingListenerCallable = + ${_blockingTypeHelper.trampNatCallType}.listener( $blockingTrampoline $exceptionalReturn)..keepIsolateAlive = false; '''); } @@ -221,7 +220,7 @@ ${blockingFunc.trampNatCallType} $blockingListenerCallable = objCRetain: true, objCAutorelease: !returnsRetained, ); - final convFn = '(${func.paramsFfiDartType}) => $convFnInvocation'; + final convFn = '(${_typeHelper.paramsFfiDartType}) => $convFnInvocation'; // Write the wrapper class. s.write(''' @@ -238,7 +237,7 @@ abstract final class $name { /// 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. - // static $blockType fromFunctionPointer(${func.natFnPtrCType} ptr) => + // static $blockType fromFunctionPointer(${_typeHelper.natFnPtrCType} ptr) => // $blockType($newPointerBlock($funcPtrCallable, ptr.cast()), // retain: false, release: true); @@ -247,18 +246,17 @@ abstract final class $name { /// 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. - static $blockType fromFunction(${func.dartType} fn) => - $blockType($newClosureBlock( - $closureCallable, $registerBlockClosure($convFn), - $blockClosureDisposePort, $disposeObjCBlockWithClosure), - retain: false, release: true); + static $blockType fromFunction(${_typeHelper.dartType} fn) => + $blockType($pkgNewClosureBlock( + $convFn, $closureCallable.cast(), + $newClosureBlock), retain: false, release: true); '''); // Listener block constructor is only available for void blocks. if (hasListener) { // This snippet is the same as the convFn above, except that the params // don't need to be retained because they've already been retained by - // _blockWrappers.listenerWrapper. + // _blockWrappers.newListenerBlock. final listenerConvertedFnArgs = params .map((p) => p.type.convertFfiDartTypeToDartType(w, p.name, objCRetain: false)) @@ -270,9 +268,9 @@ abstract final class $name { objCAutorelease: !returnsRetained, ); final listenerConvFn = - '(${func.paramsFfiDartType}) => $listenerConvFnInvocation'; - final wrapListenerFn = _blockWrappers.listenerWrapper!.name; - final wrapBlockingFn = _blockWrappers.blockingWrapper!.name; + '(${_typeHelper.paramsFfiDartType}) => $listenerConvFnInvocation'; + final newListenerBlock = _blockWrappers.newListenerBlock!.name; + final newBlockingBlock = _blockWrappers.newBlockingBlock!.name; s.write(''' @@ -285,15 +283,10 @@ abstract final class $name { /// /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. - static $blockType listener(${func.dartType} fn) { - final raw = $newClosureBlock( - $listenerCallable.nativeFunction.cast(), - $registerBlockClosure($listenerConvFn), - $blockClosureDisposePort, $disposeObjCBlockWithClosure); - final wrapper = $wrapListenerFn(raw); - $releaseFn(raw.cast()); - return $blockType(wrapper, retain: false, release: true); - } + static $blockType listener(${_typeHelper.dartType} fn) => + $blockType($pkgNewClosureBlock( + $listenerConvFn, $listenerCallable.nativeFunction.cast(), + $newListenerBlock), retain: false, release: true); /// Creates a blocking block from a Dart function. /// @@ -304,20 +297,11 @@ abstract final class $name { /// This block does not keep the owner isolate alive. If the owner isolate has /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. - static $blockType blocking(${func.dartType} fn) { - final raw = $newClosureBlock( - $blockingCallable.nativeFunction.cast(), - $registerBlockClosure($listenerConvFn), - $blockClosureDisposePort, $disposeObjCBlockWithClosure); - final rawListener = $newClosureBlock( - $blockingListenerCallable.nativeFunction.cast(), - $registerBlockClosure($listenerConvFn), - $blockClosureDisposePort, $disposeObjCBlockWithClosure); - final wrapper = $wrapBlockingBlockFn($wrapBlockingFn, raw, rawListener); - $releaseFn(raw.cast()); - $releaseFn(rawListener.cast()); - return $blockType(wrapper, retain: false, release: true); - } + static $blockType blocking(${_typeHelper.dartType} fn) => + $blockType($pkgNewBlockingBlock( + $listenerConvFn, $blockingCallable.nativeFunction.cast(), + $blockingListenerCallable.nativeFunction.cast(), + $newBlockingBlock), retain: false, release: true); '''); } s.write('}\n\n'); @@ -339,7 +323,8 @@ abstract final class $name { s.write(''' /// Call operator for `$blockType`. extension $callExtension on $blockType { - ${returnType.getDartType(w)} call(${func.paramsDartType}) => $callMethod; + ${returnType.getDartType(w)} call(${_typeHelper.paramsDartType}) => + $callMethod; } '''); @@ -382,7 +367,11 @@ extension $callExtension on $blockType { final blockingName = w.objCLevelUniqueNamer.makeUnique('_BlockingTrampoline'); final trampolineArg = - _blockWrappers.trampolineType.getNativeType(varName: 'trampoline'); + _typeHelper.trampFnType.getNativeType(varName: 'trampoline'); + final blockingTrampolineArg = + _blockingTypeHelper.trampFnType.getNativeType(varName: 'tramp'); + final blockingListenerTrampolineArg = _blockingTypeHelper.trampFnType + .getNativeType(varName: 'listener_tramp'); final retainStr = returnsRetained ? 'NS_RETURNS_RETAINED' : ''; final dtorClass = '_${w.className}_BlockDestroyer'; @@ -400,10 +389,8 @@ __attribute__((visibility("default"))) __attribute__((used)) $blockTypeName $newClosureBlock( $trampolineArg, int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - $dtorClass* obj = [[$dtorClass alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + $dtorClass* obj = [$dtorClass + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block $blockTypeName weakBlk; $blockTypeName blk = ^$returnNativeType($argStr) { return trampoline(weakBlk, ${['obj.closure_id', ...noRetains].join(', ')}); @@ -414,36 +401,51 @@ $blockTypeName $newClosureBlock( '''); if (hasListener) { - final listenerWrapper = _blockWrappers.listenerWrapper!.name; - final blockingWrapper = _blockWrappers.blockingWrapper!.name; + final newListenerBlock = _blockWrappers.newListenerBlock!.name; + final newBlockingBlock = _blockWrappers.newBlockingBlock!.name; s.write(''' __attribute__((visibility("default"))) __attribute__((used)) -$blockTypeName $listenerWrapper($blockTypeName block) NS_RETURNS_RETAINED { - return ^void($argStr) { - ${generateRetain('block')}; - block(${retains.join(', ')}); +$blockTypeName $newListenerBlock( + $trampolineArg, int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + $dtorClass* obj = [$dtorClass + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block $blockTypeName weakBlk; + $blockTypeName blk = ^$returnNativeType($argStr) { + ${generateRetain('weakBlk')}; + return trampoline(weakBlk, ${['obj.closure_id', ...retains].join(', ')}); }; + weakBlk = blk; + return blk; } typedef $returnNativeType (^$blockingName)($blockingArgStr); __attribute__((visibility("default"))) __attribute__((used)) -$blockTypeName $blockingWrapper( - $blockingName block, $blockingName listenerBlock, +$blockTypeName $newBlockingBlock( + $blockingTrampolineArg, $blockingListenerTrampolineArg, + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void($argStr) { + $dtorClass* obj = [$dtorClass + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block $blockTypeName weakBlk; + $blockTypeName blk = ^$returnNativeType($argStr) { + ${generateRetain('weakBlk')}; if ([NSThread currentThread] == targetThread) { - ${generateRetain('block')}; - block(${blockingRetains.join(', ')}); + tramp(weakBlk, ${['obj.closure_id', ...blockingRetains].join(', ')}); } else { void* waiter = newWaiter(); - ${generateRetain('listenerBlock')}; - listenerBlock(${blockingListenerRetains.join(', ')}); + listener_tramp(weakBlk, ${[ + 'obj.closure_id', + ...blockingListenerRetains + ].join(', ')}); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } '''); } @@ -523,8 +525,9 @@ $blockTypeName $blockingWrapper( } } -class _FnHelper { +class _FnTypeHelper { late final NativeFunc natFnType; + late final FunctionType trampFnType; late final String natFnFfiDartType; late final String natFnPtrCType; late final String dartType; @@ -537,7 +540,7 @@ class _FnHelper { late final String paramsFfiDartType; late final String paramsDartType; - _FnHelper(Writer w, Type returnType, List params) { + _FnTypeHelper(Writer w, Type returnType, List params) { final fnType = FunctionType(returnType: returnType, parameters: params); natFnType = NativeFunc(fnType); natFnFfiDartType = natFnType.getFfiDartType(w); @@ -545,7 +548,7 @@ class _FnHelper { dartType = fnType.getDartType(w, writeArgumentNames: false); ffiDartType = fnType.getFfiDartType(w, writeArgumentNames: false); - final trampFnType = FunctionType( + trampFnType = FunctionType( returnType: returnType, parameters: [ Parameter( @@ -554,7 +557,8 @@ class _FnHelper { objCConsumed: false), Parameter( type: NativeType(SupportedNativeType.int64), - name: 'closure_id', objCConsumed: false), + name: 'closure_id', + objCConsumed: false), ...params, ], ); diff --git a/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart b/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart index 48c771d90..65e5d59ba 100644 --- a/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart +++ b/pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart @@ -33,7 +33,8 @@ class ObjCBuiltInFunctions { static const getProtocol = ObjCImport('getProtocol'); static const objectRelease = ObjCImport('objectRelease'); static const signalWaiter = ObjCImport('signalWaiter'); - static const wrapBlockingBlock = ObjCImport('wrapBlockingBlock'); + static const newBlockingBlock = ObjCImport('newBlockingBlock'); + static const newClosureBlock = ObjCImport('newClosureBlock'); static const blockClosureDisposePort = ObjCImport('blockClosureDisposePort'); static const disposeObjCBlockWithClosure = ObjCImport('disposeObjCBlockWithClosure'); @@ -215,20 +216,6 @@ class ObjCBuiltInFunctions { ObjCBlockWrapperFuncs getBlockTrampolines(ObjCBlock block) { final id = _methodSigId(block.returnType, block.params); final idHash = fnvHash32(id).toRadixString(36); - final trampolineType = FunctionType( - returnType: block.returnType, - parameters: [ - Parameter( - type: PointerType(objCBlockType), - name: 'block', - objCConsumed: false), - Parameter( - type: NativeType(SupportedNativeType.int64), - name: 'closure_id', - objCConsumed: false), - ...block.params, - ], - ); final dtorType = FunctionType( returnType: voidType, parameters: [ @@ -243,7 +230,6 @@ class ObjCBuiltInFunctions { ], ); return _blockTrampolines[id] ??= ObjCBlockWrapperFuncs( - trampolineType, Func( name: '_${wrapperName}_invokeBlock_$idHash', returnType: block.returnType, @@ -266,7 +252,7 @@ class ObjCBuiltInFunctions { parameters: [ Parameter( name: 'trampoline', - type: PointerType(NativeFunc(trampolineType)), + type: PointerType(voidType), objCConsumed: false), Parameter( type: NativeType(SupportedNativeType.int64), @@ -287,37 +273,53 @@ class ObjCBuiltInFunctions { useNameForLookup: true, ffiNativeConfig: const FfiNativeConfig(enabled: true), ), - // TODO: wrap*Block should become new*Block. block.hasListener - ? _blockTrampolineFunc('_${wrapperName}_wrapListenerBlock_$idHash') + ? _blockTrampolineFunc( + '_${wrapperName}_newListenerBlock_$idHash', dtorType) : null, block.hasListener - ? _blockTrampolineFunc('_${wrapperName}_wrapBlockingBlock_$idHash', + ? _blockTrampolineFunc( + '_${wrapperName}_newBlockingBlock_$idHash', dtorType, blocking: true) : null, ); } - Func _blockTrampolineFunc(String name, {bool blocking = false}) => Func( + Func _blockTrampolineFunc(String name, Type dtorType, + {bool blocking = false}) => + Func( name: name, returnType: PointerType(objCBlockType), parameters: [ Parameter( - name: 'block', - type: PointerType(objCBlockType), + name: 'trampoline', + type: PointerType(voidType), objCConsumed: false), - if (blocking) ...[ + if (blocking) Parameter( - name: 'listnerBlock', - type: PointerType(objCBlockType), + name: 'listener_trampoline', + type: PointerType(voidType), objCConsumed: false), + Parameter( + type: NativeType(SupportedNativeType.int64), + name: 'closure_id', + objCConsumed: false), + Parameter( + type: NativeType(SupportedNativeType.int64), + name: 'dispose_port', + objCConsumed: false), + Parameter( + name: 'dtor', + type: PointerType(NativeFunc(dtorType)), + objCConsumed: false), + if (blocking) ...[ Parameter( - name: 'newWaiter', + name: 'new_waiter', type: PointerType(NativeFunc(FunctionType( returnType: PointerType(voidType), parameters: []))), objCConsumed: false), Parameter( - name: 'awaitWaiter', + name: 'await_waiter', type: PointerType( NativeFunc(FunctionType(returnType: voidType, parameters: [ Parameter(type: PointerType(voidType), objCConsumed: false), @@ -341,24 +343,22 @@ class ObjCBuiltInFunctions { /// A native trampoline function for a listener block. class ObjCBlockWrapperFuncs extends AstNode { - final FunctionType trampolineType; final Func invokeBlock; final Func newClosureBlock; - final Func? listenerWrapper; - final Func? blockingWrapper; + final Func? newListenerBlock; + final Func? newBlockingBlock; bool objCBindingsGenerated = false; - ObjCBlockWrapperFuncs(this.trampolineType, this.invokeBlock, - this.newClosureBlock, this.listenerWrapper, this.blockingWrapper); + ObjCBlockWrapperFuncs(this.invokeBlock, this.newClosureBlock, + this.newListenerBlock, this.newBlockingBlock); @override void visitChildren(Visitor visitor) { super.visitChildren(visitor); - visitor.visit(trampolineType); visitor.visit(invokeBlock); visitor.visit(newClosureBlock); - visitor.visit(listenerWrapper); - visitor.visit(blockingWrapper); + visitor.visit(newListenerBlock); + visitor.visit(newBlockingBlock); } } diff --git a/pkgs/ffigen/lib/src/code_generator/writer.dart b/pkgs/ffigen/lib/src/code_generator/writer.dart index d313cfa8d..f1d9b8cb6 100644 --- a/pkgs/ffigen/lib/src/code_generator/writer.dart +++ b/pkgs/ffigen/lib/src/code_generator/writer.dart @@ -438,6 +438,7 @@ class Writer { for (final entryPoint in nativeEntryPoints) { s.write(_objcImport(entryPoint, outDir)); } + final dtorClass = '_${className}_BlockDestroyer'; s.write(''' #if !__has_feature(objc_arc) @@ -447,13 +448,23 @@ class Writer { id objc_retain(id); id objc_retainBlock(id); -@interface _${className}_BlockDestroyer : NSObject {} +@interface $dtorClass : NSObject {} @property int64_t closure_id; @property int64_t dispose_port; @property void (*dtor)(int64_t, int64_t); ++ (instancetype)new:(int64_t) closure_id disposePort:(int64_t) dispose_port + destructor:(void (*)(int64_t, int64_t)) dtor; - (void)dealloc; @end -@implementation _${className}_BlockDestroyer +@implementation $dtorClass ++ (instancetype)new:(int64_t) closure_id disposePort:(int64_t) dispose_port + destructor:(void (*)(int64_t, int64_t)) dtor { + $dtorClass* d = [[$dtorClass alloc] init]; + d.closure_id = closure_id; + d.dispose_port = dispose_port; + d.dtor = dtor; + return d; +} - (void)dealloc { self.dtor(self.dispose_port, self.closure_id); } @end '''); diff --git a/pkgs/ffigen/test/native_objc_test/block_test.dart b/pkgs/ffigen/test/native_objc_test/block_test.dart index 4f7912e51..2892f425b 100644 --- a/pkgs/ffigen/test/native_objc_test/block_test.dart +++ b/pkgs/ffigen/test/native_objc_test/block_test.dart @@ -123,7 +123,7 @@ void main() { } } - /*test('Blocking block same thread', () { + test('Blocking block same thread', () { int value = 0; final block = VoidBlock.blocking(() { waitSync(Duration(milliseconds: 100)); @@ -177,7 +177,7 @@ void main() { }); block(); expect(value, 123); - });*/ + }); test('Float block', () { final block = FloatBlock.fromFunction((double x) { @@ -462,8 +462,14 @@ void main() { expect(internal_for_testing.isClosureOfBlock(closureId), false); }, skip: !canDoGC); - (Pointer, Pointer, Pointer, int, int, int) - blockBlockDartCallRefCountTest() { + ( + Pointer, + Pointer, + Pointer, + int, + int, + int + ) blockBlockDartCallRefCountTest() { final pool = lib.objc_autoreleasePoolPush(); final inputBlock = IntBlock.fromFunction((int x) { return 5 * x; @@ -488,21 +494,12 @@ void main() { // One reference held by inputBlock object, another bound to the // outputBlock lambda. expect(blockRetainCount(inputBlock.ref.pointer), 2); - expect( - internal_for_testing - .isClosureOfBlock(inputBlockId), - true); + expect(internal_for_testing.isClosureOfBlock(inputBlockId), true); expect(blockRetainCount(blockBlock.ref.pointer), 1); - expect( - internal_for_testing - .isClosureOfBlock(blockBlockId), - true); + expect(internal_for_testing.isClosureOfBlock(blockBlockId), true); expect(blockRetainCount(outputBlock.ref.pointer), 1); - expect( - internal_for_testing - .isClosureOfBlock(outputBlockId), - true); + expect(internal_for_testing.isClosureOfBlock(outputBlockId), true); return ( inputBlock.ref.pointer, blockBlock.ref.pointer, @@ -514,26 +511,34 @@ void main() { } test('Calling a block block from Dart has correct ref counting', () async { - final (inputBlock, blockBlock, outputBlock, inputBlockId, blockBlockId, outputBlockId) = - blockBlockDartCallRefCountTest(); + final ( + inputBlock, + blockBlock, + outputBlock, + inputBlockId, + blockBlockId, + outputBlockId + ) = blockBlockDartCallRefCountTest(); doGC(); await Future.delayed(Duration.zero); // Let dispose message arrive. doGC(); await Future.delayed(Duration.zero); // Let dispose message arrive. expect(blockRetainCount(inputBlock), 0); - expect(internal_for_testing.isClosureOfBlock(inputBlockId), - false); + expect(internal_for_testing.isClosureOfBlock(inputBlockId), false); expect(blockRetainCount(blockBlock), 0); - expect(internal_for_testing.isClosureOfBlock(blockBlockId), - false); + expect(internal_for_testing.isClosureOfBlock(blockBlockId), false); expect(blockRetainCount(outputBlock), 0); - expect(internal_for_testing.isClosureOfBlock(outputBlockId), - false); + expect(internal_for_testing.isClosureOfBlock(outputBlockId), false); }, skip: !canDoGC); - (Pointer, Pointer, Pointer, int, int) - blockBlockObjCCallRefCountTest() { + ( + Pointer, + Pointer, + Pointer, + int, + int + ) blockBlockObjCCallRefCountTest() { final pool = lib.objc_autoreleasePoolPush(); late Pointer inputBlock; final blockBlock = @@ -553,16 +558,16 @@ void main() { expect(blockRetainCount(inputBlock), 1); expect(blockRetainCount(blockBlock.ref.pointer), 1); - expect( - internal_for_testing - .isClosureOfBlock(blockBlockId), - true); + expect(internal_for_testing.isClosureOfBlock(blockBlockId), true); expect(blockRetainCount(outputBlock.ref.pointer), 1); - expect( - internal_for_testing - .isClosureOfBlock(outputBlockId), - true); - return (inputBlock, blockBlock.ref.pointer, outputBlock.ref.pointer, blockBlockId, outputBlockId); + expect(internal_for_testing.isClosureOfBlock(outputBlockId), true); + return ( + inputBlock, + blockBlock.ref.pointer, + outputBlock.ref.pointer, + blockBlockId, + outputBlockId + ); } test('Calling a block block from ObjC has correct ref counting', () async { @@ -763,7 +768,7 @@ void main() { expect(objectRetainCount(rawDummyObject), 0); }, skip: !canDoGC); - /*test('Blocking block ref counting new thread', () async { + test('Blocking block ref counting new thread', () async { final completer = Completer(); DummyObject? dummyObject = DummyObject.new1(); DartObjectListenerBlock? block = @@ -794,7 +799,7 @@ void main() { expect(blockRetainCount(rawBlock), 0); expect(objectRetainCount(rawDummyObject), 0); - }, skip: !canDoGC);*/ + }, skip: !canDoGC); test('Block trampoline args converted to id', () { final objCBindings = diff --git a/pkgs/objective_c/lib/src/internal.dart b/pkgs/objective_c/lib/src/internal.dart index dcfb52ad4..fd8b61929 100644 --- a/pkgs/objective_c/lib/src/internal.dart +++ b/pkgs/objective_c/lib/src/internal.dart @@ -358,9 +358,7 @@ final _blockClosureDisposer = () { }, 'ObjCBlockClosureDisposer') ..keepIsolateAlive = false; }(); - -/// Only for use by ffigen bindings. -int get blockClosureDisposePort => _blockClosureDisposer.sendPort.nativePort; +typedef DisposeBlockFn = NativeFunction; /// Only for use by ffigen bindings. int registerBlockClosure(Function closure) { @@ -370,28 +368,39 @@ int registerBlockClosure(Function closure) { return _blockClosureRegistryLastId; } -/// Only for use by ffigen bindings. -typedef DisposeBlockFn = NativeFunction; -Pointer get disposeObjCBlockWithClosure => - Native.addressOf(c.disposeObjCBlockWithClosure); - /// Only for use by ffigen bindings. Function getBlockClosure(int id) { assert(_blockClosureRegistry.containsKey(id)); return _blockClosureRegistry[id]!; } +typedef NewClosureBlockFn = BlockPtr Function( + VoidPtr, int, int, Pointer); + +/// Only for use by ffigen bindings. +BlockPtr newClosureBlock( + Function closure, VoidPtr trampoline, NewClosureBlockFn nativeNew) => + nativeNew( + trampoline, + registerBlockClosure(closure), + _blockClosureDisposer.sendPort.nativePort, + Native.addressOf(c.disposeObjCBlockWithClosure), + ); + typedef NewWaiterFn = NativeFunction; typedef AwaitWaiterFn = NativeFunction; -typedef NativeWrapperFn = BlockPtr Function( - BlockPtr, BlockPtr, Pointer, Pointer); +typedef NewBlockingBlockFn = BlockPtr Function(VoidPtr, VoidPtr, int, int, + Pointer, Pointer, Pointer); /// Only for use by ffigen bindings. -BlockPtr wrapBlockingBlock( - NativeWrapperFn nativeWrapper, BlockPtr raw, BlockPtr rawListener) => - nativeWrapper( - raw, - rawListener, +BlockPtr newBlockingBlock(Function closure, VoidPtr trampoline, + VoidPtr listenerTrampoline, NewBlockingBlockFn nativeNew) => + nativeNew( + trampoline, + listenerTrampoline, + registerBlockClosure(closure), + _blockClosureDisposer.sendPort.nativePort, + Native.addressOf(c.disposeObjCBlockWithClosure), Native.addressOf(c.newWaiter), Native.addressOf(c.awaitWaiter), ); diff --git a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart index 14cdf0217..f2fbd2a25 100644 --- a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart +++ b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart @@ -209,17 +209,154 @@ external ffi.Pointer _ObjectiveCBindings_invokeBlock_ykn0t6( ffi.Pointer arg1, ); +@ffi.Native< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64 dispose_port, ffi.Int64 closure_id)>>, + ffi.Pointer Function()>>, + ffi.Pointer< + ffi.NativeFunction)>>)>( + isLeaf: true) +external ffi.Pointer + _ObjectiveCBindings_newBlockingBlock_18d6mda( + ffi.Pointer trampoline, + ffi.Pointer listener_trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, + ffi.Pointer Function()>> new_waiter, + ffi.Pointer)>> + await_waiter, +); + +@ffi.Native< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64 dispose_port, ffi.Int64 closure_id)>>, + ffi.Pointer Function()>>, + ffi.Pointer< + ffi.NativeFunction)>>)>( + isLeaf: true) +external ffi.Pointer + _ObjectiveCBindings_newBlockingBlock_1j2nt86( + ffi.Pointer trampoline, + ffi.Pointer listener_trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, + ffi.Pointer Function()>> new_waiter, + ffi.Pointer)>> + await_waiter, +); + +@ffi.Native< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64 dispose_port, ffi.Int64 closure_id)>>, + ffi.Pointer Function()>>, + ffi.Pointer< + ffi.NativeFunction)>>)>( + isLeaf: true) +external ffi.Pointer + _ObjectiveCBindings_newBlockingBlock_ovsamd( + ffi.Pointer trampoline, + ffi.Pointer listener_trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, + ffi.Pointer Function()>> new_waiter, + ffi.Pointer)>> + await_waiter, +); + +@ffi.Native< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64 dispose_port, ffi.Int64 closure_id)>>, + ffi.Pointer Function()>>, + ffi.Pointer< + ffi.NativeFunction)>>)>( + isLeaf: true) +external ffi.Pointer + _ObjectiveCBindings_newBlockingBlock_wjovn7( + ffi.Pointer trampoline, + ffi.Pointer listener_trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, + ffi.Pointer Function()>> new_waiter, + ffi.Pointer)>> + await_waiter, +); + +@ffi.Native< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64 dispose_port, ffi.Int64 closure_id)>>, + ffi.Pointer Function()>>, + ffi.Pointer< + ffi.NativeFunction)>>)>( + isLeaf: true) +external ffi.Pointer + _ObjectiveCBindings_newBlockingBlock_wjvic9( + ffi.Pointer trampoline, + ffi.Pointer listener_trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, + ffi.Pointer Function()>> new_waiter, + ffi.Pointer)>> + await_waiter, +); + @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.UnsignedLong Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer> arg2, - ffi.UnsignedLong arg3)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -228,16 +365,7 @@ external ffi.Pointer _ObjectiveCBindings_invokeBlock_ykn0t6( ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_17ap02x( - ffi.Pointer< - ffi.NativeFunction< - ffi.UnsignedLong Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer> arg2, - ffi.UnsignedLong arg3)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -248,14 +376,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.UnsignedLong arg2)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -264,15 +385,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_18d6mda( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.UnsignedLong arg2)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -283,12 +396,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer<_NSZone> Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -297,13 +405,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1a8cl66( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer<_NSZone> Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -314,14 +416,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -330,15 +425,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1c0c70u( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -349,10 +436,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -361,11 +445,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1ckyi24( - ffi.Pointer< - ffi.NativeFunction< - ffi.UnsignedLong Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -376,14 +456,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -392,15 +465,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1j2nt86( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -411,13 +476,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - instancetype Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -426,14 +485,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1m9h2n( - ffi.Pointer< - ffi.NativeFunction< - instancetype Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -444,12 +496,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -458,13 +505,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_1yesha9( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -475,15 +516,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - instancetype Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2, - ffi.Pointer> arg3)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -492,16 +525,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_e2pkq8( - ffi.Pointer< - ffi.NativeFunction< - instancetype Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2, - ffi.Pointer> arg3)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -512,10 +536,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -524,11 +545,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_e3qsqz( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -539,10 +556,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -551,11 +565,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_ovsamd( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function(ffi.Pointer block, - ffi.Int64 closure_id, ffi.Pointer arg0)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -566,13 +576,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -581,14 +585,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_ozkafd( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -599,15 +596,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2, - ffi.Pointer arg3)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -616,16 +605,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_u8b97m( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2, - ffi.Pointer arg3)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -636,13 +616,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -651,14 +625,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_w1e3k0( - ffi.Pointer< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -669,13 +636,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -684,14 +645,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_wjovn7( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -702,13 +656,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -717,14 +665,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_wjvic9( - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -735,13 +676,7 @@ external ffi.Pointer @ffi.Native< ffi.Pointer Function( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>>, + ffi.Pointer, ffi.Int64, ffi.Int64, ffi.Pointer< @@ -750,14 +685,7 @@ external ffi.Pointer ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer _ObjectiveCBindings_newClosureBlock_ykn0t6( - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer block, - ffi.Int64 closure_id, - ffi.Pointer arg0, - ffi.Pointer arg1)>> - trampoline, + ffi.Pointer trampoline, int closure_id, int dispose_port, ffi.Pointer< @@ -766,129 +694,104 @@ external ffi.Pointer dtor, ); -@ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer Function()>>, - ffi.Pointer< - ffi.NativeFunction)>>)>( - isLeaf: true) -external ffi.Pointer - _ObjectiveCBindings_wrapBlockingBlock_18d6mda( - ffi.Pointer block, - ffi.Pointer listnerBlock, - ffi.Pointer Function()>> newWaiter, - ffi.Pointer)>> - awaitWaiter, -); - -@ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer Function()>>, - ffi.Pointer< - ffi.NativeFunction)>>)>( - isLeaf: true) -external ffi.Pointer - _ObjectiveCBindings_wrapBlockingBlock_1j2nt86( - ffi.Pointer block, - ffi.Pointer listnerBlock, - ffi.Pointer Function()>> newWaiter, - ffi.Pointer)>> - awaitWaiter, -); - -@ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer Function()>>, - ffi.Pointer< - ffi.NativeFunction)>>)>( - isLeaf: true) -external ffi.Pointer - _ObjectiveCBindings_wrapBlockingBlock_ovsamd( - ffi.Pointer block, - ffi.Pointer listnerBlock, - ffi.Pointer Function()>> newWaiter, - ffi.Pointer)>> - awaitWaiter, -); - -@ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer Function()>>, - ffi.Pointer< - ffi.NativeFunction)>>)>( - isLeaf: true) -external ffi.Pointer - _ObjectiveCBindings_wrapBlockingBlock_wjovn7( - ffi.Pointer block, - ffi.Pointer listnerBlock, - ffi.Pointer Function()>> newWaiter, - ffi.Pointer)>> - awaitWaiter, -); - -@ffi.Native< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer Function()>>, - ffi.Pointer< - ffi.NativeFunction)>>)>( - isLeaf: true) -external ffi.Pointer - _ObjectiveCBindings_wrapBlockingBlock_wjvic9( - ffi.Pointer block, - ffi.Pointer listnerBlock, - ffi.Pointer Function()>> newWaiter, - ffi.Pointer)>> - awaitWaiter, -); - @ffi.Native< ffi.Pointer Function( - ffi.Pointer)>(isLeaf: true) + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, + ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer - _ObjectiveCBindings_wrapListenerBlock_18d6mda( - ffi.Pointer block, + _ObjectiveCBindings_newListenerBlock_18d6mda( + ffi.Pointer trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, ); @ffi.Native< ffi.Pointer Function( - ffi.Pointer)>(isLeaf: true) + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, + ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer - _ObjectiveCBindings_wrapListenerBlock_1j2nt86( - ffi.Pointer block, + _ObjectiveCBindings_newListenerBlock_1j2nt86( + ffi.Pointer trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, ); @ffi.Native< ffi.Pointer Function( - ffi.Pointer)>(isLeaf: true) + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, + ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer - _ObjectiveCBindings_wrapListenerBlock_ovsamd( - ffi.Pointer block, + _ObjectiveCBindings_newListenerBlock_ovsamd( + ffi.Pointer trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, ); @ffi.Native< ffi.Pointer Function( - ffi.Pointer)>(isLeaf: true) + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, + ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer - _ObjectiveCBindings_wrapListenerBlock_wjovn7( - ffi.Pointer block, + _ObjectiveCBindings_newListenerBlock_wjovn7( + ffi.Pointer trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, ); @ffi.Native< ffi.Pointer Function( - ffi.Pointer)>(isLeaf: true) + ffi.Pointer, + ffi.Int64, + ffi.Int64, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, + ffi.Int64 closure_id)>>)>(isLeaf: true) external ffi.Pointer - _ObjectiveCBindings_wrapListenerBlock_wjvic9( - ffi.Pointer block, + _ObjectiveCBindings_newListenerBlock_wjvic9( + ffi.Pointer trampoline, + int closure_id, + int dispose_port, + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Int64 dispose_port, ffi.Int64 closure_id)>> + dtor, ); /// Helper class to adapt a Dart stream into a `NSInputStream`. @@ -9405,12 +9308,11 @@ abstract final class ObjCBlock_NSString_ffiVoid { static objc.ObjCBlock)> fromFunction( NSString Function(ffi.Pointer) fn) => objc.ObjCBlock)>( - _ObjectiveCBindings_newClosureBlock_1yesha9( - _ObjCBlock_NSString_ffiVoid_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0) => - fn(arg0).ref.retainAndAutorelease()), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0) => + fn(arg0).ref.retainAndAutorelease(), + _ObjCBlock_NSString_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1yesha9), retain: false, release: true); } @@ -9476,12 +9378,10 @@ abstract final class ObjCBlock_NSUInteger_ffiVoid { static objc.ObjCBlock)> fromFunction(int Function(ffi.Pointer) fn) => objc.ObjCBlock)>( - _ObjectiveCBindings_newClosureBlock_1ckyi24( - _ObjCBlock_NSUInteger_ffiVoid_closureCallable, - objc.registerBlockClosure( - (ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_NSUInteger_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1ckyi24), retain: false, release: true); } @@ -9580,20 +9480,20 @@ abstract final class ObjCBlock_NSUInteger_ffiVoid_NSFastEnumerationState_objcObj /// 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. - static objc.ObjCBlock, ffi.Pointer, ffi.Pointer>, ffi.UnsignedLong)> - fromFunction(int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer>, int) fn) => - objc.ObjCBlock, ffi.Pointer, ffi.Pointer>, ffi.UnsignedLong)>( - _ObjectiveCBindings_newClosureBlock_17ap02x( - _ObjCBlock_NSUInteger_ffiVoid_NSFastEnumerationState_objcObjCObject_NSUInteger_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer> arg2, - int arg3) => - fn(arg0, arg1, arg2, arg3)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), - retain: false, - release: true); + static objc.ObjCBlock< + ffi.UnsignedLong Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer>, + ffi.UnsignedLong)> fromFunction(int Function(ffi.Pointer, ffi.Pointer, ffi.Pointer>, int) fn) => + objc.ObjCBlock, ffi.Pointer, ffi.Pointer>, ffi.UnsignedLong)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, ffi.Pointer> arg2, int arg3) => + fn(arg0, arg1, arg2, arg3), + _ObjCBlock_NSUInteger_ffiVoid_NSFastEnumerationState_objcObjCObject_NSUInteger_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_17ap02x), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock, ffi.Pointer, ffi.Pointer>, ffi.UnsignedLong)>`. @@ -9661,12 +9561,10 @@ abstract final class ObjCBlock_NSZone_ffiVoid { static objc.ObjCBlock Function(ffi.Pointer)> fromFunction(ffi.Pointer<_NSZone> Function(ffi.Pointer) fn) => objc.ObjCBlock Function(ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_1a8cl66( - _ObjCBlock_NSZone_ffiVoid_closureCallable, - objc.registerBlockClosure( - (ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_NSZone_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1a8cl66), retain: false, release: true); } @@ -9727,12 +9625,10 @@ abstract final class ObjCBlock_bool_ffiVoid { static objc.ObjCBlock)> fromFunction( bool Function(ffi.Pointer) fn) => objc.ObjCBlock)>( - _ObjectiveCBindings_newClosureBlock_e3qsqz( - _ObjCBlock_bool_ffiVoid_closureCallable, - objc.registerBlockClosure( - (ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_bool_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_e3qsqz), retain: false, release: true); } @@ -9801,13 +9697,14 @@ abstract final class ObjCBlock_bool_ffiVoid_Protocol { static objc.ObjCBlock, Protocol)> fromFunction(bool Function(ffi.Pointer, Protocol) fn) => objc.ObjCBlock, Protocol)>( - _ObjectiveCBindings_newClosureBlock_ozkafd( - _ObjCBlock_bool_ffiVoid_Protocol_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, Protocol.castFromPointer(arg1, retain: true, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => + fn( + arg0, + Protocol.castFromPointer(arg1, + retain: true, release: true)), + _ObjCBlock_bool_ffiVoid_Protocol_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_ozkafd), retain: false, release: true); } @@ -9882,14 +9779,14 @@ abstract final class ObjCBlock_bool_ffiVoid_objcObjCObject { static objc.ObjCBlock, ffi.Pointer)> fromFunction( bool Function(ffi.Pointer, objc.ObjCObjectBase) fn) => - objc.ObjCBlock, ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_ozkafd( - _ObjCBlock_bool_ffiVoid_objcObjCObject_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, objc.ObjCObjectBase(arg1, retain: true, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.ObjCBlock< + ffi.Bool Function( + ffi.Pointer, ffi.Pointer)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => + fn(arg0, objc.ObjCObjectBase(arg1, retain: true, release: true)), + _ObjCBlock_bool_ffiVoid_objcObjCObject_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_ozkafd), retain: false, release: true); } @@ -9962,16 +9859,17 @@ abstract final class ObjCBlock_bool_ffiVoid_objcObjCSelector { /// 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. - static objc.ObjCBlock, ffi.Pointer)> + static objc + .ObjCBlock, ffi.Pointer)> fromFunction(bool Function(ffi.Pointer, ffi.Pointer) fn) => - objc.ObjCBlock, ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_w1e3k0( - _ObjCBlock_bool_ffiVoid_objcObjCSelector_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, arg1)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.ObjCBlock< + ffi.Bool Function( + ffi.Pointer, ffi.Pointer)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => + fn(arg0, arg1), + _ObjCBlock_bool_ffiVoid_objcObjCSelector_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_w1e3k0), retain: false, release: true); } @@ -10156,14 +10054,16 @@ abstract final class ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCO static objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)> fromFunction(void Function(objc.ObjCBlock?, NSError)>, objc.ObjCObjectBase, NSDictionary) fn) => objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)>( - _ObjectiveCBindings_newClosureBlock_1j2nt86( - _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, ffi.Pointer arg1, ffi.Pointer arg2) => fn( - ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, retain: true, release: true), - objc.ObjCObjectBase(arg1, retain: true, release: true), - NSDictionary.castFromPointer(arg2, retain: true, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0, + ffi.Pointer arg1, + ffi.Pointer arg2) => + fn( + ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, retain: true, release: true), + objc.ObjCObjectBase(arg1, retain: true, release: true), + NSDictionary.castFromPointer(arg2, retain: true, release: true)), + _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1j2nt86), retain: false, release: true); @@ -10176,42 +10076,21 @@ abstract final class ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCO /// /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. - static objc.ObjCBlock< - ffi.Void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - ffi.Pointer, - NSDictionary)> listener( - void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - objc.ObjCObjectBase, - NSDictionary) - fn) { - final raw = _ObjectiveCBindings_newClosureBlock_1j2nt86( - _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_listenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2) => - fn( - ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, - retain: false, release: true), - objc.ObjCObjectBase(arg1, retain: false, release: true), - NSDictionary.castFromPointer(arg2, - retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = _ObjectiveCBindings_wrapListenerBlock_1j2nt86(raw); - objc.objectRelease(raw.cast()); - return objc.ObjCBlock< - ffi.Void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - ffi.Pointer, - NSDictionary)>(wrapper, retain: false, release: true); - } + static objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)> + listener(void Function(objc.ObjCBlock?, NSError)>, objc.ObjCObjectBase, NSDictionary) fn) => + objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)>( + objc.newClosureBlock( + (ffi.Pointer arg0, + ffi.Pointer arg1, + ffi.Pointer arg2) => + fn( + ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, retain: false, release: true), + objc.ObjCObjectBase(arg1, retain: false, release: true), + NSDictionary.castFromPointer(arg2, retain: false, release: true)), + _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_listenerCallable.nativeFunction.cast(), + _ObjectiveCBindings_newListenerBlock_1j2nt86), + retain: false, + release: true); /// Creates a blocking block from a Dart function. /// @@ -10222,59 +10101,22 @@ abstract final class ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCO /// This block does not keep the owner isolate alive. If the owner isolate has /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. - static objc.ObjCBlock< - ffi.Void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - ffi.Pointer, - NSDictionary)> blocking( - void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - objc.ObjCObjectBase, - NSDictionary) - fn) { - final raw = _ObjectiveCBindings_newClosureBlock_1j2nt86( - _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_blockingCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2) => - fn( - ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, - retain: false, release: true), - objc.ObjCObjectBase(arg1, retain: false, release: true), - NSDictionary.castFromPointer(arg2, - retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final rawListener = _ObjectiveCBindings_newClosureBlock_1j2nt86( - _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_blockingListenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2) => - fn( - ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, - retain: false, release: true), - objc.ObjCObjectBase(arg1, retain: false, release: true), - NSDictionary.castFromPointer(arg2, - retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = objc.wrapBlockingBlock( - _ObjectiveCBindings_wrapBlockingBlock_1j2nt86, raw, rawListener); - objc.objectRelease(raw.cast()); - objc.objectRelease(rawListener.cast()); - return objc.ObjCBlock< - ffi.Void Function( - objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>, - ffi.Pointer, - NSDictionary)>(wrapper, retain: false, release: true); - } + static objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)> + blocking(void Function(objc.ObjCBlock?, NSError)>, objc.ObjCObjectBase, NSDictionary) fn) => + objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)>( + objc.newBlockingBlock( + (ffi.Pointer arg0, + ffi.Pointer arg1, + ffi.Pointer arg2) => + fn( + ObjCBlock_ffiVoid_objcObjCObject_NSError.castFromPointer(arg0, retain: false, release: true), + objc.ObjCObjectBase(arg1, retain: false, release: true), + NSDictionary.castFromPointer(arg2, retain: false, release: true)), + _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_blockingCallable.nativeFunction.cast(), + _ObjCBlock_ffiVoid_NSItemProviderCompletionHandler_objcObjCObject_NSDictionary_blockingListenerCallable.nativeFunction.cast(), + _ObjectiveCBindings_newBlockingBlock_1j2nt86), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock?, NSError)>, ffi.Pointer, NSDictionary)>`. @@ -10391,12 +10233,10 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid { static objc.ObjCBlock)> fromFunction( void Function(ffi.Pointer) fn) => objc.ObjCBlock)>( - _ObjectiveCBindings_newClosureBlock_ovsamd( - _ObjCBlock_ffiVoid_ffiVoid_closureCallable, - objc.registerBlockClosure( - (ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_ffiVoid_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_ovsamd), retain: false, release: true); @@ -10410,17 +10250,14 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid { /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. static objc.ObjCBlock)> listener( - void Function(ffi.Pointer) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_ovsamd( - _ObjCBlock_ffiVoid_ffiVoid_listenerCallable.nativeFunction.cast(), - objc.registerBlockClosure((ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = _ObjectiveCBindings_wrapListenerBlock_ovsamd(raw); - objc.objectRelease(raw.cast()); - return objc.ObjCBlock)>(wrapper, - retain: false, release: true); - } + void Function(ffi.Pointer) fn) => + objc.ObjCBlock)>( + objc.newClosureBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_ffiVoid_ffiVoid_listenerCallable.nativeFunction.cast(), + _ObjectiveCBindings_newListenerBlock_ovsamd), + retain: false, + release: true); /// Creates a blocking block from a Dart function. /// @@ -10432,25 +10269,16 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid { /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. static objc.ObjCBlock)> blocking( - void Function(ffi.Pointer) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_ovsamd( - _ObjCBlock_ffiVoid_ffiVoid_blockingCallable.nativeFunction.cast(), - objc.registerBlockClosure((ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final rawListener = _ObjectiveCBindings_newClosureBlock_ovsamd( - _ObjCBlock_ffiVoid_ffiVoid_blockingListenerCallable.nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0) => fn(arg0)), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = objc.wrapBlockingBlock( - _ObjectiveCBindings_wrapBlockingBlock_ovsamd, raw, rawListener); - objc.objectRelease(raw.cast()); - objc.objectRelease(rawListener.cast()); - return objc.ObjCBlock)>(wrapper, - retain: false, release: true); - } + void Function(ffi.Pointer) fn) => + objc.ObjCBlock)>( + objc.newBlockingBlock( + (ffi.Pointer arg0) => fn(arg0), + _ObjCBlock_ffiVoid_ffiVoid_blockingCallable.nativeFunction.cast(), + _ObjCBlock_ffiVoid_ffiVoid_blockingListenerCallable.nativeFunction + .cast(), + _ObjectiveCBindings_newBlockingBlock_ovsamd), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock)>`. @@ -10585,13 +10413,13 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSCoder { static objc.ObjCBlock, NSCoder)> fromFunction(void Function(ffi.Pointer, NSCoder) fn) => objc.ObjCBlock, NSCoder)>( - _ObjectiveCBindings_newClosureBlock_wjovn7( - _ObjCBlock_ffiVoid_ffiVoid_NSCoder_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => - fn(arg0, NSCoder.castFromPointer(arg1, retain: true, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + fn(arg0, + NSCoder.castFromPointer(arg1, retain: true, release: true)), + _ObjCBlock_ffiVoid_ffiVoid_NSCoder_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_wjovn7), retain: false, release: true); @@ -10604,24 +10432,18 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSCoder { /// /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. - static objc.ObjCBlock, NSCoder)> - listener(void Function(ffi.Pointer, NSCoder) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_wjovn7( - _ObjCBlock_ffiVoid_ffiVoid_NSCoder_listenerCallable.nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, - NSCoder.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = _ObjectiveCBindings_wrapListenerBlock_wjovn7(raw); - objc.objectRelease(raw.cast()); - return objc.ObjCBlock, NSCoder)>( - wrapper, - retain: false, - release: true); - } + static objc.ObjCBlock, NSCoder)> listener( + void Function(ffi.Pointer, NSCoder) fn) => + objc.ObjCBlock, NSCoder)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => fn( + arg0, + NSCoder.castFromPointer(arg1, retain: false, release: true)), + _ObjCBlock_ffiVoid_ffiVoid_NSCoder_listenerCallable.nativeFunction + .cast(), + _ObjectiveCBindings_newListenerBlock_wjovn7), + retain: false, + release: true); /// Creates a blocking block from a Dart function. /// @@ -10632,36 +10454,21 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSCoder { /// This block does not keep the owner isolate alive. If the owner isolate has /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. - static objc.ObjCBlock, NSCoder)> - blocking(void Function(ffi.Pointer, NSCoder) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_wjovn7( - _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingCallable.nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, - NSCoder.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final rawListener = _ObjectiveCBindings_newClosureBlock_wjovn7( - _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingListenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, - NSCoder.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = objc.wrapBlockingBlock( - _ObjectiveCBindings_wrapBlockingBlock_wjovn7, raw, rawListener); - objc.objectRelease(raw.cast()); - objc.objectRelease(rawListener.cast()); - return objc.ObjCBlock, NSCoder)>( - wrapper, - retain: false, - release: true); - } + static objc.ObjCBlock, NSCoder)> blocking( + void Function(ffi.Pointer, NSCoder) fn) => + objc.ObjCBlock, NSCoder)>( + objc.newBlockingBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => fn( + arg0, + NSCoder.castFromPointer(arg1, retain: false, release: true)), + _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingCallable.nativeFunction + .cast(), + _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingListenerCallable + .nativeFunction + .cast(), + _ObjectiveCBindings_newBlockingBlock_wjovn7), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock, NSCoder)>`. @@ -10825,13 +10632,15 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent { static objc.ObjCBlock, NSStream, ffi.UnsignedLong)> fromFunction( void Function(ffi.Pointer, NSStream, NSStreamEvent) fn) => objc.ObjCBlock, NSStream, ffi.UnsignedLong)>( - _ObjectiveCBindings_newClosureBlock_18d6mda( - _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, int arg2) => - fn(arg0, NSStream.castFromPointer(arg1, retain: true, release: true), NSStreamEvent.fromValue(arg2))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, + int arg2) => + fn( + arg0, + NSStream.castFromPointer(arg1, retain: true, release: true), + NSStreamEvent.fromValue(arg2)), + _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_18d6mda), retain: false, release: true); @@ -10844,28 +10653,20 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent { /// /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. - static objc.ObjCBlock< - ffi.Void Function(ffi.Pointer, NSStream, ffi.UnsignedLong)> - listener( - void Function(ffi.Pointer, NSStream, NSStreamEvent) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_18d6mda( - _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_listenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, int arg2) => - fn( - arg0, - NSStream.castFromPointer(arg1, retain: false, release: true), - NSStreamEvent.fromValue(arg2))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = _ObjectiveCBindings_wrapListenerBlock_18d6mda(raw); - objc.objectRelease(raw.cast()); - return objc.ObjCBlock< - ffi.Void Function(ffi.Pointer, NSStream, - ffi.UnsignedLong)>(wrapper, retain: false, release: true); - } + static objc.ObjCBlock, NSStream, ffi.UnsignedLong)> listener( + void Function(ffi.Pointer, NSStream, NSStreamEvent) fn) => + objc.ObjCBlock, NSStream, ffi.UnsignedLong)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, int arg2) => fn( + arg0, + NSStream.castFromPointer(arg1, retain: false, release: true), + NSStreamEvent.fromValue(arg2)), + _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_listenerCallable + .nativeFunction + .cast(), + _ObjectiveCBindings_newListenerBlock_18d6mda), + retain: false, + release: true); /// Creates a blocking block from a Dart function. /// @@ -10876,42 +10677,21 @@ abstract final class ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent { /// This block does not keep the owner isolate alive. If the owner isolate has /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. - static objc.ObjCBlock< - ffi.Void Function(ffi.Pointer, NSStream, ffi.UnsignedLong)> - blocking( - void Function(ffi.Pointer, NSStream, NSStreamEvent) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_18d6mda( - _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_blockingCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, int arg2) => - fn( - arg0, - NSStream.castFromPointer(arg1, retain: false, release: true), - NSStreamEvent.fromValue(arg2))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final rawListener = _ObjectiveCBindings_newClosureBlock_18d6mda( - _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_blockingListenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, int arg2) => - fn( - arg0, - NSStream.castFromPointer(arg1, retain: false, release: true), - NSStreamEvent.fromValue(arg2))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = objc.wrapBlockingBlock( - _ObjectiveCBindings_wrapBlockingBlock_18d6mda, raw, rawListener); - objc.objectRelease(raw.cast()); - objc.objectRelease(rawListener.cast()); - return objc.ObjCBlock< - ffi.Void Function(ffi.Pointer, NSStream, - ffi.UnsignedLong)>(wrapper, retain: false, release: true); - } + static objc.ObjCBlock, NSStream, ffi.UnsignedLong)> blocking( + void Function(ffi.Pointer, NSStream, NSStreamEvent) fn) => + objc.ObjCBlock, NSStream, ffi.UnsignedLong)>( + objc.newBlockingBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, int arg2) => fn( + arg0, + NSStream.castFromPointer(arg1, retain: false, release: true), + NSStreamEvent.fromValue(arg2)), + _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_blockingCallable + .nativeFunction + .cast(), + _ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent_blockingListenerCallable.nativeFunction.cast(), + _ObjectiveCBindings_newBlockingBlock_18d6mda), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock, NSStream, ffi.UnsignedLong)>`. @@ -11055,15 +10835,16 @@ abstract final class ObjCBlock_ffiVoid_objcObjCObject_NSError { static objc.ObjCBlock?, NSError)> fromFunction( void Function(objc.ObjCObjectBase?, NSError) fn) => objc.ObjCBlock?, NSError)>( - _ObjectiveCBindings_newClosureBlock_wjvic9( - _ObjCBlock_ffiVoid_objcObjCObject_NSError_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, ffi.Pointer arg1) => fn( - arg0.address == 0 - ? null - : objc.ObjCObjectBase(arg0, retain: true, release: true), - NSError.castFromPointer(arg1, retain: true, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.newClosureBlock( + (ffi.Pointer arg0, + ffi.Pointer arg1) => + fn( + arg0.address == 0 + ? null + : objc.ObjCObjectBase(arg0, retain: true, release: true), + NSError.castFromPointer(arg1, retain: true, release: true)), + _ObjCBlock_ffiVoid_objcObjCObject_NSError_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_wjvic9), retain: false, release: true); @@ -11076,28 +10857,21 @@ abstract final class ObjCBlock_ffiVoid_objcObjCObject_NSError { /// /// Note that unlike the default behavior of NativeCallable.listener, listener /// blocks do not keep the isolate alive. - static objc - .ObjCBlock?, NSError)> - listener(void Function(objc.ObjCObjectBase?, NSError) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_wjvic9( - _ObjCBlock_ffiVoid_objcObjCObject_NSError_listenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn( - arg0.address == 0 - ? null - : objc.ObjCObjectBase(arg0, retain: false, release: true), - NSError.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = _ObjectiveCBindings_wrapListenerBlock_wjvic9(raw); - objc.objectRelease(raw.cast()); - return objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>(wrapper, - retain: false, release: true); - } + static objc.ObjCBlock?, NSError)> listener( + void Function(objc.ObjCObjectBase?, NSError) fn) => + objc.ObjCBlock?, NSError)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => fn( + arg0.address == 0 + ? null + : objc.ObjCObjectBase(arg0, retain: false, release: true), + NSError.castFromPointer(arg1, retain: false, release: true)), + _ObjCBlock_ffiVoid_objcObjCObject_NSError_listenerCallable + .nativeFunction + .cast(), + _ObjectiveCBindings_newListenerBlock_wjvic9), + retain: false, + release: true); /// Creates a blocking block from a Dart function. /// @@ -11108,43 +10882,22 @@ abstract final class ObjCBlock_ffiVoid_objcObjCObject_NSError { /// This block does not keep the owner isolate alive. If the owner isolate has /// shut down, and the block is invoked by native code, it may block /// indefinitely, or have other undefined behavior. - static objc - .ObjCBlock?, NSError)> - blocking(void Function(objc.ObjCObjectBase?, NSError) fn) { - final raw = _ObjectiveCBindings_newClosureBlock_wjvic9( - _ObjCBlock_ffiVoid_objcObjCObject_NSError_blockingCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn( - arg0.address == 0 - ? null - : objc.ObjCObjectBase(arg0, retain: false, release: true), - NSError.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final rawListener = _ObjectiveCBindings_newClosureBlock_wjvic9( - _ObjCBlock_ffiVoid_objcObjCObject_NSError_blockingListenerCallable - .nativeFunction - .cast(), - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn( - arg0.address == 0 - ? null - : objc.ObjCObjectBase(arg0, retain: false, release: true), - NSError.castFromPointer(arg1, retain: false, release: true))), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure); - final wrapper = objc.wrapBlockingBlock( - _ObjectiveCBindings_wrapBlockingBlock_wjvic9, raw, rawListener); - objc.objectRelease(raw.cast()); - objc.objectRelease(rawListener.cast()); - return objc.ObjCBlock< - ffi.Void Function(ffi.Pointer?, NSError)>(wrapper, - retain: false, release: true); - } + static objc.ObjCBlock?, NSError)> blocking( + void Function(objc.ObjCObjectBase?, NSError) fn) => + objc.ObjCBlock?, NSError)>( + objc.newBlockingBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => fn( + arg0.address == 0 + ? null + : objc.ObjCObjectBase(arg0, retain: false, release: true), + NSError.castFromPointer(arg1, retain: false, release: true)), + _ObjCBlock_ffiVoid_objcObjCObject_NSError_blockingCallable + .nativeFunction + .cast(), + _ObjCBlock_ffiVoid_objcObjCObject_NSError_blockingListenerCallable.nativeFunction.cast(), + _ObjectiveCBindings_newBlockingBlock_wjvic9), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock?, NSError)>`. @@ -11212,20 +10965,21 @@ abstract final class ObjCBlock_instancetype_ffiVoid_NSCoder { /// 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. - static objc.ObjCBlock?> Function(ffi.Pointer, NSCoder)> fromFunction( - Dartinstancetype? Function(ffi.Pointer, NSCoder) fn) => - objc.ObjCBlock?> Function(ffi.Pointer, NSCoder)>( - _ObjectiveCBindings_newClosureBlock_1m9h2n( - _ObjCBlock_instancetype_ffiVoid_NSCoder_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, ffi.Pointer arg1) => - fn(arg0, NSCoder.castFromPointer(arg1, retain: true, release: true)) - ?.ref - .retainAndReturnPointer() ?? - ffi.nullptr), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), - retain: false, - release: true); + static objc + .ObjCBlock?> Function(ffi.Pointer, NSCoder)> + fromFunction( + Dartinstancetype? Function(ffi.Pointer, NSCoder) fn) => + objc.ObjCBlock?> Function(ffi.Pointer, NSCoder)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => + fn(arg0, NSCoder.castFromPointer(arg1, retain: true, release: true)) + ?.ref + .retainAndReturnPointer() ?? + ffi.nullptr, + _ObjCBlock_instancetype_ffiVoid_NSCoder_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1m9h2n), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock?> Function(ffi.Pointer, NSCoder)>`. @@ -11331,17 +11085,18 @@ abstract final class ObjCBlock_instancetype_ffiVoid_NSData_NSString_NSError { /// 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. - static objc.ObjCBlock? Function(ffi.Pointer, NSData, NSString, ffi.Pointer>)> fromFunction(Dartinstancetype? Function(ffi.Pointer, NSData, NSString, ffi.Pointer>) fn) => + static objc.ObjCBlock? Function(ffi.Pointer, NSData, NSString, ffi.Pointer>)> fromFunction( + Dartinstancetype? Function(ffi.Pointer, NSData, NSString, ffi.Pointer>) + fn) => objc.ObjCBlock? Function(ffi.Pointer, NSData, NSString, ffi.Pointer>)>( - _ObjectiveCBindings_newClosureBlock_e2pkq8( - _ObjCBlock_instancetype_ffiVoid_NSData_NSString_NSError_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, ffi.Pointer arg2, ffi.Pointer> arg3) => - fn(arg0, NSData.castFromPointer(arg1, retain: true, release: true), NSString.castFromPointer(arg2, retain: true, release: true), arg3)?.ref.retainAndAutorelease() ?? ffi.nullptr), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + fn(arg0, NSData.castFromPointer(arg1, retain: true, release: true), NSString.castFromPointer(arg2, retain: true, release: true), arg3)?.ref.retainAndAutorelease() ?? ffi.nullptr, + _ObjCBlock_instancetype_ffiVoid_NSData_NSString_NSError_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_e2pkq8), retain: false, release: true); } @@ -11425,18 +11180,18 @@ abstract final class ObjCBlock_objcObjCObject_ffiVoid { /// 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. - static objc.ObjCBlock< - ffi.Pointer Function(ffi.Pointer)> fromFunction( - objc.ObjCObjectBase Function(ffi.Pointer) fn) => - objc.ObjCBlock Function(ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_1yesha9( - _ObjCBlock_objcObjCObject_ffiVoid_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0) => - fn(arg0).ref.retainAndAutorelease()), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), - retain: false, - release: true); + static objc + .ObjCBlock Function(ffi.Pointer)> + fromFunction(objc.ObjCObjectBase Function(ffi.Pointer) fn) => + objc.ObjCBlock< + ffi.Pointer Function(ffi.Pointer)>( + objc.newClosureBlock( + (ffi.Pointer arg0) => + fn(arg0).ref.retainAndAutorelease(), + _ObjCBlock_objcObjCObject_ffiVoid_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1yesha9), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock Function(ffi.Pointer)>`. @@ -11519,14 +11274,14 @@ abstract final class ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector { /// will result in a crash. static objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer)> fromFunction(objc.ObjCObjectBase Function(ffi.Pointer, ffi.Pointer) fn) => - objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_ykn0t6( - _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1) => - fn(arg0, arg1).ref.retainAndAutorelease()), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + objc.ObjCBlock< + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer)>( + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1) => + fn(arg0, arg1).ref.retainAndAutorelease(), + _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_ykn0t6), retain: false, release: true); } @@ -11621,14 +11376,15 @@ abstract final class ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCO static objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer)> fromFunction(objc.ObjCObjectBase Function(ffi.Pointer, ffi.Pointer, objc.ObjCObjectBase) fn) => objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_1c0c70u( - _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCObject_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, + objc.newClosureBlock( + (ffi.Pointer arg0, ffi.Pointer arg1, ffi.Pointer arg2) => - fn(arg0, arg1, objc.ObjCObjectBase(arg2, retain: true, release: true)).ref.retainAndAutorelease()), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), + fn(arg0, arg1, objc.ObjCObjectBase(arg2, retain: true, release: true)) + .ref + .retainAndAutorelease(), + _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCObject_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_1c0c70u), retain: false, release: true); } @@ -11730,19 +11486,21 @@ abstract final class ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCO /// 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. - static objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer)> fromFunction(objc.ObjCObjectBase Function(ffi.Pointer, ffi.Pointer, objc.ObjCObjectBase, objc.ObjCObjectBase) fn) => - objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer)>( - _ObjectiveCBindings_newClosureBlock_u8b97m( - _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCObject_objcObjCObject_closureCallable, - objc.registerBlockClosure((ffi.Pointer arg0, - ffi.Pointer arg1, - ffi.Pointer arg2, - ffi.Pointer arg3) => - fn(arg0, arg1, objc.ObjCObjectBase(arg2, retain: true, release: true), objc.ObjCObjectBase(arg3, retain: true, release: true)).ref.retainAndAutorelease()), - objc.blockClosureDisposePort, - objc.disposeObjCBlockWithClosure), - retain: false, - release: true); + static objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer)> + fromFunction(objc.ObjCObjectBase Function(ffi.Pointer, ffi.Pointer, objc.ObjCObjectBase, objc.ObjCObjectBase) fn) => + objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer)>( + objc.newClosureBlock( + (ffi.Pointer arg0, + ffi.Pointer arg1, + ffi.Pointer arg2, + ffi.Pointer arg3) => + fn(arg0, arg1, objc.ObjCObjectBase(arg2, retain: true, release: true), objc.ObjCObjectBase(arg3, retain: true, release: true)) + .ref + .retainAndAutorelease(), + _ObjCBlock_objcObjCObject_ffiVoid_objcObjCSelector_objcObjCObject_objcObjCObject_closureCallable.cast(), + _ObjectiveCBindings_newClosureBlock_u8b97m), + retain: false, + release: true); } /// Call operator for `objc.ObjCBlock Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer)>`. diff --git a/pkgs/objective_c/src/objective_c_bindings_generated.m b/pkgs/objective_c/src/objective_c_bindings_generated.m index 417c0e11e..e4f24a85c 100644 --- a/pkgs/objective_c/src/objective_c_bindings_generated.m +++ b/pkgs/objective_c/src/objective_c_bindings_generated.m @@ -15,9 +15,19 @@ @interface _ObjectiveCBindings_BlockDestroyer : NSObject {} @property int64_t closure_id; @property int64_t dispose_port; @property void (*dtor)(int64_t, int64_t); ++ (instancetype)new:(int64_t) closure_id disposePort:(int64_t) dispose_port + destructor:(void (*)(int64_t, int64_t)) dtor; - (void)dealloc; @end @implementation _ObjectiveCBindings_BlockDestroyer ++ (instancetype)new:(int64_t) closure_id disposePort:(int64_t) dispose_port + destructor:(void (*)(int64_t, int64_t)) dtor { + _ObjectiveCBindings_BlockDestroyer* d = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; + d.closure_id = closure_id; + d.dispose_port = dispose_port; + d.dtor = dtor; + return d; +} - (void)dealloc { self.dtor(self.dispose_port, self.closure_id); } @end @@ -34,10 +44,8 @@ id _ObjectiveCBindings_invokeBlock_1yesha9( _BlockType _ObjectiveCBindings_newClosureBlock_1yesha9( id (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType weakBlk; _BlockType blk = ^id (void * arg0) { return trampoline(weakBlk, obj.closure_id, arg0); @@ -57,10 +65,8 @@ unsigned long _ObjectiveCBindings_invokeBlock_1ckyi24( _BlockType1 _ObjectiveCBindings_newClosureBlock_1ckyi24( unsigned long (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType1 weakBlk; _BlockType1 blk = ^unsigned long (void * arg0) { return trampoline(weakBlk, obj.closure_id, arg0); @@ -80,10 +86,8 @@ unsigned long _ObjectiveCBindings_invokeBlock_17ap02x( _BlockType2 _ObjectiveCBindings_newClosureBlock_17ap02x( unsigned long (*trampoline)(id , int64_t , void * , NSFastEnumerationState * , id * , unsigned long ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType2 weakBlk; _BlockType2 blk = ^unsigned long (void * arg0, NSFastEnumerationState * arg1, id * arg2, unsigned long arg3) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2, arg3); @@ -103,10 +107,8 @@ unsigned long (*trampoline)(id , int64_t , void * , NSFastEnumerationState * , _BlockType3 _ObjectiveCBindings_newClosureBlock_1a8cl66( struct _NSZone * (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType3 weakBlk; _BlockType3 blk = ^struct _NSZone * (void * arg0) { return trampoline(weakBlk, obj.closure_id, arg0); @@ -126,10 +128,8 @@ BOOL _ObjectiveCBindings_invokeBlock_e3qsqz( _BlockType4 _ObjectiveCBindings_newClosureBlock_e3qsqz( BOOL (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType4 weakBlk; _BlockType4 blk = ^BOOL (void * arg0) { return trampoline(weakBlk, obj.closure_id, arg0); @@ -149,10 +149,8 @@ BOOL _ObjectiveCBindings_invokeBlock_ozkafd( _BlockType5 _ObjectiveCBindings_newClosureBlock_ozkafd( BOOL (*trampoline)(id , int64_t , void * , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType5 weakBlk; _BlockType5 blk = ^BOOL (void * arg0, id arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -172,10 +170,8 @@ BOOL _ObjectiveCBindings_invokeBlock_w1e3k0( _BlockType6 _ObjectiveCBindings_newClosureBlock_w1e3k0( BOOL (*trampoline)(id , int64_t , void * , struct objc_selector * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType6 weakBlk; _BlockType6 blk = ^BOOL (void * arg0, struct objc_selector * arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -195,10 +191,8 @@ void _ObjectiveCBindings_invokeBlock_1j2nt86( _BlockType7 _ObjectiveCBindings_newClosureBlock_1j2nt86( void (*trampoline)(id , int64_t , id , id , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType7 weakBlk; _BlockType7 blk = ^void (id arg0, id arg1, id arg2) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2); @@ -208,30 +202,42 @@ _BlockType7 _ObjectiveCBindings_newClosureBlock_1j2nt86( } __attribute__((visibility("default"))) __attribute__((used)) -_BlockType7 _ObjectiveCBindings_wrapListenerBlock_1j2nt86(_BlockType7 block) NS_RETURNS_RETAINED { - return ^void(id arg0, id arg1, id arg2) { - objc_retainBlock(block); - block(objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); +_BlockType7 _ObjectiveCBindings_newListenerBlock_1j2nt86( + void (*trampoline)(id , int64_t , id , id , id ), int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType7 weakBlk; + _BlockType7 blk = ^void (id arg0, id arg1, id arg2) { + objc_retainBlock(weakBlk); + return trampoline(weakBlk, obj.closure_id, objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); }; + weakBlk = blk; + return blk; } typedef void (^_BlockingTrampoline7)(void * waiter, id arg0, id arg1, id arg2); __attribute__((visibility("default"))) __attribute__((used)) -_BlockType7 _ObjectiveCBindings_wrapBlockingBlock_1j2nt86( - _BlockingTrampoline7 block, _BlockingTrampoline7 listenerBlock, +_BlockType7 _ObjectiveCBindings_newBlockingBlock_1j2nt86( + void (*tramp)(id , int64_t , void * , id , id , id ), void (*listener_tramp)(id , int64_t , void * , id , id , id ), + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void(id arg0, id arg1, id arg2) { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType7 weakBlk; + _BlockType7 blk = ^void (id arg0, id arg1, id arg2) { + objc_retainBlock(weakBlk); if ([NSThread currentThread] == targetThread) { - objc_retainBlock(block); - block(nil, objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); + tramp(weakBlk, obj.closure_id, nil, objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); } else { void* waiter = newWaiter(); - objc_retainBlock(listenerBlock); - listenerBlock(waiter, objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); + listener_tramp(weakBlk, obj.closure_id, waiter, objc_retainBlock(arg0), objc_retain(arg1), objc_retain(arg2)); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } typedef void (^_BlockType8)(void * arg0); @@ -245,10 +251,8 @@ void _ObjectiveCBindings_invokeBlock_ovsamd( _BlockType8 _ObjectiveCBindings_newClosureBlock_ovsamd( void (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType8 weakBlk; _BlockType8 blk = ^void (void * arg0) { return trampoline(weakBlk, obj.closure_id, arg0); @@ -258,30 +262,42 @@ _BlockType8 _ObjectiveCBindings_newClosureBlock_ovsamd( } __attribute__((visibility("default"))) __attribute__((used)) -_BlockType8 _ObjectiveCBindings_wrapListenerBlock_ovsamd(_BlockType8 block) NS_RETURNS_RETAINED { - return ^void(void * arg0) { - objc_retainBlock(block); - block(arg0); +_BlockType8 _ObjectiveCBindings_newListenerBlock_ovsamd( + void (*trampoline)(id , int64_t , void * ), int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType8 weakBlk; + _BlockType8 blk = ^void (void * arg0) { + objc_retainBlock(weakBlk); + return trampoline(weakBlk, obj.closure_id, arg0); }; + weakBlk = blk; + return blk; } typedef void (^_BlockingTrampoline8)(void * waiter, void * arg0); __attribute__((visibility("default"))) __attribute__((used)) -_BlockType8 _ObjectiveCBindings_wrapBlockingBlock_ovsamd( - _BlockingTrampoline8 block, _BlockingTrampoline8 listenerBlock, +_BlockType8 _ObjectiveCBindings_newBlockingBlock_ovsamd( + void (*tramp)(id , int64_t , void * , void * ), void (*listener_tramp)(id , int64_t , void * , void * ), + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void(void * arg0) { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType8 weakBlk; + _BlockType8 blk = ^void (void * arg0) { + objc_retainBlock(weakBlk); if ([NSThread currentThread] == targetThread) { - objc_retainBlock(block); - block(nil, arg0); + tramp(weakBlk, obj.closure_id, nil, arg0); } else { void* waiter = newWaiter(); - objc_retainBlock(listenerBlock); - listenerBlock(waiter, arg0); + listener_tramp(weakBlk, obj.closure_id, waiter, arg0); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } typedef void (^_BlockType9)(void * arg0, id arg1); @@ -295,10 +311,8 @@ void _ObjectiveCBindings_invokeBlock_wjovn7( _BlockType9 _ObjectiveCBindings_newClosureBlock_wjovn7( void (*trampoline)(id , int64_t , void * , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType9 weakBlk; _BlockType9 blk = ^void (void * arg0, id arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -308,30 +322,42 @@ _BlockType9 _ObjectiveCBindings_newClosureBlock_wjovn7( } __attribute__((visibility("default"))) __attribute__((used)) -_BlockType9 _ObjectiveCBindings_wrapListenerBlock_wjovn7(_BlockType9 block) NS_RETURNS_RETAINED { - return ^void(void * arg0, id arg1) { - objc_retainBlock(block); - block(arg0, objc_retain(arg1)); +_BlockType9 _ObjectiveCBindings_newListenerBlock_wjovn7( + void (*trampoline)(id , int64_t , void * , id ), int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType9 weakBlk; + _BlockType9 blk = ^void (void * arg0, id arg1) { + objc_retainBlock(weakBlk); + return trampoline(weakBlk, obj.closure_id, arg0, objc_retain(arg1)); }; + weakBlk = blk; + return blk; } typedef void (^_BlockingTrampoline9)(void * waiter, void * arg0, id arg1); __attribute__((visibility("default"))) __attribute__((used)) -_BlockType9 _ObjectiveCBindings_wrapBlockingBlock_wjovn7( - _BlockingTrampoline9 block, _BlockingTrampoline9 listenerBlock, +_BlockType9 _ObjectiveCBindings_newBlockingBlock_wjovn7( + void (*tramp)(id , int64_t , void * , void * , id ), void (*listener_tramp)(id , int64_t , void * , void * , id ), + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void(void * arg0, id arg1) { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType9 weakBlk; + _BlockType9 blk = ^void (void * arg0, id arg1) { + objc_retainBlock(weakBlk); if ([NSThread currentThread] == targetThread) { - objc_retainBlock(block); - block(nil, arg0, objc_retain(arg1)); + tramp(weakBlk, obj.closure_id, nil, arg0, objc_retain(arg1)); } else { void* waiter = newWaiter(); - objc_retainBlock(listenerBlock); - listenerBlock(waiter, arg0, objc_retain(arg1)); + listener_tramp(weakBlk, obj.closure_id, waiter, arg0, objc_retain(arg1)); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } typedef void (^_BlockType10)(void * arg0, id arg1, NSStreamEvent arg2); @@ -345,10 +371,8 @@ void _ObjectiveCBindings_invokeBlock_18d6mda( _BlockType10 _ObjectiveCBindings_newClosureBlock_18d6mda( void (*trampoline)(id , int64_t , void * , id , NSStreamEvent ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType10 weakBlk; _BlockType10 blk = ^void (void * arg0, id arg1, NSStreamEvent arg2) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2); @@ -358,30 +382,42 @@ _BlockType10 _ObjectiveCBindings_newClosureBlock_18d6mda( } __attribute__((visibility("default"))) __attribute__((used)) -_BlockType10 _ObjectiveCBindings_wrapListenerBlock_18d6mda(_BlockType10 block) NS_RETURNS_RETAINED { - return ^void(void * arg0, id arg1, NSStreamEvent arg2) { - objc_retainBlock(block); - block(arg0, objc_retain(arg1), arg2); +_BlockType10 _ObjectiveCBindings_newListenerBlock_18d6mda( + void (*trampoline)(id , int64_t , void * , id , NSStreamEvent ), int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType10 weakBlk; + _BlockType10 blk = ^void (void * arg0, id arg1, NSStreamEvent arg2) { + objc_retainBlock(weakBlk); + return trampoline(weakBlk, obj.closure_id, arg0, objc_retain(arg1), arg2); }; + weakBlk = blk; + return blk; } typedef void (^_BlockingTrampoline10)(void * waiter, void * arg0, id arg1, NSStreamEvent arg2); __attribute__((visibility("default"))) __attribute__((used)) -_BlockType10 _ObjectiveCBindings_wrapBlockingBlock_18d6mda( - _BlockingTrampoline10 block, _BlockingTrampoline10 listenerBlock, +_BlockType10 _ObjectiveCBindings_newBlockingBlock_18d6mda( + void (*tramp)(id , int64_t , void * , void * , id , NSStreamEvent ), void (*listener_tramp)(id , int64_t , void * , void * , id , NSStreamEvent ), + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void(void * arg0, id arg1, NSStreamEvent arg2) { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType10 weakBlk; + _BlockType10 blk = ^void (void * arg0, id arg1, NSStreamEvent arg2) { + objc_retainBlock(weakBlk); if ([NSThread currentThread] == targetThread) { - objc_retainBlock(block); - block(nil, arg0, objc_retain(arg1), arg2); + tramp(weakBlk, obj.closure_id, nil, arg0, objc_retain(arg1), arg2); } else { void* waiter = newWaiter(); - objc_retainBlock(listenerBlock); - listenerBlock(waiter, arg0, objc_retain(arg1), arg2); + listener_tramp(weakBlk, obj.closure_id, waiter, arg0, objc_retain(arg1), arg2); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } typedef void (^_BlockType11)(id arg0, id arg1); @@ -395,10 +431,8 @@ void _ObjectiveCBindings_invokeBlock_wjvic9( _BlockType11 _ObjectiveCBindings_newClosureBlock_wjvic9( void (*trampoline)(id , int64_t , id , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType11 weakBlk; _BlockType11 blk = ^void (id arg0, id arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -408,30 +442,42 @@ _BlockType11 _ObjectiveCBindings_newClosureBlock_wjvic9( } __attribute__((visibility("default"))) __attribute__((used)) -_BlockType11 _ObjectiveCBindings_wrapListenerBlock_wjvic9(_BlockType11 block) NS_RETURNS_RETAINED { - return ^void(id arg0, id arg1) { - objc_retainBlock(block); - block(objc_retain(arg0), objc_retain(arg1)); +_BlockType11 _ObjectiveCBindings_newListenerBlock_wjvic9( + void (*trampoline)(id , int64_t , id , id ), int64_t closure_id, int64_t dispose_port, + void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType11 weakBlk; + _BlockType11 blk = ^void (id arg0, id arg1) { + objc_retainBlock(weakBlk); + return trampoline(weakBlk, obj.closure_id, objc_retain(arg0), objc_retain(arg1)); }; + weakBlk = blk; + return blk; } typedef void (^_BlockingTrampoline11)(void * waiter, id arg0, id arg1); __attribute__((visibility("default"))) __attribute__((used)) -_BlockType11 _ObjectiveCBindings_wrapBlockingBlock_wjvic9( - _BlockingTrampoline11 block, _BlockingTrampoline11 listenerBlock, +_BlockType11 _ObjectiveCBindings_newBlockingBlock_wjvic9( + void (*tramp)(id , int64_t , void * , id , id ), void (*listener_tramp)(id , int64_t , void * , id , id ), + int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t), void* (*newWaiter)(), void (*awaitWaiter)(void*)) NS_RETURNS_RETAINED { NSThread *targetThread = [NSThread currentThread]; - return ^void(id arg0, id arg1) { + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; + __weak __block _BlockType11 weakBlk; + _BlockType11 blk = ^void (id arg0, id arg1) { + objc_retainBlock(weakBlk); if ([NSThread currentThread] == targetThread) { - objc_retainBlock(block); - block(nil, objc_retain(arg0), objc_retain(arg1)); + tramp(weakBlk, obj.closure_id, nil, objc_retain(arg0), objc_retain(arg1)); } else { void* waiter = newWaiter(); - objc_retainBlock(listenerBlock); - listenerBlock(waiter, objc_retain(arg0), objc_retain(arg1)); + listener_tramp(weakBlk, obj.closure_id, waiter, objc_retain(arg0), objc_retain(arg1)); awaitWaiter(waiter); } }; + weakBlk = blk; + return blk; } typedef id (^_BlockType12)(void * arg0, id arg1); @@ -445,10 +491,8 @@ id _ObjectiveCBindings_invokeBlock_1m9h2n( _BlockType12 _ObjectiveCBindings_newClosureBlock_1m9h2n( id (*trampoline)(id , int64_t , void * , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType12 weakBlk; _BlockType12 blk = ^id (void * arg0, id arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -468,10 +512,8 @@ id _ObjectiveCBindings_invokeBlock_e2pkq8( _BlockType13 _ObjectiveCBindings_newClosureBlock_e2pkq8( id (*trampoline)(id , int64_t , void * , id , id , id * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType13 weakBlk; _BlockType13 blk = ^id (void * arg0, id arg1, id arg2, id * arg3) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2, arg3); @@ -491,10 +533,8 @@ id _ObjectiveCBindings_invokeBlock_ykn0t6( _BlockType14 _ObjectiveCBindings_newClosureBlock_ykn0t6( id (*trampoline)(id , int64_t , void * , struct objc_selector * ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType14 weakBlk; _BlockType14 blk = ^id (void * arg0, struct objc_selector * arg1) { return trampoline(weakBlk, obj.closure_id, arg0, arg1); @@ -514,10 +554,8 @@ id _ObjectiveCBindings_invokeBlock_1c0c70u( _BlockType15 _ObjectiveCBindings_newClosureBlock_1c0c70u( id (*trampoline)(id , int64_t , void * , struct objc_selector * , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType15 weakBlk; _BlockType15 blk = ^id (void * arg0, struct objc_selector * arg1, id arg2) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2); @@ -537,10 +575,8 @@ id _ObjectiveCBindings_invokeBlock_u8b97m( _BlockType16 _ObjectiveCBindings_newClosureBlock_u8b97m( id (*trampoline)(id , int64_t , void * , struct objc_selector * , id , id ), int64_t closure_id, int64_t dispose_port, void (*dtor)(int64_t, int64_t)) NS_RETURNS_RETAINED { - _ObjectiveCBindings_BlockDestroyer* obj = [[_ObjectiveCBindings_BlockDestroyer alloc] init]; - obj.closure_id = closure_id; - obj.dispose_port = dispose_port; - obj.dtor = dtor; + _ObjectiveCBindings_BlockDestroyer* obj = [_ObjectiveCBindings_BlockDestroyer + new:closure_id disposePort:dispose_port destructor:dtor]; __weak __block _BlockType16 weakBlk; _BlockType16 blk = ^id (void * arg0, struct objc_selector * arg1, id arg2, id arg3) { return trampoline(weakBlk, obj.closure_id, arg0, arg1, arg2, arg3); diff --git a/pkgs/objective_c/test/main.c b/pkgs/objective_c/test/main.c index b02316d43..422d5548f 100644 --- a/pkgs/objective_c/test/main.c +++ b/pkgs/objective_c/test/main.c @@ -19,6 +19,6 @@ int main() { ASSERT_SYMBOL("DOBJC_runOnMainThread"); // objective_c.m ASSERT_SYMBOL("OBJC_CLASS_$_DOBJCDartProxy"); // proxy.m // objective_c_bindings_generated.m - ASSERT_SYMBOL("_ObjectiveCBindings_wrapListenerBlock_ovsamd"); + ASSERT_SYMBOL("_ObjectiveCBindings_newListenerBlock_ovsamd"); return 0; } diff --git a/pkgs/objective_c/test/setup.dart b/pkgs/objective_c/test/setup.dart index d12cf593c..07e8ba8c4 100644 --- a/pkgs/objective_c/test/setup.dart +++ b/pkgs/objective_c/test/setup.dart @@ -97,7 +97,7 @@ void main(List arguments) { lib.lookup('Dart_InitializeApiDL'); // dart_api_dl.c lib.lookup('OBJC_CLASS_\$_DOBJCDartProxy'); // proxy.m // objective_c_bindings_generated.m - lib.lookup('_ObjectiveCBindings_wrapListenerBlock_ovsamd'); + lib.lookup('_ObjectiveCBindings_newListenerBlock_ovsamd'); // Sanity check that the executable can find FFI symbols. _linkMain([...objFiles, cMain], '$cMain.exe');