Commit bbe39d40 authored by Marius Wachtler's avatar Marius Wachtler

Cleanup isSubclass check. Remove isInstance()

parent 20014568
......@@ -669,7 +669,7 @@ void checkAndThrowCAPIException() {
if (_type) {
BoxedClass* type = static_cast<BoxedClass*>(_type);
assert(isInstance(_type, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException)
assert(isSubclass(_type->cls, type_cls) && isSubclass(static_cast<BoxedClass*>(type), BaseException)
&& "Only support throwing subclass of BaseException for now");
Box* value = cur_thread_state.curexc_value;
......@@ -686,7 +686,7 @@ void checkAndThrowCAPIException() {
PyErr_Clear();
// This is similar to PyErr_NormalizeException:
if (!isInstance(value, type)) {
if (!isSubclass(value->cls, type)) {
if (value->cls == tuple_cls) {
value = runtimeCall(type, ArgPassSpec(0, 0, true, false), value, NULL, NULL, NULL, NULL);
} else if (value == None) {
......
......@@ -211,18 +211,8 @@ extern "C" void my_assert(bool b) {
assert(b);
}
bool isInstance(Box* obj, BoxedClass* cls) {
int rtn = _PyObject_RealIsInstance(obj, cls);
if (rtn < 0)
checkAndThrowCAPIException();
return rtn;
}
extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent) {
int rtn = _PyObject_RealIsSubclass(child, parent);
if (rtn < 0)
checkAndThrowCAPIException();
return rtn;
return PyType_IsSubtype(child, parent);
}
extern "C" void assertFail(BoxedModule* inModule, Box* msg) {
......@@ -4465,7 +4455,7 @@ extern "C" Box* boxedLocalsGet(Box* boxedLocals, const char* attr, BoxedModule*
// TODO should check the exact semantic here but it's something like:
// If it throws a KeyError, then the variable doesn't exist so move on
// and check the globals (below); otherwise, just propogate the exception.
if (!isInstance(e.value, KeyError)) {
if (!isSubclass(e.value->cls, KeyError)) {
throw;
}
}
......
......@@ -84,7 +84,6 @@ extern "C" Box* importStar(Box* from_module, BoxedModule* to_module);
extern "C" Box** unpackIntoArray(Box* obj, int64_t expected_size);
extern "C" void assertNameDefined(bool b, const char* name, BoxedClass* exc_cls, bool local_var_msg);
extern "C" void assertFail(BoxedModule* inModule, Box* msg);
extern "C" bool isInstance(Box* obj, BoxedClass* parent);
extern "C" bool isSubclass(BoxedClass* child, BoxedClass* parent);
extern "C" BoxedClosure* createClosure(BoxedClosure* parent_closure);
......
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