Skip to content

Conversation

@isidentical
Copy link
Member

@isidentical isidentical commented Jul 13, 2019

clear error in _imp_create_dynamic_impl

https://bugs.python.org/issue35476

@isidentical isidentical changed the title bpo35476: clear error in _imp_create_dynamic_impl bpo-35476: clear error in _imp_create_dynamic_impl Jul 13, 2019

mod = _PyImport_FindExtensionObject(name, path);
if (mod != NULL || PyErr_Occurred()) {
if (PyErr_Occurred()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the overhead of calling PyErr_Occurred(), could you store the result in a variable and check that?

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is quite doing what @ericsnowcurrently meant when he said "the error should be cleared" as an option in the issue. Instead, I believe what he was thinking was that there be an elif (PyErr_Occurred()) clause to go after the if (mod != NULL) which then clears the exception.

if (mod != NULL || PyErr_Occurred()) {
if (PyErr_Occurred()) {
PyErr_Clear();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually won't work because since you cleared out the error but are returning NULL you will trigger a failure in the interpreter for saying there's an exception when one isn't set.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@brettcannon
Copy link
Member

I'm going to kick off a discussion over on the issue which I think may change the approach this PR takes.

mod = _PyImport_FindExtensionObject(name, path);
if (mod != NULL || PyErr_Occurred()) {
if (PyErr_Occurred()) {
PyErr_Clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started a discussion over on the issue where if I'm right and swallowing an exception is bad then this clearing of the exception should be removed.

@brettcannon
Copy link
Member

@isidentical please note the conversation on the issue is advocating for explicit exception raising, so that changes the approach you've taken here.

@brettcannon
Copy link
Member

CLosing as @ericsnowcurrently pointed out the current semantics cover the bug.

@isidentical isidentical deleted the bpo35476 branch December 7, 2019 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants