Skip to content

Commit

Permalink
Remove one usage of Unsafe.AsPointer. (dotnet#112079)
Browse files Browse the repository at this point in the history
  • Loading branch information
teo-tsirpanis committed Feb 6, 2025
1 parent c023336 commit 23b23c9
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal unsafe ref partial struct TypeNameResolver
private Func<Assembly?, string, bool, Type?>? _typeResolver;
private bool _throwOnError;
private bool _ignoreCase;
private void* _stackMark;
private ref StackCrawlMark _stackMark;

[RequiresUnreferencedCode("The type might be removed")]
internal static Type? GetType(
Expand Down Expand Up @@ -52,7 +52,7 @@ internal unsafe ref partial struct TypeNameResolver
_typeResolver = typeResolver,
_throwOnError = throwOnError,
_ignoreCase = ignoreCase,
_stackMark = Unsafe.AsPointer(ref stackMark)
_stackMark = ref stackMark
}.Resolve(parsed);
}

Expand All @@ -69,19 +69,17 @@ internal unsafe ref partial struct TypeNameResolver
}
else
{
ref StackCrawlMark stackMark = ref Unsafe.AsRef<StackCrawlMark>(_stackMark);

if (_throwOnError)
{
assembly = Assembly.Load(name, ref stackMark, null);
assembly = Assembly.Load(name, ref _stackMark, null);
}
else
{
// When throwOnError is false we should only catch FileNotFoundException.
// Other exceptions like BadImangeFormatException should still fly.
try
{
assembly = Assembly.Load(name, ref stackMark, null);
assembly = Assembly.Load(name, ref _stackMark, null);
}
catch (FileNotFoundException)
{
Expand Down Expand Up @@ -123,9 +121,7 @@ internal unsafe ref partial struct TypeNameResolver
{
if (assembly is null)
{
ref StackCrawlMark stackMark = ref Unsafe.AsRef<StackCrawlMark>(_stackMark);

type = RuntimeType.GetType(escapedTypeName, _throwOnError, _ignoreCase, ref stackMark);
type = RuntimeType.GetType(escapedTypeName, _throwOnError, _ignoreCase, ref _stackMark);
}
else
{
Expand Down

0 comments on commit 23b23c9

Please # to comment.