@@ -208,52 +208,22 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
208208{
209209 _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (so );
210210
211- /* Pre-increment is necessary to prevent arbitrary code in the rich
212- comparison from deallocating the key just before the insertion. */
213- Py_INCREF (key );
214-
215- return set_add_entry_takeref (so , key , hash );
211+ return set_add_entry_takeref (so , Py_NewRef (key ), hash );
216212}
217213
218214int
219215_PySet_AddTakeRef (PySetObject * so , PyObject * key )
220216{
221217 Py_hash_t hash = _PyObject_HashFast (key );
222218 if (hash == -1 ) {
219+ Py_DECREF (key );
223220 return -1 ;
224221 }
225222 // We don't pre-increment here, the caller holds a strong
226223 // reference to the object which we are stealing.
227224 return set_add_entry_takeref (so , key , hash );
228225}
229226
230- PyObject *
231- _PySet_FromStackRefSteal (const _PyStackRef * src , Py_ssize_t n )
232- {
233- PySetObject * set = (PySetObject * )PySet_New (NULL );
234- if (n == 0 ) {
235- return (PyObject * )set ;
236- }
237-
238- if (set_table_resize (set , n * 2 ) != 0 ) {
239- return NULL ;
240- }
241-
242- int err = 0 ;
243- for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
244- if (err == 0 ) {
245- err = _PySet_AddTakeRef (set , PyStackRef_AsPyObjectSteal (src [i ]));
246- } else {
247- PyStackRef_CLOSE (src [i ]);
248- }
249- }
250- if (err ) {
251- Py_CLEAR (set );
252- }
253-
254- return (PyObject * )set ;
255- }
256-
257227/*
258228Internal routine used by set_table_resize() to insert an item which is
259229known to be absent from the set. Besides the performance benefit,
0 commit comments