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