@@ -94,17 +94,45 @@ extern struct _inittab _PyImport_Inittab[];
9494
9595struct _inittab * PyImport_Inittab = _PyImport_Inittab ;
9696
97+ /* these tables define the module suffixes that Python recognizes */
98+ struct filedescr * _PyImport_Filetab = NULL ;
99+ static const struct filedescr _PyImport_StandardFiletab [] = {
100+ {".py" , "r" , PY_SOURCE },
101+ {".pyc" , "rb" , PY_COMPILED },
102+ {0 , 0 }
103+ };
104+
97105/* Initialize things */
98106
99107void
100108_PyImport_Init ()
101109{
110+ const struct filedescr * scan ;
111+ struct filedescr * filetab ;
112+ int countD = 0 ;
113+ int countS = 0 ;
114+
115+ /* prepare _PyImport_Filetab: copy entries from
116+ _PyImport_DynLoadFiletab and _PyImport_StandardFiletab.
117+ */
118+ for (scan = _PyImport_DynLoadFiletab ; scan -> suffix != NULL ; ++ scan )
119+ ++ countD ;
120+ for (scan = _PyImport_StandardFiletab ; scan -> suffix != NULL ; ++ scan )
121+ ++ countS ;
122+ filetab = malloc ((countD + countS + 1 ) * sizeof (struct filedescr ));
123+ memcpy (filetab , _PyImport_DynLoadFiletab ,
124+ countD * sizeof (struct filedescr ));
125+ memcpy (filetab + countD , _PyImport_StandardFiletab ,
126+ countS * sizeof (struct filedescr ));
127+ filetab [countD + countS ].suffix = NULL ;
128+
129+ _PyImport_Filetab = filetab ;
130+
102131 if (Py_OptimizeFlag ) {
103- /* Replace ".pyc" with ".pyo" in import_filetab */
104- struct filedescr * p ;
105- for (p = _PyImport_Filetab ; p -> suffix != NULL ; p ++ ) {
106- if (strcmp (p -> suffix , ".pyc" ) == 0 )
107- p -> suffix = ".pyo" ;
132+ /* Replace ".pyc" with ".pyo" in _PyImport_Filetab */
133+ for (; filetab -> suffix != NULL ; filetab ++ ) {
134+ if (strcmp (filetab -> suffix , ".pyc" ) == 0 )
135+ filetab -> suffix = ".pyo" ;
108136 }
109137 }
110138}
0 commit comments