Skip to content

Commit

Permalink
fix(ops): set recursion limit to 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Mar 25, 2024
1 parent 05f3825 commit 45ada8c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Set recursion limit to 1000 for all platforms by [@XuehaiPan](https://github.com/XuehaiPan) in [#121](https://github.com/metaopt/optree/pull/121).
- Allow types to be registered in both the global namespace and custom namespaces by [@XuehaiPan](https://github.com/XuehaiPan) in [#124](https://github.com/metaopt/optree/pull/124).
- Set `treespec_is_leaf` as strict by default by [@XuehaiPan](https://github.com/XuehaiPan) in [#120](https://github.com/metaopt/optree/pull/120).
- Reorder functions for better code correspondence between C++ and Python by [@XuehaiPan](https://github.com/XuehaiPan) in [#117](https://github.com/metaopt/optree/pull/117).
Expand Down
2 changes: 1 addition & 1 deletion include/treespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using size_t = py::size_t;
using ssize_t = py::ssize_t;

// The maximum depth of a pytree.
constexpr ssize_t MAX_RECURSION_DEPTH = 2000;
constexpr ssize_t MAX_RECURSION_DEPTH = 1000;

// Test whether the given object is a leaf node.
bool IsLeaf(const py::object &object,
Expand Down
4 changes: 2 additions & 2 deletions optree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@
'structseq_fields',
]

MAX_RECURSION_DEPTH: int = MAX_RECURSION_DEPTH # 2000
"""Maximum recursion depth for pytree traversal. It is 2000.
MAX_RECURSION_DEPTH: int = MAX_RECURSION_DEPTH # 1000
"""Maximum recursion depth for pytree traversal. It is 1000.
This limit prevents infinite recursion from causing an overflow of the C stack
and crashing Python.
Expand Down
4 changes: 2 additions & 2 deletions optree/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
'prefix_errors',
]

MAX_RECURSION_DEPTH: int = _C.MAX_RECURSION_DEPTH # 2000
"""Maximum recursion depth for pytree traversal. It is 2000.
MAX_RECURSION_DEPTH: int = _C.MAX_RECURSION_DEPTH # 1000
"""Maximum recursion depth for pytree traversal. It is 1000.
This limit prevents infinite recursion from causing an overflow of the C stack
and crashing Python.
Expand Down

0 comments on commit 45ada8c

Please sign in to comment.