Commit 13800032 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add sys.exc_info()

parent da7b2d7f
...@@ -32,7 +32,7 @@ namespace threading { ...@@ -32,7 +32,7 @@ namespace threading {
bool threadWasStarted(); bool threadWasStarted();
struct ThreadState { struct ThreadState {
Box* curexc_type, *curexc_value, *curexc_traceback; Box* exc_type, *exc_value, *exc_traceback;
}; };
extern __thread ThreadState cur_thread_state; extern __thread ThreadState cur_thread_state;
......
...@@ -55,12 +55,12 @@ void collectOtherThreadsStacks(TraceStack* stack) { ...@@ -55,12 +55,12 @@ void collectOtherThreadsStacks(TraceStack* stack) {
collectRoots(tstate.stack_start, tstate.stack_end, stack); collectRoots(tstate.stack_start, tstate.stack_end, stack);
collectRoots(tstate.ucontext, tstate.ucontext + 1, stack); collectRoots(tstate.ucontext, tstate.ucontext + 1, stack);
if (tstate.thread_state->curexc_type) if (tstate.thread_state->exc_type)
v.visit(tstate.thread_state->curexc_type); v.visit(tstate.thread_state->exc_type);
if (tstate.thread_state->curexc_value) if (tstate.thread_state->exc_value)
v.visit(tstate.thread_state->curexc_value); v.visit(tstate.thread_state->exc_value);
if (tstate.thread_state->curexc_traceback) if (tstate.thread_state->exc_traceback)
v.visit(tstate.thread_state->curexc_traceback); v.visit(tstate.thread_state->exc_traceback);
} }
} }
...@@ -86,12 +86,12 @@ static void collectLocalStack(TraceStack* stack) { ...@@ -86,12 +86,12 @@ static void collectLocalStack(TraceStack* stack) {
#endif #endif
GCVisitor v(stack); GCVisitor v(stack);
if (threading::cur_thread_state.curexc_type) if (threading::cur_thread_state.exc_type)
v.visit(threading::cur_thread_state.curexc_type); v.visit(threading::cur_thread_state.exc_type);
if (threading::cur_thread_state.curexc_value) if (threading::cur_thread_state.exc_value)
v.visit(threading::cur_thread_state.curexc_value); v.visit(threading::cur_thread_state.exc_value);
if (threading::cur_thread_state.curexc_traceback) if (threading::cur_thread_state.exc_traceback)
v.visit(threading::cur_thread_state.curexc_traceback); v.visit(threading::cur_thread_state.exc_traceback);
} }
void collectStackRoots(TraceStack* stack) { void collectStackRoots(TraceStack* stack) {
......
...@@ -31,6 +31,13 @@ namespace pyston { ...@@ -31,6 +31,13 @@ namespace pyston {
BoxedModule* sys_module; BoxedModule* sys_module;
BoxedDict* sys_modules_dict; BoxedDict* sys_modules_dict;
Box* sysExcInfo() {
return new BoxedTuple(
{ threading::cur_thread_state.exc_type ? threading::cur_thread_state.exc_type : None,
threading::cur_thread_state.exc_value ? threading::cur_thread_state.exc_value : None,
threading::cur_thread_state.exc_traceback ? threading::cur_thread_state.exc_traceback : None });
}
BoxedDict* getSysModulesDict() { BoxedDict* getSysModulesDict() {
// PyPy's behavior: fetch from sys.modules each time: // PyPy's behavior: fetch from sys.modules each time:
// Box *_sys_modules = sys_module->getattr("modules"); // Box *_sys_modules = sys_module->getattr("modules");
...@@ -134,6 +141,8 @@ void setupSys() { ...@@ -134,6 +141,8 @@ void setupSys() {
sys_module->giveAttr("stdin", new BoxedFile(stdin, "<stdin>", "r")); sys_module->giveAttr("stdin", new BoxedFile(stdin, "<stdin>", "r"));
sys_module->giveAttr("stderr", new BoxedFile(stderr, "<stderr>", "w")); sys_module->giveAttr("stderr", new BoxedFile(stderr, "<stderr>", "w"));
sys_module->giveAttr("exc_info", new BoxedFunction(boxRTFunction((void*)sysExcInfo, BOXED_TUPLE, 0)));
sys_module->giveAttr("warnoptions", new BoxedList()); sys_module->giveAttr("warnoptions", new BoxedList());
sys_module->giveAttr("py3kwarning", False); sys_module->giveAttr("py3kwarning", False);
......
...@@ -630,30 +630,30 @@ extern "C" int PyCallable_Check(PyObject* x) { ...@@ -630,30 +630,30 @@ extern "C" int PyCallable_Check(PyObject* x) {
} }
void checkAndThrowCAPIException() { void checkAndThrowCAPIException() {
Box* value = threading::cur_thread_state.curexc_value; Box* value = threading::cur_thread_state.exc_value;
if (value) { if (value) {
RELEASE_ASSERT(threading::cur_thread_state.curexc_traceback == NULL, "unsupported"); RELEASE_ASSERT(threading::cur_thread_state.exc_traceback == NULL, "unsupported");
// This doesn't seem like the right behavior... // This doesn't seem like the right behavior...
if (value->cls != threading::cur_thread_state.curexc_type) { if (value->cls != threading::cur_thread_state.exc_type) {
if (value->cls == tuple_cls) if (value->cls == tuple_cls)
value = runtimeCall(threading::cur_thread_state.curexc_type, ArgPassSpec(0, 0, true, false), value, value = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(0, 0, true, false), value, NULL,
NULL, NULL, NULL, NULL); NULL, NULL, NULL);
else else
value = runtimeCall(threading::cur_thread_state.curexc_type, ArgPassSpec(1), value, NULL, NULL, NULL, value
NULL); = runtimeCall(threading::cur_thread_state.exc_type, ArgPassSpec(1), value, NULL, NULL, NULL, NULL);
} }
RELEASE_ASSERT(value->cls == threading::cur_thread_state.curexc_type, "unsupported"); RELEASE_ASSERT(value->cls == threading::cur_thread_state.exc_type, "unsupported");
PyErr_Clear(); PyErr_Clear();
throw value; throw value;
} }
} }
extern "C" void PyErr_Restore(PyObject* type, PyObject* value, PyObject* traceback) { extern "C" void PyErr_Restore(PyObject* type, PyObject* value, PyObject* traceback) {
threading::cur_thread_state.curexc_type = type; threading::cur_thread_state.exc_type = type;
threading::cur_thread_state.curexc_value = value; threading::cur_thread_state.exc_value = value;
threading::cur_thread_state.curexc_traceback = traceback; threading::cur_thread_state.exc_traceback = traceback;
} }
extern "C" void PyErr_Clear() { extern "C" void PyErr_Clear() {
...@@ -685,7 +685,7 @@ extern "C" int PyErr_ExceptionMatches(PyObject* exc) { ...@@ -685,7 +685,7 @@ extern "C" int PyErr_ExceptionMatches(PyObject* exc) {
} }
extern "C" PyObject* PyErr_Occurred() { extern "C" PyObject* PyErr_Occurred() {
return threading::cur_thread_state.curexc_type; return threading::cur_thread_state.exc_type;
} }
extern "C" int PyErr_WarnEx(PyObject* category, const char* text, Py_ssize_t stacklevel) { extern "C" int PyErr_WarnEx(PyObject* category, const char* text, Py_ssize_t stacklevel) {
......
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