FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-102660: Fix is_core_module() by ericsnowcurrently · Pull Request #103257 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 13 additions & 1 deletion Python/import.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,17 @@ get_core_module_dict(PyInterpreterState *interp,
static inline int
is_core_module(PyInterpreterState *interp, PyObject *name, PyObject *filename)
{
return get_core_module_dict(interp, name, filename) != NULL;
/* This might be called before the core dict copies are in place,
so we can't rely on get_core_module_dict() here. */
if (filename == name) {
if (PyUnicode_CompareWithASCIIString(name, "sys") == 0) {
return 1;
}
if (PyUnicode_CompareWithASCIIString(name, "builtins") == 0) {
return 1;
}
}
return 0;
}

static int
Expand All @@ -1136,6 +1146,8 @@ fix_up_extension(PyObject *mod, PyObject *name, PyObject *filename)
// when the extension module doesn't support sub-interpreters.
if (def->m_size == -1) {
if (!is_core_module(tstate->interp, name, filename)) {
assert(PyUnicode_CompareWithASCIIString(name, "sys") != 0);
assert(PyUnicode_CompareWithASCIIString(name, "builtins") != 0);
if (def->m_base.m_copy) {
/* Somebody already imported the module,
likely under a different name.
Expand Down

Back | FazBrowse Home | New Git URL