mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
tp_clear methods.
This commit is contained in:
parent
ed8f783126
commit
edf17d8798
8 changed files with 30 additions and 57 deletions
|
|
@ -559,8 +559,8 @@ clear_slots(PyTypeObject *type, PyObject *self)
|
|||
char *addr = (char *)self + mp->offset;
|
||||
PyObject *obj = *(PyObject **)addr;
|
||||
if (obj != NULL) {
|
||||
Py_DECREF(obj);
|
||||
*(PyObject **)addr = NULL;
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2236,13 +2236,6 @@ type_clear(PyTypeObject *type)
|
|||
for heaptypes. */
|
||||
assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
|
||||
|
||||
#define CLEAR(SLOT) \
|
||||
if (SLOT) { \
|
||||
tmp = (PyObject *)(SLOT); \
|
||||
SLOT = NULL; \
|
||||
Py_DECREF(tmp); \
|
||||
}
|
||||
|
||||
/* The only field we need to clear is tp_mro, which is part of a
|
||||
hard cycle (its first element is the class itself) that won't
|
||||
be broken otherwise (it's a tuple and tuples don't have a
|
||||
|
|
@ -2268,9 +2261,7 @@ type_clear(PyTypeObject *type)
|
|||
A tuple of strings can't be part of a cycle.
|
||||
*/
|
||||
|
||||
CLEAR(type->tp_mro);
|
||||
|
||||
#undef CLEAR
|
||||
Py_CLEAR(type->tp_mro);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue