mirror of https://github.com/python/cpython.git
Issue 18772: Restore set dummy object back to unicode and restore the identity checks in lookkey().
The Gdb prettyprint plugin depended on the dummy object being displayable. Other solutions besides a unicode object are possible. For now, get it back up and running. The identity checks in lookkey() need to be there to prevent the dummy object from leaking through Py_RichCompareBool() into user code in the rare circumstance where the dummy's hash value exactly matches the hash value of the actual key being looked up.
This commit is contained in:
parent
0688897f05
commit
ae9e616a00
|
@ -95,7 +95,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
entry = &table[i];
|
entry = &table[i];
|
||||||
if (entry->key == NULL || entry->key == key)
|
if (entry->key == NULL || entry->key == key)
|
||||||
return entry;
|
return entry;
|
||||||
if (entry->hash == hash) {
|
if (entry->hash == hash && entry->key != dummy) {
|
||||||
startkey = entry->key;
|
startkey = entry->key;
|
||||||
Py_INCREF(startkey);
|
Py_INCREF(startkey);
|
||||||
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
||||||
|
@ -127,7 +127,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
}
|
}
|
||||||
if (entry->key == key)
|
if (entry->key == key)
|
||||||
break;
|
break;
|
||||||
if (entry->hash == hash) {
|
if (entry->hash == hash && entry->key != dummy) {
|
||||||
startkey = entry->key;
|
startkey = entry->key;
|
||||||
Py_INCREF(startkey);
|
Py_INCREF(startkey);
|
||||||
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
||||||
|
@ -157,7 +157,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
}
|
}
|
||||||
if (entry->key == key)
|
if (entry->key == key)
|
||||||
break;
|
break;
|
||||||
if (entry->hash == hash) {
|
if (entry->hash == hash && entry->key != dummy) {
|
||||||
startkey = entry->key;
|
startkey = entry->key;
|
||||||
Py_INCREF(startkey);
|
Py_INCREF(startkey);
|
||||||
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
||||||
|
@ -1090,7 +1090,7 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
|
||||||
PySetObject *so = NULL;
|
PySetObject *so = NULL;
|
||||||
|
|
||||||
if (dummy == NULL) { /* Auto-initialize dummy */
|
if (dummy == NULL) { /* Auto-initialize dummy */
|
||||||
dummy = _PyObject_New(&PyBaseObject_Type);
|
dummy = PyUnicode_FromString("<dummy key>");
|
||||||
if (dummy == NULL)
|
if (dummy == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue