Skip to content

bpo-45061: Detect Py_DECREF(Py_True) bug#28089

Merged
vstinner merged 2 commits intopython:mainfrom
vstinner:bool_dealloc
Aug 31, 2021
Merged

bpo-45061: Detect Py_DECREF(Py_True) bug#28089
vstinner merged 2 commits intopython:mainfrom
vstinner:bool_dealloc

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Aug 31, 2021

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.

https://bugs.python.org/issue45061

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.
@vstinner
Copy link
Copy Markdown
Member Author

cc @ambv @corona10

@vstinner
Copy link
Copy Markdown
Member Author

vstinner commented Aug 31, 2021

Using os_uname_refcount_bug.patch of bpo-45061, I get the following error message:

Fatal Python error: bool_dealloc: deallocating True or False likely caused by refcount bug in a C extension

@vstinner
Copy link
Copy Markdown
Member Author

It is not possible to create a subclass of bool:

>>> class MyBool(bool): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type 'bool' is not an acceptable base type

static void _Py_NO_RETURN
bool_dealloc(PyObject* Py_UNUSED(ignore))
{
Py_FatalError("deallocating True or False likely caused by refcount bug "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Py_FatalError("deallocating True or False likely caused by refcount bug "
Py_FatalError("deallocating True or False likely caused by a refcount bug "

Objects/object.c Outdated
* we accidentally decref None out of existence.
*/
Py_FatalError("deallocating None");
Py_FatalError("deallocating None likely caused by refcount bug "
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Py_FatalError("deallocating None likely caused by refcount bug "
Py_FatalError("deallocating None likely caused by a refcount bug "

Copy link
Copy Markdown
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Copy Markdown
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with @ambv's suggestion ;)

@vstinner
Copy link
Copy Markdown
Member Author

@ambv: Sure, I changed the error message.

@vstinner vstinner merged commit 4300352 into python:main Aug 31, 2021
@vstinner
Copy link
Copy Markdown
Member Author

Merged. Thanks for the reviews! I don't think that it's worth it to backport it to 3.10, it's a new feature.

@vstinner vstinner deleted the bool_dealloc branch August 31, 2021 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants