Commit bbe39d40 authored by Marius Wachtler's avatar Marius Wachtler

Cleanup isSubclass check. Remove isInstance()

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