Skip to content

Commit 70244f3

Browse files
committed
upper bound kMaxFrames
1 parent 21d68e6 commit 70244f3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

mlir/lib/Bindings/Python/Globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class PyGlobals {
134134

135135
bool isUserTracebackFilename(llvm::StringRef file);
136136

137+
static constexpr size_t kMaxFrames = 512;
138+
137139
private:
138140
nanobind::ft_mutex mutex;
139141
bool locTracebackEnabled_ = false;

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,18 +2786,16 @@ class PyOpAttributeMap {
27862786
PyOperationRef operation;
27872787
};
27882788

2789-
constexpr size_t kMaxFrames = 512;
2790-
27912789
MlirLocation tracebackToLocation(MlirContext ctx) {
27922790
size_t framesLimit =
27932791
PyGlobals::get().getTracebackLoc().locTracebackFramesLimit();
27942792
// Use a thread_local here to avoid requiring a large amount of space.
2795-
thread_local std::array<MlirLocation, kMaxFrames> frames;
2793+
thread_local std::array<MlirLocation, PyGlobals::TracebackLoc::kMaxFrames>
2794+
frames;
27962795
size_t count = 0;
27972796

27982797
nb::gil_scoped_acquire acquire;
27992798
PyThreadState *tstate = PyThreadState_GET();
2800-
28012799
PyFrameObject *next;
28022800
PyFrameObject *pyFrame = PyThreadState_GetFrame(tstate);
28032801
for (; pyFrame != nullptr && count < framesLimit;

mlir/lib/Bindings/Python/IRModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ size_t PyGlobals::TracebackLoc::locTracebackFramesLimit() {
215215

216216
void PyGlobals::TracebackLoc::setLocTracebackFramesLimit(size_t value) {
217217
nanobind::ft_lock_guard lock(mutex);
218-
locTracebackFramesLimit_ = value;
218+
locTracebackFramesLimit_ = std::min(value, kMaxFrames);
219219
}
220220

221221
void PyGlobals::TracebackLoc::registerTracebackFileInclusion(

0 commit comments

Comments
 (0)