-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-142349: Implement PEP 810 - Explicit lazy imports #142351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1c691ea
3b0d745
9eef03c
de281fd
41ab092
058bc6e
6d7c87a
f992ee7
6a91132
03a419a
e0878be
f9880bf
f3f5795
44a3e46
73de8d0
07a633f
20b14d9
164423b
00e7800
781eedb
9be59ec
b179da2
9078f57
f67310c
39c33df
c8c8838
7c49405
5d6026a
c0c0d80
5ff0dd2
214b254
e5e9592
aa85f9d
2799a4d
7d07ae1
c63198c
46b3b75
c5efb20
0c246bc
d9ad012
fe526b4
06b9110
ee77665
a3ddde4
cdec6a6
c3b4807
2e19765
2af21a1
34ea0a5
5166d39
a0a9184
1f6518d
90246cc
824ac88
c075f5b
59110fc
aeda7ac
8d57aca
d8f95f7
b743eb0
e6cb131
0409481
617e9d1
db151a5
ea120fc
973a4fa
266fd4d
441602a
e6633ff
2f642c8
ab07b14
76846fe
0b36549
971d395
0c019fd
8e1b20a
70e5ce7
a39cd25
f70d4df
510c200
d58b0cf
8e4f292
4cd4322
2d3681e
4cc6905
4f675fd
4c3477b
2f7d223
0985e2a
610af78
917b92e
e777866
952ac21
33dc19e
80133a5
b0adc30
470b9e4
41761e5
74b3efe
006ca9c
b5121b0
093f08b
2a514d9
74f35c4
3014816
f96a99c
c4ed3c4
5000033
a0a28c2
023f806
4b352dc
7a0ddfd
6fd8c59
a05b50d
ac80f2d
2d4bdcc
cd1878c
31b7fe9
edf9e75
4fd8fe8
5e4c90a
ca0899c
07c1738
11e5dca
9c6757c
7ef7737
1cc816b
b3060f6
909b69a
7995d56
d95fd85
3a535de
1572241
f2adb04
9bcbe0a
9715124
578dbfd
002276a
9d6c8e8
366ebd2
49712b7
c24d68f
4d1129b
931d1c1
d4196df
b437afb
9fc7da2
29bd6c4
eaf8335
b90e3ea
8639e50
37e8863
b628adf
1f67a54
2abd718
72a7111
b960d3a
9dc236e
05c1f85
4ce061e
99dae60
8fd3f20
aa2f4de
fad3ae2
0c9b6a2
80b3925
a6328d7
bf5adba
3d443ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1036,6 +1036,23 @@ _PyModule_IsPossiblyShadowing(PyObject *origin) | |
| return result; | ||
| } | ||
|
|
||
| int | ||
| _PyModule_ReplaceLazyValue(PyObject *dict, PyObject *name, PyObject *value) | ||
| { | ||
| // The adaptive interpreter uses the dictionary version to return the slot at | ||
| // a given index from the module. When replacing a value the version number doesn't | ||
| // change, so we need to atomically clear the version before replacing so that it | ||
| // doesn't return a lazy value. | ||
| int err; | ||
| Py_BEGIN_CRITICAL_SECTION(dict); | ||
|
|
||
| _PyDict_ClearKeysVersion(dict); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are just updating the value, but it is the dictionary keys version that we need to clear to invalidate the existing inline caches. I'm open to a better name but it seems like it might get really unwieldy if it includes the "ClearKeysVersionBecauseWeModifyValues" |
||
| err = _PyDict_SetItem_LockHeld((PyDictObject *)dict, name, value); | ||
|
|
||
| Py_END_CRITICAL_SECTION(); | ||
| return err; | ||
| } | ||
|
|
||
| PyObject* | ||
| _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress) | ||
| { | ||
|
|
@@ -1052,13 +1069,13 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress) | |
| // instead treated as if the attribute doesn't exist. | ||
| PyErr_Clear(); | ||
| } | ||
|
|
||
| return NULL; | ||
| } else if (PyDict_SetItem(m->md_dict, name, new_value) < 0) { | ||
| Py_DECREF(new_value); | ||
| Py_DECREF(attr); | ||
| return NULL; | ||
| } | ||
|
|
||
| if (_PyModule_ReplaceLazyValue(m->md_dict, name, new_value) < 0) { | ||
| Py_CLEAR(new_value); | ||
| } | ||
| Py_DECREF(attr); | ||
| return new_value; | ||
| } | ||
|
|
@@ -1490,7 +1507,7 @@ module_get_dict(PyObject *mod, void *Py_UNUSED(ignored)) | |
| if (new_value == NULL) { | ||
| return NULL; | ||
| } | ||
| if (PyDict_SetItem(self->md_dict, key, new_value) < 0) { | ||
| if (_PyModule_ReplaceLazyValue(self->md_dict, key, new_value) < 0) { | ||
| Py_DECREF(new_value); | ||
| return NULL; | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.