| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -1065,7 +1065,6 @@ compare_unicode_generic(PyDictObject *mp, PyDictKeysObject *dk, | |
| assert(ep->me_key != NULL); | ||
| assert(PyUnicode_CheckExact(ep->me_key)); | ||
| assert(!PyUnicode_CheckExact(key)); | ||
| // TODO: Thread safety | ||
|
|
||
| if (unicode_get_hash(ep->me_key) == hash) { | ||
| PyObject *startkey = ep->me_key; | ||
| Expand Down Expand Up | @@ -1192,7 +1191,8 @@ _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **valu | |
| PyDictKeysObject *dk; | ||
| DictKeysKind kind; | ||
| Py_ssize_t ix; | ||
| // TODO: Thread safety | ||
|
|
||
| _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(mp); | ||
| start: | ||
| dk = mp->ma_keys; | ||
| kind = dk->dk_kind; | ||
| Expand Down Expand Up | @@ -1390,7 +1390,7 @@ dictkeys_generic_lookup_threadsafe(PyDictObject *mp, PyDictKeysObject* dk, PyObj | |
| return do_lookup(mp, dk, key, hash, compare_generic_threadsafe); | ||
| } | ||
|
|
||
| static Py_ssize_t | ||
| Py_ssize_t | ||
| _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr) | ||
| { | ||
| PyDictKeysObject *dk; | ||
| Expand Down Expand Up | @@ -1488,6 +1488,16 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb | |
| return ix; | ||
| } | ||
|
|
||
| #else // Py_GIL_DISABLED | ||
|
|
||
| Py_ssize_t | ||
| _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr) | ||
| { | ||
| Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, value_addr); | ||
| Py_XNewRef(*value_addr); | ||
| return ix; | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| int | ||
| Expand Down Expand Up | @@ -2343,11 +2353,12 @@ _PyDict_GetItemStringWithError(PyObject *v, const char *key) | |
| * Raise an exception and return NULL if an error occurred (ex: computing the | ||
| * key hash failed, key comparison failed, ...). Return NULL if the key doesn't | ||
| * exist. Return the value if the key exists. | ||
| * | ||
| * Returns a new reference. | ||
| */ | ||
| PyObject * | ||
| _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key) | ||
| { | ||
| // TODO: Thread safety | ||
| Py_ssize_t ix; | ||
| Py_hash_t hash; | ||
| PyObject *value; | ||
| Expand All | @@ -2359,14 +2370,14 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key) | |
| } | ||
|
|
||
| /* namespace 1: globals */ | ||
| ix = _Py_dict_lookup(globals, key, hash, &value); | ||
| ix = _Py_dict_lookup_threadsafe(globals, key, hash, &value); | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think this pattern might be simpler if we define _Py_dict_lookup_threadsafe in the default build as _Py_dict_lookup_threadsafe + Py_XNewRef(). We could use it in dict_subscript and dict_get_impl as well.
Sorry, something went wrong.
DinoV reacted with heart emoji
All reactions
|
||
| if (ix == DKIX_ERROR) | ||
| return NULL; | ||
| if (ix != DKIX_EMPTY && value != NULL) | ||
| return value; | ||
|
|
||
| /* namespace 2: builtins */ | ||
| ix = _Py_dict_lookup(builtins, key, hash, &value); | ||
| ix = _Py_dict_lookup_threadsafe(builtins, key, hash, &value); | ||
| assert(ix >= 0 || value == NULL); | ||
| return value; | ||
| } | ||
| Expand Down Expand Up | @@ -3214,11 +3225,7 @@ dict_subscript(PyObject *self, PyObject *key) | |
| if (hash == -1) | ||
| return NULL; | ||
| } | ||
| #ifdef Py_GIL_DISABLED | ||
| ix = _Py_dict_lookup_threadsafe(mp, key, hash, &value); | ||
| #else | ||
| ix = _Py_dict_lookup(mp, key, hash, &value); | ||
| #endif | ||
| if (ix == DKIX_ERROR) | ||
| return NULL; | ||
| if (ix == DKIX_EMPTY || value == NULL) { | ||
| Expand All | @@ -3238,11 +3245,7 @@ dict_subscript(PyObject *self, PyObject *key) | |
| _PyErr_SetKeyError(key); | ||
| return NULL; | ||
| } | ||
| #ifdef Py_GIL_DISABLED | ||
| return value; | ||
| #else | ||
| return Py_NewRef(value); | ||
| #endif | ||
| } | ||
|
|
||
| static int | ||
| Expand Down Expand Up | @@ -4109,24 +4112,13 @@ dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value) | |
| if (hash == -1) | ||
| return NULL; | ||
| } | ||
| #ifdef Py_GIL_DISABLED | ||
| ix = _Py_dict_lookup_threadsafe(self, key, hash, &val); | ||
| #else | ||
| ix = _Py_dict_lookup(self, key, hash, &val); | ||
| #endif | ||
| if (ix == DKIX_ERROR) | ||
| return NULL; | ||
| #ifdef Py_GIL_DISABLED | ||
| if (ix == DKIX_EMPTY || val == NULL) { | ||
| val = Py_NewRef(default_value); | ||
| } | ||
| return val; | ||
| #else | ||
| if (ix == DKIX_EMPTY || val == NULL) { | ||
| val = default_value; | ||
| } | ||
| return Py_NewRef(val); | ||
| #endif | ||
| } | ||
|
|
||
| static int | ||
| Expand Down | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think we will want it to return a possibly deferred reference soon, but this is good for now.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.