Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9d3666

Browse filesBrowse files
committed
Fixup recursive locking
1 parent 7407ce9 commit a9d3666
Copy full SHA for a9d3666

File tree

Expand file treeCollapse file tree

1 file changed

+8
-34
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-34
lines changed

‎Objects/dictobject.c

Copy file name to clipboardExpand all lines: Objects/dictobject.c
+8-34Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,8 @@ insert_split_dict(PyInterpreterState *interp, PyDictObject *mp,
13421342
LOCK_KEYS(keys);
13431343
if (keys->dk_usable <= 0) {
13441344
/* Need to resize. */
1345-
dictkeys_incref(keys);
1346-
int ins = insertion_resize(interp, mp, 1);
1347-
dictkeys_decref(interp, keys);
13481345
UNLOCK_KEYS(keys);
1346+
int ins = insertion_resize(interp, mp, 1);
13491347
if (ins < 0) {
13501348
return -1;
13511349
}
@@ -1371,30 +1369,6 @@ insert_split_dict(PyInterpreterState *interp, PyDictObject *mp,
13711369
return 0;
13721370
}
13731371

1374-
static int
1375-
convert_to_nonunicode_keys(PyInterpreterState *interp, PyDictObject *mp)
1376-
{
1377-
PyDictKeysObject *keys = mp->ma_keys;
1378-
if (_PyDict_HasSplitTable(mp)) {
1379-
LOCK_KEYS(keys);
1380-
dictkeys_incref(keys);
1381-
} else {
1382-
keys = NULL;
1383-
}
1384-
1385-
int res = insertion_resize(interp, mp, 0);
1386-
1387-
if (keys != NULL) {
1388-
dictkeys_decref(interp, keys);
1389-
UNLOCK_KEYS(keys);
1390-
}
1391-
if (res < 0) {
1392-
return res;
1393-
}
1394-
assert(mp->ma_keys->dk_kind == DICT_KEYS_GENERAL);
1395-
return 0;
1396-
}
1397-
13981372
/*
13991373
Internal routine to insert a new item into the table.
14001374
Used both by the internal resize routine and by the public insert routine.
@@ -1410,9 +1384,9 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
14101384
ASSERT_DICT_LOCKED(mp);
14111385

14121386
if (DK_IS_UNICODE(mp->ma_keys) && !PyUnicode_CheckExact(key)) {
1413-
if (convert_to_nonunicode_keys(interp, mp) < 0) {
1387+
if (insertion_resize(interp, mp, 0) < 0)
14141388
goto Fail;
1415-
}
1389+
assert(mp->ma_keys->dk_kind == DICT_KEYS_GENERAL);
14161390
}
14171391

14181392
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &old_value);
@@ -1432,7 +1406,8 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
14321406
if (insert_combined_dict(interp, mp, hash, key, value) < 0) {
14331407
goto Fail;
14341408
}
1435-
} else {
1409+
}
1410+
else {
14361411
if (insert_split_dict(interp, mp, hash, key, value) < 0)
14371412
goto Fail;
14381413
}
@@ -3803,7 +3778,7 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
38033778
}
38043779

38053780
if (!PyUnicode_CheckExact(key) && DK_IS_UNICODE(mp->ma_keys)) {
3806-
if (convert_to_nonunicode_keys(interp, mp) < 0) {
3781+
if (insertion_resize(interp, mp, 0) < 0) {
38073782
if (result) {
38083783
*result = NULL;
38093784
}
@@ -3834,7 +3809,8 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
38343809
}
38353810
return -1;
38363811
}
3837-
} else {
3812+
}
3813+
else {
38383814
if (insert_split_dict(interp, mp, hash, Py_NewRef(key), Py_NewRef(value)) < 0) {
38393815
Py_DECREF(key);
38403816
Py_DECREF(value);
@@ -3997,8 +3973,6 @@ dict_popitem_impl(PyDictObject *self)
39973973
}
39983974
/* Convert split table to combined table */
39993975
if (_PyDict_HasSplitTable(self)) {
4000-
PyDictKeysObject *keys = self->ma_keys;
4001-
40023976
if (dictresize(interp, self, DK_LOG_SIZE(self->ma_keys), 1) < 0) {
40033977
Py_DECREF(res);
40043978
return NULL;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.