Commit 98dfb53b authored by Marius Wachtler's avatar Marius Wachtler

ExcInfo: don't set traceback to None instead use NULL

This makes it more similar to cpythons and without this PyTraceBack_Here does not work correctly.
parent f15399e3
......@@ -126,8 +126,6 @@ PyTraceBack_Here(PyFrameObject *frame)
int
PyTraceBack_Here_Tb(PyFrameObject *frame, PyTracebackObject** tb)
{
if ((PyObject*)*tb == Py_None)
*tb = NULL;
*tb = newtracebackobject(*tb, frame);
if (*tb == NULL)
return -1;
......
......@@ -719,12 +719,12 @@ ExcInfo* getFrameExcInfo() {
if (!copy_from_exc->type) {
// No exceptions found:
*copy_from_exc = ExcInfo(None, None, None);
*copy_from_exc = ExcInfo(None, None, NULL);
}
assert(gc::isValidGCObject(copy_from_exc->type));
assert(gc::isValidGCObject(copy_from_exc->value));
assert(gc::isValidGCObject(copy_from_exc->traceback));
assert(!copy_from_exc->traceback || gc::isValidGCObject(copy_from_exc->traceback));
for (auto* ex : to_update) {
*ex = *copy_from_exc;
......
......@@ -48,19 +48,18 @@ 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);
exc->type = None;
exc->value = None;
exc->traceback = None;
exc->traceback = NULL;
return None;
}
......
......@@ -715,8 +715,6 @@ void checkAndThrowCAPIException() {
value = None;
Box* tb = cur_thread_state.curexc_traceback;
if (!tb)
tb = None;
// Make sure to call PyErr_Clear() *before* normalizing the exception, since otherwise
// the normalization can think that it had raised an exception, resulting to a call
......@@ -736,7 +734,7 @@ void checkAndThrowCAPIException() {
RELEASE_ASSERT(value->cls == type, "unsupported");
if (tb != None)
if (tb)
throw ExcInfo(value->cls, value, tb);
raiseExc(value);
}
......@@ -760,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,10 +73,10 @@ namespace pyston {
void checkExcInfo(const ExcInfo* exc) {
assert(exc);
assert(exc->type && exc->value && exc->traceback);
assert(exc->type && exc->value);
ASSERT(gc::isValidGCObject(exc->type), "%p", exc->type);
ASSERT(gc::isValidGCObject(exc->value), "%p", exc->value);
ASSERT(gc::isValidGCObject(exc->traceback), "%p", exc->traceback);
ASSERT(!exc->traceback || gc::isValidGCObject(exc->traceback), "%p", exc->traceback);
}
static StatCounter us_unwind_loop("us_unwind_loop");
......
......@@ -27,7 +27,7 @@ namespace pyston {
void raiseExc(Box* exc_obj) {
assert(!PyErr_Occurred());
throw ExcInfo(exc_obj->cls, exc_obj, None);
throw ExcInfo(exc_obj->cls, exc_obj, NULL);
}
// Have a special helper function for syntax errors, since we want to include the location
......@@ -46,7 +46,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR
auto args = BoxedTuple::create({ boxString(file), boxInt(lineno), None, loc });
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(2), boxString(msg), args, NULL, NULL, NULL);
assert(!PyErr_Occurred());
throw ExcInfo(exc->cls, exc, None);
throw ExcInfo(exc->cls, exc, NULL);
} else {
PyErr_SetString(SyntaxError, msg);
PyErr_SyntaxLocation(file.str().c_str(), lineno);
......@@ -140,10 +140,6 @@ ExcInfo excInfoForRaise(Box* type, Box* value, Box* tb) {
assert(PyExceptionClass_Check(type));
if (tb == NULL) {
tb = None;
}
return ExcInfo(type, value, tb);
}
......@@ -169,7 +165,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