Commit 2254da9f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix bug if you try to call something not callable

parent 53c2fadd
......@@ -30,6 +30,10 @@
#include "core/stats.h"
#include "core/util.h"
//#undef VERBOSITY
//#define VERBOSITY(x) 2
//#define TIME_INTERPRETS
extern "C" void* __cxa_allocate_exception(size_t);
namespace pyston {
......@@ -62,10 +66,6 @@ int width(llvm::Value* v, const llvm::DataLayout& dl) {
return width(v->getType(), dl);
}
//#undef VERBOSITY
//#define VERBOSITY(x) 2
//#define TIME_INTERPRETS
Val fetch(llvm::Value* v, const llvm::DataLayout& dl, const SymMap& symbols) {
assert(v);
......@@ -636,6 +636,10 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* arg1, Box* arg2, Box*
}
}
catch (Box* e) {
if (VERBOSITY("interpreter") >= 2) {
printf("Caught exception: %p\n", e);
}
if (invoke == nullptr)
throw;
......
......@@ -1560,13 +1560,17 @@ Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, int64_t nargs,
Box* orig_obj = obj;
if (obj->cls != function_cls && obj->cls != instancemethod_cls) {
Box* rtn;
if (rewrite_args) {
// TODO is this ok?
// rewrite_args->rewriter->trap();
return callattrInternal(obj, &_call_str, CLASS_ONLY, rewrite_args, nargs, arg1, arg2, arg3, args);
rtn = callattrInternal(obj, &_call_str, CLASS_ONLY, rewrite_args, nargs, arg1, arg2, arg3, args);
} else {
return callattrInternal(obj, &_call_str, CLASS_ONLY, NULL, nargs, arg1, arg2, arg3, args);
rtn = callattrInternal(obj, &_call_str, CLASS_ONLY, NULL, nargs, arg1, arg2, arg3, args);
}
if (!rtn)
raiseExcHelper(TypeError, "'%s' object is not callable", getTypeName(obj)->c_str());
return rtn;
}
if (rewrite_args) {
......@@ -1747,6 +1751,7 @@ extern "C" Box* runtimeCall(Box* obj, int64_t nargs, Box* arg1, Box* arg2, Box*
} else {
rtn = runtimeCallInternal(obj, NULL, nargs, arg1, arg2, arg3, args);
}
assert(rtn);
if (rewriter.get()) {
rewriter->commit();
......
......@@ -33,17 +33,17 @@ except ZeroDivisionError, e:
class MyException(Exception):
pass
def catches(e):
def catches(e, c):
try:
try:
raise e
except MyException:
except c:
return True
except:
return False
print catches(Exception())
print catches(AttributeError())
print catches(MyException())
for e in [Exception(), AttributeError(), MyException()]:
for c in [Exception, AttributeError, MyException, TypeError]:
print catches(e, c)
def f():
try:
......
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