Skip to content

Commit

Permalink
Improve stack overflow prevention (fixes #321)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed May 7, 2024
1 parent 1ad44b1 commit 5c26872
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,20 @@ bool __CanCastByVarianceToInterfaceOrDelegate(DmdType target) {
return false;

// The original code used a list to check for infinite recursion, we'll use this code unless it throws too often
try {
// For an unknown to me reason, in .NET 8, the RuntimeHelpers.EnsureSufficientExecutionStack() method does not work.
#if NETCOREAPP
if (RuntimeHelpers.TryEnsureSufficientExecutionStack())
throw new InsufficientExecutionStackException();
if (!RuntimeHelpers.TryEnsureSufficientExecutionStack()) {
Debug.Fail("Should probably not happen often");
return false;
}
#else
try {
RuntimeHelpers.EnsureSufficientExecutionStack();
#endif
}
catch (InsufficientExecutionStackException) {
Debug.Fail("Should probably not happen often");
return false;
}
#endif

var inst = GetGenericArguments();
if (inst.Count > 0) {
Expand Down

0 comments on commit 5c26872

Please sign in to comment.