(self)
| 594 | 0) # Write buffer is cleared after every dump(). |
| 595 | |
| 596 | def test_unpickler(self): |
| 597 | basesize = support.calcobjsize('2P2n2P 2P2n2i5P 2P3n8P2n3i') |
| 598 | unpickler = _pickle.Unpickler |
| 599 | P = struct.calcsize('P') # Size of memo table entry. |
| 600 | n = struct.calcsize('n') # Size of mark table entry. |
| 601 | check = self.check_sizeof |
| 602 | for encoding in 'ASCII', 'UTF-16', 'latin-1': |
| 603 | for errors in 'strict', 'replace': |
| 604 | u = unpickler(io.BytesIO(), |
| 605 | encoding=encoding, errors=errors) |
| 606 | self.assertEqual(object.__sizeof__(u), basesize) |
| 607 | check(u, basesize + |
| 608 | 32 * P + # Minimal memo table size. |
| 609 | len(encoding) + 1 + len(errors) + 1) |
| 610 | |
| 611 | stdsize = basesize + len('ASCII') + 1 + len('strict') + 1 |
| 612 | def check_unpickler(data, memo_size, marks_size): |
| 613 | dump = pickle.dumps(data) |
| 614 | u = unpickler(io.BytesIO(dump), |
| 615 | encoding='ASCII', errors='strict') |
| 616 | u.load() |
| 617 | check(u, stdsize + memo_size * P + marks_size * n) |
| 618 | |
| 619 | check_unpickler(0, 32, 0) |
| 620 | # 20 is minimal non-empty mark stack size. |
| 621 | check_unpickler([0] * 100, 32, 20) |
| 622 | # 128 is memo table size required to save references to 100 objects. |
| 623 | check_unpickler([chr(i) for i in range(100)], 128, 20) |
| 624 | def recurse(deep): |
| 625 | data = 0 |
| 626 | for i in range(deep): |
| 627 | data = [data, data] |
| 628 | return data |
| 629 | check_unpickler(recurse(0), 32, 0) |
| 630 | check_unpickler(recurse(1), 32, 20) |
| 631 | check_unpickler(recurse(20), 32, 20) |
| 632 | check_unpickler(recurse(50), 64, 60) |
| 633 | if not (support.is_wasi and support.Py_DEBUG): |
| 634 | # stack depth too shallow in pydebug WASI. |
| 635 | check_unpickler(recurse(100), 128, 140) |
| 636 | |
| 637 | u = unpickler(io.BytesIO(pickle.dumps('a', 0)), |
| 638 | encoding='ASCII', errors='strict') |
| 639 | u.load() |
| 640 | check(u, stdsize + 32 * P + 2 + 1) |
| 641 | |
| 642 | |
| 643 | ALT_IMPORT_MAPPING = { |
nothing calls this directly
no test coverage detected