Commit d034a63e authored by Chris Toshok's avatar Chris Toshok

make BoxedTraceback hold a single line, instead of a vector. rename...

make BoxedTraceback hold a single line, instead of a vector.  rename BoxedTraceback::Here to BoxedTraceback::here
parent e7bd664b
......@@ -518,7 +518,7 @@ public:
exc_info.reraise = false;
return;
}
BoxedTraceback::Here(line_info, reinterpret_cast<BoxedTraceback**>(&exc_info.traceback));
BoxedTraceback::here(line_info, &exc_info.traceback);
}
void logException() {
......@@ -614,7 +614,7 @@ void exceptionCaughtInInterpreter(LineInfo line_info, ExcInfo* exc_info) {
exc_info->reraise = false;
return;
}
BoxedTraceback::Here(line_info, reinterpret_cast<BoxedTraceback**>(&exc_info->traceback));
BoxedTraceback::here(line_info, &exc_info->traceback);
}
void unwindingThroughFrame(PythonUnwindSession* unwind_session, unw_cursor_t* cursor) {
......@@ -754,18 +754,16 @@ BoxedTraceback* getTraceback() {
Timer _t("getTraceback", 1000);
BoxedTraceback::LinesVector entries;
Box* tb = new BoxedTraceback();
unwindPythonStack([&](PythonFrameIteratorImpl* frame_iter) {
entries.push_back(lineInfoForFrame(frame_iter));
BoxedTraceback::here(lineInfoForFrame(frame_iter), &tb);
return false;
});
std::reverse(entries.begin(), entries.end());
long us = _t.end();
us_gettraceback.log(us);
return new BoxedTraceback(std::move(entries));
return static_cast<BoxedTraceback*>(tb);
}
ExcInfo* getFrameExcInfo() {
......
......@@ -55,8 +55,7 @@ void raiseExc(Box* exc_obj) {
void raiseSyntaxError(const char* msg, int lineno, int col_offset, llvm::StringRef file, llvm::StringRef func) {
Box* exc = runtimeCall(SyntaxError, ArgPassSpec(1), boxString(msg), NULL, NULL, NULL, NULL);
auto tb = new BoxedTraceback();
tb->addLine(LineInfo(lineno, col_offset, file, func));
auto tb = new BoxedTraceback(LineInfo(lineno, col_offset, file, func), None);
throw ExcInfo(exc->cls, exc, tb);
}
......
......@@ -57,7 +57,7 @@ void printTraceback(Box* b) {
fprintf(stderr, "Traceback (most recent call last):\n");
for (; tb && tb != None; tb = static_cast<BoxedTraceback*>(tb->tb_next)) {
for (auto line : tb->lines) {
auto& line = tb->line;
fprintf(stderr, " File \"%s\", line %d, in %s:\n", line.file.c_str(), line.line, line.func.c_str());
if (line.line < 0)
......@@ -92,11 +92,6 @@ void printTraceback(Box* b) {
fclose(f);
}
}
}
}
void BoxedTraceback::addLine(const LineInfo line) {
lines.insert(lines.begin(), line);
}
Box* BoxedTraceback::getLines(Box* b) {
......@@ -107,8 +102,8 @@ Box* BoxedTraceback::getLines(Box* b) {
if (!tb->py_lines) {
BoxedList* lines = new BoxedList();
for (BoxedTraceback* wtb = tb; wtb && wtb != None; wtb = static_cast<BoxedTraceback*>(wtb->tb_next)) {
lines->ensure(wtb->lines.size());
for (auto& line : wtb->lines) {
if (wtb->has_line) {
auto& line = wtb->line;
auto l = BoxedTuple::create({ boxString(line.file), boxString(line.func), boxInt(line.line) });
listAppendInternal(lines, l);
}
......@@ -119,9 +114,8 @@ Box* BoxedTraceback::getLines(Box* b) {
return tb->py_lines;
}
void BoxedTraceback::Here(LineInfo lineInfo, BoxedTraceback** tb) {
*tb = new BoxedTraceback(*tb);
(*tb)->addLine(lineInfo);
void BoxedTraceback::here(LineInfo lineInfo, Box** tb) {
*tb = new BoxedTraceback(lineInfo, *tb);
}
void setupTraceback() {
......
......@@ -27,25 +27,22 @@ class GCVisitor;
extern "C" BoxedClass* traceback_cls;
class BoxedTraceback : public Box {
public:
typedef llvm::SmallVector<LineInfo, 1> LinesVector;
Box* tb_next;
LinesVector lines;
bool has_line;
LineInfo line;
Box* py_lines;
BoxedTraceback(LinesVector&& lines) : tb_next(None), lines(std::move(lines)), py_lines(NULL) {}
BoxedTraceback(BoxedTraceback* tb_next) : tb_next(tb_next), py_lines(NULL) {}
BoxedTraceback() : tb_next(None), py_lines(NULL) {}
BoxedTraceback(LineInfo line, Box* tb_next) : tb_next(tb_next), has_line(true), line(line), py_lines(NULL) {}
BoxedTraceback() : tb_next(None), has_line(false), line(-1, -1, "", ""), py_lines(NULL) {}
DEFAULT_CLASS(traceback_cls);
void addLine(const LineInfo line);
static Box* getLines(Box* b);
static void gcHandler(gc::GCVisitor* v, Box* b);
// somewhat equivalent to PyTraceBack_Here
static void Here(LineInfo lineInfo, BoxedTraceback** tb);
static void here(LineInfo lineInfo, Box** tb);
};
void printTraceback(Box* b);
......
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