@@ -982,21 +982,27 @@ static PyObject *
982
982
get_core_module_dict (PyInterpreterState * interp ,
983
983
PyObject * name , PyObject * filename )
984
984
{
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 ;
985
+ /* Only builtin modules are core. */
986
+ if (filename == name ) {
987
+ assert (!PyErr_Occurred ());
988
+ if (PyUnicode_CompareWithASCIIString (name , "sys" ) == 0 ) {
989
+ return interp -> sysdict_copy ;
990
+ }
991
+ assert (!PyErr_Occurred ());
992
+ if (PyUnicode_CompareWithASCIIString (name , "builtins" ) == 0 ) {
993
+ return interp -> builtins_copy ;
994
+ }
995
+ assert (!PyErr_Occurred ());
995
996
}
996
- assert (!PyErr_Occurred ());
997
997
return 0 ;
998
998
}
999
999
1000
+ static inline int
1001
+ is_core_module (PyInterpreterState * interp , PyObject * name , PyObject * filename )
1002
+ {
1003
+ return get_core_module_dict (interp , name , filename ) == NULL ;
1004
+ }
1005
+
1000
1006
static int
1001
1007
fix_up_extension (PyObject * mod , PyObject * name , PyObject * filename )
1002
1008
{
@@ -1019,9 +1025,8 @@ fix_up_extension(PyObject *mod, PyObject *name, PyObject *filename)
1019
1025
// bpo-44050: Extensions and def->m_base.m_copy can be updated
1020
1026
// when the extension module doesn't support sub-interpreters.
1021
1027
// XXX Why special-case the main interpreter?
1022
- if (_Py_IsMainInterpreter (tstate -> interp ) || def -> m_size == -1 ) {
1023
- /* m_copy of Py_None means it is copied some other way. */
1024
- if (def -> m_size == -1 && def -> m_base .m_copy != Py_None ) {
1028
+ if (def -> m_size == -1 ) {
1029
+ if (!is_core_module (tstate -> interp , name , filename )) {
1025
1030
if (def -> m_base .m_copy ) {
1026
1031
/* Somebody already imported the module,
1027
1032
likely under a different name.
@@ -1037,7 +1042,9 @@ fix_up_extension(PyObject *mod, PyObject *name, PyObject *filename)
1037
1042
return -1 ;
1038
1043
}
1039
1044
}
1045
+ }
1040
1046
1047
+ if (_Py_IsMainInterpreter (tstate -> interp ) || def -> m_size == -1 ) {
1041
1048
if (_extensions_cache_set (filename , name , def ) < 0 ) {
1042
1049
return -1 ;
1043
1050
}
@@ -1078,12 +1085,8 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
1078
1085
PyObject * m_copy = def -> m_base .m_copy ;
1079
1086
/* Module does not support repeated initialization */
1080
1087
if (m_copy == NULL ) {
1081
- return NULL ;
1082
- }
1083
- else if (m_copy == Py_None ) {
1084
1088
m_copy = get_core_module_dict (tstate -> interp , name , filename );
1085
1089
if (m_copy == NULL ) {
1086
- _PyErr_SetString (tstate , PyExc_ImportError , "missing m_copy" );
1087
1090
return NULL ;
1088
1091
}
1089
1092
}
0 commit comments