Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-105922: PyImport_AddModule() uses Py_DECREF()
Rewrite PyImport_AddModule() to simply call Py_DECREF(), rather than
creating a weak reference,  to get a borrowed reference to the
module.
  • Loading branch information
vstinner committed Jun 22, 2023
commit cef28f1c62a75b6ba867ecc7aa989f51ea0930e9
11 changes: 1 addition & 10 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,7 @@ PyImport_AddModuleObject(PyObject *name)
if (!mod) {
return NULL;
}

// gh-86160: PyImport_AddModuleObject() returns a borrowed reference
PyObject *ref = PyWeakref_NewRef(mod, NULL);
Py_DECREF(mod);
if (ref == NULL) {
return NULL;
}

mod = PyWeakref_GetObject(ref);
Py_DECREF(ref);
Py_DECREF(mod); // sys.modules holds a strong reference
return mod; /* borrowed reference */
}

Expand Down