summary refs log tree commit diff
path: root/pkgs/development/python-modules/btrees-py35.patch
blob: 77e47d670b9b38016dc7d9654d903cdd234f2c89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From eee0beef88d135640871050b40844272a3aee790 Mon Sep 17 00:00:00 2001
From: Tres Seaver <tseaver@palladion.com>
Date: Tue, 15 Sep 2015 17:20:18 -0400
Subject: [PATCH 1/2] Ensure that we don't overlook errors in first
 PyObject_RichCompareBool call.

Python 3.5 turns such cases into SystemErrors.

See: https://bugs.python.org/issue23571

Fixes #15.
---
 BTrees/_compat.h | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/BTrees/_compat.h b/BTrees/_compat.h
index e004d54..19dd377 100644
--- a/BTrees/_compat.h
+++ b/BTrees/_compat.h
@@ -27,9 +27,25 @@
 #define TEXT_FROM_STRING PyUnicode_FromString
 #define TEXT_FORMAT PyUnicode_Format
 
-#define COMPARE(lhs, rhs) \
-    PyObject_RichCompareBool((lhs), (rhs), Py_LT) > 0 ? -1 : \
-    (PyObject_RichCompareBool((lhs), (rhs), Py_EQ) > 0 ? 0 : 1)
+/* Emulate Python2's __cmp__,  wrapping PyObject_RichCompareBool(),
+ * Return -2/-3 for errors, -1 for lhs<rhs, 0 for lhs==rhs, 1 for lhs>rhs.
+ */
+static inline
+int __compare(PyObject *lhs, PyObject *rhs) {
+    int less, equal;
+
+    less = PyObject_RichCompareBool(lhs, rhs, Py_LT);
+    if ( less == -1 ) {
+        return -2;
+    }
+    equal = PyObject_RichCompareBool(lhs, rhs, Py_EQ);
+    if ( equal == -1 ) {
+        return -3;
+    }
+    return less ? -1 : (equal ? 0 : 1);
+}
+
+#define COMPARE(lhs, rhs) __compare((lhs), (rhs))
 
 
 #else

From ff4c3309fe471f2b9bdd642b8f7d1c2fe0f5e458 Mon Sep 17 00:00:00 2001
From: Tres Seaver <tseaver@palladion.com>
Date: Sun, 20 Sep 2015 11:07:10 -0400
Subject: [PATCH 2/2] Avoid unnecessary comparison for 'Py_EQ' if 'Py_LT'
 returned True.

---
 BTrees/_compat.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/BTrees/_compat.h b/BTrees/_compat.h
index 19dd377..ece2bf9 100644
--- a/BTrees/_compat.h
+++ b/BTrees/_compat.h
@@ -38,11 +38,14 @@ int __compare(PyObject *lhs, PyObject *rhs) {
     if ( less == -1 ) {
         return -2;
     }
+    if (less) {
+        return -1;
+    }
     equal = PyObject_RichCompareBool(lhs, rhs, Py_EQ);
     if ( equal == -1 ) {
         return -3;
     }
-    return less ? -1 : (equal ? 0 : 1);
+    return equal ? 0 : 1;
 }
 
 #define COMPARE(lhs, rhs) __compare((lhs), (rhs))