@@ -978,11 +978,20 @@ _PyImport_CheckSubinterpIncompatibleExtensionAllowed(const char *name)
978
978
return 0 ;
979
979
}
980
980
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 )
983
984
{
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 ;
986
995
}
987
996
assert (!PyErr_Occurred ());
988
997
return 0 ;
@@ -1072,13 +1081,8 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
1072
1081
return NULL ;
1073
1082
}
1074
1083
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 ) {
1082
1086
_PyErr_SetString (tstate , PyExc_ImportError , "missing m_copy" );
1083
1087
return NULL ;
1084
1088
}
0 commit comments