Skip to content

[marshal methods] Add support for wrapping the char type#8146

Closed
grendello wants to merge 1 commit intodotnet:mainfrom
grendello:marshal-methods-support-char
Closed

[marshal methods] Add support for wrapping the char type#8146
grendello wants to merge 1 commit intodotnet:mainfrom
grendello:marshal-methods-support-char

Conversation

@grendello
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@jonpryor
Copy link
Copy Markdown
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
Copy Markdown
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.

@grendello grendello closed this Feb 6, 2026
@grendello grendello deleted the marshal-methods-support-char branch February 6, 2026 08:44
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants