From f968b70fb9b6034208487d550c926a4c94f6319e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Mon, 11 May 2015 17:27:43 +0200 Subject: [PATCH] Multisets: Improved handling of unorderable values. Fixes [bug 7494]. It's not a good idea to pretend that values that don't have an order relation do... Fixes a bug that was introduced ~4 years ago. --- src/multiset.c | 2 -- src/testsuite.in | 13 ++++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/multiset.c b/src/multiset.c index bc70ad1571..5ac958851f 100644 --- a/src/multiset.c +++ b/src/multiset.c @@ -2834,7 +2834,6 @@ PMOD_EXPORT struct multiset *merge_multisets (struct multiset *a, { INTERNAL_CMP (&a_ind, &b_ind, cmp_res); - if (cmp_res == CMPFUN_UNORDERED) cmp_res = 0; }, { /* Copy m.a_node. */ @@ -2882,7 +2881,6 @@ PMOD_EXPORT struct multiset *merge_multisets (struct multiset *a, { INTERNAL_CMP (&a_ind, &b_ind, cmp_res); - if (cmp_res == CMPFUN_UNORDERED) cmp_res = 0; }, { /* Copy m.a_node. */ diff --git a/src/testsuite.in b/src/testsuite.in index 4e69fc128f..436f25f621 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -5650,8 +5650,19 @@ test_any_equal([[ ]], [[({4, 4, 5})]]) test_do(add_constant("cnt");) - test_eq([[sizeof(mtest_m2)]],sizeof(mtest_i2)) + +test_any([[ + // Test subtraction of multisets of objects. + class X(int a) + { + protected int `<(mixed o) { return objectp(o) && (a < o->a); } + protected int `==(mixed o) { return objectp(o) && (a == o->a); } + }; + multiset m = (< @map(allocate(5), X) >); + return sizeof(m - (<0>)); +]], 5) + test_any([[int e;multiset q=(<>),p=(<>); for(e=0;e<1000;e++) { p[reverse(e)]=1; q+=(<reverse(e)>); if(!equal(sort(indices(p)),sort(indices(q)))) return 0; } return 1;]],1) test_equal(sort(indices(mtest_m|mtest_m2)),sort(mtest_i|mtest_i2)) -- GitLab