Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/core/IronPython/Runtime/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public sealed partial class PythonContext : LanguageContext {
internal readonly object _codeCleanupLock = new object();
internal readonly object _codeUpdateLock = new object();
internal int _codeCount, _nextCodeCleanup = 200;
private int _recursionLimit;
private int _recursionLimit = int.MaxValue; // not enforced until set from the options in the constructor

private readonly object _indexBindersLock = new object(); // https://github.com/IronLanguages/ironpython3/issues/1596

Expand Down Expand Up @@ -348,9 +348,10 @@ public int RecursionLimit {
}

lock (_codeUpdateLock) {
bool wasEnforced = _recursionLimit != int.MaxValue;
_recursionLimit = value;

if ((_recursionLimit == int.MaxValue) != (value == int.MaxValue)) {
if (wasEnforced != (value != int.MaxValue)) {
// recursion setting has changed, we need to update all of our
// function codes to enforce or un-enforce recursion.
FunctionCode.UpdateAllCode(this);
Expand Down
18 changes: 18 additions & 0 deletions tests/suite/modules/system_related/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,22 @@ def test_builtin_module_names(self):
See issue https://github.com/IronLanguages/ironpython3/issues/875 for full details '''
self.assertTrue(sys.builtin_module_names == tuple(sorted(sys.builtin_module_names)))

def test_setrecursionlimit_existing_function(self):
# Setting a recursion limit is enforced also for functions that were already called before
# (in a new process, where IronPython enforces no limit by default)
import subprocess
code = """import sys
def f(n):
return f(n - 1) if n else 0
f(10)
sys.setrecursionlimit(50)
try:
f(100)
print(False)
except RecursionError:
print(True)
"""
out = subprocess.check_output([sys.executable, '-c', code])
self.assertEqual(out.strip(), b'True')

run_test(__name__)
Loading