mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-45061: Detect Py_DECREF(Py_True) bug (GH-28089)
Add a deallocator to the bool type to detect refcount bugs in C extensions which call Py_DECREF(Py_True) or Py_DECREF(Py_False) by mistake.
This commit is contained in:
parent
9a7ec2fcde
commit
4300352000
3 changed files with 14 additions and 7 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
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.
|
|
@ -153,6 +153,13 @@ static PyNumberMethods bool_as_number = {
|
||||||
0, /* nb_index */
|
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! */
|
/* The type object for bool. Note that this cannot be subclassed! */
|
||||||
|
|
||||||
PyTypeObject PyBool_Type = {
|
PyTypeObject PyBool_Type = {
|
||||||
|
@ -160,7 +167,7 @@ PyTypeObject PyBool_Type = {
|
||||||
"bool",
|
"bool",
|
||||||
sizeof(struct _longobject),
|
sizeof(struct _longobject),
|
||||||
0,
|
0,
|
||||||
0, /* tp_dealloc */
|
bool_dealloc, /* tp_dealloc */
|
||||||
0, /* tp_vectorcall_offset */
|
0, /* tp_vectorcall_offset */
|
||||||
0, /* tp_getattr */
|
0, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
|
|
|
@ -1560,14 +1560,11 @@ none_repr(PyObject *op)
|
||||||
return PyUnicode_FromString("None");
|
return PyUnicode_FromString("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ARGUSED */
|
|
||||||
static void _Py_NO_RETURN
|
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
|
Py_FatalError("deallocating None likely caused by a refcount bug "
|
||||||
* we accidentally decref None out of existence.
|
"in a C extension");
|
||||||
*/
|
|
||||||
Py_FatalError("deallocating None");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue