From bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 11 Dec 2018 08:28:18 +0200 Subject: bpo-35444: Unify and optimize the helper for getting a builtin object. (GH-11047) This speeds up pickling of some iterators. This fixes also error handling in pickling methods when fail to look up builtin "getattr". --- Python/ceval.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Python') diff --git a/Python/ceval.c b/Python/ceval.c index 7ffc68a1e1f..ebe1c50e7ba 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4437,6 +4437,20 @@ PyEval_GetBuiltins(void) return current_frame->f_builtins; } +/* Convenience function to get a builtin from its name */ +PyObject * +_PyEval_GetBuiltinId(_Py_Identifier *name) +{ + PyObject *attr = _PyDict_GetItemIdWithError(PyEval_GetBuiltins(), name); + if (attr) { + Py_INCREF(attr); + } + else if (!PyErr_Occurred()) { + PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(name)); + } + return attr; +} + PyObject * PyEval_GetLocals(void) { -- cgit v1.3.1