Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for

tp_clear methods.
This commit is contained in:
Thomas Wouters 2006-04-15 17:28:34 +00:00
parent ed8f783126
commit edf17d8798
8 changed files with 30 additions and 57 deletions

View file

@ -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;
}