Commit d99f473e authored by Dong-hee,Na's avatar Dong-hee,Na

modify exeception handling during repr

parent 86096848
...@@ -32,10 +32,11 @@ using pyston::ExceptionStyle::ExceptionStyle; ...@@ -32,10 +32,11 @@ using pyston::ExceptionStyle::ExceptionStyle;
Box* dictRepr(BoxedDict* self) { Box* dictRepr(BoxedDict* self) {
std::vector<char> chars;
try { try {
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
...@@ -49,32 +50,38 @@ Box* dictRepr(BoxedDict* self) { ...@@ -49,32 +50,38 @@ Box* dictRepr(BoxedDict* self) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
} catch (ExcInfo e) {
setCAPIException(e);
Py_ReprLeave((PyObject*)self);
return NULL;
}
chars.push_back('{'); chars.push_back('{');
bool first = true; bool first = true;
for (const auto& p : self->d) { for (const auto& p : self->d) {
if (!first) { if (!first) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
} }
first = false; first = false;
BoxedString* k = static_cast<BoxedString*>(repr(p.first)); BoxedString* k = static_cast<BoxedString*>(repr(p.first));
BoxedString* v = static_cast<BoxedString*>(repr(p.second)); BoxedString* v = static_cast<BoxedString*>(repr(p.second));
chars.insert(chars.end(), k->s().begin(), k->s().end()); chars.insert(chars.end(), k->s().begin(), k->s().end());
chars.push_back(':'); chars.push_back(':');
chars.push_back(' '); chars.push_back(' ');
chars.insert(chars.end(), v->s().begin(), v->s().end()); chars.insert(chars.end(), v->s().begin(), v->s().end());
} }
chars.push_back('}'); chars.push_back('}');
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
} }
Box* dictClear(BoxedDict* self) { Box* dictClear(BoxedDict* self) {
......
...@@ -62,12 +62,13 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept { ...@@ -62,12 +62,13 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept {
extern "C" Box* listRepr(BoxedList* self) { extern "C" Box* listRepr(BoxedList* self) {
std::vector<char> chars;
// Implementing Recursive Print of list in same way from Cpython
try { try {
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
...@@ -79,13 +80,11 @@ extern "C" Box* listRepr(BoxedList* self) { ...@@ -79,13 +80,11 @@ extern "C" Box* listRepr(BoxedList* self) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
} catch (ExcInfo e) {
setCAPIException(e);
Py_ReprLeave((PyObject*)self);
return NULL;
}
chars.push_back('['); chars.push_back('[');
for (int i = 0; i < self->size; i++) { for (int i = 0; i < self->size; i++) {
if (i > 0) { if (i > 0) {
chars.push_back(','); chars.push_back(',');
chars.push_back(' '); chars.push_back(' ');
...@@ -97,10 +96,19 @@ extern "C" Box* listRepr(BoxedList* self) { ...@@ -97,10 +96,19 @@ extern "C" Box* listRepr(BoxedList* self) {
BoxedString* s = static_cast<BoxedString*>(r); BoxedString* s = static_cast<BoxedString*>(r);
chars.insert(chars.end(), s->s().begin(), s->s().end()); chars.insert(chars.end(), s->s().begin(), s->s().end());
} }
chars.push_back(']'); chars.push_back(']');
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
} }
extern "C" Box* listNonzero(BoxedList* self) { extern "C" Box* listNonzero(BoxedList* self) {
......
...@@ -95,11 +95,13 @@ Box* setNew(Box* _cls, Box* container) { ...@@ -95,11 +95,13 @@ Box* setNew(Box* _cls, Box* container) {
static Box* _setRepr(BoxedSet* self, const char* type_name) { static Box* _setRepr(BoxedSet* self, const char* type_name) {
std::vector<char> chars;
try { try {
std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)self); int status = Py_ReprEnter((PyObject*)self);
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
...@@ -114,11 +116,6 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) { ...@@ -114,11 +116,6 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
} catch (ExcInfo e) {
setCAPIException(e);
Py_ReprLeave((PyObject*)self);
return NULL;
}
std::string ty = std::string(type_name); std::string ty = std::string(type_name);
chars.insert(chars.end(), ty.begin(), ty.end()); chars.insert(chars.end(), ty.begin(), ty.end());
...@@ -142,6 +139,11 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) { ...@@ -142,6 +139,11 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
chars.push_back(')'); chars.push_back(')');
Py_ReprLeave((PyObject*)self); Py_ReprLeave((PyObject*)self);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)self);
throw e;
}
} }
Box* setRepr(BoxedSet* self) { Box* setRepr(BoxedSet* self) {
......
...@@ -201,8 +201,11 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept { ...@@ -201,8 +201,11 @@ extern "C" Py_ssize_t PyTuple_Size(PyObject* op) noexcept {
Box* tupleRepr(BoxedTuple* t) { Box* tupleRepr(BoxedTuple* t) {
assert(isSubclass(t->cls, tuple_cls)); assert(isSubclass(t->cls, tuple_cls));
try {
int n; int n;
std::vector<char> chars; std::vector<char> chars;
int status = Py_ReprEnter((PyObject*)t);
n = t->size(); n = t->size();
if (n == 0) { if (n == 0) {
...@@ -211,8 +214,6 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -211,8 +214,6 @@ Box* tupleRepr(BoxedTuple* t) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
try {
int status = Py_ReprEnter((PyObject*)t);
if (status != 0) { if (status != 0) {
if (status < 0) if (status < 0)
throwCAPIException(); throwCAPIException();
...@@ -226,13 +227,6 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -226,13 +227,6 @@ Box* tupleRepr(BoxedTuple* t) {
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} }
} catch (ExcInfo e) {
setCAPIException(e);
Py_ReprLeave((PyObject*)t);
return NULL;
}
chars.push_back('('); chars.push_back('(');
...@@ -252,6 +246,11 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -252,6 +246,11 @@ Box* tupleRepr(BoxedTuple* t) {
Py_ReprLeave((PyObject*)t); Py_ReprLeave((PyObject*)t);
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
} catch (ExcInfo e) {
Py_ReprLeave((PyObject*)t);
throw e;
}
} }
Box* tupleNonzero(BoxedTuple* self) { Box* tupleNonzero(BoxedTuple* self) {
......
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