8000 Use PyDict_GetItemRef instead of PyDict_GetItemWithError · python/cpython@7fe6a06 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fe6a06

Browse files
committed
Use PyDict_GetItemRef instead of PyDict_GetItemWithError
1 parent 83c4c50 commit 7fe6a06

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Objects/moduleobject.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -869,28 +869,31 @@ _Py_module_getattro(PyModuleObject *m, PyObject *name)
869869
static int
870870
module_setattro(PyModuleObject *mod, PyObject *name, PyObject *value)
871871
{
872-
PyObject *ret;
872+
PyObject *res;
873+
int ret;
873874
assert(mod->md_dict != NULL);
874875
if (value == NULL) {
875-
PyObject *delattr = PyDict_GetItemWithError(mod->md_dict, &_Py_ID(__delattr__));
876-
if (PyErr_Occurred()) {
876+
PyObject *delattr;
877+
ret = PyDict_GetItemRef(mod->md_dict, &_Py_ID(__delattr__), &delattr);
878+
if (ret == -1) {
877879
return -1;
878880
}
879-
if (delattr) {
880-
ret = PyObject_CallFunctionObjArgs(delattr, name, NULL);
881-
if (ret == NULL) {
881+
if (ret) {
882+
res = PyObject_CallFunctionObjArgs(delattr, name, NULL);
883+
if (res == NULL) {
882884
return -1;
883885
}
884886
return 0;
885887
}
886888
} else {
887-
PyObject *setattr = PyDict_GetItemWithError(mod->md_dict, &_Py_ID(__setattr__));
888-
if (PyErr_Occurred()) {
889+
PyObject *setattr;
890+
ret = PyDict_GetItemRef(mod->md_dict, &_Py_ID(__setattr__), &setattr);
891+
if (ret == -1) {
889892
return -1;
890893
}
891-
if (setattr) {
892-
ret = PyObject_CallFunctionObjArgs(setattr, name, value, NULL);
893-
if (ret == NULL) {
894+
if (ret) {
895+
res = PyObject_CallFunctionObjArgs(setattr, name, value, NULL);
896+
if (res == NULL) {
894897
return -1;
895898
}
896899
return 0;

0 commit comments

Comments
 (0)
0