Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove one usage of Unsafe.AsPointer. #112079

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Preview

Copilot AI Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the usage of 'ref' with 'StackCrawlMark' is correct and doesn't introduce any unintended side effects. Verify that all usages of '_stackMark' are correctly updated.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

[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
Loading