Hello,
I've been working with the marshal package and came across this issue (I think) -
Python 3.9.10 Interpreter
(Same output in 3.11.0a5+ (heads/master:b6b711a1aa) on darwin)
>>> import marshal
>>> var_example = [(1,2,3),(4,5,6)]
>>> var_marshaled = marshal.dumps(var_example)
>>> raw_marshaled = marshal.dumps([(1,2,3),(4,5,6)])
>>> def pp(to_print):
>>> [print(byt) for byt in to_print]
>>> pp(var_marshaled)
219
2
0
0
0
41
3
233
1
0
0
0
233
2
0
0
0
233
3
0
0
0
169
3
233
4
0
0
0
233
5
0
0
0
233
6
0
0
0
91
2
0
0
0
41
3
233
1
0
0
0
233
2
0
0
0
233
3
0
0
0
169
3
233
4
0
0
0
233
5
0
0
0
233
6
0
0
0
>>> pp(raw_marshaled)
219
2
0
0
0
169
3
233
1
0
0
0
233
2
0
0
0
233
3
0
0
0
169
3
233
4
0
0
0
233
5
0
0
0
233
6
0
0
0
91
2
0
0
0
169
3
233
1
0
0
0
233
2
0
0
0
233
3
0
0
0
169
3
233
4
0
0
0
233
5
0
0
0
233
6
0
0
0
The difference above lies in the byte representation of the tuple type (41 in the variable version and 169 in the raw version). Is this intended behavior?
|
The difference is the FLAG_REF which is set to 128 (0x80).
>>> import marshal
>>> var_example = [(1,2,3),(4,5,6)]
>>> vm = marshal.dumps(var_example)
>>> rm = marshal.dumps([(1,2,3),(4,5,6)])
>>> [v ^ r for v, r in zip(vm, rm)]
[128, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Whether a flag for possible reuse is generated depends on the reference count of a object.
When passing in the list as variable, the reference count is higher than passing it as a literal.
That flag tells marshal whether to generate an index entry. Whether that occurs re
|