mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
bpo-29802: Fix reference counting in module-level struct functions (#1213)
when pass arguments of wrong type.
This commit is contained in:
parent
8f5cdfa9fc
commit
40db90c1ce
4 changed files with 15 additions and 0 deletions
|
@ -599,6 +599,16 @@ class StructTest(unittest.TestCase):
|
|||
'offset -11 out of range for 10-byte buffer'):
|
||||
struct.pack_into('<B', byte_list, -11, 123)
|
||||
|
||||
def test_issue29802(self):
|
||||
# When the second argument of struct.unpack() was of wrong type
|
||||
# the Struct object was decrefed twice and the reference to
|
||||
# deallocated object was left in a cache.
|
||||
with self.assertRaises(TypeError):
|
||||
struct.unpack(b'b', 0)
|
||||
# Shouldn't crash.
|
||||
self.assertEqual(struct.unpack(b'b', b'a'), (b'a'[0],))
|
||||
|
||||
|
||||
class UnpackIteratorTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for iterative unpacking (struct.Struct.iter_unpack).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue