[issue24992] collections.OrderedDict constructor (odict_new) doesn't handle PyDict_New() failure

STINNER Victor report at bugs.python.org
Thu Sep 3 16:03:54 CEST 2015


STINNER Victor added the comment:

> If don't initialize fields, then they will be not initialized in odict_dealloc

Old code initialized all fields to zero (or NULL), like "_odict_FIRST(od) = NULL;". The type allocator fills the newly allocated with zeros. So setting fields again to zero is redundant (useless).

> I would allocate a dict for od_inst_dict before calling PyDict_Type.tp_new. An allocator can release GIL and call Python code, and at that moment the OrderedDict object is in inconsistent state.

Yes, but the newly created object is not still private at this point, there is only one reference known in the C code. dict_new() has the same design. You can please elaborate the issue?

We only give the reference to the caller when the newly created OrderedDict is fully initialized (consistent).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24992>
_______________________________________


More information about the Python-bugs-list mailing list