Skip to content

Commit

Permalink
Merge pull request #293 from tannergooding/main
Browse files Browse the repository at this point in the history
Ensure that top level classes/structs correctly mark themselves as unsafe and include the right namespace for tests
  • Loading branch information
tannergooding authored Nov 15, 2021
2 parents 0f2b740 + 86431b4 commit 37f7e1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,11 @@ private void VisitRecordDecl(RecordDecl recordDecl)
{
_topLevelClassUsings[name] = withUsings;
}

if (desc.IsUnsafe)
{
_isTopLevelClassUnsafe[name] = true;
}
}

if (hasVtbl)
Expand Down
4 changes: 3 additions & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4991,7 +4991,9 @@ void CreateTestOutputBuilder(string name)
{
_testOutputBuilder = _outputBuilderFactory.CreateTests(name);

if (!_topLevelClassNames.Contains(name))
var isTopLevelStruct = _config.WithTypes.TryGetValue(name, out var withType) && (withType == "struct");

if (!_topLevelClassNames.Contains(name) || isTopLevelStruct)
{
_testOutputBuilder.AddUsingDirective("System.Runtime.InteropServices");
}
Expand Down

0 comments on commit 37f7e1d

Please sign in to comment.