-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-109521: Fix obscure cases handling in PyImport_GetImporter() #109522
gh-109521: Fix obscure cases handling in PyImport_GetImporter() #109522
Conversation
PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingle. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I left minor remarks.
Misc/NEWS.d/next/C API/2023-09-17-21-47-31.gh-issue-109521.JDF6i9.rst
Outdated
Show resolved
Hide resolved
PyErr_SetString(PyExc_RuntimeError, "sys.path_hooks is not a list"); | ||
return NULL; | ||
} | ||
if (!PyDict_Check(path_importer_cache)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might replace PyDict_GetItemWithError() with PyDict_GetItemRef() below to avoid _PyErr_Occurred() call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to backport this change.
BTW, I have a separate branch in which most of PyDict_GetItemWithError()
are replaced with PyDict_GetItemRef()
. I will make a PR or several PRs from it in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to backport this change.
Oh right. In this case, just ignore my remark. It's more a "coding style" change than a fix, the current code is correct.
…6i9.rst Co-authored-by: Victor Stinner <vstinner@python.org>
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
…pythonGH-109522) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type. (cherry picked from commit 62c7015) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-109777 is a backport of this pull request to the 3.12 branch. |
|
…orter() (pythonGH-109522) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type.. (cherry picked from commit 62c7015) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-109781 is a backport of this pull request to the 3.11 branch. |
…pythonGH-109522) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type.
GH-109522) (#109777) gh-109521: Fix obscure cases handling in PyImport_GetImporter() (GH-109522) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type. (cherry picked from commit 62c7015) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-109522) (GH-109781) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type. (cherry picked from commit 62c7015)
…pythonGH-109522) PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingly. Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type.
PyImport_GetImporter() now sets RuntimeError if it fails to get sys.path_hooks or sys.path_importer_cache or they are not list and dict correspondingle.
Previously it could return NULL without setting error in obscure cases, crash or raise SystemError if these attributes have wrong type.