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] Avoid non-blittable types in native callback methods #1296

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jan 29, 2025

Fixes: #1027

To make marshaling callbacks from Java easier we should avoid non-blittable types in native callback methods. This means we should marshal bool as sbyte and char as ushort.

generator has built in support for conversions when the native type does not match the managed type. (ISymbol.[To|From]Native). However this affects marshaling both ways: managed to Java and Java to managed. We do not want to affect managed to Java marshaling, so we introduce a new ISymbol.OnlyFormatOnMarshal property to control this.

This also requires some changes in dotnet\android via this PR: dotnet/android#9724.

@jpobst jpobst force-pushed the dev/jpobst/blittable branch from 099c5a8 to db62a97 Compare January 29, 2025 21:35
@jonpryor
Copy link
Member

jonpryor commented Feb 3, 2025

Looks like char will need to be replaced with uint16 as well; see e.g. https://github.com/dotnet/runtime/blob/3ab8574307f12f4afbb813fbe708734334f87914/docs/design/libraries/LibraryImportGenerator/Compatibility.md#char-marshalling

[char marshaling] will not be supported when configured with any of the following:

  • No explicit marshalling information…

@jpobst jpobst force-pushed the dev/jpobst/blittable branch from ae914d7 to be273b5 Compare February 6, 2025 22:50
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.

Avoid non-blittable types in native callback methods
2 participants