This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fixes for PyObject_GetItem()
Type: Stage: commit review
Components: Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vstinner Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2015-11-05 09:52 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pyobject_getitem.patch vstinner, 2015-11-05 10:11 review
Messages (10)
msg254094 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-05 09:52
Attached patch adds assertions to PyObject_GetItem() to ensure that an exception is raised if the function failed. _Py_CheckFunctionResult() could be used to implement such check, but it might adds a little overhead, whereas I really don't think that such bug occurs in the wild. The assertion only helps when you develop a new custom type implementing the mapping API.

The patch also simplifies Python/ceval.c: it now considers that an exception is raised if PyObject_GetItem() returns NULL.

Finally, the patch also fixes a bug in the LOAD_NAME bytecode, when globals are not a dict but a custom type and the name doesn't exist in globals: clear the exception before calling PyObject_GetItem() on builtins.
msg254096 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-05 09:59
Where is a patch?
msg254098 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-05 10:11
Oops, sorry. It's now attached to the issue :-)
msg254105 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-05 12:50
LGTM. The fix for LOAD_GLOBAL should be applied for all versions.
msg254106 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-05 13:02
New changeset 1e87bcf20707 by Victor Stinner in branch '3.5':
Issue #25556: Fix LOAD_GLOBAL bytecode when globals type is not dict and the
https://hg.python.org/cpython/rev/1e87bcf20707

New changeset c1414f80ebc9 by Victor Stinner in branch 'default':
Issue #25556: Add assertions to PyObject_GetItem() to ensure that an exception
https://hg.python.org/cpython/rev/c1414f80ebc9
msg254108 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-05 13:03
> LGTM. The fix for LOAD_GLOBAL should be applied for all versions.

Thanks for the review. I applied the LOAD_GLOBAL fix to Python 3.5 and 3.6. Python 2.7 doesn't support globals not being dict.
msg254109 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-05 13:05
What about 3.4?
msg254110 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-05 13:06
> What about 3.4?

I consider it as almost dead (no more bugfixes), and this really is really a corner case. Except me, I don't think that anyone uses globals which are not dict :-D (It never worked...)
msg254111 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-05 13:32
In issue25557 I mentioned that there is the same error for globals which are dict.
msg254113 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-11-05 13:39
> In issue25557 I mentioned that there is the same error for globals which are dict.

This issue fixed a bug for LOAD_GLOBAL bytecode bytecode when globals are not dict. (Sorry, I wrote LOAD_NAME bytecode in my first message, it was a mistake.)

Please discuss the issue #25557 in the issue #issue25557. (I already replied there, I don't understand where you spotted a bug.)
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69742
2015-11-05 13:39:39vstinnersetmessages: + msg254113
2015-11-05 13:32:54serhiy.storchakasetmessages: + msg254111
2015-11-05 13:06:26vstinnersetmessages: + msg254110
2015-11-05 13:05:06serhiy.storchakasetmessages: + msg254109
2015-11-05 13:04:30vstinnersetstatus: open -> closed
resolution: fixed
versions: + Python 3.5
2015-11-05 13:03:08vstinnersetmessages: + msg254108
2015-11-05 13:02:24python-devsetnosy: + python-dev
messages: + msg254106
2015-11-05 12:50:17serhiy.storchakasetassignee: vstinner
messages: + msg254105
stage: patch review -> commit review
2015-11-05 10:16:13serhiy.storchakasetstage: patch review
2015-11-05 10:11:57vstinnersetfiles: + pyobject_getitem.patch
keywords: + patch
messages: + msg254098
2015-11-05 09:59:53serhiy.storchakasetmessages: + msg254096
2015-11-05 09:52:03vstinnercreate