[issue46900] marshal.dumps represents the same list object differently
Raymond Hettinger
report at bugs.python.org
Wed Mar 2 10:47:07 EST 2022
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
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
----------
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46900>
_______________________________________
More information about the Python-bugs-list
mailing list