Issue 33209: Repeated Pickler.dump() doesn't reset the state in the C implementation of pickle (original) (raw)

test_clear_pickler_memo tested only the default protocol and fails when bump the default protocol to 4. For some reasons C implementation writes FRAME before PROTO when call Pickler.dump() repeatedly.

Python implementation: b'\x80\x04\x95\x13\x00\x00\x00\x00\x00\x00\x00]\x94(\x8c\x07abcdefg\x94h\x01K,e.' 0: \x80 PROTO 4 2: \x95 FRAME 19 11: ] EMPTY_LIST 12: \x94 MEMOIZE (as 0) 13: ( MARK 14: \x8c SHORT_BINUNICODE 'abcdefg' 23: \x94 MEMOIZE (as 1) 24: h BINGET 1 26: K BININT1 44 28: e APPENDS (MARK at 13) 29: . STOP highest protocol among opcodes = 4

C implementation: b'\x95\x15\x00\x00\x00\x00\x00\x00\x00\x80\x04]\x94(\x8c\x07abcdefg\x94h\x01K,e.' 0: \x95 FRAME 21 9: \x80 PROTO 4 11: ] EMPTY_LIST 12: \x94 MEMOIZE (as 0) 13: ( MARK 14: \x8c SHORT_BINUNICODE 'abcdefg' 23: \x94 MEMOIZE (as 1) 24: h BINGET 1 26: K BININT1 44 28: e APPENDS (MARK at 13) 29: . STOP highest protocol among opcodes = 4