Commit 294a77b4 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix a number of exception-catching reference issues

Where we hadn't gone through and updated the exception-catch
sites to clear/hand off their owned ref appropriately.
parent 67f66027
......@@ -1911,6 +1911,7 @@ extern "C" PyObject* PyNumber_Divmod(PyObject* lhs, PyObject* rhs) noexcept {
try {
return binop(lhs, rhs, AST_TYPE::DivMod);
} catch (ExcInfo e) {
e.clear();
fatalOrError(PyExc_NotImplementedError, "unimplemented");
return nullptr;
}
......
......@@ -967,6 +967,8 @@ Box* slotTpGetattrHookInternal(Box* self, BoxedString* name, GetattrRewriteArgs*
throw e;
}
e.clear();
if (grewrite_args.isSuccessful()) {
grewrite_args.getReturn(); // to make the asserts happy
grewrite_args.clearReturn();
......@@ -1017,6 +1019,7 @@ Box* slotTpGetattrHookInternal(Box* self, BoxedString* name, GetattrRewriteArgs*
} else
throw e;
}
e.clear();
res = NULL;
}
}
......
......@@ -1006,6 +1006,10 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
} catch (ExcInfo e) {
error = true;
BoxedString* error_message = str(e.value);
e.clear();
AUTO_DECREF(error_message);
if (error_message && error_message->cls == str_cls)
return std::string(error_message->s());
return "Encountered an unknown error inside pypaEscapeDecoder";
......
......@@ -1021,8 +1021,9 @@ extern "C" void abort() {
alarm(1);
try {
_printStacktrace();
} catch (ExcInfo) {
} catch (ExcInfo e) {
fprintf(stderr, "error printing stack trace during abort()");
e.clear();
}
// Cancel the alarm.
......
......@@ -445,6 +445,7 @@ static int main(int argc, char** argv) noexcept {
throwCAPIException();
} catch (ExcInfo e) {
e.printExcAndTraceback();
e.clear();
return 1;
}
}
......
......@@ -76,6 +76,7 @@ static void* thread_start(Box* target, Box* varargs, Box* kwargs) {
autoDecref(runtimeCall(target, ArgPassSpec(0, 0, true, kwargs != NULL), varargs, kwargs, NULL, NULL, NULL));
} catch (ExcInfo e) {
e.printExcAndTraceback();
e.clear();
}
#if STAT_TIMERS
......
......@@ -1664,7 +1664,8 @@ extern "C" BORROWED(struct _frame*) PyEval_GetFrame(void) noexcept {
Box* frame = NULL;
try {
frame = getFrame(0);
} catch (ExcInfo) {
} catch (ExcInfo e) {
e.clear();
RELEASE_ASSERT(0, "untested");
}
return (struct _frame*)frame;
......
......@@ -673,6 +673,7 @@ Box* instanceNonzero(Box* _inst) {
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
e.clear();
}
if (nonzero_func == NULL) {
......@@ -682,6 +683,7 @@ Box* instanceNonzero(Box* _inst) {
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
e.clear();
}
}
......@@ -745,6 +747,7 @@ Box* instanceGetslice(Box* _inst, Box* i, Box* j) {
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
e.clear();
}
if (getslice_func == NULL) {
......@@ -768,6 +771,7 @@ Box* instanceSetslice(Box* _inst, Box* i, Box* j, Box** sequence) {
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
e.clear();
}
if (setslice_func == NULL) {
......@@ -792,6 +796,7 @@ Box* instanceDelslice(Box* _inst, Box* i, Box* j) {
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
e.clear();
}
if (delslice_func == NULL) {
......
......@@ -291,8 +291,10 @@ Box* generatorClose(Box* s) {
autoDecref(generatorThrow(self, GeneratorExit, nullptr, nullptr));
raiseExcHelper(RuntimeError, "generator ignored GeneratorExit");
} catch (ExcInfo e) {
if (e.matches(StopIteration) || e.matches(GeneratorExit))
if (e.matches(StopIteration) || e.matches(GeneratorExit)) {
e.clear();
return incref(None);
}
throw e;
}
assert(0); // unreachable
......
......@@ -718,6 +718,8 @@ Box* setContains(BoxedSet* self, Box* key) {
if (!e.matches(TypeError))
throw e;
e.clear();
BoxedSet* tmpKey = makeNewSet(frozenset_cls, key);
AUTO_DECREF(tmpKey);
return boxBool(self->s.find(tmpKey) != self->s.end());
......@@ -742,6 +744,8 @@ Box* setRemove(BoxedSet* self, Box* key) {
if (!e.matches(TypeError))
throw e;
e.clear();
BoxedSet* tmpKey = makeNewSet(frozenset_cls, key);
AUTO_DECREF(tmpKey);
if (self->s.find(tmpKey) != self->s.end()) {
......@@ -776,6 +780,8 @@ Box* setDiscard(BoxedSet* self, Box* key) {
if (!e.matches(TypeError))
throw e;
e.clear();
BoxedSet* tmpKey = makeNewSet(frozenset_cls, key);
AUTO_DECREF(tmpKey);
if (self->s.find(tmpKey) != self->s.end()) {
......
......@@ -3011,7 +3011,8 @@ Box* objectRepr(Box* self) {
mod = typeModule(type, NULL);
if (!PyString_Check(mod))
mod = NULL;
} catch (ExcInfo) {
} catch (ExcInfo e) {
e.clear();
}
DecrefHandle<Box> name(typeName(type, NULL));
......
# expected: reffail
class M(type):
pass
......
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