Browse Source

Use marshal instead of Pickle for the MvS

Yentl Van Tendeloo 3 years ago
parent
commit
4f9b277bec
1 changed files with 3 additions and 6 deletions
  1. 3 6
      state/modelverse_state/main.py

+ 3 - 6
state/modelverse_state/main.py

@@ -3,16 +3,13 @@ from collections import defaultdict
 import os
 import gzip
 import time
-
-
+import marshal
 
 # Work around Python 2 where a 'big integer' automatically becomes a long
 if sys.version > '3': # pragma: no cover
-    import pickle as pickle
     integer_types = (int,)
     primitive_types = (int, float, str, bool)
 else: # pragma: no cover
-    import cPickle as pickle
     integer_types = (int, long)
     primitive_types = (int, long, float, str, bool, unicode)
 complex_primitives = frozenset(["if", "while", "assign", "call", "break", "continue", "return","resolve","access", "constant", "input", "output", "declare", "global", "none"])
@@ -60,7 +57,7 @@ class ModelverseState(object):
         try:
             if os.path.getmtime(picklefile) > os.path.getmtime(filename):
                 # Pickle is more recent than bootstrap file, so we can use it
-                self.root, self.free_id, self.nodes, self.edges, self.values, self.cache, self.cache_node = pickle.load(open(picklefile, 'rb'))
+                self.root, self.free_id, self.nodes, self.edges, self.values, self.cache, self.cache_node = marshal.load(open(picklefile, 'rb'))
                 for name in self.edges:
                     source, destination = self.edges[name]
                     self.outgoing.setdefault(source, set()).add(name)
@@ -123,7 +120,7 @@ class ModelverseState(object):
 
             # Creation successful, now also create a pickle
             with open(picklefile, 'wb') as f:
-                pickle.dump((symbols["root"], self.free_id, self.nodes, self.edges, self.values, self.cache, self.cache_node), f, pickle.HIGHEST_PROTOCOL)
+                marshal.dump((symbols["root"], self.free_id, self.nodes, self.edges, self.values, self.cache, self.cache_node), f)
 
             return symbols["root"]