mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
This commit is contained in:
parent
a198645fa0
commit
5a57ade58e
28 changed files with 92 additions and 120 deletions
|
|
@ -3520,8 +3520,7 @@ PyBytes_Concat(PyObject **pv, PyObject *w)
|
|||
/* Multiple references, need to create new object */
|
||||
PyObject *v;
|
||||
v = bytes_concat(*pv, w);
|
||||
Py_DECREF(*pv);
|
||||
*pv = v;
|
||||
Py_SETREF(*pv, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1509,8 +1509,7 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
PyObject *get_doc = _PyObject_GetAttrId(get, &PyId___doc__);
|
||||
if (get_doc) {
|
||||
if (Py_TYPE(self) == &PyProperty_Type) {
|
||||
Py_XDECREF(prop->prop_doc);
|
||||
prop->prop_doc = get_doc;
|
||||
Py_SETREF(prop->prop_doc, get_doc);
|
||||
}
|
||||
else {
|
||||
/* If this is a property subclass, put __doc__
|
||||
|
|
|
|||
|
|
@ -236,8 +236,7 @@ BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb)
|
|||
}
|
||||
|
||||
Py_XINCREF(tb);
|
||||
Py_XDECREF(self->traceback);
|
||||
self->traceback = tb;
|
||||
Py_SETREF(self->traceback, tb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -857,8 +857,7 @@ dict_to_map(PyObject *map, Py_ssize_t nmap, PyObject *dict, PyObject **values,
|
|||
}
|
||||
} else if (values[j] != value) {
|
||||
Py_XINCREF(value);
|
||||
Py_XDECREF(values[j]);
|
||||
values[j] = value;
|
||||
Py_SETREF(values[j], value);
|
||||
}
|
||||
Py_XDECREF(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,8 +127,7 @@ PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
|
|||
PyErr_SetString(PyExc_SystemError, "non-tuple default args");
|
||||
return -1;
|
||||
}
|
||||
Py_XDECREF(((PyFunctionObject *) op) -> func_defaults);
|
||||
((PyFunctionObject *) op) -> func_defaults = defaults;
|
||||
Py_SETREF(((PyFunctionObject *)op)->func_defaults, defaults);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -159,8 +158,7 @@ PyFunction_SetKwDefaults(PyObject *op, PyObject *defaults)
|
|||
"non-dict keyword only default args");
|
||||
return -1;
|
||||
}
|
||||
Py_XDECREF(((PyFunctionObject *)op) -> func_kwdefaults);
|
||||
((PyFunctionObject *) op) -> func_kwdefaults = defaults;
|
||||
Py_SETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +190,7 @@ PyFunction_SetClosure(PyObject *op, PyObject *closure)
|
|||
closure->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
Py_XDECREF(((PyFunctionObject *) op) -> func_closure);
|
||||
((PyFunctionObject *) op) -> func_closure = closure;
|
||||
Py_SETREF(((PyFunctionObject *)op)->func_closure, closure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -224,8 +221,7 @@ PyFunction_SetAnnotations(PyObject *op, PyObject *annotations)
|
|||
"non-dict annotations");
|
||||
return -1;
|
||||
}
|
||||
Py_XDECREF(((PyFunctionObject *)op) -> func_annotations);
|
||||
((PyFunctionObject *) op) -> func_annotations = annotations;
|
||||
Py_SETREF(((PyFunctionObject *)op)->func_annotations, annotations);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -531,8 +527,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
|
|||
|
||||
if (name != Py_None) {
|
||||
Py_INCREF(name);
|
||||
Py_DECREF(newfunc->func_name);
|
||||
newfunc->func_name = name;
|
||||
Py_SETREF(newfunc->func_name, name);
|
||||
}
|
||||
if (defaults != Py_None) {
|
||||
Py_INCREF(defaults);
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict,
|
|||
return -1;
|
||||
if (PyUnicode_CheckExact(name)) {
|
||||
Py_INCREF(name);
|
||||
Py_XDECREF(mod->md_name);
|
||||
mod->md_name = name;
|
||||
Py_SETREF(mod->md_name, name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1066,8 +1066,7 @@ longrangeiter_next(longrangeiterobject *r)
|
|||
result = PyNumber_Add(r->start, product);
|
||||
Py_DECREF(product);
|
||||
if (result) {
|
||||
Py_DECREF(r->index);
|
||||
r->index = new_index;
|
||||
Py_SETREF(r->index, new_index);
|
||||
}
|
||||
else {
|
||||
Py_DECREF(new_index);
|
||||
|
|
|
|||
|
|
@ -315,9 +315,8 @@ assign_version_tag(PyTypeObject *type)
|
|||
are borrowed reference */
|
||||
for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
|
||||
method_cache[i].value = NULL;
|
||||
Py_XDECREF(method_cache[i].name);
|
||||
method_cache[i].name = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
Py_SETREF(method_cache[i].name, Py_None);
|
||||
}
|
||||
/* mark all version tags as invalid */
|
||||
PyType_Modified(&PyBaseObject_Type);
|
||||
|
|
@ -462,8 +461,7 @@ type_set_qualname(PyTypeObject *type, PyObject *value, void *context)
|
|||
|
||||
et = (PyHeapTypeObject*)type;
|
||||
Py_INCREF(value);
|
||||
Py_DECREF(et->ht_qualname);
|
||||
et->ht_qualname = value;
|
||||
Py_SETREF(et->ht_qualname, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2910,8 +2908,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
|
|||
else
|
||||
method_cache_misses++;
|
||||
#endif
|
||||
Py_DECREF(method_cache[h].name);
|
||||
method_cache[h].name = name;
|
||||
Py_SETREF(method_cache[h].name, name);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1665,8 +1665,7 @@ unicode_resize(PyObject **p_unicode, Py_ssize_t length)
|
|||
_Py_INCREF_UNICODE_EMPTY();
|
||||
if (!unicode_empty)
|
||||
return -1;
|
||||
Py_DECREF(*p_unicode);
|
||||
*p_unicode = unicode_empty;
|
||||
Py_SETREF(*p_unicode, unicode_empty);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1674,8 +1673,7 @@ unicode_resize(PyObject **p_unicode, Py_ssize_t length)
|
|||
PyObject *copy = resize_copy(unicode, length);
|
||||
if (copy == NULL)
|
||||
return -1;
|
||||
Py_DECREF(*p_unicode);
|
||||
*p_unicode = copy;
|
||||
Py_SETREF(*p_unicode, copy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -13322,8 +13320,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
|
|||
return -1;
|
||||
_PyUnicode_FastCopyCharacters(newbuffer, 0,
|
||||
writer->buffer, 0, writer->pos);
|
||||
Py_DECREF(writer->buffer);
|
||||
writer->buffer = newbuffer;
|
||||
Py_SETREF(writer->buffer, newbuffer);
|
||||
}
|
||||
_PyUnicodeWriter_Update(writer);
|
||||
return 0;
|
||||
|
|
@ -15009,8 +15006,7 @@ PyUnicode_InternInPlace(PyObject **p)
|
|||
|
||||
if (t) {
|
||||
Py_INCREF(t);
|
||||
Py_DECREF(*p);
|
||||
*p = t;
|
||||
Py_SETREF(*p, t);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue