From ccf62abac7be516e2947f5badb6bc86021159772 Mon Sep 17 00:00:00 2001 From: Daniel Holth Date: Mon, 20 Jun 2016 19:40:16 -0400 Subject: centralize the preferred pickle protocol; use highest protocol. --- src/engine/SCons/SConsign.py | 6 ++++-- src/engine/SCons/Tool/msvs.py | 15 ++++++++------- src/engine/SCons/compat/__init__.py | 5 +++++ src/engine/SCons/dblite.py | 4 +++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/engine/SCons/SConsign.py b/src/engine/SCons/SConsign.py index cb089aa..3a5e5c0 100644 --- a/src/engine/SCons/SConsign.py +++ b/src/engine/SCons/SConsign.py @@ -39,6 +39,8 @@ import pickle import SCons.dblite import SCons.Warnings +from SCons.compat import PICKLE_PROTOCOL + def corrupt_dblite_warning(filename): SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning, "Ignoring corrupt .sconsign file: %s"%filename) @@ -272,7 +274,7 @@ class DB(Base): path = normcase(self.dir.get_internal_path()) for key, entry in self.entries.items(): entry.convert_to_sconsign() - db[path] = pickle.dumps(self.entries, 1) + db[path] = pickle.dumps(self.entries, PICKLE_PROTOCOL) if sync: try: @@ -360,7 +362,7 @@ class DirFile(Dir): return for key, entry in self.entries.items(): entry.convert_to_sconsign() - pickle.dump(self.entries, file, 1) + pickle.dump(self.entries, file, PICKLE_PROTOCOL) file.close() if fname != self.sconsign: try: diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py index 6df4928..02b9a34 100644 --- a/src/engine/SCons/Tool/msvs.py +++ b/src/engine/SCons/Tool/msvs.py @@ -54,6 +54,7 @@ import SCons.Warnings from .MSCommon import msvc_exists, msvc_setup_env_once from SCons.Defaults import processDefines +from SCons.compat import PICKLE_PROTOCOL ############################################################################## # Below here are the classes and functions for generation of @@ -641,10 +642,10 @@ class _GenerateV6DSP(_DSPGenerator): if self.nokeep == 0: # now we pickle some data and add it to the file -- MSDEV will ignore it. - pdata = pickle.dumps(self.configs,1) + pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') - pdata = pickle.dumps(self.sources,1) + pdata = pickle.dumps(self.sources,PICKLE_PROTOCOL) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') @@ -913,10 +914,10 @@ class _GenerateV7DSP(_DSPGenerator, _GenerateV7User): if self.nokeep == 0: # now we pickle some data and add it to the file -- MSDEV will ignore it. - pdata = pickle.dumps(self.configs,1) + pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL) pdata = base64.encodestring(pdata) self.file.write('\n') @@ -1232,10 +1233,10 @@ class _GenerateV10DSP(_DSPGenerator, _GenerateV10User): if self.nokeep == 0: # now we pickle some data and add it to the file -- MSDEV will ignore it. - pdata = pickle.dumps(self.configs,1) + pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL) pdata = base64.encodestring(pdata) self.file.write('\n') @@ -1606,7 +1607,7 @@ class _GenerateV7DSW(_DSWGenerator): '\tEndGlobalSection\n') self.file.write('EndGlobal\n') if self.nokeep == 0: - pdata = pickle.dumps(self.configs,1) + pdata = pickle.dumps(self.configs,PICKLE_PROTOCOL) pdata = base64.encodestring(pdata) self.file.write(pdata + '\n') diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index 6f20b73..9a911f7 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -88,6 +88,11 @@ def rename_module(new, old): # In 3.x, 'pickle' automatically loads the fast version if available. rename_module('pickle', 'cPickle') +# Default pickle protocol. Higher protocols are more efficient/featureful +# but incompatible with older Python versions. On Python 2.7 this is 2. +# Negative numbers choose the highest available protocol. +PICKLE_PROTOCOL=-1 + # TODO: FIXME # In 3.x, 'profile' automatically loads the fast version if available. rename_module('profile', 'cProfile') diff --git a/src/engine/SCons/dblite.py b/src/engine/SCons/dblite.py index b12d320..c32f494 100644 --- a/src/engine/SCons/dblite.py +++ b/src/engine/SCons/dblite.py @@ -4,6 +4,8 @@ from __future__ import print_function import SCons.compat +from SCons.compat import PICKLE_PROTOCOL + import os import pickle import shutil @@ -119,7 +121,7 @@ class dblite(object): def sync(self): self._check_writable() f = self._open(self._tmp_name, "wb", self._mode) - self._pickle_dump(self._dict, f, 1) + self._pickle_dump(self._dict, f, PICKLE_PROTOCOL) f.close() # Windows doesn't allow renaming if the file exists, so unlink # it first, chmod'ing it to make sure we can do so. On UNIX, we -- cgit v0.12 From b10a8e66e04ed191b27c8d7d33040deabe255714 Mon Sep 17 00:00:00 2001 From: Daniel Holth Date: Tue, 21 Jun 2016 01:06:22 +0000 Subject: CHANGES.txt edited --- src/CHANGES.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index db52cf0..4cf2100 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -15,7 +15,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER metaclass on PyPy); wrap most-used open() calls in 'with' statements to avoid too many open files. - Add __main__.py for `python -m SCons` in case it is on PYTHONPATH. - +  - Always use highest available pickle protocol for efficiency. + From Paweł Tomulik: - Fixed the issue with LDMODULEVERSIONFLAGS reported by Tim Jennes (https://pairlist4.pair.net/pipermail/scons-users/2016-May/004893.html). -- cgit v0.12 From d8f891005dc3edc527e62fd06fa92feab94db61d Mon Sep 17 00:00:00 2001 From: Daniel Holth Date: Tue, 21 Jun 2016 12:24:43 +0000 Subject: use pickle.HIGHEST_PROTOCOL instead of -1 --- src/engine/SCons/compat/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index 9a911f7..c6c7214 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -91,7 +91,8 @@ rename_module('pickle', 'cPickle') # Default pickle protocol. Higher protocols are more efficient/featureful # but incompatible with older Python versions. On Python 2.7 this is 2. # Negative numbers choose the highest available protocol. -PICKLE_PROTOCOL=-1 +import pickle +PICKLE_PROTOCOL=pickle.HIGHEST_PROTOCOL # TODO: FIXME # In 3.x, 'profile' automatically loads the fast version if available. -- cgit v0.12