Skip to content

Commit

Permalink
Upgrade metadata to 31.0.4-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Sep 1, 2022
1 parent 9fbfc99 commit 3f57350
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<IncludeSymbols Condition=" '$(DebugType)' != 'embedded' ">true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<MetadataVersion>29.0.6-preview</MetadataVersion>
<MetadataVersion>31.0.4-preview</MetadataVersion>
<!-- <DiaMetadataVersion>0.2.185-preview-g7e1e6a442c</DiaMetadataVersion> -->
<ApiDocsVersion>0.1.7-alpha</ApiDocsVersion>
</PropertyGroup>
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ internal void RequestConstant(FieldDefinitionHandle fieldDefHandle)
}
}

internal bool TryGetTypeDefFieldType(TypeHandleInfo typeDef, [NotNullWhen(true)] out TypeHandleInfo? fieldType)
internal bool TryGetTypeDefFieldType(TypeHandleInfo? typeDef, [NotNullWhen(true)] out TypeHandleInfo? fieldType)
{
if (typeDef is HandleTypeHandleInfo handle)
{
Expand Down Expand Up @@ -3816,6 +3816,11 @@ private bool IsHandle(TypeDefinitionHandle typeDefHandle, out string? releaseMet
|| this.Reader.StringComparer.Equals(typeDef.Name, "HWND");
}

private bool IsSafeHandleCompatibleTypeDef(TypeHandleInfo? typeDef)
{
return this.TryGetTypeDefFieldType(typeDef, out TypeHandleInfo? fieldType) && this.IsSafeHandleCompatibleTypeDefFieldType(fieldType);
}

private bool IsSafeHandleCompatibleTypeDefFieldType(TypeHandleInfo? fieldType)
{
return fieldType is PointerTypeHandleInfo
Expand Down Expand Up @@ -4382,7 +4387,8 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
Argument(LiteralExpression(doNotRelease ? SyntaxKind.FalseLiteralExpression : SyntaxKind.TrueLiteralExpression)).WithNameColon(NameColon(IdentifierName("ownsHandle")))))));
}
}
else if (this.options.UseSafeHandles && isIn && !isOut && !isReleaseMethod && parameterTypeInfo is HandleTypeHandleInfo parameterHandleTypeInfo && this.TryGetHandleReleaseMethod(parameterHandleTypeInfo.Handle, out string? releaseMethod) && !this.Reader.StringComparer.Equals(methodDefinition.Name, releaseMethod))
else if (this.options.UseSafeHandles && isIn && !isOut && !isReleaseMethod && parameterTypeInfo is HandleTypeHandleInfo parameterHandleTypeInfo && this.TryGetHandleReleaseMethod(parameterHandleTypeInfo.Handle, out string? releaseMethod) && !this.Reader.StringComparer.Equals(methodDefinition.Name, releaseMethod)
&& !(this.TryGetTypeDefFieldType(parameterHandleTypeInfo, out TypeHandleInfo? fieldType) && !this.IsSafeHandleCompatibleTypeDefFieldType(fieldType)))
{
IdentifierNameSyntax typeDefHandleName = IdentifierName(externParam.Identifier.ValueText + "Local");
signatureChanged = true;
Expand Down
1 change: 1 addition & 0 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void InterestingAPIs(
"CIDLData_CreateFromIDArray", // Method with out parameter of a possibly marshaled interop type shared with the BCL,
"ID3D12Resource", // COM interface with base types
"OpenTrace", // the CloseTrace method called by the SafeHandle returns WIN32_ERROR. The handle is ALWAYS 64-bits.
"QueryTraceProcessingHandle", // uses a handle that is always 64-bits, even in 32-bit processes
"ID2D1RectangleGeometry")] // COM interface with base types
string api,
bool allowMarshaling)
Expand Down

0 comments on commit 3f57350

Please sign in to comment.