Commit 1c25c150 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get rid of the global "last_exc" in favor of sys.exc_info

last_exc was not thread safe, and didn't respect frame-localness.
Now that we have sys.exc_info support we can do this the right way
parent 1c3f474d
......@@ -253,5 +253,7 @@ void initGlobalFuncs(GlobalState& g) {
GET(floordiv_float_float);
GET(mod_float_float);
GET(pow_float_float);
GET(dump);
}
}
......@@ -50,6 +50,8 @@ struct GlobalFuncs {
llvm::Value* raise0, *raise3;
llvm::Value* div_float_float, *floordiv_float_float, *mod_float_float, *pow_float_float;
llvm::Value* dump;
};
}
......
......@@ -80,9 +80,11 @@ private:
public:
void registerCF(CompiledFunction* cf) { cfs.push_back(cf); }
// addr is the return address of the callsite, so we will check it against
// the region (start, end] (opposite-endedness of normal half-open regions)
CompiledFunction* getCFForAddress(uint64_t addr) {
for (auto* cf : cfs) {
if (cf->code_start <= addr && addr < cf->code_start + cf->code_size)
if (cf->code_start < addr && addr <= cf->code_start + cf->code_size)
return cf;
}
return NULL;
......
......@@ -26,7 +26,6 @@ const LineInfo* getMostRecentLineInfo();
class BoxedModule;
BoxedModule* getCurrentModule();
CompiledFunction* getCFForAddress(uint64_t addr);
class BoxedDict;
BoxedDict* getLocals(bool only_user_visible);
......
......@@ -116,6 +116,8 @@ void force() {
FORCE(mod_float_float);
FORCE(pow_float_float);
FORCE(dump);
FORCE(boxFloat);
FORCE(createModule);
......
......@@ -95,7 +95,6 @@ void unwindExc(Box* exc_obj) {
abort();
}
static gc::GCRootHandle last_exc;
static std::vector<const LineInfo*> last_tb;
void raiseRaw(const ExcInfo& e) __attribute__((__noreturn__));
......@@ -115,7 +114,6 @@ void raiseRaw(const ExcInfo& e) {
void raiseExc(Box* exc_obj) {
auto entries = getTracebackEntries();
last_tb = std::move(entries);
last_exc = exc_obj;
raiseRaw(ExcInfo(exc_obj->cls, exc_obj, None));
}
......@@ -123,14 +121,14 @@ void raiseExc(Box* exc_obj) {
// Have a special helper function for syntax errors, since we want to include the location
// of the syntax error in the traceback, even though it is not part of the execution:
void raiseSyntaxError(const char* msg, int lineno, int col_offset, const std::string& file, const std::string& func) {
last_exc = exceptionNew2(SyntaxError, boxStrConstant(msg));
Box* exc = exceptionNew2(SyntaxError, boxStrConstant(msg));
auto entries = getTracebackEntries();
last_tb = std::move(entries);
// TODO: leaks this!
last_tb.push_back(new LineInfo(lineno, col_offset, file, func));
raiseRaw(ExcInfo(SyntaxError, last_exc, None));
raiseRaw(ExcInfo(exc->cls, exc, None));
}
static void _printTraceback(const std::vector<const LineInfo*>& tb) {
......@@ -221,7 +219,7 @@ extern "C" void exit(int code) {
}
void raise0() {
raiseRaw(ExcInfo(last_exc->cls, last_exc, None));
raiseRaw(getFrameExcInfo());
}
bool ExcInfo::matches(BoxedClass* cls) const {
......
......@@ -107,6 +107,26 @@ def f4():
print "caught attribute error (makes sense, but wrong)"
except NotImplementedError:
print "caught not implemented error (weird, but right)"
# As a variant, if we put the inner exception inside a function call,
# it only sets that frame's exc_info.
try:
try:
raise AttributeError()
except AttributeError:
def thrower():
try:
raise NotImplementedError()
except:
pass
thrower()
# This time, it should throw the AttributeError
raise
except AttributeError:
print "caught attribute error (right this time)"
except NotImplementedError:
print "caught not implemented error (wrong this time)"
f4()
def f5():
......
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