@@ -117,7 +117,7 @@ typedef unsigned short mode_t;
117
117
static long pyc_magic = MAGIC ;
118
118
static const char * pyc_tag = TAG ;
119
119
120
- /* See _PyImport_FixupExtensionUnicode () below */
120
+ /* See _PyImport_FixupExtensionObject () below */
121
121
static PyObject * extensions = NULL ;
122
122
123
123
/* This table is defined in config.c: */
@@ -563,10 +563,10 @@ PyImport_GetMagicTag(void)
563
563
once, we keep a static dictionary 'extensions' keyed by module name
564
564
(for built-in modules) or by filename (for dynamically loaded
565
565
modules), containing these modules. A copy of the module's
566
- dictionary is stored by calling _PyImport_FixupExtensionUnicode ()
566
+ dictionary is stored by calling _PyImport_FixupExtensionObject ()
567
567
immediately after the module initialization function succeeds. A
568
568
copy can be retrieved from there by calling
569
- _PyImport_FindExtensionUnicode ().
569
+ _PyImport_FindExtensionObject ().
570
570
571
571
Modules which do support multiple initialization set their m_size
572
572
field to a non-negative number (indicating the size of the
@@ -575,7 +575,8 @@ PyImport_GetMagicTag(void)
575
575
*/
576
576
577
577
int
578
- _PyImport_FixupExtensionUnicode (PyObject * mod , char * name , PyObject * filename )
578
+ _PyImport_FixupExtensionObject (PyObject * mod , PyObject * name ,
579
+ PyObject * filename )
579
580
{
580
581
PyObject * modules , * dict ;
581
582
struct PyModuleDef * def ;
@@ -594,10 +595,10 @@ _PyImport_FixupExtensionUnicode(PyObject *mod, char *name, PyObject *filename)
594
595
return -1 ;
595
596
}
596
597
modules = PyImport_GetModuleDict ();
597
- if (PyDict_SetItemString (modules , name , mod ) < 0 )
598
+ if (PyDict_SetItem (modules , name , mod ) < 0 )
598
599
return -1 ;
599
600
if (_PyState_AddModule (mod , def ) < 0 ) {
600
- PyDict_DelItemString (modules , name );
601
+ PyDict_DelItem (modules , name );
601
602
return -1 ;
602
603
}
603
604
if (def -> m_size == -1 ) {
@@ -623,17 +624,17 @@ int
623
624
_PyImport_FixupBuiltin (PyObject * mod , char * name )
624
625
{
625
626
int res ;
626
- PyObject * filename ;
627
- filename = PyUnicode_FromString (name );
628
- if (filename == NULL )
627
+ PyObject * nameobj ;
628
+ nameobj = PyUnicode_FromString (name );
629
+ if (nameobj == NULL )
629
630
return -1 ;
630
- res = _PyImport_FixupExtensionUnicode (mod , name , filename );
631
- Py_DECREF (filename );
631
+ res = _PyImport_FixupExtensionObject (mod , nameobj , nameobj );
632
+ Py_DECREF (nameobj );
632
633
return res ;
633
634
}
634
635
635
636
PyObject *
636
- _PyImport_FindExtensionUnicode ( const char * name , PyObject * filename )
637
+ _PyImport_FindExtensionObject ( PyObject * name , PyObject * filename )
637
638
{
638
639
PyObject * mod , * mdict ;
639
640
PyModuleDef * def ;
@@ -646,7 +647,7 @@ _PyImport_FindExtensionUnicode(const char *name, PyObject *filename)
646
647
/* Module does not support repeated initialization */
647
648
if (def -> m_base .m_copy == NULL )
648
649
return NULL ;
649
- mod = PyImport_AddModule (name );
650
+ mod = PyImport_AddModuleObject (name );
650
651
if (mod == NULL )
651
652
return NULL ;
652
653
mdict = PyModule_GetDict (mod );
@@ -661,16 +662,16 @@ _PyImport_FindExtensionUnicode(const char *name, PyObject *filename)
661
662
mod = def -> m_base .m_init ();
662
663
if (mod == NULL )
663
664
return NULL ;
664
- PyDict_SetItemString (PyImport_GetModuleDict (), name , mod );
665
+ PyDict_SetItem (PyImport_GetModuleDict (), name , mod );
665
666
Py_DECREF (mod );
666
667
}
667
668
if (_PyState_AddModule (mod , def ) < 0 ) {
668
- PyDict_DelItemString (PyImport_GetModuleDict (), name );
669
+ PyDict_DelItem (PyImport_GetModuleDict (), name );
669
670
Py_DECREF (mod );
670
671
return NULL ;
671
672
}
672
673
if (Py_VerboseFlag )
673
- PySys_FormatStderr ("import %s # previously loaded (%U )\n" ,
674
+ PySys_FormatStderr ("import %U # previously loaded (%R )\n" ,
674
675
name , filename );
675
676
return mod ;
676
677
@@ -679,12 +680,12 @@ _PyImport_FindExtensionUnicode(const char *name, PyObject *filename)
679
680
PyObject *
680
681
_PyImport_FindBuiltin (const char * name )
681
682
{
682
- PyObject * res , * filename ;
683
- filename = PyUnicode_FromString (name );
684
- if (filename == NULL )
683
+ PyObject * res , * nameobj ;
684
+ nameobj = PyUnicode_FromString (name );
685
+ if (nameobj == NULL )
685
686
return NULL ;
686
- res = _PyImport_FindExtensionUnicode ( name , filename );
687
- Py_DECREF (filename );
687
+ res = _PyImport_FindExtensionObject ( nameobj , nameobj );
688
+ Py_DECREF (nameobj );
688
689
return res ;
689
690
}
690
691
@@ -1491,11 +1492,12 @@ load_package(char *name, char *pathname)
1491
1492
/* Helper to test for built-in module */
1492
1493
1493
1494
static int
1494
- is_builtin (char * name )
1495
+ is_builtin (PyObject * name )
1495
1496
{
1496
- int i ;
1497
+ int i , cmp ;
1497
1498
for (i = 0 ; PyImport_Inittab [i ].name != NULL ; i ++ ) {
1498
- if (strcmp (name , PyImport_Inittab [i ].name ) == 0 ) {
1499
+ cmp = PyUnicode_CompareWithASCIIString (name , PyImport_Inittab [i ].name );
1500
+ if (cmp == 0 ) {
1499
1501
if (PyImport_Inittab [i ].initfunc == NULL )
1500
1502
return -1 ;
1501
1503
else
@@ -1617,7 +1619,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
1617
1619
size_t saved_namelen ;
1618
1620
char * saved_buf = NULL ;
1619
1621
#endif
1620
- PyObject * fullname_obj ;
1622
+ PyObject * fullname_obj , * nameobj ;
1621
1623
1622
1624
if (p_loader != NULL )
1623
1625
* p_loader = NULL ;
@@ -1677,10 +1679,15 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
1677
1679
}
1678
1680
1679
1681
if (path == NULL ) {
1680
- if (is_builtin (name )) {
1682
+ nameobj = PyUnicode_FromString (name );
1683
+ if (nameobj == NULL )
1684
+ return NULL ;
1685
+ if (is_builtin (nameobj )) {
1686
+ Py_DECREF (nameobj );
1681
1687
strcpy (buf , name );
1682
1688
return & fd_builtin ;
1683
1689
}
1690
+ Py_DECREF (nameobj );
1684
1691
#ifdef MS_COREDLL
1685
1692
fp = _PyWin_FindRegisteredModule (name , & fdp , buf , buflen );
1686
1693
if (fp != NULL ) {
@@ -2086,40 +2093,35 @@ find_init_module(char *buf)
2086
2093
#endif /* HAVE_STAT */
2087
2094
2088
2095
2089
- static int init_builtin (char * ); /* Forward */
2096
+ static int init_builtin (PyObject * ); /* Forward */
2090
2097
2091
2098
static PyObject *
2092
- load_builtin (char * name , char * pathname , int type )
2099
+ load_builtin (PyObject * name , int type )
2093
2100
{
2094
2101
PyObject * m , * modules ;
2095
2102
int err ;
2096
2103
2097
- if (pathname != NULL && pathname [0 ] != '\0' )
2098
- name = pathname ;
2099
-
2100
2104
if (type == C_BUILTIN )
2101
2105
err = init_builtin (name );
2102
2106
else
2103
- err = PyImport_ImportFrozenModule (name );
2107
+ err = PyImport_ImportFrozenModuleObject (name );
2104
2108
if (err < 0 )
2105
2109
return NULL ;
2106
2110
if (err == 0 ) {
2107
2111
PyErr_Format (PyExc_ImportError ,
2108
- "Purported %s module %.200s not found" ,
2109
- type == C_BUILTIN ?
2110
- "builtin" : "frozen" ,
2112
+ "Purported %s module %R not found" ,
2113
+ type == C_BUILTIN ? "builtin" : "frozen" ,
2111
2114
name );
2112
2115
return NULL ;
2113
2116
}
2114
2117
2115
2118
modules = PyImport_GetModuleDict ();
2116
- m = PyDict_GetItemString (modules , name );
2119
+ m = PyDict_GetItem (modules , name );
2117
2120
if (m == NULL ) {
2118
2121
PyErr_Format (
2119
2122
PyExc_ImportError ,
2120
- "%s module %.200s not properly initialized" ,
2121
- type == C_BUILTIN ?
2122
- "builtin" : "frozen" ,
2123
+ "%s module %R not properly initialized" ,
2124
+ type == C_BUILTIN ? "builtin" : "frozen" ,
2123
2125
name );
2124
2126
return NULL ;
2125
2127
}
@@ -2168,9 +2170,15 @@ load_module(char *name, FILE *fp, char *pathname, int type, PyObject *loader)
2168
2170
break ;
2169
2171
2170
2172
case C_BUILTIN :
2171
- case PY_FROZEN :
2172
- m = load_builtin (name , pathname , type );
2173
+ case PY_FROZEN : {
2174
+ PyObject * nameobj = PyUnicode_FromString (name );
2175
+ if (nameobj != NULL ) {
2176
+ m = load_builtin (nameobj , type );
2177
+ Py_DECREF (nameobj );
2178
+ } else
2179
+ m = NULL ;
2173
2180
break ;
2181
+ }
2174
2182
2175
2183
case IMP_HOOK : {
2176
2184
if (loader == NULL ) {
@@ -2199,28 +2207,28 @@ load_module(char *name, FILE *fp, char *pathname, int type, PyObject *loader)
2199
2207
an exception set if the initialization failed. */
2200
2208
2201
2209
static int
2202
- init_builtin (char * name )
2210
+ init_builtin (PyObject * name )
2203
2211
{
2204
2212
struct _inittab * p ;
2205
2213
2206
- if (_PyImport_FindBuiltin ( name ) != NULL )
2214
+ if (_PyImport_FindExtensionObject ( name , name ) != NULL )
2207
2215
return 1 ;
2208
2216
2209
2217
for (p = PyImport_Inittab ; p -> name != NULL ; p ++ ) {
2210
2218
PyObject * mod ;
2211
- if (strcmp (name , p -> name ) == 0 ) {
2219
+ if (PyUnicode_CompareWithASCIIString (name , p -> name ) == 0 ) {
2212
2220
if (p -> initfunc == NULL ) {
2213
2221
PyErr_Format (PyExc_ImportError ,
2214
- "Cannot re-init internal module %.200s " ,
2222
+ "Cannot re-init internal module %R " ,
2215
2223
name );
2216
2224
return -1 ;
2217
2225
}
2218
2226
if (Py_VerboseFlag )
2219
- PySys_WriteStderr ("import %s # builtin\n" , name );
2227
+ PySys_FormatStderr ("import %U # builtin\n" , name );
2220
2228
mod = (* p -> initfunc )();
2221
2229
if (mod == 0 )
2222
2230
return -1 ;
2223
- if (_PyImport_FixupBuiltin (mod , name ) < 0 )
2231
+ if (_PyImport_FixupExtensionObject (mod , name , name ) < 0 )
2224
2232
return -1 ;
2225
2233
/* FixupExtension has put the module into sys.modules,
2226
2234
so we can release our own reference. */
@@ -3286,10 +3294,10 @@ imp_find_module(PyObject *self, PyObject *args)
3286
3294
static PyObject *
3287
3295
imp_init_builtin (PyObject * self , PyObject * args )
3288
3296
{
3289
- char * name ;
3297
+ PyObject * name ;
3290
3298
int ret ;
3291
3299
PyObject * m ;
3292
- if (!PyArg_ParseTuple (args , "s :init_builtin" , & name ))
3300
+ if (!PyArg_ParseTuple (args , "U :init_builtin" , & name ))
3293
3301
return NULL ;
3294
3302
ret = init_builtin (name );
3295
3303
if (ret < 0 )
@@ -3298,7 +3306,7 @@ imp_init_builtin(PyObject *self, PyObject *args)
3298
3306
Py_INCREF (Py_None );
3299
3307
return Py_None ;
3300
3308
}
3301
- m = PyImport_AddModule (name );
3309
+ m = PyImport_AddModuleObject (name );
3302
3310
Py_XINCREF (m );
3303
3311
return m ;
3304
3312
}
@@ -3346,8 +3354,8 @@ imp_is_frozen_package(PyObject *self, PyObject *args)
3346
3354
static PyObject *
3347
3355
imp_is_builtin (PyObject * self , PyObject * args )
3348
3356
{
3349
- char * name ;
3350
- if (!PyArg_ParseTuple (args , "s :is_builtin" , & name ))
3357
+ PyObject * name ;
3358
+ if (!PyArg_ParseTuple (args , "U :is_builtin" , & name ))
3351
3359
return NULL ;
3352
3360
return PyLong_FromLong (is_builtin (name ));
3353
3361
}
0 commit comments