Skip to content

Commit d2fb5a0

Browse files
committed
Revert "Address code review"
This reverts commit 8d8fc98.
1 parent 26c46c7 commit d2fb5a0

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

Objects/dictobject.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,33 @@ _PyDict_FromKeys(PyObject *cls, PyObject *iterable, PyObject *value)
32903290
return NULL;
32913291

32923292

3293-
if (PyAnyDict_CheckExact(d)) {
3293+
if (PyDict_CheckExact(d)) {
3294+
if (PyDict_CheckExact(iterable)) {
3295+
PyDictObject *mp = (PyDictObject *)d;
3296+
3297+
Py_BEGIN_CRITICAL_SECTION2(d, iterable);
3298+
d = (PyObject *)dict_dict_fromkeys(mp, iterable, value);
3299+
Py_END_CRITICAL_SECTION2();
3300+
return d;
3301+
}
3302+
else if (PyFrozenDict_CheckExact(iterable)) {
3303+
PyDictObject *mp = (PyDictObject *)d;
3304+
3305+
Py_BEGIN_CRITICAL_SECTION(d);
3306+
d = (PyObject *)dict_dict_fromkeys(mp, iterable, value);
3307+
Py_END_CRITICAL_SECTION();
3308+
return d;
3309+
}
3310+
else if (PyAnySet_CheckExact(iterable)) {
3311+
PyDictObject *mp = (PyDictObject *)d;
3312+
3313+
Py_BEGIN_CRITICAL_SECTION2(d, iterable);
3314+
d = (PyObject *)dict_set_fromkeys(mp, iterable, value);
3315+
Py_END_CRITICAL_SECTION2();
3316+
return d;
3317+
}
3318+
}
3319+
else if (PyFrozenDict_CheckExact(d)) {
32943320
if (PyDict_CheckExact(iterable)) {
32953321
PyDictObject *mp = (PyDictObject *)d;
32963322

@@ -3307,7 +3333,7 @@ _PyDict_FromKeys(PyObject *cls, PyObject *iterable, PyObject *value)
33073333
else if (PyAnySet_CheckExact(iterable)) {
33083334
PyDictObject *mp = (PyDictObject *)d;
33093335

3310-
Py_BEGIN_CRITICAL_SECTION(d);
3336+
Py_BEGIN_CRITICAL_SECTION(iterable);
33113337
d = (PyObject *)dict_set_fromkeys(mp, iterable, value);
33123338
Py_END_CRITICAL_SECTION();
33133339
return d;
@@ -3320,7 +3346,20 @@ _PyDict_FromKeys(PyObject *cls, PyObject *iterable, PyObject *value)
33203346
return NULL;
33213347
}
33223348

3323-
if (PyAnyDict_CheckExact(d)) {
3349+
if (PyDict_CheckExact(d)) {
3350+
Py_BEGIN_CRITICAL_SECTION(d);
3351+
while ((key = PyIter_Next(it)) != NULL) {
3352+
status = setitem_lock_held((PyDictObject *)d, key, value);
3353+
Py_DECREF(key);
3354+
if (status < 0) {
3355+
assert(PyErr_Occurred());
3356+
goto dict_iter_exit;
3357+
}
3358+
}
3359+
dict_iter_exit:;
3360+
Py_END_CRITICAL_SECTION();
3361+
}
3362+
else if (PyFrozenDict_CheckExact(d)) {
33243363
while ((key = PyIter_Next(it)) != NULL) {
33253364
status = anydict_setitem_take2((PyDictObject *)d,
33263365
key, Py_NewRef(value));

0 commit comments

Comments
 (0)