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