Commit 42014a09 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Some more refcounting fixes for exceptions

parent 63a6c334
...@@ -848,9 +848,17 @@ extern "C" void Py_Exit(int sts) noexcept { ...@@ -848,9 +848,17 @@ extern "C" void Py_Exit(int sts) noexcept {
} }
extern "C" void PyErr_Restore(PyObject* type, PyObject* value, PyObject* traceback) noexcept { extern "C" void PyErr_Restore(PyObject* type, PyObject* value, PyObject* traceback) noexcept {
auto oldtype = cur_thread_state.curexc_type;
auto oldvalue = cur_thread_state.curexc_value;
auto oldtraceback = cur_thread_state.curexc_traceback;
cur_thread_state.curexc_type = type; cur_thread_state.curexc_type = type;
cur_thread_state.curexc_value = value; cur_thread_state.curexc_value = value;
cur_thread_state.curexc_traceback = traceback; cur_thread_state.curexc_traceback = traceback;
Py_XDECREF(oldtype);
Py_XDECREF(oldvalue);
Py_XDECREF(oldtraceback);
} }
extern "C" void PyErr_Clear() noexcept { extern "C" void PyErr_Clear() noexcept {
......
...@@ -28,7 +28,7 @@ namespace pyston { ...@@ -28,7 +28,7 @@ namespace pyston {
void raiseExc(Box* exc_obj) { void raiseExc(Box* exc_obj) {
assert(!PyErr_Occurred()); assert(!PyErr_Occurred());
throw ExcInfo(exc_obj->cls, exc_obj, None); throw ExcInfo(incref(exc_obj->cls), exc_obj, incref(None));
} }
// Have a special helper function for syntax errors, since we want to include the location // Have a special helper function for syntax errors, since we want to include the location
...@@ -231,8 +231,7 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) { ...@@ -231,8 +231,7 @@ void raiseExcHelper(BoxedClass* cls, const char* msg, ...) {
va_end(ap); va_end(ap);
BoxedString* message = boxString(buf); BoxedString* message = boxString(buf);
Box* exc_obj = runtimeCall(cls, ArgPassSpec(1), message, NULL, NULL, NULL, NULL); Box* exc_obj = runtimeCall(cls, ArgPassSpec(1), autoDecref(message), NULL, NULL, NULL, NULL);
Py_DECREF(message);
raiseExc(exc_obj); raiseExc(exc_obj);
} else { } else {
Box* exc_obj = runtimeCall(cls, ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL); Box* exc_obj = runtimeCall(cls, ArgPassSpec(0), NULL, NULL, NULL, NULL, NULL);
......
...@@ -515,6 +515,7 @@ Box* importModuleLevel(llvm::StringRef name, Box* globals, Box* from_imports, in ...@@ -515,6 +515,7 @@ Box* importModuleLevel(llvm::StringRef name, Box* globals, Box* from_imports, in
bool again = loadNext(parent, level < 0 ? None : parent, _name, buf, &head); bool again = loadNext(parent, level < 0 ? None : parent, _name, buf, &head);
if (head == NULL) if (head == NULL)
return NULL; return NULL;
assert((!again) && "check refcounting");
Box* tail = head; Box* tail = head;
while (again) { while (again) {
......
...@@ -37,7 +37,7 @@ extern "C" void raise0(ExcInfo* frame_exc_info) __attribute__((__noreturn__)); ...@@ -37,7 +37,7 @@ extern "C" void raise0(ExcInfo* frame_exc_info) __attribute__((__noreturn__));
extern "C" void raise0_capi(ExcInfo* frame_exc_info) noexcept; extern "C" void raise0_capi(ExcInfo* frame_exc_info) noexcept;
extern "C" void raise3(Box*, Box*, Box*) __attribute__((__noreturn__)); extern "C" void raise3(Box*, Box*, Box*) __attribute__((__noreturn__));
extern "C" void raise3_capi(Box*, Box*, Box*) noexcept; extern "C" void raise3_capi(Box*, Box*, Box*) noexcept;
void raiseExc(Box* exc_obj) __attribute__((__noreturn__)); void raiseExc(STOLEN(Box*) exc_obj) __attribute__((__noreturn__));
void _printStacktrace(); void _printStacktrace();
extern "C" Box* deopt(AST_expr* expr, Box* value); extern "C" Box* deopt(AST_expr* expr, Box* value);
......
...@@ -4150,8 +4150,8 @@ void setupRuntime() { ...@@ -4150,8 +4150,8 @@ void setupRuntime() {
setupBuiltins(); setupBuiltins();
_PyExc_Init(); _PyExc_Init();
setupThread(); setupThread();
//initgc();
setupImport(); setupImport();
initgc();
setupPyston(); setupPyston();
setupAST(); setupAST();
......
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