Skip to content

Commit

Permalink
Emit ExactSpelling = true for all of our emitted target DllImports.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Feb 15, 2022
1 parent 68fb49b commit a3f9c67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ private static GeneratedDllImportData ProcessGeneratedDllImportAttribute(Attribu
DllImportMember userDefinedValues = DllImportMember.None;
CharSet charSet = CharSet.Ansi;
string? entryPoint = null;
bool exactSpelling = false; // VB has different and unusual default behavior here.
bool setLastError = false;

// All other data on attribute is defined as NamedArguments.
Expand All @@ -366,10 +365,6 @@ private static GeneratedDllImportData ProcessGeneratedDllImportAttribute(Attribu
userDefinedValues |= DllImportMember.EntryPoint;
entryPoint = (string)namedArg.Value.Value!;
break;
case nameof(GeneratedDllImportData.ExactSpelling):
userDefinedValues |= DllImportMember.ExactSpelling;
exactSpelling = (bool)namedArg.Value.Value!;
break;
case nameof(GeneratedDllImportData.SetLastError):
userDefinedValues |= DllImportMember.SetLastError;
setLastError = (bool)namedArg.Value.Value!;
Expand All @@ -382,7 +377,6 @@ private static GeneratedDllImportData ProcessGeneratedDllImportAttribute(Attribu
IsUserDefined = userDefinedValues,
CharSet = charSet,
EntryPoint = entryPoint,
ExactSpelling = exactSpelling,
SetLastError = setLastError,
};
}
Expand Down Expand Up @@ -560,7 +554,11 @@ private static AttributeSyntax CreateDllImportAttributeForTarget(GeneratedDllImp
AttributeArgument(
NameEquals(nameof(DllImportAttribute.EntryPoint)),
null,
CreateStringExpressionSyntax(targetDllImportData.EntryPoint!))
CreateStringExpressionSyntax(targetDllImportData.EntryPoint!)),
AttributeArgument(
NameEquals(nameof(DllImportAttribute.ExactSpelling)),
null,
CreateBoolExpressionSyntax(true))
};

if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.CharSet))
Expand All @@ -569,12 +567,6 @@ private static AttributeSyntax CreateDllImportAttributeForTarget(GeneratedDllImp
ExpressionSyntax value = CreateEnumExpressionSyntax(targetDllImportData.CharSet);
newAttributeArgs.Add(AttributeArgument(name, null, value));
}
if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.ExactSpelling))
{
NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.ExactSpelling));
ExpressionSyntax value = CreateBoolExpressionSyntax(targetDllImportData.ExactSpelling);
newAttributeArgs.Add(AttributeArgument(name, null, value));
}
if (targetDllImportData.IsUserDefined.HasFlag(DllImportMember.SetLastError))
{
NameEqualsSyntax name = NameEquals(nameof(DllImportAttribute.SetLastError));
Expand Down Expand Up @@ -626,7 +618,6 @@ private static GeneratedDllImportData GetTargetDllImportDataFromStubData(Generat
{
CharSet = dllImportData.CharSet,
EntryPoint = dllImportData.EntryPoint,
ExactSpelling = dllImportData.ExactSpelling,
SetLastError = dllImportData.SetLastError,
IsUserDefined = dllImportData.IsUserDefined & membersToForward
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public enum DllImportMember
None = 0,
CharSet = 1 << 0,
EntryPoint = 1 << 1,
ExactSpelling = 1 << 2,
SetLastError = 1 << 3,
SetLastError = 1 << 2,
All = ~None
}

Expand All @@ -37,7 +36,6 @@ public sealed record GeneratedDllImportData(string ModuleName)
public DllImportMember IsUserDefined { get; init; }
public CharSet CharSet { get; init; }
public string? EntryPoint { get; init; }
public bool ExactSpelling { get; init; }
public bool SetLastError { get; init; }
}
}

0 comments on commit a3f9c67

Please sign in to comment.