Commit 8b483912 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix a bug in list.__index__

I think this exists on master as well.
parent cf179f85
...@@ -585,9 +585,9 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -585,9 +585,9 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
_str = coerceUnicodeToStr<S>(_str); _str = coerceUnicodeToStr<S>(_str);
if (S == CAPI && !_str) if (S == CAPI && !_str)
return NULL; return NULL;
AUTO_DECREF(_str);
if (!PyString_Check(_str)) { if (!PyString_Check(_str)) {
Py_DECREF(_str);
if (S == CAPI) { if (S == CAPI) {
PyErr_SetString(TypeError, "getattr(): attribute name must be string"); PyErr_SetString(TypeError, "getattr(): attribute name must be string");
return NULL; return NULL;
...@@ -598,6 +598,7 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -598,6 +598,7 @@ Box* getattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
if (!PyString_CHECK_INTERNED(str)) if (!PyString_CHECK_INTERNED(str))
internStringMortalInplace(str); internStringMortalInplace(str);
AUTO_DECREF(str);
Box* rtn; Box* rtn;
RewriterVar* r_rtn; RewriterVar* r_rtn;
...@@ -717,9 +718,9 @@ Box* hasattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -717,9 +718,9 @@ Box* hasattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
_str = coerceUnicodeToStr<S>(_str); _str = coerceUnicodeToStr<S>(_str);
if (S == CAPI && !_str) if (S == CAPI && !_str)
return NULL; return NULL;
AUTO_DECREF(_str);
if (!PyString_Check(_str)) { if (!PyString_Check(_str)) {
Py_DECREF(_str);
if (S == CAPI) { if (S == CAPI) {
PyErr_SetString(TypeError, "hasattr(): attribute name must be string"); PyErr_SetString(TypeError, "hasattr(): attribute name must be string");
return NULL; return NULL;
...@@ -729,7 +730,6 @@ Box* hasattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ...@@ -729,7 +730,6 @@ Box* hasattrFuncInternal(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args,
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
Py_INCREF(str);
if (!PyString_CHECK_INTERNED(str)) if (!PyString_CHECK_INTERNED(str))
internStringMortalInplace(str); internStringMortalInplace(str);
AUTO_DECREF(str); AUTO_DECREF(str);
......
...@@ -1105,6 +1105,7 @@ Box* listIndex(BoxedList* self, Box* elt, Box* _start, Box** args) { ...@@ -1105,6 +1105,7 @@ Box* listIndex(BoxedList* self, Box* elt, Box* _start, Box** args) {
if (stop < 0) if (stop < 0)
stop = 0; stop = 0;
} }
stop = std::min(stop, self->size);
for (int64_t i = start; i < stop; i++) { for (int64_t i = start; i < stop; i++) {
Box* e = self->elts->elts[i]; Box* e = self->elts->elts[i];
......
# expected: reffail
l = range(5) l = range(5)
print l print l
print l * 5 print l * 5
...@@ -237,4 +236,11 @@ try: ...@@ -237,4 +236,11 @@ try:
except TypeError as e: except TypeError as e:
print(type(e)) print(type(e))
print range(5).index(10, 100L, 200L) try:
print range(5).index(10, 100L, 200L)
except Exception as e:
print e
try:
print range(5).index(10, 100, 200)
except Exception as e:
print e
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