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