mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
gh-96538: Fix refleak in _bisectmodule.c (gh-96619)
This commit is contained in:
parent
147eb723b2
commit
56d9cf7fc8
2 changed files with 30 additions and 0 deletions
|
|
@ -263,6 +263,34 @@ class TestBisect:
|
||||||
for f in (self.module.insort_left, self.module.insort_right):
|
for f in (self.module.insort_left, self.module.insort_right):
|
||||||
self.assertRaises(TypeError, f, x, y, key = "b")
|
self.assertRaises(TypeError, f, x, y, key = "b")
|
||||||
|
|
||||||
|
def test_lt_returns_non_bool(self):
|
||||||
|
class A:
|
||||||
|
def __init__(self, val):
|
||||||
|
self.val = val
|
||||||
|
def __lt__(self, other):
|
||||||
|
return "nonempty" if self.val < other.val else ""
|
||||||
|
|
||||||
|
data = [A(i) for i in range(100)]
|
||||||
|
i1 = self.module.bisect_left(data, A(33))
|
||||||
|
i2 = self.module.bisect_right(data, A(33))
|
||||||
|
self.assertEqual(i1, 33)
|
||||||
|
self.assertEqual(i2, 34)
|
||||||
|
|
||||||
|
def test_lt_returns_notimplemented(self):
|
||||||
|
class A:
|
||||||
|
def __init__(self, val):
|
||||||
|
self.val = val
|
||||||
|
def __lt__(self, other):
|
||||||
|
return NotImplemented
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.val > other.val
|
||||||
|
|
||||||
|
data = [A(i) for i in range(100)]
|
||||||
|
i1 = self.module.bisect_left(data, A(40))
|
||||||
|
i2 = self.module.bisect_right(data, A(40))
|
||||||
|
self.assertEqual(i1, 40)
|
||||||
|
self.assertEqual(i2, 41)
|
||||||
|
|
||||||
class TestBisectPython(TestBisect, unittest.TestCase):
|
class TestBisectPython(TestBisect, unittest.TestCase):
|
||||||
module = py_bisect
|
module = py_bisect
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res = PyObject_IsTrue(res_obj);
|
res = PyObject_IsTrue(res_obj);
|
||||||
|
Py_DECREF(res_obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -299,6 +300,7 @@ internal_bisect_left(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t h
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res = PyObject_IsTrue(res_obj);
|
res = PyObject_IsTrue(res_obj);
|
||||||
|
Py_DECREF(res_obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue