Author serhiy.storchaka
Recipients kristjan.jonsson, pitrou, serhiy.storchaka, vstinner
Date 2018-12-09.11:01:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
_PyIter_GetBuiltin() was introduced in issue14288 (31668b8f7a3efc7b17511bb08525b28e8ff5f23a). This was used for getting references to the builtin "iter" and "reverse". It was renamed to _PyObject_GetBuiltin() in a701388de1135241b5a8e4c970e06c0e83a66dc0.

There is other code that gets references to the builtin "getattr" using PyEval_GetBuiltins(). It is more efficient, but contains bugs.

The proposed PR unifies getting references to builtins:

* The prefix _PyObject_ is changed to _PyEval_, since this function has relation not to the object type but to the evaluation environment.

* It uses now the private _Py_Identifier API instead of a raw C string. This saves time by omitting the creation of a Unicode object on every call.

* It uses now fast PyEval_GetBuiltins() instead of slower PyImport_Import().

* Fixed errors handling in the code that used PyEval_GetBuiltins() before. It no longer swallows unexpected exceptions, no longer returns an error without setting an exception, and no longer causes raising a SystemError.

An example of an error in current code:

>>> import builtins
>>> del builtins.getattr
>>> int.bit_length.__reduce__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: NULL object passed to Py_BuildValue
Date User Action Args
2018-12-09 11:01:30serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, kristjan.jonsson, vstinner
2018-12-09 11:01:30serhiy.storchakasetmessageid: <>
2018-12-09 11:01:30serhiy.storchakalinkissue35444 messages
2018-12-09 11:01:30serhiy.storchakacreate