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: ...@@ -545,14 +545,17 @@ public:
stat.log(); stat.log();
} }
std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor> pause() { std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor, bool> pause() {
static StatCounter stat("us_unwind_session"); static StatCounter stat("us_unwind_session");
stat.log(t.end()); 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) { void resume(std::tuple<FrameInfo*, ExcInfo, PythonStackExtractor, bool>&& state) {
std::tie(prev_frame_info, exc_info, pystack_extractor) = state; std::tie(prev_frame_info, exc_info, pystack_extractor, getIsReraiseFlag()) = state;
t.restart(); t.restart();
} }
...@@ -620,11 +623,12 @@ public: ...@@ -620,11 +623,12 @@ public:
// make sure that our libunwind based python frame handling and the manual one are the same. // make sure that our libunwind based python frame handling and the manual one are the same.
assert(prev_frame_info == getTopFrameInfo()); assert(prev_frame_info == getTopFrameInfo());
if (exceptionAtLineCheck()) { if (!getIsReraiseFlag()) {
// TODO: shouldn't fetch this multiple times? // TODO: shouldn't fetch this multiple times?
frame_iter.getCurrentStatement()->cxx_exception_count++; frame_iter.getCurrentStatement()->cxx_exception_count++;
exceptionAtLine(&exc_info.traceback); exceptionAtLine(&exc_info.traceback);
} } else
getIsReraiseFlag() = false;
} }
} }
}; };
......
...@@ -59,8 +59,10 @@ void unwindingThroughFrame(PythonUnwindSession* unwind_session, unw_cursor_t* cu ...@@ -59,8 +59,10 @@ void unwindingThroughFrame(PythonUnwindSession* unwind_session, unw_cursor_t* cu
// TODO move these to exceptions.h // TODO move these to exceptions.h
void logException(ExcInfo* exc_info); void logException(ExcInfo* exc_info);
void startReraise(); bool& getIsReraiseFlag();
bool exceptionAtLineCheck(); inline void startReraise() {
getIsReraiseFlag() = true;
}
void exceptionAtLine(Box** traceback); void exceptionAtLine(Box** traceback);
void caughtCxxException(ExcInfo* exc_info); void caughtCxxException(ExcInfo* exc_info);
extern "C" void caughtCapiException(); extern "C" void caughtCapiException();
......
...@@ -299,30 +299,20 @@ void caughtCxxException(ExcInfo* exc_info) { ...@@ -299,30 +299,20 @@ void caughtCxxException(ExcInfo* exc_info) {
exceptionAtLine(&exc_info->traceback); exceptionAtLine(&exc_info->traceback);
} }
struct ExcState { struct ExcState {
bool is_reraise; bool is_reraise;
constexpr ExcState() : is_reraise(false) {} constexpr ExcState() : is_reraise(false) {}
} static __thread exc_state; } static __thread exc_state;
bool exceptionAtLineCheck() { bool& getIsReraiseFlag() {
if (exc_state.is_reraise) { return exc_state.is_reraise;
exc_state.is_reraise = false;
return false;
}
return true;
} }
void exceptionAtLine(Box** traceback) { void exceptionAtLine(Box** traceback) {
if (exceptionAtLineCheck()) { if (!getIsReraiseFlag())
PyTraceBack_Here_Tb((struct _frame*)getFrame((FrameInfo*)cur_thread_state.frame_info), PyTraceBack_Here_Tb((struct _frame*)getFrame((FrameInfo*)cur_thread_state.frame_info),
(PyTracebackObject**)traceback); (PyTracebackObject**)traceback);
} else
} getIsReraiseFlag() = false;
void startReraise() {
assert(!exc_state.is_reraise);
exc_state.is_reraise = true;
} }
} }
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