@@ -121,7 +121,7 @@ typedef unsigned short mode_t;
121121static long pyc_magic = MAGIC ;
122122static const char * pyc_tag = TAG ;
123123
124- /* See _PyImport_FixupExtension () below */
124+ /* See _PyImport_FixupExtensionUnicode () below */
125125static PyObject * extensions = NULL ;
126126
127127/* This table is defined in config.c: */
@@ -561,10 +561,10 @@ PyImport_GetMagicTag(void)
561561 once, we keep a static dictionary 'extensions' keyed by module name
562562 (for built-in modules) or by filename (for dynamically loaded
563563 modules), containing these modules. A copy of the module's
564- dictionary is stored by calling _PyImport_FixupExtension ()
564+ dictionary is stored by calling _PyImport_FixupExtensionUnicode ()
565565 immediately after the module initialization function succeeds. A
566566 copy can be retrieved from there by calling
567- _PyImport_FindExtension ().
567+ _PyImport_FindExtensionUnicode ().
568568
569569 Modules which do support multiple initialization set their m_size
570570 field to a non-negative number (indicating the size of the
@@ -573,7 +573,7 @@ PyImport_GetMagicTag(void)
573573*/
574574
575575int
576- _PyImport_FixupExtension (PyObject * mod , char * name , char * filename )
576+ _PyImport_FixupExtensionUnicode (PyObject * mod , char * name , PyObject * filename )
577577{
578578 PyObject * modules , * dict ;
579579 struct PyModuleDef * def ;
@@ -613,18 +613,31 @@ _PyImport_FixupExtension(PyObject *mod, char *name, char *filename)
613613 if (def -> m_base .m_copy == NULL )
614614 return -1 ;
615615 }
616- PyDict_SetItemString (extensions , filename , (PyObject * )def );
616+ PyDict_SetItem (extensions , filename , (PyObject * )def );
617617 return 0 ;
618618}
619619
620+ int
621+ _PyImport_FixupBuiltin (PyObject * mod , char * name )
622+ {
623+ int res ;
624+ PyObject * filename ;
625+ filename = PyUnicode_FromString (name );
626+ if (filename == NULL )
627+ return -1 ;
628+ res = _PyImport_FixupExtensionUnicode (mod , name , filename );
629+ Py_DECREF (filename );
630+ return res ;
631+ }
632+
620633PyObject *
621- _PyImport_FindExtension (char * name , char * filename )
634+ _PyImport_FindExtensionUnicode (char * name , PyObject * filename )
622635{
623636 PyObject * mod , * mdict ;
624637 PyModuleDef * def ;
625638 if (extensions == NULL )
626639 return NULL ;
627- def = (PyModuleDef * )PyDict_GetItemString (extensions , filename );
640+ def = (PyModuleDef * )PyDict_GetItem (extensions , filename );
628641 if (def == NULL )
629642 return NULL ;
630643 if (def -> m_size == -1 ) {
@@ -655,12 +668,23 @@ _PyImport_FindExtension(char *name, char *filename)
655668 return NULL ;
656669 }
657670 if (Py_VerboseFlag )
658- PySys_WriteStderr ("import %s # previously loaded (%s )\n" ,
671+ PySys_FormatStderr ("import %s # previously loaded (%U )\n" ,
659672 name , filename );
660673 return mod ;
661674
662675}
663676
677+ PyObject *
678+ _PyImport_FindBuiltin (char * name )
679+ {
680+ PyObject * res , * filename ;
681+ filename = PyUnicode_FromString (name );
682+ if (filename == NULL )
683+ return NULL ;
684+ res = _PyImport_FindExtensionUnicode (name , filename );
685+ Py_DECREF (filename );
686+ return res ;
687+ }
664688
665689/* Get the module object corresponding to a module name.
666690 First check the modules dictionary if there's one there,
@@ -2121,7 +2145,7 @@ init_builtin(char *name)
21212145{
21222146 struct _inittab * p ;
21232147
2124- if (_PyImport_FindExtension ( name , name ) != NULL )
2148+ if (_PyImport_FindBuiltin ( name ) != NULL )
21252149 return 1 ;
21262150
21272151 for (p = PyImport_Inittab ; p -> name != NULL ; p ++ ) {
@@ -2138,7 +2162,7 @@ init_builtin(char *name)
21382162 mod = (* p -> initfunc )();
21392163 if (mod == 0 )
21402164 return -1 ;
2141- if (_PyImport_FixupExtension (mod , name , name ) < 0 )
2165+ if (_PyImport_FixupBuiltin (mod , name ) < 0 )
21422166 return -1 ;
21432167 /* FixupExtension has put the module into sys.modules,
21442168 so we can release our own reference. */
0 commit comments