Commit 7244a144 authored by John R. Lenton's avatar John R. Lenton
Browse files

oops, nasty off-by-one in set_copy

parent be790f94
......@@ -27,6 +27,10 @@ static mp_obj_t set_it_iternext(mp_obj_t self_in);
void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
mp_obj_set_t *self = self_in;
if (self->set.used == 0) {
print(env, "set()");
return;
}
bool first = true;
print(env, "{");
for (int i = 0; i < self->set.alloc; i++) {
......@@ -122,7 +126,7 @@ static mp_obj_t set_copy(mp_obj_t self_in) {
mp_obj_set_t *other = m_new_obj(mp_obj_set_t);
other->base.type = &set_type;
mp_set_init(&other->set, self->set.alloc);
mp_set_init(&other->set, self->set.alloc - 1);
other->set.used = self->set.used;
memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t));
......
def r(s):
l = list(s)
l.sort()
print(l)
s = {1, 2}
t = {2, 3}
r(s | t)
r(s ^ t)
r(s & t)
r(s - t)
u = s.copy()
u |= t
r(u)
u = s.copy()
u ^= t
r(u)
u = s.copy()
u &= t
r(u)
u = s.copy()
u -= t
r(u)
return l
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}]
for s in sets:
for t in sets:
print(s, '|', t, '=', r(s | t))
print(s, '^', t, '=', r(s ^ t))
print(s, '&', t, '=', r(s & t))
print(s, '-', t, '=', r(s - t))
u = s.copy()
u |= t
print(s, "|=", t, '-->', r(u))
u = s.copy()
u ^= t
print(s, "^=", t, '-->', r(u))
u = s.copy()
u &= t
print(s, "&=", t, "-->", r(u))
u = s.copy()
u -= t
print(s, "-=", t, "-->", r(u))
print(s == t)
print(s != t)
print(s > t)
print(s >= t)
print(s < t)
print(s <= t)
print(s, '==', t, '=', s == t)
print(s, '!=', t, '=', s != t)
print(s, '>', t, '=', s > t)
print(s, '>=', t, '=', s >= t)
print(s, '<', t, '=', s < t)
print(s, '<=', t, '=', s <= t)
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