Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift language feature] Implement generic return type in Swift async functions #3022

Open
kotlarmilos opened this issue Feb 24, 2025 · 0 comments
Assignees
Labels
area-SwiftBindings Swift bindings for .NET

Comments

@kotlarmilos
Copy link
Member

kotlarmilos commented Feb 24, 2025

Description

We need to implement AOT compatible C# async callback. Here is an example:

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static void GenericCollectionConstraintOnComplete(System.IntPtr rawResult, IntPtr task)
{
    GCHandle handle = GCHandle.FromIntPtr(task);
    try
    {

        var result = SwiftMarshal.MarshalFromSwift<System.IntPtr>((SwiftHandle)new IntPtr(&rawResult));
        if (handle.Target is TaskCompletionSource<System.IntPtr> tcs)
        {
            tcs.TrySetResult(result);
        }
    }
    finally
    {
        handle.Free();
    }
}

The rawResult parameter should be generic type, which is not allowed in UnmanagedCallersOnly methods.

@kotlarmilos kotlarmilos self-assigned this Feb 24, 2025
@kotlarmilos kotlarmilos added area-SwiftBindings Swift bindings for .NET User Story A single user-facing feature. Can be grouped under an epic. and removed User Story A single user-facing feature. Can be grouped under an epic. labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-SwiftBindings Swift bindings for .NET
Projects
None yet
Development

No branches or pull requests

1 participant