-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-132657: Add maybe_enable_deferred_ref_count(). #142843
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
8fae6ec
2372f96
03977d9
5ef77af
04826f7
1c59358
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 |
|---|---|---|
|
|
@@ -355,6 +355,28 @@ static int function_kind(PyCodeObject *code); | |
| static bool function_check_args(PyObject *o, int expected_argcount, int opcode); | ||
| static uint32_t function_get_version(PyObject *o, int opcode); | ||
|
|
||
| #ifdef Py_GIL_DISABLED | ||
| static void | ||
| maybe_enable_deferred_ref_count(PyObject *dict, PyObject *name) | ||
| { | ||
| PyObject *op; | ||
| if (PyDict_GetItemRef(dict, name, &op) != 1) { | ||
| return; | ||
| } | ||
| if (_Py_IsOwnedByCurrentThread(op) || | ||
| !PyType_IS_GC(Py_TYPE(op)) || | ||
| _PyObject_HasDeferredRefcount(op)) { | ||
| Py_DECREF(op); | ||
| return; | ||
| } | ||
|
||
| if (PyFrozenSet_Check(op) || PyTuple_Check(op) || PyType_Check(op)) { | ||
| PyUnstable_Object_EnableDeferredRefcount(op); | ||
| } | ||
|
||
| Py_DECREF(op); | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
| static int | ||
| specialize_module_load_attr_lock_held(PyDictObject *dict, _Py_CODEUNIT *instr, PyObject *name) | ||
| { | ||
|
|
@@ -384,6 +406,9 @@ specialize_module_load_attr_lock_held(PyDictObject *dict, _Py_CODEUNIT *instr, P | |
| SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OUT_OF_VERSIONS); | ||
| return -1; | ||
| } | ||
| #ifdef Py_GIL_DISABLED | ||
| maybe_enable_deferred_ref_count((PyObject *)dict, name); | ||
| #endif | ||
| write_u32(cache->version, keys_version); | ||
| cache->index = (uint16_t)index; | ||
| specialize(instr, LOAD_ATTR_MODULE); | ||
|
|
@@ -1264,7 +1289,6 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr, | |
| return 1; | ||
| } | ||
|
|
||
|
|
||
| static void | ||
| specialize_load_global_lock_held( | ||
| PyObject *globals, PyObject *builtins, | ||
|
|
@@ -1305,6 +1329,9 @@ specialize_load_global_lock_held( | |
| SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_OUT_OF_RANGE); | ||
| goto fail; | ||
| } | ||
| #ifdef Py_GIL_DISABLED | ||
| maybe_enable_deferred_ref_count(globals, name); | ||
| #endif | ||
| cache->index = (uint16_t)index; | ||
| cache->module_keys_version = (uint16_t)keys_version; | ||
| specialize(instr, LOAD_GLOBAL_MODULE); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's combine this lookup with the earlier
_PyDict_LookupIndex._PyDict_LookupIndexalready gets the value internally and throws it away.