Skip to content

Conversation

@grendello
Copy link
Contributor

System.Char is an unblittable type and, as such, it has to be treated
specially by the marshal methods wrapper generator to properly cast it
to/from a matching blittable type. In this case the latter is ushort,
since both on the Java and Managed side, char is a 16-bit entity.

`System.Char` is an unblittable type and, as such, it has to be treated
specially by the marshal methods wrapper generator to properly cast it
to/from a matching blittable type.  In this case the latter is `ushort`,
since both on the Java and Managed side, `char` is a 16-bit entity.
@grendello grendello requested a review from jonpryor June 27, 2023 09:40
@jonpryor
Copy link
Contributor

Why is char not blittable? Documentation lists it as "sometimes" blittable (which itself is worrying, to be fair): https://learn.microsoft.com/en-us/dotnet/standard/native-interop/best-practices#blittable-types-when-runtime-marshalling-is-enabled

Then there's the following section Blittable types when runtime marshalling is disabled:

char is always passed as a 2-byte value

which implies to me that char is supported as a blittable type, and (when runtime marshaling is disabled) is marshaled as a 16-bit construct, which is perfect as that matches Java's char type.

@grendello
Copy link
Contributor Author

@jonpryor
Copy link
Contributor

jonpryor commented Jul 5, 2023

@grendello: based on the URL scheme and the "banner" at the top of the link, I believe that the docs you referred to are for .NET Framework, not .NET. As such, I do not believe that this special-casing of char is required.

@grendello
Copy link
Contributor Author

grendello commented Jul 6, 2023

@jonpryor it doesn't change for .NET https://learn.microsoft.com/en-us/dotnet/standard/native-interop/best-practices#blittable-types-when-runtime-marshalling-is-enabled, and also the docs in the previous link refer to the .NET Framework docs, so they're still valid I think.

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.

2 participants