[New-bugs-announce] [issue13735] The protocol > 0 of cPickle does not given stable dictionary values

Kay Hayen report at bugs.python.org
Sun Jan 8 04:38:30 CET 2012


New submission from Kay Hayen <kayhayen at gmx.de>:

Hello,

I am implementing a Python compiler (Nuitka) that is testing if when it compiles itself, it gives the same output. 

I have been using "protocol = 0" ever since with "pickle" module for historic reasons (gcc bug with raw strings lead me to believe it's better) and lately, I have changed to "protocol = 2" and cPickle. But then I noticed that my compile itself test now fail to give same code from pickling of dictionary constants.

Imanaged and isolated the issue, and it's a Python2.7 regression, Python2.6 is fine:

Observe this output from "cPickle.dumps" for a constant dictionary with one element:

Protocol 0 :
Dumping read const const stream "(dp1\nS'modules'\np2\nNs."
Dumping load const const stream "(dp1\nS'modules'\np2\nNs."
Dumping load const const stream "(dp1\nS'modules'\np2\nNs."
Protocol 1 :
Dumping read const const stream '}q\x01U\x07modulesq\x02Ns.'
Dumping load const const stream '}q\x01U\x07modulesNs.'
Dumping load const const stream '}q\x01U\x07modulesNs.'
Protocol 2 :
Dumping read const const stream '\x80\x02}q\x01U\x07modulesq\x02Ns.'
Dumping load const const stream '\x80\x02}q\x01U\x07modulesNs.'
Dumping load const const stream '\x80\x02}q\x01U\x07modulesNs.'

It seems that cPickle as of CPython2.7 does give a better stream for dictionaries it itself emitted. With CPython2.6 I observe no difference.

My work-around is to "re-stream", "dumps" -> "loads" -> "dumps" with CPython2.7 for the time being.

Can you either: Fix cPickle to treat the dictionaries the same, or enhance to core to produce the same dict as cPickle does? It appears at least some kind of efficiency might be missed out for marshall as well.

----------
components: Interpreter Core, Library (Lib)
files: stream.py
messages: 150841
nosy: kayhayen
priority: normal
severity: normal
status: open
title: The protocol > 0 of cPickle does not given stable dictionary values
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file24170/stream.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13735>
_______________________________________


More information about the New-bugs-announce mailing list