diff --git a/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts b/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts index edc8576b2..06e77003f 100644 --- a/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts +++ b/packages/nitrogen/src/syntax/swift/SwiftCxxBridgedType.ts @@ -30,6 +30,7 @@ import { createSwiftVariant, getSwiftVariantCaseName } from './SwiftVariant.js' import { VoidType } from '../types/VoidType.js' import { NamedWrappingType } from '../types/NamedWrappingType.js' import { ErrorType } from '../types/ErrorType.js' +import { createSwiftFunctionBridge } from './SwiftFunction.js' // TODO: Remove enum bridge once Swift fixes bidirectional enums crashing the `-Swift.h` header. @@ -176,10 +177,24 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> { files.push(extensionFile) break } + case 'function': { + const functionType = getTypeAs(this.type, FunctionType) + const extensionFile = createSwiftFunctionBridge(functionType) + files.push(extensionFile) + break + } + case 'promise': { + // Promise needs resolver and rejecter funcs in Swift + const promiseType = getTypeAs(this.type, PromiseType) + files.push(createSwiftFunctionBridge(promiseType.resolverFunction)) + files.push(createSwiftFunctionBridge(promiseType.rejecterFunction)) + break + } case 'variant': { const variant = getTypeAs(this.type, VariantType) const file = createSwiftVariant(variant) files.push(file) + break } } @@ -345,23 +360,27 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> { const promise = getTypeAs(this.type, PromiseType) switch (language) { case 'swift': { + const bridge = this.getBridgeOrThrow() if (promise.resultingType.kind === 'void') { // It's void - resolve() + const resolverFunc = new FunctionType(new VoidType(), []) const rejecterFunc = new FunctionType(new VoidType(), [ new NamedWrappingType('error', new ErrorType()), ]) + const resolverFuncBridge = new SwiftCxxBridgedType(resolverFunc) const rejecterFuncBridge = new SwiftCxxBridgedType(rejecterFunc) return ` { () -> ${promise.getCode('swift')} in let __promise = ${promise.getCode('swift')}() - let __resolver = SwiftClosure { __promise.resolve(withResult: ()) } + let __resolver = { __promise.resolve(withResult: ()) } let __rejecter = { (__error: Error) in __promise.reject(withError: __error) } - let __resolverCpp = __resolver.getFunctionCopy() + let __resolverCpp = ${indent(resolverFuncBridge.parseFromSwiftToCpp('__resolver', 'swift'), ' ')} let __rejecterCpp = ${indent(rejecterFuncBridge.parseFromSwiftToCpp('__rejecter', 'swift'), ' ')} - ${cppParameterName}.addOnResolvedListener(__resolverCpp) - ${cppParameterName}.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_${bridge.specializationName}(${cppParameterName}) + __promiseHolder.addOnResolvedListener(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }()`.trim() } else { @@ -389,8 +408,9 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> { } let __resolverCpp = ${indent(resolverFuncBridge.parseFromSwiftToCpp('__resolver', 'swift'), ' ')} let __rejecterCpp = ${indent(rejecterFuncBridge.parseFromSwiftToCpp('__rejecter', 'swift'), ' ')} - ${cppParameterName}.${resolverFuncName}(__resolverCpp) - ${cppParameterName}.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_${bridge.specializationName}(${cppParameterName}) + __promiseHolder.${resolverFuncName}(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }()`.trim() } @@ -532,18 +552,21 @@ case ${i}: if (funcType.returnType.kind === 'void') { return ` { () -> ${swiftClosureType} in - let __sharedClosure = bridge.share_${bridge.specializationName}(${cppParameterName}) + let __wrappedFunction = bridge.wrap_${bridge.specializationName}(${cppParameterName}) return { ${signature} in - __sharedClosure.pointee.call(${indent(paramsForward.join(', '), ' ')}) + __wrappedFunction.call(${indent(paramsForward.join(', '), ' ')}) } }()`.trim() } else { - const resultBridged = new SwiftCxxBridgedType(funcType.returnType) + const resultBridged = new SwiftCxxBridgedType( + funcType.returnType, + true + ) return ` { () -> ${swiftClosureType} in - let __sharedClosure = bridge.share_${bridge.specializationName}(${cppParameterName}) + let __wrappedFunction = bridge.wrap_${bridge.specializationName}(${cppParameterName}) return { ${signature} in - let __result = __sharedClosure.pointee.call(${indent(paramsForward.join(', '), ' ')}) + let __result = __wrappedFunction.call(${indent(paramsForward.join(', '), ' ')}) return ${indent(resultBridged.parseFromCppToSwift('__result', 'swift'), ' ')} } }()`.trim() @@ -661,30 +684,20 @@ case ${i}: true ) switch (language) { - case 'c++': - if (this.isBridgingToDirectCppTarget) { - return swiftParameterName - } else { - return `${swiftParameterName}.getPromise()` - } case 'swift': const arg = promise.resultingType.kind === 'void' ? '' : resolvingType.parseFromSwiftToCpp('__result', 'swift') - const code = ` + return ` { () -> bridge.${bridge.specializationName} in let __promise = ${makePromise}() + let __promiseHolder = bridge.wrap_${bridge.specializationName}(__promise) ${swiftParameterName} - .then({ __result in __promise.resolve(${indent(arg, ' ')}) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(${indent(arg, ' ')}) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise }()`.trim() - if (this.isBridgingToDirectCppTarget) { - return `${code}.getPromise()` - } else { - return code - } default: return swiftParameterName } @@ -772,52 +785,11 @@ case ${i}: switch (language) { case 'swift': { const bridge = this.getBridgeOrThrow() - const func = getTypeAs(this.type, FunctionType) - const cFuncParamsForward = func.parameters - .map((p) => { - const bridged = new SwiftCxxBridgedType(p) - return bridged.parseFromCppToSwift( - `__${p.escapedName}`, - 'swift' - ) - }) - .join(', ') - const paramsSignature = func.parameters - .map((p) => `_ __${p.escapedName}: ${p.getCode('swift')}`) - .join(', ') - const paramsForward = func.parameters - .map((p) => `__${p.escapedName}`) - .join(', ') - const cFuncParamsSignature = [ - '__closureHolder: UnsafeMutableRawPointer', - ...func.parameters.map((p) => { - const bridged = new SwiftCxxBridgedType(p) - return `__${p.escapedName}: ${bridged.getTypeCode('swift')}` - }), - ].join(', ') const createFunc = `bridge.${bridge.funcName}` return ` { () -> bridge.${bridge.specializationName} in - final class ClosureHolder { - let closure: ${func.getCode('swift')} - init(wrappingClosure closure: @escaping ${func.getCode('swift')}) { - self.closure = closure - } - func invoke(${paramsSignature}) { - self.closure(${indent(paramsForward, ' ')}) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: ${swiftParameterName})).toOpaque() - func __callClosure(${cFuncParamsSignature}) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(${indent(cFuncParamsForward, ' ')}) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return ${createFunc}(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = ${bridge.specializationName}(${swiftParameterName}) + return ${createFunc}(__closureWrapper.toUnsafe()) }() `.trim() } diff --git a/packages/nitrogen/src/syntax/swift/SwiftCxxTypeHelper.ts b/packages/nitrogen/src/syntax/swift/SwiftCxxTypeHelper.ts index d2e2af697..264a1f558 100644 --- a/packages/nitrogen/src/syntax/swift/SwiftCxxTypeHelper.ts +++ b/packages/nitrogen/src/syntax/swift/SwiftCxxTypeHelper.ts @@ -303,58 +303,47 @@ function createCxxFunctionSwiftHelper(type: FunctionType): SwiftCxxHelper { return `${p.getCode('c++')} ${p.escapedName}` } }) - const callCppFuncParamsSignature = type.parameters.map((p) => { + const paramsForward = type.parameters.map((p) => { const bridge = new SwiftCxxBridgedType(p) - const cppType = bridge.getTypeCode('c++') - return `${cppType} ${p.escapedName}` + return bridge.parseFromCppToSwift(p.escapedName, 'c++') }) + const name = type.specializationName + const wrapperName = `${name}_Wrapper` + const swiftClassName = `${NitroConfig.getIosModuleName()}::${type.specializationName}` + const callParamsForward = type.parameters.map((p) => { const bridge = new SwiftCxxBridgedType(p) return bridge.parseFromSwiftToCpp(p.escapedName, 'c++') }) - const paramsForward = [ - 'sharedClosureHolder.get()', - ...type.parameters.map((p) => { - const bridge = new SwiftCxxBridgedType(p) - return bridge.parseFromCppToSwift(p.escapedName, 'c++') - }), - ] - const callFuncReturnType = returnBridge.getTypeCode('c++') - const callFuncParams = [ - 'void* _Nonnull /* closureHolder */', - ...type.parameters.map((p) => { - const bridge = new SwiftCxxBridgedType(p) - return bridge.getTypeCode('c++') - }), - ] - const functionPointerParam = `${callFuncReturnType}(* _Nonnull call)(${callFuncParams.join(', ')})` - const name = type.specializationName - const wrapperName = `${name}_Wrapper` + const callFuncReturnType = returnBridge.getTypeCode('c++') + const callCppFuncParamsSignature = type.parameters.map((p) => { + const bridge = new SwiftCxxBridgedType(p) + const cppType = bridge.getTypeCode('c++') + return `${cppType} ${p.escapedName}` + }) let callCppFuncBody: string if (returnBridge.hasType) { callCppFuncBody = ` -auto __result = _function(${callParamsForward.join(', ')}); +auto __result = _function->operator()(${callParamsForward.join(', ')}); return ${returnBridge.parseFromCppToSwift('__result', 'c++')}; `.trim() } else { - callCppFuncBody = `_function(${callParamsForward.join(', ')});` + callCppFuncBody = `_function->operator()(${callParamsForward.join(', ')});` } - let callSwiftFuncBody: string - if (returnBridge.hasType) { - callSwiftFuncBody = ` -auto __result = call(${paramsForward.join(', ')}); + let body: string + if (type.returnType.kind === 'void') { + body = ` +swiftClosure.call(${paramsForward.join(', ')}); +`.trim() + } else { + body = ` +auto __result = swiftClosure.call(${paramsForward.join(', ')}); return ${returnBridge.parseFromSwiftToCpp('__result', 'c++')}; `.trim() - } else { - callSwiftFuncBody = `call(${paramsForward.join(', ')});` } - // TODO: Remove shared_Func_void(...) function that returns a std::shared_ptr> - // once Swift fixes the bug where a regular std::function cannot be captured. - // https://github.com/swiftlang/swift/issues/76143 - return { cxxType: actualType, funcName: `create_${name}`, @@ -370,22 +359,16 @@ using ${name} = ${actualType}; */ class ${wrapperName} final { public: - explicit ${wrapperName}(const ${actualType}& func): _function(func) {} - explicit ${wrapperName}(${actualType}&& func): _function(std::move(func)) {} + explicit ${wrapperName}(${actualType}&& func): _function(std::make_shared<${actualType}>(std::move(func))) {} inline ${callFuncReturnType} call(${callCppFuncParamsSignature.join(', ')}) const { ${indent(callCppFuncBody, ' ')} } private: - ${actualType} _function; -} SWIFT_NONCOPYABLE; -inline ${name} create_${name}(void* _Nonnull closureHolder, ${functionPointerParam}, void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return ${name}([sharedClosureHolder = std::move(sharedClosureHolder), call](${paramsSignature.join(', ')}) -> ${type.returnType.getCode('c++')} { - ${indent(callSwiftFuncBody, ' ')} - }); -} -inline std::shared_ptr<${wrapperName}> share_${name}(const ${name}& value) { - return std::make_shared<${wrapperName}>(value); + std::shared_ptr<${actualType}> _function; +}; +${name} create_${name}(void* _Nonnull swiftClosureWrapper); +inline ${wrapperName} wrap_${name}(${name} value) { + return ${wrapperName}(std::move(value)); } `.trim(), requiredIncludes: [ @@ -402,6 +385,24 @@ inline std::shared_ptr<${wrapperName}> share_${name}(const ${name}& value) { ...bridgedType.getRequiredImports(), ], }, + cxxImplementation: { + code: ` +${name} create_${name}(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = ${swiftClassName}::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](${paramsSignature.join(', ')}) mutable -> ${type.returnType.getCode('c++')} { + ${indent(body, ' ')} + }; +} +`.trim(), + requiredIncludes: [ + { + language: 'c++', + // Swift umbrella header + name: getUmbrellaHeaderName(), + space: 'user', + }, + ], + }, dependencies: [], } } @@ -566,7 +567,7 @@ ${functions.join('\n')} function createCxxPromiseSwiftHelper(type: PromiseType): SwiftCxxHelper { const resultingType = type.resultingType.getCode('c++') const bridgedType = new SwiftCxxBridgedType(type) - const actualType = `PromiseHolder<${resultingType}>` + const actualType = `std::shared_ptr>` const resolverArgs: NamedType[] = [] if (type.resultingType.kind !== 'void') { @@ -589,7 +590,10 @@ function createCxxPromiseSwiftHelper(type: PromiseType): SwiftCxxHelper { */ using ${name} = ${actualType}; inline ${actualType} create_${name}() { - return PromiseHolder<${resultingType}>::create(); + return Promise<${resultingType}>::create(); +} +inline PromiseHolder<${resultingType}> wrap_${name}(${actualType} promise) { + return PromiseHolder<${resultingType}>(std::move(promise)); } `.trim(), requiredIncludes: [ diff --git a/packages/nitrogen/src/syntax/swift/SwiftFunction.ts b/packages/nitrogen/src/syntax/swift/SwiftFunction.ts new file mode 100644 index 000000000..97b47471b --- /dev/null +++ b/packages/nitrogen/src/syntax/swift/SwiftFunction.ts @@ -0,0 +1,85 @@ +import { indent } from '../../utils.js' +import { createFileMetadataString } from '../helpers.js' +import type { SourceFile } from '../SourceFile.js' +import type { FunctionType } from '../types/FunctionType.js' +import { SwiftCxxBridgedType } from './SwiftCxxBridgedType.js' +import { getBridgeNamespace } from './SwiftHybridObjectBridge.js' + +export function createSwiftFunctionBridge( + functionType: FunctionType +): SourceFile { + const swiftClassName = functionType.specializationName + const argsTypes = functionType.parameters.map((p) => { + const bridged = new SwiftCxxBridgedType(p) + return `${p.escapedName}: ${bridged.getTypeCode('swift')}` + }) + const returnType = new SwiftCxxBridgedType(functionType.returnType) + const argsForward = functionType.parameters.map((p) => { + const bridged = new SwiftCxxBridgedType(p) + return bridged.parseFromCppToSwift(p.escapedName, 'swift') + }) + + let body: string + if (functionType.returnType.kind === 'void') { + body = ` +self.closure(${argsForward.join(', ')}) + `.trim() + } else { + body = ` +let __result: ${functionType.returnType.getCode('swift')} = self.closure(${argsForward.join(', ')}) +return ${returnType.parseFromSwiftToCpp('__result', 'swift')} + `.trim() + } + + const code = ` +${createFileMetadataString(`${swiftClassName}.swift`)} + +import NitroModules + +/** + * Wraps a Swift \`${functionType.getCode('swift')}\` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a \`std::function\`. + */ +public final class ${swiftClassName} { + public typealias bridge = ${getBridgeNamespace()} + + private let closure: ${functionType.getCode('swift')} + + public init(_ closure: @escaping ${functionType.getCode('swift')}) { + self.closure = closure + } + + @inline(__always) + public func call(${argsTypes.join(', ')}) -> ${returnType.getTypeCode('swift')} { + ${indent(body, ' ')} + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a \`${swiftClassName}\`. + * The pointer has to be a retained opaque \`Unmanaged<${swiftClassName}>\`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> ${swiftClassName} { + return Unmanaged<${swiftClassName}>.fromOpaque(pointer).takeRetainedValue() + } +} + `.trim() + + return { + content: code, + language: 'swift', + name: `${swiftClassName}.swift`, + platform: 'ios', + subdirectory: [], + } +} diff --git a/packages/nitrogen/src/syntax/types/PromiseType.ts b/packages/nitrogen/src/syntax/types/PromiseType.ts index 190d9ecbd..22007731c 100644 --- a/packages/nitrogen/src/syntax/types/PromiseType.ts +++ b/packages/nitrogen/src/syntax/types/PromiseType.ts @@ -1,12 +1,18 @@ import type { Language } from '../../getPlatformSpecs.js' import { type SourceFile, type SourceImport } from '../SourceFile.js' +import { ErrorType } from './ErrorType.js' +import { FunctionType } from './FunctionType.js' +import { NamedWrappingType } from './NamedWrappingType.js' import type { Type, TypeKind } from './Type.js' +import { VoidType } from './VoidType.js' export class PromiseType implements Type { readonly resultingType: Type + readonly errorType: Type constructor(resultingType: Type) { this.resultingType = resultingType + this.errorType = new ErrorType() } get canBePassedByReference(): boolean { @@ -17,6 +23,22 @@ export class PromiseType implements Type { return 'promise' } + get resolverFunction(): FunctionType { + if (this.resultingType.kind === 'void') { + return new FunctionType(new VoidType(), []) + } else { + return new FunctionType(new VoidType(), [ + new NamedWrappingType('value', this.resultingType), + ]) + } + } + + get rejecterFunction(): FunctionType { + return new FunctionType(new VoidType(), [ + new NamedWrappingType('error', this.errorType), + ]) + } + getCode(language: Language): string { const resultingCode = this.resultingType.getCode(language) switch (language) { diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp index 682d80eca..f8ab3605c 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.cpp @@ -17,6 +17,14 @@ namespace margelo::nitro::image::bridge::swift { + // pragma MARK: std::function + Func_void_std__string create_Func_void_std__string(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_std__string::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](const std::string& path) mutable -> void { + swiftClosure.call(path); + }; + } + // pragma MARK: std::shared_ptr std::shared_ptr create_std__shared_ptr_margelo__nitro__image__HybridImageSpec_(void* _Nonnull swiftUnsafePointer) { NitroImage::HybridImageSpec_cxx swiftPart = NitroImage::HybridImageSpec_cxx::fromUnsafe(swiftUnsafePointer); @@ -65,6 +73,88 @@ namespace margelo::nitro::image::bridge::swift { return swiftPart.toUnsafe(); } + // pragma MARK: std::function& /* array */)> + Func_void_std__vector_Powertrain_ create_Func_void_std__vector_Powertrain_(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_std__vector_Powertrain_::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](const std::vector& array) mutable -> void { + swiftClosure.call(array); + }; + } + + // pragma MARK: std::function + Func_void create_Func_void(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)]() mutable -> void { + swiftClosure.call(); + }; + } + + // pragma MARK: std::function + Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void { + swiftClosure.call(error); + }; + } + + // pragma MARK: std::function + Func_void_int64_t create_Func_void_int64_t(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_int64_t::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](int64_t result) mutable -> void { + swiftClosure.call(result); + }; + } + + // pragma MARK: std::function + Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_double::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](double result) mutable -> void { + swiftClosure.call(result); + }; + } + + // pragma MARK: std::function + Func_void_Car create_Func_void_Car(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_Car::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](const Car& result) mutable -> void { + swiftClosure.call(result); + }; + } + + // pragma MARK: std::function /* maybe */)> + Func_void_std__optional_double_ create_Func_void_std__optional_double_(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_std__optional_double_::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](std::optional maybe) mutable -> void { + swiftClosure.call(maybe); + }; + } + + // pragma MARK: std::function>()> + Func_std__shared_ptr_Promise_double__ create_Func_std__shared_ptr_Promise_double__(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_std__shared_ptr_Promise_double__::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)]() mutable -> std::shared_ptr> { + auto __result = swiftClosure.call(); + return __result; + }; + } + + // pragma MARK: std::function>()> + Func_std__shared_ptr_Promise_std__string__ create_Func_std__shared_ptr_Promise_std__string__(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_std__shared_ptr_Promise_std__string__::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)]() mutable -> std::shared_ptr> { + auto __result = swiftClosure.call(); + return __result; + }; + } + + // pragma MARK: std::function& /* result */)> + Func_void_std__shared_ptr_ArrayBuffer_ create_Func_void_std__shared_ptr_ArrayBuffer_(void* _Nonnull swiftClosureWrapper) { + auto swiftClosure = NitroImage::Func_void_std__shared_ptr_ArrayBuffer_::fromUnsafe(swiftClosureWrapper); + return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr& result) mutable -> void { + swiftClosure.call(ArrayBufferHolder(result)); + }; + } + // pragma MARK: std::shared_ptr std::shared_ptr create_std__shared_ptr_margelo__nitro__image__HybridBaseSpec_(void* _Nonnull swiftUnsafePointer) { NitroImage::HybridBaseSpec_cxx swiftPart = NitroImage::HybridBaseSpec_cxx::fromUnsafe(swiftUnsafePointer); diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp index a82067302..881dd86c2 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/NitroImage-Swift-Cxx-Bridge.hpp @@ -85,22 +85,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_std__string_Wrapper final { public: - explicit Func_void_std__string_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_std__string_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_std__string_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call(std::string path) const { - _function(path); + _function->operator()(path); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void_std__string create_Func_void_std__string(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::string), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_std__string([sharedClosureHolder = std::move(sharedClosureHolder), call](const std::string& path) -> void { - call(sharedClosureHolder.get(), path); - }); - } - inline std::shared_ptr share_Func_void_std__string(const Func_void_std__string& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void_std__string create_Func_void_std__string(void* _Nonnull swiftClosureWrapper); + inline Func_void_std__string_Wrapper wrap_Func_void_std__string(Func_void_std__string value) { + return Func_void_std__string_Wrapper(std::move(value)); } // pragma MARK: std::shared_ptr @@ -265,31 +259,28 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_std__vector_Powertrain__Wrapper final { public: - explicit Func_void_std__vector_Powertrain__Wrapper(const std::function& /* array */)>& func): _function(func) {} - explicit Func_void_std__vector_Powertrain__Wrapper(std::function& /* array */)>&& func): _function(std::move(func)) {} + explicit Func_void_std__vector_Powertrain__Wrapper(std::function& /* array */)>&& func): _function(std::make_shared& /* array */)>>(std::move(func))) {} inline void call(std::vector array) const { - _function(array); + _function->operator()(array); } private: - std::function& /* array */)> _function; - } SWIFT_NONCOPYABLE; - inline Func_void_std__vector_Powertrain_ create_Func_void_std__vector_Powertrain_(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::vector), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_std__vector_Powertrain_([sharedClosureHolder = std::move(sharedClosureHolder), call](const std::vector& array) -> void { - call(sharedClosureHolder.get(), array); - }); - } - inline std::shared_ptr share_Func_void_std__vector_Powertrain_(const Func_void_std__vector_Powertrain_& value) { - return std::make_shared(value); + std::shared_ptr& /* array */)>> _function; + }; + Func_void_std__vector_Powertrain_ create_Func_void_std__vector_Powertrain_(void* _Nonnull swiftClosureWrapper); + inline Func_void_std__vector_Powertrain__Wrapper wrap_Func_void_std__vector_Powertrain_(Func_void_std__vector_Powertrain_ value) { + return Func_void_std__vector_Powertrain__Wrapper(std::move(value)); } - // pragma MARK: PromiseHolder + // pragma MARK: std::shared_ptr> /** - * Specialized version of `PromiseHolder`. + * Specialized version of `std::shared_ptr>`. */ - using PromiseHolder_void_ = PromiseHolder; - inline PromiseHolder create_PromiseHolder_void_() { - return PromiseHolder::create(); + using std__shared_ptr_Promise_void__ = std::shared_ptr>; + inline std::shared_ptr> create_std__shared_ptr_Promise_void__() { + return Promise::create(); + } + inline PromiseHolder wrap_std__shared_ptr_Promise_void__(std::shared_ptr> promise) { + return PromiseHolder(std::move(promise)); } // pragma MARK: std::function @@ -302,22 +293,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_Wrapper final { public: - explicit Func_void_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call() const { - _function(); + _function->operator()(); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void create_Func_void(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void([sharedClosureHolder = std::move(sharedClosureHolder), call]() -> void { - call(sharedClosureHolder.get()); - }); - } - inline std::shared_ptr share_Func_void(const Func_void& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void create_Func_void(void* _Nonnull swiftClosureWrapper); + inline Func_void_Wrapper wrap_Func_void(Func_void value) { + return Func_void_Wrapper(std::move(value)); } // pragma MARK: std::function @@ -330,22 +315,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_std__exception_ptr_Wrapper final { public: - explicit Func_void_std__exception_ptr_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_std__exception_ptr_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_std__exception_ptr_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call(std::exception_ptr error) const { - _function(error); + _function->operator()(error); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::exception_ptr), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_std__exception_ptr([sharedClosureHolder = std::move(sharedClosureHolder), call](const std::exception_ptr& error) -> void { - call(sharedClosureHolder.get(), error); - }); - } - inline std::shared_ptr share_Func_void_std__exception_ptr(const Func_void_std__exception_ptr& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* _Nonnull swiftClosureWrapper); + inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) { + return Func_void_std__exception_ptr_Wrapper(std::move(value)); } // pragma MARK: std::optional @@ -386,13 +365,16 @@ namespace margelo::nitro::image::bridge::swift { return std::get<1>(variantWrapper.variant); } - // pragma MARK: PromiseHolder + // pragma MARK: std::shared_ptr> /** - * Specialized version of `PromiseHolder`. + * Specialized version of `std::shared_ptr>`. */ - using PromiseHolder_int64_t_ = PromiseHolder; - inline PromiseHolder create_PromiseHolder_int64_t_() { - return PromiseHolder::create(); + using std__shared_ptr_Promise_int64_t__ = std::shared_ptr>; + inline std::shared_ptr> create_std__shared_ptr_Promise_int64_t__() { + return Promise::create(); + } + inline PromiseHolder wrap_std__shared_ptr_Promise_int64_t__(std::shared_ptr> promise) { + return PromiseHolder(std::move(promise)); } // pragma MARK: std::function @@ -405,31 +387,28 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_int64_t_Wrapper final { public: - explicit Func_void_int64_t_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_int64_t_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_int64_t_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call(int64_t result) const { - _function(result); + _function->operator()(result); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void_int64_t create_Func_void_int64_t(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, int64_t), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_int64_t([sharedClosureHolder = std::move(sharedClosureHolder), call](int64_t result) -> void { - call(sharedClosureHolder.get(), result); - }); - } - inline std::shared_ptr share_Func_void_int64_t(const Func_void_int64_t& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void_int64_t create_Func_void_int64_t(void* _Nonnull swiftClosureWrapper); + inline Func_void_int64_t_Wrapper wrap_Func_void_int64_t(Func_void_int64_t value) { + return Func_void_int64_t_Wrapper(std::move(value)); } - // pragma MARK: PromiseHolder + // pragma MARK: std::shared_ptr> /** - * Specialized version of `PromiseHolder`. + * Specialized version of `std::shared_ptr>`. */ - using PromiseHolder_double_ = PromiseHolder; - inline PromiseHolder create_PromiseHolder_double_() { - return PromiseHolder::create(); + using std__shared_ptr_Promise_double__ = std::shared_ptr>; + inline std::shared_ptr> create_std__shared_ptr_Promise_double__() { + return Promise::create(); + } + inline PromiseHolder wrap_std__shared_ptr_Promise_double__(std::shared_ptr> promise) { + return PromiseHolder(std::move(promise)); } // pragma MARK: std::function @@ -442,22 +421,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_double_Wrapper final { public: - explicit Func_void_double_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_double_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_double_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call(double result) const { - _function(result); + _function->operator()(result); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void_double create_Func_void_double(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, double), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_double([sharedClosureHolder = std::move(sharedClosureHolder), call](double result) -> void { - call(sharedClosureHolder.get(), result); - }); - } - inline std::shared_ptr share_Func_void_double(const Func_void_double& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void_double create_Func_void_double(void* _Nonnull swiftClosureWrapper); + inline Func_void_double_Wrapper wrap_Func_void_double(Func_void_double value) { + return Func_void_double_Wrapper(std::move(value)); } // pragma MARK: std::optional @@ -469,13 +442,16 @@ namespace margelo::nitro::image::bridge::swift { return std::optional(value); } - // pragma MARK: PromiseHolder + // pragma MARK: std::shared_ptr> /** - * Specialized version of `PromiseHolder`. + * Specialized version of `std::shared_ptr>`. */ - using PromiseHolder_Car_ = PromiseHolder; - inline PromiseHolder create_PromiseHolder_Car_() { - return PromiseHolder::create(); + using std__shared_ptr_Promise_Car__ = std::shared_ptr>; + inline std::shared_ptr> create_std__shared_ptr_Promise_Car__() { + return Promise::create(); + } + inline PromiseHolder wrap_std__shared_ptr_Promise_Car__(std::shared_ptr> promise) { + return PromiseHolder(std::move(promise)); } // pragma MARK: std::function @@ -488,22 +464,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_Car_Wrapper final { public: - explicit Func_void_Car_Wrapper(const std::function& func): _function(func) {} - explicit Func_void_Car_Wrapper(std::function&& func): _function(std::move(func)) {} + explicit Func_void_Car_Wrapper(std::function&& func): _function(std::make_shared>(std::move(func))) {} inline void call(Car result) const { - _function(result); + _function->operator()(result); } private: - std::function _function; - } SWIFT_NONCOPYABLE; - inline Func_void_Car create_Func_void_Car(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, Car), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_Car([sharedClosureHolder = std::move(sharedClosureHolder), call](const Car& result) -> void { - call(sharedClosureHolder.get(), result); - }); - } - inline std::shared_ptr share_Func_void_Car(const Func_void_Car& value) { - return std::make_shared(value); + std::shared_ptr> _function; + }; + Func_void_Car create_Func_void_Car(void* _Nonnull swiftClosureWrapper); + inline Func_void_Car_Wrapper wrap_Func_void_Car(Func_void_Car value) { + return Func_void_Car_Wrapper(std::move(value)); } // pragma MARK: std::optional @@ -525,22 +495,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_std__optional_double__Wrapper final { public: - explicit Func_void_std__optional_double__Wrapper(const std::function /* maybe */)>& func): _function(func) {} - explicit Func_void_std__optional_double__Wrapper(std::function /* maybe */)>&& func): _function(std::move(func)) {} + explicit Func_void_std__optional_double__Wrapper(std::function /* maybe */)>&& func): _function(std::make_shared /* maybe */)>>(std::move(func))) {} inline void call(std::optional maybe) const { - _function(maybe); + _function->operator()(maybe); } private: - std::function /* maybe */)> _function; - } SWIFT_NONCOPYABLE; - inline Func_void_std__optional_double_ create_Func_void_std__optional_double_(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::optional), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_std__optional_double_([sharedClosureHolder = std::move(sharedClosureHolder), call](std::optional maybe) -> void { - call(sharedClosureHolder.get(), maybe); - }); - } - inline std::shared_ptr share_Func_void_std__optional_double_(const Func_void_std__optional_double_& value) { - return std::make_shared(value); + std::shared_ptr /* maybe */)>> _function; + }; + Func_void_std__optional_double_ create_Func_void_std__optional_double_(void* _Nonnull swiftClosureWrapper); + inline Func_void_std__optional_double__Wrapper wrap_Func_void_std__optional_double_(Func_void_std__optional_double_ value) { + return Func_void_std__optional_double__Wrapper(std::move(value)); } // pragma MARK: std::function>()> @@ -553,24 +517,17 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_std__shared_ptr_Promise_double___Wrapper final { public: - explicit Func_std__shared_ptr_Promise_double___Wrapper(const std::function>()>& func): _function(func) {} - explicit Func_std__shared_ptr_Promise_double___Wrapper(std::function>()>&& func): _function(std::move(func)) {} - inline PromiseHolder call() const { - auto __result = _function(); + explicit Func_std__shared_ptr_Promise_double___Wrapper(std::function>()>&& func): _function(std::make_shared>()>>(std::move(func))) {} + inline std::shared_ptr> call() const { + auto __result = _function->operator()(); return __result; } private: - std::function>()> _function; - } SWIFT_NONCOPYABLE; - inline Func_std__shared_ptr_Promise_double__ create_Func_std__shared_ptr_Promise_double__(void* _Nonnull closureHolder, PromiseHolder(* _Nonnull call)(void* _Nonnull /* closureHolder */), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_std__shared_ptr_Promise_double__([sharedClosureHolder = std::move(sharedClosureHolder), call]() -> std::shared_ptr> { - auto __result = call(sharedClosureHolder.get()); - return __result.getPromise(); - }); - } - inline std::shared_ptr share_Func_std__shared_ptr_Promise_double__(const Func_std__shared_ptr_Promise_double__& value) { - return std::make_shared(value); + std::shared_ptr>()>> _function; + }; + Func_std__shared_ptr_Promise_double__ create_Func_std__shared_ptr_Promise_double__(void* _Nonnull swiftClosureWrapper); + inline Func_std__shared_ptr_Promise_double___Wrapper wrap_Func_std__shared_ptr_Promise_double__(Func_std__shared_ptr_Promise_double__ value) { + return Func_std__shared_ptr_Promise_double___Wrapper(std::move(value)); } // pragma MARK: std::function>()> @@ -583,42 +540,41 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_std__shared_ptr_Promise_std__string___Wrapper final { public: - explicit Func_std__shared_ptr_Promise_std__string___Wrapper(const std::function>()>& func): _function(func) {} - explicit Func_std__shared_ptr_Promise_std__string___Wrapper(std::function>()>&& func): _function(std::move(func)) {} - inline PromiseHolder call() const { - auto __result = _function(); + explicit Func_std__shared_ptr_Promise_std__string___Wrapper(std::function>()>&& func): _function(std::make_shared>()>>(std::move(func))) {} + inline std::shared_ptr> call() const { + auto __result = _function->operator()(); return __result; } private: - std::function>()> _function; - } SWIFT_NONCOPYABLE; - inline Func_std__shared_ptr_Promise_std__string__ create_Func_std__shared_ptr_Promise_std__string__(void* _Nonnull closureHolder, PromiseHolder(* _Nonnull call)(void* _Nonnull /* closureHolder */), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_std__shared_ptr_Promise_std__string__([sharedClosureHolder = std::move(sharedClosureHolder), call]() -> std::shared_ptr> { - auto __result = call(sharedClosureHolder.get()); - return __result.getPromise(); - }); - } - inline std::shared_ptr share_Func_std__shared_ptr_Promise_std__string__(const Func_std__shared_ptr_Promise_std__string__& value) { - return std::make_shared(value); + std::shared_ptr>()>> _function; + }; + Func_std__shared_ptr_Promise_std__string__ create_Func_std__shared_ptr_Promise_std__string__(void* _Nonnull swiftClosureWrapper); + inline Func_std__shared_ptr_Promise_std__string___Wrapper wrap_Func_std__shared_ptr_Promise_std__string__(Func_std__shared_ptr_Promise_std__string__ value) { + return Func_std__shared_ptr_Promise_std__string___Wrapper(std::move(value)); } - // pragma MARK: PromiseHolder + // pragma MARK: std::shared_ptr> /** - * Specialized version of `PromiseHolder`. + * Specialized version of `std::shared_ptr>`. */ - using PromiseHolder_std__string_ = PromiseHolder; - inline PromiseHolder create_PromiseHolder_std__string_() { - return PromiseHolder::create(); + using std__shared_ptr_Promise_std__string__ = std::shared_ptr>; + inline std::shared_ptr> create_std__shared_ptr_Promise_std__string__() { + return Promise::create(); + } + inline PromiseHolder wrap_std__shared_ptr_Promise_std__string__(std::shared_ptr> promise) { + return PromiseHolder(std::move(promise)); } - // pragma MARK: PromiseHolder> + // pragma MARK: std::shared_ptr>> /** - * Specialized version of `PromiseHolder>`. + * Specialized version of `std::shared_ptr>>`. */ - using PromiseHolder_std__shared_ptr_ArrayBuffer__ = PromiseHolder>; - inline PromiseHolder> create_PromiseHolder_std__shared_ptr_ArrayBuffer__() { - return PromiseHolder>::create(); + using std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___ = std::shared_ptr>>; + inline std::shared_ptr>> create_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___() { + return Promise>::create(); + } + inline PromiseHolder> wrap_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___(std::shared_ptr>> promise) { + return PromiseHolder>(std::move(promise)); } // pragma MARK: std::function& /* result */)> @@ -631,22 +587,16 @@ namespace margelo::nitro::image::bridge::swift { */ class Func_void_std__shared_ptr_ArrayBuffer__Wrapper final { public: - explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(const std::function& /* result */)>& func): _function(func) {} - explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(std::function& /* result */)>&& func): _function(std::move(func)) {} + explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(std::function& /* result */)>&& func): _function(std::make_shared& /* result */)>>(std::move(func))) {} inline void call(ArrayBufferHolder result) const { - _function(result.getArrayBuffer()); + _function->operator()(result.getArrayBuffer()); } private: - std::function& /* result */)> _function; - } SWIFT_NONCOPYABLE; - inline Func_void_std__shared_ptr_ArrayBuffer_ create_Func_void_std__shared_ptr_ArrayBuffer_(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, ArrayBufferHolder), void(* _Nonnull destroy)(void* _Nonnull)) { - std::shared_ptr sharedClosureHolder(closureHolder, destroy); - return Func_void_std__shared_ptr_ArrayBuffer_([sharedClosureHolder = std::move(sharedClosureHolder), call](const std::shared_ptr& result) -> void { - call(sharedClosureHolder.get(), ArrayBufferHolder(result)); - }); - } - inline std::shared_ptr share_Func_void_std__shared_ptr_ArrayBuffer_(const Func_void_std__shared_ptr_ArrayBuffer_& value) { - return std::make_shared(value); + std::shared_ptr& /* result */)>> _function; + }; + Func_void_std__shared_ptr_ArrayBuffer_ create_Func_void_std__shared_ptr_ArrayBuffer_(void* _Nonnull swiftClosureWrapper); + inline Func_void_std__shared_ptr_ArrayBuffer__Wrapper wrap_Func_void_std__shared_ptr_ArrayBuffer_(Func_void_std__shared_ptr_ArrayBuffer_ value) { + return Func_void_std__shared_ptr_ArrayBuffer__Wrapper(std::move(value)); } // pragma MARK: std::shared_ptr diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift new file mode 100644 index 000000000..586ac9ea2 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_double__.swift @@ -0,0 +1,54 @@ +/// +/// Func_std__shared_ptr_Promise_double__.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `(() -> Promise)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_std__shared_ptr_Promise_double__ { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: (() -> Promise) + + public init(_ closure: @escaping (() -> Promise)) { + self.closure = closure + } + + @inline(__always) + public func call() -> bridge.std__shared_ptr_Promise_double__ { + let __result: Promise = self.closure() + return { () -> bridge.std__shared_ptr_Promise_double__ in + let __promise = bridge.create_std__shared_ptr_Promise_double__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__promise) + __result + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) + return __promise + }() + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_double__`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_double__ { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift new file mode 100644 index 000000000..e28348a44 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__string__.swift @@ -0,0 +1,54 @@ +/// +/// Func_std__shared_ptr_Promise_std__string__.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `(() -> Promise)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_std__shared_ptr_Promise_std__string__ { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: (() -> Promise) + + public init(_ closure: @escaping (() -> Promise)) { + self.closure = closure + } + + @inline(__always) + public func call() -> bridge.std__shared_ptr_Promise_std__string__ { + let __result: Promise = self.closure() + return { () -> bridge.std__shared_ptr_Promise_std__string__ in + let __promise = bridge.create_std__shared_ptr_Promise_std__string__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise) + __result + .then({ __result in __promiseHolder.resolve(std.string(__result)) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) + return __promise + }() + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__string__`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__string__ { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift new file mode 100644 index 000000000..6f287786d --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void.swift @@ -0,0 +1,46 @@ +/// +/// Func_void.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `(() -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: (() -> Void) + + public init(_ closure: @escaping (() -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call() -> Void { + self.closure() + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift new file mode 100644 index 000000000..2c9db07f9 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_Car.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_Car.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ value: Car) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_Car { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ value: Car) -> Void) + + public init(_ closure: @escaping ((_ value: Car) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(value: Car) -> Void { + self.closure(value) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_Car`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_Car { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift new file mode 100644 index 000000000..cbbcf48f0 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_double.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_double.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ value: Double) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_double { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ value: Double) -> Void) + + public init(_ closure: @escaping ((_ value: Double) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(value: Double) -> Void { + self.closure(value) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_double`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_double { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift new file mode 100644 index 000000000..f9197bc41 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_int64_t.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_int64_t.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ value: Int64) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_int64_t { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ value: Int64) -> Void) + + public init(_ closure: @escaping ((_ value: Int64) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(value: Int64) -> Void { + self.closure(value) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_int64_t`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_int64_t { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift new file mode 100644 index 000000000..9c1ac436a --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_std__exception_ptr.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ error: Error) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_std__exception_ptr { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ error: Error) -> Void) + + public init(_ closure: @escaping ((_ error: Error) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(error: std.exception_ptr) -> Void { + self.closure(RuntimeError.from(cppError: error)) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_std__exception_ptr`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift new file mode 100644 index 000000000..b6e9489c1 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__optional_double_.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_std__optional_double_.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ maybe: Double?) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_std__optional_double_ { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ maybe: Double?) -> Void) + + public init(_ closure: @escaping ((_ maybe: Double?) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(maybe: bridge.std__optional_double_) -> Void { + self.closure(maybe.value) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_std__optional_double_`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_double_ { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift new file mode 100644 index 000000000..08b30e6f1 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_ArrayBuffer_.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_std__shared_ptr_ArrayBuffer_.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ value: ArrayBufferHolder) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_std__shared_ptr_ArrayBuffer_ { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ value: ArrayBufferHolder) -> Void) + + public init(_ closure: @escaping ((_ value: ArrayBufferHolder) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(value: ArrayBufferHolder) -> Void { + self.closure(value) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_std__shared_ptr_ArrayBuffer_`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_ArrayBuffer_ { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift new file mode 100644 index 000000000..23d0fc6e5 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__string.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_std__string.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ valueFromJs: String) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_std__string { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ valueFromJs: String) -> Void) + + public init(_ closure: @escaping ((_ valueFromJs: String) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(valueFromJs: std.string) -> Void { + self.closure(String(valueFromJs)) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_std__string`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift new file mode 100644 index 000000000..4eeb326ec --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/Func_void_std__vector_Powertrain_.swift @@ -0,0 +1,46 @@ +/// +/// Func_void_std__vector_Powertrain_.swift +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +import NitroModules + +/** + * Wraps a Swift `((_ array: [Powertrain]) -> Void)` as a class. + * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`. + */ +public final class Func_void_std__vector_Powertrain_ { + public typealias bridge = margelo.nitro.image.bridge.swift + + private let closure: ((_ array: [Powertrain]) -> Void) + + public init(_ closure: @escaping ((_ array: [Powertrain]) -> Void)) { + self.closure = closure + } + + @inline(__always) + public func call(array: bridge.std__vector_Powertrain_) -> Void { + self.closure(array.map({ __item in __item })) + } + + /** + * Casts this instance to a retained unsafe raw pointer. + * This acquires one additional strong reference on the object! + */ + @inline(__always) + public func toUnsafe() -> UnsafeMutableRawPointer { + return Unmanaged.passRetained(self).toOpaque() + } + + /** + * Casts an unsafe pointer to a `Func_void_std__vector_Powertrain_`. + * The pointer has to be a retained opaque `Unmanaged`. + * This removes one strong reference from the object! + */ + @inline(__always) + public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_Powertrain_ { + return Unmanaged.fromOpaque(pointer).takeRetainedValue() + } +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift index 6a7c906d6..63b28065e 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridImageSpec_cxx.swift @@ -139,9 +139,9 @@ public class HybridImageSpec_cxx { public func saveToFile(path: std.string, onFinished: bridge.Func_void_std__string) -> bridge.Result_void_ { do { try self.__implementation.saveToFile(path: String(path), onFinished: { () -> ((String) -> Void) in - let __sharedClosure = bridge.share_Func_void_std__string(onFinished) + let __wrappedFunction = bridge.wrap_Func_void_std__string(onFinished) return { (__path: String) -> Void in - __sharedClosure.pointee.call(std.string(__path)) + __wrappedFunction.call(std.string(__path)) } }()) return bridge.create_Result_void_() diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift index ad1831653..7a102a67c 100644 --- a/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/swift/HybridTestObjectSwiftKotlinSpec_cxx.swift @@ -480,9 +480,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func complexEnumCallback(array: bridge.std__vector_Powertrain_, callback: bridge.Func_void_std__vector_Powertrain_) -> bridge.Result_void_ { do { try self.__implementation.complexEnumCallback(array: array.map({ __item in __item }), callback: { () -> (([Powertrain]) -> Void) in - let __sharedClosure = bridge.share_Func_void_std__vector_Powertrain_(callback) + let __wrappedFunction = bridge.wrap_Func_void_std__vector_Powertrain_(callback) return { (__array: [Powertrain]) -> Void in - __sharedClosure.pointee.call({ () -> bridge.std__vector_Powertrain_ in + __wrappedFunction.call({ () -> bridge.std__vector_Powertrain_ in var __vector = bridge.create_std__vector_Powertrain_(__array.count) for __item in __array { __vector.push_back(__item) @@ -538,13 +538,14 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func funcThatThrowsBeforePromise() -> bridge.Result_std__shared_ptr_Promise_void___ { do { let __result = try self.__implementation.funcThatThrowsBeforePromise() - let __resultCpp = { () -> bridge.PromiseHolder_void_ in - let __promise = bridge.create_PromiseHolder_void_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in + let __promise = bridge.create_std__shared_ptr_Promise_void__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise) __result - .then({ __result in __promise.resolve() }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve() }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -627,13 +628,14 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func calculateFibonacciAsync(value: Double) -> bridge.Result_std__shared_ptr_Promise_int64_t___ { do { let __result = try self.__implementation.calculateFibonacciAsync(value: value) - let __resultCpp = { () -> bridge.PromiseHolder_int64_t_ in - let __promise = bridge.create_PromiseHolder_int64_t_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_int64_t__ in + let __promise = bridge.create_std__shared_ptr_Promise_int64_t__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_int64_t__(__promise) __result - .then({ __result in __promise.resolve(__result) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_int64_t___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -645,13 +647,14 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func wait(seconds: Double) -> bridge.Result_std__shared_ptr_Promise_void___ { do { let __result = try self.__implementation.wait(seconds: seconds) - let __resultCpp = { () -> bridge.PromiseHolder_void_ in - let __promise = bridge.create_PromiseHolder_void_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in + let __promise = bridge.create_std__shared_ptr_Promise_void__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise) __result - .then({ __result in __promise.resolve() }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve() }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -663,13 +666,14 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func promiseThrows() -> bridge.Result_std__shared_ptr_Promise_void___ { do { let __result = try self.__implementation.promiseThrows() - let __resultCpp = { () -> bridge.PromiseHolder_void_ in - let __promise = bridge.create_PromiseHolder_void_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in + let __promise = bridge.create_std__shared_ptr_Promise_void__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise) __result - .then({ __result in __promise.resolve() }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve() }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -678,7 +682,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { } @inline(__always) - public func awaitAndGetPromise(promise: bridge.PromiseHolder_double_) -> bridge.Result_std__shared_ptr_Promise_double___ { + public func awaitAndGetPromise(promise: bridge.std__shared_ptr_Promise_double__) -> bridge.Result_std__shared_ptr_Promise_double___ { do { let __result = try self.__implementation.awaitAndGetPromise(promise: { () -> Promise in let __promise = Promise() @@ -689,60 +693,26 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { __promise.reject(withError: __error) } let __resolverCpp = { () -> bridge.Func_void_double in - final class ClosureHolder { - let closure: ((_ result: Double) -> Void) - init(wrappingClosure closure: @escaping ((_ result: Double) -> Void)) { - self.closure = closure - } - func invoke(_ __result: Double) { - self.closure(__result) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __resolver)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __result: Double) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(__result) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_double(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_double(__resolver) + return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - promise.addOnResolvedListenerCopy(__resolverCpp) - promise.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(promise) + __promiseHolder.addOnResolvedListenerCopy(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }()) - let __resultCpp = { () -> bridge.PromiseHolder_double_ in - let __promise = bridge.create_PromiseHolder_double_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_double__ in + let __promise = bridge.create_std__shared_ptr_Promise_double__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__promise) __result - .then({ __result in __promise.resolve(__result) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_double___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -751,7 +721,7 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { } @inline(__always) - public func awaitAndGetComplexPromise(promise: bridge.PromiseHolder_Car_) -> bridge.Result_std__shared_ptr_Promise_Car___ { + public func awaitAndGetComplexPromise(promise: bridge.std__shared_ptr_Promise_Car__) -> bridge.Result_std__shared_ptr_Promise_Car___ { do { let __result = try self.__implementation.awaitAndGetComplexPromise(promise: { () -> Promise in let __promise = Promise() @@ -762,60 +732,26 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { __promise.reject(withError: __error) } let __resolverCpp = { () -> bridge.Func_void_Car in - final class ClosureHolder { - let closure: ((_ result: Car) -> Void) - init(wrappingClosure closure: @escaping ((_ result: Car) -> Void)) { - self.closure = closure - } - func invoke(_ __result: Car) { - self.closure(__result) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __resolver)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __result: Car) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(__result) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_Car(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_Car(__resolver) + return bridge.create_Func_void_Car(__closureWrapper.toUnsafe()) }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - promise.addOnResolvedListener(__resolverCpp) - promise.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_Car__(promise) + __promiseHolder.addOnResolvedListener(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }()) - let __resultCpp = { () -> bridge.PromiseHolder_Car_ in - let __promise = bridge.create_PromiseHolder_Car_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_Car__ in + let __promise = bridge.create_std__shared_ptr_Promise_Car__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_Car__(__promise) __result - .then({ __result in __promise.resolve(__result) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_Car___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -824,48 +760,35 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { } @inline(__always) - public func awaitPromise(promise: bridge.PromiseHolder_void_) -> bridge.Result_std__shared_ptr_Promise_void___ { + public func awaitPromise(promise: bridge.std__shared_ptr_Promise_void__) -> bridge.Result_std__shared_ptr_Promise_void___ { do { let __result = try self.__implementation.awaitPromise(promise: { () -> Promise in let __promise = Promise() - let __resolver = SwiftClosure { __promise.resolve(withResult: ()) } + let __resolver = { __promise.resolve(withResult: ()) } let __rejecter = { (__error: Error) in __promise.reject(withError: __error) } - let __resolverCpp = __resolver.getFunctionCopy() + let __resolverCpp = { () -> bridge.Func_void in + let __closureWrapper = Func_void(__resolver) + return bridge.create_Func_void(__closureWrapper.toUnsafe()) + }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - promise.addOnResolvedListener(__resolverCpp) - promise.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(promise) + __promiseHolder.addOnResolvedListener(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }()) - let __resultCpp = { () -> bridge.PromiseHolder_void_ in - let __promise = bridge.create_PromiseHolder_void_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in + let __promise = bridge.create_std__shared_ptr_Promise_void__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise) __result - .then({ __result in __promise.resolve() }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve() }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -877,9 +800,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func callCallback(callback: bridge.Func_void) -> bridge.Result_void_ { do { try self.__implementation.callCallback(callback: { () -> (() -> Void) in - let __sharedClosure = bridge.share_Func_void(callback) + let __wrappedFunction = bridge.wrap_Func_void(callback) return { () -> Void in - __sharedClosure.pointee.call() + __wrappedFunction.call() } }()) return bridge.create_Result_void_() @@ -893,19 +816,19 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func callAll(first: bridge.Func_void, second: bridge.Func_void, third: bridge.Func_void) -> bridge.Result_void_ { do { try self.__implementation.callAll(first: { () -> (() -> Void) in - let __sharedClosure = bridge.share_Func_void(first) + let __wrappedFunction = bridge.wrap_Func_void(first) return { () -> Void in - __sharedClosure.pointee.call() + __wrappedFunction.call() } }(), second: { () -> (() -> Void) in - let __sharedClosure = bridge.share_Func_void(second) + let __wrappedFunction = bridge.wrap_Func_void(second) return { () -> Void in - __sharedClosure.pointee.call() + __wrappedFunction.call() } }(), third: { () -> (() -> Void) in - let __sharedClosure = bridge.share_Func_void(third) + let __wrappedFunction = bridge.wrap_Func_void(third) return { () -> Void in - __sharedClosure.pointee.call() + __wrappedFunction.call() } }()) return bridge.create_Result_void_() @@ -919,9 +842,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func callWithOptional(value: bridge.std__optional_double_, callback: bridge.Func_void_std__optional_double_) -> bridge.Result_void_ { do { try self.__implementation.callWithOptional(value: value.value, callback: { () -> ((Double?) -> Void) in - let __sharedClosure = bridge.share_Func_void_std__optional_double_(callback) + let __wrappedFunction = bridge.wrap_Func_void_std__optional_double_(callback) return { (__maybe: Double?) -> Void in - __sharedClosure.pointee.call({ () -> bridge.std__optional_double_ in + __wrappedFunction.call({ () -> bridge.std__optional_double_ in if let __unwrappedValue = __maybe { return bridge.create_std__optional_double_(__unwrappedValue) } else { @@ -941,9 +864,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func callSumUpNTimes(callback: bridge.Func_std__shared_ptr_Promise_double__, n: Double) -> bridge.Result_std__shared_ptr_Promise_double___ { do { let __result = try self.__implementation.callSumUpNTimes(callback: { () -> (() -> Promise) in - let __sharedClosure = bridge.share_Func_std__shared_ptr_Promise_double__(callback) + let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_double__(callback) return { () -> Promise in - let __result = __sharedClosure.pointee.call() + let __result = __wrappedFunction.call() return { () -> Promise in let __promise = Promise() let __resolver = { (__result: Double) in @@ -953,62 +876,28 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { __promise.reject(withError: __error) } let __resolverCpp = { () -> bridge.Func_void_double in - final class ClosureHolder { - let closure: ((_ result: Double) -> Void) - init(wrappingClosure closure: @escaping ((_ result: Double) -> Void)) { - self.closure = closure - } - func invoke(_ __result: Double) { - self.closure(__result) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __resolver)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __result: Double) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(__result) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_double(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_double(__resolver) + return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - __result.addOnResolvedListenerCopy(__resolverCpp) - __result.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__result) + __promiseHolder.addOnResolvedListenerCopy(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }() } }(), n: n) - let __resultCpp = { () -> bridge.PromiseHolder_double_ in - let __promise = bridge.create_PromiseHolder_double_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_double__ in + let __promise = bridge.create_std__shared_ptr_Promise_double__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__promise) __result - .then({ __result in __promise.resolve(__result) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_double___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -1020,9 +909,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func getValueFromJSCallbackAndWait(getValue: bridge.Func_std__shared_ptr_Promise_double__) -> bridge.Result_std__shared_ptr_Promise_double___ { do { let __result = try self.__implementation.getValueFromJSCallbackAndWait(getValue: { () -> (() -> Promise) in - let __sharedClosure = bridge.share_Func_std__shared_ptr_Promise_double__(getValue) + let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_double__(getValue) return { () -> Promise in - let __result = __sharedClosure.pointee.call() + let __result = __wrappedFunction.call() return { () -> Promise in let __promise = Promise() let __resolver = { (__result: Double) in @@ -1032,62 +921,28 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { __promise.reject(withError: __error) } let __resolverCpp = { () -> bridge.Func_void_double in - final class ClosureHolder { - let closure: ((_ result: Double) -> Void) - init(wrappingClosure closure: @escaping ((_ result: Double) -> Void)) { - self.closure = closure - } - func invoke(_ __result: Double) { - self.closure(__result) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __resolver)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __result: Double) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(__result) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_double(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_double(__resolver) + return bridge.create_Func_void_double(__closureWrapper.toUnsafe()) }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - __result.addOnResolvedListenerCopy(__resolverCpp) - __result.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__result) + __promiseHolder.addOnResolvedListenerCopy(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }() } }()) - let __resultCpp = { () -> bridge.PromiseHolder_double_ in - let __promise = bridge.create_PromiseHolder_double_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_double__ in + let __promise = bridge.create_std__shared_ptr_Promise_double__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_double__(__promise) __result - .then({ __result in __promise.resolve(__result) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_double___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -1099,9 +954,9 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func getValueFromJsCallback(callback: bridge.Func_std__shared_ptr_Promise_std__string__, andThenCall: bridge.Func_void_std__string) -> bridge.Result_std__shared_ptr_Promise_void___ { do { let __result = try self.__implementation.getValueFromJsCallback(callback: { () -> (() -> Promise) in - let __sharedClosure = bridge.share_Func_std__shared_ptr_Promise_std__string__(callback) + let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__string__(callback) return { () -> Promise in - let __result = __sharedClosure.pointee.call() + let __result = __wrappedFunction.call() return { () -> Promise in let __promise = Promise() let __resolver = { (__result: String) in @@ -1111,67 +966,33 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { __promise.reject(withError: __error) } let __resolverCpp = { () -> bridge.Func_void_std__string in - final class ClosureHolder { - let closure: ((_ result: String) -> Void) - init(wrappingClosure closure: @escaping ((_ result: String) -> Void)) { - self.closure = closure - } - func invoke(_ __result: String) { - self.closure(__result) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __resolver)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __result: std.string) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(String(__result)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__string(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__string(__resolver) + return bridge.create_Func_void_std__string(__closureWrapper.toUnsafe()) }() let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in - final class ClosureHolder { - let closure: ((_ error: Error) -> Void) - init(wrappingClosure closure: @escaping ((_ error: Error) -> Void)) { - self.closure = closure - } - func invoke(_ __error: Error) { - self.closure(__error) - } - } - - let __closureHolder = Unmanaged.passRetained(ClosureHolder(wrappingClosure: __rejecter)).toOpaque() - func __callClosure(__closureHolder: UnsafeMutableRawPointer, __error: std.exception_ptr) -> Void { - let closure = Unmanaged.fromOpaque(__closureHolder).takeUnretainedValue() - closure.invoke(RuntimeError.from(cppError: __error)) - } - func __destroyClosure(_ __closureHolder: UnsafeMutableRawPointer) -> Void { - Unmanaged.fromOpaque(__closureHolder).release() - } - - return bridge.create_Func_void_std__exception_ptr(__closureHolder, __callClosure, __destroyClosure) + let __closureWrapper = Func_void_std__exception_ptr(__rejecter) + return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe()) }() - __result.addOnResolvedListener(__resolverCpp) - __result.addOnRejectedListener(__rejecterCpp) + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__result) + __promiseHolder.addOnResolvedListener(__resolverCpp) + __promiseHolder.addOnRejectedListener(__rejecterCpp) return __promise }() } }(), andThenCall: { () -> ((String) -> Void) in - let __sharedClosure = bridge.share_Func_void_std__string(andThenCall) + let __wrappedFunction = bridge.wrap_Func_void_std__string(andThenCall) return { (__valueFromJs: String) -> Void in - __sharedClosure.pointee.call(std.string(__valueFromJs)) + __wrappedFunction.call(std.string(__valueFromJs)) } }()) - let __resultCpp = { () -> bridge.PromiseHolder_void_ in - let __promise = bridge.create_PromiseHolder_void_() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in + let __promise = bridge.create_std__shared_ptr_Promise_void__() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise) __result - .then({ __result in __promise.resolve() }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve() }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() @@ -1260,13 +1081,14 @@ public class HybridTestObjectSwiftKotlinSpec_cxx { public func createArrayBufferAsync() -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____ { do { let __result = try self.__implementation.createArrayBufferAsync() - let __resultCpp = { () -> bridge.PromiseHolder_std__shared_ptr_ArrayBuffer__ in - let __promise = bridge.create_PromiseHolder_std__shared_ptr_ArrayBuffer__() + let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___ in + let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___() + let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer___(__promise) __result - .then({ __result in __promise.resolve(__result.getArrayBuffer()) }) - .catch({ __error in __promise.reject(__error.toCpp()) }) + .then({ __result in __promiseHolder.resolve(__result.getArrayBuffer()) }) + .catch({ __error in __promiseHolder.reject(__error.toCpp()) }) return __promise - }().getPromise() + }() return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_ArrayBuffer____(__resultCpp) } catch (let __error) { let __exceptionPtr = __error.toCpp() diff --git a/packages/react-native-nitro-modules/ios/core/PromiseHolder.hpp b/packages/react-native-nitro-modules/ios/core/PromiseHolder.hpp index e20959a6b..ba1016d3e 100644 --- a/packages/react-native-nitro-modules/ios/core/PromiseHolder.hpp +++ b/packages/react-native-nitro-modules/ios/core/PromiseHolder.hpp @@ -53,11 +53,6 @@ class PromiseHolder final { _promise->addOnRejectedListener([onRejected = std::move(onRejected)](const std::exception_ptr& error) { onRejected(error); }); } -public: - inline std::shared_ptr> getPromise() const { - return _promise; - } - private: std::shared_ptr> _promise; }; @@ -91,11 +86,6 @@ class PromiseHolder final { _promise->addOnRejectedListener([onRejected = std::move(onRejected)](const std::exception_ptr& error) { onRejected(error); }); } -public: - inline std::shared_ptr> getPromise() const { - return _promise; - } - private: std::shared_ptr> _promise; };