--- /dev/null
+Add a deallocator to the :class:`bool` type to detect refcount bugs in C
+extensions which call ``Py_DECREF(Py_True);`` or ``Py_DECREF(Py_False);`` by
+mistake. Patch by Victor Stinner.
0, /* nb_index */
};
+static void _Py_NO_RETURN
+bool_dealloc(PyObject* Py_UNUSED(ignore))
+{
+ Py_FatalError("deallocating True or False likely caused by "
+ "a refcount bug in a C extension");
+}
+
/* The type object for bool. Note that this cannot be subclassed! */
PyTypeObject PyBool_Type = {
"bool",
sizeof(struct _longobject),
0,
- 0, /* tp_dealloc */
+ bool_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
return PyUnicode_FromString("None");
}
-/* ARGUSED */
static void _Py_NO_RETURN
-none_dealloc(PyObject* ignore)
+none_dealloc(PyObject* Py_UNUSED(ignore))
{
- /* This should never get called, but we also don't want to SEGV if
- * we accidentally decref None out of existence.
- */
- Py_FatalError("deallocating None");
+ Py_FatalError("deallocating None likely caused by a refcount bug "
+ "in a C extension");
}
static PyObject *