Skip to content

Commit 37f7e1d

Browse files
Merge pull request #293 from tannergooding/main
Ensure that top level classes/structs correctly mark themselves as unsafe and include the right namespace for tests
2 parents 0f2b740 + 86431b4 commit 37f7e1d

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,11 @@ private void VisitRecordDecl(RecordDecl recordDecl)
13001300
{
13011301
_topLevelClassUsings[name] = withUsings;
13021302
}
1303+
1304+
if (desc.IsUnsafe)
1305+
{
1306+
_isTopLevelClassUnsafe[name] = true;
1307+
}
13031308
}
13041309

13051310
if (hasVtbl)

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4991,7 +4991,9 @@ void CreateTestOutputBuilder(string name)
49914991
{
49924992
_testOutputBuilder = _outputBuilderFactory.CreateTests(name);
49934993

4994-
if (!_topLevelClassNames.Contains(name))
4994+
var isTopLevelStruct = _config.WithTypes.TryGetValue(name, out var withType) && (withType == "struct");
4995+
4996+
if (!_topLevelClassNames.Contains(name) || isTopLevelStruct)
49954997
{
49964998
_testOutputBuilder.AddUsingDirective("System.Runtime.InteropServices");
49974999
}

0 commit comments

Comments
 (0)