bpo-33330: PyImport_Cleanup check for exc leaks#7068
Conversation
* Add "assert(!PyErr_Occurred());" assertions to PyImport_Cleanup() and _PyGC_CollectNoFail() to make sure that these functions don't leak exceptions. * Replace also PyImport_GetModuleDict() call with interp->modules to prevent a fatal error if modules is already NULL.
|
The commit d393c1b replaced interp->modules with PyImport_GetModuleDict(), but this function fails with a fatal error if modules is NULL. I'm not sure that it was a deliberate change. Moreover, this commit has been partially reverted (interp->modules is back!). |
Sorry, something went wrong.
|
PyImport_Cleanup() is part of the public API, but it's documented as "Empty the module table. For internal use only." :-( Why do we have public API for internal use only? Likely a mistake from the past. |
Sorry, something went wrong.
|
I would left only few asserts after calls that can raise exceptions if the third-party code has bugs. And one at the end of |
Sorry, something went wrong.
|
The last 2 years, I added many "assert(!PyErr_Occurred());" in ceval.c and object.c, and it helped me a lot to detect some very old bugs. The rationale here is the same. |
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, except that GC is covered by a separate PR.
Sorry, something went wrong.
I will wait until #7126 is merged, and then rebase this PR on top of it. |
Sorry, something went wrong.
|
Why not rebase and merge this PR? |
Sorry, something went wrong.
|
It's just that I wrote it 2 months ago, and I lost interest in this minor enhancement in the meanwhile. I'm trying to reduce my number of open PRs. Feel free to reuse my patch to create a new PR if you want. |
Sorry, something went wrong.
and _PyGC_CollectNoFail() to make sure that these functions don't
leak exceptions.
prevent a fatal error if modules is already NULL.
https://bugs.python.org/issue33330