8000 [3.13] gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) by miss-islington · Pull Request #120652 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] gh-115649: Copy the filename into main interp 8000 reter before intern in import.c (GH-120315) #120652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
gh-115649: Copy the filename into main interpreter before intern in i…
…mport.c (GH-120315)

(cherry picked from commit 28140d1)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
  • Loading branch information
2 people authored and miss-islington committed Jun 17, 2024
commit 25d87323079a9af7cb64c5510256b07c807c2529
2 changes: 2 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,8 @@ def test_single_init_extension_compat(self):
self.check_incompatible_here(module)
with self.subTest(f'{module}: strict, fresh'):
self.check_incompatible_fresh(module)
with self.subTest(f'{module}: isolated, fresh'):
self.check_incompatible_fresh(module, isolated=True)

@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
def test_multi_init_extension_compat(self):
Expand Down
12 changes: 11 additions & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,17 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
if (info->filename != NULL) {
// XXX There's a refleak somewhere with the filename.
// Until we can track it down, we intern it.
PyObject *filename = Py_NewRef(info->filename);
PyObject *filename = NULL;
if (switched) {
// The original filename may be allocated by subinterpreter's
// obmalloc, so we create a copy here.
filename = _PyUnicode_Copy(info->filename);
if (filename == NULL) {
return NULL;
}
} else {
filename = Py_NewRef(info->filename);
}
PyUnicode_InternInPlace(&filename);
if (PyModule_AddObjectRef(mod, "__file__", filename) < 0) {
PyErr_Clear(); /* Not important enough to report */
Expand Down
Loading
0