Skip to content

gh-105927: PyImport_AddModule() uses _PyWeakref_GET_REF() - #106001

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:getref_add_module
Jun 22, 2023
Merged

gh-105927: PyImport_AddModule() uses _PyWeakref_GET_REF()#106001
vstinner merged 1 commit into
python:mainfrom
vstinner:getref_add_module

Conversation

@vstinner

@vstinnervstinner commented Jun 22, 2023

Copy link
Copy Markdown
Member

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.
@vstinner
vstinner merged commit ee52158 into python:mainJun 22, 2023
@vstinner
vstinner deleted the getref_add_module branch June 22, 2023 23:23
Comment threadPython/import.c
Py_DECREF(ref);
Py_XDECREF(mod);

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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