mirror of
https://github.com/python/cpython.git
synced 2025-12-08 02:08:20 +00:00
Issue #26745: Removed redundant code in _PyObject_GenericSetAttrWithDict.
Based on patch by Xiang Zhang.
This commit is contained in:
parent
a858bbde03
commit
55c861f637
1 changed files with 21 additions and 30 deletions
|
|
@ -1040,8 +1040,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
||||||
name->ob_type->tp_name);
|
name->ob_type->tp_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
Py_INCREF(name);
|
||||||
Py_INCREF(name);
|
|
||||||
|
|
||||||
if (tp->tp_dict == NULL) {
|
if (tp->tp_dict == NULL) {
|
||||||
if (PyType_Ready(tp) < 0)
|
if (PyType_Ready(tp) < 0)
|
||||||
|
|
@ -1049,10 +1048,10 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
||||||
}
|
}
|
||||||
|
|
||||||
descr = _PyType_Lookup(tp, name);
|
descr = _PyType_Lookup(tp, name);
|
||||||
Py_XINCREF(descr);
|
|
||||||
|
|
||||||
f = NULL;
|
f = NULL;
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
|
Py_INCREF(descr);
|
||||||
f = descr->ob_type->tp_descr_get;
|
f = descr->ob_type->tp_descr_get;
|
||||||
if (f != NULL && PyDescr_IsData(descr)) {
|
if (f != NULL && PyDescr_IsData(descr)) {
|
||||||
res = f(descr, obj, (PyObject *)obj->ob_type);
|
res = f(descr, obj, (PyObject *)obj->ob_type);
|
||||||
|
|
@ -1072,8 +1071,9 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
|
||||||
if (tsize < 0)
|
if (tsize < 0)
|
||||||
tsize = -tsize;
|
tsize = -tsize;
|
||||||
size = _PyObject_VAR_SIZE(tp, tsize);
|
size = _PyObject_VAR_SIZE(tp, tsize);
|
||||||
|
assert(size <= PY_SSIZE_T_MAX);
|
||||||
|
|
||||||
dictoffset += (long)size;
|
dictoffset += (Py_ssize_t)size;
|
||||||
assert(dictoffset > 0);
|
assert(dictoffset > 0);
|
||||||
assert(dictoffset % SIZEOF_VOID_P == 0);
|
assert(dictoffset % SIZEOF_VOID_P == 0);
|
||||||
}
|
}
|
||||||
|
|
@ -1141,12 +1141,11 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
Py_INCREF(name);
|
Py_INCREF(name);
|
||||||
|
|
||||||
descr = _PyType_Lookup(tp, name);
|
descr = _PyType_Lookup(tp, name);
|
||||||
Py_XINCREF(descr);
|
|
||||||
|
|
||||||
f = NULL;
|
|
||||||
if (descr != NULL) {
|
if (descr != NULL) {
|
||||||
|
Py_INCREF(descr);
|
||||||
f = descr->ob_type->tp_descr_set;
|
f = descr->ob_type->tp_descr_set;
|
||||||
if (f != NULL && PyDescr_IsData(descr)) {
|
if (f != NULL) {
|
||||||
res = f(descr, obj, value);
|
res = f(descr, obj, value);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -1154,40 +1153,32 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
||||||
|
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
dictptr = _PyObject_GetDictPtr(obj);
|
dictptr = _PyObject_GetDictPtr(obj);
|
||||||
if (dictptr != NULL) {
|
if (dictptr == NULL) {
|
||||||
res = _PyObjectDict_SetItem(Py_TYPE(obj), dictptr, name, value);
|
if (descr == NULL) {
|
||||||
if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
|
PyErr_Format(PyExc_AttributeError,
|
||||||
PyErr_SetObject(PyExc_AttributeError, name);
|
"'%.100s' object has no attribute '%U'",
|
||||||
|
tp->tp_name, name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_Format(PyExc_AttributeError,
|
||||||
|
"'%.50s' object attribute '%U' is read-only",
|
||||||
|
tp->tp_name, name);
|
||||||
|
}
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
res = _PyObjectDict_SetItem(tp, dictptr, name, value);
|
||||||
}
|
}
|
||||||
if (dict != NULL) {
|
else {
|
||||||
Py_INCREF(dict);
|
Py_INCREF(dict);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
res = PyDict_DelItem(dict, name);
|
res = PyDict_DelItem(dict, name);
|
||||||
else
|
else
|
||||||
res = PyDict_SetItem(dict, name, value);
|
res = PyDict_SetItem(dict, name, value);
|
||||||
Py_DECREF(dict);
|
Py_DECREF(dict);
|
||||||
if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
|
|
||||||
PyErr_SetObject(PyExc_AttributeError, name);
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
|
||||||
|
PyErr_SetObject(PyExc_AttributeError, name);
|
||||||
|
|
||||||
if (f != NULL) {
|
|
||||||
res = f(descr, obj, value);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descr == NULL) {
|
|
||||||
PyErr_Format(PyExc_AttributeError,
|
|
||||||
"'%.100s' object has no attribute '%U'",
|
|
||||||
tp->tp_name, name);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyErr_Format(PyExc_AttributeError,
|
|
||||||
"'%.50s' object attribute '%U' is read-only",
|
|
||||||
tp->tp_name, name);
|
|
||||||
done:
|
done:
|
||||||
Py_XDECREF(descr);
|
Py_XDECREF(descr);
|
||||||
Py_DECREF(name);
|
Py_DECREF(name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue