This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bug with deepcopy and new style objects
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, jiba, rhettinger
Priority: normal Keywords:

Created on 2002-08-08 12:42 by jiba, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test2.py jiba, 2002-08-08 12:45
Messages (4)
msg11876 - (view) Author: Jiba (jiba) Date: 2002-08-08 12:42
Deepcopying new style objects can bug if more than one
of such objects are deep copied at the same time (E.g.
you are deepcopying a list of two new style objects).

It seems that , in copy._reconstruct, the "state" 
variable should be "kept alive" (by passing it to the
"_keep_alive" function), since this state may be gc'ed,
and another state may be created later with the same
address memory / ID.

BTW, the same problem may arise with the "args"
variable, in the same function.

The included file demonstrates the bug.
msg11877 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-09 03:43
Logged In: YES 
user_id=80475

Confirmed on 2.2.1 and 2.3a:

Before deepcopying :
[11, 12, 13]
[21, 22, 23]
[31, 32, 33]

After deepcopying :
[11, 12, 13]
[11, 12, 13]
[11, 12, 13]
msg11878 - (view) Author: Jiba (jiba) Date: 2002-08-12 19:03
Logged In: YES 
user_id=591223

I have just submitted a patch for fixing this bug -- the
patch uses an alternative solution to the one i explained
above; i would prefer the patch to the above solution.
msg11879 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-08-12 20:22
Logged In: YES 
user_id=6380

Fixed in CVS, both for Python 2.3 and 2.2.2, using your
proposed patch (with a different comment). Thanks!
History
Date User Action Args
2022-04-10 16:05:34adminsetgithub: 37004
2002-08-08 12:42:12jibacreate