summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-08-23 15:40:26 (GMT)
committerGitHub <noreply@github.com>2023-08-23 15:40:26 (GMT)
commitf5559f38d9831e7e55a518e516bcd620ec13af14 (patch)
treeb605c775e1bc02b864d17e663400cde01562088d /Python/pylifecycle.c
parent154477be722ae5c4e18d22d0860e284006b09c4f (diff)
downloadcpython-f5559f38d9831e7e55a518e516bcd620ec13af14.zip
cpython-f5559f38d9831e7e55a518e516bcd620ec13af14.tar.gz
cpython-f5559f38d9831e7e55a518e516bcd620ec13af14.tar.bz2
gh-108308: Replace PyDict_GetItem() with PyDict_GetItemRef() (#108309)
Replace PyDict_GetItem() calls with PyDict_GetItemRef() or PyDict_GetItemWithError() to handle errors. * Replace PyLong_AS_LONG() with _PyLong_AsInt() and check for errors. * Check for PyDict_Contains() error. * pycore_init_builtins() checks for _PyType_Lookup() failure.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 9837e0f..8c321fb 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -762,18 +762,30 @@ pycore_init_builtins(PyThreadState *tstate)
}
interp->builtins = Py_NewRef(builtins_dict);
- PyObject *isinstance = PyDict_GetItem(builtins_dict, &_Py_ID(isinstance));
- assert(isinstance);
+ PyObject *isinstance = PyDict_GetItemWithError(builtins_dict, &_Py_ID(isinstance));
+ if (!isinstance) {
+ goto error;
+ }
interp->callable_cache.isinstance = isinstance;
- PyObject *len = PyDict_GetItem(builtins_dict, &_Py_ID(len));
- assert(len);
+
+ PyObject *len = PyDict_GetItemWithError(builtins_dict, &_Py_ID(len));
+ if (!len) {
+ goto error;
+ }
interp->callable_cache.len = len;
+
PyObject *list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
- assert(list_append);
+ if (list_append == NULL) {
+ goto error;
+ }
interp->callable_cache.list_append = list_append;
+
PyObject *object__getattribute__ = _PyType_Lookup(&PyBaseObject_Type, &_Py_ID(__getattribute__));
- assert(object__getattribute__);
+ if (object__getattribute__ == NULL) {
+ goto error;
+ }
interp->callable_cache.object__getattribute__ = object__getattribute__;
+
if (_PyBuiltins_AddExceptions(bimod) < 0) {
return _PyStatus_ERR("failed to add exceptions to builtins");
}