@@ -5249,11 +5249,10 @@ static PyObject *
52495249dict_new_untracked (PyTypeObject * type )
52505250{
52515251 assert (type != NULL );
5252- assert (type -> tp_alloc != NULL );
52535252 // dict subclasses must implement the GC protocol
52545253 assert (_PyType_IS_GC (type ));
52555254
5256- PyObject * self = type -> tp_alloc (type , 0 );
5255+ PyObject * self = _PyType_AllocNoTrack (type , 0 );
52575256 if (self == NULL ) {
52585257 return NULL ;
52595258 }
@@ -5277,9 +5276,8 @@ dict_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds
52775276 if (self == NULL ) {
52785277 return NULL ;
52795278 }
5280- if (!_PyObject_GC_IS_TRACKED (self )) {
5281- _PyObject_GC_TRACK (self );
5282- }
5279+ assert (!_PyObject_GC_IS_TRACKED (self ));
5280+ _PyObject_GC_TRACK (self );
52835281 return self ;
52845282}
52855283
@@ -8380,28 +8378,16 @@ frozendict_hash(PyObject *op)
83808378}
83818379
83828380
8383- /* Allocate an empty, GC-untracked frozendict. Allocation never tracks the
8384- object -- even for subclasses, whose tp_alloc is PyType_GenericAlloc -- so it
8385- stays untracked for the whole construction and a half-built frozendict is kept
8386- out of gc.get_objects(). The constructor GC-tracks it exactly once, when
8381+ /* Allocate an empty, GC-untracked frozendict; the constructor tracks it once
83878382 fully built. */
83888383static PyObject *
83898384frozendict_new_untracked (PyTypeObject * type )
83908385{
8391- assert (_PyType_IS_GC (type ));
8392- PyObject * d = _PyType_AllocNoTrack (type , 0 );
8386+ PyObject * d = dict_new_untracked (type );
83938387 if (d == NULL ) {
83948388 return NULL ;
83958389 }
8396- PyDictObject * mp = (PyDictObject * )d ;
8397- mp -> ma_used = 0 ;
8398- mp -> _ma_watcher_tag = 0 ;
8399- // Py_EMPTY_KEYS is immortal, so it is not incref'd.
8400- assert ((Py_EMPTY_KEYS )-> dk_refcnt == _Py_DICT_IMMORTAL_INITIAL_REFCNT );
8401- mp -> ma_keys = Py_EMPTY_KEYS ;
8402- mp -> ma_values = NULL ;
8403- ASSERT_CONSISTENT (mp );
8404- assert (can_modify_dict (mp ));
8390+ assert (can_modify_dict (_PyAnyDict_CAST (d )));
84058391 _PyFrozenDictObject_CAST (d )-> ma_hash = -1 ;
84068392 return d ;
84078393}
0 commit comments