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
// 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.