Issue 1473625: cPickle produces locale-dependent dumps (original) (raw)

Issue1473625

Created on 2006-04-20 15:25 by ivilata, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
locale-dependent-cpickle.txt ivilata,2006-04-20 15:25 Sample session showing locale-dependent cPickle dump.
save_float_pep_331.diff ivilata,2006-04-21 09:42 Fix for save_float() to produce locale-independent dumps.
Messages (5)
msg50085 - (view) Author: Ivan Vilata i Balaguer (ivilata) Date: 2006-04-20 15:25
Dumping a float with cPickle produces a result which is locale-dependent. This causes problems when trying to load the dump under a different locale (the regular pickle module is not affected by this bug). IMHO, the dump should be locale-independent to ensure portability. See the attached file for a sample session log showing the behaviour of both pickle and cPickle under C and ca_ES.UTF-8 locales (Catalan uses a comma to separate the integer and decimal part).
msg50086 - (view) Author: Ivan Vilata i Balaguer (ivilata) Date: 2006-04-20 15:28
Logged In: YES user_id=1064183 As a side note, does this have anything to do with PEP 311? http://www.python.org/dev/peps/pep-0331/
msg50087 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-04-20 21:54
Logged In: YES user_id=21627 Right, cPickle should use C locale floating point numbers, using the PEP 331 API. Would you like to investigate a patch?
msg50088 - (view) Author: Ivan Vilata i Balaguer (ivilata) Date: 2006-04-21 09:42
Logged In: YES user_id=1064183 The problem seems to be in save_float() in the cPickle.c module. It uses PyOS_snprintf() to dump floats, but it is locale-dependent. Fortunately, the PyOS_ascii_formatd() function can be used. The attached patch seems to fix the problem, and pickling tests run OK. It would be nice to see this patch applied to 2.4 also. (BTW, I meant PEP 331 in the previous comment, not 311, sorry.)
msg50089 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-04-30 11:14
Logged In: YES user_id=849994 I applied a similar patch in rev. 45821. Thank you!
History
Date User Action Args
2022-04-11 14:56:16 admin set github: 43256
2006-04-20 15:25:56 ivilata create