diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-11 06:28:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 06:28:18 (GMT) |
commit | bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d (patch) | |
tree | b9dbe54e2c1380294f3e2396450132d5b205af0a /Python | |
parent | 7cf3d8e25174c8871883e42f3240fd7f01efd3a8 (diff) | |
download | cpython-bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d.zip cpython-bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d.tar.gz cpython-bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d.tar.bz2 |
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".
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 7ffc68a..ebe1c50 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) { |