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

Pin stage only accepts FixedStatementSyntaxes #1653

Closed
Tracked by #60595
SupinePandora43 opened this issue Oct 14, 2021 · 2 comments · Fixed by dotnet/runtime#61539
Closed
Tracked by #60595

Pin stage only accepts FixedStatementSyntaxes #1653

SupinePandora43 opened this issue Oct 14, 2021 · 2 comments · Fixed by dotnet/runtime#61539
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#

Comments

@SupinePandora43
Copy link

Generally, we only pin for cases where we directly pass down the value. That’s why the Pin stage only accepts FixedStatementSyntaxes
I’d honestly recommend keeping the heap allocation or at most adding a stackalloc optimization with the native marshalling APIs
If that’s not high enough perf, then you’d have to file an issue or fork the generator

By @jkoritzinsky in private discord messages.

i'm thinking about implementing IMarshallingGenerator that will output:

    private static void ulConfigSetCachePath(IntPtr config, in string cache_path)
        {
            unsafe
            {
                global::UltralightNet.ULString __cache_path_gen = default;
                global::UltralightNet.ULString* __cache_path_gen_native = default;
                //
                // Pin
                //
                fixed(char* __cache_path_gen_native_pinned = cache_path)
                {
                    __cache_path_gen = new ULString() { data = (ushort*)__cache_path_gen_native_pinned, length = (nuint)cache_path.Length };
                    __cache_path_gen_native = &__cache_path_gen;
                    //
                    // Invoke
                    //
                    ulConfigSetCachePath__PInvoke__(config, __cache_path_gen_native);
                }
            }
        }
     [System.Runtime.InteropServices.DllImportAttribute("Ultralight", EntryPoint = "ulConfigSetCachePath")]
        extern private static unsafe void ulConfigSetCachePath__PInvoke__(global::System.IntPtr config, global::UltralightNet.ULString* cache_path);

So it isn't possible yet?

@jkoritzinsky
Copy link
Member

cc: @AaronRobinsonMSFT this is the community request for the “pin as a side effect” issue we talked about yesterday.

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Oct 14, 2021

@jkoritzinsky Thanks. The only feedback I think I'd offer is whatever is pinned is required to be used as an input somewhere. The example we were discussing had the pinning as an implicit side-effect as opposed to being used in a subsequent call – like the above example.

/cc @elinor-fung

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants