Commit 37c237f8 authored by Marius Wachtler's avatar Marius Wachtler

check return value instead of calling checkAndThrowCAPIException()

this should make pyston more robust to cases where the error is set by a previous operation

no functional change intended
parent 4027c960
...@@ -981,7 +981,8 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi ...@@ -981,7 +981,8 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
BoxedString* str_utf8 = (BoxedString*)PyUnicode_AsUTF8String(str); BoxedString* str_utf8 = (BoxedString*)PyUnicode_AsUTF8String(str);
AUTO_DECREF(str_utf8); AUTO_DECREF(str_utf8);
assert(str_utf8->cls == str_cls); assert(str_utf8->cls == str_cls);
checkAndThrowCAPIException(); if (!str_utf8)
throwCAPIException();
return str_utf8->s().str(); return str_utf8->s().str();
} }
......
...@@ -350,7 +350,7 @@ extern "C" Box* unichr(Box* arg) { ...@@ -350,7 +350,7 @@ extern "C" Box* unichr(Box* arg) {
Box* rtn = PyUnicode_FromOrdinal(n); Box* rtn = PyUnicode_FromOrdinal(n);
if (!rtn) if (!rtn)
checkAndThrowCAPIException(); throwCAPIException();
return rtn; return rtn;
} }
...@@ -409,21 +409,27 @@ Box* range(Box* start, Box* stop, Box* step) { ...@@ -409,21 +409,27 @@ Box* range(Box* start, Box* stop, Box* step) {
if (stop == NULL) { if (stop == NULL) {
istart = 0; istart = 0;
istop = PyLong_AsLong(start); istop = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
istep = 1; istep = 1;
} else if (step == NULL) { } else if (step == NULL) {
istart = PyLong_AsLong(start); istart = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istart == -1) && PyErr_Occurred())
throwCAPIException();
istop = PyLong_AsLong(stop); istop = PyLong_AsLong(stop);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
istep = 1; istep = 1;
} else { } else {
istart = PyLong_AsLong(start); istart = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istart == -1) && PyErr_Occurred())
throwCAPIException();
istop = PyLong_AsLong(stop); istop = PyLong_AsLong(stop);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
istep = PyLong_AsLong(step); istep = PyLong_AsLong(step);
checkAndThrowCAPIException(); if ((istep == -1) && PyErr_Occurred())
throwCAPIException();
} }
BoxedList* rtn = new BoxedList(); BoxedList* rtn = new BoxedList();
...@@ -470,7 +476,7 @@ Box* isinstance_func(Box* obj, Box* cls) { ...@@ -470,7 +476,7 @@ Box* isinstance_func(Box* obj, Box* cls) {
Box* issubclass_func(Box* child, Box* parent) { Box* issubclass_func(Box* child, Box* parent) {
int rtn = PyObject_IsSubclass(child, parent); int rtn = PyObject_IsSubclass(child, parent);
if (rtn < 0) if (rtn < 0)
checkAndThrowCAPIException(); throwCAPIException();
return boxBool(rtn); return boxBool(rtn);
} }
...@@ -479,7 +485,6 @@ Box* intern_func(Box* str) { ...@@ -479,7 +485,6 @@ Box* intern_func(Box* str) {
raiseExcHelper(TypeError, "can't intern subclass of string"); raiseExcHelper(TypeError, "can't intern subclass of string");
Py_INCREF(str); Py_INCREF(str);
PyString_InternInPlace(&str); PyString_InternInPlace(&str);
checkAndThrowCAPIException();
return str; return str;
} }
...@@ -1797,7 +1802,8 @@ Box* builtinApply(Box* func, Box* _args, Box* keywords) { ...@@ -1797,7 +1802,8 @@ Box* builtinApply(Box* func, Box* _args, Box* keywords) {
if (!PySequence_Check(_args)) if (!PySequence_Check(_args))
raiseExcHelper(TypeError, "apply() arg 2 expected sequence, found %s", getTypeName(_args)); raiseExcHelper(TypeError, "apply() arg 2 expected sequence, found %s", getTypeName(_args));
args = PySequence_Tuple(_args); args = PySequence_Tuple(_args);
checkAndThrowCAPIException(); if (!args)
throwCAPIException();
} else { } else {
args = incref(_args); args = incref(_args);
} }
......
...@@ -154,13 +154,16 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) { ...@@ -154,13 +154,16 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) {
if (stop == NULL) { if (stop == NULL) {
i64 istop = PyLong_AsLong(start); i64 istop = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
return new BoxedXrange(0, istop, 1); return new BoxedXrange(0, istop, 1);
} else if (step == NULL) { } else if (step == NULL) {
i64 istart = PyLong_AsLong(start); i64 istart = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istart == -1) && PyErr_Occurred())
throwCAPIException();
i64 istop = PyLong_AsLong(stop); i64 istop = PyLong_AsLong(stop);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
i64 n = BoxedXrange::get_len_of_range(istart, istop, 1); i64 n = BoxedXrange::get_len_of_range(istart, istop, 1);
if (n > (unsigned long)LONG_MAX || (long)n > PY_SSIZE_T_MAX) { if (n > (unsigned long)LONG_MAX || (long)n > PY_SSIZE_T_MAX) {
raiseExcHelper(OverflowError, "xrange() result has too many items"); raiseExcHelper(OverflowError, "xrange() result has too many items");
...@@ -168,11 +171,14 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) { ...@@ -168,11 +171,14 @@ Box* xrange(Box* cls, Box* start, Box* stop, Box** args) {
return new BoxedXrange(istart, istop, 1); return new BoxedXrange(istart, istop, 1);
} else { } else {
i64 istart = PyLong_AsLong(start); i64 istart = PyLong_AsLong(start);
checkAndThrowCAPIException(); if ((istart == -1) && PyErr_Occurred())
throwCAPIException();
i64 istop = PyLong_AsLong(stop); i64 istop = PyLong_AsLong(stop);
checkAndThrowCAPIException(); if ((istop == -1) && PyErr_Occurred())
throwCAPIException();
i64 istep = PyLong_AsLong(step); i64 istep = PyLong_AsLong(step);
checkAndThrowCAPIException(); if ((istep == -1) && PyErr_Occurred())
throwCAPIException();
if (istep == 0) if (istep == 0)
raiseExcHelper(ValueError, "xrange() arg 3 must not be zero"); raiseExcHelper(ValueError, "xrange() arg 3 must not be zero");
unsigned long n = BoxedXrange::get_len_of_range(istart, istop, istep); unsigned long n = BoxedXrange::get_len_of_range(istart, istop, istep);
......
...@@ -57,7 +57,8 @@ public: ...@@ -57,7 +57,8 @@ public:
if (next) { if (next) {
value = next; value = next;
} else { } else {
checkAndThrowCAPIException(); if (PyErr_Occurred())
throwCAPIException();
Py_CLEAR(iterator); Py_CLEAR(iterator);
*this = *end(); *this = *end();
} }
......
...@@ -1500,8 +1500,8 @@ void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rew ...@@ -1500,8 +1500,8 @@ void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rew
Box* d = attrs->attr_list->attrs[0]; Box* d = attrs->attr_list->attrs[0];
assert(d); assert(d);
assert(attr->data()[attr->size()] == '\0'); assert(attr->data()[attr->size()] == '\0');
PyDict_SetItem(d, attr, val); if (PyDict_SetItem(d, attr, val) < 0)
checkAndThrowCAPIException(); throwCAPIException();
return; return;
} }
...@@ -2983,9 +2983,10 @@ bool dataDescriptorSetSpecialCases(Box* obj, STOLEN(Box*) val, Box* descr, Setat ...@@ -2983,9 +2983,10 @@ bool dataDescriptorSetSpecialCases(Box* obj, STOLEN(Box*) val, Box* descr, Setat
member_def.type = member_desc->type; member_def.type = member_desc->type;
if (member_desc->readonly) if (member_desc->readonly)
member_def.flags |= READONLY; member_def.flags |= READONLY;
PyMember_SetOne((char*)obj, &member_def, val); int ret = PyMember_SetOne((char*)obj, &member_def, val);
Py_DECREF(val); Py_DECREF(val);
checkAndThrowCAPIException(); if (ret < 0)
throwCAPIException();
return true; return true;
} }
...@@ -6558,8 +6559,8 @@ void Box::delattr(BoxedString* attr, DelattrRewriteArgs* rewrite_args) { ...@@ -6558,8 +6559,8 @@ void Box::delattr(BoxedString* attr, DelattrRewriteArgs* rewrite_args) {
Box* d = attrs->attr_list->attrs[0]; Box* d = attrs->attr_list->attrs[0];
assert(d); assert(d);
assert(attr->data()[attr->size()] == '\0'); assert(attr->data()[attr->size()] == '\0');
PyDict_DelItem(d, attr); if (PyDict_DelItem(d, attr) < 0)
checkAndThrowCAPIException(); throwCAPIException();
return; return;
} }
...@@ -6834,7 +6835,8 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD ...@@ -6834,7 +6835,8 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
} }
BoxedClass* base = best_base(bases); BoxedClass* base = best_base(bases);
checkAndThrowCAPIException(); if (!base)
throwCAPIException();
assert(base); assert(base);
if (!PyType_HasFeature(base, Py_TPFLAGS_BASETYPE)) if (!PyType_HasFeature(base, Py_TPFLAGS_BASETYPE))
raiseExcHelper(TypeError, "type '%.100s' is not an acceptable base type", base->tp_name); raiseExcHelper(TypeError, "type '%.100s' is not an acceptable base type", base->tp_name);
......
...@@ -2306,7 +2306,8 @@ Box* strDecode(BoxedString* self, Box* encoding, Box* error) { ...@@ -2306,7 +2306,8 @@ Box* strDecode(BoxedString* self, Box* encoding, Box* error) {
Box* result = PyString_AsDecodedObject(self, encoding_str ? encoding_str->data() : NULL, Box* result = PyString_AsDecodedObject(self, encoding_str ? encoding_str->data() : NULL,
error_str ? error_str->data() : NULL); error_str ? error_str->data() : NULL);
checkAndThrowCAPIException(); if (!result)
throwCAPIException();
return result; return result;
} }
...@@ -2331,7 +2332,8 @@ Box* strEncode(BoxedString* self, Box* encoding, Box* error) { ...@@ -2331,7 +2332,8 @@ Box* strEncode(BoxedString* self, Box* encoding, Box* error) {
Box* result = PyString_AsEncodedObject(self, encoding_str ? encoding_str->data() : PyUnicode_GetDefaultEncoding(), Box* result = PyString_AsEncodedObject(self, encoding_str ? encoding_str->data() : PyUnicode_GetDefaultEncoding(),
error_str ? error_str->data() : NULL); error_str ? error_str->data() : NULL);
checkAndThrowCAPIException(); if (!result)
throwCAPIException();
return result; return result;
} }
......
...@@ -268,7 +268,8 @@ BoxedString* Box::reprICAsString() { ...@@ -268,7 +268,8 @@ BoxedString* Box::reprICAsString() {
if (isSubclass(r->cls, unicode_cls)) { if (isSubclass(r->cls, unicode_cls)) {
r = PyUnicode_AsASCIIString(autoDecref(r)); r = PyUnicode_AsASCIIString(autoDecref(r));
checkAndThrowCAPIException(); if (!r)
throwCAPIException();
} }
if (r->cls != str_cls) { if (r->cls != str_cls) {
Py_DECREF(r); Py_DECREF(r);
...@@ -2115,7 +2116,8 @@ static PyObject* type_subclasses(PyTypeObject* type, PyObject* args_ignored) noe ...@@ -2115,7 +2116,8 @@ static PyObject* type_subclasses(PyTypeObject* type, PyObject* args_ignored) noe
Box* typeSubclasses(BoxedClass* self) { Box* typeSubclasses(BoxedClass* self) {
assert(PyType_Check(self)); assert(PyType_Check(self));
Box* rtn = type_subclasses(self, 0); Box* rtn = type_subclasses(self, 0);
checkAndThrowCAPIException(); if (!rtn)
throwCAPIException();
return rtn; return rtn;
} }
......
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