Commit c0ffc375 authored by Chris Toshok's avatar Chris Toshok

do beginUnwind() inside __cxa_allocate_exception so we can support 'throw e' (instead of aborting)

parent 49d146cc
...@@ -926,7 +926,7 @@ void checkAndThrowCAPIException() { ...@@ -926,7 +926,7 @@ void checkAndThrowCAPIException() {
RELEASE_ASSERT(value->cls == type, "unsupported"); RELEASE_ASSERT(value->cls == type, "unsupported");
if (tb != None) if (tb != None)
raiseRaw(ExcInfo(value->cls, value, tb)); throw ExcInfo(value->cls, value, tb);
raiseExc(value); raiseExc(value);
} }
} }
......
...@@ -635,7 +635,7 @@ extern "C" void* __cxa_allocate_exception(size_t size) noexcept { ...@@ -635,7 +635,7 @@ extern "C" void* __cxa_allocate_exception(size_t size) noexcept {
// our exception info in curexc_*, and then unset these in __cxa_end_catch, then we'll wipe our exception info // our exception info in curexc_*, and then unset these in __cxa_end_catch, then we'll wipe our exception info
// during unwinding! // during unwinding!
return pyston::getExceptionStorage(pyston::getUnwind()); return pyston::getExceptionStorage(pyston::beginUnwind());
} }
// Takes the value that resume() sent us in RAX, and returns a pointer to the exception object actually thrown. In our // Takes the value that resume() sent us in RAX, and returns a pointer to the exception object actually thrown. In our
......
...@@ -155,7 +155,7 @@ static void generatorSendInternal(BoxedGenerator* self, Box* v) { ...@@ -155,7 +155,7 @@ static void generatorSendInternal(BoxedGenerator* self, Box* v) {
freeGeneratorStack(self); freeGeneratorStack(self);
// don't raise StopIteration exceptions because those are handled specially. // don't raise StopIteration exceptions because those are handled specially.
if (!self->exception.matches(StopIteration)) if (!self->exception.matches(StopIteration))
raiseRaw(self->exception); throw self->exception;
return; return;
} }
...@@ -193,7 +193,7 @@ Box* generatorSend(Box* s, Box* v) { ...@@ -193,7 +193,7 @@ Box* generatorSend(Box* s, Box* v) {
self->exception = ExcInfo(nullptr, nullptr, nullptr); self->exception = ExcInfo(nullptr, nullptr, nullptr);
if (old_exc.type == NULL) if (old_exc.type == NULL)
raiseExcHelper(StopIteration, (const char*)nullptr); raiseExcHelper(StopIteration, (const char*)nullptr);
raiseRaw(old_exc); throw old_exc;
} }
return self->returnValue; return self->returnValue;
...@@ -272,7 +272,7 @@ extern "C" Box* yield(BoxedGenerator* obj, Box* value) { ...@@ -272,7 +272,7 @@ extern "C" Box* yield(BoxedGenerator* obj, Box* value) {
if (self->exception.type) { if (self->exception.type) {
ExcInfo e = self->exception; ExcInfo e = self->exception;
self->exception = ExcInfo(NULL, NULL, NULL); self->exception = ExcInfo(NULL, NULL, NULL);
raiseRaw(e); throw e;
} }
return self->returnValue; return self->returnValue;
} }
......
...@@ -49,7 +49,7 @@ Box* createAndRunModule(const std::string& name, const std::string& fn) { ...@@ -49,7 +49,7 @@ Box* createAndRunModule(const std::string& name, const std::string& fn) {
compileAndRunModule(ast, module); compileAndRunModule(ast, module);
} catch (ExcInfo e) { } catch (ExcInfo e) {
removeModule(name); removeModule(name);
raiseRaw(e); throw e;
} }
Box* r = getSysModulesDict()->getOrNull(boxString(name)); Box* r = getSysModulesDict()->getOrNull(boxString(name));
...@@ -74,7 +74,7 @@ static Box* createAndRunModule(const std::string& name, const std::string& fn, c ...@@ -74,7 +74,7 @@ static Box* createAndRunModule(const std::string& name, const std::string& fn, c
compileAndRunModule(ast, module); compileAndRunModule(ast, module);
} catch (ExcInfo e) { } catch (ExcInfo e) {
removeModule(name); removeModule(name);
raiseRaw(e); throw e;
} }
Box* r = getSysModulesDict()->getOrNull(boxString(name)); Box* r = getSysModulesDict()->getOrNull(boxString(name));
...@@ -406,7 +406,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box ...@@ -406,7 +406,7 @@ static Box* importSub(const std::string& name, const std::string& full_name, Box
RELEASE_ASSERT(0, "%d", sr.type); RELEASE_ASSERT(0, "%d", sr.type);
} catch (ExcInfo e) { } catch (ExcInfo e) {
removeModule(name); removeModule(name);
raiseRaw(e); throw e;
} }
if (parent_module && parent_module != None) if (parent_module && parent_module != None)
...@@ -560,7 +560,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re ...@@ -560,7 +560,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
pathlist = getattrInternal(module, path_str, NULL); pathlist = getattrInternal(module, path_str, NULL);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (!e.matches(AttributeError)) if (!e.matches(AttributeError))
raiseRaw(e); throw e;
} }
if (pathlist == NULL) { if (pathlist == NULL) {
......
...@@ -727,7 +727,7 @@ void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) { ...@@ -727,7 +727,7 @@ void listSort(BoxedList* self, Box* cmp, Box* key, Box* reverse) {
std::stable_sort<Box**, PyLt>(self->elts->elts, self->elts->elts + self->size, PyLt()); std::stable_sort<Box**, PyLt>(self->elts->elts, self->elts->elts + self->size, PyLt());
} catch (ExcInfo e) { } catch (ExcInfo e) {
remove_keys(); remove_keys();
raiseRaw(e); throw e;
} }
remove_keys(); remove_keys();
......
...@@ -72,8 +72,6 @@ void raiseRaw(const ExcInfo& e) { ...@@ -72,8 +72,6 @@ void raiseRaw(const ExcInfo& e) {
#endif #endif
#endif #endif
// printf ("beginning unwind\n");
beginUnwind();
throw e; throw e;
} }
...@@ -88,7 +86,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR ...@@ -88,7 +86,7 @@ void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringR
auto tb = new BoxedTraceback(); auto tb = new BoxedTraceback();
tb->addLine(LineInfo(lineno, col_offset, file, func)); tb->addLine(LineInfo(lineno, col_offset, file, func));
raiseRaw(ExcInfo(exc->cls, exc, tb)); throw ExcInfo(exc->cls, exc, tb);
} }
void raiseSyntaxErrorHelper(llvm::StringRef file, llvm::StringRef func, AST* node_at, const char* msg, ...) { void raiseSyntaxErrorHelper(llvm::StringRef file, llvm::StringRef func, AST* node_at, const char* msg, ...) {
...@@ -207,7 +205,7 @@ extern "C" void raise0() { ...@@ -207,7 +205,7 @@ extern "C" void raise0() {
raiseExcHelper(TypeError, "exceptions must be old-style classes or derived from BaseException, not NoneType"); raiseExcHelper(TypeError, "exceptions must be old-style classes or derived from BaseException, not NoneType");
exc_info->reraise = true; exc_info->reraise = true;
raiseRaw(*exc_info); throw * exc_info;
} }
#ifndef NDEBUG #ifndef NDEBUG
...@@ -288,7 +286,7 @@ extern "C" void raise3(Box* arg0, Box* arg1, Box* arg2) { ...@@ -288,7 +286,7 @@ extern "C" void raise3(Box* arg0, Box* arg1, Box* arg2) {
auto exc_info = excInfoForRaise(arg0, arg1, arg2); auto exc_info = excInfoForRaise(arg0, arg1, arg2);
exc_info.reraise = reraise; exc_info.reraise = reraise;
raiseRaw(exc_info); throw exc_info;
} }
void raiseExcHelper(BoxedClass* cls, Box* arg) { void raiseExcHelper(BoxedClass* cls, Box* arg) {
......
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