Commit 6f9c6d68 authored by Chris Toshok's avatar Chris Toshok

stop using 'WHY' just to be similar to cpython. 'STATE' is better. also,...

stop using 'WHY' just to be similar to cpython.  'STATE' is better.  also, reduce duplicate code in unwindProcessFrame
parent 083ef4e1
......@@ -111,13 +111,13 @@ typedef struct _ts {
} PyThreadState;
#endif
// somewhat similar to CPython's WHY_* enum
// UNWIND_WHY_NORMAL : == WHY_EXCEPTION. we call it "NORMAL" since we often unwind due to things other than exceptions (getGlobals, getLocals, etc)
// UNWIND_WHY_RERAISE: same as NORMAL, except we are supposed to skip the first frame.
// UNWIND_WHY_OSR : The previous frame was an osr replacement for the next one, so we should skip it
enum {
UNWIND_WHY_NORMAL = 0,
UNWIND_WHY_RERAISE,
UNWIND_WHY_OSR
// UNWIND_STATE_NORMAL : == WHY_EXCEPTION. we call it "NORMAL" since we often unwind due to things other than exceptions (getGlobals, getLocals, etc)
// UNWIND_STATE_RERAISE: same as NORMAL, except we are supposed to skip the first frame.
// UNWIND_STATE_OSR : The previous frame was an osr replacement for the next one, so we should skip it
enum UnwindState {
UNWIND_STATE_NORMAL = 0,
UNWIND_STATE_RERAISE,
UNWIND_STATE_OSR
};
typedef struct _ts {
int recursion_depth;
......@@ -128,8 +128,8 @@ typedef struct _ts {
PyObject *dict; /* Stores per-thread state */
// one of the UNWIND_WHY_* above
int unwind_why;
// one of the UNWIND_STATE_* above
int unwind_state;
// Pyston note: additions in here need to be mirrored in ThreadStateInternal::accept
} PyThreadState;
......
......@@ -631,7 +631,7 @@ Value ASTInterpreter::visit_invoke(AST_Invoke* node) {
next_block = node->normal_dest;
} catch (ExcInfo e) {
if (cur_thread_state.unwind_why == UNWIND_WHY_NORMAL) {
if (cur_thread_state.unwind_state == UNWIND_STATE_NORMAL) {
// when generating the traceback incrementally we only
// include an interpreter frame if we unwind through
// ASTInterpreter::execute_inner. this will keep a toplevel
......@@ -643,7 +643,7 @@ Value ASTInterpreter::visit_invoke(AST_Invoke* node) {
reinterpret_cast<BoxedTraceback**>(&e.traceback));
}
cur_thread_state.unwind_why = UNWIND_WHY_NORMAL;
cur_thread_state.unwind_state = UNWIND_STATE_NORMAL;
next_block = node->exc_dest;
last_exception = e;
......
......@@ -444,9 +444,19 @@ static inline unw_word_t get_cursor_bp(unw_cursor_t* cursor) {
template <typename FrameFunc>
bool unwindProcessFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, FrameFunc func) {
CompiledFunction* cf = getCFForAddress(ip);
if (cf) {
PythonFrameIteratorImpl info(PythonFrameId::COMPILED, ip, bp, cf);
bool jitted = cf != NULL;
if (!cf) {
if (inASTInterpreterExecuteInner(ip)) {
cf = getCFForInterpretedFrame((void*)bp);
assert(cf);
}
}
if (!cf)
return false;
PythonFrameIteratorImpl info(jitted ? PythonFrameId::COMPILED : PythonFrameId::INTERPRETED, ip, bp, cf);
if (jitted) {
// Try getting all the callee-save registers, and save the ones we were able to get.
// Some of them may be inaccessible, I think because they weren't defined by that
// stack frame, which can show up as a -UNW_EBADREG return code.
......@@ -461,33 +471,15 @@ bool unwindProcessFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, Fram
info.regs_valid |= (1 << i);
}
}
if (cur_thread_state.unwind_why == UNWIND_WHY_NORMAL) {
bool stop = func(&info);
if (stop)
return true;
}
cur_thread_state.unwind_why = (bool)cf->entry_descriptor ? UNWIND_WHY_OSR : UNWIND_WHY_NORMAL;
return false;
}
if (inASTInterpreterExecuteInner(ip)) {
cf = getCFForInterpretedFrame((void*)bp);
assert(cf);
PythonFrameIteratorImpl info(PythonFrameId::INTERPRETED, ip, bp, cf);
if (cur_thread_state.unwind_why == UNWIND_WHY_NORMAL) {
if (cur_thread_state.unwind_state == UNWIND_STATE_NORMAL) {
bool stop = func(&info);
if (stop)
return true;
}
cur_thread_state.unwind_why = (bool)cf->entry_descriptor ? UNWIND_WHY_OSR : UNWIND_WHY_NORMAL;
return false;
}
cur_thread_state.unwind_state = (bool)cf->entry_descriptor ? UNWIND_STATE_OSR : UNWIND_STATE_NORMAL;
return false;
}
......@@ -496,7 +488,7 @@ bool unwindProcessFrame(unw_word_t ip, unw_word_t bp, unw_cursor_t* cursor, Fram
// C++11 range loops, for example).
// Return true from the handler to stop iteration at that frame.
template <typename Func> void unwindPythonStack(Func func) {
cur_thread_state.unwind_why = UNWIND_WHY_NORMAL; // ensure we won't be skipping any python frames at the start
cur_thread_state.unwind_state = UNWIND_STATE_NORMAL; // ensure we won't be skipping any python frames at the start
unw_context_t ctx;
unw_cursor_t cursor;
unw_getcontext(&ctx);
......
......@@ -37,8 +37,9 @@ namespace pyston {
namespace threading {
extern "C" {
__thread PyThreadState cur_thread_state
= { 0, NULL, NULL, NULL, NULL, UNWIND_WHY_NORMAL }; // not sure if we need to explicitly request zero-initialization
__thread PyThreadState cur_thread_state = {
0, NULL, NULL, NULL, NULL, UNWIND_STATE_NORMAL
}; // not sure if we need to explicitly request zero-initialization
}
PthreadFastMutex threading_lock;
......
......@@ -204,7 +204,7 @@ extern "C" void raise0() {
if (exc_info->type == None)
raiseExcHelper(TypeError, "exceptions must be old-style classes or derived from BaseException, not NoneType");
cur_thread_state.unwind_why = UNWIND_WHY_RERAISE;
cur_thread_state.unwind_state = UNWIND_STATE_RERAISE;
raiseRaw(*exc_info);
}
......@@ -283,7 +283,7 @@ ExcInfo excInfoForRaise(Box* type, Box* value, Box* tb) {
extern "C" void raise3(Box* arg0, Box* arg1, Box* arg2) {
bool reraise = arg2 != NULL && arg2 != None;
auto exc_info = excInfoForRaise(arg0, arg1, arg2);
cur_thread_state.unwind_why = reraise ? UNWIND_WHY_RERAISE : UNWIND_WHY_NORMAL;
cur_thread_state.unwind_state = reraise ? UNWIND_STATE_RERAISE : UNWIND_STATE_NORMAL;
raiseRaw(exc_info);
}
......
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