Commit 24ee1667 authored by Marius Wachtler's avatar Marius Wachtler

store and restore is_reraise flag

I did not trigger this bug (also could not come up with a test) but just by inspecting the code I thought it's very suspicious.

But I did remove the assert(!exc_state.is_reraise) assert because it got hit in a legitimate case,
(c++ exception got rethrowen in the llvm tier, cought in our c++ code and rethrowen because of api mismatch. With no python code in between.)
parent 88070844
......@@ -545,14 +545,17 @@ public:
stat.log();
}
std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor> pause() {
std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor, bool> pause() {
static StatCounter stat("us_unwind_session");
stat.log(t.end());
return std::make_tuple(std::move(prev_frame_info), std::move(exc_info), std::move(pystack_extractor));
bool is_reraise = getIsReraiseFlag();
getIsReraiseFlag() = false;
return std::make_tuple(std::move(prev_frame_info), std::move(exc_info), std::move(pystack_extractor),
is_reraise);
}
void resume(std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor>&& state) {
std::tie(prev_frame_info, exc_info, pystack_extractor) = state;
void resume(std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor, bool>&& state) {
std::tie(prev_frame_info, exc_info, pystack_extractor, getIsReraiseFlag()) = state;
t.restart();
}
......@@ -620,11 +623,12 @@ public:
// make sure that our libunwind based python frame handling and the manual one are the same.
assert(prev_frame_info == getTopFrameInfo());
if (exceptionAtLineCheck()) {
if (!getIsReraiseFlag()) {
// TODO: shouldn't fetch this multiple times?
frame_iter.getCurrentStatement()->cxx_exception_count++;
exceptionAtLine(&exc_info.traceback);
}
} else
getIsReraiseFlag() = false;
}
}
};
......
......@@ -59,8 +59,10 @@ void unwindingThroughFrame(PythonUnwindSession* unwind_session, unw_cursor_t* cu
// TODO move these to exceptions.h
void logException(ExcInfo* exc_info);
void startReraise();
bool exceptionAtLineCheck();
bool& getIsReraiseFlag();
inline void startReraise() {
getIsReraiseFlag() = true;
}
void exceptionAtLine(Box** traceback);
void caughtCxxException(ExcInfo* exc_info);
extern "C" void caughtCapiException();
......
......@@ -299,30 +299,20 @@ void caughtCxxException(ExcInfo* exc_info) {
exceptionAtLine(&exc_info->traceback);
}
struct ExcState {
bool is_reraise;
constexpr ExcState() : is_reraise(false) {}
} static __thread exc_state;
bool exceptionAtLineCheck() {
if (exc_state.is_reraise) {
exc_state.is_reraise = false;
return false;
}
return true;
bool& getIsReraiseFlag() {
return exc_state.is_reraise;
}
void exceptionAtLine(Box** traceback) {
if (exceptionAtLineCheck()) {
if (!getIsReraiseFlag())
PyTraceBack_Here_Tb((struct _frame*)getFrame((FrameInfo*)cur_thread_state.frame_info),
(PyTracebackObject**)traceback);
}
}
void startReraise() {
assert(!exc_state.is_reraise);
exc_state.is_reraise = true;
else
getIsReraiseFlag() = false;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment