[issue35459] Use PyDict_GetItemWithError() with PyDict_GetItem()

Serhiy Storchaka report at bugs.python.org
Tue Dec 11 05:54:17 EST 2018


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

There is an issue with using PyDict_GetItem(). Since it silences all exceptions, it can return incorrect result when an exception like MemoryError or KeyboardInterrupt was raised in the user __hash__() and __eq__(). In addition PyDict_GetItemString() and _PyDict_GetItemId() swallow a MemoryError raised when fail to allocate a temporary string object.

In addition, PyDict_GetItemWithError() is a tiny bit faster than PyDict_GetItem(), because it avoids checking the exception state in successful case.

The proposed PR replaces most calls of PyDict_GetItem(), PyDict_GetItemString() and _PyDict_GetItemId() with calls of PyDict_GetItemWithError(), _PyDict_GetItemStringWithError() and _PyDict_GetItemIdWithError().

----------
components: Extension Modules, Interpreter Core
messages: 331604
nosy: serhiy.storchaka, vstinner
priority: normal
severity: normal
status: open
title: Use PyDict_GetItemWithError() with PyDict_GetItem()
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35459>
_______________________________________


More information about the Python-bugs-list mailing list