|
44 | 44 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ImportError;
|
45 | 45 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RuntimeError;
|
46 | 46 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.RuntimeWarning;
|
| 47 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemExit; |
47 | 48 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
|
48 | 49 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.UnicodeEncodeError;
|
49 | 50 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
|
|
68 | 69 | import static com.oracle.graal.python.nodes.BuiltinNames.BUILTINS;
|
69 | 70 | import static com.oracle.graal.python.nodes.BuiltinNames.DISPLAYHOOK;
|
70 | 71 | import static com.oracle.graal.python.nodes.BuiltinNames.EXCEPTHOOK;
|
| 72 | +import static com.oracle.graal.python.nodes.BuiltinNames.EXIT; |
71 | 73 | import static com.oracle.graal.python.nodes.BuiltinNames.PYTHONBREAKPOINT;
|
72 | 74 | import static com.oracle.graal.python.nodes.BuiltinNames.STDERR;
|
73 | 75 | import static com.oracle.graal.python.nodes.BuiltinNames.STDIN;
|
|
82 | 84 | import static com.oracle.graal.python.nodes.BuiltinNames.__UNRAISABLEHOOK__;
|
83 | 85 | import static com.oracle.graal.python.nodes.ErrorMessages.ARG_TYPE_MUST_BE;
|
84 | 86 | import static com.oracle.graal.python.nodes.ErrorMessages.LOST_S;
|
| 87 | +import static com.oracle.graal.python.nodes.ErrorMessages.REC_LIMIT_GREATER_THAN_1; |
| 88 | +import static com.oracle.graal.python.nodes.ErrorMessages.S_EXPECTED_GOT_P; |
85 | 89 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_CANNOT_RUN_PDB_YET;
|
86 | 90 | import static com.oracle.graal.python.nodes.ErrorMessages.WARN_IGNORE_UNIMPORTABLE_BREAKPOINT_S;
|
87 | 91 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__;
|
|
99 | 103 | import java.util.Map;
|
100 | 104 | import java.util.Set;
|
101 | 105 |
|
| 106 | +import com.oracle.graal.python.lib.PyFloatCheckExactNode; |
| 107 | +import com.oracle.graal.python.lib.PyLongAsIntNode; |
| 108 | +import com.oracle.graal.python.runtime.exception.PythonExitException; |
102 | 109 | import org.graalvm.nativeimage.ImageInfo;
|
103 | 110 |
|
104 | 111 | import com.oracle.graal.python.PythonLanguage;
|
@@ -1386,4 +1393,53 @@ Object doHook(VirtualFrame frame, Object[] args, PKeyword[] keywords,
|
1386 | 1393 | return callNode.execute(hook, args, keywords);
|
1387 | 1394 | }
|
1388 | 1395 | }
|
| 1396 | + |
| 1397 | + @Builtin(name = "getrecursionlimit", minNumOfPositionalArgs = 1, declaresExplicitSelf = true, doc = "getrecursionlimit($module, /)\n" + |
| 1398 | + "--\n" + |
| 1399 | + "\n" + |
| 1400 | + "Return the current value of the recursion limit.\n" + |
| 1401 | + "\n" + |
| 1402 | + "The recursion limit is the maximum depth of the Python interpreter\n" + |
| 1403 | + "stack. This limit prevents infinite recursion from causing an overflow\n" + |
| 1404 | + "of the C stack and crashing Python.") |
| 1405 | + @GenerateNodeFactory |
| 1406 | + abstract static class GetRecursionLimitNode extends PythonBuiltinNode { |
| 1407 | + @Specialization |
| 1408 | + Object getRecLim(@SuppressWarnings("unused") PythonModule sys) { |
| 1409 | + return getContext().getSysModuleState().getRecursionLimit(); |
| 1410 | + } |
| 1411 | + } |
| 1412 | + |
| 1413 | + @Builtin(name = "setrecursionlimit", minNumOfPositionalArgs = 2, declaresExplicitSelf = true, doc = "setrecursionlimit($module, limit, /)\n" + |
| 1414 | + "--\n" + |
| 1415 | + "\n" + |
| 1416 | + "Set the maximum depth of the Python interpreter stack to n.\n" + |
| 1417 | + "\n" + |
| 1418 | + "This limit prevents infinite recursion from causing an overflow of the C\n" + |
| 1419 | + "stack and crashing Python. The highest possible limit is platform-\n" + |
| 1420 | + "dependent.") |
| 1421 | + @GenerateNodeFactory |
| 1422 | + abstract static class SetRecursionLimitNode extends PythonBuiltinNode { |
| 1423 | + @Specialization |
| 1424 | + Object setRecLim(VirtualFrame frame, @SuppressWarnings("unused") PythonModule sys, Object limit, |
| 1425 | + @Cached PyLongAsIntNode longAsIntNode, |
| 1426 | + @Cached PyFloatCheckExactNode floatCheckExactNode) { |
| 1427 | + if (floatCheckExactNode.execute(limit)) { |
| 1428 | + throw raise(TypeError, S_EXPECTED_GOT_P, "integer", limit); |
| 1429 | + } |
| 1430 | + |
| 1431 | + try { |
| 1432 | + final int newLimit = longAsIntNode.execute(frame, limit); |
| 1433 | + if (newLimit < 1) { |
| 1434 | + throw raise(ValueError, REC_LIMIT_GREATER_THAN_1); |
| 1435 | + } |
| 1436 | + |
| 1437 | + // TODO: check to see if Issue #25274 applies |
| 1438 | + getContext().getSysModuleState().setRecursionLimit(newLimit); |
| 1439 | + } catch (PException ignore) { |
| 1440 | + } |
| 1441 | + return PNone.NONE; |
| 1442 | + } |
| 1443 | + } |
| 1444 | + |
1389 | 1445 | }
|
0 commit comments