Skip to content

Commit 87278ef

Browse files
committed
Fix frozenset contains method.
1 parent 8ff7dbd commit 87278ef

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Objects/setobject.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static inline Py_ALWAYS_INLINE int
169169
set_compare_frozenset(PySetObject *so, setentry *table, setentry *ep,
170170
PyObject *key, Py_hash_t hash)
171171
{
172-
assert(PyFrozenSet_CheckExact(so));
172+
assert(PyFrozenSet_Check(so));
173173
PyObject *startkey = ep->key;
174174
if (startkey == NULL) {
175175
return SET_LOOKKEY_EMPTY;
@@ -2434,6 +2434,7 @@ _PySet_Contains(PySetObject *so, PyObject *key)
24342434
Py_hash_t hash = _PyObject_HashFast(key);
24352435
if (hash == -1) {
24362436
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) {
2437+
set_unhashable_type(key);
24372438
return -1;
24382439
}
24392440
PyErr_Clear();
@@ -2488,12 +2489,23 @@ static PyObject *
24882489
frozenset___contains___impl(PySetObject *so, PyObject *key)
24892490
/*[clinic end generated code: output=2301ed91bc3a6dd5 input=2f04922a98d8bab7]*/
24902491
{
2491-
long result;
2492-
2493-
result = set_contains_lock_held(so, key);
2494-
if (result < 0)
2492+
Py_hash_t hash = _PyObject_HashFast(key);
2493+
if (hash == -1) {
2494+
if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) {
2495+
set_unhashable_type(key);
2496+
return NULL;
2497+
}
2498+
PyErr_Clear();
2499+
Py_BEGIN_CRITICAL_SECTION(key);
2500+
hash = frozenset_hash_impl(key);
2501+
Py_END_CRITICAL_SECTION();
2502+
}
2503+
setentry *entry; // unused
2504+
int status = set_do_lookup(so, so->table, so->mask, key, hash, &entry,
2505+
set_compare_frozenset);
2506+
if (status < 0)
24952507
return NULL;
2496-
return PyBool_FromLong(result);
2508+
return PyBool_FromLong(status);
24972509
}
24982510

24992511
/*[clinic input]

0 commit comments

Comments
 (0)