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

[generator] Add [UnmanagedFunctionPointer] to marshal delegate declarations. #1281

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Dec 3, 2024

Fixes: #1262
Context: 2197579

NativeAOT doesn't like this by default. In order to convince
NativeAOT to support this, every delegate instance provided to
JniNativeMethodRegistration.Delegate must be of a delegate type
which has UnmanagedFunctionPointerAttribute. This coerces
NativeAOT to emit "stubs" for the referenced method, allowing things
to work with fewer changes.

For possible future NativeAOT support, every _JniMarshal_* delegate emitted by generator needs to have [UnmanagedFunctionPointer], a'la:

[UnmanagedFunctionPointer (CallingConvention.Winapi)]
delegate long _JniMarshal_PP_L (IntPtr env, IntPtr klass, long value);

@jpobst jpobst marked this pull request as ready for review December 3, 2024 22:25
@jpobst jpobst requested a review from jonpryor December 3, 2024 22:26
@vitek-karas
Copy link
Member

From the docs:

These fields are optional, but if you do not specify a field name, UnmanagedFunctionPointerAttribute is ignored.

This worries me - maybe the docs are wrong?
@AaronRobinsonMSFT would you know?

@AaronRobinsonMSFT
Copy link
Member

This worries me - maybe the docs are wrong?

That is definitely not true. The calling convention is kept and respected. I think the doc needs to be updated.

@jonpryor jonpryor merged commit 619286d into main Dec 5, 2024
4 checks passed
@jonpryor jonpryor deleted the unmanaged-function-pointer branch December 5, 2024 19:56
jonpryor pushed a commit to dotnet/android that referenced this pull request Dec 7, 2024
Fixes: dotnet/java-interop#1262

Changes: dotnet/java-interop@2d48efe...619286d

  * dotnet/java-interop@619286d5: [generator] Add `[UnmanagedFunctionPointer]` to `_JniMarshal*` decls (dotnet/java-interop#1281)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UnmanagedFunctionPointer] on delegates
4 participants