Commit 76c861ad authored by Kevin Modzelewski's avatar Kevin Modzelewski

capi exceptions fixes

We got away with sloppy exception clearing in some places, since
raiseExcHelper would end up calling typeCall which would re-throw
the capi exception that hadn't been cleared.

Now that typeCall doesn't do that (which is fine), those bugs got
exposed.
parent be68face
......@@ -248,7 +248,7 @@ Box* open(Box* arg1, Box* arg2, Box* arg3) {
extern "C" Box* chr(Box* arg) {
i64 n = PyInt_AsLong(arg);
if (n == -1 && PyErr_Occurred())
raiseExcHelper(TypeError, "an integer is required");
throwCAPIException();
if (n < 0 || n >= 256) {
raiseExcHelper(ValueError, "chr() arg not in range(256)");
......
......@@ -347,6 +347,9 @@ Box* BoxedMethodDescriptor::callInternal(BoxedFunctionBase* f, CallRewriteArgs*
RELEASE_ASSERT(0, "0x%x", call_flags);
}
if (!rtn)
throwCAPIException();
rewrite_args->rewriter->call(true, (void*)checkAndThrowCAPIException);
rewrite_args->out_rtn = r_rtn;
rewrite_args->out_success = true;
......
......@@ -44,9 +44,11 @@ public:
Box* next = PyIter_Next(iterator);
if (next)
value = next;
else
else {
checkAndThrowCAPIException();
*this = *end();
}
}
Box* getValue() override { return value; }
......
......@@ -101,7 +101,7 @@ extern "C" Box* listPop(BoxedList* self, Box* idx) {
int64_t n = PyInt_AsSsize_t(idx);
if (n == -1 && PyErr_Occurred())
raiseExcHelper(TypeError, "an integer is required");
throwCAPIException();
if (n < 0)
n = self->size + n;
......
......@@ -3515,6 +3515,7 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg
ASSERT(chosen_cf->spec->rtn_type->isFitBy(r->cls), "%s (%p) was supposed to return %s, but gave a %s",
g.func_addr_registry.getFuncNameAtAddress(chosen_cf->code, true, NULL).c_str(), chosen_cf->code,
chosen_cf->spec->rtn_type->debugName().c_str(), r->cls->tp_name);
assert(!PyErr_Occurred());
return r;
}
......
......@@ -47,6 +47,7 @@ void showBacktrace() {
}
void raiseExc(Box* exc_obj) {
assert(!PyErr_Occurred());
throw ExcInfo(exc_obj->cls, exc_obj, None);
}
......@@ -56,6 +57,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(1), boxString(msg), NULL, NULL, NULL, NULL);
auto tb = new BoxedTraceback(LineInfo(lineno, col_offset, file, func), None);
assert(!PyErr_Occurred());
throw ExcInfo(exc->cls, exc, tb);
}
......@@ -175,6 +177,7 @@ extern "C" void raise0() {
raiseExcHelper(TypeError, "exceptions must be old-style classes or derived from BaseException, not NoneType");
exc_info->reraise = true;
assert(!PyErr_Occurred());
throw * exc_info;
}
......@@ -256,6 +259,7 @@ extern "C" void raise3(Box* arg0, Box* arg1, Box* arg2) {
auto exc_info = excInfoForRaise(arg0, arg1, arg2);
exc_info.reraise = reraise;
assert(!PyErr_Occurred());
throw exc_info;
}
......
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