Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-121459: Deferred LOAD_GLOBAL#123128
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
Uh oh!
There was an error while loading. Please reload this page.
gh-121459: Deferred LOAD_GLOBAL #123128
Changes from all commits
803e9f7b213b6f11d2fb6ea8d855af0c0321a431de48bebe96e948b4e23567adbbebf9dbdee106d176c04ff9f17c644ebf64f932abfd44000c1ee7ead33dd1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1496,6 +1496,45 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb | ||
| return ix; | ||
| } | ||
| Py_ssize_t | ||
| _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr) | ||
| { | ||
| PyDictKeysObject *dk = _Py_atomic_load_ptr(&mp->ma_keys); | ||
| if (dk->dk_kind == DICT_KEYS_UNICODE && PyUnicode_CheckExact(key)){ | ||
| Py_ssize_t ix = unicodekeys_lookup_unicode_threadsafe(dk, key, hash); | ||
| if (ix == DKIX_EMPTY){ | ||
| *value_addr = PyStackRef_NULL; | ||
| return ix; | ||
| } | ||
| else if (ix >= 0){ | ||
| PyObject **addr_of_value = &DK_UNICODE_ENTRIES(dk)[ix].me_value; | ||
| PyObject *value = _Py_atomic_load_ptr(addr_of_value); | ||
| if (value == NULL){ | ||
| *value_addr = PyStackRef_NULL; | ||
| return DKIX_EMPTY; | ||
| } | ||
| if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)){ | ||
| *value_addr = (_PyStackRef){.bits = (uintptr_t)value | Py_TAG_DEFERRED }; | ||
| return ix; | ||
| } | ||
| if (_Py_TryIncrefCompare(addr_of_value, value)){ | ||
| *value_addr = PyStackRef_FromPyObjectSteal(value); | ||
| return ix; | ||
| } | ||
| } | ||
| } | ||
| PyObject *obj; | ||
| Py_ssize_t ix = _Py_dict_lookup_threadsafe(mp, key, hash, &obj); | ||
| if (ix >= 0 && obj != NULL){ | ||
| *value_addr = PyStackRef_FromPyObjectSteal(obj); | ||
| } | ||
| else{ | ||
| *value_addr = PyStackRef_NULL; | ||
| } | ||
| return ix; | ||
| } | ||
| #else // Py_GIL_DISABLED | ||
| Py_ssize_t | ||
| @@ -1506,6 +1545,15 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb | ||
| return ix; | ||
| } | ||
| Py_ssize_t | ||
| _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr) | ||
| { | ||
| PyObject *val; | ||
| Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &val); | ||
| *value_addr = val == NULL ? PyStackRef_NULL : PyStackRef_FromPyObjectNew(val); | ||
| return ix; | ||
| } | ||
| #endif | ||
| int | ||
| @@ -2418,6 +2466,32 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key) | ||
| return value; | ||
| } | ||
| void | ||
| _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObject *key, _PyStackRef *res) | ||
| { | ||
| Py_ssize_t ix; | ||
| Py_hash_t hash; | ||
| hash = _PyObject_HashFast(key); | ||
| if (hash == -1){ | ||
| *res = PyStackRef_NULL; | ||
Fidget-Spinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return; | ||
| } | ||
| /* namespace 1: globals */ | ||
| ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res); | ||
| if (ix == DKIX_ERROR){ | ||
| *res = PyStackRef_NULL; | ||
| } | ||
| if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)){ | ||
| return; | ||
| } | ||
| /* namespace 2: builtins */ | ||
| ix = _Py_dict_lookup_threadsafe_stackref(builtins, key, hash, res); | ||
| assert(ix >= 0 || PyStackRef_IsNull(*res)); | ||
| } | ||
| /* Consumes references to key and value */ | ||
| static int | ||
| setitem_take2_lock_held(PyDictObject *mp, PyObject *key, PyObject *value) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3072,15 +3072,14 @@ _PyEval_GetANext(PyObject *aiter) | ||
| return awaitable; | ||
| } | ||
| PyObject * | ||
| _PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name) | ||
| void | ||
| _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name, _PyStackRef *writeto) | ||
| { | ||
| PyObject *res; | ||
| if (PyDict_CheckExact(globals) && PyDict_CheckExact(builtins)){ | ||
| res = _PyDict_LoadGlobal((PyDictObject *)globals, | ||
| _PyDict_LoadGlobalStackRef((PyDictObject *)globals, | ||
| (PyDictObject *)builtins, | ||
| name); | ||
| if (res == NULL && !PyErr_Occurred()){ | ||
| name, writeto); | ||
Fidget-Spinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if (PyStackRef_IsNull(*writeto) && !PyErr_Occurred()){ | ||
| /* _PyDict_LoadGlobal() returns NULL without raising | ||
| * an exception if the key doesn't exist */ | ||
| _PyEval_FormatExcCheckArg(PyThreadState_GET(), PyExc_NameError, | ||
| @@ -3090,22 +3089,25 @@ _PyEval_LoadGlobal(PyObject *globals, PyObject *builtins, PyObject *name) | ||
| else{ | ||
| /* Slow-path if globals or builtins is not a dict */ | ||
| /* namespace 1: globals */ | ||
| PyObject *res; | ||
| if (PyMapping_GetOptionalItem(globals, name, &res) < 0){ | ||
| return NULL; | ||
| *writeto = PyStackRef_NULL; | ||
| return; | ||
| } | ||
| if (res == NULL){ | ||
| /* namespace 2: builtins */ | ||
| if (PyMapping_GetOptionalItem(builtins, name, &res) < 0){ | ||
| return NULL; | ||
| *writeto = PyStackRef_NULL; | ||
| return; | ||
| } | ||
| if (res == NULL){ | ||
| _PyEval_FormatExcCheckArg( | ||
| PyThreadState_GET(), PyExc_NameError, | ||
| NAME_ERROR_MSG, name); | ||
| } | ||
| } | ||
| *writeto = PyStackRef_FromPyObjectSteal(res); | ||
| } | ||
| return res; | ||
| } | ||
| PyObject * | ||
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.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.