Kaydet (Commit) 61154600 authored tarafından Guido van Rossum's avatar Guido van Rossum

Make sure that *any* object whose id() is used as a memo key is kept

alive in the memo.  This fixes SF bug 592567.
üst 547607c4
...@@ -185,6 +185,7 @@ def deepcopy(x, memo = None): ...@@ -185,6 +185,7 @@ def deepcopy(x, memo = None):
else: else:
y = copierfunction(x, memo) y = copierfunction(x, memo)
memo[d] = y memo[d] = y
_keep_alive(x, memo) # Make sure x lives at least as long as d
return y return y
_deepcopy_dispatch = d = {} _deepcopy_dispatch = d = {}
...@@ -269,7 +270,6 @@ def _deepcopy_inst(x, memo): ...@@ -269,7 +270,6 @@ def _deepcopy_inst(x, memo):
return x.__deepcopy__(memo) return x.__deepcopy__(memo)
if hasattr(x, '__getinitargs__'): if hasattr(x, '__getinitargs__'):
args = x.__getinitargs__() args = x.__getinitargs__()
_keep_alive(args, memo)
args = deepcopy(args, memo) args = deepcopy(args, memo)
y = apply(x.__class__, args) y = apply(x.__class__, args)
else: else:
...@@ -278,7 +278,6 @@ def _deepcopy_inst(x, memo): ...@@ -278,7 +278,6 @@ def _deepcopy_inst(x, memo):
memo[id(x)] = y memo[id(x)] = y
if hasattr(x, '__getstate__'): if hasattr(x, '__getstate__'):
state = x.__getstate__() state = x.__getstate__()
_keep_alive(state, memo)
else: else:
state = x.__dict__ state = x.__dict__
state = deepcopy(state, memo) state = deepcopy(state, memo)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment