From 0684503a0aa37b9e98549e94209eba3557e693f0 Mon Sep 17 00:00:00 2001 From: ghord Date: Mon, 29 Dec 2025 23:11:16 +0100 Subject: [PATCH] Added special handling of bool to byte remapping in indirect fields. Fixes #658. --- .../PInvokeGenerator.VisitDecl.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 88992629..bd29843b 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -923,6 +923,19 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) var accessSpecifier = GetAccessSpecifier(anonymousRecordDecl, matchStar: true); var typeName = GetRemappedTypeName(fieldDecl, context: null, type, out _); + + if (!_config.GenerateDisableRuntimeMarshalling && typeName.Equals("bool", StringComparison.Ordinal)) + { + // bool is not blittable when DisableRuntimeMarshalling is not specified, so we shouldn't use it for structs that may be in P/Invoke signatures + typeName = "byte"; + } + + if (_config.GenerateCompatibleCode && typeName.StartsWith("bool*", StringComparison.Ordinal)) + { + // bool* is not blittable in compat mode, so we shouldn't use it for structs that may be in P/Invoke signatures + typeName = typeName.Replace("bool*", "byte*", StringComparison.Ordinal); + } + var name = GetRemappedCursorName(fieldDecl); var escapedName = EscapeName(name);