[Python-Dev] Guarantee the success of some object creation C API functions
Serhiy Storchaka
storchaka at gmail.com
Mon May 1 05:50:22 EDT 2017
I want to add promises to public C API functions that create trivial
instances of immutable basic types (integers 0 and 1, empty tuple,
string and bytes object) -- PyLong_FromLong(0), PyLong_FromLong(1),
PyTuple_New(0), PyUnicode_FromStringAndSize(NULL, 0),
PyUnicode_FromString(""), PyBytes_FromStringAndSize(NULL, 0),
PyBytes_FromString("") -- that they always succeed and never return
NULL. Currently they always or almost always succeed, but this is an
implementation detail. I want to make this promise official and more
strong, so that it is true even at very early stage of the interpreter
intitalization and at very late stage of the finalization. Also I want
to add private references to singletons that represent these values
(_PyLong_Zero, _PyTuple_Empty, etc) similar to Py_None and Py_True.
This could make some code clearer. For example see [1] and [2].
These promises add limitations for future changes of the interpreter,
but the official promise decreases the probability of unintentional
changes that break implicit properties.
Do I have the right to give such promises? Are there any reasons that
might prevent their implementation?
[1] https://bugs.python.org/issue29878
[2] https://bugs.python.org/issue30162
More information about the Python-Dev
mailing list