Commit bbe839c6 authored by Marius Wachtler's avatar Marius Wachtler

Merge commit '98dfb53b' into refcounting

Conflicts:
	from_cpython/Python/traceback.c
	src/codegen/unwinding.cpp
	src/runtime/builtin_modules/sys.cpp
	src/runtime/capi.cpp
	src/runtime/cxx_unwind.cpp
	src/runtime/exceptions.cpp
parents 06854823 98dfb53b
......@@ -124,14 +124,9 @@ PyTraceBack_Here(PyFrameObject *frame)
int
PyTraceBack_Here_Tb(PyFrameObject *frame, PyTracebackObject** tb)
{
PyObject* prev_tb = (PyObject*)*tb;
if (prev_tb == Py_None) {
Py_DECREF(prev_tb);
*tb = NULL;
prev_tb = NULL;
}
*tb = newtracebackobject(*tb, frame);
Py_XDECREF(prev_tb);
PyTracebackObject* oldtb = *tb;
*tb = newtracebackobject(oldtb, frame);
Py_XDECREF(oldtb);
if (*tb == NULL)
return -1;
return 0;
......
......@@ -703,7 +703,7 @@ ExcInfo* getFrameExcInfo() {
if (!copy_from_exc->type) {
// No exceptions found:
*copy_from_exc = ExcInfo(None, None, None);
*copy_from_exc = ExcInfo(None, None, NULL);
}
for (auto* ex : to_update) {
......
......@@ -48,25 +48,24 @@ Box* sysExcInfo() {
ExcInfo* exc = getFrameExcInfo();
assert(exc->type);
assert(exc->value);
assert(exc->traceback);
return BoxedTuple::create({ exc->type, exc->value, exc->traceback });
Box* tb = exc->traceback ? exc->traceback : None;
return BoxedTuple::create({ exc->type, exc->value, tb });
}
Box* sysExcClear() {
ExcInfo* exc = getFrameExcInfo();
assert(exc->type);
assert(exc->value);
assert(exc->traceback);
Box* old_type = exc->type;
Box* old_value = exc->value;
Box* old_traceback = exc->traceback;
exc->type = incref(None);
exc->value = incref(None);
exc->traceback = incref(None);
exc->traceback = NULL;
Py_DECREF(old_type);
Py_DECREF(old_value);
Py_DECREF(old_traceback);
Py_XDECREF(old_traceback);
Py_RETURN_NONE;
}
......
......@@ -717,9 +717,6 @@ void checkAndThrowCAPIException() {
if (!value)
value = incref(None);
if (!tb)
tb = incref(None);
// This is similar to PyErr_NormalizeException:
if (!isSubclass(value->cls, type)) {
if (value->cls == tuple_cls) {
......@@ -733,10 +730,10 @@ void checkAndThrowCAPIException() {
RELEASE_ASSERT(value->cls == type, "unsupported");
if (tb != None)
if (tb)
throw ExcInfo(value->cls, value, tb);
Py_DECREF(type);
Py_DECREF(tb);
Py_XDECREF(tb);
raiseExc(value);
}
}
......@@ -761,7 +758,7 @@ extern "C" void PyErr_SetExcInfo(PyObject* type, PyObject* value, PyObject* trac
ExcInfo* exc = getFrameExcInfo();
exc->type = type ? type : None;
exc->value = value ? value : None;
exc->traceback = traceback ? traceback : None;
exc->traceback = traceback;
}
extern "C" const char* PyExceptionClass_Name(PyObject* o) noexcept {
......
......@@ -73,7 +73,7 @@ namespace pyston {
void checkExcInfo(const ExcInfo* exc) {
assert(exc);
assert(exc->type && exc->value && exc->traceback);
assert(exc->type && exc->value);
}
static StatCounter us_unwind_loop("us_unwind_loop");
......
......@@ -27,7 +27,7 @@ namespace pyston {
void raiseExc(STOLEN(Box*) exc_obj) {
assert(!PyErr_Occurred());
throw ExcInfo(incref(exc_obj->cls), exc_obj, incref(None));
throw ExcInfo(incref(exc_obj->cls), exc_obj, NULL);
}
// Have a special helper function for syntax errors, since we want to include the location
......@@ -47,7 +47,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR
auto args = BoxedTuple::create({ autoDecref(boxString(file)), autoDecref(boxInt(lineno)), None, loc });
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(2), autoDecref(boxString(msg)), args, NULL, NULL, NULL);
assert(!PyErr_Occurred());
throw ExcInfo(incref(exc->cls), exc, incref(None));
throw ExcInfo(incref(exc->cls), exc, NULL);
} else {
PyErr_SetString(SyntaxError, msg);
PyErr_SyntaxLocation(file.str().c_str(), lineno);
......@@ -154,10 +154,6 @@ ExcInfo excInfoForRaise(STOLEN(Box*) type, STOLEN(Box*) value, STOLEN(Box*) tb)
assert(PyExceptionClass_Check(type));
if (tb == NULL) {
tb = incref(None);
}
return ExcInfo(type, value, tb);
}
......@@ -186,7 +182,7 @@ extern "C" void raise0_capi(ExcInfo* frame_exc_info) noexcept {
frame_exc_info->type = TypeError;
frame_exc_info->value
= boxString("exceptions must be old-style classes or derived from BaseException, not NoneType");
frame_exc_info->traceback = None;
frame_exc_info->traceback = NULL;
PyErr_NormalizeException(&frame_exc_info->type, &frame_exc_info->value, &frame_exc_info->traceback);
}
......
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