@@ -153,7 +153,6 @@ static const struct filedescr _PyImport_StandardFiletab[] = {
153153};
154154
155155static PyObject * initstr = NULL ;
156- _Py_IDENTIFIER (__path__ );
157156
158157/* Initialize things */
159158
@@ -3106,12 +3105,12 @@ PyImport_ReloadModule(PyObject *m)
31063105 PyInterpreterState * interp = PyThreadState_Get ()-> interp ;
31073106 PyObject * modules_reloading = interp -> modules_reloading ;
31083107 PyObject * modules = PyImport_GetModuleDict ();
3109- PyObject * path_list = NULL , * loader = NULL , * existing_m = NULL ;
3110- PyObject * name , * bufobj , * subname ;
3108+ PyObject * loader = NULL , * existing_m = NULL ;
3109+ PyObject * name ;
31113110 Py_ssize_t subname_start ;
3112- struct filedescr * fdp ;
3113- FILE * fp = NULL ;
31143111 PyObject * newm = NULL ;
3112+ _Py_IDENTIFIER (__loader__ );
3113+ _Py_IDENTIFIER (load_module );
31153114
31163115 if (modules_reloading == NULL ) {
31173116 Py_FatalError ("PyImport_ReloadModule: "
@@ -3149,51 +3148,28 @@ PyImport_ReloadModule(PyObject *m)
31493148
31503149 subname_start = PyUnicode_FindChar (name , '.' , 0 ,
31513150 PyUnicode_GET_LENGTH (name ), -1 );
3152- if (subname_start == -1 ) {
3153- Py_INCREF (name );
3154- subname = name ;
3155- }
3156- else {
3151+ if (subname_start != -1 ) {
31573152 PyObject * parentname , * parent ;
3158- Py_ssize_t len ;
31593153 parentname = PyUnicode_Substring (name , 0 , subname_start );
31603154 if (parentname == NULL ) {
31613155 goto error ;
31623156 }
31633157 parent = PyDict_GetItem (modules , parentname );
3158+ Py_XDECREF (parent );
31643159 if (parent == NULL ) {
31653160 PyErr_Format (PyExc_ImportError ,
31663161 "reload(): parent %R not in sys.modules" ,
31673162 parentname );
3168- Py_DECREF (parentname );
31693163 goto error ;
31703164 }
3171- Py_DECREF (parentname );
3172- path_list = _PyObject_GetAttrId (parent , & PyId___path__ );
3173- if (path_list == NULL )
3174- PyErr_Clear ();
3175- subname_start ++ ;
3176- len = PyUnicode_GET_LENGTH (name ) - (subname_start + 1 );
3177- subname = PyUnicode_Substring (name , subname_start , len );
31783165 }
3179- if (subname == NULL )
3180- goto error ;
3181- fdp = find_module (name , subname , path_list ,
3182- & bufobj , & fp , & loader );
3183- Py_DECREF (subname );
3184- Py_XDECREF (path_list );
31853166
3186- if ( fdp == NULL ) {
3187- Py_XDECREF (loader );
3167+ loader = _PyObject_GetAttrId ( m , & PyId___loader__ );
3168+ if (loader == NULL ) {
31883169 goto error ;
31893170 }
3190-
3191- newm = load_module (name , fp , bufobj , fdp -> type , loader );
3192- Py_XDECREF (bufobj );
3193- Py_XDECREF (loader );
3194-
3195- if (fp )
3196- fclose (fp );
3171+ newm = _PyObject_CallMethodId (loader , & PyId_load_module , "O" , name );
3172+ Py_DECREF (loader );
31973173 if (newm == NULL ) {
31983174 /* load_module probably removed name from modules because of
31993175 * the error. Put back the original module object. We're
0 commit comments