mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
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.
This commit is contained in:
parent
154477be72
commit
f5559f38d9
4 changed files with 105 additions and 32 deletions
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue