bad_iter = map(int, "X")
self.assertRaises(ValueError, array.extend, bad_iter)
+ def test_bytearray_join_with_misbehaving_iterator(self):
+ # Issue #112625
+ array = bytearray(b',')
+ def iterator():
+ array.clear()
+ yield b'A'
+ yield b'B'
+ self.assertRaises(BufferError, array.join, iterator())
+
+ def test_bytearray_join_with_custom_iterator(self):
+ # Issue #112625
+ array = bytearray(b',')
+ def iterator():
+ yield b'A'
+ yield b'B'
+ self.assertEqual(bytearray(b'A,B'), array.join(iterator()))
+
def test_construct_singletons(self):
for const in None, Ellipsis, NotImplemented:
tp = type(const)
bytearray_join(PyByteArrayObject *self, PyObject *iterable_of_bytes)
/*[clinic end generated code: output=a8516370bf68ae08 input=aba6b1f9b30fcb8e]*/
{
- return stringlib_bytes_join((PyObject*)self, iterable_of_bytes);
+ self->ob_exports++; // this protects `self` from being cleared/resized if `iterable_of_bytes` is a custom iterator
+ PyObject* ret = stringlib_bytes_join((PyObject*)self, iterable_of_bytes);
+ self->ob_exports--; // unexport `self`
+ return ret;
}
/*[clinic input]