The Wayback Machine - https://web.archive.org/web/20230819191537/https://github.com/python/cpython/pull/28089
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Aug 31, 2021
Merged

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

merged 2 commits into from Aug 31, 2021

Conversation

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

cc @ambv @corona10

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

@ambv: Sure, I changed the error message.

@vstinner vstinner merged commit 4300352 into python:main Aug 31, 2021
@vstinner
Copy link
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.

None yet

5 participants