Commit 9dc1ae0
authored
OrderedDict.copy() walks the internal linked list while building the new
dict. The loop body can run arbitrary Python (a key's __eq__/__hash__, or
a subclass __getitem__/__setitem__) which can clear the source dict and
free the nodes being iterated.
Detect this the same way OrderedDict.__eq__ already does (gh-119004):
snapshot od_state before the loop, hold a strong reference to the key and
read the hash before any reentrant call, and raise RuntimeError if the
state changed before advancing to the next node.
(cherry picked from commit 7d128e3)
1 parent e041cdc commit 9dc1ae0
3 files changed
Lines changed: 62 additions & 10 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
877 | 910 | | |
878 | 911 | | |
879 | 912 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1224 | 1224 | | |
1225 | 1225 | | |
1226 | 1226 | | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
1227 | 1231 | | |
1228 | 1232 | | |
1229 | | - | |
1230 | | - | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
1231 | 1236 | | |
1232 | 1237 | | |
1233 | 1238 | | |
| 1239 | + | |
1234 | 1240 | | |
1235 | 1241 | | |
1236 | | - | |
1237 | | - | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
1238 | 1246 | | |
| 1247 | + | |
| 1248 | + | |
1239 | 1249 | | |
1240 | 1250 | | |
1241 | 1251 | | |
1242 | 1252 | | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1247 | 1257 | | |
1248 | | - | |
1249 | | - | |
| 1258 | + | |
| 1259 | + | |
1250 | 1260 | | |
| 1261 | + | |
1251 | 1262 | | |
1252 | 1263 | | |
| 1264 | + | |
| 1265 | + | |
1253 | 1266 | | |
1254 | 1267 | | |
1255 | 1268 | | |
1256 | 1269 | | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
1257 | 1273 | | |
1258 | 1274 | | |
1259 | 1275 | | |
| |||
0 commit comments