Skip to content

Commit 0512932

Browse files
match_mod_name() -> get_core_module_dict().
1 parent 61b9ff3 commit 0512932

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Python/import.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,20 @@ _PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
978978
return 0;
979979
}
980980

981-
static inline int
982-
match_mod_name(PyObject *actual, const char *expected)
981+
static PyObject *
982+
get_core_module_dict(PyInterpreterState *interp,
983+
PyObject *name, PyObject *filename)
983984
{
984-
if (PyUnicode_CompareWithASCIIString(actual, expected) == 0) {
985-
return 1;
985+
if (filename != name && filename != NULL) {
986+
/* It isn't a builtin module, which means it isn't core. */
987+
return 0;
988+
}
989+
if (PyUnicode_CompareWithASCIIString(name, "sys") == 0) {
990+
return interp->sysdict_copy;
991+
}
992+
assert(!PyErr_Occurred());
993+
if (PyUnicode_CompareWithASCIIString(name, "builtins") == 0) {
994+
return interp->builtins_copy;
986995
}
987996
assert(!PyErr_Occurred());
988997
return 0;
@@ -1072,13 +1081,8 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
10721081
return NULL;
10731082
}
10741083
else if (m_copy == Py_None) {
1075-
if (match_mod_name(name, "sys")) {
1076-
m_copy = tstate->interp->sysdict_copy;
1077-
}
1078-
else if (match_mod_name(name, "builtins")) {
1079-
m_copy = tstate->interp->builtins_copy;
1080-
}
1081-
else {
1084+
m_copy = get_core_module_dict(tstate->interp, name, filename);
1085+
if (m_copy == NULL) {
10821086
_PyErr_SetString(tstate, PyExc_ImportError, "missing m_copy");
10831087
return NULL;
10841088
}

0 commit comments

Comments
 (0)