diff options
-rw-r--r-- | dist/s_string.ok | 2 | ||||
-rw-r--r-- | examples/c/ex_all.c | 2 | ||||
-rw-r--r-- | examples/java/com/wiredtiger/examples/ex_all.java | 6 | ||||
-rw-r--r-- | lang/python/wiredtiger.i | 9 | ||||
-rw-r--r-- | src/btree/bt_cursor.c | 12 | ||||
-rw-r--r-- | src/cursor/cur_file.c | 4 | ||||
-rw-r--r-- | src/cursor/cur_std.c | 5 | ||||
-rw-r--r-- | src/include/extern.h | 4 | ||||
-rw-r--r-- | src/include/wiredtiger.in | 6 | ||||
-rw-r--r-- | test/suite/test_cursor_compare.py | 16 |
10 files changed, 29 insertions, 37 deletions
diff --git a/dist/s_string.ok b/dist/s_string.ok index 956b4061c62..6c658df8bf0 100644 --- a/dist/s_string.ok +++ b/dist/s_string.ok @@ -581,7 +581,7 @@ enum's env eof eop -equalityp +equalp errhandler errno errv diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c index 532a4bca66c..108cca583a8 100644 --- a/examples/c/ex_all.c +++ b/examples/c/ex_all.c @@ -246,7 +246,7 @@ cursor_ops(WT_SESSION *session) /*! [Cursor equality] */ int equal; ret = cursor->equals(cursor, other, &equal); - if (equal == 0) { + if (equal) { /* Cursors reference the same key */ } else { /* Cursors don't reference the same key */ diff --git a/examples/java/com/wiredtiger/examples/ex_all.java b/examples/java/com/wiredtiger/examples/ex_all.java index 2bc412307f1..c0315672ba6 100644 --- a/examples/java/com/wiredtiger/examples/ex_all.java +++ b/examples/java/com/wiredtiger/examples/ex_all.java @@ -217,10 +217,8 @@ public static int cursor_ops(Session session) { Cursor other = null; /*! [Cursor equality] */ - int equal; - equal = cursor.equals(other); - if (equal == 0) { - /* Cursors reference the same key */ + if (cursor.equals(other)) { + /* redtiger.iCursors reference the same key */ } else { /* Cursors don't reference the same key */ } diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i index 1a23bd5ea5e..7963b5b74c9 100644 --- a/lang/python/wiredtiger.i +++ b/lang/python/wiredtiger.i @@ -712,13 +712,8 @@ typedef int int_void; } else { ret = $self->equals($self, other, &cmp); - - /* - * Compare-equal is documented to return 0 and !0, map - * less-than-zero and greater-than-zero to 1 to avoid - * colliding with other errors. - */ - ret = (ret != 0) ? ret : (cmp == 0 ? 0 : 1); + if (ret == 0) + ret = cmp; } return (ret); } diff --git a/src/btree/bt_cursor.c b/src/btree/bt_cursor.c index e3fa169e751..704b258a7dd 100644 --- a/src/btree/bt_cursor.c +++ b/src/btree/bt_cursor.c @@ -875,10 +875,11 @@ __cursor_equals(WT_CURSOR_BTREE *a, WT_CURSOR_BTREE *b) */ int __wt_btcur_equals( - WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *cmpp) + WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *equalp) { WT_CURSOR *a, *b; WT_SESSION_IMPL *session; + int cmp; a = (WT_CURSOR *)a_arg; b = (WT_CURSOR *)b_arg; @@ -893,15 +894,14 @@ __wt_btcur_equals( * The reason for an equals method is because we can avoid doing * a full key comparison in some cases. If both cursors point into the * tree, take the fast path, otherwise fall back to the slower compare - * method; in both cases, return 0 if the cursors are equal, 1 if they + * method; in both cases, return 1 if the cursors are equal, 0 if they * are not. */ if (F_ISSET(a, WT_CURSTD_KEY_INT) && F_ISSET(b, WT_CURSTD_KEY_INT)) - *cmpp = !__cursor_equals(a_arg, b_arg); + *equalp = __cursor_equals(a_arg, b_arg); else { - WT_RET(__wt_btcur_compare(a_arg, b_arg, cmpp)); - if (*cmpp != 0) - *cmpp = 1; + WT_RET(__wt_btcur_compare(a_arg, b_arg, &cmp)); + *equalp = (cmp == 0) ? 1 : 0; } return (0); } diff --git a/src/cursor/cur_file.c b/src/cursor/cur_file.c index 5136ba04243..fd044ff87b6 100644 --- a/src/cursor/cur_file.c +++ b/src/cursor/cur_file.c @@ -68,7 +68,7 @@ err: API_END_RET(session, ret); * WT_CURSOR->equals method for the btree cursor type. */ static int -__curfile_equals(WT_CURSOR *a, WT_CURSOR *b, int *cmpp) +__curfile_equals(WT_CURSOR *a, WT_CURSOR *b, int *equalp) { WT_CURSOR_BTREE *cbt; WT_DECL_RET; @@ -90,7 +90,7 @@ __curfile_equals(WT_CURSOR *a, WT_CURSOR *b, int *cmpp) WT_CURSOR_CHECKKEY(b); ret = __wt_btcur_equals( - (WT_CURSOR_BTREE *)a, (WT_CURSOR_BTREE *)b, cmpp); + (WT_CURSOR_BTREE *)a, (WT_CURSOR_BTREE *)b, equalp); err: API_END_RET(session, ret); } diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c index 0e3f8a7f460..494b54890e5 100644 --- a/src/cursor/cur_std.c +++ b/src/cursor/cur_std.c @@ -506,7 +506,7 @@ __wt_cursor_close(WT_CURSOR *cursor) * WT_CURSOR->equals default implementation. */ int -__wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalityp) +__wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp) { WT_DECL_RET; WT_SESSION_IMPL *session; @@ -516,8 +516,7 @@ __wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalityp) CURSOR_API_CALL(cursor, session, equals, NULL); WT_ERR(cursor->compare(cursor, other, &cmp)); - - *equalityp = (cmp == 0) ? 0 : 1; + *equalp = (cmp == 0) ? 1 : 0; err: API_END(session, ret); return (ret); diff --git a/src/include/extern.h b/src/include/extern.h index 94146e8d0d5..5555fe832ff 100644 --- a/src/include/extern.h +++ b/src/include/extern.h @@ -96,7 +96,7 @@ extern int __wt_btcur_remove(WT_CURSOR_BTREE *cbt); extern int __wt_btcur_update(WT_CURSOR_BTREE *cbt); extern int __wt_btcur_next_random(WT_CURSOR_BTREE *cbt); extern int __wt_btcur_compare(WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *cmpp); -extern int __wt_btcur_equals( WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *cmpp); +extern int __wt_btcur_equals( WT_CURSOR_BTREE *a_arg, WT_CURSOR_BTREE *b_arg, int *equalp); extern int __wt_btcur_range_truncate(WT_CURSOR_BTREE *start, WT_CURSOR_BTREE *stop); extern int __wt_btcur_close(WT_CURSOR_BTREE *cbt); extern int __wt_debug_set_verbose(WT_SESSION_IMPL *session, const char *v); @@ -281,7 +281,7 @@ extern int __wt_cursor_get_valuev(WT_CURSOR *cursor, va_list ap); extern void __wt_cursor_set_value(WT_CURSOR *cursor, ...); extern void __wt_cursor_set_valuev(WT_CURSOR *cursor, va_list ap); extern int __wt_cursor_close(WT_CURSOR *cursor); -extern int __wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalityp); +extern int __wt_cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp); extern int __wt_cursor_dup_position(WT_CURSOR *to_dup, WT_CURSOR *cursor); extern int __wt_cursor_init(WT_CURSOR *cursor, const char *uri, WT_CURSOR *owner, const char *cfg[], WT_CURSOR **cursorp); extern int __wt_curtable_get_key(WT_CURSOR *cursor, ...); diff --git a/src/include/wiredtiger.in b/src/include/wiredtiger.in index 8bd1d301990..84b5a81a1f3 100644 --- a/src/include/wiredtiger.in +++ b/src/include/wiredtiger.in @@ -295,11 +295,11 @@ struct __wt_cursor { * * @param cursor the cursor handle * @param other another cursor handle - * @param equalityp the status of the comparison: 0 if the cursors - * refer to the same key, otherwise 1. + * @param[out] equalp the status of the comparison: 1 if the cursors + * refer to the same key, otherwise 0. * @errors */ - int __F(equals)(WT_CURSOR *cursor, WT_CURSOR *other, int *equalityp); + int __F(equals)(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp); /*! * Return the next record. diff --git a/test/suite/test_cursor_compare.py b/test/suite/test_cursor_compare.py index b65bd5181ce..7712997059b 100644 --- a/test/suite/test_cursor_compare.py +++ b/test/suite/test_cursor_compare.py @@ -137,11 +137,11 @@ class test_cursor_comparison(wttest.WiredTigerTestCase): # Test cursors before they're positioned. c1.set_key(key_populate(c1, 10)) c2.set_key(key_populate(c2, 20)) - self.assertNotEqual(c1.equals(c2), 0) - self.assertNotEqual(c2.equals(c1), 0) + self.assertFalse(c1.equals(c2)) + self.assertFalse(c2.equals(c1)) c2.set_key(key_populate(c2, 10)) - self.assertEqual(c1.equals(c2), 0) - self.assertEqual(c2.equals(c1), 0) + self.assertTrue(c1.equals(c2)) + self.assertTrue(c2.equals(c1)) # Confirm failure for different objects. cX = self.session.open_cursor(uriX, None) @@ -156,12 +156,12 @@ class test_cursor_comparison(wttest.WiredTigerTestCase): self.assertEqual(c1.search(), 0) c2.set_key(key_populate(c2, 20)) self.assertEqual(c2.search(), 0) - self.assertNotEqual(c1.equals(c2), 0) - self.assertNotEqual(c2.equals(c1), 0) + self.assertFalse(c1.equals(c2)) + self.assertFalse(c2.equals(c1)) c2.set_key(key_populate(c2, 10)) self.assertEqual(c2.search(), 0) - self.assertEqual(c1.equals(c2), 0) - self.assertEqual(c2.equals(c1), 0) + self.assertTrue(c1.equals(c2)) + self.assertTrue(c2.equals(c1)) # Confirm failure for different objects. cX = self.session.open_cursor(uriX, None) |