Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented Jun 22, 2023

It now raises an exception if sys.modules doesn't hold a strong reference to the module.

Elaborate the comment explaining why a weak reference is used to create a borrowed reference.

It now raises an exception if sys.modules doesn't hold a strong reference to the module. Elaborate the comment explaining why a weak reference is used to create a borrowed reference.
@vstinnervstinner merged commit ee52158 into python:mainJun 22, 2023
@vstinnervstinner deleted the getref_add_module branch June 22, 2023 23:23
Py_DECREF(ref);
Py_XDECREF(mod);

if (mod==NULL&& !PyErr_Occurred()){

Choose a reason for hiding this comment

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

I am not sure that comparing mod with NULL after Py_XDECREF does not have an undefined behavior. AFAIK, you can do nothing with a pointer to released memory, not even compare it with NULL.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

See comments of my PR #105998: IMO most of this code is useless and can be removed.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@serhiy-storchaka@bedevere-bot