Commit b21fad57 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1246 from aisk/test_list

make more list unit test pass
parents eb8815b4 4f48bbe9
......@@ -727,6 +727,11 @@ Box* listMul(BoxedList* self, Box* rhs) {
return incref(NotImplemented);
}
if (n > 0 && Py_SIZE(self) > PY_SSIZE_T_MAX / n) {
PyErr_NoMemory();
throwCAPIException();
}
int s = self->size;
BoxedList* rtn = new BoxedList();
......@@ -755,6 +760,11 @@ Box* listImul(BoxedList* self, Box* rhs) {
return incref(NotImplemented);
}
if (n > 0 && Py_SIZE(self) > PY_SSIZE_T_MAX / n) {
PyErr_NoMemory();
throwCAPIException();
}
int s = self->size;
self->ensure(n * s);
......@@ -1129,7 +1139,7 @@ Box* listIndex(BoxedList* self, Box* elt, Box* _start, Box** args) {
}
stop = std::min(stop, self->size);
for (int64_t i = start; i < stop; i++) {
for (int64_t i = start; i < stop && i < self->size; i++) {
Box* e = self->elts->elts[i];
int r = PyObject_RichCompareBool(e, elt, Py_EQ);
......@@ -1171,6 +1181,8 @@ BoxedClass* list_reverse_iterator_cls = NULL;
Box* listInit(BoxedList* self, Box* container) {
assert(PyList_Check(self));
BoxedList::clear(self);
if (container) {
Box* r = listIAdd(self, container);
Py_DECREF(r);
......
import sys
l = range(5)
print l
print l * 5
......@@ -68,7 +70,7 @@ for i in xrange(1, 6):
print list_index.index(i, -1, -1)
except ValueError as e:
print e
assert list_index.index(3) == 2
assert [1, '2'].index('2') == 1
......@@ -244,3 +246,36 @@ try:
print range(5).index(10, 100, 200)
except Exception as e:
print e
lst = [4, 5, 6, 7]
n = int((sys.maxsize * 2 + 2) // len(lst))
try:
lst * n
except MemoryError as e:
print e
else:
raise RuntimeError('MemoryError not raised')
try:
lst *= n
except MemoryError as e:
print e
l = [1, 2, 3]
l.__init__()
print l
class EvilCmp:
def __init__(self, victim):
self.victim = victim
def __eq__(self, other):
del self.victim[:]
return False
a = []
a[:] = [EvilCmp(a) for _ in xrange(100)]
try:
a.index(None)
except ValueError 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