Issue #27128: Cleanup slot_sq_item()

* Invert condition of test to avoid levels of indentation
* Remove useless Py_XDECREF(args) in the error block
* Replace Py_XDECREF(func) with Py_DECREF(func) in the error block: func cannot
  be NULL when reaching the error block
This commit is contained in:
Victor Stinner 2016-08-19 18:17:37 +02:00
parent f736c261a2
commit 018016d8e3
1 changed files with 33 additions and 25 deletions

View File

@ -5808,38 +5808,46 @@ slot_sq_length(PyObject *self)
static PyObject * static PyObject *
slot_sq_item(PyObject *self, Py_ssize_t i) slot_sq_item(PyObject *self, Py_ssize_t i)
{ {
PyObject *func, *args = NULL, *ival = NULL, *retval = NULL; PyObject *func, *ival = NULL, *args, *retval = NULL;
descrgetfunc f; descrgetfunc f;
func = _PyType_LookupId(Py_TYPE(self), &PyId___getitem__); func = _PyType_LookupId(Py_TYPE(self), &PyId___getitem__);
if (func != NULL) { if (func == NULL) {
if ((f = Py_TYPE(func)->tp_descr_get) == NULL) PyObject *getitem_str = _PyUnicode_FromId(&PyId___getitem__);
PyErr_SetObject(PyExc_AttributeError, getitem_str);
return NULL;
}
f = Py_TYPE(func)->tp_descr_get;
if (f == NULL) {
Py_INCREF(func); Py_INCREF(func);
}
else { else {
func = f(func, self, (PyObject *)(Py_TYPE(self))); func = f(func, self, (PyObject *)(Py_TYPE(self)));
if (func == NULL) { if (func == NULL) {
return NULL; return NULL;
} }
} }
ival = PyLong_FromSsize_t(i); ival = PyLong_FromSsize_t(i);
if (ival != NULL) { if (ival == NULL) {
goto error;
}
args = PyTuple_New(1); args = PyTuple_New(1);
if (args != NULL) { if (args == NULL) {
goto error;
}
PyTuple_SET_ITEM(args, 0, ival); PyTuple_SET_ITEM(args, 0, ival);
retval = PyObject_Call(func, args, NULL); retval = PyObject_Call(func, args, NULL);
Py_DECREF(args);
Py_DECREF(func); Py_DECREF(func);
Py_DECREF(args);
return retval; return retval;
}
} error:
} Py_DECREF(func);
else {
PyObject *getitem_str = _PyUnicode_FromId(&PyId___getitem__);
PyErr_SetObject(PyExc_AttributeError, getitem_str);
}
Py_XDECREF(args);
Py_XDECREF(ival); Py_XDECREF(ival);
Py_XDECREF(func);
return NULL; return NULL;
} }